Commit d64fe199 authored by Steve Lhomme's avatar Steve Lhomme Committed by Jean-Baptiste Kempf

dxva2: store the internal hardware buffer in a picture_t

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent ad0b948a
......@@ -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 );
......
......@@ -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;
......
......@@ -133,6 +133,9 @@ struct picture_sys_t
LPDIRECT3DSURFACE9 surface;
};
static picture_t *DxAllocPicture(vlc_va_t *, const video_format_t *, unsigned index);
/* */
static int D3dCreateDevice(vlc_va_t *);
static void D3dDestroyDevice(vlc_va_t *);
......@@ -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;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment