[vlc-devel] [PATCH 2/4] avcodec: va: get the output video format from the VA module

Steve Lhomme robux4 at ycbcr.xyz
Fri Oct 25 12:20:42 CEST 2019


Fill the proper i_width/i_height corresponding to the padded decoder surfaces.

We don't need to pass the lavc pixel format anymore
---
 modules/codec/avcodec/d3d11va.c    | 17 +++++++++--------
 modules/codec/avcodec/directx_va.c |  1 -
 modules/codec/avcodec/dxva2.c      | 17 +++++++++--------
 modules/codec/avcodec/va.c         |  9 +++++----
 modules/codec/avcodec/va.h         |  6 +++---
 modules/codec/avcodec/vaapi.c      |  6 +++---
 modules/codec/avcodec/video.c      |  3 ++-
 modules/hw/vdpau/avcodec.c         |  7 ++++---
 8 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 9c1d9418068..78bf372a0a6 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -61,8 +61,8 @@ struct d3d11va_pic_context
 
 #include "directx_va.h"
 
-static int Open(vlc_va_t *, AVCodecContext *, const AVPixFmtDescriptor *, enum PixelFormat,
-                const es_format_t *, vlc_decoder_device *, vlc_video_context **);
+static int Open(vlc_va_t *, AVCodecContext *, const AVPixFmtDescriptor *,
+                const es_format_t *, vlc_decoder_device *, video_format_t *, vlc_video_context **);
 
 vlc_module_begin()
     set_description(N_("Direct3D11 Video Acceleration"))
@@ -250,15 +250,15 @@ static void Close(vlc_va_t *va)
 static const struct vlc_va_operations ops = { Get, Close, };
 
 static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *desc,
-                enum PixelFormat pix_fmt,
                 const es_format_t *fmt_in, vlc_decoder_device *dec_device,
-                vlc_video_context **vtcx_out)
+                video_format_t *fmt_out, vlc_video_context **vtcx_out)
 {
     int err = VLC_EGENERIC;
 
     ctx->hwaccel_context = NULL;
 
-    if (pix_fmt != AV_PIX_FMT_D3D11VA_VLD)
+    if ( fmt_out->i_chroma != VLC_CODEC_D3D11_OPAQUE &&
+         fmt_out->i_chroma != VLC_CODEC_D3D11_OPAQUE_10B )
         return VLC_EGENERIC;
 
     d3d11_decoder_device_t *d3d11_device = GetD3D11OpaqueDevice( dec_device );
@@ -320,17 +320,17 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
         goto error;
     }
 
-    video_format_t fmt_out;
+    video_format_t final_fmt = *fmt_out;
     static const directx_sys_t dx_sys = { DxGetInputList, DxSetupOutput };
     sys->selected_decoder = directx_va_Setup(va, &dx_sys, ctx, desc, fmt_in, isXboxHardware(sys->d3d_dev.d3ddevice),
-                                             &fmt_out, &sys->hw.surface_count);
+                                             &final_fmt, &sys->hw.surface_count);
     if (sys->selected_decoder == NULL)
     {
         err = VLC_EGENERIC;
         goto error;
     }
 
-    err = va_pool_SetupDecoder(va, sys->va_pool, ctx, &fmt_out, sys->hw.surface_count);
+    err = va_pool_SetupDecoder(va, sys->va_pool, ctx, &final_fmt, sys->hw.surface_count);
     if (err != VLC_SUCCESS)
         goto error;
 
@@ -351,6 +351,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
     ID3D11DeviceContext_Release(priv->device);
 
     va->ops = &ops;
+    *fmt_out = final_fmt;
     *vtcx_out = sys->vctx;
     return VLC_SUCCESS;
 
diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index 61ad7f79868..d7a1e7edead 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -335,7 +335,6 @@ const directx_va_mode_t *directx_va_Setup(vlc_va_t *va, const directx_sys_t *dx_
                   surface_width, surface_height,
                   avctx->coded_width, avctx->coded_height);
 
-    *fmt_out = fmt->video;
     fmt_out->i_width  = surface_width;
     fmt_out->i_height = surface_height;
 
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index bb0b821e69c..47f5dc9243c 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -48,8 +48,8 @@ struct dxva2_pic_context
 
 #include "directx_va.h"
 
-static int Open(vlc_va_t *, AVCodecContext *, const AVPixFmtDescriptor *, enum PixelFormat,
-                const es_format_t *, vlc_decoder_device *, vlc_video_context **);
+static int Open(vlc_va_t *, AVCodecContext *, const AVPixFmtDescriptor *,
+                const es_format_t *, vlc_decoder_device *, video_format_t *, vlc_video_context **);
 
 vlc_module_begin()
     set_description(N_("DirectX Video Acceleration (DXVA) 2.0"))
@@ -248,13 +248,13 @@ static void Close(vlc_va_t *va)
 static const struct vlc_va_operations ops = { Get, Close, };
 
 static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *desc,
-                enum PixelFormat pix_fmt,
                 const es_format_t *fmt_in, vlc_decoder_device *dec_device,
-                vlc_video_context **vtcx_out)
+                video_format_t *fmt_out, vlc_video_context **vtcx_out)
 {
     int err = VLC_EGENERIC;
 
-    if (pix_fmt != AV_PIX_FMT_DXVA2_VLD)
+    if ( fmt_out->i_chroma != VLC_CODEC_D3D9_OPAQUE &&
+         fmt_out->i_chroma != VLC_CODEC_D3D9_OPAQUE_10B )
         return VLC_EGENERIC;
 
     d3d9_decoder_device_t *d3d9_decoder = GetD3D9OpaqueDevice( dec_device );
@@ -317,17 +317,17 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
         goto error;
     }
 
-    video_format_t fmt_out;
+    video_format_t final_fmt = *fmt_out;
     static const directx_sys_t dx_sys = { DxGetInputList, DxSetupOutput };
     sys->selected_decoder = directx_va_Setup(va, &dx_sys, ctx, desc, fmt_in, 0,
-                                             &fmt_out, &sys->hw.surface_count);
+                                             &final_fmt, &sys->hw.surface_count);
     if (sys->selected_decoder == NULL)
     {
         err = VLC_EGENERIC;
         goto error;
     }
 
-    err = va_pool_SetupDecoder(va, sys->va_pool, ctx, &fmt_out, sys->hw.surface_count);
+    err = va_pool_SetupDecoder(va, sys->va_pool, ctx, &final_fmt, sys->hw.surface_count);
     if (err != VLC_SUCCESS)
         goto error;
 
@@ -342,6 +342,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
     octx->format = sys->render;
 
     va->ops = &ops;
+    *fmt_out = final_fmt;
     *vtcx_out = sys->vctx;
     return VLC_SUCCESS;
 
diff --git a/modules/codec/avcodec/va.c b/modules/codec/avcodec/va.c
index e500544fe0b..c4768f24bd0 100644
--- a/modules/codec/avcodec/va.c
+++ b/modules/codec/avcodec/va.c
@@ -100,19 +100,19 @@ static int vlc_va_Start(void *func, bool forced, va_list ap)
     vlc_va_t *va = va_arg(ap, vlc_va_t *);
     AVCodecContext *ctx = va_arg(ap, AVCodecContext *);
     const AVPixFmtDescriptor *src_desc = va_arg(ap, const AVPixFmtDescriptor *);
-    enum PixelFormat pix_fmt = va_arg(ap, enum PixelFormat);
     const es_format_t *fmt_in = va_arg(ap, const es_format_t *);
     vlc_decoder_device *device = va_arg(ap, vlc_decoder_device *);
+    video_format_t *fmt_out = va_arg(ap, video_format_t *);
     vlc_video_context **vtcx_out = va_arg(ap, vlc_video_context **);
     vlc_va_open open = func;
 
     (void) forced;
-    return open(va, ctx, src_desc, pix_fmt, fmt_in, device, vtcx_out);
+    return open(va, ctx, src_desc, fmt_in, device, fmt_out, vtcx_out);
 }
 
 vlc_va_t *vlc_va_New(vlc_object_t *obj,
                      AVCodecContext *avctx, const AVPixFmtDescriptor *src_desc,
-                     enum PixelFormat pix_fmt, const es_format_t *fmt,
+                     const es_format_t *fmt_in, video_format_t *fmt_out,
                      vlc_decoder_device *device, vlc_video_context **vtcx_out)
 {
     struct vlc_va_t *va = vlc_object_create(obj, sizeof (*va));
@@ -121,7 +121,8 @@ vlc_va_t *vlc_va_New(vlc_object_t *obj,
 
 
     if (vlc_module_load(va, "hw decoder", NULL, true,
-                        vlc_va_Start, va, avctx, src_desc, pix_fmt, fmt, device, vtcx_out) == NULL)
+                        vlc_va_Start, va, avctx, src_desc, fmt_in, device,
+                        fmt_out, vtcx_out) == NULL)
     {
         vlc_object_delete(va);
         va = NULL;
diff --git a/modules/codec/avcodec/va.h b/modules/codec/avcodec/va.h
index b10cab7e0be..c03aecd38ba 100644
--- a/modules/codec/avcodec/va.h
+++ b/modules/codec/avcodec/va.h
@@ -44,8 +44,8 @@ struct vlc_va_t {
 };
 
 typedef int (*vlc_va_open)(vlc_va_t *, AVCodecContext *, const AVPixFmtDescriptor *,
-                           enum PixelFormat,
-                           const es_format_t *, vlc_decoder_device *, vlc_video_context **);
+                           const es_format_t *, vlc_decoder_device *,
+                           video_format_t *, vlc_video_context **);
 
 #define set_va_callback(activate, priority) \
     { \
@@ -71,7 +71,7 @@ vlc_fourcc_t vlc_va_GetChroma(enum PixelFormat hwfmt, enum PixelFormat swfmt);
  * @return a new VLC object on success, NULL on error.
  */
 vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *, const AVPixFmtDescriptor *,
-                     enum PixelFormat, const es_format_t *fmt,
+                     const es_format_t *fmt, video_format_t *,
                      vlc_decoder_device *device, vlc_video_context **vtcx_out);
 
 /**
diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c
index f058884ba60..daec9b4b4e7 100644
--- a/modules/codec/avcodec/vaapi.c
+++ b/modules/codec/avcodec/vaapi.c
@@ -236,12 +236,12 @@ static void VAAPISetupAVCodecContext(void *opaque, AVCodecContext *avctx)
 }
 
 static int Create(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *desc,
-                  enum PixelFormat pix_fmt,
                   const es_format_t *fmt_in, vlc_decoder_device *dec_device,
-                  vlc_video_context **vtcx_out)
+                  video_format_t *fmt_out, vlc_video_context **vtcx_out)
 {
     VLC_UNUSED(desc);
-    if (pix_fmt != AV_PIX_FMT_VAAPI_VLD || dec_device == NULL ||
+    if ( (fmt_out->i_chroma != VLC_CODEC_VAAPI_420 &&
+          fmt_out->i_chroma != VLC_CODEC_VAAPI_420_10BPP) || dec_device == NULL ||
         dec_device->type != VLC_DECODER_DEVICE_VAAPI)
         return VLC_EGENERIC;
 
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index a6aff927889..6856499e811 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -1748,8 +1748,9 @@ no_reuse:
         vlc_mutex_unlock(&p_sys->lock);
 
         vlc_video_context *vctx_out;
-        vlc_va_t *va = vlc_va_New(VLC_OBJECT(p_dec), p_context, src_desc, hwfmt,
+        vlc_va_t *va = vlc_va_New(VLC_OBJECT(p_dec), p_context, src_desc,
                                   &p_dec->fmt_in,
+                                  &p_dec->fmt_out.video,
                                   init_device, &vctx_out);
         if (init_device)
             vlc_decoder_device_Release(init_device);
diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
index dd4c754e3d1..a4f1cf96d31 100644
--- a/modules/hw/vdpau/avcodec.c
+++ b/modules/hw/vdpau/avcodec.c
@@ -157,11 +157,12 @@ const struct vlc_video_context_operations vdpau_vctx_ops = {
 };
 
 static int Open(vlc_va_t *va, AVCodecContext *avctx, const AVPixFmtDescriptor *desc,
-                enum PixelFormat pix_fmt,
                 const es_format_t *fmt_in, vlc_decoder_device *dec_device,
-                vlc_video_context **vtcx_out)
+                video_format_t *fmt_out, vlc_video_context **vtcx_out)
 {
-    if (pix_fmt != AV_PIX_FMT_VDPAU|| dec_device == NULL ||
+    if ( ( fmt_out->i_chroma != VLC_CODEC_VDPAU_VIDEO_420 &&
+           fmt_out->i_chroma != VLC_CODEC_VDPAU_VIDEO_422 &&
+           fmt_out->i_chroma != VLC_CODEC_VDPAU_VIDEO_444 ) ||
         GetVDPAUOpaqueDevice(dec_device) == NULL)
         return VLC_EGENERIC;
 
-- 
2.17.1



More information about the vlc-devel mailing list