当前位置:网站首页>openh264解码数据流向分析
openh264解码数据流向分析
2022-07-05 19:34:00 【HUI的技術筆記】
openh264dec中finish_frame的逻辑和avviddec比起来比较简单,在handle_frame中,buffer先送给解码器解码(DecodeFrameNoDelay
),然后调用gst_video_decoder_finish_frame
将解码后的buffer发到downstream。
DecodeFrameNoDelay解码,返回yuvdata,完成后unmap input_buffer:
openh264dec->decoder->DecodeFrameNoDelay (map_info.data, map_info.size,
yuvdata, &dst_buf_info);
gst_buffer_unmap (frame->input_buffer, &map_info);
gst_video_frame_map的功能
gst_video_frame_map()将在GstVideoFrame结构中填入buffer的像素以及所需的各种视频信息。
gboolean
gst_video_frame_map (GstVideoFrame * frame, GstVideoInfo * info, GstBuffer * buffer, GstMapFlags flags)
使用@info和@buffer来填入到@frame,地址会被传给分配在堆栈中的#GstVideoFrame结构。
可以使用访问器宏访问,如:
GST_VIDEO_FRAME_COMP_DATA()
GST_VIDEO_FRAME_PLANE_DATA()
GST_VIDEO_FRAME_COMP_STRIDE()
GST_VIDEO_FRAME_PLANE_STRIDE()
这个功能的目的是使你能够很容易地获得视频像素,而不需要担心太多细节问题。
比如视频数据是被分配在一个连续的内存块中还是多个内存块(例如,对于每一个plane都有一个内存块),或者是否使用自定义strides和自定义plane偏移(由每个缓冲区上的GstVideoMeta记录)。
这个函数只是用正确的值填充#GstVideoFrame结构
,使用访问器宏,可以很容易地访问数据。它还会为你映射底层的内存块。
gst_video_frame_map的使用从ffmpeg avviddec和openh264dec的实现也可以看到,能方便的把解码器解码的数据放到plane内存块中。
GstVideoFrame的定义
/** * GstVideoFrame: * @info: the #GstVideoInfo * @flags: #GstVideoFrameFlags for the frame * @buffer: the mapped GstBuffer's buffer * @meta: pointer to metadata if any * @id: id of the mapped frame. the id can for example be used to * identify the frame in case of multiview video. * @data: pointers to the plane data * @map: mappings of the planes * * A video frame obtained from gst_video_frame_map() */
struct _GstVideoFrame {
GstVideoInfo info;
GstVideoFrameFlags flags;
GstBuffer *buffer;
gpointer meta;
gint id;
gpointer data[GST_VIDEO_MAX_PLANES];
GstMapInfo map[GST_VIDEO_MAX_PLANES];
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
gst_video_decoder_allocate_output_frame
辅助函数,为@decoder当前的#GstVideoCodecState分配一个缓冲区来容纳一个视频帧。子类应该已经配置了视频状态并设置了src pad caps。从openH264dec和avdec_h264中都可以看到,最后解码的数据要先allocate_output_frame,然后copy数据到这个里面,avviddec里面的处理需要看get_output_buffer函数的实现。
gst_video_decoder_finish_frame
在openh264dec中,通过gst_video_decoder_finish_frame
将解码后的数据push到downstream,如果没有提供输出数据,frame被视为skipped。在任何情况下,frame都被视为finished和released。
gst_openh264dec_handle_frame
- 收到frame后先交给openh264dec解码->DecodeFrameNoDelay
- gst_video_frame_map:映射frame->output_buffer,将解码的yuvdata填进去。
- gst_video_decoder_set_output_state:在srcpad上创建新的codec state作为解码器的输出状态
- gst_video_decoder_finish_frame发送给downstream
因为output state部分配置的是I420,所以在进行数据copy的时候,是yuv依次copy:
// i = 0; Y plane
// i = 1; U plane
// i = 2; V plane
for (i = 0; i < 3; i++) {
p = GST_VIDEO_FRAME_COMP_DATA (&video_frame, i);
row_stride = GST_VIDEO_FRAME_COMP_STRIDE (&video_frame, i);
component_width = GST_VIDEO_FRAME_COMP_WIDTH (&video_frame, i);
component_height = GST_VIDEO_FRAME_COMP_HEIGHT (&video_frame, i);
src_width =
i <
1 ? dst_buf_info.UsrData.sSystemBuffer.
iStride[0] : dst_buf_info.UsrData.sSystemBuffer.iStride[1];
for (row = 0; row < component_height; row++) {
memcpy (p, yuvdata[i], component_width);
p += row_stride;
yuvdata[i] += src_width;
}
}
边栏推荐
- Vagrant2.2.6 supports virtualbox6.1
- After the company went bankrupt, the blackstones came
- MMO项目学习一:预热
- 如何实现游戏中的在线计时器和离线计时器
- [OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
- Fundamentals of machine learning (III) -- KNN / naive Bayes / cross validation / grid search
- 全网最全的低代码/无代码平台盘点:简道云、伙伴云、明道云、轻流、速融云、集简云、Treelab、钉钉·宜搭、腾讯云·微搭、智能云·爱速搭、百数云
- IBM has laid off 40 + year-old employees in a large area. Mastering these ten search skills will improve your work efficiency ten times
- Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
- Advanced application of C # language
猜你喜欢
Ultrasonic ranging based on FPGA
Postman核心功能解析-参数化和测试报告
Do you know several assertion methods commonly used by JMeter?
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法
太牛了,看这篇足矣了
毫米波雷达人体感应器,智能感知静止存在,人体存在检测应用
14、用户、组和权限(14)
XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
强化学习-学习笔记4 | Actor-Critic
随机推荐
【无标题】
手机股票开户安全吗?靠不靠谱啊?
Mysql如何对json数据进行查询及修改
Zhongang Mining: analysis of the current market supply situation of the global fluorite industry in 2022
中国银河证券开户安全吗 证券开户
Vagrant2.2.6 supports virtualbox6.1
不愧是大佬,字节大牛耗时八个月又一力作
太牛了,看这篇足矣了
数学分析_笔记_第9章:曲线积分与曲面积分
司空见惯 - 英雄扫雷鼠
Ultrasonic ranging based on FPGA
Postman核心功能解析-参数化和测试报告
Decision tree and random forest
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
Common interview questions in Android, 2022 golden nine silver ten Android factory interview questions hit
HAC cluster modifying administrator user password
【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
#夏日挑战赛#数据库学霸笔记,考试/面试快速复习~
Go语言学习教程(十五)