[vlc-devel] [PATCH 1/3] dxva2: store the internal hardware buffer in a picture_t

Steve Lhomme robux4 at gmail.com
Tue Jun 2 16:08:53 CEST 2015


---
 modules/codec/avcodec/directx_va.c | 11 +++++++++--
 modules/codec/avcodec/directx_va.h |  7 +++++++
 modules/codec/avcodec/dxva2.c      | 24 ++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index fdc0092..c0b3c93 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -324,15 +324,18 @@ int directx_va_Setup(vlc_va_t *va, directx_sys_t *dx_sys, AVCodecContext *avctx,
                   dx_sys->surface_width, dx_sys->surface_height,
                   avctx->coded_width, avctx->coded_height);
 
+    dx_sys->pf_setup_avcodec_ctx(va);
+
     for (int i = 0; i < dx_sys->surface_count; i++) {
         vlc_va_surface_t *surface = &dx_sys->surface[i];
         surface->refcount = 0;
         surface->order = 0;
         surface->p_lock = &dx_sys->surface_lock;
+        surface->p_pic = dx_sys->pf_alloc_surface_pic(va, &fmt, i);
+        if (unlikely(surface->p_pic == NULL))
+            return VLC_EGENERIC;
     }
 
-    dx_sys->pf_setup_avcodec_ctx(va);
-
 ok:
     return VLC_SUCCESS;
 }
@@ -344,6 +347,10 @@ void DestroyVideoDecoder(vlc_va_t *va, directx_sys_t *dx_sys)
     for (int i = 0; i < dx_sys->surface_count; i++)
         IUnknown_Release( dx_sys->hw_surface[i] );
 
+    for (int i = 0; i < dx_sys->surface_count; i++)
+        if (dx_sys->surface[i].p_pic)
+            picture_Release(dx_sys->surface[i].p_pic);
+
     if (dx_sys->decoder)
         IUnknown_Release( dx_sys->decoder );
 
diff --git a/modules/codec/avcodec/directx_va.h b/modules/codec/avcodec/directx_va.h
index 8117e04..3377f85 100644
--- a/modules/codec/avcodec/directx_va.h
+++ b/modules/codec/avcodec/directx_va.h
@@ -46,6 +46,7 @@ typedef struct {
     int                refcount;
     unsigned int       order;
     vlc_mutex_t        *p_lock;
+    picture_t          *p_pic;
 } vlc_va_surface_t;
 
 typedef struct input_list_t {
@@ -124,6 +125,12 @@ typedef struct
      * Set the avcodec hw context after the decoder is created
      */
     void (*pf_setup_avcodec_ctx)(vlc_va_t *);
+    /**
+     * @brief pf_alloc_surface_pic
+     * @param fmt
+     * @return
+     */
+    picture_t *(*pf_alloc_surface_pic)(vlc_va_t *, const video_format_t *, unsigned);
 
 } directx_sys_t;
 
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 9b002c3..382b2b1 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -152,6 +152,9 @@ static void DxDestroyVideoDecoder(vlc_va_t *);
 static int DxResetVideoDecoder(vlc_va_t *);
 static void SetupAVCodecContext(vlc_va_t *);
 
+static picture_t *DxAllocPicture(vlc_va_t *, const video_format_t *, unsigned index);
+
+
 /* */
 static int Setup(vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *chroma)
 {
@@ -281,6 +284,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     dx_sys->pf_setup_avcodec_ctx       = SetupAVCodecContext;
     dx_sys->pf_get_input_list          = DxGetInputList;
     dx_sys->pf_setup_output            = DxSetupOutput;
+    dx_sys->pf_alloc_surface_pic       = DxAllocPicture;
     dx_sys->psz_decoder_dll            = TEXT("DXVA2.DLL");
 
     va->sys = sys;
@@ -713,3 +717,23 @@ static int DxResetVideoDecoder(vlc_va_t *va)
     return VLC_EGENERIC;
 }
 
+static picture_t *DxAllocPicture(vlc_va_t *va, const video_format_t *fmt, unsigned index)
+{
+    video_format_t src_fmt = *fmt;
+    src_fmt.i_chroma = VLC_CODEC_D3D9_OPAQUE;
+    picture_sys_t *pic_sys = calloc(1, sizeof(*pic_sys));
+    if (unlikely(pic_sys == NULL))
+        return NULL;
+    pic_sys->surface = (LPDIRECT3DSURFACE9) va->sys->dx_sys.hw_surface[index];
+
+    picture_resource_t res = {
+        .p_sys = pic_sys,
+    };
+    picture_t *pic = picture_NewFromResource(&src_fmt, &res);
+    if (unlikely(pic == NULL))
+    {
+        free(pic_sys);
+        return NULL;
+    }
+    return pic;
+}
-- 
2.4.0




More information about the vlc-devel mailing list