Re: [FFmpeg-devel] [PATCH, v2] lavc/qsvdec: Add GPU-accelerated memory copy support
> > > +static int ff_qsv_get_continuous_buffer(AVCodecContext *avctx, > > AVFrame > > > +*frame, AVBufferPool *pool) { > > > +int ret = 0; > > > + > > > +ff_decode_frame_props(avctx, frame); > > > + > > > +frame->width = avctx->width; > > > +frame->height = avctx->height; > > > +frame->linesize[0] = FFALIGN(avctx->width, 128); > > > +frame->linesize[1] = frame->linesize[0]; > > > +frame->buf[0] = av_buffer_pool_get(pool); > > > +if (!frame->buf[0]) > > > +return AVERROR(ENOMEM); > > > + > > > +frame->data[0] = frame->buf[0]->data; > > > +frame->data[1] = frame->data[0] + > > > +frame->linesize[0] * > > > + FFALIGN(avctx->height, 64); > > > + > > > +ret = ff_attach_decode_data(frame); > > > > Could you please explain why need this function? I don't see > > private_ref is needed from qsv decoding. > > private_ref is required if a decoder declares the capability of > AV_CODEC_CAP_DR1. > https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/decode.c#L654 > > - Linjie Ok, to keep consistency it is ok though get_buffer() is not called in the path of ff_qsv_get_continuous_buffer (). ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH, v2] lavc/qsvdec: Add GPU-accelerated memory copy support
> -Original Message- > From: Li, Zhong > Sent: Sunday, September 29, 2019 11:57 > To: FFmpeg development discussions and patches de...@ffmpeg.org> > Cc: ChaoX A Liu ; Fu, Linjie > Subject: RE: [FFmpeg-devel] [PATCH, v2] lavc/qsvdec: Add GPU-accelerated > memory copy support > > > From: ffmpeg-devel On Behalf Of > Linjie Fu > > Sent: Friday, September 27, 2019 1:47 PM > > To: ffmpeg-devel@ffmpeg.org > > Cc: ChaoX A Liu ; Fu, Linjie > > Subject: [FFmpeg-devel] [PATCH, v2] lavc/qsvdec: Add GPU-accelerated > memory > > copy support > > > > GPU copy enables or disables GPU accelerated copying between video and > > system memory. This may lead to a notable performance improvement. > > Memory must be sequent and aligned with 128x64. > > (first introduced in FFmpeg 3.3.1) > > This line should be removed. FFmpeg 3.3.1 mainline never support GPU copy. > Double confirmed and removed. > > > > CMD: > > ffmpeg -init_hw_device qsv=hw -filter_hw_device hw -c:v h264_qsv > > -gpu_copy on -i input.h264 -f null - > > or: > > ffmpeg -c:v h264_qsv -gpu_copy on -i input.h264 -f null - > > > > Signed-off-by: Linjie Fu > > Signed-off-by: ChaoX A Liu > > --- > > Rebased and send again. > > > > libavcodec/qsv.c | 31 +--- > > libavcodec/qsv_internal.h | 7 +++--- > > libavcodec/qsvdec.c | 50 ++-- > --- > > libavcodec/qsvdec.h | 2 ++ > > libavcodec/qsvdec_h2645.c | 10 libavcodec/qsvdec_other.c | 5 > > > libavcodec/qsvenc.c | 8 --- > > 7 files changed, 92 insertions(+), 21 deletions(-) > > > > diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c index > 994c9ebcb0..9e66fbc9da > > 100644 > > --- a/libavcodec/qsv.c > > +++ b/libavcodec/qsv.c > > @@ -412,15 +412,19 @@ static int > ff_qsv_set_display_handle(AVCodecContext > > *avctx, QSVSession *qs) #endif > //AVCODEC_QSV_LINUX_SESSION_HANDLE > > > > int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs, > > - const char *load_plugins) > > + const char *load_plugins, int > > + gpu_copy) > > { > > -mfxIMPL impl = MFX_IMPL_AUTO_ANY; > > -mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } }; > > +mfxIMPL impl = MFX_IMPL_AUTO_ANY; > > +mfxVersionver = { { QSV_VERSION_MINOR, > QSV_VERSION_MAJOR } }; > > +mfxInitParam init_par = { MFX_IMPL_AUTO_ANY }; > > > > const char *desc; > > int ret; > > > > -ret = MFXInit(impl, &ver, &qs->session); > > +init_par.GPUCopy= gpu_copy; > > GPUCopy field is introduced from API 1.16, would better to check it to avoid > compile issue with old API. > > @@ -802,8 +811,12 @@ int ff_qsv_init_session_frames(AVCodecContext > *avctx, > > mfxSession *psession, > > > > int ret; > > > > +if (gpu_copy == MFX_GPUCOPY_ON) > > +av_log(avctx, AV_LOG_WARNING, "GPU-accelerated memory copy " > > +"only works in > > + MFX_IOPATTERN_OUT_SYSTEM_MEMORY.\n"); > > This looks weird: > 1. the waring log will always turn on if gpu_copy is true no matter what > iopattern. > So would be better: > if (gpu_copy == MFX_GPUCOPY_ON && iopattern != system memory) > print a warning. > > 2. It is only added for ff_qsv_init_session_frames(), but looks like should be > apply for qsv_init_session() > Thanks, will update and resend the patch soon. > > > > +static int ff_qsv_get_continuous_buffer(AVCodecContext *avctx, > AVFrame > > +*frame, AVBufferPool *pool) { > > +int ret = 0; > > + > > +ff_decode_frame_props(avctx, frame); > > + > > +frame->width = avctx->width; > > +frame->height = avctx->height; > > +frame->linesize[0] = FFALIGN(avctx->width, 128); > > +frame->linesize[1] = frame->linesize[0]; > > +frame->buf[0] = av_buffer_pool_get(pool); > > +if (!frame->buf[0]) > > +return AVERROR(ENOMEM); > > + > > +frame->data[0] = frame->buf[0]->data; > > +frame->data[1] = frame->data[0] + > > +frame->linesize[0] * FFALIGN(avctx->height, > > + 64); > > + > > +ret = ff_attach_decode_data(frame); > > Could you please explain why need this function? I don't see private_ref is > needed from qsv decoding. private_ref is required if a decoder declares the capability of AV_CODEC_CAP_DR1. https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/decode.c#L654 - linjie ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH, v2] lavc/qsvdec: Add GPU-accelerated memory copy support
> From: ffmpeg-devel On Behalf Of Linjie Fu > Sent: Friday, September 27, 2019 1:47 PM > To: ffmpeg-devel@ffmpeg.org > Cc: ChaoX A Liu ; Fu, Linjie > Subject: [FFmpeg-devel] [PATCH, v2] lavc/qsvdec: Add GPU-accelerated memory > copy support > > GPU copy enables or disables GPU accelerated copying between video and > system memory. This may lead to a notable performance improvement. > Memory must be sequent and aligned with 128x64. > (first introduced in FFmpeg 3.3.1) This line should be removed. FFmpeg 3.3.1 mainline never support GPU copy. > > CMD: > ffmpeg -init_hw_device qsv=hw -filter_hw_device hw -c:v h264_qsv > -gpu_copy on -i input.h264 -f null - > or: > ffmpeg -c:v h264_qsv -gpu_copy on -i input.h264 -f null - > > Signed-off-by: Linjie Fu > Signed-off-by: ChaoX A Liu > --- > Rebased and send again. > > libavcodec/qsv.c | 31 +--- > libavcodec/qsv_internal.h | 7 +++--- > libavcodec/qsvdec.c | 50 ++- > libavcodec/qsvdec.h | 2 ++ > libavcodec/qsvdec_h2645.c | 10 libavcodec/qsvdec_other.c | 5 > libavcodec/qsvenc.c | 8 --- > 7 files changed, 92 insertions(+), 21 deletions(-) > > diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c index 994c9ebcb0..9e66fbc9da > 100644 > --- a/libavcodec/qsv.c > +++ b/libavcodec/qsv.c > @@ -412,15 +412,19 @@ static int ff_qsv_set_display_handle(AVCodecContext > *avctx, QSVSession *qs) #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE > > int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs, > - const char *load_plugins) > + const char *load_plugins, int > + gpu_copy) > { > -mfxIMPL impl = MFX_IMPL_AUTO_ANY; > -mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } }; > +mfxIMPL impl = MFX_IMPL_AUTO_ANY; > +mfxVersionver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } }; > +mfxInitParam init_par = { MFX_IMPL_AUTO_ANY }; > > const char *desc; > int ret; > > -ret = MFXInit(impl, &ver, &qs->session); > +init_par.GPUCopy= gpu_copy; GPUCopy field is introduced from API 1.16, would better to check it to avoid compile issue with old API. > +init_par.Implementation = impl; > +init_par.Version= ver; > +ret = MFXInitEx(init_par, &qs->session); > if (ret < 0) > return ff_qsv_print_error(avctx, ret, >"Error initializing an internal MFX > session"); @@ -712,7 > +716,8 @@ static mfxStatus qsv_frame_get_hdl(mfxHDL pthis, mfxMemId mid, > mfxHDL *hdl) } > > int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession, > - AVBufferRef *device_ref, const char > *load_plugins) > + AVBufferRef *device_ref, const char > *load_plugins, > + int gpu_copy) > { > static const mfxHandleType handle_types[] = { > MFX_HANDLE_VA_DISPLAY, > @@ -722,11 +727,12 @@ int ff_qsv_init_session_device(AVCodecContext > *avctx, mfxSession *psession, > AVHWDeviceContext*device_ctx = (AVHWDeviceContext*)device_ref- > >data; > AVQSVDeviceContext *device_hwctx = device_ctx->hwctx; > mfxSessionparent_session = device_hwctx->session; > +mfxInitParaminit_par = { MFX_IMPL_AUTO_ANY }; > +mfxHDLhandle = NULL; > > mfxSessionsession; > mfxVersionver; > mfxIMPL impl; > -mfxHDLhandle = NULL; > mfxHandleType handle_type; > mfxStatus err; > > @@ -752,7 +758,10 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, > mfxSession *psession, > "from the session\n"); > } > > -err = MFXInit(impl, &ver, &session); > +init_par.GPUCopy= gpu_copy; > +init_par.Implementation = impl; > +init_par.Version= ver; > +err = MFXInitEx(init_par, &session); > if (err != MFX_ERR_NONE) > return ff_qsv_print_error(avctx, err, >"Error initializing a child MFX session"); > @@ -783,7 +792,7 > @@ int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession > *psession, > > int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession, > QSVFramesContext *qsv_frames_ctx, > - const char *load_plugins, int opaque) > + const char *load_plugins, int opaque, > + int gpu_copy) > { > mfxFrameAllocator frame_allocator = { > .pthis = qsv_frames_ctx, > @@ -802,8 +811,12 @@ int ff_qsv_init_session_frames(AVCodecContext *avctx, > mfxSession *psession, > > int ret; > > +if (gpu_copy == MFX_GPUCOPY_ON) > +av_log(avctx, AV_LOG_WARNING, "GPU-accelerated memory copy " > +"only works in > + MFX_