Apollo 10.0
自动驾驶开放平台
apollo::drivers::video::H265Decoder类 参考

H265Decoder is a class to actually decode videos. 更多...

#include <h265_decoder.h>

apollo::drivers::video::H265Decoder 的协作图:

Public 类型

enum class  DecodingResult { SUCCESS , FATAL , WARN }
 

Public 成员函数

 H265Decoder ()=default
 
bool Init ()
 
DecodingResult Process (const uint8_t *indata, const int32_t insize, std::vector< uint8_t > *outdata) const
 
 ~H265Decoder ()
 
AVCodecContext * GetCodecCtxH265 () const
 

详细描述

H265Decoder is a class to actually decode videos.

在文件 h265_decoder.h36 行定义.

成员枚举类型说明

◆ DecodingResult

构造及析构函数说明

◆ H265Decoder()

apollo::drivers::video::H265Decoder::H265Decoder ( )
default

◆ ~H265Decoder()

apollo::drivers::video::H265Decoder::~H265Decoder ( )
inline

在文件 h265_decoder.h55 行定义.

55{ Release(); }

成员函数说明

◆ GetCodecCtxH265()

AVCodecContext * apollo::drivers::video::H265Decoder::GetCodecCtxH265 ( ) const
inline

在文件 h265_decoder.h58 行定义.

58{ return codec_ctx_h265_; }

◆ Init()

bool apollo::drivers::video::H265Decoder::Init ( )

在文件 h265_decoder.cc30 行定义.

30 {
31 avcodec_register_all();
32 AVCodec* codec_h265 = avcodec_find_decoder(AV_CODEC_ID_H265);
33 if (codec_h265 == nullptr) {
34 AERROR << "error: codec not found";
35 return false;
36 }
37 codec_ctx_h265_ = avcodec_alloc_context3(codec_h265);
38 if (codec_ctx_h265_ == nullptr) {
39 AERROR << "error: codec context alloc fail";
40 return false;
41 }
42 if (avcodec_open2(codec_ctx_h265_, codec_h265, nullptr) < 0) {
43 AERROR << "error: could not open codec";
44 return false;
45 }
46 yuv_frame_ = av_frame_alloc();
47 if (yuv_frame_ == nullptr) {
48 AERROR << "error: could not alloc yuv frame";
49 return false;
50 }
51 AVCodec* codec_jpeg = avcodec_find_encoder(AV_CODEC_ID_MJPEG);
52 if (codec_jpeg == nullptr) {
53 AERROR << "error: jpeg Codec not found";
54 return false;
55 }
56 codec_ctx_jpeg_ = avcodec_alloc_context3(codec_jpeg);
57 if (codec_ctx_jpeg_ == nullptr) {
58 AERROR << "error: jpeg ctx allco fail";
59 return false;
60 }
61 // Put sample parameters and open it
62 codec_ctx_jpeg_->bit_rate = 400000;
63 codec_ctx_jpeg_->codec_type = AVMEDIA_TYPE_VIDEO;
64 codec_ctx_jpeg_->codec_id = AV_CODEC_ID_MJPEG;
65 codec_ctx_jpeg_->width = 1920;
66 codec_ctx_jpeg_->height = 1080;
67 codec_ctx_jpeg_->time_base = (AVRational){1, 15};
68 codec_ctx_jpeg_->pix_fmt = AV_PIX_FMT_YUVJ422P;
69 if (avcodec_open2(codec_ctx_jpeg_, codec_jpeg, nullptr) < 0) {
70 AERROR << "error: could not open jpeg context";
71 return false;
72 }
73 return true;
74}
#define AERROR
Definition log.h:44
#define AV_CODEC_ID_MJPEG
Definition usb_cam.h:58

◆ Process()

H265Decoder::DecodingResult apollo::drivers::video::H265Decoder::Process ( const uint8_t *  indata,
const int32_t  insize,
std::vector< uint8_t > *  outdata 
) const

在文件 h265_decoder.cc91 行定义.

93 {
94 AVPacket apt;
95 outdata->clear();
96 av_init_packet(&apt);
97 int got_picture = 0;
98 apt.data = const_cast<uint8_t*>(indata);
99 apt.size = insize;
100 if (apt.size == 0) {
101 apt.data = nullptr;
102 }
103 int ret =
104 avcodec_decode_video2(codec_ctx_h265_, yuv_frame_, &got_picture, &apt);
105 if (ret < 0) {
106 AERROR << "error: decode failed: input_framesize = " << apt.size
107 << ". error code = " << ret;
109 }
110 if (!got_picture) {
111 // Not an error, but just did not read pictures out
112 AWARN << "warn: failed to get yuv picture";
114 }
115 av_packet_unref(&apt);
116 got_picture = 0;
117 ret = avcodec_encode_video2(codec_ctx_jpeg_, &apt, yuv_frame_, &got_picture);
118 if (ret < 0) {
119 AERROR << "error: jpeg encode failed, error code = " << ret;
121 }
122 if (!got_picture) {
123 AERROR << "error: failed to get jpeg picture from yuyv";
125 }
126 outdata->resize(apt.size);
127 std::copy(apt.data, apt.data + apt.size, outdata->begin());
129}
#define AWARN
Definition log.h:43

该类的文档由以下文件生成: