diff options
author | Kevin Mitchell <kevmitch@gmail.com> | 2016-02-15 11:15:17 -0800 |
---|---|---|
committer | Kevin Mitchell <kevmitch@gmail.com> | 2016-02-16 12:36:56 -0800 |
commit | d5348a66dc7dcc22d4e6b905caa7e92468f25b94 (patch) | |
tree | 6ef8beb28f367b8c6fa252966b02656d016a03b3 /video/dxva2.c | |
parent | 01743f4ecd42b2974072d31604c2e91941488dd8 (diff) | |
download | mpv-d5348a66dc7dcc22d4e6b905caa7e92468f25b94.tar.bz2 mpv-d5348a66dc7dcc22d4e6b905caa7e92468f25b94.tar.xz |
dxva2: another attempt at using mp_image pool
Apparently, some drivers require you to allocate all of the decoder d3d surfaces
at once. This commit changes the strategy from allocating surfaces as needed via
mp_image_pool_set_allocator, to allocating all the surfaces in one call to
IDirectXVideoDecoderService_CreateSurface and adding them to the pool with
mp_image_pool_add.
fixes #2822
Diffstat (limited to 'video/dxva2.c')
-rw-r--r-- | video/dxva2.c | 56 |
1 files changed, 10 insertions, 46 deletions
diff --git a/video/dxva2.c b/video/dxva2.c index ee8ff00431..8e31a45b57 100644 --- a/video/dxva2.c +++ b/video/dxva2.c @@ -37,17 +37,7 @@ LPDIRECT3DSURFACE9 d3d9_surface_in_mp_image(struct mp_image *mpi) (LPDIRECT3DSURFACE9)mpi->planes[3] : NULL; } -void dxva2_img_ref_decoder(struct mp_image *mpi, IDirectXVideoDecoder *decoder) -{ - assert(mpi->imgfmt == IMGFMT_DXVA2); - struct dxva2_surface *surface = (struct dxva2_surface *)mpi->planes[0]; - if (surface->decoder) - IDirectXVideoDecoder_Release(surface->decoder); - surface->decoder = decoder; - IDirectXVideoDecoder_AddRef(surface->decoder); -} - -static void dxva2_pool_release_img(void *arg) +static void dxva2_release_img(void *arg) { struct dxva2_surface *surface = arg; if (surface->surface) @@ -65,15 +55,10 @@ static void dxva2_pool_release_img(void *arg) talloc_free(surface); } -struct pool_alloc_ctx { - IDirectXVideoDecoderService *decoder_service; - D3DFORMAT target_format; - int surface_alignment; -}; - -static struct mp_image *dxva2_pool_alloc_img(void *arg, int fmt, int w, int h) +struct mp_image *dxva2_new_ref(IDirectXVideoDecoder *decoder, + LPDIRECT3DSURFACE9 d3d9_surface, int w, int h) { - if (fmt != IMGFMT_DXVA2) + if (!decoder || !d3d9_surface) return NULL; struct dxva2_surface *surface = talloc_zero(NULL, struct dxva2_surface); @@ -84,39 +69,18 @@ static struct mp_image *dxva2_pool_alloc_img(void *arg, int fmt, int w, int h) if (!surface->d3dlib || !surface->dxva2lib) goto fail; - struct pool_alloc_ctx *alloc_ctx = arg; - HRESULT hr = IDirectXVideoDecoderService_CreateSurface( - alloc_ctx->decoder_service, - FFALIGN(w, alloc_ctx->surface_alignment), - FFALIGN(h, alloc_ctx->surface_alignment), - 0, alloc_ctx->target_format, D3DPOOL_DEFAULT, 0, - DXVA2_VideoDecoderRenderTarget, - &surface->surface, NULL); - if (FAILED(hr)) - goto fail; + surface->surface = d3d9_surface; + IDirect3DSurface9_AddRef(surface->surface); + surface->decoder = decoder; + IDirectXVideoDecoder_AddRef(surface->decoder); struct mp_image mpi = {0}; mp_image_setfmt(&mpi, IMGFMT_DXVA2); mp_image_set_size(&mpi, w, h); - mpi.planes[0] = (void *)surface; mpi.planes[3] = (void *)surface->surface; - return mp_image_new_custom_ref(&mpi, surface, dxva2_pool_release_img); + return mp_image_new_custom_ref(&mpi, surface, dxva2_release_img); fail: - dxva2_pool_release_img(surface); + dxva2_release_img(surface); return NULL; } - -void dxva2_pool_set_allocator(struct mp_image_pool *pool, - IDirectXVideoDecoderService *decoder_service, - D3DFORMAT target_format, int surface_alignment) -{ - struct pool_alloc_ctx *alloc_ctx = talloc_ptrtype(pool, alloc_ctx); - *alloc_ctx = (struct pool_alloc_ctx){ - decoder_service = decoder_service, - target_format = target_format, - surface_alignment = surface_alignment - }; - mp_image_pool_set_allocator(pool, dxva2_pool_alloc_img, alloc_ctx); - mp_image_pool_set_lru(pool); -} |