AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IReader.cpp
Go to the documentation of this file.
1 #include "IReader.hpp"
2 
3 #include <cassert>
4 
5 namespace avtranscoder
6 {
7 
8 IReader::IReader(const std::string& filename, const size_t streamIndex, const int channelIndex)
9  : _inputFile(NULL)
10  , _streamProperties(NULL)
11  , _decoder(NULL)
12  , _generator(NULL)
13  , _currentDecoder(NULL)
14  , _srcFrame(NULL)
15  , _dstFrame(NULL)
16  , _transform(NULL)
17  , _streamIndex(streamIndex)
18  , _channelIndex(channelIndex)
19  , _currentFrame(-1)
20  , _inputFileAllocated(true)
21  , _continueWithGenerator(false)
22 {
23  _inputFile = new InputFile(filename);
24 }
25 
26 IReader::IReader(InputFile& inputFile, const size_t streamIndex, const int channelIndex)
27  : _inputFile(&inputFile)
28  , _streamProperties(NULL)
29  , _decoder(NULL)
30  , _generator(NULL)
31  , _currentDecoder(NULL)
32  , _srcFrame(NULL)
33  , _dstFrame(NULL)
34  , _transform(NULL)
35  , _streamIndex(streamIndex)
36  , _channelIndex(channelIndex)
37  , _currentFrame(-1)
38  , _inputFileAllocated(false)
39  , _continueWithGenerator(false)
40 {
41 }
42 
44 {
46  delete _inputFile;
47 }
48 
50 {
51  return readFrameAt(_currentFrame + 1);
52 }
53 
55 {
56  return readFrameAt(_currentFrame - 1);
57 }
58 
59 Frame* IReader::readFrameAt(const size_t frame)
60 {
61  assert(_currentDecoder != NULL);
62  assert(_transform != NULL);
63  assert(_srcFrame != NULL);
64  assert(_dstFrame != NULL);
65 
66  // seek
67  if((int)frame != _currentFrame + 1)
68  {
69  _inputFile->seekAtFrame(frame);
71  }
72  _currentFrame = frame;
73  // decode
74  bool decodingStatus = false;
75  if(_channelIndex != -1)
77  else
78  decodingStatus = _currentDecoder->decodeNextFrame(*_srcFrame);
79  // if decoding failed
80  if(!decodingStatus)
81  {
82  // generate data (ie silence or black)
84  {
86  return readFrameAt(frame);
87  }
88  // or return NULL
89  else
90  {
91  return NULL;
92  }
93  }
94  // transform
96  return _dstFrame;
97 }
98 }
IDecoder * _generator
Definition: IReader.hpp:70
bool _inputFileAllocated
Does the InputFile is held by the class or not (depends on the constructor called) ...
Definition: IReader.hpp:83
IDecoder * _decoder
Definition: IReader.hpp:69
int _currentFrame
The current decoded frame.
Definition: IReader.hpp:82
IReader(const std::string &filename, const size_t streamIndex=0, const int channelIndex=-1)
Create a new InputFile and prepare to read the stream at the given index.
Definition: IReader.cpp:8
bool seekAtFrame(const size_t frame, const int flag=AVSEEK_FLAG_ANY)
Seek at a specific frame / time (in seconds)
Definition: InputFile.cpp:96
virtual void flushDecoder()
Reset the internal decoder state / flush internal buffers.
Definition: IDecoder.hpp:53
InputFile * _inputFile
Definition: IReader.hpp:67
Frame * readPrevFrame()
Definition: IReader.cpp:54
virtual void convert(const Frame &src, Frame &dst)=0
Frame * readFrameAt(const size_t frame)
Definition: IReader.cpp:59
This class describes decoded (raw) audio or video data.
Definition: Frame.hpp:16
ITransform * _transform
Definition: IReader.hpp:76
Frame * readNextFrame()
Definition: IReader.cpp:49
virtual ~IReader()=0
Definition: IReader.cpp:43
virtual bool decodeNextFrame(Frame &frameBuffer)=0
Decode next frame.
IDecoder * _currentDecoder
Link to _inputDecoder or _generator.
Definition: IReader.hpp:71
bool _continueWithGenerator
If there is no more data to decode, complete with generated data.
Definition: IReader.hpp:84