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

Submitted by Mark Thompson on Jan. 17, 2017, 10:31 p.m.

Details

Message ID 765ae39b-d219-6f7a-68e5-43bd1de3e9e9@jkqxz.net
State New
Headers show

Commit Message

Mark Thompson Jan. 17, 2017, 10:31 p.m.
---
 libavcodec/qsvenc.c | 15 +++++++++++++++
 libavcodec/qsvenc.h |  2 ++
 2 files changed, 17 insertions(+)

Comments

wm4 Jan. 18, 2017, 7:58 a.m.
On Tue, 17 Jan 2017 22:31:10 +0000
Mark Thompson <sw@jkqxz.net> wrote:

> ---
>  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

Also seems fine.

Patch hide | download patch | download mbox

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