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.
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
---
[v4]: add an assert check.
libavcodec/qsv.c | 31 ++--
libavcodec/qsv_internal.h | 7 +++--
libavcodec/qsvdec.c | 60 ---
libavcodec/qsvdec.h | 2 ++
libavcodec/qsvdec_h2645.c | 10 +++
libavcodec/qsvdec_other.c | 5
libavcodec/qsvenc.c | 8 --
7 files changed, 104 insertions(+), 19 deletions(-)
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 994c9ebcb0..75ecf85053 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -412,15 +412,21 @@ 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, , >session);
+#if QSV_VERSION_ATLEAST(1, 16)
+init_par.GPUCopy= gpu_copy;
+#endif
+init_par.Implementation = impl;
+init_par.Version= ver;
+ret = MFXInitEx(init_par, >session);
if (ret < 0)
return ff_qsv_print_error(avctx, ret,
"Error initializing an internal MFX
session");
@@ -712,7 +718,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 +729,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 +760,12 @@ int ff_qsv_init_session_device(AVCodecContext *avctx,
mfxSession *psession,
"from the session\n");
}
-err = MFXInit(impl, , );
+#if QSV_VERSION_ATLEAST(1, 16)
+init_par.GPUCopy= gpu_copy;
+#endif
+init_par.Implementation = impl;
+init_par.Version= ver;
+err = MFXInitEx(init_par, );
if (err != MFX_ERR_NONE)
return ff_qsv_print_error(avctx, err,
"Error initializing a child MFX session");
@@ -783,7 +796,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,
@@ -803,7 +816,7 @@ int ff_qsv_init_session_frames(AVCodecContext *avctx,
mfxSession *psession,
int ret;
ret = ff_qsv_init_session_device(avctx, ,
- frames_ctx->device_ref, load_plugins);
+ frames_ctx->device_ref, load_plugins,
gpu_copy);
if (ret < 0)
return ret;
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 8b44a9b6f4..37559270e5 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -127,16 +127,17 @@ enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type);
enum AVFieldOrder ff_qsv_map_picstruct(int mfx_pic_struct);
int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
- const char *load_plugins);
+ const char *load_plugins, int gpu_copy);
int