[vlc-devel] [PATCH 1/2] avcodec: pass whole AVCodecContext instead of hwaccel_context only

Rémi Denis-Courmont remi at remlab.net
Sat Oct 27 12:02:30 CEST 2012


In current versions of libavcodec, VDPAU does not use hwaccel_context,
but it does use draw_horiz_band. Now vlc_va_Setup() can access and
modify the entire AVCodecContext.

TBD: This patch makes the width and height parameters redundant.
They should probably be removed too.

TBD: If libavcodec VDPAU support were normalized, this patch might
become useless.
---
 modules/codec/avcodec/dxva2.c |    6 +++---
 modules/codec/avcodec/va.h    |    8 ++++----
 modules/codec/avcodec/vaapi.c |   11 ++++++-----
 modules/codec/avcodec/vda.c   |    8 ++++----
 modules/codec/avcodec/video.c |    7 +++----
 5 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 44d24d3..ad20798 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -317,7 +317,7 @@ static void DxCreateVideoConversion(vlc_va_dxva2_t *);
 static void DxDestroyVideoConversion(vlc_va_dxva2_t *);
 
 /* */
-static int Setup(vlc_va_t *external, void **hw, vlc_fourcc_t *chroma,
+static int Setup(vlc_va_t *external, AVCodecContext *ctx, vlc_fourcc_t *chroma,
                  int width, int height)
 {
     vlc_va_dxva2_t *va = vlc_va_dxva2_Get(external);
@@ -329,7 +329,7 @@ static int Setup(vlc_va_t *external, void **hw, vlc_fourcc_t *chroma,
     DxDestroyVideoConversion(va);
     DxDestroyVideoDecoder(va);
 
-    *hw = NULL;
+    ctx->hwaccel_context = NULL;
     *chroma = 0;
     if (width <= 0 || height <= 0)
         return VLC_EGENERIC;
@@ -355,7 +355,7 @@ static int Setup(vlc_va_t *external, void **hw, vlc_fourcc_t *chroma,
 
     /* */
 ok:
-    *hw = &va->hw;
+    ctx->hwaccel_context = &va->hw;
     const d3d_format_t *output = D3dFindFormat(va->output);
     *chroma = output->codec;
 
diff --git a/modules/codec/avcodec/va.h b/modules/codec/avcodec/va.h
index 970fe2e..e38371e 100644
--- a/modules/codec/avcodec/va.h
+++ b/modules/codec/avcodec/va.h
@@ -35,17 +35,17 @@ struct vlc_va_t {
     char *description;
     int pix_fmt;
 
-    int  (*setup)(vlc_va_t *, void **hw, vlc_fourcc_t *output,
+    int  (*setup)(vlc_va_t *, AVCodecContext *, vlc_fourcc_t *output,
                   int width, int height);
     int  (*get)(vlc_va_t *, AVFrame *frame);
     void (*release)(vlc_va_t *, AVFrame *frame);
     int  (*extract)(vlc_va_t *, picture_t *dst, AVFrame *src);
 };
 
-static inline int vlc_va_Setup(vlc_va_t *va, void **hw, vlc_fourcc_t *output,
-                                int width, int height)
+static inline int vlc_va_Setup(vlc_va_t *va, AVCodecContext *ctx,
+                               vlc_fourcc_t *chroma, int width, int height)
 {
-    return va->setup(va, hw, output, width, height);
+    return va->setup(va, ctx, chroma, width, height);
 }
 static inline int vlc_va_Get(vlc_va_t *va, AVFrame *frame)
 {
diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c
index 40d2cc1..a3e7e19 100644
--- a/modules/codec/avcodec/vaapi.c
+++ b/modules/codec/avcodec/vaapi.c
@@ -344,26 +344,27 @@ error:
     return VLC_EGENERIC;
 }
 
-static int Setup( vlc_va_t *p_external, void **pp_hw_ctx, vlc_fourcc_t *pi_chroma,
-                  int i_width, int i_height )
+static int Setup( vlc_va_t *p_external, AVCodecContext *p_ctx,
+                  vlc_fourcc_t *pi_chroma, int i_width, int i_height )
 {
     vlc_va_sys_t *p_va = p_external->sys;
 
     if( p_va->i_surface_width == i_width &&
         p_va->i_surface_height == i_height )
     {
-        *pp_hw_ctx = &p_va->hw_ctx;
+        p_ctx->hwaccel_context = &p_va->hw_ctx;
         *pi_chroma = p_va->i_surface_chroma;
         return VLC_SUCCESS;
     }
 
-    *pp_hw_ctx = NULL;
+    p_ctx->hwaccel_context = NULL;
     *pi_chroma = 0;
     if( p_va->i_surface_width || p_va->i_surface_height )
         DestroySurfaces( p_va );
 
     if( i_width > 0 && i_height > 0 )
-        return CreateSurfaces( p_va, pp_hw_ctx, pi_chroma, i_width, i_height );
+        return CreateSurfaces( p_va, &p_ctx->hwaccel_context, pi_chroma,
+                               i_width, i_height );
 
     return VLC_EGENERIC;
 }
diff --git a/modules/codec/avcodec/vda.c b/modules/codec/avcodec/vda.c
index 2bc4615..9e18978 100644
--- a/modules/codec/avcodec/vda.c
+++ b/modules/codec/avcodec/vda.c
@@ -135,8 +135,8 @@ static void vda_Copy422YpCbCr8( picture_t *p_pic,
     CVPixelBufferUnlockBaseAddress( buffer, 0 );
 }
 
-static int Setup( vlc_va_t *p_external, void **pp_hw_ctx, vlc_fourcc_t *pi_chroma,
-                  int i_width, int i_height )
+static int Setup( vlc_va_t *p_external, AVCodecContext *p_ctx,
+                  vlc_fourcc_t *pi_chroma, int i_width, int i_height )
 {
 
     vlc_va_vda_t *p_va = vlc_va_vda_Get( p_external );
@@ -145,7 +145,7 @@ static int Setup( vlc_va_t *p_external, void **pp_hw_ctx, vlc_fourcc_t *pi_chrom
         && p_va->hw_ctx.height == i_height
         && p_va->hw_ctx.decoder )
     {
-        *pp_hw_ctx = &p_va->hw_ctx;
+        p_ctx->hwaccel_context = &p_va->hw_ctx;
         *pi_chroma = p_va->i_chroma;
         return VLC_SUCCESS;
     }
@@ -179,7 +179,7 @@ static int Setup( vlc_va_t *p_external, void **pp_hw_ctx, vlc_fourcc_t *pi_chrom
 
 ok:
     /* Setup the libavcodec hardware context */
-    *pp_hw_ctx = &p_va->hw_ctx;
+    p_ctx->hwaccel_context = &p_va->hw_ctx;
     *pi_chroma = p_va->i_chroma;
 
     /* create the decoder */
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 355a71b..b07e236 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -952,9 +952,8 @@ static int ffmpeg_GetFrameBuf( struct AVCodecContext *p_context,
 
     if( p_sys->p_va )
     {
-        /* hwaccel_context is not present in old ffmpeg version */
-        if( vlc_va_Setup( p_sys->p_va,
-                          &p_context->hwaccel_context, &p_dec->fmt_out.video.i_chroma,
+        if( vlc_va_Setup( p_sys->p_va, p_context,
+                          &p_dec->fmt_out.video.i_chroma,
                           p_context->width, p_context->height ) )
         {
             msg_Err( p_dec, "vlc_va_Setup failed" );
@@ -1176,7 +1175,7 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
             /* We try to call vlc_va_Setup when possible to detect errors when
              * possible (later is too late) */
             if( p_context->width > 0 && p_context->height > 0
-             && vlc_va_Setup( p_va, &p_context->hwaccel_context,
+             && vlc_va_Setup( p_va, p_context,
                               &p_dec->fmt_out.video.i_chroma,
                               p_context->width, p_context->height ) )
             {
-- 
1.7.9.5




More information about the vlc-devel mailing list