Skip to content

Commit

Permalink
directx_va: move the pre-allocated hw_surface in directx_va
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Baptiste Kempf <[email protected]>
  • Loading branch information
robUx4 authored and jbkempf committed Jun 22, 2017
1 parent 056eca0 commit 65b4993
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
22 changes: 12 additions & 10 deletions modules/codec/avcodec/d3d11va.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void SetupAVCodecContext(vlc_va_t *va)
sys->hw.decoder = dx_sys->decoder;
sys->hw.cfg = &sys->cfg;
sys->hw.surface_count = dx_sys->va_pool.surface_count;
sys->hw.surface = dx_sys->va_pool.hw_surface;
sys->hw.surface = dx_sys->hw_surface;
sys->hw.context_mutex = sys->context_mutex;

if (IsEqualGUID(&dx_sys->input, &DXVA_Intel_H264_NoFGT_ClearVideo))
Expand Down Expand Up @@ -239,8 +239,10 @@ static struct va_pic_context *CreatePicContext(
return pic_ctx;
}

static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, ID3D11VideoDecoderOutputView *surface)
static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, int surface_index)
{
directx_sys_t *dx_sys = &va->sys->dx_sys;
ID3D11VideoDecoderOutputView *surface = dx_sys->hw_surface[surface_index];
ID3D11ShaderResourceView *resourceView[D3D11_MAX_SHADER_VIEW];
ID3D11Resource *p_resource;
ID3D11VideoDecoderOutputView_GetResource(surface, &p_resource);
Expand Down Expand Up @@ -792,7 +794,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
for (surface_idx = 0; surface_idx < surface_count; surface_idx++) {
picture_t *pic = decoder_NewPicture( (decoder_t*) va->obj.parent );
sys->extern_pics[surface_idx] = pic;
dx_sys->va_pool.hw_surface[surface_idx] = NULL;
dx_sys->hw_surface[surface_idx] = NULL;
if (pic==NULL)
{
msg_Warn(va, "not enough decoder pictures %d out of %d", surface_idx, surface_count);
Expand Down Expand Up @@ -835,17 +837,17 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,

AllocateShaderView(VLC_OBJECT(va), dx_sys->d3ddev, textureFmt, pic->p_sys->texture, pic->p_sys->slice_index, pic->p_sys->resourceView);

dx_sys->va_pool.hw_surface[surface_idx] = pic->p_sys->decoder;
dx_sys->hw_surface[surface_idx] = pic->p_sys->decoder;
}

if (!sys->b_extern_pool)
{
for (size_t i = 0; i < surface_idx; ++i)
{
if (dx_sys->va_pool.hw_surface[i])
if (dx_sys->hw_surface[i])
{
ID3D11VideoDecoderOutputView_Release(dx_sys->va_pool.hw_surface[i]);
dx_sys->va_pool.hw_surface[i] = NULL;
ID3D11VideoDecoderOutputView_Release(dx_sys->hw_surface[i]);
dx_sys->hw_surface[i] = NULL;
}
if (sys->extern_pics[i])
{
Expand Down Expand Up @@ -893,7 +895,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
hr = ID3D11VideoDevice_CreateVideoDecoderOutputView( dx_sys->d3ddec,
(ID3D11Resource*) p_texture,
&viewDesc,
&dx_sys->va_pool.hw_surface[surface_idx] );
&dx_sys->hw_surface[surface_idx] );
if (FAILED(hr)) {
msg_Err(va, "CreateVideoDecoderOutputView %d failed. (hr=0x%0lx)", surface_idx, hr);
ID3D11Texture2D_Release(p_texture);
Expand Down Expand Up @@ -986,13 +988,13 @@ static void DxDestroySurfaces(vlc_va_t *va)
directx_sys_t *dx_sys = &va->sys->dx_sys;
if (dx_sys->va_pool.surface_count && !va->sys->b_extern_pool) {
ID3D11Resource *p_texture;
ID3D11VideoDecoderOutputView_GetResource( dx_sys->va_pool.hw_surface[0], &p_texture );
ID3D11VideoDecoderOutputView_GetResource( dx_sys->hw_surface[0], &p_texture );
ID3D11Resource_Release(p_texture);
ID3D11Resource_Release(p_texture);
}
for (unsigned i = 0; i < dx_sys->va_pool.surface_count; i++)
{
ID3D11VideoDecoderOutputView_Release( dx_sys->va_pool.hw_surface[i] );
ID3D11VideoDecoderOutputView_Release( dx_sys->hw_surface[i] );
for (int j = 0; j < D3D11_MAX_SHADER_VIEW; j++)
{
if (va->sys->resourceView[i*D3D11_MAX_SHADER_VIEW + j])
Expand Down
3 changes: 3 additions & 0 deletions modules/codec/avcodec/directx_va.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ typedef struct
{
va_pool_t va_pool;

/* for pre allocation */
D3D_DecoderSurface *hw_surface[MAX_SURFACE_COUNT];

/* DLL */
HINSTANCE hdecoder_dll;
const TCHAR *psz_decoder_dll;
Expand Down
18 changes: 9 additions & 9 deletions modules/codec/avcodec/dxva2.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void SetupAVCodecContext(vlc_va_t *va)
sys->hw.decoder = dx_sys->decoder;
sys->hw.cfg = &sys->cfg;
sys->hw.surface_count = dx_sys->va_pool.surface_count;
sys->hw.surface = dx_sys->va_pool.hw_surface;
sys->hw.surface = dx_sys->hw_surface;

if (IsEqualGUID(&dx_sys->input, &DXVA_Intel_H264_NoFGT_ClearVideo))
sys->hw.workaround |= FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO;
Expand Down Expand Up @@ -218,10 +218,10 @@ static struct va_pic_context *CreatePicContext(IDirect3DSurface9 *surface)
return pic_ctx;
}

static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, IDirect3DSurface9 *surface)
static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, int surface_index)
{
VLC_UNUSED(va);
return CreatePicContext(surface);
directx_sys_t *dx_sys = &va->sys->dx_sys;
return CreatePicContext(dx_sys->hw_surface[surface_index]);
}

static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
Expand Down Expand Up @@ -663,7 +663,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
D3DPOOL_DEFAULT,
0,
DXVA2_VideoDecoderRenderTarget,
sys->va_pool.hw_surface,
sys->hw_surface,
NULL);
if (FAILED(hr)) {
msg_Err(va, "IDirectXVideoAccelerationService_CreateSurface %d failed (hr=0x%0lx)", surface_count - 1, hr);
Expand All @@ -686,7 +686,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
if (FAILED(hr)) {
msg_Err(va, "extra buffer impossible, avoid a crash (hr=0x%0lx)", hr);
for (unsigned i = 0; i < surface_count; i++)
IDirect3DSurface9_Release( sys->va_pool.hw_surface[i] );
IDirect3DSurface9_Release( sys->hw_surface[i] );
return VLC_EGENERIC;
}
IDirect3DSurface9_Release(tstCrash);
Expand Down Expand Up @@ -729,7 +729,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
&cfg_list))) {
msg_Err(va, "IDirectXVideoDecoderService_GetDecoderConfigurations failed");
for (unsigned i = 0; i < surface_count; i++)
IDirect3DSurface9_Release( sys->va_pool.hw_surface[i] );
IDirect3DSurface9_Release( sys->hw_surface[i] );
return VLC_EGENERIC;
}
msg_Dbg(va, "we got %d decoder configurations", cfg_count);
Expand Down Expand Up @@ -771,12 +771,12 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
&sys->input,
&dsc,
&p_sys->cfg,
sys->va_pool.hw_surface,
sys->hw_surface,
surface_count,
&decoder))) {
msg_Err(va, "IDirectXVideoDecoderService_CreateVideoDecoder failed");
for (unsigned i = 0; i < surface_count; i++)
IDirect3DSurface9_Release( sys->va_pool.hw_surface[i] );
IDirect3DSurface9_Release( sys->hw_surface[i] );
return VLC_EGENERIC;
}
sys->decoder = decoder;
Expand Down
4 changes: 1 addition & 3 deletions modules/codec/avcodec/va_surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#include <vlc_codec.h>
#include <vlc_picture.h>


#define D3D_DecoderSurface void
struct picture_sys_t {
void *dummy;
};
Expand Down Expand Up @@ -98,7 +96,7 @@ int va_pool_Setup(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext *avctx,
struct vlc_va_surface_t *p_surface = malloc(sizeof(*p_surface));
if (unlikely(p_surface==NULL))
goto done;
va_pool->surface[i] = va_pool->pf_new_surface_context(va, va_pool->hw_surface[i]);
va_pool->surface[i] = va_pool->pf_new_surface_context(va, i);
if (unlikely(va_pool->surface[i]==NULL))
{
free(p_surface);
Expand Down
3 changes: 1 addition & 2 deletions modules/codec/avcodec/va_surface_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ typedef struct
int surface_height;

struct va_pic_context *surface[MAX_SURFACE_COUNT];
D3D_DecoderSurface *hw_surface[MAX_SURFACE_COUNT];

int (*pf_create_device)(vlc_va_t *);
void (*pf_destroy_device)(vlc_va_t *);
Expand Down Expand Up @@ -77,7 +76,7 @@ typedef struct
/**
* Create a new context for the surface being acquired
*/
struct va_pic_context* (*pf_new_surface_context)(vlc_va_t *, D3D_DecoderSurface *);
struct va_pic_context* (*pf_new_surface_context)(vlc_va_t *, int surface_index);

} va_pool_t;

Expand Down

0 comments on commit 65b4993

Please sign in to comment.