|
2019-05-17
if (hw_device_ctx == nullptr) {
(*dec_ctx)->get_format = hw_get_format;
// 创建硬件加速器的缓冲区
if (av_hwdevice_ctx_create(&hw_device_ctx,device_type,NULL,NULL,0) < 0) {
SoError("av_hwdevice_ctx_create fail!");
return;
}
/** 如果使用软解码则默认有一个软解码的缓冲区(获取AVFrame的),而硬解码则可以额外创建硬件解码的缓冲区
* 这个缓冲区变量为hw_frames_ctx,不手动创建,则在调用avcodec_send_packet()函数内部自动创建一个
* 但是必须手动赋值硬件解码缓冲区引用hw_device_ctx(是一个AVBufferRef变量)
* 即hw_device_ctx有值,则使用硬件缓存方式解码
*/
SoDebug("av_hwdevice_ctx_create end, ctx: %p.", hw_device_ctx);
}
(*dec_ctx)->hw_device_ctx = av_buffer_ref(hw_device_ctx);
// 配置获取硬件加速器像素格式的函数;该函数实际上就是将AVCodec中AVHWCodecConfig中的pix_fmt返回
enum AVPixelFormat hw_device_pixel;
enum AVPixelFormat hw_get_format(AVCodecContext *ctx,const enum AVPixelFormat *fmts)
{
const enum AVPixelFormat *p;
for (p = fmts; *p != AV_PIX_FMT_NONE; p++) {
if (*p == hw_device_pixel) {
SoDebug("get hw_get_format res: %d", *p);
return *p;
}
}
SoWarn("Failed to get HW surface format!");
return AV_PIX_FMT_NONE;
}
编辑:航网科技 来源:腾讯云 本文版权归原作者所有 转载请注明出处
微信扫一扫咨询客服
全国免费服务热线
0755-36300002