vlc | branch: master | Steve Lhomme <[email protected]> | Tue Jun 11 11:47:51 2019 +0200| [2545a0a3fd05bd32eb194d6be77b7cf5e9a69d26] | committer: Steve Lhomme
direct3d9: add a decoder device Works with internal and external rendering. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2545a0a3fd05bd32eb194d6be77b7cf5e9a69d26 --- modules/hw/d3d9/Makefile.am | 1 + modules/hw/d3d9/d3d9_device.c | 126 +++++++++++++++++++++++++++++++++++++++++ modules/hw/d3d9/d3d9_filters.c | 6 ++ modules/hw/d3d9/d3d9_filters.h | 3 + 4 files changed, 136 insertions(+) diff --git a/modules/hw/d3d9/Makefile.am b/modules/hw/d3d9/Makefile.am index 1711953e39..68f0084ab1 100644 --- a/modules/hw/d3d9/Makefile.am +++ b/modules/hw/d3d9/Makefile.am @@ -4,6 +4,7 @@ libdirect3d9_filters_plugin_la_SOURCES = hw/d3d9/d3d9_filters.h \ hw/d3d9/d3d9_filters.c \ hw/d3d9/dxva2_deinterlace.c \ hw/d3d9/dxa9.c \ + hw/d3d9/d3d9_device.c \ hw/d3d9/d3d9_instance.c libdirect3d9_filters_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(d3d9dir)' libdirect3d9_filters_plugin_la_LIBADD = libchroma_copy.la libdeinterlace_common.la libd3d9_common.la $(LIBCOM) diff --git a/modules/hw/d3d9/d3d9_device.c b/modules/hw/d3d9/d3d9_device.c new file mode 100644 index 0000000000..cd5a2770fa --- /dev/null +++ b/modules/hw/d3d9/d3d9_device.c @@ -0,0 +1,126 @@ +/***************************************************************************** + * d3d9_device.c : D3D9 decoder device from external IDirect3DDevice9 + ***************************************************************************** + * Copyright © 2019 VLC authors, VideoLAN and VideoLabs + * + * Authors: Steve Lhomme <[email protected]> + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +/***************************************************************************** + * Preamble + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <vlc_common.h> +#include <vlc_codec.h> + +#include <vlc/libvlc.h> +#include <vlc/libvlc_picture.h> +#include <vlc/libvlc_media.h> +#include <vlc/libvlc_renderer_discoverer.h> +#include <vlc/libvlc_media_player.h> + +#include "d3d9_filters.h" + +typedef struct { + void *opaque; + libvlc_video_direct3d_device_cleanup_cb cleanupDeviceCb; + + d3d9_handle_t hd3d; + d3d9_decoder_device_t dec_device; +} d3d9_decoder_device; + +static void D3D9CloseDecoderDevice(vlc_decoder_device *device) +{ + d3d9_decoder_device *sys = device->sys; + + D3D9_Destroy( &sys->hd3d ); + + if ( sys->cleanupDeviceCb ) + sys->cleanupDeviceCb( sys->opaque ); + vlc_obj_free( VLC_OBJECT(device), sys ); +} +static const struct vlc_decoder_device_operations d3d9_dev_ops = { + .close = D3D9CloseDecoderDevice, +}; + +int D3D9OpenDecoderDevice(vlc_decoder_device *device, vout_window_t *wnd) +{ + VLC_UNUSED(wnd); + d3d9_decoder_device *sys = vlc_obj_malloc(VLC_OBJECT(device), sizeof(*sys)); + if (unlikely(sys==NULL)) + return VLC_ENOMEM; + + sys->cleanupDeviceCb = NULL; + libvlc_video_direct3d_device_setup_cb setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" ); + if ( setupDeviceCb ) + { + /* external rendering */ + libvlc_video_direct3d_device_setup_t out = { .device_context = NULL, .adapter = 0 }; + sys->opaque = var_InheritAddress( device, "vout-cb-opaque" ); + sys->cleanupDeviceCb = var_InheritAddress( device, "vout-cb-cleanup" ); + libvlc_video_direct3d_device_cfg_t cfg = { + .hardware_decoding = true, /* ignored anyway */ + }; + if (!setupDeviceCb( &sys->opaque, &cfg, &out )) + { + if ( sys->cleanupDeviceCb ) + sys->cleanupDeviceCb( sys->opaque ); + goto error; + } + + D3D9_CloneExternal( &sys->hd3d, (IDirect3D9*) out.device_context ); + sys->dec_device.adapter = out.adapter; + } + else + { + /* internal rendering */ + if (D3D9_Create(device, &sys->hd3d) != VLC_SUCCESS) + { + msg_Err( device, "Direct3D9 could not be initialized" ); + goto error; + } + + d3d9_device_t tmp_d3ddev; + /* find the best adapter to use, not based on the HWND used */ + HRESULT hr = D3D9_CreateDevice( device, &sys->hd3d, -1, &tmp_d3ddev ); + if ( FAILED(hr) ) + { + D3D9_Destroy( &sys->hd3d ); + goto error; + } + + sys->dec_device.adapter = tmp_d3ddev.adapterId; + + D3D9_ReleaseDevice(&tmp_d3ddev); + } + + sys->dec_device.device = sys->hd3d.obj; + + device->ops = &d3d9_dev_ops; + device->opaque = &sys->dec_device; + device->type = VLC_DECODER_DEVICE_DXVA2; + device->sys = sys; + + return VLC_SUCCESS; +error: + vlc_obj_free( VLC_OBJECT(device), sys ); + return VLC_EGENERIC; +} diff --git a/modules/hw/d3d9/d3d9_filters.c b/modules/hw/d3d9/d3d9_filters.c index a995c61d14..f7361b9118 100644 --- a/modules/hw/d3d9/d3d9_filters.c +++ b/modules/hw/d3d9/d3d9_filters.c @@ -32,6 +32,7 @@ #include <vlc_plugin.h> #include <vlc_filter.h> #include <vlc_picture.h> +#include <vlc_codec.h> #define COBJMACROS #include <initguid.h> @@ -496,4 +497,9 @@ vlc_module_begin() add_submodule() set_callbacks( D3D9OpenCPUConverter, D3D9CloseCPUConverter ) set_capability( "video converter", 10 ) + + add_submodule() + set_description(N_("Direct3D9")) + set_callback_dec_device( D3D9OpenDecoderDevice, 10 ) + add_shortcut ("d3d9-device") vlc_module_end() diff --git a/modules/hw/d3d9/d3d9_filters.h b/modules/hw/d3d9/d3d9_filters.h index ee0878bf3e..c313429b9d 100644 --- a/modules/hw/d3d9/d3d9_filters.h +++ b/modules/hw/d3d9/d3d9_filters.h @@ -24,6 +24,7 @@ #define VLC_D3D9_FILTERS_H #include <vlc_common.h> +#include <vlc_vout_display.h> #include "../../video_chroma/d3d9_fmt.h" @@ -34,6 +35,8 @@ void D3D9CloseConverter(vlc_object_t *); int D3D9OpenCPUConverter(vlc_object_t *); void D3D9CloseCPUConverter(vlc_object_t *); +int D3D9OpenDecoderDevice(vlc_decoder_device *, vout_window_t *); + void D3D9_FilterHoldInstance(filter_t *, d3d9_device_t *, D3DSURFACE_DESC *); void D3D9_FilterReleaseInstance(d3d9_device_t *); _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
