From 39b64fb176bf90d7146cf7f20c61ab3e7def4191 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 17 May 2016 11:05:51 +0200 Subject: video: merge dxva2 source files video/dxva2.c exported only 2 functions, both used only by video/decode/dxva2.c. The same was already done for d3d11. --- video/decode/dxva2.c | 64 ++++++++++++++++++++++++++++++++++++-- video/dxva2.c | 87 ---------------------------------------------------- video/dxva2.h | 32 ------------------- wscript_build.py | 1 - 4 files changed, 62 insertions(+), 122 deletions(-) delete mode 100644 video/dxva2.c delete mode 100644 video/dxva2.h diff --git a/video/decode/dxva2.c b/video/decode/dxva2.c index fe78a52e8c..829d77ccbf 100644 --- a/video/decode/dxva2.c +++ b/video/decode/dxva2.c @@ -32,7 +32,6 @@ #include "video/mp_image_pool.h" #include "video/hwdec.h" -#include "video/dxva2.h" #include "d3d.h" #define ADDITIONAL_SURFACES (4 + HWDEC_DELAY_QUEUE_COUNT) @@ -53,6 +52,66 @@ struct priv { int mpfmt_decoded; }; +struct dxva2_surface { + HMODULE d3dlib; + HMODULE dxva2lib; + + IDirectXVideoDecoder *decoder; + IDirect3DSurface9 *surface; +}; + +static void dxva2_release_img(void *arg) +{ + struct dxva2_surface *surface = arg; + if (surface->surface) + IDirect3DSurface9_Release(surface->surface); + + if (surface->decoder) + IDirectXVideoDecoder_Release(surface->decoder); + + if (surface->dxva2lib) + FreeLibrary(surface->dxva2lib); + + if (surface->d3dlib) + FreeLibrary(surface->d3dlib); + + talloc_free(surface); +} + +static struct mp_image *dxva2_new_ref(IDirectXVideoDecoder *decoder, + IDirect3DSurface9 *d3d9_surface, + int w, int h) +{ + if (!decoder || !d3d9_surface) + return NULL; + struct dxva2_surface *surface = talloc_zero(NULL, struct dxva2_surface); + + // Add additional references to the libraries which might otherwise be freed + // before the surface, which is observed to lead to bad behaviour + surface->d3dlib = LoadLibrary(L"d3d9.dll"); + surface->dxva2lib = LoadLibrary(L"dxva2.dll"); + if (!surface->d3dlib || !surface->dxva2lib) + goto fail; + + surface->surface = d3d9_surface; + IDirect3DSurface9_AddRef(surface->surface); + surface->decoder = decoder; + IDirectXVideoDecoder_AddRef(surface->decoder); + + struct mp_image *mpi = + mp_image_new_custom_ref(NULL, surface, dxva2_release_img); + if (!mpi) + abort(); + + mp_image_setfmt(mpi, IMGFMT_DXVA2); + mp_image_set_size(mpi, w, h); + mpi->planes[3] = (void *)surface->surface; + return mpi; +fail: + dxva2_release_img(surface); + return NULL; +} + static struct mp_image *dxva2_allocate_image(struct lavc_ctx *s, int w, int h) { struct priv *p = s->hwdec_priv; @@ -68,7 +127,8 @@ static struct mp_image *dxva2_retrieve_image(struct lavc_ctx *s, { HRESULT hr; struct priv *p = s->hwdec_priv; - IDirect3DSurface9 *surface = d3d9_surface_in_mp_image(img); + IDirect3DSurface9 *surface = img->imgfmt == IMGFMT_DXVA2 ? + (IDirect3DSurface9 *)img->planes[3] : NULL; if (!surface) { MP_ERR(p, "Failed to get Direct3D surface from mp_image\n"); diff --git a/video/dxva2.c b/video/dxva2.c deleted file mode 100644 index cad3c54f72..0000000000 --- a/video/dxva2.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with mpv. If not, see . - */ - -#include "common/av_common.h" -#include "dxva2.h" -#include "mp_image.h" -#include "img_format.h" -#include "mp_image_pool.h" - -struct dxva2_surface { - HMODULE d3dlib; - HMODULE dxva2lib; - - IDirectXVideoDecoder *decoder; - IDirect3DSurface9 *surface; -}; - -IDirect3DSurface9 *d3d9_surface_in_mp_image(struct mp_image *mpi) -{ - return mpi && mpi->imgfmt == IMGFMT_DXVA2 ? - (IDirect3DSurface9 *)mpi->planes[3] : NULL; -} - -static void dxva2_release_img(void *arg) -{ - struct dxva2_surface *surface = arg; - if (surface->surface) - IDirect3DSurface9_Release(surface->surface); - - if (surface->decoder) - IDirectXVideoDecoder_Release(surface->decoder); - - if (surface->dxva2lib) - FreeLibrary(surface->dxva2lib); - - if (surface->d3dlib) - FreeLibrary(surface->d3dlib); - - talloc_free(surface); -} - -struct mp_image *dxva2_new_ref(IDirectXVideoDecoder *decoder, - IDirect3DSurface9 *d3d9_surface, int w, int h) -{ - if (!decoder || !d3d9_surface) - return NULL; - struct dxva2_surface *surface = talloc_zero(NULL, struct dxva2_surface); - - // Add additional references to the libraries which might otherwise be freed - // before the surface, which is observed to lead to bad behaviour - surface->d3dlib = LoadLibrary(L"d3d9.dll"); - surface->dxva2lib = LoadLibrary(L"dxva2.dll"); - if (!surface->d3dlib || !surface->dxva2lib) - goto fail; - - surface->surface = d3d9_surface; - IDirect3DSurface9_AddRef(surface->surface); - surface->decoder = decoder; - IDirectXVideoDecoder_AddRef(surface->decoder); - - struct mp_image *mpi = - mp_image_new_custom_ref(NULL, surface, dxva2_release_img); - if (!mpi) - abort(); - - mp_image_setfmt(mpi, IMGFMT_DXVA2); - mp_image_set_size(mpi, w, h); - mpi->planes[3] = (void *)surface->surface; - return mpi; -fail: - dxva2_release_img(surface); - return NULL; -} diff --git a/video/dxva2.h b/video/dxva2.h deleted file mode 100644 index 1f2e4a4071..0000000000 --- a/video/dxva2.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with mpv. If not, see . - */ - -#ifndef MPV_DXVA2_H -#define MPV_DXVA2_H - -#include -#include - -struct mp_image; -struct mp_image_pool; - -IDirect3DSurface9 *d3d9_surface_in_mp_image(struct mp_image *mpi); - -struct mp_image *dxva2_new_ref(IDirectXVideoDecoder *decoder, - IDirect3DSurface9 *d3d9_surface, int w, int h); - -#endif diff --git a/wscript_build.py b/wscript_build.py index 22ec75ce19..61830b5dff 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -286,7 +286,6 @@ def build(ctx): ( "video/mp_image.c" ), ( "video/mp_image_pool.c" ), ( "video/sws_utils.c" ), - ( "video/dxva2.c", "d3d-hwaccel" ), ( "video/vaapi.c", "vaapi" ), ( "video/vdpau.c", "vdpau" ), ( "video/vdpau_mixer.c", "vdpau" ), -- cgit v1.2.3