[FFmpeg-cvslog] qsv: Add ability to create a session from a device
Mark Thompson
git at videolan.org
Thu Jun 15 00:39:25 EEST 2017
ffmpeg | branch: master | Mark Thompson <sw at jkqxz.net> | Sat Mar 4 23:57:35 2017 +0000| [91c3b50d74ba8874ea090c29063f953f4cc90ba9] | committer: Mark Thompson
qsv: Add ability to create a session from a device
(cherry picked from commit 4936a48b1e6fc2147599541f8b25f43a8a9d1f16)
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=91c3b50d74ba8874ea090c29063f953f4cc90ba9
---
libavcodec/qsv.c | 49 ++++++++++++++++++++++++++++++++---------------
libavcodec/qsv_internal.h | 9 ++++++---
libavcodec/qsvdec.c | 6 +++---
libavcodec/qsvenc.c | 6 +++---
4 files changed, 46 insertions(+), 24 deletions(-)
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 1284419741..b9e2cd990d 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -535,27 +535,16 @@ static mfxStatus qsv_frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
return MFX_ERR_NONE;
}
-int ff_qsv_init_session_hwcontext(AVCodecContext *avctx, mfxSession *psession,
- QSVFramesContext *qsv_frames_ctx,
- const char *load_plugins, int opaque)
+int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession,
+ AVBufferRef *device_ref, const char *load_plugins)
{
static const mfxHandleType handle_types[] = {
MFX_HANDLE_VA_DISPLAY,
MFX_HANDLE_D3D9_DEVICE_MANAGER,
MFX_HANDLE_D3D11_DEVICE,
};
- mfxFrameAllocator frame_allocator = {
- .pthis = qsv_frames_ctx,
- .Alloc = qsv_frame_alloc,
- .Lock = qsv_frame_lock,
- .Unlock = qsv_frame_unlock,
- .GetHDL = qsv_frame_get_hdl,
- .Free = qsv_frame_free,
- };
-
- AVHWFramesContext *frames_ctx = (AVHWFramesContext*)qsv_frames_ctx->hw_frames_ctx->data;
- AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
- AVQSVDeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
+ AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)device_ref->data;
+ AVQSVDeviceContext *device_hwctx = device_ctx->hwctx;
mfxSession parent_session = device_hwctx->session;
mfxSession session;
@@ -605,6 +594,36 @@ int ff_qsv_init_session_hwcontext(AVCodecContext *avctx, mfxSession *psession,
return ret;
}
+ *psession = session;
+ return 0;
+}
+
+int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession,
+ QSVFramesContext *qsv_frames_ctx,
+ const char *load_plugins, int opaque)
+{
+ mfxFrameAllocator frame_allocator = {
+ .pthis = qsv_frames_ctx,
+ .Alloc = qsv_frame_alloc,
+ .Lock = qsv_frame_lock,
+ .Unlock = qsv_frame_unlock,
+ .GetHDL = qsv_frame_get_hdl,
+ .Free = qsv_frame_free,
+ };
+
+ AVHWFramesContext *frames_ctx = (AVHWFramesContext*)qsv_frames_ctx->hw_frames_ctx->data;
+ AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
+
+ mfxSession session;
+ mfxStatus err;
+
+ int ret;
+
+ ret = ff_qsv_init_session_device(avctx, &session,
+ frames_ctx->device_ref, load_plugins);
+ if (ret < 0)
+ return ret;
+
if (!opaque) {
qsv_frames_ctx->logctx = avctx;
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 814db08e6c..c0305508dd 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -90,9 +90,12 @@ int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc);
int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session,
const char *load_plugins);
-int ff_qsv_init_session_hwcontext(AVCodecContext *avctx, mfxSession *session,
- QSVFramesContext *qsv_frames_ctx,
- const char *load_plugins, int opaque);
+int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession,
+ AVBufferRef *device_ref, const char *load_plugins);
+
+int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *session,
+ QSVFramesContext *qsv_frames_ctx,
+ const char *load_plugins, int opaque);
int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame);
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index d7664ce581..74866b57ff 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -59,9 +59,9 @@ static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession ses
if (!q->frames_ctx.hw_frames_ctx)
return AVERROR(ENOMEM);
- ret = ff_qsv_init_session_hwcontext(avctx, &q->internal_session,
- &q->frames_ctx, q->load_plugins,
- q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY);
+ ret = ff_qsv_init_session_frames(avctx, &q->internal_session,
+ &q->frames_ctx, q->load_plugins,
+ q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY);
if (ret < 0) {
av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
return ret;
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 57bc83a47f..64227cea6e 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -691,9 +691,9 @@ static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
if (!q->frames_ctx.hw_frames_ctx)
return AVERROR(ENOMEM);
- ret = ff_qsv_init_session_hwcontext(avctx, &q->internal_session,
- &q->frames_ctx, q->load_plugins,
- q->param.IOPattern == MFX_IOPATTERN_IN_OPAQUE_MEMORY);
+ ret = ff_qsv_init_session_frames(avctx, &q->internal_session,
+ &q->frames_ctx, q->load_plugins,
+ q->param.IOPattern == MFX_IOPATTERN_IN_OPAQUE_MEMORY);
if (ret < 0) {
av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
return ret;
More information about the ffmpeg-cvslog
mailing list