当前位置:网站首页>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;
}
}
边栏推荐
- 安卓面试宝典,2022Android面试笔试总结
- [AI framework basic technology] automatic derivation mechanism (autograd)
- Realizing deep learning framework from zero -- LSTM from theory to practice [practice]
- PG basics -- Logical Structure Management (user and permission management)
- 开源 SPL 消灭数以万计的数据库中间表
- Apprentissage du projet MMO I: préchauffage
- Shell编程基础(第8篇:分支语句-case in)
- What are the reliable domestic low code development platforms?
- Pandora IOT development board learning (HAL Library) - Experiment 8 timer interrupt experiment (learning notes)
- 不愧是大佬,字节大牛耗时八个月又一力作
猜你喜欢
大厂面试必备技能,2022Android不死我不倒
MMO項目學習一:預熱
Webuploader file upload drag upload progress monitoring type control upload result monitoring control
5 years of experience, 27 days of Android programmer interview, 2022 programmer advanced classic
[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
What are the reliable domestic low code development platforms?
众昂矿业:2022年全球萤石行业市场供给现状分析
Hiengine: comparable to the local cloud native memory database engine
The city chain technology Digital Innovation Strategy Summit was successfully held
四万字长文说operator new & operator delete
随机推荐
MySQL中字段类型为longtext的值导出后显示二进制串方式
Reinforcement learning - learning notes 4 | actor critical
S7-200SMART利用V90 MODBUS通信控制库控制V90伺服的具体方法和步骤
数据库 逻辑处理功能
Xaas trap: all things serve (possible) is not what it really needs
Django使用mysqlclient服务连接并写入数据库的操作过程
Reptile exercises (II)
What is the core value of testing?
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Postman核心功能解析-参数化和测试报告
How to convert word into PDF? Word to PDF simple way to share!
Fundamentals of shell programming (Part 8: branch statements -case in)
Notion 类生产力工具如何选择?Notion 、FlowUs 、Wolai 对比评测
webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
手机股票开户安全吗?靠不靠谱啊?
Debezium系列之:解析默认值字符集
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
爬虫练习题(二)
开源 SPL 消灭数以万计的数据库中间表
司空见惯 - 英雄扫雷鼠