bebop_video_decoder.h
Go to the documentation of this file.
1 
25 #ifndef BEBOP_AUTONOMY_BEBOP_VIDEO_DECODER_H
26 #define BEBOP_AUTONOMY_BEBOP_VIDEO_DECODER_H
27 
28 extern "C"
29 {
30  #include "libARController/ARCONTROLLER_Error.h"
31  #include "libARController/ARCONTROLLER_Frame.h"
32  #include <libavcodec/avcodec.h>
33  #include <libavformat/avformat.h>
34  #include <libavformat/avio.h>
35  #include <libswscale/swscale.h>
36 }
37 
38 #include <string>
39 #include <vector>
40 
41 // https://github.com/libav/libav/commit/104e10fb426f903ba9157fdbfe30292d0e4c3d72
42 // https://github.com/libav/libav/blob/33d18982fa03feb061c8f744a4f0a9175c1f63ab/doc/APIchanges#L697
43 #if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 25, 0))
44 #define AV_CODEC_ID_H264 CODEC_ID_H264
45 #endif
46 
47 // https://github.com/libav/libav/blob/33d18982fa03feb061c8f744a4f0a9175c1f63ab/doc/APIchanges#L653
48 #if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(51, 42, 0))
49 #define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P
50 #endif
51 
52 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
53 #define av_frame_alloc avcodec_alloc_frame
54 #define av_frame_free avcodec_free_frame
55 #endif
56 
57 namespace bebop_driver
58 {
59 
61 {
62 private:
63  static const char* LOG_TAG;
64 
67  AVFormatContext* format_ctx_ptr_;
68  AVCodecContext* codec_ctx_ptr_;
69  AVCodec* codec_ptr_;
70  AVFrame* frame_ptr_;
71  AVFrame* frame_rgb_ptr_;
72  AVPacket packet_;
73  SwsContext* img_convert_ctx_ptr_;
74  AVInputFormat* input_format_ptr_;
76 
78  std::vector<uint8_t> codec_data_;
79 
80  static void ThrowOnCondition(const bool cond, const std::string& message);
81  bool InitCodec();
82  bool ReallocateBuffers();
83  void CleanupBuffers();
84  void Reset();
85 
86  void ConvertFrameToRGB();
87 
88 public:
89  VideoDecoder();
90  ~VideoDecoder();
91 
92  bool SetH264Params(uint8_t* sps_buffer_ptr, uint32_t sps_buffer_size,
93  uint8_t* pps_buffer_ptr, uint32_t pps_buffer_size);
94  bool Decode(const ARCONTROLLER_Frame_t* bebop_frame_ptr_);
95  inline uint32_t GetFrameWidth() const {return codec_initialized_ ? codec_ctx_ptr_->width : 0;}
96  inline uint32_t GetFrameHeight() const {return codec_initialized_ ? codec_ctx_ptr_->height : 0;}
97 
98  inline const uint8_t* GetFrameRGBRawCstPtr() const {return frame_rgb_raw_ptr_;}
99 };
100 
101 } // namespace bebop_driver
102 
103 #endif // BEBOP_AUTONOMY_BEBOP_VIDEO_DECODER_H
uint32_t GetFrameHeight() const
bool Decode(const ARCONTROLLER_Frame_t *bebop_frame_ptr_)
bool SetH264Params(uint8_t *sps_buffer_ptr, uint32_t sps_buffer_size, uint8_t *pps_buffer_ptr, uint32_t pps_buffer_size)
std::vector< uint8_t > codec_data_
const uint8_t * GetFrameRGBRawCstPtr() const
static void ThrowOnCondition(const bool cond, const std::string &message)
AVFormatContext * format_ctx_ptr_


bebop_driver
Author(s): Mani Monajjemi
autogenerated on Mon Jun 10 2019 12:58:56