[vlc-commits] d3d9_fmt: do not use the custom VA_PICSYS anymore
Steve Lhomme
git at videolan.org
Tue Oct 8 15:06:50 CEST 2019
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Tue Oct 1 10:52:20 2019 +0200| [5a435545fd2a14d3ee1fc2dc13d3de651cb7049c] | committer: Steve Lhomme
d3d9_fmt: do not use the custom VA_PICSYS anymore
There is a common common picture context for all D3D9 opaque formats.
dxva2 adds extra data around the picture context to handle the va_surface
refcounting.
We don't use any directy casts from va_pic_context anymore.
Use common picture_context_t callbacks.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5a435545fd2a14d3ee1fc2dc13d3de651cb7049c
---
modules/codec/avcodec/dxva2.c | 49 +++++++++++++++++++---------------
modules/hw/d3d9/d3d9_filters.c | 7 ++---
modules/hw/d3d9/d3d9_instance.c | 5 +---
modules/hw/d3d9/dxa9.c | 34 +++++------------------
modules/hw/d3d9/dxva2_deinterlace.c | 34 +++++------------------
modules/video_chroma/d3d9_fmt.c | 27 +++++++++++++++++--
modules/video_chroma/d3d9_fmt.h | 14 ++++++++++
modules/video_output/win32/direct3d9.c | 17 +++++-------
8 files changed, 89 insertions(+), 98 deletions(-)
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 862f55329a..350e7f08a0 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -37,8 +37,14 @@
#include <libavcodec/dxva2.h>
#include "../../video_chroma/d3d9_fmt.h"
-typedef picture_sys_d3d9_t VA_PICSYS;
-#include "va_surface.h"
+struct dxva2_pic_context
+{
+ struct d3d9_pic_context ctx;
+ struct vlc_va_surface_t *va_surface;
+};
+
+#define DXVA2_PICCONTEXT_FROM_PICCTX(pic_ctx) \
+ container_of((pic_ctx), struct dxva2_pic_context, ctx.s)
#include "directx_va.h"
@@ -153,55 +159,56 @@ static void SetupAVCodecContext(vlc_va_sys_t *sys, unsigned surfaces)
sys->hw.workaround = sys->selected_decoder->workaround;
}
-static void d3d9_pic_context_destroy(struct picture_context_t *opaque)
+static void dxva2_pic_context_destroy(picture_context_t *opaque)
{
- struct va_pic_context *pic_ctx = (struct va_pic_context*)opaque;
+ struct dxva2_pic_context *pic_ctx = (struct dxva2_pic_context*)opaque;
if (pic_ctx->va_surface)
{
- ReleaseD3D9PictureSys(&pic_ctx->picsys);
+ ReleaseD3D9PictureSys(&pic_ctx->ctx.picsys);
va_surface_Release(pic_ctx->va_surface);
free(pic_ctx);
}
}
-static struct va_pic_context *CreatePicContext(IDirect3DSurface9 *, IDirectXVideoDecoder *);
+static struct dxva2_pic_context *CreatePicContext(IDirect3DSurface9 *, IDirectXVideoDecoder *);
-static struct picture_context_t *d3d9_pic_context_copy(struct picture_context_t *ctx)
+static picture_context_t *dxva2_pic_context_copy(picture_context_t *ctx)
{
- struct va_pic_context *src_ctx = (struct va_pic_context*)ctx;
- struct va_pic_context *pic_ctx = CreatePicContext(src_ctx->picsys.surface, src_ctx->picsys.decoder);
+ struct dxva2_pic_context *src_ctx = (struct dxva2_pic_context*)ctx;
+ struct dxva2_pic_context *pic_ctx = CreatePicContext(src_ctx->ctx.picsys.surface, src_ctx->ctx.picsys.decoder);
if (unlikely(pic_ctx==NULL))
return NULL;
pic_ctx->va_surface = src_ctx->va_surface;
va_surface_AddRef(pic_ctx->va_surface);
- return &pic_ctx->s;
+ return &pic_ctx->ctx.s;
}
-static struct va_pic_context *CreatePicContext(IDirect3DSurface9 *surface, IDirectXVideoDecoder *decoder)
+static struct dxva2_pic_context *CreatePicContext(IDirect3DSurface9 *surface, IDirectXVideoDecoder *decoder)
{
- struct va_pic_context *pic_ctx = calloc(1, sizeof(*pic_ctx));
+ struct dxva2_pic_context *pic_ctx = calloc(1, sizeof(*pic_ctx));
if (unlikely(pic_ctx==NULL))
return NULL;
- pic_ctx->s.destroy = d3d9_pic_context_destroy;
- pic_ctx->s.copy = d3d9_pic_context_copy;
- pic_ctx->picsys.surface = surface;
- pic_ctx->picsys.decoder = decoder;
- AcquireD3D9PictureSys(&pic_ctx->picsys);
+ pic_ctx->ctx.s = (picture_context_t) {
+ dxva2_pic_context_destroy, dxva2_pic_context_copy,
+ };
+ pic_ctx->ctx.picsys.surface = surface;
+ pic_ctx->ctx.picsys.decoder = decoder;
+ AcquireD3D9PictureSys(&pic_ctx->ctx.picsys);
return pic_ctx;
}
static picture_context_t* NewSurfacePicContext(vlc_va_t *va, int surface_index, vlc_va_surface_t *va_surface)
{
vlc_va_sys_t *sys = va->sys;
- struct va_pic_context *pic_ctx = CreatePicContext(sys->hw_surface[surface_index], sys->hw.decoder);
+ struct dxva2_pic_context *pic_ctx = CreatePicContext(sys->hw_surface[surface_index], sys->hw.decoder);
if (unlikely(pic_ctx==NULL))
return NULL;
/* all the resources are acquired during surfaces init, and a second time in
* CreatePicContext(), undo one of them otherwise we need an extra release
* when the pool is emptied */
- ReleaseD3D9PictureSys(&pic_ctx->picsys);
+ ReleaseD3D9PictureSys(&pic_ctx->ctx.picsys);
pic_ctx->va_surface = va_surface;
- return &pic_ctx->s;
+ return &pic_ctx->ctx.s;
}
static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
@@ -223,7 +230,7 @@ static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
return VLC_ENOITEM;
pic->context = pic_ctx;
- *data = (uint8_t*)((struct va_pic_context*)pic->context)->picsys.surface;
+ *data = (uint8_t*)DXVA2_PICCONTEXT_FROM_PICCTX(pic->context)->ctx.picsys.surface;
return VLC_SUCCESS;
}
diff --git a/modules/hw/d3d9/d3d9_filters.c b/modules/hw/d3d9/d3d9_filters.c
index f7361b9118..5261eec035 100644
--- a/modules/hw/d3d9/d3d9_filters.c
+++ b/modules/hw/d3d9/d3d9_filters.c
@@ -40,9 +40,6 @@
#include <dxva2api.h>
#include "../../video_chroma/d3d9_fmt.h"
-typedef picture_sys_d3d9_t VA_PICSYS;
-#include "../../codec/avcodec/va_surface.h"
-
#include "d3d9_filters.h"
struct filter_level
@@ -93,7 +90,7 @@ static void FillSample( DXVA2_VideoSample *p_sample,
picture_t *p_pic,
const RECT *p_area )
{
- picture_sys_d3d9_t *p_sys_src = ActivePictureSys(p_pic);
+ picture_sys_d3d9_t *p_sys_src = ActiveD3D9PictureSys(p_pic);
p_sample->SrcSurface = p_sys_src->surface;
p_sample->SampleFormat.SampleFormat = DXVA2_SampleProgressiveFrame;
@@ -108,7 +105,7 @@ static picture_t *Filter(filter_t *p_filter, picture_t *p_pic)
{
filter_sys_t *p_sys = p_filter->p_sys;
- picture_sys_d3d9_t *p_src_sys = ActivePictureSys(p_pic);
+ picture_sys_d3d9_t *p_src_sys = ActiveD3D9PictureSys(p_pic);
picture_t *p_outpic = filter_NewPicture( p_filter );
if( !p_outpic )
diff --git a/modules/hw/d3d9/d3d9_instance.c b/modules/hw/d3d9/d3d9_instance.c
index 1a83637ffb..c61139641c 100644
--- a/modules/hw/d3d9/d3d9_instance.c
+++ b/modules/hw/d3d9/d3d9_instance.c
@@ -34,9 +34,6 @@
#include "d3d9_filters.h"
-typedef picture_sys_d3d9_t VA_PICSYS;
-#include "../../codec/avcodec/va_surface.h"
-
static vlc_mutex_t inst_lock = VLC_STATIC_MUTEX;
static d3d9_device_t device = { .dev = NULL };
static size_t instances = 0;
@@ -49,7 +46,7 @@ void D3D9_FilterHoldInstance(filter_t *filter, d3d9_device_t *out, D3DSURFACE_DE
if (!pic)
return;
- picture_sys_d3d9_t *p_sys = ActivePictureSys(pic);
+ picture_sys_d3d9_t *p_sys = ActiveD3D9PictureSys(pic);
vlc_mutex_lock(&inst_lock);
if (p_sys)
diff --git a/modules/hw/d3d9/dxa9.c b/modules/hw/d3d9/dxa9.c
index d1a34645e2..0f5700b9e8 100644
--- a/modules/hw/d3d9/dxa9.c
+++ b/modules/hw/d3d9/dxa9.c
@@ -41,9 +41,6 @@
#include <d3d9.h>
#include "../../video_chroma/d3d9_fmt.h"
-typedef picture_sys_d3d9_t VA_PICSYS;
-#include "../../codec/avcodec/va_surface.h"
-
typedef struct
{
/* GPU to CPU */
@@ -74,7 +71,7 @@ static bool GetLock(filter_t *p_filter, IDirect3DSurface9 *d3d,
static void DXA9_YV12(filter_t *p_filter, picture_t *src, picture_t *dst)
{
copy_cache_t *p_copy_cache = (copy_cache_t*) p_filter->p_sys;
- picture_sys_d3d9_t *p_sys = &((struct va_pic_context *)src->context)->picsys;
+ picture_sys_d3d9_t *p_sys = ActiveD3D9PictureSys(src);
D3DSURFACE_DESC desc;
D3DLOCKED_RECT lock;
@@ -144,7 +141,7 @@ static void DXA9_YV12(filter_t *p_filter, picture_t *src, picture_t *dst)
static void DXA9_NV12(filter_t *p_filter, picture_t *src, picture_t *dst)
{
copy_cache_t *p_copy_cache = (copy_cache_t*) p_filter->p_sys;
- picture_sys_d3d9_t *p_sys = &((struct va_pic_context *)src->context)->picsys;
+ picture_sys_d3d9_t *p_sys = ActiveD3D9PictureSys(src);
D3DSURFACE_DESC desc;
D3DLOCKED_RECT lock;
@@ -231,26 +228,6 @@ struct d3d_pic_context
picture_context_t s;
};
-static void d3d9_pic_context_destroy(struct picture_context_t *ctx)
-{
- struct va_pic_context *pic_ctx = (struct va_pic_context*)ctx;
- ReleaseD3D9PictureSys(&pic_ctx->picsys);
- free(pic_ctx);
-}
-
-static struct picture_context_t *d3d9_pic_context_copy(struct picture_context_t *ctx)
-{
- struct va_pic_context *src_ctx = (struct va_pic_context*)ctx;
- struct va_pic_context *pic_ctx = calloc(1, sizeof(*pic_ctx));
- if (unlikely(pic_ctx==NULL))
- return NULL;
- pic_ctx->s.destroy = d3d9_pic_context_destroy;
- pic_ctx->s.copy = d3d9_pic_context_copy;
- pic_ctx->picsys = src_ctx->picsys;
- AcquireD3D9PictureSys(&pic_ctx->picsys);
- return &pic_ctx->s;
-}
-
static void YV12_D3D9(filter_t *p_filter, picture_t *src, picture_t *dst)
{
filter_sys_t *sys = p_filter->p_sys;
@@ -283,11 +260,12 @@ static void YV12_D3D9(filter_t *p_filter, picture_t *src, picture_t *dst)
if (dst->context == NULL)
{
- struct va_pic_context *pic_ctx = calloc(1, sizeof(*pic_ctx));
+ struct d3d9_pic_context *pic_ctx = calloc(1, sizeof(*pic_ctx));
if (likely(pic_ctx))
{
- pic_ctx->s.destroy = d3d9_pic_context_destroy;
- pic_ctx->s.copy = d3d9_pic_context_copy;
+ pic_ctx->s = (picture_context_t) {
+ d3d9_pic_context_destroy, d3d9_pic_context_copy,
+ };
pic_ctx->picsys = *p_sys;
AcquireD3D9PictureSys(&pic_ctx->picsys);
dst->context = &pic_ctx->s;
diff --git a/modules/hw/d3d9/dxva2_deinterlace.c b/modules/hw/d3d9/dxva2_deinterlace.c
index ac8e3822d7..7c6bdd0721 100644
--- a/modules/hw/d3d9/dxva2_deinterlace.c
+++ b/modules/hw/d3d9/dxva2_deinterlace.c
@@ -40,9 +40,6 @@
#include "d3d9_filters.h"
-typedef picture_sys_d3d9_t VA_PICSYS;
-#include "../../codec/avcodec/va_surface.h"
-
typedef struct
{
HINSTANCE hdecoder_dll;
@@ -145,7 +142,7 @@ static void FillSample( DXVA2_VideoSample *p_sample,
const RECT *p_area,
int i_field )
{
- picture_sys_d3d9_t *p_sys_src = ActivePictureSys(p_pic);
+ picture_sys_d3d9_t *p_sys_src = ActiveD3D9PictureSys(p_pic);
p_sample->SrcSurface = p_sys_src->surface;
p_sample->SampleFormat.SampleFormat = p_pic->b_top_field_first ?
@@ -203,7 +200,7 @@ static int RenderPic( filter_t *filter, picture_t *p_outpic, picture_t *src,
picture_t *p_cur = sys->context.pp_history[1];
picture_t *p_next = sys->context.pp_history[2];
- picture_sys_d3d9_t *p_sys_src = ActivePictureSys(src);
+ picture_sys_d3d9_t *p_sys_src = ActiveD3D9PictureSys(src);
hr = IDirect3DSurface9_GetDesc( p_sys_src->surface, &srcDesc );
if (unlikely(FAILED(hr)))
@@ -286,26 +283,6 @@ static const struct filter_mode_t *GetFilterMode(const char *mode)
return NULL;
}
-static void d3d9_pic_context_destroy(struct picture_context_t *ctx)
-{
- struct va_pic_context *pic_ctx = (struct va_pic_context*)ctx;
- ReleaseD3D9PictureSys(&pic_ctx->picsys);
- free(pic_ctx);
-}
-
-static struct picture_context_t *d3d9_pic_context_copy(struct picture_context_t *ctx)
-{
- struct va_pic_context *src_ctx = (struct va_pic_context*)ctx;
- struct va_pic_context *pic_ctx = calloc(1, sizeof(*pic_ctx));
- if (unlikely(pic_ctx==NULL))
- return NULL;
- pic_ctx->s.destroy = d3d9_pic_context_destroy;
- pic_ctx->s.copy = d3d9_pic_context_copy;
- pic_ctx->picsys = src_ctx->picsys;
- AcquireD3D9PictureSys(&pic_ctx->picsys);
- return &pic_ctx->s;
-}
-
picture_t *AllocPicture( filter_t *p_filter )
{
filter_sys_t *p_sys = p_filter->p_sys;
@@ -344,11 +321,12 @@ picture_t *AllocPicture( filter_t *p_filter )
b_local_texture = true;
}
/* the picture might be duplicated for snapshots so it needs a context */
- struct va_pic_context *pic_ctx = calloc(1, sizeof(*pic_ctx));
+ struct d3d9_pic_context *pic_ctx = calloc(1, sizeof(*pic_ctx));
if (likely(pic_ctx!=NULL))
{
- pic_ctx->s.destroy = d3d9_pic_context_destroy;
- pic_ctx->s.copy = d3d9_pic_context_copy;
+ pic_ctx->s = (picture_context_t) {
+ d3d9_pic_context_destroy, d3d9_pic_context_copy,
+ };
pic_ctx->picsys = *pic_sys;
AcquireD3D9PictureSys( &pic_ctx->picsys );
pic->context = &pic_ctx->s;
diff --git a/modules/video_chroma/d3d9_fmt.c b/modules/video_chroma/d3d9_fmt.c
index 566140a971..ca96fa1e5b 100644
--- a/modules/video_chroma/d3d9_fmt.c
+++ b/modules/video_chroma/d3d9_fmt.c
@@ -28,8 +28,14 @@
#include <initguid.h>
#include "d3d9_fmt.h"
-typedef picture_sys_d3d9_t VA_PICSYS;
-#include "../codec/avcodec/va_surface.h"
+picture_sys_d3d9_t *ActiveD3D9PictureSys(picture_t *pic)
+{
+ if (unlikely(pic->context == NULL))
+ return pic->p_sys;
+
+ struct d3d9_pic_context *pic_ctx = D3D9_PICCONTEXT_FROM_PICCTX(pic->context);
+ return &pic_ctx->picsys;
+}
#undef D3D9_CreateDevice
HRESULT D3D9_CreateDevice(vlc_object_t *o, d3d9_handle_t *hd3d, int AdapterToUse,
@@ -276,3 +282,20 @@ void D3D9_CloneExternal(d3d9_handle_t *hd3d, IDirect3D9 *dev)
if (hd3d->use_ex && pv)
IDirect3D9Ex_Release((IDirect3D9Ex*) pv);
}
+
+void d3d9_pic_context_destroy(picture_context_t *ctx)
+{
+ struct d3d9_pic_context *pic_ctx = D3D9_PICCONTEXT_FROM_PICCTX(ctx);
+ ReleaseD3D9PictureSys(&pic_ctx->picsys);
+ free(pic_ctx);
+}
+
+picture_context_t *d3d9_pic_context_copy(picture_context_t *ctx)
+{
+ struct d3d9_pic_context *pic_ctx = calloc(1, sizeof(*pic_ctx));
+ if (unlikely(pic_ctx==NULL))
+ return NULL;
+ *pic_ctx = *D3D9_PICCONTEXT_FROM_PICCTX(ctx);
+ AcquireD3D9PictureSys(&pic_ctx->picsys);
+ return &pic_ctx->s;
+}
diff --git a/modules/video_chroma/d3d9_fmt.h b/modules/video_chroma/d3d9_fmt.h
index eef89fa3c4..f06c47b370 100644
--- a/modules/video_chroma/d3d9_fmt.h
+++ b/modules/video_chroma/d3d9_fmt.h
@@ -41,6 +41,12 @@ typedef struct
HINSTANCE dxva2_dll;
} picture_sys_d3d9_t;
+struct d3d9_pic_context
+{
+ picture_context_t s;
+ picture_sys_d3d9_t picsys;
+};
+
typedef struct
{
HINSTANCE hdll; /* handle of the opened d3d9 dll */
@@ -85,6 +91,11 @@ static inline bool is_d3d9_opaque(vlc_fourcc_t chroma)
}
}
+#define D3D9_PICCONTEXT_FROM_PICCTX(pic_ctx) \
+ container_of((pic_ctx), struct d3d9_pic_context, s)
+
+picture_sys_d3d9_t *ActiveD3D9PictureSys(picture_t *);
+
static inline d3d9_decoder_device_t *GetD3D9OpaqueDevice(vlc_decoder_device *device)
{
if (device == NULL || device->type != VLC_DECODER_DEVICE_DXVA2)
@@ -138,4 +149,7 @@ void D3D9_Destroy(d3d9_handle_t *);
int D3D9_FillPresentationParameters(d3d9_handle_t *, const d3d9_device_t *, D3DPRESENT_PARAMETERS *);
+void d3d9_pic_context_destroy(picture_context_t *);
+picture_context_t *d3d9_pic_context_copy(picture_context_t *);
+
#endif /* VLC_VIDEOCHROMA_D3D9_FMT_H_ */
diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index 23d2c067bb..76be7ba2a1 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -56,9 +56,6 @@
#endif
#include "../../video_chroma/d3d9_fmt.h"
-typedef picture_sys_d3d9_t VA_PICSYS;
-#include "../../codec/avcodec/va_surface.h"
-
#include "common.h"
#include "builtin_shaders.h"
#include "../../video_chroma/copy.h"
@@ -1272,7 +1269,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture,
* wrapper, we can't */
IDirect3DSurface9 *surface;
- picture_sys_d3d9_t *p_sys = picture->p_sys;
+ picture_sys_d3d9_t *p_sys = ActiveD3D9PictureSys(picture);
surface = p_sys->surface;
if ( !is_d3d9_opaque(picture->format.i_chroma) )
{
@@ -1291,14 +1288,14 @@ static void Prepare(vout_display_t *vd, picture_t *picture,
}
else if (picture->context)
{
- const struct va_pic_context *pic_ctx = (struct va_pic_context*)picture->context;
- if (pic_ctx->picsys.surface != surface)
+ const picture_sys_d3d9_t *picsys = ActiveD3D9PictureSys(picture);
+ if (picsys->surface != surface)
{
D3DSURFACE_DESC srcDesc, dstDesc;
- IDirect3DSurface9_GetDesc(pic_ctx->picsys.surface, &srcDesc);
+ IDirect3DSurface9_GetDesc(picsys->surface, &srcDesc);
IDirect3DSurface9_GetDesc(surface, &dstDesc);
if ( srcDesc.Width == dstDesc.Width && srcDesc.Height == dstDesc.Height )
- surface = pic_ctx->picsys.surface;
+ surface = picsys->surface;
else
{
HRESULT hr;
@@ -1308,7 +1305,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture,
visibleSource.right = picture->format.i_visible_width;
visibleSource.bottom = picture->format.i_visible_height;
- hr = IDirect3DDevice9_StretchRect( p_d3d9_dev->dev, pic_ctx->picsys.surface, &visibleSource, surface, &visibleSource, D3DTEXF_NONE);
+ hr = IDirect3DDevice9_StretchRect( p_d3d9_dev->dev, picsys->surface, &visibleSource, surface, &visibleSource, D3DTEXF_NONE);
if (FAILED(hr)) {
msg_Err(vd, "Failed to copy the hw surface to the decoder surface (hr=0x%lX)", hr );
}
@@ -1782,7 +1779,7 @@ GLConvUpdate(const opengl_tex_converter_t *tc, GLuint *textures,
struct glpriv *priv = tc->priv;
HRESULT hr;
- picture_sys_d3d9_t *picsys = ActivePictureSys(pic);
+ picture_sys_d3d9_t *picsys = ActiveD3D9PictureSys(pic);
if (unlikely(!picsys || !priv->gl_render))
return VLC_EGENERIC;
More information about the vlc-commits
mailing list