-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathIReader.cpp
More file actions
83 lines (75 loc) · 1.86 KB
/
IReader.cpp
File metadata and controls
83 lines (75 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "IReader.hpp"
#include <cassert>
namespace avtranscoder
{
IReader::IReader(const InputStreamDesc& inputDesc)
: _inputDesc(inputDesc)
, _inputFile(NULL)
, _streamProperties(NULL)
, _decoder(NULL)
, _generator(NULL)
, _currentDecoder(NULL)
, _srcFrame(NULL)
, _dstFrame(NULL)
, _transform(NULL)
, _currentFrame(-1)
, _continueWithGenerator(false)
{
_inputFile = new InputFile(_inputDesc._filename);
}
IReader::~IReader()
{
delete _inputFile;
}
IFrame* IReader::readNextFrame()
{
return readFrameAt(_currentFrame + 1);
}
IFrame* IReader::readPrevFrame()
{
return readFrameAt(_currentFrame - 1);
}
IFrame* IReader::readFrameAt(const size_t frame)
{
assert(_currentDecoder != NULL);
assert(_transform != NULL);
assert(_srcFrame != NULL);
assert(_dstFrame != NULL);
// seek
if((int)frame != _currentFrame + 1)
{
_inputFile->seekAtFrame(frame);
_decoder->flushDecoder();
}
_currentFrame = frame;
// decode
bool decodingStatus = false;
if(! _inputDesc._channelIndexArray.empty())
{
decodingStatus = _currentDecoder->decodeNextFrame(*_srcFrame, _inputDesc._channelIndexArray);
}
else
decodingStatus = _currentDecoder->decodeNextFrame(*_srcFrame);
// if decoding failed
if(!decodingStatus)
{
// generate data (ie silence or black)
if(_continueWithGenerator)
{
// allocate the frame since the process will continue with some generated data
if(! _srcFrame->isDataAllocated())
_srcFrame->allocateData();
_currentDecoder = _generator;
return readFrameAt(frame);
}
// or return NULL
else
{
return NULL;
}
}
// transform
_transform->convert(*_srcFrame, *_dstFrame);
return _dstFrame;
}
}