bebop_video_decoder.h
Go to the documentation of this file.
00001 
00025 #ifndef BEBOP_AUTONOMY_BEBOP_VIDEO_DECODER_H
00026 #define BEBOP_AUTONOMY_BEBOP_VIDEO_DECODER_H
00027 
00028 extern "C"
00029 {
00030   #include "libARController/ARCONTROLLER_Error.h"
00031   #include "libARController/ARCONTROLLER_Frame.h"
00032   #include <libavcodec/avcodec.h>
00033   #include <libavformat/avformat.h>
00034   #include <libavformat/avio.h>
00035   #include <libswscale/swscale.h>
00036 }
00037 
00038 #include <string>
00039 #include <vector>
00040 
00041 // https://github.com/libav/libav/commit/104e10fb426f903ba9157fdbfe30292d0e4c3d72
00042 // https://github.com/libav/libav/blob/33d18982fa03feb061c8f744a4f0a9175c1f63ab/doc/APIchanges#L697
00043 #if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 25, 0))
00044 #define AV_CODEC_ID_H264 CODEC_ID_H264
00045 #endif
00046 
00047 // https://github.com/libav/libav/blob/33d18982fa03feb061c8f744a4f0a9175c1f63ab/doc/APIchanges#L653
00048 #if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(51, 42, 0))
00049 #define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P
00050 #endif
00051 
00052 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
00053 #define av_frame_alloc  avcodec_alloc_frame
00054 #define av_frame_free avcodec_free_frame
00055 #endif
00056 
00057 namespace bebop_driver
00058 {
00059 
00060 class VideoDecoder
00061 {
00062 private:
00063   static const char* LOG_TAG;
00064 
00065   bool codec_initialized_;
00066   bool first_iframe_recv_;
00067   AVFormatContext* format_ctx_ptr_;
00068   AVCodecContext* codec_ctx_ptr_;
00069   AVCodec* codec_ptr_;
00070   AVFrame* frame_ptr_;
00071   AVFrame* frame_rgb_ptr_;
00072   AVPacket packet_;
00073   SwsContext* img_convert_ctx_ptr_;
00074   AVInputFormat* input_format_ptr_;
00075   uint8_t *frame_rgb_raw_ptr_;
00076 
00077   bool update_codec_params_;
00078   std::vector<uint8_t> codec_data_;
00079 
00080   static void ThrowOnCondition(const bool cond, const std::string& message);
00081   bool InitCodec();
00082   bool ReallocateBuffers();
00083   void CleanupBuffers();
00084   void Reset();
00085 
00086   void ConvertFrameToRGB();
00087 
00088 public:
00089   VideoDecoder();
00090   ~VideoDecoder();
00091 
00092   bool SetH264Params(uint8_t* sps_buffer_ptr, uint32_t sps_buffer_size,
00093                      uint8_t* pps_buffer_ptr, uint32_t pps_buffer_size);
00094   bool Decode(const ARCONTROLLER_Frame_t* bebop_frame_ptr_);
00095   inline uint32_t GetFrameWidth() const {return codec_initialized_ ? codec_ctx_ptr_->width : 0;}
00096   inline uint32_t GetFrameHeight() const {return codec_initialized_ ? codec_ctx_ptr_->height : 0;}
00097 
00098   inline const uint8_t* GetFrameRGBRawCstPtr() const {return frame_rgb_raw_ptr_;}
00099 };
00100 
00101 }  // namespace bebop_driver
00102 
00103 #endif  // BEBOP_AUTONOMY_BEBOP_VIDEO_DECODER_H


bebop_driver
Author(s): Mani Monajjemi
autogenerated on Mon Aug 21 2017 02:36:39