[FFmpeg-devel] [PATCH 4/6] qsvenc: Allow creation of the internal session from a device context

Mark Thompson sw at jkqxz.net
Wed Jan 18 00:31:10 EET 2017


---
 libavcodec/qsvenc.c | 15 +++++++++++++++
 libavcodec/qsvenc.h |  2 ++
 2 files changed, 17 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index ac443c1..7a46979 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -672,6 +672,19 @@ static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
         }
 
         q->session = q->internal_session;
+    } else if (avctx->hw_device_ctx) {
+        q->hw_device_ctx = av_buffer_ref(avctx->hw_device_ctx);
+        if (!q->hw_device_ctx)
+            return AVERROR(ENOMEM);
+
+        ret = ff_qsv_init_session_device(avctx, &q->internal_session,
+                                         q->hw_device_ctx, q->load_plugins);
+        if (ret < 0) {
+            av_buffer_unref(&q->hw_device_ctx);
+            return ret;
+        }
+
+        q->session = q->internal_session;
     } else {
         ret = ff_qsv_init_internal_session(avctx, &q->internal_session,
                                            q->load_plugins);
@@ -1121,5 +1134,7 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
 
     av_freep(&q->extparam);
 
+    av_buffer_unref(&q->hw_device_ctx);
+
     return 0;
 }
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 361d933..a2187ad 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -104,6 +104,8 @@ typedef struct QSVEncContext {
 
     AVFifoBuffer *async_fifo;
 
+    AVBufferRef *hw_device_ctx;
+
     QSVFramesContext frames_ctx;
 
     // options set by the caller
-- 
2.7.4


More information about the ffmpeg-devel mailing list