CLibAvVideoDecoderComp.h
Go to the documentation of this file.
1 #ifndef ilibav_CLibAvVideoDecoderComp_included
2 #define ilibav_CLibAvVideoDecoderComp_included
3 
4 
5 // LIBAV includes
6 extern "C"{
7 #define inline _inline
8 #define __STDC_CONSTANT_MACROS
9 #include <libavformat/avformat.h>
10 #undef inline
11 #undef __STDC_CONSTANT_MACROS
12 #undef PixelFormat
13 #undef BYTES_PER_SAMPLE
14 #undef BITS_PER_SAMPLE
15 #undef WAVE_FORMAT_PCM
16 }
17 
18 // Qt includes
19 #include <QtCore/QVector>
20 
21 // ACF includes
22 #include "ilog/TLoggerCompWrap.h"
23 
24 // ACF-Solutions includes
26 #include "imm/IVideoController.h"
27 #include "imeas/IDataSequence.h"
29 
30 
31 namespace ilibav
32 {
33 
34 
40  virtual public icam::IBitmapAcquisition,
41  virtual public imeas::ISampleAcquisition,
42  virtual public imm::IVideoController
43 {
44 public:
46 
47  enum MessageId
48  {
49  MI_CANNOT_OPEN = 0x56a20,
51  };
52 
53  I_BEGIN_COMPONENT(CLibAvVideoDecoderComp);
54  I_REGISTER_INTERFACE(iproc::IProcessor);
55  I_REGISTER_INTERFACE(icam::IBitmapAcquisition);
56  I_REGISTER_INTERFACE(imeas::ISampleAcquisition);
57  I_REGISTER_INTERFACE(istd::IChangeable);
58  I_REGISTER_INTERFACE(imm::IMediaController);
59  I_REGISTER_INTERFACE(imm::IVideoInfo);
60  I_REGISTER_INTERFACE(imm::IVideoController);
61  I_ASSIGN(m_bitmapObjectCompPtr, "BitmapObject", "Bitmap object where current bitmap is stored", false, "Bitmap");
62  I_ASSIGN(m_audioSampleObjectCompPtr, "AudioSampleObject", "Sample sequence object where current audio sample is stored", false, "AudioSequence");
63  I_ASSIGN(m_tracePositionAttrPtr, "TracePosition", "If enabled, all position changes will be updated in preview objects", true, true);
64  I_ASSIGN(m_grabProgressiveAttrPtr, "GrabProgressive", "If enabled the next frame will be returned by image and sample grab, if false only current frame will be returned", true, false);
65  I_ASSIGN(m_minimalImageDistanceAttrPtr, "MinimalImageDistance", "Minimal distance between two grabbed images if progressive grabbing enabled", false, 0.1);
66  I_END_COMPONENT;
67 
69  virtual ~CLibAvVideoDecoderComp();
70 
71  // reimplemented (icam::IBitmapAcquisition)
72  virtual istd::CIndex2d GetBitmapSize(const iprm::IParamsSet* paramsPtr) const;
73 
74  // reimplemented (imeas::ISampleAcquisition)
75  virtual double GetSamplingRate(const iprm::IParamsSet* paramsPtr) const;
76 
77  // reimplemented (iproc::IProcessor)
78  virtual int GetProcessorState(const iprm::IParamsSet* paramsPtr) const;
79  virtual bool AreParamsAccepted(
80  const iprm::IParamsSet* paramsPtr,
81  const istd::IPolymorphic* inputPtr,
82  const istd::IChangeable* outputPtr) const;
83  virtual int DoProcessing(
84  const iprm::IParamsSet* paramsPtr,
85  const istd::IPolymorphic* inputPtr,
86  istd::IChangeable* outputPtr,
87  ibase::IProgressManager* progressManagerPtr = NULL);
88  virtual int BeginTask(
89  const iprm::IParamsSet* paramsPtr,
90  const istd::IPolymorphic* inputPtr,
91  istd::IChangeable* outputPtr,
92  ibase::IProgressManager* progressManagerPtr = NULL);
93  virtual int WaitTaskFinished(
94  int taskId = -1,
95  double timeoutTime = -1,
96  bool killOnTimeout = true);
97  virtual void CancelTask(int taskId = -1);
98  virtual int GetReadyTask();
99  virtual int GetTaskState(int taskId = -1) const;
100  virtual void InitProcessor(const iprm::IParamsSet* paramsPtr);
101 
102  // reimplemented (imm::IMediaController)
103  virtual QString GetOpenedMediumUrl() const;
104  virtual bool OpenMediumUrl(const QString& url, bool autoPlay = true);
105  virtual void CloseMedium();
106  virtual bool IsPlaying() const;
107  virtual bool SetPlaying(bool state = true);
108  virtual double GetMediumLength() const;
109  virtual double GetCurrentPosition() const;
110  virtual bool SetCurrentPosition(double position);
111  virtual int GetSupportedFeatures() const;
112 
113  // reimplemented (imm::IVideoInfo)
114  virtual int GetFramesCount() const;
115  virtual double GetFrameIntervall() const;
116  virtual istd::CIndex2d GetFrameSize() const;
117  virtual double GetPixelAspectRatio() const;
118 
119  // reimplemented (imm::IVideoController)
120  virtual int GetCurrentFrame() const;
121  virtual bool SetCurrentFrame(int frameIndex);
122 
123  // reimplemented (ifile::IFileTypeInfo)
124  virtual bool GetFileExtensions(QStringList& result, int flags = -1, bool doAppend = false) const;
125  virtual QString GetTypeDescription(const QString* extensionPtr = NULL) const;
126 
127 protected:
129  {
130  FT_ERROR = -1,
136  };
137 
139  iimg::IBitmap* bitmapPtr,
140  imeas::IDataSequence* audioSequencePtr,
141  int minimalImageFrame = -1,
142  int minimalAudioFrame = -1);
143 
147  bool ReadNextPacket();
148 
152  int FinishNextTask();
153 
154  bool TryTracePosition(
155  int minimalImageFrame = -1,
156  int minimalAudioFrame = -1);
157 
158  // reimplemented (icomp::CComponentBase)
159  void OnComponentCreated();
160  void OnComponentDestroyed();
161 
162 private:
163  struct ImageTask
164  {
165  int state;
166  iimg::IBitmap* outputPtr;
167  };
168  typedef QMap<int, ImageTask> ImageTaskMap;
169  ImageTaskMap m_imageTasks;
170 
171  struct AudioTask
172  {
173  int state;
174  imeas::IDataSequence* outputPtr;
175  };
176  typedef QMap<int, AudioTask> AudioTaskMap;
177  AudioTaskMap m_audioTasks;
178 
179  int m_videoStreamId;
180  int m_audioStreamId;
181  AVFormatContext* m_formatContextPtr;
182  AVCodecContext* m_videoCodecContextPtr;
183  AVCodecContext* m_audioCodecContextPtr;
184  AVCodec* m_videoCodecPtr;
185  AVCodec* m_audioCodecPtr;
186 
187  AVFrame* m_framePtr;
188  AVFrame* m_frameRgbPtr;
189 
190  int16_t* m_audioOutputBuffer;
191  bool m_ignoreFirstAudioFrame;
192 
193  QVector<quint8> m_imageBuffer;
194 
195  AVPacket m_packet;
196  int m_rawDataSize;
197  uint8_t* m_rawDataPtr;
198 
199  QString m_currentUrl;
200 
201  I_REF(iimg::IBitmap, m_bitmapObjectCompPtr);
202  I_REF(imeas::IDataSequence, m_audioSampleObjectCompPtr);
203  I_ATTR(bool, m_tracePositionAttrPtr);
204  I_ATTR(bool, m_grabProgressiveAttrPtr);
205  I_ATTR(double, m_minimalImageDistanceAttrPtr);
206 
207  int m_currentFrame;
208  int m_lastReadFrame;
209 
210  bool m_isCurrentImageValid;
211  bool m_isCurrentSampleValid;
212  int m_nextTaskId;
213 };
214 
215 
216 } // namespace ilibav
217 
218 
219 #endif // !ilibav_CLibAvVideoDecoderComp_included
220 
virtual bool AreParamsAccepted(const iprm::IParamsSet *paramsPtr, const istd::IPolymorphic *inputPtr, const istd::IChangeable *outputPtr) const
virtual bool SetCurrentPosition(double position)
virtual void InitProcessor(const iprm::IParamsSet *paramsPtr)
virtual bool SetCurrentFrame(int frameIndex)
virtual int GetFramesCount() const
virtual bool GetFileExtensions(QStringList &result, int flags=-1, bool doAppend=false) const
virtual QString GetTypeDescription(const QString *extensionPtr=NULL) const
virtual double GetCurrentPosition() const
virtual double GetMediumLength() const
virtual bool SetPlaying(bool state=true)
virtual istd::CIndex2d GetBitmapSize(const iprm::IParamsSet *paramsPtr) const
virtual bool IsPlaying() const
ilog::CLoggerComponentBase BaseClass
int FinishNextTask()
Fininsh single task and return its ID.
virtual double GetSamplingRate(const iprm::IParamsSet *paramsPtr) const
virtual int GetProcessorState(const iprm::IParamsSet *paramsPtr) const
virtual double GetPixelAspectRatio() const
Implementation of imm::IVideoController and icam::IBitmapAcquisition interfaces using LibAv library...
virtual double GetFrameIntervall() const
virtual int GetTaskState(int taskId=-1) const
virtual int DoProcessing(const iprm::IParamsSet *paramsPtr, const istd::IPolymorphic *inputPtr, istd::IChangeable *outputPtr, ibase::IProgressManager *progressManagerPtr=NULL)
bool TryTracePosition(int minimalImageFrame=-1, int minimalAudioFrame=-1)
virtual int GetSupportedFeatures() const
bool ReadNextPacket()
Read next packet from stream.
virtual int WaitTaskFinished(int taskId=-1, double timeoutTime=-1, bool killOnTimeout=true)
virtual bool OpenMediumUrl(const QString &url, bool autoPlay=true)
virtual QString GetOpenedMediumUrl() const
virtual void CancelTask(int taskId=-1)
virtual int GetCurrentFrame() const
virtual int BeginTask(const iprm::IParamsSet *paramsPtr, const istd::IPolymorphic *inputPtr, istd::IChangeable *outputPtr, ibase::IProgressManager *progressManagerPtr=NULL)
FrameType ReadNextFrame(iimg::IBitmap *bitmapPtr, imeas::IDataSequence *audioSequencePtr, int minimalImageFrame=-1, int minimalAudioFrame=-1)
virtual istd::CIndex2d GetFrameSize() const

© 2007-2011 Witold Gantzke and Kirill Lepskiy