Skip to content

Commit 61b9f6e

Browse files
author
Clement Champetier
committed
IReader: added behavior to generate data when there is no more data to decode
* New attribute: _continueWithGenerator * New method: continueWithGenerator
1 parent 1b8bce2 commit 61b9f6e

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/AvTranscoder/reader/IReader.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ IReader::IReader(const std::string& filename, const size_t streamIndex, const in
1616
, _channelIndex(channelIndex)
1717
, _currentFrame(-1)
1818
, _inputFileAllocated(true)
19+
, _continueWithGenerator(false)
1920
{
2021
_inputFile = new InputFile(filename);
2122
}
@@ -31,6 +32,7 @@ IReader::IReader(InputFile& inputFile, const size_t streamIndex, const int chann
3132
, _channelIndex(channelIndex)
3233
, _currentFrame(-1)
3334
, _inputFileAllocated(false)
35+
, _continueWithGenerator(false)
3436
{
3537
}
3638

@@ -53,6 +55,7 @@ Frame* IReader::readPrevFrame()
5355
Frame* IReader::readFrameAt(const size_t frame)
5456
{
5557
assert(_decoder != NULL);
58+
assert(_generator != NULL);
5659
assert(_transform != NULL);
5760
assert(_srcFrame != NULL);
5861
assert(_dstFrame != NULL);
@@ -70,10 +73,20 @@ Frame* IReader::readFrameAt(const size_t frame)
7073
decodingStatus = _decoder->decodeNextFrame(*_srcFrame, _channelIndex);
7174
else
7275
decodingStatus = _decoder->decodeNextFrame(*_srcFrame);
76+
// if decoding failed
7377
if(!decodingStatus)
7478
{
75-
_dstFrame->clear();
76-
return _dstFrame;
79+
// generate data (ie silence or black)
80+
if(_continueWithGenerator)
81+
{
82+
_generator->decodeNextFrame(*_srcFrame);
83+
}
84+
// or return an empty frame
85+
else
86+
{
87+
_dstFrame->clear();
88+
return _dstFrame;
89+
}
7790
}
7891
// transform
7992
_transform->convert(*_srcFrame, *_dstFrame);

src/AvTranscoder/reader/IReader.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,17 @@ class AvExport IReader
5353
*/
5454
const StreamProperties* getSourceProperties() const { return _streamProperties; }
5555

56+
/**
57+
* @brief Set the reader state to generate data (ie silence or black) when there is no more data to decode.
58+
* @note By default, the reader returns an empty frame.
59+
*/
60+
void continueWithGenerator(const bool continueWithGenerator = true) { _continueWithGenerator = continueWithGenerator; }
61+
5662
protected:
5763
InputFile* _inputFile;
5864
const StreamProperties* _streamProperties;
5965
IDecoder* _decoder;
66+
IDecoder* _generator;
6067

6168
Frame* _srcFrame;
6269
Frame* _dstFrame;
@@ -69,6 +76,7 @@ class AvExport IReader
6976
private:
7077
int _currentFrame; ///< The current decoded frame.
7178
bool _inputFileAllocated; ///< Does the InputFile is held by the class or not (depends on the constructor called)
79+
bool _continueWithGenerator; ///< If there is no more data to decode, complete with generated data
7280
};
7381
}
7482

0 commit comments

Comments
 (0)