forked from avTranscoder/avTranscoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIReader.cpp
More file actions
98 lines (89 loc) · 2.21 KB
/
Copy pathIReader.cpp
File metadata and controls
98 lines (89 loc) · 2.21 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "IReader.hpp"
#include <cassert>
namespace avtranscoder
{
IReader::IReader(const std::string& filename, const size_t streamIndex, const int channelIndex)
: _inputFile(NULL)
, _streamProperties(NULL)
, _decoder(NULL)
, _generator(NULL)
, _currentDecoder(NULL)
, _srcFrame(NULL)
, _dstFrame(NULL)
, _transform(NULL)
, _streamIndex(streamIndex)
, _channelIndex(channelIndex)
, _currentFrame(-1)
, _inputFileAllocated(true)
, _continueWithGenerator(false)
{
_inputFile = new InputFile(filename);
}
IReader::IReader(InputFile& inputFile, const size_t streamIndex, const int channelIndex)
: _inputFile(&inputFile)
, _streamProperties(NULL)
, _decoder(NULL)
, _generator(NULL)
, _currentDecoder(NULL)
, _srcFrame(NULL)
, _dstFrame(NULL)
, _transform(NULL)
, _streamIndex(streamIndex)
, _channelIndex(channelIndex)
, _currentFrame(-1)
, _inputFileAllocated(false)
, _continueWithGenerator(false)
{
}
IReader::~IReader()
{
if(_inputFileAllocated)
delete _inputFile;
}
Frame* IReader::readNextFrame()
{
return readFrameAt(_currentFrame + 1);
}
Frame* IReader::readPrevFrame()
{
return readFrameAt(_currentFrame - 1);
}
Frame* 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(_channelIndex != -1)
decodingStatus = _currentDecoder->decodeNextFrame(*_srcFrame, _channelIndex);
else
decodingStatus = _currentDecoder->decodeNextFrame(*_srcFrame);
// if decoding failed
if(!decodingStatus)
{
// generate data (ie silence or black)
if(_continueWithGenerator)
{
_currentDecoder = _generator;
return readFrameAt(frame);
}
// or return NULL
else
{
return NULL;
}
}
// transform
_transform->convert(*_srcFrame, *_dstFrame);
return _dstFrame;
}
}