Re: [FFmpeg-devel] [PATCH 4/6] lavf/vpp: enable video memory accel for transcoding with vpp. lavc/qsv: export symbols "ff_qsv_*" which will be used by vpp. ffmpeg_qsv: set default hwaccel to qsv.
Idem. Patch does too many things and changes unrelated code. On 25 Aug, Nablet Developer wrote : > From: ChaoX A Liu > > Signed-off-by: ChaoX A Liu > --- > ffmpeg_qsv.c| 46 --- > libavcodec/libavcodec.v | 1 + > libavcodec/qsv.h| 2 + > libavfilter/vf_qsvvpp.c | 153 > > 4 files changed, 172 insertions(+), 30 deletions(-) > > diff --git a/ffmpeg_qsv.c b/ffmpeg_qsv.c > index 43402d6..aed9240 100644 > --- a/ffmpeg_qsv.c > +++ b/ffmpeg_qsv.c > @@ -386,7 +386,7 @@ static mfxStatus frame_alloc(mfxHDL pthis, > mfxFrameAllocRequest *request, mfxFra > unsigned int va_fourcc = 0; > mfxU32 fourcc = request->Info.FourCC; > QSVContext *q = pthis; > -AVQSVContext *qsv = q->ost->enc_ctx->hwaccel_context; > +AVQSVContext *qsv = NULL; > mfxU16 numAllocated = 0; > bool bCreateSrfSucceeded = false; > mfxU32 mfx_fourcc; > @@ -394,17 +394,40 @@ static mfxStatus frame_alloc(mfxHDL pthis, > mfxFrameAllocRequest *request, mfxFra > int width32; > int height32; > void *avctx = NULL; > +FilterGraph *fg = q->ost->filter->graph; > > -av_log(avctx, AV_LOG_INFO, "=vaapi alloc frame==\n"); > if (!request || !response || !request->NumFrameSuggested) > return MFX_ERR_MEMORY_ALLOC; > > memset(response, 0, sizeof(*response)); > surface_num = request->NumFrameSuggested; > -if ((request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) && > -(request->Type & MFX_MEMTYPE_FROM_DECODE)) > -surface_num += (qsv->nb_encoder_surfaces + qsv->nb_decoder_surfaces); > +if (request->Type & MFX_MEMTYPE_FROM_DECODE) { > +avctx = input_streams[q->ost->source_index]->dec_ctx; > +if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) { > +AVFilterContext *qsvvpp = avfilter_graph_get_filter(fg->graph, > "Parsed_qsvvpp_0"); > +qsv = > input_streams[q->ost->source_index]->dec_ctx->hwaccel_context; > +surface_num += qsv->nb_decoder_surfaces; > +if (qsvvpp) { > +qsv = qsvvpp->hw_device_ctx->data; > +surface_num += qsv->nb_vpp_surfaces; > +} else { > +qsv = q->ost->enc_ctx->hwaccel_context; > +surface_num += qsv->nb_encoder_surfaces; > +} > +} > +} else if (request->Type & MFX_MEMTYPE_FROM_VPPOUT) { > +AVFilterContext *qsvvpp = avfilter_graph_get_filter(fg->graph, > "Parsed_qsvvpp_0"); > +avctx = qsvvpp; > +if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) { > +qsv = q->ost->enc_ctx->hwaccel_context; > +surface_num += qsv->nb_encoder_surfaces; > +} > +} else if (request->Type & MFX_MEMTYPE_FROM_ENCODE) { > +avctx = q->ost->enc_ctx; > +} else > +av_log(avctx, AV_LOG_WARNING, "FrameAlloc: may get a bug.\n"); > > +av_log(avctx, AV_LOG_INFO, "=vaapi alloc frame==\n"); > av_log(avctx, AV_LOG_INFO, "VAAPI: va_dpy =%p, surface_num=%d, width=%d, > height=%d\n", > g_session.va_display, surface_num, request->Info.Width, > request->Info.Height); > av_log(avctx, AV_LOG_INFO, "VAAPI: request->Type=%x\n",request->Type); > @@ -720,7 +743,7 @@ static int qsv_check_filters(const OutputStream *ost) > AVFilterInOut *inputs, *outputs; > int ret = 0; > int i; > -const char *filter_list = "buffer|buffersink|null|format|setpts"; > +const char *filter_list = "buffer|buffersink|null|format|setpts|qsvvpp"; > > if (!ost->avfilter) > return -1; > @@ -820,6 +843,7 @@ int qsv_transcode_init_vidmem(OutputStream *ost) > > QSVContext *qsv = NULL; > AVQSVContext *enc_hwctx = NULL; > +AVQSVContext *vpp_hwctx = NULL; > > /* check if the encoder supports QSV */ > if (!ost->enc->pix_fmts) > @@ -836,6 +860,8 @@ int qsv_transcode_init_vidmem(OutputStream *ost) > > /* check if the decoder supports QSV and the output only goes to this > stream */ > ist = input_streams[ost->source_index]; > +if (ist->hwaccel_id == HWACCEL_NONE || ist->hwaccel_id == HWACCEL_AUTO) > +ist->hwaccel_id = HWACCEL_QSV; > if (ist->nb_filters || ist->hwaccel_id != HWACCEL_QSV || > !ist->dec || !ist->dec->pix_fmts) > return 0; > @@ -854,7 +880,8 @@ int qsv_transcode_init_vidmem(OutputStream *ost) > > qsv = av_mallocz(sizeof(*qsv)); > enc_hwctx = av_qsv_alloc_context(); > -if (!qsv || !enc_hwctx) > +vpp_hwctx = av_qsv_alloc_context(); > +if (!qsv || !enc_hwctx || !vpp_hwctx) > goto fail; > > err = ff_qsv_init_internal_session(NULL, &g_session); > @@ -891,6 +918,11 @@ int qsv_transcode_init_vidmem(OutputStream *ost) > ist->resample_pix_fmt= AV_PIX_FMT_QSV; > ist->hwaccel_ctx = qsv; > > +vpp_hwctx->session = qsv->session; > +
[FFmpeg-devel] [PATCH 4/6] lavf/vpp: enable video memory accel for transcoding with vpp. lavc/qsv: export symbols "ff_qsv_*" which will be used by vpp. ffmpeg_qsv: set default hwaccel to qsv.
From: ChaoX A Liu Signed-off-by: ChaoX A Liu --- ffmpeg_qsv.c| 46 --- libavcodec/libavcodec.v | 1 + libavcodec/qsv.h| 2 + libavfilter/vf_qsvvpp.c | 153 4 files changed, 172 insertions(+), 30 deletions(-) diff --git a/ffmpeg_qsv.c b/ffmpeg_qsv.c index 43402d6..aed9240 100644 --- a/ffmpeg_qsv.c +++ b/ffmpeg_qsv.c @@ -386,7 +386,7 @@ static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *request, mfxFra unsigned int va_fourcc = 0; mfxU32 fourcc = request->Info.FourCC; QSVContext *q = pthis; -AVQSVContext *qsv = q->ost->enc_ctx->hwaccel_context; +AVQSVContext *qsv = NULL; mfxU16 numAllocated = 0; bool bCreateSrfSucceeded = false; mfxU32 mfx_fourcc; @@ -394,17 +394,40 @@ static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *request, mfxFra int width32; int height32; void *avctx = NULL; +FilterGraph *fg = q->ost->filter->graph; -av_log(avctx, AV_LOG_INFO, "=vaapi alloc frame==\n"); if (!request || !response || !request->NumFrameSuggested) return MFX_ERR_MEMORY_ALLOC; memset(response, 0, sizeof(*response)); surface_num = request->NumFrameSuggested; -if ((request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) && -(request->Type & MFX_MEMTYPE_FROM_DECODE)) -surface_num += (qsv->nb_encoder_surfaces + qsv->nb_decoder_surfaces); +if (request->Type & MFX_MEMTYPE_FROM_DECODE) { +avctx = input_streams[q->ost->source_index]->dec_ctx; +if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) { +AVFilterContext *qsvvpp = avfilter_graph_get_filter(fg->graph, "Parsed_qsvvpp_0"); +qsv = input_streams[q->ost->source_index]->dec_ctx->hwaccel_context; +surface_num += qsv->nb_decoder_surfaces; +if (qsvvpp) { +qsv = qsvvpp->hw_device_ctx->data; +surface_num += qsv->nb_vpp_surfaces; +} else { +qsv = q->ost->enc_ctx->hwaccel_context; +surface_num += qsv->nb_encoder_surfaces; +} +} +} else if (request->Type & MFX_MEMTYPE_FROM_VPPOUT) { +AVFilterContext *qsvvpp = avfilter_graph_get_filter(fg->graph, "Parsed_qsvvpp_0"); +avctx = qsvvpp; +if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) { +qsv = q->ost->enc_ctx->hwaccel_context; +surface_num += qsv->nb_encoder_surfaces; +} +} else if (request->Type & MFX_MEMTYPE_FROM_ENCODE) { +avctx = q->ost->enc_ctx; +} else +av_log(avctx, AV_LOG_WARNING, "FrameAlloc: may get a bug.\n"); +av_log(avctx, AV_LOG_INFO, "=vaapi alloc frame==\n"); av_log(avctx, AV_LOG_INFO, "VAAPI: va_dpy =%p, surface_num=%d, width=%d, height=%d\n", g_session.va_display, surface_num, request->Info.Width, request->Info.Height); av_log(avctx, AV_LOG_INFO, "VAAPI: request->Type=%x\n",request->Type); @@ -720,7 +743,7 @@ static int qsv_check_filters(const OutputStream *ost) AVFilterInOut *inputs, *outputs; int ret = 0; int i; -const char *filter_list = "buffer|buffersink|null|format|setpts"; +const char *filter_list = "buffer|buffersink|null|format|setpts|qsvvpp"; if (!ost->avfilter) return -1; @@ -820,6 +843,7 @@ int qsv_transcode_init_vidmem(OutputStream *ost) QSVContext *qsv = NULL; AVQSVContext *enc_hwctx = NULL; +AVQSVContext *vpp_hwctx = NULL; /* check if the encoder supports QSV */ if (!ost->enc->pix_fmts) @@ -836,6 +860,8 @@ int qsv_transcode_init_vidmem(OutputStream *ost) /* check if the decoder supports QSV and the output only goes to this stream */ ist = input_streams[ost->source_index]; +if (ist->hwaccel_id == HWACCEL_NONE || ist->hwaccel_id == HWACCEL_AUTO) +ist->hwaccel_id = HWACCEL_QSV; if (ist->nb_filters || ist->hwaccel_id != HWACCEL_QSV || !ist->dec || !ist->dec->pix_fmts) return 0; @@ -854,7 +880,8 @@ int qsv_transcode_init_vidmem(OutputStream *ost) qsv = av_mallocz(sizeof(*qsv)); enc_hwctx = av_qsv_alloc_context(); -if (!qsv || !enc_hwctx) +vpp_hwctx = av_qsv_alloc_context(); +if (!qsv || !enc_hwctx || !vpp_hwctx) goto fail; err = ff_qsv_init_internal_session(NULL, &g_session); @@ -891,6 +918,11 @@ int qsv_transcode_init_vidmem(OutputStream *ost) ist->resample_pix_fmt= AV_PIX_FMT_QSV; ist->hwaccel_ctx = qsv; +vpp_hwctx->session = qsv->session; +vpp_hwctx->iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY; +vpp_hwctx->pFrameAllocator = &qsv->frame_allocator; +hw_device_ctx = av_buffer_create(vpp_hwctx, sizeof(*vpp_hwctx), av_buffer_default_free, NULL, 0); + return 0; fail: diff --git a/libavcodec/libavcodec.v b/libavcodec/libavcodec.v index 304c2ef
[FFmpeg-devel] [PATCH 4/6] lavf/vpp: enable video memory accel for transcoding with vpp. lavc/qsv: export symbols "ff_qsv_*" which will be used by vpp. ffmpeg_qsv: set default hwaccel to qsv.
From: ChaoX A Liu Signed-off-by: ChaoX A Liu --- ffmpeg_qsv.c| 46 --- libavcodec/libavcodec.v | 1 + libavcodec/qsv.h| 2 + libavfilter/vf_vpp.c| 153 4 files changed, 172 insertions(+), 30 deletions(-) diff --git a/ffmpeg_qsv.c b/ffmpeg_qsv.c index ec8a41b..70a3ecf 100644 --- a/ffmpeg_qsv.c +++ b/ffmpeg_qsv.c @@ -387,7 +387,7 @@ static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *request, mfxFra unsigned int va_fourcc = 0; mfxU32 fourcc = request->Info.FourCC; QSVContext *q = pthis; -AVQSVContext *qsv = q->ost->enc_ctx->hwaccel_context; +AVQSVContext *qsv = NULL; mfxU16 numAllocated = 0; bool bCreateSrfSucceeded = false; mfxU32 mfx_fourcc; @@ -395,17 +395,40 @@ static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *request, mfxFra int width32; int height32; void *avctx = NULL; +FilterGraph *fg = q->ost->filter->graph; -av_log(avctx, AV_LOG_INFO, "=vaapi alloc frame==\n"); if (!request || !response || !request->NumFrameSuggested) return MFX_ERR_MEMORY_ALLOC; memset(response, 0, sizeof(*response)); surface_num = request->NumFrameSuggested; -if ((request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) && -(request->Type & MFX_MEMTYPE_FROM_DECODE)) -surface_num += (qsv->nb_encoder_surfaces + qsv->nb_decoder_surfaces); +if (request->Type & MFX_MEMTYPE_FROM_DECODE) { +avctx = input_streams[q->ost->source_index]->dec_ctx; +if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) { +AVFilterContext *vpp = avfilter_graph_get_filter(fg->graph, "Parsed_vpp_0"); +qsv = input_streams[q->ost->source_index]->dec_ctx->hwaccel_context; +surface_num += qsv->nb_decoder_surfaces; +if (vpp) { +qsv = vpp->hw_device_ctx->data; +surface_num += qsv->nb_vpp_surfaces; +} else { +qsv = q->ost->enc_ctx->hwaccel_context; +surface_num += qsv->nb_encoder_surfaces; +} +} +} else if (request->Type & MFX_MEMTYPE_FROM_VPPOUT) { +AVFilterContext *vpp = avfilter_graph_get_filter(fg->graph, "Parsed_vpp_0"); +avctx = vpp; +if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) { +qsv = q->ost->enc_ctx->hwaccel_context; +surface_num += qsv->nb_encoder_surfaces; +} +} else if (request->Type & MFX_MEMTYPE_FROM_ENCODE) { +avctx = q->ost->enc_ctx; +} else +av_log(avctx, AV_LOG_WARNING, "FrameAlloc: may get a bug.\n"); +av_log(avctx, AV_LOG_INFO, "=vaapi alloc frame==\n"); av_log(avctx, AV_LOG_INFO, "VAAPI: va_dpy =%p, surface_num=%d, width=%d, height=%d\n", g_session.va_display, surface_num, request->Info.Width, request->Info.Height); av_log(avctx, AV_LOG_INFO, "VAAPI: request->Type=%x\n",request->Type); @@ -721,7 +744,7 @@ static int qsv_check_filters(const OutputStream *ost) AVFilterInOut *inputs, *outputs; int ret = 0; int i; -const char *filter_list = "buffer|buffersink|null|format|setpts"; +const char *filter_list = "buffer|buffersink|null|format|setpts|vpp"; if (!ost->avfilter) return -1; @@ -821,6 +844,7 @@ int qsv_transcode_init_vidmem(OutputStream *ost) QSVContext *qsv = NULL; AVQSVContext *enc_hwctx = NULL; +AVQSVContext *vpp_hwctx = NULL; /* check if the encoder supports QSV */ if (!ost->enc->pix_fmts) @@ -837,6 +861,8 @@ int qsv_transcode_init_vidmem(OutputStream *ost) /* check if the decoder supports QSV and the output only goes to this stream */ ist = input_streams[ost->source_index]; +if (ist->hwaccel_id == HWACCEL_NONE || ist->hwaccel_id == HWACCEL_AUTO) +ist->hwaccel_id = HWACCEL_QSV; if (ist->nb_filters || ist->hwaccel_id != HWACCEL_QSV || !ist->dec || !ist->dec->pix_fmts) return 0; @@ -855,7 +881,8 @@ int qsv_transcode_init_vidmem(OutputStream *ost) qsv = av_mallocz(sizeof(*qsv)); enc_hwctx = av_qsv_alloc_context(); -if (!qsv || !enc_hwctx) +vpp_hwctx = av_qsv_alloc_context(); +if (!qsv || !enc_hwctx || !vpp_hwctx) goto fail; err = ff_qsv_init_internal_session(NULL, &g_session); @@ -892,6 +919,11 @@ int qsv_transcode_init_vidmem(OutputStream *ost) ist->resample_pix_fmt= AV_PIX_FMT_QSV; ist->hwaccel_ctx = qsv; +vpp_hwctx->session = qsv->session; +vpp_hwctx->iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY; +vpp_hwctx->pFrameAllocator = &qsv->frame_allocator; +hw_device_ctx = av_buffer_create(vpp_hwctx, sizeof(*vpp_hwctx), av_buffer_default_free, NULL, 0); + return 0; fail: diff --git a/libavcodec/libavcodec.v b/libavcodec/libavcodec.v index 304c2ef..1a4cac8 100644 --- a/l