d3d11: Port to C++

Direct3D11 objects are COM, and most COM C APIs are verbose
(C++ is a little better). So, by using C++ APIs, we can make code
shorter and more readable.
Moreover, "ComPtr" helper class (which is C++ only) can be
utilized, that is very helpful for avoiding error-prone COM refcounting
issue/leak.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2077>
This commit is contained in:
Seungha Yang 2021-03-13 17:40:57 +09:00
parent 3c40ffc00f
commit 5b3e316039
33 changed files with 1064 additions and 1186 deletions

View file

@ -78,8 +78,8 @@ gst_d3d11_base_filter_class_init (GstD3D11BaseFilterClass * klass)
g_param_spec_int ("adapter", "Adapter", g_param_spec_int ("adapter", "Adapter",
"Adapter index for creating device (-1 for default)", "Adapter index for creating device (-1 for default)",
-1, G_MAXINT32, DEFAULT_ADAPTER, -1, G_MAXINT32, DEFAULT_ADAPTER,
G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY | (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS)));
element_class->set_context = element_class->set_context =
GST_DEBUG_FUNCPTR (gst_d3d11_base_filter_set_context); GST_DEBUG_FUNCPTR (gst_d3d11_base_filter_set_context);
@ -93,7 +93,8 @@ gst_d3d11_base_filter_class_init (GstD3D11BaseFilterClass * klass)
GST_DEBUG_FUNCPTR (gst_d3d11_base_filter_get_unit_size); GST_DEBUG_FUNCPTR (gst_d3d11_base_filter_get_unit_size);
trans_class->query = GST_DEBUG_FUNCPTR (gst_d3d11_base_filter_query); trans_class->query = GST_DEBUG_FUNCPTR (gst_d3d11_base_filter_query);
gst_type_mark_as_plugin_api (GST_TYPE_D3D11_BASE_FILTER, 0); gst_type_mark_as_plugin_api (GST_TYPE_D3D11_BASE_FILTER,
(GstPluginAPIFlags) 0);
} }
static void static void

View file

@ -1,65 +0,0 @@
/* GStreamer
* Copyright (C) <2019> Seungha Yang <seungha.yang@navercorp.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_D3D11_COLOR_CONVERTER_H__
#define __GST_D3D11_COLOR_CONVERTER_H__
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/d3d11/gstd3d11.h>
G_BEGIN_DECLS
typedef struct _GstD3D11ColorConverter GstD3D11ColorConverter;
GstD3D11ColorConverter * gst_d3d11_color_converter_new (GstD3D11Device * device,
GstVideoInfo * in_info,
GstVideoInfo * out_info);
GstD3D11ColorConverter * gst_d3d11_color_converter_new_with_alpha (GstD3D11Device * device,
GstVideoInfo * in_info,
GstVideoInfo * out_info,
gfloat alpha);
void gst_d3d11_color_converter_free (GstD3D11ColorConverter * converter);
gboolean gst_d3d11_color_converter_convert (GstD3D11ColorConverter * converter,
ID3D11ShaderResourceView *srv[GST_VIDEO_MAX_PLANES],
ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES],
ID3D11BlendState *blend,
gfloat blend_factor[4]);
gboolean gst_d3d11_color_converter_convert_unlocked (GstD3D11ColorConverter * converter,
ID3D11ShaderResourceView *srv[GST_VIDEO_MAX_PLANES],
ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES],
ID3D11BlendState *blend,
gfloat blend_factor[4]);
gboolean gst_d3d11_color_converter_update_viewport (GstD3D11ColorConverter * converter,
D3D11_VIEWPORT * viewport);
gboolean gst_d3d11_color_converter_update_src_rect (GstD3D11ColorConverter * converter,
RECT * src_rect);
gboolean gst_d3d11_color_converter_update_dest_rect (GstD3D11ColorConverter * converter,
RECT * dest_rect);
G_END_DECLS
#endif /* __GST_D3D11_COLOR_CONVERTER_H__ */

View file

@ -37,14 +37,23 @@
#endif #endif
#include "gstd3d11compositor.h" #include "gstd3d11compositor.h"
#include "gstd3d11colorconverter.h" #include "gstd3d11converter.h"
#include "gstd3d11shader.h" #include "gstd3d11shader.h"
#include "gstd3d11pluginutils.h" #include "gstd3d11pluginutils.h"
#include <string.h> #include <string.h>
#include <wrl.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_compositor_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_compositor_debug);
#define GST_CAT_DEFAULT gst_d3d11_compositor_debug #define GST_CAT_DEFAULT gst_d3d11_compositor_debug
G_END_DECLS
/* *INDENT-ON* */
/** /**
* GstD3D11CompositorBlendOperation: * GstD3D11CompositorBlendOperation:
* @GST_D3D11_COMPOSITOR_BLEND_OP_ADD: * @GST_D3D11_COMPOSITOR_BLEND_OP_ADD:
@ -389,7 +398,7 @@ struct _GstD3D11CompositorPad
{ {
GstVideoAggregatorConvertPad parent; GstVideoAggregatorConvertPad parent;
GstD3D11ColorConverter *convert; GstD3D11Converter *convert;
GstBufferPool *fallback_pool; GstBufferPool *fallback_pool;
GstBuffer *fallback_buf; GstBuffer *fallback_buf;
@ -490,39 +499,46 @@ gst_d3d11_compositor_pad_class_init (GstD3D11CompositorPadClass * klass)
g_object_class_install_property (gobject_class, PROP_PAD_XPOS, g_object_class_install_property (gobject_class, PROP_PAD_XPOS,
g_param_spec_int ("xpos", "X Position", "X position of the picture", g_param_spec_int ("xpos", "X Position", "X position of the picture",
G_MININT, G_MAXINT, DEFAULT_PAD_XPOS, G_MININT, G_MAXINT, DEFAULT_PAD_XPOS,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_PAD_YPOS, g_object_class_install_property (gobject_class, PROP_PAD_YPOS,
g_param_spec_int ("ypos", "Y Position", "Y position of the picture", g_param_spec_int ("ypos", "Y Position", "Y position of the picture",
G_MININT, G_MAXINT, DEFAULT_PAD_YPOS, G_MININT, G_MAXINT, DEFAULT_PAD_YPOS,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_PAD_WIDTH, g_object_class_install_property (gobject_class, PROP_PAD_WIDTH,
g_param_spec_int ("width", "Width", "Width of the picture", g_param_spec_int ("width", "Width", "Width of the picture",
G_MININT, G_MAXINT, DEFAULT_PAD_WIDTH, G_MININT, G_MAXINT, DEFAULT_PAD_WIDTH,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_PAD_HEIGHT, g_object_class_install_property (gobject_class, PROP_PAD_HEIGHT,
g_param_spec_int ("height", "Height", "Height of the picture", g_param_spec_int ("height", "Height", "Height of the picture",
G_MININT, G_MAXINT, DEFAULT_PAD_HEIGHT, G_MININT, G_MAXINT, DEFAULT_PAD_HEIGHT,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_PAD_ALPHA, g_object_class_install_property (gobject_class, PROP_PAD_ALPHA,
g_param_spec_double ("alpha", "Alpha", "Alpha of the picture", 0.0, 1.0, g_param_spec_double ("alpha", "Alpha", "Alpha of the picture", 0.0, 1.0,
DEFAULT_PAD_ALPHA, DEFAULT_PAD_ALPHA,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_PAD_BLEND_OP_RGB, g_object_class_install_property (gobject_class, PROP_PAD_BLEND_OP_RGB,
g_param_spec_enum ("blend-op-rgb", "Blend Operation RGB", g_param_spec_enum ("blend-op-rgb", "Blend Operation RGB",
"Blend equation for RGB", GST_TYPE_D3D11_COMPOSITOR_BLEND_OPERATION, "Blend equation for RGB", GST_TYPE_D3D11_COMPOSITOR_BLEND_OPERATION,
DEFAULT_PAD_BLEND_OP_RGB, DEFAULT_PAD_BLEND_OP_RGB,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_PAD_BLEND_OP_ALPHA, g_object_class_install_property (gobject_class, PROP_PAD_BLEND_OP_ALPHA,
g_param_spec_enum ("blend-op-alpha", "Blend Operation Alpha", g_param_spec_enum ("blend-op-alpha", "Blend Operation Alpha",
"Blend equation for alpha", GST_TYPE_D3D11_COMPOSITOR_BLEND_OPERATION, "Blend equation for alpha", GST_TYPE_D3D11_COMPOSITOR_BLEND_OPERATION,
DEFAULT_PAD_BLEND_OP_ALPHA, DEFAULT_PAD_BLEND_OP_ALPHA,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_PAD_BLEND_SRC_RGB, PROP_PAD_BLEND_SRC_RGB,
@ -530,7 +546,8 @@ gst_d3d11_compositor_pad_class_init (GstD3D11CompositorPadClass * klass)
"Blend factor for source RGB", "Blend factor for source RGB",
GST_TYPE_D3D11_COMPOSITOR_BLEND, GST_TYPE_D3D11_COMPOSITOR_BLEND,
DEFAULT_PAD_BLEND_SRC_RGB, DEFAULT_PAD_BLEND_SRC_RGB,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_PAD_BLEND_SRC_ALPHA, PROP_PAD_BLEND_SRC_ALPHA,
@ -539,7 +556,8 @@ gst_d3d11_compositor_pad_class_init (GstD3D11CompositorPadClass * klass)
"Blend factor for source alpha, \"*-color\" values are not allowed", "Blend factor for source alpha, \"*-color\" values are not allowed",
GST_TYPE_D3D11_COMPOSITOR_BLEND, GST_TYPE_D3D11_COMPOSITOR_BLEND,
DEFAULT_PAD_BLEND_SRC_ALPHA, DEFAULT_PAD_BLEND_SRC_ALPHA,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_PAD_BLEND_DEST_RGB, PROP_PAD_BLEND_DEST_RGB,
@ -548,7 +566,8 @@ gst_d3d11_compositor_pad_class_init (GstD3D11CompositorPadClass * klass)
"Blend factor for destination RGB", "Blend factor for destination RGB",
GST_TYPE_D3D11_COMPOSITOR_BLEND, GST_TYPE_D3D11_COMPOSITOR_BLEND,
DEFAULT_PAD_BLEND_DEST_RGB, DEFAULT_PAD_BLEND_DEST_RGB,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_PAD_BLEND_DEST_ALPHA, PROP_PAD_BLEND_DEST_ALPHA,
@ -558,43 +577,50 @@ gst_d3d11_compositor_pad_class_init (GstD3D11CompositorPadClass * klass)
"\"*-color\" values are not allowed", "\"*-color\" values are not allowed",
GST_TYPE_D3D11_COMPOSITOR_BLEND, GST_TYPE_D3D11_COMPOSITOR_BLEND,
DEFAULT_PAD_BLEND_DEST_ALPHA, DEFAULT_PAD_BLEND_DEST_ALPHA,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_PAD_BLEND_FACTOR_RED, g_object_class_install_property (gobject_class, PROP_PAD_BLEND_FACTOR_RED,
g_param_spec_float ("blend-factor-red", "Blend Factor Red", g_param_spec_float ("blend-factor-red", "Blend Factor Red",
"Blend factor for red component " "Blend factor for red component "
"when blend type is \"blend-factor\" or \"inv-blend-factor\"", "when blend type is \"blend-factor\" or \"inv-blend-factor\"",
0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_PAD_BLEND_FACTOR_GREEN, g_object_class_install_property (gobject_class, PROP_PAD_BLEND_FACTOR_GREEN,
g_param_spec_float ("blend-factor-green", "Blend Factor Green", g_param_spec_float ("blend-factor-green", "Blend Factor Green",
"Blend factor for green component " "Blend factor for green component "
"when blend type is \"blend-factor\" or \"inv-blend-factor\"", "when blend type is \"blend-factor\" or \"inv-blend-factor\"",
0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_PAD_BLEND_FACTOR_BLUE, g_object_class_install_property (gobject_class, PROP_PAD_BLEND_FACTOR_BLUE,
g_param_spec_float ("blend-factor-blue", "Blend Factor Blue", g_param_spec_float ("blend-factor-blue", "Blend Factor Blue",
"Blend factor for blue component " "Blend factor for blue component "
"when blend type is \"blend-factor\" or \"inv-blend-factor\"", "when blend type is \"blend-factor\" or \"inv-blend-factor\"",
0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_PAD_BLEND_FACTOR_ALPHA, g_object_class_install_property (gobject_class, PROP_PAD_BLEND_FACTOR_ALPHA,
g_param_spec_float ("blend-factor-alpha", "Blend Factor Alpha", g_param_spec_float ("blend-factor-alpha", "Blend Factor Alpha",
"Blend factor for alpha component " "Blend factor for alpha component "
"when blend type is \"blend-factor\" or \"inv-blend-factor\"", "when blend type is \"blend-factor\" or \"inv-blend-factor\"",
0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
vaggpadclass->prepare_frame = vaggpadclass->prepare_frame =
GST_DEBUG_FUNCPTR (gst_d3d11_compositor_pad_prepare_frame); GST_DEBUG_FUNCPTR (gst_d3d11_compositor_pad_prepare_frame);
vaggpadclass->clean_frame = vaggpadclass->clean_frame =
GST_DEBUG_FUNCPTR (gst_d3d11_compositor_pad_clean_frame); GST_DEBUG_FUNCPTR (gst_d3d11_compositor_pad_clean_frame);
gst_type_mark_as_plugin_api (GST_TYPE_D3D11_COMPOSITOR_BLEND, 0); gst_type_mark_as_plugin_api (GST_TYPE_D3D11_COMPOSITOR_BLEND,
gst_type_mark_as_plugin_api (GST_TYPE_D3D11_COMPOSITOR_BLEND_OPERATION, 0); (GstPluginAPIFlags) 0);
gst_type_mark_as_plugin_api (GST_TYPE_D3D11_COMPOSITOR_BLEND_OPERATION,
(GstPluginAPIFlags) 0);
} }
static void static void
@ -624,7 +650,7 @@ gst_d3d11_compositor_pad_update_blend_function (GstD3D11CompositorPad * pad,
static void static void
gst_d3d11_compositor_pad_update_blend_equation (GstD3D11CompositorPad * pad, gst_d3d11_compositor_pad_update_blend_equation (GstD3D11CompositorPad * pad,
D3D11_BLEND_OP * value, GstD3D11CompositorBlend new_value) D3D11_BLEND_OP * value, GstD3D11CompositorBlendOperation new_value)
{ {
D3D11_BLEND_OP temp = D3D11_BLEND_OP temp =
gst_d3d11_compositor_blend_operation_to_native (new_value); gst_d3d11_compositor_blend_operation_to_native (new_value);
@ -670,19 +696,21 @@ gst_d3d11_compositor_pad_set_property (GObject * object, guint prop_id,
} }
case PROP_PAD_BLEND_OP_RGB: case PROP_PAD_BLEND_OP_RGB:
gst_d3d11_compositor_pad_update_blend_equation (pad, &pad->desc.BlendOp, gst_d3d11_compositor_pad_update_blend_equation (pad, &pad->desc.BlendOp,
g_value_get_enum (value)); (GstD3D11CompositorBlendOperation) g_value_get_enum (value));
break; break;
case PROP_PAD_BLEND_OP_ALPHA: case PROP_PAD_BLEND_OP_ALPHA:
gst_d3d11_compositor_pad_update_blend_equation (pad, gst_d3d11_compositor_pad_update_blend_equation (pad,
&pad->desc.BlendOpAlpha, g_value_get_enum (value)); &pad->desc.BlendOpAlpha,
(GstD3D11CompositorBlendOperation) g_value_get_enum (value));
break; break;
case PROP_PAD_BLEND_SRC_RGB: case PROP_PAD_BLEND_SRC_RGB:
gst_d3d11_compositor_pad_update_blend_function (pad, &pad->desc.SrcBlend, gst_d3d11_compositor_pad_update_blend_function (pad, &pad->desc.SrcBlend,
g_value_get_enum (value)); (GstD3D11CompositorBlend) g_value_get_enum (value));
break; break;
case PROP_PAD_BLEND_SRC_ALPHA: case PROP_PAD_BLEND_SRC_ALPHA:
{ {
GstD3D11CompositorBlend blend = g_value_get_enum (value); GstD3D11CompositorBlend blend =
(GstD3D11CompositorBlend) g_value_get_enum (value);
if (blend == GST_D3D11_COMPOSITOR_BLEND_SRC_COLOR || if (blend == GST_D3D11_COMPOSITOR_BLEND_SRC_COLOR ||
blend == GST_D3D11_COMPOSITOR_BLEND_INV_SRC_COLOR || blend == GST_D3D11_COMPOSITOR_BLEND_INV_SRC_COLOR ||
blend == GST_D3D11_COMPOSITOR_BLEND_DEST_COLOR || blend == GST_D3D11_COMPOSITOR_BLEND_DEST_COLOR ||
@ -696,11 +724,12 @@ gst_d3d11_compositor_pad_set_property (GObject * object, guint prop_id,
} }
case PROP_PAD_BLEND_DEST_RGB: case PROP_PAD_BLEND_DEST_RGB:
gst_d3d11_compositor_pad_update_blend_function (pad, &pad->desc.DestBlend, gst_d3d11_compositor_pad_update_blend_function (pad, &pad->desc.DestBlend,
g_value_get_enum (value)); (GstD3D11CompositorBlend) g_value_get_enum (value));
break; break;
case PROP_PAD_BLEND_DEST_ALPHA: case PROP_PAD_BLEND_DEST_ALPHA:
{ {
GstD3D11CompositorBlend blend = g_value_get_enum (value); GstD3D11CompositorBlend blend =
(GstD3D11CompositorBlend) g_value_get_enum (value);
if (blend == GST_D3D11_COMPOSITOR_BLEND_SRC_COLOR || if (blend == GST_D3D11_COMPOSITOR_BLEND_SRC_COLOR ||
blend == GST_D3D11_COMPOSITOR_BLEND_INV_SRC_COLOR || blend == GST_D3D11_COMPOSITOR_BLEND_INV_SRC_COLOR ||
blend == GST_D3D11_COMPOSITOR_BLEND_DEST_COLOR || blend == GST_D3D11_COMPOSITOR_BLEND_DEST_COLOR ||
@ -798,7 +827,7 @@ gst_d3d11_compositor_pad_get_property (GObject * object, guint prop_id,
static void static void
gst_d3d11_compositor_pad_init_blend_options (GstD3D11CompositorPad * pad) gst_d3d11_compositor_pad_init_blend_options (GstD3D11CompositorPad * pad)
{ {
gint i; guint i;
pad->desc.BlendEnable = TRUE; pad->desc.BlendEnable = TRUE;
pad->desc.SrcBlend = pad->desc.SrcBlend =
@ -840,7 +869,7 @@ gst_d3d11_compositor_configure_fallback_pool (GstD3D11Compositor * self,
} }
d3d11_params = gst_d3d11_allocation_params_new (self->device, d3d11_params = gst_d3d11_allocation_params_new (self->device,
info, 0, bind_flags); info, (GstD3D11AllocationFlags) 0, bind_flags);
new_pool = gst_d3d11_buffer_pool_new_with_options (self->device, new_pool = gst_d3d11_buffer_pool_new_with_options (self->device,
caps, d3d11_params, 0, 0); caps, d3d11_params, 0, 0);
@ -865,7 +894,7 @@ gst_d3d11_compsitor_prepare_fallback_buffer (GstD3D11Compositor * self,
{ {
GstBuffer *new_buf = NULL; GstBuffer *new_buf = NULL;
gint bind_flags = D3D11_BIND_SHADER_RESOURCE; gint bind_flags = D3D11_BIND_SHADER_RESOURCE;
gint i; guint i;
gst_clear_buffer (fallback_buffer); gst_clear_buffer (fallback_buffer);
@ -911,7 +940,7 @@ gst_d3d11_compositor_copy_buffer (GstD3D11Compositor * self,
GstVideoInfo * info, GstBuffer * src_buf, GstBuffer * dest_buf, GstVideoInfo * info, GstBuffer * src_buf, GstBuffer * dest_buf,
gboolean do_device_copy) gboolean do_device_copy)
{ {
gint i; guint i;
if (do_device_copy) { if (do_device_copy) {
return gst_d3d11_buffer_copy_into (dest_buf, src_buf, info); return gst_d3d11_buffer_copy_into (dest_buf, src_buf, info);
@ -919,13 +948,13 @@ gst_d3d11_compositor_copy_buffer (GstD3D11Compositor * self,
GstVideoFrame src_frame, dest_frame; GstVideoFrame src_frame, dest_frame;
if (!gst_video_frame_map (&src_frame, info, src_buf, if (!gst_video_frame_map (&src_frame, info, src_buf,
GST_MAP_READ | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)) { (GstMapFlags) (GST_MAP_READ | GST_VIDEO_FRAME_MAP_FLAG_NO_REF))) {
GST_ERROR_OBJECT (self, "Couldn't map input buffer"); GST_ERROR_OBJECT (self, "Couldn't map input buffer");
return FALSE; return FALSE;
} }
if (!gst_video_frame_map (&dest_frame, info, dest_buf, if (!gst_video_frame_map (&dest_frame, info, dest_buf,
GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)) { (GstMapFlags) (GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF))) {
GST_ERROR_OBJECT (self, "Couldn't fallback buffer"); GST_ERROR_OBJECT (self, "Couldn't fallback buffer");
gst_video_frame_unmap (&src_frame); gst_video_frame_unmap (&src_frame);
return FALSE; return FALSE;
@ -953,7 +982,7 @@ static gboolean
gst_d3d11_compositor_check_d3d11_memory (GstD3D11Compositor * self, gst_d3d11_compositor_check_d3d11_memory (GstD3D11Compositor * self,
GstBuffer * buffer, gboolean is_input, gboolean * view_available) GstBuffer * buffer, gboolean is_input, gboolean * view_available)
{ {
gint i; guint i;
gboolean ret = TRUE; gboolean ret = TRUE;
*view_available = TRUE; *view_available = TRUE;
@ -1134,7 +1163,7 @@ gst_d3d11_compositor_pad_prepare_frame (GstVideoAggregatorPad * pad,
} }
if (!gst_video_frame_map (prepared_frame, &pad->info, target_buf, if (!gst_video_frame_map (prepared_frame, &pad->info, target_buf,
GST_MAP_READ | GST_MAP_D3D11)) { (GstMapFlags) (GST_MAP_READ | GST_MAP_D3D11))) {
GST_WARNING_OBJECT (pad, "Couldn't map input buffer"); GST_WARNING_OBJECT (pad, "Couldn't map input buffer");
return FALSE; return FALSE;
} }
@ -1171,9 +1200,9 @@ gst_d3d11_compositor_pad_setup_converter (GstVideoAggregatorPad * pad,
if (!cpad->convert || cpad->alpha_updated || cpad->caps_updated) { if (!cpad->convert || cpad->alpha_updated || cpad->caps_updated) {
if (cpad->convert) if (cpad->convert)
gst_d3d11_color_converter_free (cpad->convert); gst_d3d11_converter_free (cpad->convert);
cpad->convert = cpad->convert =
gst_d3d11_color_converter_new_with_alpha (self->device, gst_d3d11_converter_new_with_alpha (self->device,
&pad->info, &vagg->info, cpad->alpha); &pad->info, &vagg->info, cpad->alpha);
cpad->alpha_updated = FALSE; cpad->alpha_updated = FALSE;
cpad->caps_updated = FALSE; cpad->caps_updated = FALSE;
@ -1192,16 +1221,13 @@ gst_d3d11_compositor_pad_setup_converter (GstVideoAggregatorPad * pad,
ID3D11Device *device_handle = ID3D11Device *device_handle =
gst_d3d11_device_get_device_handle (self->device); gst_d3d11_device_get_device_handle (self->device);
if (cpad->blend) { GST_D3D11_CLEAR_COM (cpad->blend);
ID3D11BlendState_Release (cpad->blend);
cpad->blend = NULL;
}
desc.AlphaToCoverageEnable = FALSE; desc.AlphaToCoverageEnable = FALSE;
desc.IndependentBlendEnable = FALSE; desc.IndependentBlendEnable = FALSE;
desc.RenderTarget[0] = cpad->desc; desc.RenderTarget[0] = cpad->desc;
hr = ID3D11Device_CreateBlendState (device_handle, &desc, &blend); hr = device_handle->CreateBlendState (&desc, &blend);
if (!gst_d3d11_result (hr, self->device)) { if (!gst_d3d11_result (hr, self->device)) {
GST_ERROR_OBJECT (pad, "Couldn't create blend staten, hr: 0x%x", GST_ERROR_OBJECT (pad, "Couldn't create blend staten, hr: 0x%x",
(guint) hr); (guint) hr);
@ -1239,7 +1265,7 @@ gst_d3d11_compositor_pad_setup_converter (GstVideoAggregatorPad * pad,
cpad->position_updated = FALSE; cpad->position_updated = FALSE;
return gst_d3d11_color_converter_update_dest_rect (cpad->convert, &rect); return gst_d3d11_converter_update_dest_rect (cpad->convert, &rect);
} }
static GstStaticCaps pad_template_caps = static GstStaticCaps pad_template_caps =
@ -1313,13 +1339,14 @@ gst_d3d11_compositor_class_init (GstD3D11CompositorClass * klass)
g_param_spec_int ("adapter", "Adapter", g_param_spec_int ("adapter", "Adapter",
"Adapter index for creating device (-1 for default)", "Adapter index for creating device (-1 for default)",
-1, G_MAXINT32, DEFAULT_ADAPTER, -1, G_MAXINT32, DEFAULT_ADAPTER,
G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY | (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_BACKGROUND, g_object_class_install_property (gobject_class, PROP_BACKGROUND,
g_param_spec_enum ("background", "Background", "Background type", g_param_spec_enum ("background", "Background", "Background type",
GST_TYPE_COMPOSITOR_BACKGROUND, GST_TYPE_COMPOSITOR_BACKGROUND,
DEFAULT_BACKGROUND, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_BACKGROUND,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
element_class->request_new_pad = element_class->request_new_pad =
GST_DEBUG_FUNCPTR (gst_d3d11_compositor_request_new_pad); GST_DEBUG_FUNCPTR (gst_d3d11_compositor_request_new_pad);
@ -1360,8 +1387,10 @@ gst_d3d11_compositor_class_init (GstD3D11CompositorClass * klass)
"Filter/Editor/Video/Compositor", "Filter/Editor/Video/Compositor",
"A Direct3D11 compositor", "Seungha Yang <seungha@centricular.com>"); "A Direct3D11 compositor", "Seungha Yang <seungha@centricular.com>");
gst_type_mark_as_plugin_api (GST_TYPE_COMPOSITOR_BACKGROUND, 0); gst_type_mark_as_plugin_api (GST_TYPE_COMPOSITOR_BACKGROUND,
gst_type_mark_as_plugin_api (GST_TYPE_D3D11_COMPOSITOR_PAD, 0); (GstPluginAPIFlags) 0);
gst_type_mark_as_plugin_api (GST_TYPE_D3D11_COMPOSITOR_PAD,
(GstPluginAPIFlags) 0);
} }
static void static void
@ -1395,7 +1424,8 @@ gst_d3d11_compositor_set_property (GObject * object,
self->adapter = g_value_get_int (value); self->adapter = g_value_get_int (value);
break; break;
case PROP_BACKGROUND: case PROP_BACKGROUND:
self->background = g_value_get_enum (value); self->background =
(GstD3D11CompositorBackground) g_value_get_enum (value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -1430,7 +1460,7 @@ gst_d3d11_compositor_child_proxy_get_child_by_index (GstChildProxy * proxy,
GObject *obj = NULL; GObject *obj = NULL;
GST_OBJECT_LOCK (self); GST_OBJECT_LOCK (self);
obj = g_list_nth_data (GST_ELEMENT_CAST (self)->sinkpads, index); obj = (GObject *) g_list_nth_data (GST_ELEMENT_CAST (self)->sinkpads, index);
if (obj) if (obj)
gst_object_ref (obj); gst_object_ref (obj);
GST_OBJECT_UNLOCK (self); GST_OBJECT_UNLOCK (self);
@ -1455,7 +1485,7 @@ gst_d3d11_compositor_child_proxy_get_children_count (GstChildProxy * proxy)
static void static void
gst_d3d11_compositor_child_proxy_init (gpointer g_iface, gpointer iface_data) gst_d3d11_compositor_child_proxy_init (gpointer g_iface, gpointer iface_data)
{ {
GstChildProxyInterface *iface = g_iface; GstChildProxyInterface *iface = (GstChildProxyInterface *) g_iface;
iface->get_child_by_index = iface->get_child_by_index =
gst_d3d11_compositor_child_proxy_get_child_by_index; gst_d3d11_compositor_child_proxy_get_child_by_index;
@ -1502,11 +1532,8 @@ gst_d3d11_compositor_release_pad (GstElement * element, GstPad * pad)
gst_clear_buffer (&cpad->fallback_buf); gst_clear_buffer (&cpad->fallback_buf);
gst_clear_object (&cpad->fallback_pool); gst_clear_object (&cpad->fallback_pool);
g_clear_pointer (&cpad->convert, gst_d3d11_color_converter_free); g_clear_pointer (&cpad->convert, gst_d3d11_converter_free);
if (cpad->blend) { GST_D3D11_CLEAR_COM (cpad->blend);
ID3D11BlendState_Release (cpad->blend);
cpad->blend = NULL;
}
GST_ELEMENT_CLASS (parent_class)->release_pad (element, pad); GST_ELEMENT_CLASS (parent_class)->release_pad (element, pad);
} }
@ -1691,7 +1718,7 @@ gst_d3d11_compositor_fixate_src_caps (GstAggregator * aggregator,
GST_OBJECT_LOCK (vagg); GST_OBJECT_LOCK (vagg);
for (l = GST_ELEMENT (vagg)->sinkpads; l; l = l->next) { for (l = GST_ELEMENT (vagg)->sinkpads; l; l = l->next) {
GstVideoAggregatorPad *vaggpad = l->data; GstVideoAggregatorPad *vaggpad = GST_VIDEO_AGGREGATOR_PAD (l->data);
GstD3D11CompositorPad *cpad = GST_D3D11_COMPOSITOR_PAD (vaggpad); GstD3D11CompositorPad *cpad = GST_D3D11_COMPOSITOR_PAD (vaggpad);
gint this_width, this_height; gint this_width, this_height;
gint width, height; gint width, height;
@ -1765,8 +1792,8 @@ gst_d3d11_compositor_propose_allocation (GstAggregator * aggregator,
if (gst_query_get_n_allocation_pools (query) == 0) { if (gst_query_get_n_allocation_pools (query) == 0) {
GstD3D11AllocationParams *d3d11_params; GstD3D11AllocationParams *d3d11_params;
d3d11_params = gst_d3d11_allocation_params_new (self->device, &info, 0, d3d11_params = gst_d3d11_allocation_params_new (self->device, &info,
D3D11_BIND_SHADER_RESOURCE); (GstD3D11AllocationFlags) 0, D3D11_BIND_SHADER_RESOURCE);
pool = gst_d3d11_buffer_pool_new_with_options (self->device, pool = gst_d3d11_buffer_pool_new_with_options (self->device,
caps, d3d11_params, 0, 0); caps, d3d11_params, 0, 0);
@ -1833,9 +1860,9 @@ gst_d3d11_compositor_decide_allocation (GstAggregator * aggregator,
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config); d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
if (!d3d11_params) { if (!d3d11_params) {
d3d11_params = gst_d3d11_allocation_params_new (self->device, d3d11_params = gst_d3d11_allocation_params_new (self->device,
&info, 0, D3D11_BIND_RENDER_TARGET); &info, (GstD3D11AllocationFlags) 0, D3D11_BIND_RENDER_TARGET);
} else { } else {
gint i; guint i;
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&info); i++) { for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&info); i++) {
d3d11_params->desc[i].BindFlags |= D3D11_BIND_RENDER_TARGET; d3d11_params->desc[i].BindFlags |= D3D11_BIND_RENDER_TARGET;
@ -1894,9 +1921,6 @@ typedef struct
static GstD3D11Quad * static GstD3D11Quad *
gst_d3d11_compositor_create_checker_quad (GstD3D11Compositor * self) gst_d3d11_compositor_create_checker_quad (GstD3D11Compositor * self)
{ {
ID3D11PixelShader *ps = NULL;
ID3D11VertexShader *vs = NULL;
ID3D11InputLayout *layout = NULL;
GstD3D11Quad *quad = NULL; GstD3D11Quad *quad = NULL;
VertexData *vertex_data; VertexData *vertex_data;
WORD *indices; WORD *indices;
@ -1905,18 +1929,21 @@ gst_d3d11_compositor_create_checker_quad (GstD3D11Compositor * self)
D3D11_MAPPED_SUBRESOURCE map; D3D11_MAPPED_SUBRESOURCE map;
D3D11_INPUT_ELEMENT_DESC input_desc; D3D11_INPUT_ELEMENT_DESC input_desc;
D3D11_BUFFER_DESC buffer_desc; D3D11_BUFFER_DESC buffer_desc;
ID3D11Buffer *vertex_buffer = NULL; /* *INDENT-OFF* */
ID3D11Buffer *index_buffer = NULL; ComPtr<ID3D11Buffer> vertex_buffer;
gboolean ret = FALSE; ComPtr<ID3D11Buffer> index_buffer;
ComPtr<ID3D11PixelShader> ps;
ComPtr<ID3D11VertexShader> vs;
ComPtr<ID3D11InputLayout> layout;
/* *INDENT-ON* */
HRESULT hr; HRESULT hr;
device_handle = gst_d3d11_device_get_device_handle (self->device); device_handle = gst_d3d11_device_get_device_handle (self->device);
context_handle = gst_d3d11_device_get_device_context_handle (self->device); context_handle = gst_d3d11_device_get_device_context_handle (self->device);
ret = gst_d3d11_create_pixel_shader (self->device, checker_ps_src, &ps); if (!gst_d3d11_create_pixel_shader (self->device, checker_ps_src, &ps)) {
if (!ret) {
GST_ERROR_OBJECT (self, "Couldn't setup pixel shader"); GST_ERROR_OBJECT (self, "Couldn't setup pixel shader");
goto done; return NULL;
} }
memset (&input_desc, 0, sizeof (D3D11_INPUT_ELEMENT_DESC)); memset (&input_desc, 0, sizeof (D3D11_INPUT_ELEMENT_DESC));
@ -1931,7 +1958,7 @@ gst_d3d11_compositor_create_checker_quad (GstD3D11Compositor * self)
if (!gst_d3d11_create_vertex_shader (self->device, checker_vs_src, if (!gst_d3d11_create_vertex_shader (self->device, checker_vs_src,
&input_desc, 1, &vs, &layout)) { &input_desc, 1, &vs, &layout)) {
GST_ERROR_OBJECT (self, "Couldn't setup vertex shader"); GST_ERROR_OBJECT (self, "Couldn't setup vertex shader");
goto done; return NULL;
} }
memset (&buffer_desc, 0, sizeof (D3D11_BUFFER_DESC)); memset (&buffer_desc, 0, sizeof (D3D11_BUFFER_DESC));
@ -1940,21 +1967,19 @@ gst_d3d11_compositor_create_checker_quad (GstD3D11Compositor * self)
buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
hr = ID3D11Device_CreateBuffer (device_handle, &buffer_desc, NULL, hr = device_handle->CreateBuffer (&buffer_desc, NULL, &vertex_buffer);
&vertex_buffer);
if (!gst_d3d11_result (hr, self->device)) { if (!gst_d3d11_result (hr, self->device)) {
GST_ERROR_OBJECT (self, GST_ERROR_OBJECT (self,
"Couldn't create vertex buffer, hr: 0x%x", (guint) hr); "Couldn't create vertex buffer, hr: 0x%x", (guint) hr);
goto done; return NULL;
} }
hr = ID3D11DeviceContext_Map (context_handle, hr = context_handle->Map (vertex_buffer.Get (),
(ID3D11Resource *) vertex_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
if (!gst_d3d11_result (hr, self->device)) { if (!gst_d3d11_result (hr, self->device)) {
GST_ERROR_OBJECT (self, "Couldn't map vertex buffer, hr: 0x%x", (guint) hr); GST_ERROR_OBJECT (self, "Couldn't map vertex buffer, hr: 0x%x", (guint) hr);
goto done; return NULL;
} }
vertex_data = (VertexData *) map.pData; vertex_data = (VertexData *) map.pData;
@ -1987,29 +2012,26 @@ gst_d3d11_compositor_create_checker_quad (GstD3D11Compositor * self)
vertex_data[3].texture.u = 1.0f; vertex_data[3].texture.u = 1.0f;
vertex_data[3].texture.v = 1.0f; vertex_data[3].texture.v = 1.0f;
ID3D11DeviceContext_Unmap (context_handle, context_handle->Unmap (vertex_buffer.Get (), 0);
(ID3D11Resource *) vertex_buffer, 0);
buffer_desc.Usage = D3D11_USAGE_DYNAMIC; buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
buffer_desc.ByteWidth = sizeof (WORD) * 6; buffer_desc.ByteWidth = sizeof (WORD) * 6;
buffer_desc.BindFlags = D3D11_BIND_INDEX_BUFFER; buffer_desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
hr = ID3D11Device_CreateBuffer (device_handle, &buffer_desc, NULL, hr = device_handle->CreateBuffer (&buffer_desc, NULL, &index_buffer);
&index_buffer);
if (!gst_d3d11_result (hr, self->device)) { if (!gst_d3d11_result (hr, self->device)) {
GST_ERROR_OBJECT (self, GST_ERROR_OBJECT (self,
"Couldn't create index buffer, hr: 0x%x", (guint) hr); "Couldn't create index buffer, hr: 0x%x", (guint) hr);
goto done; return NULL;
} }
hr = ID3D11DeviceContext_Map (context_handle, hr = context_handle->Map (index_buffer.Get (),
(ID3D11Resource *) index_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
if (!gst_d3d11_result (hr, self->device)) { if (!gst_d3d11_result (hr, self->device)) {
GST_ERROR_OBJECT (self, "Couldn't map index buffer, hr: 0x%x", (guint) hr); GST_ERROR_OBJECT (self, "Couldn't map index buffer, hr: 0x%x", (guint) hr);
goto done; return NULL;
} }
indices = (WORD *) map.pData; indices = (WORD *) map.pData;
@ -2023,29 +2045,17 @@ gst_d3d11_compositor_create_checker_quad (GstD3D11Compositor * self)
indices[4] = 0; /* bottom left */ indices[4] = 0; /* bottom left */
indices[5] = 2; /* top right */ indices[5] = 2; /* top right */
ID3D11DeviceContext_Unmap (context_handle, context_handle->Unmap (index_buffer.Get (), 0);
(ID3D11Resource *) index_buffer, 0);
quad = gst_d3d11_quad_new (self->device, quad = gst_d3d11_quad_new (self->device,
ps, vs, layout, NULL, NULL, NULL, NULL, vertex_buffer, ps.Get (), vs.Get (), layout.Get (), NULL, NULL, NULL, NULL,
sizeof (VertexData), index_buffer, DXGI_FORMAT_R16_UINT, 6); vertex_buffer.Get (), sizeof (VertexData), index_buffer.Get (),
DXGI_FORMAT_R16_UINT, 6);
if (!quad) { if (!quad) {
GST_ERROR_OBJECT (self, "Couldn't setup quad"); GST_ERROR_OBJECT (self, "Couldn't setup quad");
goto done; return NULL;
} }
done:
if (ps)
ID3D11PixelShader_Release (ps);
if (vs)
ID3D11VertexShader_Release (vs);
if (layout)
ID3D11InputLayout_Release (layout);
if (vertex_buffer)
ID3D11Buffer_Release (vertex_buffer);
if (index_buffer)
ID3D11Buffer_Release (index_buffer);
return quad; return quad;
} }
@ -2101,7 +2111,7 @@ gst_d3d11_compositor_draw_background (GstD3D11Compositor * self,
return FALSE; return FALSE;
} }
ID3D11DeviceContext_ClearRenderTargetView (device_context, rtv, rgba); device_context->ClearRenderTargetView (rtv, rgba);
return TRUE; return TRUE;
} }
@ -2117,7 +2127,7 @@ gst_d3d11_compositor_aggregate_frames (GstVideoAggregator * vagg,
gboolean do_device_copy = FALSE; gboolean do_device_copy = FALSE;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES] = { NULL, }; ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES] = { NULL, };
gint i, j; guint i, j;
gint view_idx; gint view_idx;
/* Use fallback buffer when output buffer is: /* Use fallback buffer when output buffer is:
@ -2181,7 +2191,7 @@ gst_d3d11_compositor_aggregate_frames (GstVideoAggregator * vagg,
GST_OBJECT_LOCK (self); GST_OBJECT_LOCK (self);
for (iter = GST_ELEMENT (vagg)->sinkpads; iter; iter = g_list_next (iter)) { for (iter = GST_ELEMENT (vagg)->sinkpads; iter; iter = g_list_next (iter)) {
GstVideoAggregatorPad *pad = iter->data; GstVideoAggregatorPad *pad = GST_VIDEO_AGGREGATOR_PAD (iter->data);
GstD3D11CompositorPad *cpad = GST_D3D11_COMPOSITOR_PAD (pad); GstD3D11CompositorPad *cpad = GST_D3D11_COMPOSITOR_PAD (pad);
GstVideoFrame *prepared_frame = GstVideoFrame *prepared_frame =
gst_video_aggregator_pad_get_prepared_frame (pad); gst_video_aggregator_pad_get_prepared_frame (pad);
@ -2213,7 +2223,7 @@ gst_d3d11_compositor_aggregate_frames (GstVideoAggregator * vagg,
} }
} }
if (!gst_d3d11_color_converter_convert_unlocked (cpad->convert, srv, rtv, if (!gst_d3d11_converter_convert_unlocked (cpad->convert, srv, rtv,
cpad->blend, cpad->blend_factor)) { cpad->blend, cpad->blend_factor)) {
GST_ERROR_OBJECT (self, "Couldn't convert frame"); GST_ERROR_OBJECT (self, "Couldn't convert frame");
ret = GST_FLOW_ERROR; ret = GST_FLOW_ERROR;

View file

@ -47,9 +47,15 @@
#include "gstd3d11compositor.h" #include "gstd3d11compositor.h"
#include "gstd3d11pluginutils.h" #include "gstd3d11pluginutils.h"
/* *INDENT-OFF* */
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_compositor_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_compositor_debug);
#define GST_CAT_DEFAULT gst_d3d11_compositor_debug #define GST_CAT_DEFAULT gst_d3d11_compositor_debug
G_END_DECLS
/* *INDENT-ON* */
/**************************** /****************************
* GstD3D11CompositorBinPad * * GstD3D11CompositorBinPad *
****************************/ ****************************/
@ -113,7 +119,7 @@ gst_d3d11_compositor_bin_pad_class_init (GstD3D11CompositorBinPadClass * klass)
g_param_spec_boolean ("emit-signals", "Emit signals", g_param_spec_boolean ("emit-signals", "Emit signals",
"Send signals to signal data consumption", "Send signals to signal data consumption",
DEFAULT_PAD_EMIT_SIGNALS, DEFAULT_PAD_EMIT_SIGNALS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
gst_d3d11_compositor_bin_pad_signals[SIGNAL_PAD_BUFFER_CONSUMED] = gst_d3d11_compositor_bin_pad_signals[SIGNAL_PAD_BUFFER_CONSUMED] =
g_signal_new ("buffer-consumed", G_TYPE_FROM_CLASS (klass), g_signal_new ("buffer-consumed", G_TYPE_FROM_CLASS (klass),
@ -286,13 +292,15 @@ gst_d3d11_compositor_bin_input_class_init (GstD3D11CompositorBinInputClass *
g_object_class_install_property (gobject_class, PROP_INPUT_ZORDER, g_object_class_install_property (gobject_class, PROP_INPUT_ZORDER,
g_param_spec_uint ("zorder", "Z-Order", "Z Order of the picture", g_param_spec_uint ("zorder", "Z-Order", "Z Order of the picture",
0, G_MAXUINT, DEFAULT_INPUT_ZORDER, 0, G_MAXUINT, DEFAULT_INPUT_ZORDER,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_INPUT_REPEAT_AFTER_EOS, g_object_class_install_property (gobject_class, PROP_INPUT_REPEAT_AFTER_EOS,
g_param_spec_boolean ("repeat-after-eos", "Repeat After EOS", g_param_spec_boolean ("repeat-after-eos", "Repeat After EOS",
"Repeat the " "last frame after EOS until all pads are EOS", "Repeat the " "last frame after EOS until all pads are EOS",
DEFAULT_INPUT_REPEAT_AFTER_EOS, DEFAULT_INPUT_REPEAT_AFTER_EOS,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_INPUT_MAX_LAST_BUFFER_REPEAT, PROP_INPUT_MAX_LAST_BUFFER_REPEAT,
@ -300,46 +308,53 @@ gst_d3d11_compositor_bin_input_class_init (GstD3D11CompositorBinInputClass *
"Repeat last buffer for time (in ns, -1=until EOS), " "Repeat last buffer for time (in ns, -1=until EOS), "
"behaviour on EOS is not affected", 0, G_MAXUINT64, "behaviour on EOS is not affected", 0, G_MAXUINT64,
DEFAULT_INPUT_MAX_LAST_BUFFER_REPEAT, DEFAULT_INPUT_MAX_LAST_BUFFER_REPEAT,
G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS)));
/* GstD3D11CompositorPad */ /* GstD3D11CompositorPad */
g_object_class_install_property (gobject_class, PROP_INPUT_XPOS, g_object_class_install_property (gobject_class, PROP_INPUT_XPOS,
g_param_spec_int ("xpos", "X Position", "X position of the picture", g_param_spec_int ("xpos", "X Position", "X position of the picture",
G_MININT, G_MAXINT, DEFAULT_INPUT_XPOS, G_MININT, G_MAXINT, DEFAULT_INPUT_XPOS,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_INPUT_YPOS, g_object_class_install_property (gobject_class, PROP_INPUT_YPOS,
g_param_spec_int ("ypos", "Y Position", "Y position of the picture", g_param_spec_int ("ypos", "Y Position", "Y position of the picture",
G_MININT, G_MAXINT, DEFAULT_INPUT_YPOS, G_MININT, G_MAXINT, DEFAULT_INPUT_YPOS,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_INPUT_WIDTH, g_object_class_install_property (gobject_class, PROP_INPUT_WIDTH,
g_param_spec_int ("width", "Width", "Width of the picture", g_param_spec_int ("width", "Width", "Width of the picture",
G_MININT, G_MAXINT, DEFAULT_INPUT_WIDTH, G_MININT, G_MAXINT, DEFAULT_INPUT_WIDTH,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_INPUT_HEIGHT, g_object_class_install_property (gobject_class, PROP_INPUT_HEIGHT,
g_param_spec_int ("height", "Height", "Height of the picture", g_param_spec_int ("height", "Height", "Height of the picture",
G_MININT, G_MAXINT, DEFAULT_INPUT_HEIGHT, G_MININT, G_MAXINT, DEFAULT_INPUT_HEIGHT,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_INPUT_ALPHA, g_object_class_install_property (gobject_class, PROP_INPUT_ALPHA,
g_param_spec_double ("alpha", "Alpha", "Alpha of the picture", 0.0, 1.0, g_param_spec_double ("alpha", "Alpha", "Alpha of the picture", 0.0, 1.0,
DEFAULT_INPUT_ALPHA, DEFAULT_INPUT_ALPHA,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_INPUT_BLEND_OP_RGB, g_object_class_install_property (gobject_class, PROP_INPUT_BLEND_OP_RGB,
g_param_spec_enum ("blend-op-rgb", "Blend Operation RGB", g_param_spec_enum ("blend-op-rgb", "Blend Operation RGB",
"Blend equation for RGB", GST_TYPE_D3D11_COMPOSITOR_BLEND_OPERATION, "Blend equation for RGB", GST_TYPE_D3D11_COMPOSITOR_BLEND_OPERATION,
DEFAULT_INPUT_BLEND_OP_RGB, DEFAULT_INPUT_BLEND_OP_RGB,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_INPUT_BLEND_OP_ALPHA, g_object_class_install_property (gobject_class, PROP_INPUT_BLEND_OP_ALPHA,
g_param_spec_enum ("blend-op-alpha", "Blend Operation Alpha", g_param_spec_enum ("blend-op-alpha", "Blend Operation Alpha",
"Blend equation for alpha", GST_TYPE_D3D11_COMPOSITOR_BLEND_OPERATION, "Blend equation for alpha", GST_TYPE_D3D11_COMPOSITOR_BLEND_OPERATION,
DEFAULT_INPUT_BLEND_OP_ALPHA, DEFAULT_INPUT_BLEND_OP_ALPHA,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_INPUT_BLEND_SRC_RGB, PROP_INPUT_BLEND_SRC_RGB,
@ -347,7 +362,8 @@ gst_d3d11_compositor_bin_input_class_init (GstD3D11CompositorBinInputClass *
"Blend factor for source RGB", "Blend factor for source RGB",
GST_TYPE_D3D11_COMPOSITOR_BLEND, GST_TYPE_D3D11_COMPOSITOR_BLEND,
DEFAULT_INPUT_BLEND_SRC_RGB, DEFAULT_INPUT_BLEND_SRC_RGB,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_INPUT_BLEND_SRC_ALPHA, PROP_INPUT_BLEND_SRC_ALPHA,
@ -356,7 +372,8 @@ gst_d3d11_compositor_bin_input_class_init (GstD3D11CompositorBinInputClass *
"Blend factor for source alpha, \"*-color\" values are not allowed", "Blend factor for source alpha, \"*-color\" values are not allowed",
GST_TYPE_D3D11_COMPOSITOR_BLEND, GST_TYPE_D3D11_COMPOSITOR_BLEND,
DEFAULT_INPUT_BLEND_SRC_ALPHA, DEFAULT_INPUT_BLEND_SRC_ALPHA,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_INPUT_BLEND_DEST_RGB, PROP_INPUT_BLEND_DEST_RGB,
@ -365,7 +382,8 @@ gst_d3d11_compositor_bin_input_class_init (GstD3D11CompositorBinInputClass *
"Blend factor for destination RGB", "Blend factor for destination RGB",
GST_TYPE_D3D11_COMPOSITOR_BLEND, GST_TYPE_D3D11_COMPOSITOR_BLEND,
DEFAULT_INPUT_BLEND_DEST_RGB, DEFAULT_INPUT_BLEND_DEST_RGB,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_INPUT_BLEND_DEST_ALPHA, PROP_INPUT_BLEND_DEST_ALPHA,
@ -375,35 +393,40 @@ gst_d3d11_compositor_bin_input_class_init (GstD3D11CompositorBinInputClass *
"\"*-color\" values are not allowed", "\"*-color\" values are not allowed",
GST_TYPE_D3D11_COMPOSITOR_BLEND, GST_TYPE_D3D11_COMPOSITOR_BLEND,
DEFAULT_INPUT_BLEND_DEST_ALPHA, DEFAULT_INPUT_BLEND_DEST_ALPHA,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_INPUT_BLEND_FACTOR_RED, g_object_class_install_property (gobject_class, PROP_INPUT_BLEND_FACTOR_RED,
g_param_spec_float ("blend-factor-red", "Blend Factor Red", g_param_spec_float ("blend-factor-red", "Blend Factor Red",
"Blend factor for red component " "Blend factor for red component "
"when blend type is \"blend-factor\" or \"inv-blend-factor\"", "when blend type is \"blend-factor\" or \"inv-blend-factor\"",
0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_INPUT_BLEND_FACTOR_GREEN, g_object_class_install_property (gobject_class, PROP_INPUT_BLEND_FACTOR_GREEN,
g_param_spec_float ("blend-factor-green", "Blend Factor Green", g_param_spec_float ("blend-factor-green", "Blend Factor Green",
"Blend factor for green component " "Blend factor for green component "
"when blend type is \"blend-factor\" or \"inv-blend-factor\"", "when blend type is \"blend-factor\" or \"inv-blend-factor\"",
0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_INPUT_BLEND_FACTOR_BLUE, g_object_class_install_property (gobject_class, PROP_INPUT_BLEND_FACTOR_BLUE,
g_param_spec_float ("blend-factor-blue", "Blend Factor Blue", g_param_spec_float ("blend-factor-blue", "Blend Factor Blue",
"Blend factor for blue component " "Blend factor for blue component "
"when blend type is \"blend-factor\" or \"inv-blend-factor\"", "when blend type is \"blend-factor\" or \"inv-blend-factor\"",
0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_INPUT_BLEND_FACTOR_ALPHA, g_object_class_install_property (gobject_class, PROP_INPUT_BLEND_FACTOR_ALPHA,
g_param_spec_float ("blend-factor-alpha", "Blend Factor Alpha", g_param_spec_float ("blend-factor-alpha", "Blend Factor Alpha",
"Blend factor for alpha component " "Blend factor for alpha component "
"when blend type is \"blend-factor\" or \"inv-blend-factor\"", "when blend type is \"blend-factor\" or \"inv-blend-factor\"",
0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
G_PARAM_STATIC_STRINGS)));
pad_class->set_target = pad_class->set_target =
GST_DEBUG_FUNCPTR (gst_d3d11_compositor_bin_input_set_target); GST_DEBUG_FUNCPTR (gst_d3d11_compositor_bin_input_set_target);
@ -590,7 +613,8 @@ gst_d3d11_compositor_bin_class_init (GstD3D11CompositorBinClass * klass)
g_object_class_install_property (gobject_class, PROP_MIXER, g_object_class_install_property (gobject_class, PROP_MIXER,
g_param_spec_object ("mixer", "D3D11 mixer element", g_param_spec_object ("mixer", "D3D11 mixer element",
"The d3d11 mixer chain to use", "The d3d11 mixer chain to use",
GST_TYPE_ELEMENT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); GST_TYPE_ELEMENT,
(GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
/*GstAggregator */ /*GstAggregator */
g_object_class_install_property (gobject_class, PROP_LATENCY, g_object_class_install_property (gobject_class, PROP_LATENCY,
@ -598,7 +622,8 @@ gst_d3d11_compositor_bin_class_init (GstD3D11CompositorBinClass * klass)
"Additional latency in live mode to allow upstream " "Additional latency in live mode to allow upstream "
"to take longer to produce buffers for the current " "to take longer to produce buffers for the current "
"position (in nanoseconds)", 0, G_MAXUINT64, "position (in nanoseconds)", 0, G_MAXUINT64,
DEFAULT_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_LATENCY,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_MIN_UPSTREAM_LATENCY, g_object_class_install_property (gobject_class, PROP_MIN_UPSTREAM_LATENCY,
g_param_spec_uint64 ("min-upstream-latency", "Buffer latency", g_param_spec_uint64 ("min-upstream-latency", "Buffer latency",
@ -608,41 +633,46 @@ gst_d3d11_compositor_bin_class_init (GstD3D11CompositorBinClass * klass)
"initial source(s). This is only taken into account when larger " "initial source(s). This is only taken into account when larger "
"than the actually reported minimum latency. (nanoseconds)", "than the actually reported minimum latency. (nanoseconds)",
0, G_MAXUINT64, 0, G_MAXUINT64,
DEFAULT_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_LATENCY,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_START_TIME_SELECTION, g_object_class_install_property (gobject_class, PROP_START_TIME_SELECTION,
g_param_spec_enum ("start-time-selection", "Start Time Selection", g_param_spec_enum ("start-time-selection", "Start Time Selection",
"Decides which start time is output", "Decides which start time is output",
gst_aggregator_start_time_selection_get_type (), gst_aggregator_start_time_selection_get_type (),
DEFAULT_START_TIME_SELECTION, DEFAULT_START_TIME_SELECTION,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_START_TIME, g_object_class_install_property (gobject_class, PROP_START_TIME,
g_param_spec_uint64 ("start-time", "Start Time", g_param_spec_uint64 ("start-time", "Start Time",
"Start time to use if start-time-selection=set", 0, "Start time to use if start-time-selection=set", 0,
G_MAXUINT64, G_MAXUINT64,
DEFAULT_START_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_START_TIME,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_EMIT_SIGNALS, g_object_class_install_property (gobject_class, PROP_EMIT_SIGNALS,
g_param_spec_boolean ("emit-signals", "Emit signals", g_param_spec_boolean ("emit-signals", "Emit signals",
"Send signals", DEFAULT_EMIT_SIGNALS, "Send signals", DEFAULT_EMIT_SIGNALS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
/* GstD3D11Compositor */ /* GstD3D11Compositor */
g_object_class_install_property (gobject_class, PROP_ADAPTER, g_object_class_install_property (gobject_class, PROP_ADAPTER,
g_param_spec_int ("adapter", "Adapter", g_param_spec_int ("adapter", "Adapter",
"Adapter index for creating device (-1 for default)", "Adapter index for creating device (-1 for default)",
-1, G_MAXINT32, DEFAULT_ADAPTER, -1, G_MAXINT32, DEFAULT_ADAPTER,
G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY | (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_BACKGROUND, g_object_class_install_property (gobject_class, PROP_BACKGROUND,
g_param_spec_enum ("background", "Background", "Background type", g_param_spec_enum ("background", "Background", "Background type",
GST_TYPE_COMPOSITOR_BACKGROUND, GST_TYPE_COMPOSITOR_BACKGROUND,
DEFAULT_BACKGROUND, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_BACKGROUND,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
gst_type_mark_as_plugin_api (GST_TYPE_D3D11_COMPOSITOR_BIN_PAD, 0); gst_type_mark_as_plugin_api (GST_TYPE_D3D11_COMPOSITOR_BIN_PAD,
gst_type_mark_as_plugin_api (GST_TYPE_D3D11_COMPOSITOR_BIN_INPUT, 0); (GstPluginAPIFlags) 0);
gst_type_mark_as_plugin_api (GST_TYPE_D3D11_COMPOSITOR_BIN_INPUT,
(GstPluginAPIFlags) 0);
} }
static void static void
@ -934,14 +964,15 @@ gst_d3d11_compositor_bin_child_proxy_get_child_by_index (GstChildProxy * proxy,
GST_OBJECT_LOCK (self); GST_OBJECT_LOCK (self);
/* XXX: not exactly thread safe with ordering */ /* XXX: not exactly thread safe with ordering */
if (index < bin->numchildren) { if (index < (guint) bin->numchildren) {
if ((res = g_list_nth_data (bin->children, index))) if ((res = (GObject *) g_list_nth_data (bin->children, index)))
gst_object_ref (res); gst_object_ref (res);
} else { } else {
GstD3D11CompositorBinChain *chain; GstD3D11CompositorBinChain *chain;
if ((chain = if ((chain =
g_list_nth_data (self->input_chains, index - bin->numchildren))) { (GstD3D11CompositorBinChain *) g_list_nth_data (self->input_chains,
res = gst_object_ref (chain->ghost_pad); index - bin->numchildren))) {
res = (GObject *) gst_object_ref (chain->ghost_pad);
} }
} }
GST_OBJECT_UNLOCK (self); GST_OBJECT_UNLOCK (self);
@ -967,7 +998,7 @@ static void
gst_d3d11_compositor_bin_child_proxy_init (gpointer g_iface, gst_d3d11_compositor_bin_child_proxy_init (gpointer g_iface,
gpointer iface_data) gpointer iface_data)
{ {
GstChildProxyInterface *iface = g_iface; GstChildProxyInterface *iface = (GstChildProxyInterface *) g_iface;
iface->get_child_by_index = iface->get_child_by_index =
gst_d3d11_compositor_bin_child_proxy_get_child_by_index; gst_d3d11_compositor_bin_child_proxy_get_child_by_index;

View file

@ -26,9 +26,10 @@
# include <config.h> # include <config.h>
#endif #endif
#include "gstd3d11colorconvert.h" #include "gstd3d11convert.h"
#include "gstd3d11colorconverter.h" #include "gstd3d11converter.h"
#include "gstd3d11videoprocessor.h" #include "gstd3d11videoprocessor.h"
#include "gstd3d11pluginutils.h"
GST_DEBUG_CATEGORY_STATIC (gst_d3d11_convert_debug); GST_DEBUG_CATEGORY_STATIC (gst_d3d11_convert_debug);
#define GST_CAT_DEFAULT gst_d3d11_convert_debug #define GST_CAT_DEFAULT gst_d3d11_convert_debug
@ -64,7 +65,7 @@ struct _GstD3D11BaseConvert
ID3D11RenderTargetView *render_target_view[GST_VIDEO_MAX_PLANES]; ID3D11RenderTargetView *render_target_view[GST_VIDEO_MAX_PLANES];
guint num_output_view; guint num_output_view;
GstD3D11ColorConverter *converter; GstD3D11Converter *converter;
GstD3D11VideoProcessor *processor; GstD3D11VideoProcessor *processor;
gboolean processor_in_use; gboolean processor_in_use;
@ -271,7 +272,8 @@ gst_d3d11_base_convert_class_init (GstD3D11BaseConvertClass * klass)
bfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_d3d11_base_convert_set_info); bfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_d3d11_base_convert_set_info);
gst_type_mark_as_plugin_api (GST_TYPE_D3D11_BASE_CONVERT, 0); gst_type_mark_as_plugin_api (GST_TYPE_D3D11_BASE_CONVERT,
(GstPluginAPIFlags) 0);
} }
static void static void
@ -285,33 +287,19 @@ gst_d3d11_base_convert_clear_shader_resource (GstD3D11BaseConvert * self)
gint i; gint i;
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) { for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
if (self->shader_resource_view[i]) { GST_D3D11_CLEAR_COM (self->shader_resource_view[i]);
ID3D11ShaderResourceView_Release (self->shader_resource_view[i]); GST_D3D11_CLEAR_COM (self->render_target_view[i]);
self->shader_resource_view[i] = NULL;
}
if (self->render_target_view[i]) {
ID3D11RenderTargetView_Release (self->render_target_view[i]);
self->render_target_view[i] = NULL;
}
} }
self->num_input_view = 0; self->num_input_view = 0;
self->num_output_view = 0; self->num_output_view = 0;
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) { for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
if (self->in_texture[i]) { GST_D3D11_CLEAR_COM (self->in_texture[i]);
ID3D11Texture2D_Release (self->in_texture[i]); GST_D3D11_CLEAR_COM (self->out_texture[i]);
self->in_texture[i] = NULL;
}
if (self->out_texture[i]) {
ID3D11Texture2D_Release (self->out_texture[i]);
self->out_texture[i] = NULL;
}
} }
g_clear_pointer (&self->converter, gst_d3d11_color_converter_free); g_clear_pointer (&self->converter, gst_d3d11_converter_free);
g_clear_pointer (&self->processor, gst_d3d11_video_processor_free); g_clear_pointer (&self->processor, gst_d3d11_video_processor_free);
self->processor_in_use = FALSE; self->processor_in_use = FALSE;
@ -402,7 +390,7 @@ score_value (GstBaseTransform * base, const GstVideoFormatInfo * in_info,
{ {
const gchar *fname; const gchar *fname;
const GstVideoFormatInfo *t_info; const GstVideoFormatInfo *t_info;
GstVideoFormatFlags in_flags, t_flags; guint in_flags, t_flags;
gint loss; gint loss;
fname = g_value_get_string (val); fname = g_value_get_string (val);
@ -540,7 +528,7 @@ gst_d3d11_base_convert_fixate_format (GstBaseTransform * trans,
static gboolean static gboolean
subsampling_unchanged (GstVideoInfo * in_info, GstVideoInfo * out_info) subsampling_unchanged (GstVideoInfo * in_info, GstVideoInfo * out_info)
{ {
gint i; guint i;
const GstVideoFormatInfo *in_format, *out_format; const GstVideoFormatInfo *in_format, *out_format;
if (GST_VIDEO_INFO_N_COMPONENTS (in_info) != if (GST_VIDEO_INFO_N_COMPONENTS (in_info) !=
@ -1124,7 +1112,7 @@ gst_d3d11_base_convert_fixate_caps (GstBaseTransform * base,
gst_d3d11_base_convert_fixate_size (base, direction, caps, othercaps); gst_d3d11_base_convert_fixate_size (base, direction, caps, othercaps);
if (gst_caps_get_size (othercaps) == 1) { if (gst_caps_get_size (othercaps) == 1) {
gint i; guint i;
const gchar *format_fields[] = { "format", "colorimetry", "chroma-site" }; const gchar *format_fields[] = { "format", "colorimetry", "chroma-site" };
GstStructure *format_struct = gst_caps_get_structure (format, 0); GstStructure *format_struct = gst_caps_get_structure (format, 0);
GstStructure *fixated_struct; GstStructure *fixated_struct;
@ -1208,8 +1196,8 @@ gst_d3d11_base_convert_propose_allocation (GstBaseTransform * trans,
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config); d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
if (!d3d11_params) { if (!d3d11_params) {
d3d11_params = gst_d3d11_allocation_params_new (filter->device, &info, 0, d3d11_params = gst_d3d11_allocation_params_new (filter->device, &info,
D3D11_BIND_SHADER_RESOURCE); (GstD3D11AllocationFlags) 0, D3D11_BIND_SHADER_RESOURCE);
} else { } else {
/* Set bind flag */ /* Set bind flag */
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&info); i++) { for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&info); i++) {
@ -1258,7 +1246,7 @@ gst_d3d11_base_convert_decide_allocation (GstBaseTransform * trans,
GstD3D11AllocationParams *d3d11_params; GstD3D11AllocationParams *d3d11_params;
gboolean update_pool = FALSE; gboolean update_pool = FALSE;
GstVideoInfo info; GstVideoInfo info;
gint i; guint i;
gst_query_parse_allocation (query, &outcaps, NULL); gst_query_parse_allocation (query, &outcaps, NULL);
@ -1288,7 +1276,8 @@ gst_d3d11_base_convert_decide_allocation (GstBaseTransform * trans,
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config); d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
if (!d3d11_params) { if (!d3d11_params) {
d3d11_params = gst_d3d11_allocation_params_new (filter->device, &info, 0, d3d11_params = gst_d3d11_allocation_params_new (filter->device, &info,
(GstD3D11AllocationFlags) 0,
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET); D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET);
} else { } else {
/* Set bind flag */ /* Set bind flag */
@ -1321,8 +1310,8 @@ static gboolean
create_shader_input_resource (GstD3D11BaseConvert * self, create_shader_input_resource (GstD3D11BaseConvert * self,
GstD3D11Device * device, const GstD3D11Format * format, GstVideoInfo * info) GstD3D11Device * device, const GstD3D11Format * format, GstVideoInfo * info)
{ {
D3D11_TEXTURE2D_DESC texture_desc = { 0, }; D3D11_TEXTURE2D_DESC texture_desc;
D3D11_SHADER_RESOURCE_VIEW_DESC view_desc = { 0 }; D3D11_SHADER_RESOURCE_VIEW_DESC view_desc;
HRESULT hr; HRESULT hr;
ID3D11Device *device_handle; ID3D11Device *device_handle;
ID3D11Texture2D *tex[GST_VIDEO_MAX_PLANES] = { NULL, }; ID3D11Texture2D *tex[GST_VIDEO_MAX_PLANES] = { NULL, };
@ -1332,6 +1321,9 @@ create_shader_input_resource (GstD3D11BaseConvert * self,
if (self->num_input_view) if (self->num_input_view)
return TRUE; return TRUE;
memset (&texture_desc, 0, sizeof (texture_desc));
memset (&view_desc, 0, sizeof (view_desc));
device_handle = gst_d3d11_device_get_device_handle (device); device_handle = gst_d3d11_device_get_device_handle (device);
texture_desc.MipLevels = 1; texture_desc.MipLevels = 1;
@ -1350,8 +1342,7 @@ create_shader_input_resource (GstD3D11BaseConvert * self,
texture_desc.Height = GST_VIDEO_INFO_COMP_HEIGHT (info, i); texture_desc.Height = GST_VIDEO_INFO_COMP_HEIGHT (info, i);
texture_desc.Format = format->resource_format[i]; texture_desc.Format = format->resource_format[i];
hr = ID3D11Device_CreateTexture2D (device_handle, hr = device_handle->CreateTexture2D (&texture_desc, NULL, &tex[i]);
&texture_desc, NULL, &tex[i]);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR_OBJECT (self, "Failed to create texture (0x%x)", (guint) hr); GST_ERROR_OBJECT (self, "Failed to create texture (0x%x)", (guint) hr);
goto error; goto error;
@ -1375,15 +1366,14 @@ create_shader_input_resource (GstD3D11BaseConvert * self,
texture_desc.Height = GST_ROUND_UP_2 (texture_desc.Height); texture_desc.Height = GST_ROUND_UP_2 (texture_desc.Height);
} }
hr = ID3D11Device_CreateTexture2D (device_handle, hr = device_handle->CreateTexture2D (&texture_desc, NULL, &tex[0]);
&texture_desc, NULL, &tex[0]);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR_OBJECT (self, "Failed to create texture (0x%x)", (guint) hr); GST_ERROR_OBJECT (self, "Failed to create texture (0x%x)", (guint) hr);
goto error; goto error;
} }
if (is_semiplanar) { if (is_semiplanar) {
ID3D11Resource_AddRef (tex[0]); tex[0]->AddRef ();
tex[1] = tex[0]; tex[1] = tex[0];
} }
} }
@ -1396,8 +1386,7 @@ create_shader_input_resource (GstD3D11BaseConvert * self,
break; break;
view_desc.Format = format->resource_format[i]; view_desc.Format = format->resource_format[i];
hr = ID3D11Device_CreateShaderResourceView (device_handle, hr = device_handle->CreateShaderResourceView (tex[i], &view_desc, &view[i]);
(ID3D11Resource *) tex[i], &view_desc, &view[i]);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR_OBJECT (self, GST_ERROR_OBJECT (self,
@ -1420,13 +1409,11 @@ create_shader_input_resource (GstD3D11BaseConvert * self,
error: error:
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) { for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
if (view[i]) GST_D3D11_CLEAR_COM (view[i]);
ID3D11ShaderResourceView_Release (view[i]);
} }
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) { for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
if (tex[i]) GST_D3D11_CLEAR_COM (tex[i]);
ID3D11Texture2D_Release (tex[i]);
} }
return FALSE; return FALSE;
@ -1452,7 +1439,7 @@ clear_rtv_color_rgb (GstD3D11BaseConvert * self,
else else
target = clear_color_limited; target = clear_color_limited;
ID3D11DeviceContext_ClearRenderTargetView (context_handle, rtv, target); context_handle->ClearRenderTargetView (rtv, target);
} }
static inline void static inline void
@ -1470,7 +1457,7 @@ clear_rtv_color_vuya (GstD3D11BaseConvert * self,
else else
target = clear_color_limited; target = clear_color_limited;
ID3D11DeviceContext_ClearRenderTargetView (context_handle, rtv, target); context_handle->ClearRenderTargetView (rtv, target);
} }
static inline void static inline void
@ -1490,7 +1477,7 @@ clear_rtv_color_luma (GstD3D11BaseConvert * self,
else else
target = clear_color_limited; target = clear_color_limited;
ID3D11DeviceContext_ClearRenderTargetView (context_handle, rtv, target); context_handle->ClearRenderTargetView (rtv, target);
} }
static inline void static inline void
@ -1499,7 +1486,7 @@ clear_rtv_color_chroma (GstD3D11BaseConvert * self,
{ {
const FLOAT clear_color[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; const FLOAT clear_color[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
ID3D11DeviceContext_ClearRenderTargetView (context_handle, rtv, clear_color); context_handle->ClearRenderTargetView (rtv, clear_color);
} }
static void static void
@ -1533,8 +1520,8 @@ static gboolean
create_shader_output_resource (GstD3D11BaseConvert * self, create_shader_output_resource (GstD3D11BaseConvert * self,
GstD3D11Device * device, const GstD3D11Format * format, GstVideoInfo * info) GstD3D11Device * device, const GstD3D11Format * format, GstVideoInfo * info)
{ {
D3D11_TEXTURE2D_DESC texture_desc = { 0, }; D3D11_TEXTURE2D_DESC texture_desc;
D3D11_RENDER_TARGET_VIEW_DESC view_desc = { 0, }; D3D11_RENDER_TARGET_VIEW_DESC view_desc;
HRESULT hr; HRESULT hr;
ID3D11Device *device_handle; ID3D11Device *device_handle;
ID3D11DeviceContext *context_handle; ID3D11DeviceContext *context_handle;
@ -1545,6 +1532,9 @@ create_shader_output_resource (GstD3D11BaseConvert * self,
if (self->num_output_view) if (self->num_output_view)
return TRUE; return TRUE;
memset (&texture_desc, 0, sizeof (texture_desc));
memset (&view_desc, 0, sizeof (view_desc));
device_handle = gst_d3d11_device_get_device_handle (device); device_handle = gst_d3d11_device_get_device_handle (device);
context_handle = gst_d3d11_device_get_device_context_handle (device); context_handle = gst_d3d11_device_get_device_context_handle (device);
@ -1565,8 +1555,7 @@ create_shader_output_resource (GstD3D11BaseConvert * self,
texture_desc.Height = GST_VIDEO_INFO_COMP_HEIGHT (info, i); texture_desc.Height = GST_VIDEO_INFO_COMP_HEIGHT (info, i);
texture_desc.Format = format->resource_format[i]; texture_desc.Format = format->resource_format[i];
hr = ID3D11Device_CreateTexture2D (device_handle, hr = device_handle->CreateTexture2D (&texture_desc, NULL, &tex[i]);
&texture_desc, NULL, &tex[i]);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR_OBJECT (self, "Failed to create texture (0x%x)", (guint) hr); GST_ERROR_OBJECT (self, "Failed to create texture (0x%x)", (guint) hr);
goto error; goto error;
@ -1590,15 +1579,14 @@ create_shader_output_resource (GstD3D11BaseConvert * self,
texture_desc.Height = GST_ROUND_UP_2 (texture_desc.Height); texture_desc.Height = GST_ROUND_UP_2 (texture_desc.Height);
} }
hr = ID3D11Device_CreateTexture2D (device_handle, hr = device_handle->CreateTexture2D (&texture_desc, NULL, &tex[0]);
&texture_desc, NULL, &tex[0]);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR_OBJECT (self, "Failed to create texture (0x%x)", (guint) hr); GST_ERROR_OBJECT (self, "Failed to create texture (0x%x)", (guint) hr);
goto error; goto error;
} }
if (is_semiplanar) { if (is_semiplanar) {
ID3D11Resource_AddRef (tex[0]); tex[0]->AddRef ();
tex[1] = tex[0]; tex[1] = tex[0];
} }
} }
@ -1610,8 +1598,7 @@ create_shader_output_resource (GstD3D11BaseConvert * self,
break; break;
view_desc.Format = format->resource_format[i]; view_desc.Format = format->resource_format[i];
hr = ID3D11Device_CreateRenderTargetView (device_handle, hr = device_handle->CreateRenderTargetView (tex[i], &view_desc, &view[i]);
(ID3D11Resource *) tex[i], &view_desc, &view[i]);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR_OBJECT (self, GST_ERROR_OBJECT (self,
"Failed to create %dth render target view (0x%x)", i, (guint) hr); "Failed to create %dth render target view (0x%x)", i, (guint) hr);
@ -1636,13 +1623,11 @@ create_shader_output_resource (GstD3D11BaseConvert * self,
error: error:
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) { for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
if (view[i]) GST_D3D11_CLEAR_COM (view[i]);
ID3D11RenderTargetView_Release (view[i]);
} }
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) { for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
if (tex[i]) GST_D3D11_CLEAR_COM (tex[i]);
ID3D11Texture2D_Release (tex[i]);
} }
return FALSE; return FALSE;
@ -1732,8 +1717,7 @@ gst_d3d11_base_convert_set_info (GstD3D11BaseFilter * filter,
goto format_unknown; goto format_unknown;
} }
self->converter = gst_d3d11_color_converter_new (filter->device, self->converter = gst_d3d11_converter_new (filter->device, in_info, out_info);
in_info, out_info);
if (!self->converter) { if (!self->converter) {
GST_ERROR_OBJECT (self, "couldn't set converter"); GST_ERROR_OBJECT (self, "couldn't set converter");
@ -1832,7 +1816,7 @@ gst_d3d11_base_convert_set_info (GstD3D11BaseFilter * filter,
view_port.MinDepth = 0.0f; view_port.MinDepth = 0.0f;
view_port.MaxDepth = 1.0f; view_port.MaxDepth = 1.0f;
gst_d3d11_color_converter_update_viewport (self->converter, &view_port); gst_d3d11_converter_update_viewport (self->converter, &view_port);
return TRUE; return TRUE;
@ -1967,7 +1951,7 @@ gst_d3d11_base_convert_transform (GstBaseTransform * trans,
ID3D11ShaderResourceView *resource_view[GST_VIDEO_MAX_PLANES] = { NULL, }; ID3D11ShaderResourceView *resource_view[GST_VIDEO_MAX_PLANES] = { NULL, };
ID3D11RenderTargetView *render_view[GST_VIDEO_MAX_PLANES] = { NULL, }; ID3D11RenderTargetView *render_view[GST_VIDEO_MAX_PLANES] = { NULL, };
ID3D11RenderTargetView **target_rtv; ID3D11RenderTargetView **target_rtv;
gint i; guint i;
gboolean copy_input = FALSE; gboolean copy_input = FALSE;
gboolean copy_output = FALSE; gboolean copy_output = FALSE;
GstMapInfo in_map[GST_VIDEO_MAX_PLANES]; GstMapInfo in_map[GST_VIDEO_MAX_PLANES];
@ -2027,7 +2011,7 @@ gst_d3d11_base_convert_transform (GstBaseTransform * trans,
subidx = gst_d3d11_memory_get_subresource_index (mem); subidx = gst_d3d11_memory_get_subresource_index (mem);
gst_d3d11_memory_get_texture_desc (mem, &src_desc); gst_d3d11_memory_get_texture_desc (mem, &src_desc);
ID3D11Texture2D_GetDesc (self->in_texture[i], &dst_desc); self->in_texture[i]->GetDesc (&dst_desc);
src_box.left = 0; src_box.left = 0;
src_box.top = 0; src_box.top = 0;
@ -2036,8 +2020,7 @@ gst_d3d11_base_convert_transform (GstBaseTransform * trans,
src_box.right = MIN (src_desc.Width, dst_desc.Width); src_box.right = MIN (src_desc.Width, dst_desc.Width);
src_box.bottom = MIN (src_desc.Height, dst_desc.Height); src_box.bottom = MIN (src_desc.Height, dst_desc.Height);
ID3D11DeviceContext_CopySubresourceRegion (context_handle, context_handle->CopySubresourceRegion (self->in_texture[i], 0, 0, 0, 0,
(ID3D11Resource *) self->in_texture[i], 0, 0, 0, 0,
(ID3D11Resource *) in_map[i].data, subidx, &src_box); (ID3D11Resource *) in_map[i].data, subidx, &src_box);
} }
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
@ -2070,7 +2053,7 @@ gst_d3d11_base_convert_transform (GstBaseTransform * trans,
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
} }
if (!gst_d3d11_color_converter_convert (self->converter, if (!gst_d3d11_converter_convert (self->converter,
copy_input ? self->shader_resource_view : resource_view, copy_input ? self->shader_resource_view : resource_view,
target_rtv, NULL, NULL)) { target_rtv, NULL, NULL)) {
goto conversion_failed; goto conversion_failed;
@ -2086,7 +2069,7 @@ gst_d3d11_base_convert_transform (GstBaseTransform * trans,
D3D11_TEXTURE2D_DESC src_desc; D3D11_TEXTURE2D_DESC src_desc;
D3D11_TEXTURE2D_DESC dst_desc; D3D11_TEXTURE2D_DESC dst_desc;
ID3D11Texture2D_GetDesc (self->out_texture[i], &src_desc); self->out_texture[i]->GetDesc (&src_desc);
subidx = gst_d3d11_memory_get_subresource_index (mem); subidx = gst_d3d11_memory_get_subresource_index (mem);
gst_d3d11_memory_get_texture_desc (mem, &dst_desc); gst_d3d11_memory_get_texture_desc (mem, &dst_desc);
@ -2097,9 +2080,8 @@ gst_d3d11_base_convert_transform (GstBaseTransform * trans,
src_box.right = MIN (src_desc.Width, dst_desc.Width); src_box.right = MIN (src_desc.Width, dst_desc.Width);
src_box.bottom = MIN (src_desc.Height, dst_desc.Height); src_box.bottom = MIN (src_desc.Height, dst_desc.Height);
ID3D11DeviceContext_CopySubresourceRegion (context_handle, context_handle->CopySubresourceRegion ((ID3D11Resource *) out_map[i].data,
(ID3D11Resource *) out_map[i].data, subidx, 0, 0, 0, subidx, 0, 0, 0, self->out_texture[i], 0, &src_box);
(ID3D11Resource *) self->out_texture[i], 0, &src_box);
} }
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
} }

View file

@ -22,13 +22,22 @@
# include <config.h> # include <config.h>
#endif #endif
#include "gstd3d11colorconverter.h" #include "gstd3d11converter.h"
#include "gstd3d11shader.h" #include "gstd3d11shader.h"
#include "gstd3d11pluginutils.h"
#include <wrl.h>
#include <string.h> #include <string.h>
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_colorconverter_debug); /* *INDENT-OFF* */
#define GST_CAT_DEFAULT gst_d3d11_colorconverter_debug using namespace Microsoft::WRL;
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_converter_debug);
#define GST_CAT_DEFAULT gst_d3d11_converter_debug
G_END_DECLS
/* *INDENT-ON* */
#define CONVERTER_MAX_QUADS 2 #define CONVERTER_MAX_QUADS 2
@ -317,7 +326,7 @@ typedef struct
PixelShaderColorTransform transform; PixelShaderColorTransform transform;
} ConvertInfo; } ConvertInfo;
struct _GstD3D11ColorConverter struct _GstD3D11Converter
{ {
GstD3D11Device *device; GstD3D11Device *device;
GstVideoInfo in_info; GstVideoInfo in_info;
@ -419,7 +428,7 @@ color_matrix_scale_components (MatrixData * m, gfloat a1, gfloat a2, gfloat a3)
} }
static void static void
color_matrix_debug (GstD3D11ColorConverter * self, const MatrixData * s) color_matrix_debug (GstD3D11Converter * self, const MatrixData * s)
{ {
GST_DEBUG ("[%f %f %f %f]", GST_DEBUG ("[%f %f %f %f]",
s->dm[0][0], s->dm[0][1], s->dm[0][2], s->dm[0][3]); s->dm[0][0], s->dm[0][1], s->dm[0][2], s->dm[0][3]);
@ -480,7 +489,7 @@ color_matrix_RGB_to_YCbCr (MatrixData * m, gfloat Kr, gfloat Kb)
} }
static void static void
compute_matrix_to_RGB (GstD3D11ColorConverter * self, MatrixData * data, compute_matrix_to_RGB (GstD3D11Converter * self, MatrixData * data,
GstVideoInfo * info) GstVideoInfo * info)
{ {
gdouble Kr = 0, Kb = 0; gdouble Kr = 0, Kb = 0;
@ -503,7 +512,7 @@ compute_matrix_to_RGB (GstD3D11ColorConverter * self, MatrixData * data,
} }
static void static void
compute_matrix_to_YUV (GstD3D11ColorConverter * self, MatrixData * data, compute_matrix_to_YUV (GstD3D11Converter * self, MatrixData * data,
GstVideoInfo * info) GstVideoInfo * info)
{ {
gdouble Kr = 0, Kb = 0; gdouble Kr = 0, Kb = 0;
@ -527,7 +536,7 @@ compute_matrix_to_YUV (GstD3D11ColorConverter * self, MatrixData * data,
} }
static gboolean static gboolean
converter_get_matrix (GstD3D11ColorConverter * self, MatrixData * matrix, converter_get_matrix (GstD3D11Converter * self, MatrixData * matrix,
GstVideoInfo * in_info, GstVideoInfo * out_info) GstVideoInfo * in_info, GstVideoInfo * out_info)
{ {
gboolean same_matrix; gboolean same_matrix;
@ -577,7 +586,7 @@ converter_get_matrix (GstD3D11ColorConverter * self, MatrixData * matrix,
} }
static gboolean static gboolean
setup_convert_info_rgb_to_rgb (GstD3D11ColorConverter * self, setup_convert_info_rgb_to_rgb (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *convert_info = &self->convert_info; ConvertInfo *convert_info = &self->convert_info;
@ -590,7 +599,7 @@ setup_convert_info_rgb_to_rgb (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
get_packed_yuv_components (GstD3D11ColorConverter * self, GstVideoFormat get_packed_yuv_components (GstD3D11Converter * self, GstVideoFormat
format, gchar * y, gchar * u, gchar * v) format, gchar * y, gchar * u, gchar * v)
{ {
switch (format) { switch (format) {
@ -646,7 +655,7 @@ get_packed_yuv_components (GstD3D11ColorConverter * self, GstVideoFormat
} }
static gboolean static gboolean
setup_convert_info_yuv_to_rgb (GstD3D11ColorConverter * self, setup_convert_info_yuv_to_rgb (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -698,7 +707,7 @@ setup_convert_info_yuv_to_rgb (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_rgb_to_yuv (GstD3D11ColorConverter * self, setup_convert_info_rgb_to_yuv (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -740,7 +749,7 @@ setup_convert_info_rgb_to_yuv (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_planar_to_planar (GstD3D11ColorConverter * self, setup_convert_info_planar_to_planar (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -765,7 +774,7 @@ setup_convert_info_planar_to_planar (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_planar_to_semi_planar (GstD3D11ColorConverter * self, setup_convert_info_planar_to_semi_planar (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -787,7 +796,7 @@ setup_convert_info_planar_to_semi_planar (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_semi_planar_to_planar (GstD3D11ColorConverter * self, setup_convert_info_semi_planar_to_planar (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -809,7 +818,7 @@ setup_convert_info_semi_planar_to_planar (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_semi_planar_to_semi_planar (GstD3D11ColorConverter * self, setup_convert_info_semi_planar_to_semi_planar (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -828,7 +837,7 @@ setup_convert_info_semi_planar_to_semi_planar (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_vuya_to_vuya (GstD3D11ColorConverter * self, setup_convert_info_vuya_to_vuya (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -842,7 +851,7 @@ setup_convert_info_vuya_to_vuya (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_vuya_to_planar (GstD3D11ColorConverter * self, setup_convert_info_vuya_to_planar (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -863,7 +872,7 @@ setup_convert_info_vuya_to_planar (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_vuya_to_semi_planar (GstD3D11ColorConverter * self, setup_convert_info_vuya_to_semi_planar (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -880,7 +889,7 @@ setup_convert_info_vuya_to_semi_planar (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_planar_to_vuya (GstD3D11ColorConverter * self, setup_convert_info_planar_to_vuya (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -898,7 +907,7 @@ setup_convert_info_planar_to_vuya (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_packed_yuv_to_vuya (GstD3D11ColorConverter * self, setup_convert_info_packed_yuv_to_vuya (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -918,7 +927,7 @@ setup_convert_info_packed_yuv_to_vuya (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_semi_planar_to_vuya (GstD3D11ColorConverter * self, setup_convert_info_semi_planar_to_vuya (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -932,7 +941,7 @@ setup_convert_info_semi_planar_to_vuya (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_packed_yuv_to_planar (GstD3D11ColorConverter * self, setup_convert_info_packed_yuv_to_planar (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -959,7 +968,7 @@ setup_convert_info_packed_yuv_to_planar (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_packed_yuv_to_semi_planar (GstD3D11ColorConverter * self, setup_convert_info_packed_yuv_to_semi_planar (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
ConvertInfo *info = &self->convert_info; ConvertInfo *info = &self->convert_info;
@ -983,7 +992,7 @@ setup_convert_info_packed_yuv_to_semi_planar (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
setup_convert_info_yuv_to_yuv (GstD3D11ColorConverter * self, setup_convert_info_yuv_to_yuv (GstD3D11Converter * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info)
{ {
gboolean in_planar, out_planar; gboolean in_planar, out_planar;
@ -1042,29 +1051,35 @@ setup_convert_info_yuv_to_yuv (GstD3D11ColorConverter * self,
} }
static gboolean static gboolean
gst_d3d11_color_convert_setup_shader (GstD3D11ColorConverter * self, gst_d3d11_color_convert_setup_shader (GstD3D11Converter * self,
GstD3D11Device * device, GstVideoInfo * in_info, GstVideoInfo * out_info) GstD3D11Device * device, GstVideoInfo * in_info, GstVideoInfo * out_info)
{ {
HRESULT hr; HRESULT hr;
D3D11_SAMPLER_DESC sampler_desc = { 0, }; D3D11_SAMPLER_DESC sampler_desc;
D3D11_INPUT_ELEMENT_DESC input_desc[2] = { 0, }; D3D11_INPUT_ELEMENT_DESC input_desc[2];
D3D11_BUFFER_DESC buffer_desc = { 0, }; D3D11_BUFFER_DESC buffer_desc;
D3D11_MAPPED_SUBRESOURCE map; D3D11_MAPPED_SUBRESOURCE map;
VertexData *vertex_data; VertexData *vertex_data;
WORD *indices; WORD *indices;
ID3D11Device *device_handle; ID3D11Device *device_handle;
ID3D11DeviceContext *context_handle; ID3D11DeviceContext *context_handle;
ConvertInfo *convert_info = &self->convert_info; ConvertInfo *convert_info = &self->convert_info;
ID3D11PixelShader *ps[CONVERTER_MAX_QUADS] = { NULL, NULL }; /* *INDENT-OFF* */
ID3D11VertexShader *vs = NULL; ComPtr<ID3D11PixelShader> ps[CONVERTER_MAX_QUADS];
ID3D11InputLayout *layout = NULL; ComPtr<ID3D11VertexShader> vs;
ID3D11SamplerState *sampler = NULL; ComPtr<ID3D11InputLayout> layout;
ID3D11Buffer *const_buffer = NULL; ComPtr<ID3D11SamplerState> sampler;
ID3D11Buffer *vertex_buffer = NULL; ComPtr<ID3D11Buffer> const_buffer;
ID3D11Buffer *index_buffer = NULL; ComPtr<ID3D11Buffer> vertex_buffer;
ComPtr<ID3D11Buffer> index_buffer;
/* *INDENT-ON* */
const guint index_count = 2 * 3; const guint index_count = 2 * 3;
gboolean ret = TRUE;
gint i; gint i;
gboolean ret;
memset (&sampler_desc, 0, sizeof (sampler_desc));
memset (input_desc, 0, sizeof (input_desc));
memset (&buffer_desc, 0, sizeof (buffer_desc));
device_handle = gst_d3d11_device_get_device_handle (device); device_handle = gst_d3d11_device_get_device_handle (device);
context_handle = gst_d3d11_device_get_device_context_handle (device); context_handle = gst_d3d11_device_get_device_context_handle (device);
@ -1078,11 +1093,10 @@ gst_d3d11_color_convert_setup_shader (GstD3D11ColorConverter * self,
sampler_desc.MinLOD = 0; sampler_desc.MinLOD = 0;
sampler_desc.MaxLOD = D3D11_FLOAT32_MAX; sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
hr = ID3D11Device_CreateSamplerState (device_handle, &sampler_desc, &sampler); hr = device_handle->CreateSamplerState (&sampler_desc, &sampler);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't create sampler state, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't create sampler state, hr: 0x%x", (guint) hr);
ret = FALSE; return FALSE;
goto clear;
} }
for (i = 0; i < CONVERTER_MAX_QUADS; i++) { for (i = 0; i < CONVERTER_MAX_QUADS; i++) {
@ -1101,8 +1115,7 @@ gst_d3d11_color_convert_setup_shader (GstD3D11ColorConverter * self,
ret = gst_d3d11_create_pixel_shader (device, shader_code, &ps[i]); ret = gst_d3d11_create_pixel_shader (device, shader_code, &ps[i]);
g_free (shader_code); g_free (shader_code);
if (!ret) { if (!ret) {
GST_ERROR ("Couldn't create pixel shader"); return FALSE;
goto clear;
} }
} }
} }
@ -1117,31 +1130,26 @@ gst_d3d11_color_convert_setup_shader (GstD3D11ColorConverter * self,
const_buffer_desc.MiscFlags = 0; const_buffer_desc.MiscFlags = 0;
const_buffer_desc.StructureByteStride = 0; const_buffer_desc.StructureByteStride = 0;
hr = ID3D11Device_CreateBuffer (device_handle, &const_buffer_desc, NULL, hr = device_handle->CreateBuffer (&const_buffer_desc, NULL, &const_buffer);
&const_buffer);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't create constant buffer, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't create constant buffer, hr: 0x%x", (guint) hr);
ret = FALSE; return FALSE;
goto clear;
} }
gst_d3d11_device_lock (device); gst_d3d11_device_lock (device);
hr = ID3D11DeviceContext_Map (context_handle, hr = context_handle->Map (const_buffer.Get (),
(ID3D11Resource *) const_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't map constant buffer, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't map constant buffer, hr: 0x%x", (guint) hr);
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
ret = FALSE; return FALSE;
goto clear;
} }
memcpy (map.pData, &convert_info->transform, memcpy (map.pData, &convert_info->transform,
sizeof (PixelShaderColorTransform)); sizeof (PixelShaderColorTransform));
ID3D11DeviceContext_Unmap (context_handle, context_handle->Unmap (const_buffer.Get (), 0);
(ID3D11Resource *) const_buffer, 0);
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
} }
@ -1164,8 +1172,7 @@ gst_d3d11_color_convert_setup_shader (GstD3D11ColorConverter * self,
if (!gst_d3d11_create_vertex_shader (device, templ_vertex_shader, if (!gst_d3d11_create_vertex_shader (device, templ_vertex_shader,
input_desc, G_N_ELEMENTS (input_desc), &vs, &layout)) { input_desc, G_N_ELEMENTS (input_desc), &vs, &layout)) {
GST_ERROR ("Couldn't vertex pixel shader"); GST_ERROR ("Couldn't vertex pixel shader");
ret = FALSE; return FALSE;
goto clear;
} }
/* setup vertext buffer and index buffer */ /* setup vertext buffer and index buffer */
@ -1174,13 +1181,10 @@ gst_d3d11_color_convert_setup_shader (GstD3D11ColorConverter * self,
buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
hr = ID3D11Device_CreateBuffer (device_handle, &buffer_desc, NULL, hr = device_handle->CreateBuffer (&buffer_desc, NULL, &vertex_buffer);
&vertex_buffer);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't create vertex buffer, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't create vertex buffer, hr: 0x%x", (guint) hr);
ret = FALSE; return FALSE;
goto clear;
} }
buffer_desc.Usage = D3D11_USAGE_DYNAMIC; buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
@ -1188,38 +1192,30 @@ gst_d3d11_color_convert_setup_shader (GstD3D11ColorConverter * self,
buffer_desc.BindFlags = D3D11_BIND_INDEX_BUFFER; buffer_desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
hr = ID3D11Device_CreateBuffer (device_handle, &buffer_desc, NULL, hr = device_handle->CreateBuffer (&buffer_desc, NULL, &index_buffer);
&index_buffer);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't create index buffer, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't create index buffer, hr: 0x%x", (guint) hr);
ret = FALSE; return FALSE;
goto clear;
} }
gst_d3d11_device_lock (device); gst_d3d11_device_lock (device);
hr = ID3D11DeviceContext_Map (context_handle, hr = context_handle->Map (vertex_buffer.Get (), 0, D3D11_MAP_WRITE_DISCARD, 0,
(ID3D11Resource *) vertex_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); &map);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't map vertex buffer, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't map vertex buffer, hr: 0x%x", (guint) hr);
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
ret = FALSE; return FALSE;
goto clear;
} }
vertex_data = (VertexData *) map.pData; vertex_data = (VertexData *) map.pData;
hr = ID3D11DeviceContext_Map (context_handle, hr = context_handle->Map (index_buffer.Get (), 0, D3D11_MAP_WRITE_DISCARD, 0,
(ID3D11Resource *) index_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); &map);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't map index buffer, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't map index buffer, hr: 0x%x", (guint) hr);
ID3D11DeviceContext_Unmap (context_handle, context_handle->Unmap (vertex_buffer.Get (), 0);
(ID3D11Resource *) vertex_buffer, 0);
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
ret = FALSE; return FALSE;
goto clear;
} }
indices = (WORD *) map.pData; indices = (WORD *) map.pData;
@ -1261,28 +1257,27 @@ gst_d3d11_color_convert_setup_shader (GstD3D11ColorConverter * self,
indices[4] = 0; /* bottom left */ indices[4] = 0; /* bottom left */
indices[5] = 2; /* top right */ indices[5] = 2; /* top right */
ID3D11DeviceContext_Unmap (context_handle, context_handle->Unmap (vertex_buffer.Get (), 0);
(ID3D11Resource *) vertex_buffer, 0); context_handle->Unmap (index_buffer.Get (), 0);
ID3D11DeviceContext_Unmap (context_handle,
(ID3D11Resource *) index_buffer, 0);
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
self->quad[0] = gst_d3d11_quad_new (device, self->quad[0] = gst_d3d11_quad_new (device,
ps[0], vs, layout, sampler, NULL, NULL, const_buffer, vertex_buffer, ps[0].Get (), vs.Get (), layout.Get (), sampler.Get (), NULL, NULL,
sizeof (VertexData), index_buffer, DXGI_FORMAT_R16_UINT, index_count); const_buffer.Get (), vertex_buffer.Get (), sizeof (VertexData),
index_buffer.Get (), DXGI_FORMAT_R16_UINT, index_count);
if (ps[1]) { if (ps[1]) {
self->quad[1] = gst_d3d11_quad_new (device, self->quad[1] = gst_d3d11_quad_new (device,
ps[1], vs, layout, sampler, NULL, NULL, const_buffer, vertex_buffer, ps[1].Get (), vs.Get (), layout.Get (), sampler.Get (), NULL, NULL,
sizeof (VertexData), index_buffer, DXGI_FORMAT_R16_UINT, index_count); const_buffer.Get (), vertex_buffer.Get (), sizeof (VertexData),
index_buffer.Get (), DXGI_FORMAT_R16_UINT, index_count);
} }
self->num_input_view = GST_VIDEO_INFO_N_PLANES (in_info); self->num_input_view = GST_VIDEO_INFO_N_PLANES (in_info);
self->num_output_view = GST_VIDEO_INFO_N_PLANES (out_info); self->num_output_view = GST_VIDEO_INFO_N_PLANES (out_info);
/* holds vertex buffer for crop rect update */ /* holds vertex buffer for crop rect update */
self->vertex_buffer = vertex_buffer; self->vertex_buffer = vertex_buffer.Detach ();
ID3D11Buffer_AddRef (vertex_buffer);
self->src_rect.left = 0; self->src_rect.left = 0;
self->src_rect.top = 0; self->src_rect.top = 0;
@ -1297,29 +1292,11 @@ gst_d3d11_color_convert_setup_shader (GstD3D11ColorConverter * self,
self->input_texture_width = GST_VIDEO_INFO_WIDTH (in_info); self->input_texture_width = GST_VIDEO_INFO_WIDTH (in_info);
self->input_texture_height = GST_VIDEO_INFO_HEIGHT (in_info); self->input_texture_height = GST_VIDEO_INFO_HEIGHT (in_info);
clear: return TRUE;
for (i = 0; i < CONVERTER_MAX_QUADS; i++) {
if (ps[i])
ID3D11PixelShader_Release (ps[i]);
}
if (vs)
ID3D11VertexShader_Release (vs);
if (layout)
ID3D11InputLayout_Release (layout);
if (sampler)
ID3D11SamplerState_Release (sampler);
if (const_buffer)
ID3D11Buffer_Release (const_buffer);
if (vertex_buffer)
ID3D11Buffer_Release (vertex_buffer);
if (index_buffer)
ID3D11Buffer_Release (index_buffer);
return ret;
} }
static GstD3D11ColorConverter * static GstD3D11Converter *
gst_d3d11_color_converter_new_internal (GstD3D11Device * device, gst_d3d11_converter_new_internal (GstD3D11Device * device,
GstVideoInfo * in_info, GstVideoInfo * out_info, gfloat alpha) GstVideoInfo * in_info, GstVideoInfo * out_info, gfloat alpha)
{ {
const GstVideoInfo *unknown_info; const GstVideoInfo *unknown_info;
@ -1327,9 +1304,9 @@ gst_d3d11_color_converter_new_internal (GstD3D11Device * device,
const GstD3D11Format *out_d3d11_format; const GstD3D11Format *out_d3d11_format;
gboolean is_supported = FALSE; gboolean is_supported = FALSE;
MatrixData matrix; MatrixData matrix;
GstD3D11ColorConverter *converter = NULL; GstD3D11Converter *converter = NULL;
gboolean ret; gboolean ret;
gint i; guint i;
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL); g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL);
g_return_val_if_fail (in_info != NULL, NULL); g_return_val_if_fail (in_info != NULL, NULL);
@ -1355,8 +1332,8 @@ gst_d3d11_color_converter_new_internal (GstD3D11Device * device,
goto format_unknown; goto format_unknown;
} }
converter = g_new0 (GstD3D11ColorConverter, 1); converter = g_new0 (GstD3D11Converter, 1);
converter->device = gst_object_ref (device); converter->device = (GstD3D11Device *) gst_object_ref (device);
converter->alpha = alpha; converter->alpha = alpha;
if (GST_VIDEO_INFO_IS_RGB (in_info)) { if (GST_VIDEO_INFO_IS_RGB (in_info)) {
@ -1413,7 +1390,7 @@ gst_d3d11_color_converter_new_internal (GstD3D11Device * device,
if (!ret) { if (!ret) {
GST_ERROR ("Couldn't setup shader"); GST_ERROR ("Couldn't setup shader");
gst_d3d11_color_converter_free (converter); gst_d3d11_converter_free (converter);
converter = NULL; converter = NULL;
} else { } else {
converter->in_info = *in_info; converter->in_info = *in_info;
@ -1434,32 +1411,30 @@ conversion_not_supported:
GST_ERROR ("Conversion %s to %s not supported", GST_ERROR ("Conversion %s to %s not supported",
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (in_info)), gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (in_info)),
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (out_info))); gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (out_info)));
gst_d3d11_color_converter_free (converter); gst_d3d11_converter_free (converter);
return NULL; return NULL;
} }
} }
GstD3D11ColorConverter * GstD3D11Converter *
gst_d3d11_color_converter_new (GstD3D11Device * device, gst_d3d11_converter_new (GstD3D11Device * device,
GstVideoInfo * in_info, GstVideoInfo * out_info) GstVideoInfo * in_info, GstVideoInfo * out_info)
{ {
return gst_d3d11_color_converter_new_internal (device, in_info, out_info, return gst_d3d11_converter_new_internal (device, in_info, out_info, 1.0f);
1.0f);
} }
GstD3D11ColorConverter * GstD3D11Converter *
gst_d3d11_color_converter_new_with_alpha (GstD3D11Device * device, gst_d3d11_converter_new_with_alpha (GstD3D11Device * device,
GstVideoInfo * in_info, GstVideoInfo * out_info, gfloat alpha) GstVideoInfo * in_info, GstVideoInfo * out_info, gfloat alpha)
{ {
g_return_val_if_fail (alpha >= 0.0f, NULL); g_return_val_if_fail (alpha >= 0.0f, NULL);
g_return_val_if_fail (alpha <= 1.0f, NULL); g_return_val_if_fail (alpha <= 1.0f, NULL);
return gst_d3d11_color_converter_new_internal (device, in_info, out_info, return gst_d3d11_converter_new_internal (device, in_info, out_info, alpha);
alpha);
} }
void void
gst_d3d11_color_converter_free (GstD3D11ColorConverter * converter) gst_d3d11_converter_free (GstD3D11Converter * converter)
{ {
gint i; gint i;
@ -1472,8 +1447,7 @@ gst_d3d11_color_converter_free (GstD3D11ColorConverter * converter)
g_free (converter->convert_info.ps_body[i]); g_free (converter->convert_info.ps_body[i]);
} }
if (converter->vertex_buffer) GST_D3D11_CLEAR_COM (converter->vertex_buffer);
ID3D11Buffer_Release (converter->vertex_buffer);
gst_clear_object (&converter->device); gst_clear_object (&converter->device);
g_free (converter); g_free (converter);
@ -1482,7 +1456,7 @@ gst_d3d11_color_converter_free (GstD3D11ColorConverter * converter)
/* must be called with gst_d3d11_device_lock since ID3D11DeviceContext is not /* must be called with gst_d3d11_device_lock since ID3D11DeviceContext is not
* thread-safe */ * thread-safe */
static gboolean static gboolean
gst_d3d11_color_converter_update_vertex_buffer (GstD3D11ColorConverter * self) gst_d3d11_converter_update_vertex_buffer (GstD3D11Converter * self)
{ {
D3D11_MAPPED_SUBRESOURCE map; D3D11_MAPPED_SUBRESOURCE map;
VertexData *vertex_data; VertexData *vertex_data;
@ -1498,8 +1472,7 @@ gst_d3d11_color_converter_update_vertex_buffer (GstD3D11ColorConverter * self)
context_handle = gst_d3d11_device_get_device_context_handle (self->device); context_handle = gst_d3d11_device_get_device_context_handle (self->device);
hr = ID3D11DeviceContext_Map (context_handle, hr = context_handle->Map (self->vertex_buffer, 0, D3D11_MAP_WRITE_DISCARD,
(ID3D11Resource *) self->vertex_buffer, 0, D3D11_MAP_WRITE_DISCARD,
0, &map); 0, &map);
if (!gst_d3d11_result (hr, self->device)) { if (!gst_d3d11_result (hr, self->device)) {
@ -1566,8 +1539,7 @@ gst_d3d11_color_converter_update_vertex_buffer (GstD3D11ColorConverter * self)
vertex_data[3].texture.x = u; vertex_data[3].texture.x = u;
vertex_data[3].texture.y = v; vertex_data[3].texture.y = v;
ID3D11DeviceContext_Unmap (context_handle, context_handle->Unmap (self->vertex_buffer, 0);
(ID3D11Resource *) self->vertex_buffer, 0);
self->update_vertex = FALSE; self->update_vertex = FALSE;
@ -1575,7 +1547,7 @@ gst_d3d11_color_converter_update_vertex_buffer (GstD3D11ColorConverter * self)
} }
gboolean gboolean
gst_d3d11_color_converter_convert (GstD3D11ColorConverter * converter, gst_d3d11_converter_convert (GstD3D11Converter * converter,
ID3D11ShaderResourceView * srv[GST_VIDEO_MAX_PLANES], ID3D11ShaderResourceView * srv[GST_VIDEO_MAX_PLANES],
ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES], ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES],
ID3D11BlendState * blend, gfloat blend_factor[4]) ID3D11BlendState * blend, gfloat blend_factor[4])
@ -1587,7 +1559,7 @@ gst_d3d11_color_converter_convert (GstD3D11ColorConverter * converter,
g_return_val_if_fail (rtv != NULL, FALSE); g_return_val_if_fail (rtv != NULL, FALSE);
gst_d3d11_device_lock (converter->device); gst_d3d11_device_lock (converter->device);
ret = gst_d3d11_color_converter_convert_unlocked (converter, ret = gst_d3d11_converter_convert_unlocked (converter,
srv, rtv, blend, blend_factor); srv, rtv, blend, blend_factor);
gst_d3d11_device_unlock (converter->device); gst_d3d11_device_unlock (converter->device);
@ -1595,13 +1567,16 @@ gst_d3d11_color_converter_convert (GstD3D11ColorConverter * converter,
} }
gboolean gboolean
gst_d3d11_color_converter_convert_unlocked (GstD3D11ColorConverter * converter, gst_d3d11_converter_convert_unlocked (GstD3D11Converter * converter,
ID3D11ShaderResourceView * srv[GST_VIDEO_MAX_PLANES], ID3D11ShaderResourceView * srv[GST_VIDEO_MAX_PLANES],
ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES], ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES],
ID3D11BlendState * blend, gfloat blend_factor[4]) ID3D11BlendState * blend, gfloat blend_factor[4])
{ {
gboolean ret; gboolean ret;
ID3D11Resource *resource; /* *INDENT-OFF* */
ComPtr<ID3D11Resource> resource;
ComPtr<ID3D11Texture2D> texture;
/* *INDENT-ON* */
D3D11_TEXTURE2D_DESC desc; D3D11_TEXTURE2D_DESC desc;
g_return_val_if_fail (converter != NULL, FALSE); g_return_val_if_fail (converter != NULL, FALSE);
@ -1609,20 +1584,20 @@ gst_d3d11_color_converter_convert_unlocked (GstD3D11ColorConverter * converter,
g_return_val_if_fail (rtv != NULL, FALSE); g_return_val_if_fail (rtv != NULL, FALSE);
/* check texture resolution and update crop area */ /* check texture resolution and update crop area */
ID3D11ShaderResourceView_GetResource (srv[0], &resource); srv[0]->GetResource (&resource);
ID3D11Texture2D_GetDesc ((ID3D11Texture2D *) resource, &desc); resource.As (&texture);
ID3D11Resource_Release (resource); texture->GetDesc (&desc);
if (converter->update_vertex || if (converter->update_vertex ||
desc.Width != converter->input_texture_width || desc.Width != (guint) converter->input_texture_width ||
desc.Height != converter->input_texture_height) { desc.Height != (guint) converter->input_texture_height) {
GST_DEBUG ("Update vertext buffer, texture resolution: %dx%d", GST_DEBUG ("Update vertext buffer, texture resolution: %dx%d",
desc.Width, desc.Height); desc.Width, desc.Height);
converter->input_texture_width = desc.Width; converter->input_texture_width = desc.Width;
converter->input_texture_height = desc.Height; converter->input_texture_height = desc.Height;
if (!gst_d3d11_color_converter_update_vertex_buffer (converter)) { if (!gst_d3d11_converter_update_vertex_buffer (converter)) {
GST_ERROR ("Cannot update vertex buffer"); GST_ERROR ("Cannot update vertex buffer");
return FALSE; return FALSE;
} }
@ -1648,7 +1623,7 @@ gst_d3d11_color_converter_convert_unlocked (GstD3D11ColorConverter * converter,
} }
gboolean gboolean
gst_d3d11_color_converter_update_viewport (GstD3D11ColorConverter * converter, gst_d3d11_converter_update_viewport (GstD3D11Converter * converter,
D3D11_VIEWPORT * viewport) D3D11_VIEWPORT * viewport)
{ {
g_return_val_if_fail (converter != NULL, FALSE); g_return_val_if_fail (converter != NULL, FALSE);
@ -1662,7 +1637,7 @@ gst_d3d11_color_converter_update_viewport (GstD3D11ColorConverter * converter,
case GST_VIDEO_FORMAT_P016_LE: case GST_VIDEO_FORMAT_P016_LE:
case GST_VIDEO_FORMAT_I420: case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_I420_10LE:{ case GST_VIDEO_FORMAT_I420_10LE:{
gint i; guint i;
converter->viewport[1].TopLeftX = converter->viewport[0].TopLeftX / 2; converter->viewport[1].TopLeftX = converter->viewport[0].TopLeftX / 2;
converter->viewport[1].TopLeftY = converter->viewport[0].TopLeftY / 2; converter->viewport[1].TopLeftY = converter->viewport[0].TopLeftY / 2;
converter->viewport[1].Width = converter->viewport[0].Width / 2; converter->viewport[1].Width = converter->viewport[0].Width / 2;
@ -1683,7 +1658,7 @@ gst_d3d11_color_converter_update_viewport (GstD3D11ColorConverter * converter,
} }
gboolean gboolean
gst_d3d11_color_converter_update_src_rect (GstD3D11ColorConverter * converter, gst_d3d11_converter_update_src_rect (GstD3D11Converter * converter,
RECT * src_rect) RECT * src_rect)
{ {
g_return_val_if_fail (converter != NULL, FALSE); g_return_val_if_fail (converter != NULL, FALSE);
@ -1703,7 +1678,7 @@ gst_d3d11_color_converter_update_src_rect (GstD3D11ColorConverter * converter,
} }
gboolean gboolean
gst_d3d11_color_converter_update_dest_rect (GstD3D11ColorConverter * converter, gst_d3d11_converter_update_dest_rect (GstD3D11Converter * converter,
RECT * dest_rect) RECT * dest_rect)
{ {
g_return_val_if_fail (converter != NULL, FALSE); g_return_val_if_fail (converter != NULL, FALSE);

View file

@ -0,0 +1,65 @@
/* GStreamer
* Copyright (C) <2019> Seungha Yang <seungha.yang@navercorp.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_D3D11_COLOR_CONVERTER_H__
#define __GST_D3D11_COLOR_CONVERTER_H__
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/d3d11/gstd3d11.h>
G_BEGIN_DECLS
typedef struct _GstD3D11Converter GstD3D11Converter;
GstD3D11Converter * gst_d3d11_converter_new (GstD3D11Device * device,
GstVideoInfo * in_info,
GstVideoInfo * out_info);
GstD3D11Converter * gst_d3d11_converter_new_with_alpha (GstD3D11Device * device,
GstVideoInfo * in_info,
GstVideoInfo * out_info,
gfloat alpha);
void gst_d3d11_converter_free (GstD3D11Converter * converter);
gboolean gst_d3d11_converter_convert (GstD3D11Converter * converter,
ID3D11ShaderResourceView *srv[GST_VIDEO_MAX_PLANES],
ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES],
ID3D11BlendState *blend,
gfloat blend_factor[4]);
gboolean gst_d3d11_converter_convert_unlocked (GstD3D11Converter * converter,
ID3D11ShaderResourceView *srv[GST_VIDEO_MAX_PLANES],
ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES],
ID3D11BlendState *blend,
gfloat blend_factor[4]);
gboolean gst_d3d11_converter_update_viewport (GstD3D11Converter * converter,
D3D11_VIEWPORT * viewport);
gboolean gst_d3d11_converter_update_src_rect (GstD3D11Converter * converter,
RECT * src_rect);
gboolean gst_d3d11_converter_update_dest_rect (GstD3D11Converter * converter,
RECT * dest_rect);
G_END_DECLS
#endif /* __GST_D3D11_COLOR_CONVERTER_H__ */

View file

@ -52,7 +52,7 @@
#endif #endif
#include "gstd3d11decoder.h" #include "gstd3d11decoder.h"
#include "gstd3d11colorconverter.h" #include "gstd3d11converter.h"
#include "gstd3d11pluginutils.h" #include "gstd3d11pluginutils.h"
#include <string.h> #include <string.h>
@ -81,8 +81,8 @@ struct _GstD3D11DecoderPrivate
GstBufferPool *internal_pool; GstBufferPool *internal_pool;
/* Internal pool params */ /* Internal pool params */
guint aligned_width; gint aligned_width;
guint aligned_height; gint aligned_height;
gboolean use_array_of_texture; gboolean use_array_of_texture;
guint dpb_size; guint dpb_size;
guint downstream_min_buffers; guint downstream_min_buffers;
@ -98,7 +98,7 @@ struct _GstD3D11DecoderPrivate
gboolean can_direct_rendering; gboolean can_direct_rendering;
/* for internal shader */ /* for internal shader */
GstD3D11ColorConverter *converter; GstD3D11Converter *converter;
ID3D11Texture2D *shader_resource_texture; ID3D11Texture2D *shader_resource_texture;
ID3D11ShaderResourceView *shader_resource_view[GST_VIDEO_MAX_PLANES]; ID3D11ShaderResourceView *shader_resource_view[GST_VIDEO_MAX_PLANES];
ID3D11Texture2D *fallback_shader_output_texture; ID3D11Texture2D *fallback_shader_output_texture;
@ -131,7 +131,8 @@ gst_d3d11_decoder_class_init (GstD3D11DecoderClass * klass)
g_object_class_install_property (gobject_class, PROP_DEVICE, g_object_class_install_property (gobject_class, PROP_DEVICE,
g_param_spec_object ("device", "Device", g_param_spec_object ("device", "Device",
"D3D11 Devicd to use", GST_TYPE_D3D11_DEVICE, "D3D11 Devicd to use", GST_TYPE_D3D11_DEVICE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)));
GST_DEBUG_CATEGORY_INIT (d3d11_decoder_debug, GST_DEBUG_CATEGORY_INIT (d3d11_decoder_debug,
"d3d11decoder", 0, "Direct3D11 Base Video Decoder object"); "d3d11decoder", 0, "Direct3D11 Base Video Decoder object");
@ -140,7 +141,8 @@ gst_d3d11_decoder_class_init (GstD3D11DecoderClass * klass)
static void static void
gst_d3d11_decoder_init (GstD3D11Decoder * self) gst_d3d11_decoder_init (GstD3D11Decoder * self)
{ {
self->priv = gst_d3d11_decoder_get_instance_private (self); self->priv =
(GstD3D11DecoderPrivate *) gst_d3d11_decoder_get_instance_private (self);
} }
static void static void
@ -161,9 +163,7 @@ gst_d3d11_decoder_constructed (GObject * object)
device_context_handle = device_context_handle =
gst_d3d11_device_get_device_context_handle (priv->device); gst_d3d11_device_get_device_context_handle (priv->device);
hr = ID3D11Device_QueryInterface (device_handle, &IID_ID3D11VideoDevice, hr = device_handle->QueryInterface (IID_PPV_ARGS (&priv->video_device));
(void **) &priv->video_device);
if (!gst_d3d11_result (hr, priv->device) || !priv->video_device) { if (!gst_d3d11_result (hr, priv->device) || !priv->video_device) {
GST_WARNING_OBJECT (self, "Cannot create VideoDevice Object: 0x%x", GST_WARNING_OBJECT (self, "Cannot create VideoDevice Object: 0x%x",
(guint) hr); (guint) hr);
@ -172,9 +172,8 @@ gst_d3d11_decoder_constructed (GObject * object)
return; return;
} }
hr = ID3D11DeviceContext_QueryInterface (device_context_handle, hr = device_context_handle->
&IID_ID3D11VideoContext, (void **) &priv->video_context); QueryInterface (IID_PPV_ARGS (&priv->video_context));
if (!gst_d3d11_result (hr, priv->device) || !priv->video_context) { if (!gst_d3d11_result (hr, priv->device) || !priv->video_context) {
GST_WARNING_OBJECT (self, "Cannot create VideoContext Object: 0x%x", GST_WARNING_OBJECT (self, "Cannot create VideoContext Object: 0x%x",
(guint) hr); (guint) hr);
@ -186,15 +185,8 @@ gst_d3d11_decoder_constructed (GObject * object)
return; return;
fail: fail:
if (priv->video_device) { GST_D3D11_CLEAR_COM (priv->video_device);
ID3D11VideoDevice_Release (priv->video_device); GST_D3D11_CLEAR_COM (priv->video_context);
priv->video_device = NULL;
}
if (priv->video_context) {
ID3D11VideoContext_Release (priv->video_context);
priv->video_context = NULL;
}
return; return;
} }
@ -208,7 +200,7 @@ gst_d3d11_decoder_set_property (GObject * object, guint prop_id,
switch (prop_id) { switch (prop_id) {
case PROP_DEVICE: case PROP_DEVICE:
priv->device = g_value_dup_object (value); priv->device = (GstD3D11Device *) g_value_dup_object (value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -240,15 +232,8 @@ gst_d3d11_decoder_close (GstD3D11Decoder * self)
gst_d3d11_decoder_reset (self); gst_d3d11_decoder_reset (self);
if (priv->video_device) { GST_D3D11_CLEAR_COM (priv->video_device);
ID3D11VideoDevice_Release (priv->video_device); GST_D3D11_CLEAR_COM (priv->video_context);
priv->video_device = NULL;
}
if (priv->video_context) {
ID3D11VideoContext_Release (priv->video_context);
priv->video_context = NULL;
}
return TRUE; return TRUE;
} }
@ -262,42 +247,18 @@ gst_d3d11_decoder_reset_unlocked (GstD3D11Decoder * decoder)
priv = decoder->priv; priv = decoder->priv;
gst_clear_object (&priv->internal_pool); gst_clear_object (&priv->internal_pool);
if (priv->decoder) { GST_D3D11_CLEAR_COM (priv->decoder);
ID3D11VideoDecoder_Release (priv->decoder); GST_D3D11_CLEAR_COM (priv->staging);
priv->decoder = NULL;
}
if (priv->staging) { g_clear_pointer (&priv->converter, gst_d3d11_converter_free);
ID3D11Texture2D_Release (priv->staging);
priv->staging = NULL;
}
if (priv->converter) {
gst_d3d11_color_converter_free (priv->converter);
priv->converter = NULL;
}
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) { for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
if (priv->shader_resource_view[i]) { GST_D3D11_CLEAR_COM (priv->shader_resource_view[i]);
ID3D11ShaderResourceView_Release (priv->shader_resource_view[i]); GST_D3D11_CLEAR_COM (priv->fallback_render_target_view[i]);
priv->shader_resource_view[i] = NULL;
}
if (priv->fallback_render_target_view[i]) {
ID3D11RenderTargetView_Release (priv->fallback_render_target_view[i]);
priv->fallback_render_target_view[i] = NULL;
}
} }
if (priv->shader_resource_texture) { GST_D3D11_CLEAR_COM (priv->shader_resource_texture);
ID3D11Texture2D_Release (priv->shader_resource_texture); GST_D3D11_CLEAR_COM (priv->fallback_shader_output_texture);
priv->shader_resource_texture = NULL;
}
if (priv->fallback_shader_output_texture) {
ID3D11Texture2D_Release (priv->fallback_shader_output_texture);
priv->fallback_shader_output_texture = NULL;
}
priv->dpb_size = 0; priv->dpb_size = 0;
priv->downstream_min_buffers = 0; priv->downstream_min_buffers = 0;
@ -341,7 +302,8 @@ gst_d3d11_decoder_new (GstD3D11Device * device)
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL); g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL);
decoder = g_object_new (GST_TYPE_D3D11_DECODER, "device", device, NULL); decoder = (GstD3D11Decoder *)
g_object_new (GST_TYPE_D3D11_DECODER, "device", device, NULL);
priv = decoder->priv; priv = decoder->priv;
if (!priv->video_device || !priv->video_context) { if (!priv->video_device || !priv->video_context) {
@ -379,7 +341,7 @@ gst_d3d11_decoder_prepare_output_view_pool (GstD3D11Decoder * self)
GstBufferPool *pool = NULL; GstBufferPool *pool = NULL;
GstCaps *caps = NULL; GstCaps *caps = NULL;
GstVideoAlignment align; GstVideoAlignment align;
GstD3D11AllocationFlags alloc_flags = 0; GstD3D11AllocationFlags alloc_flags = (GstD3D11AllocationFlags) 0;
gint bind_flags = D3D11_BIND_DECODER; gint bind_flags = D3D11_BIND_DECODER;
GstVideoInfo *info = &priv->info; GstVideoInfo *info = &priv->info;
guint pool_size; guint pool_size;
@ -462,8 +424,9 @@ gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Decoder * decoder,
GUID *guid_list = NULL; GUID *guid_list = NULL;
const GUID *profile = NULL; const GUID *profile = NULL;
guint available_profile_count; guint available_profile_count;
gint i, j; guint i, j;
HRESULT hr; HRESULT hr;
ID3D11VideoDevice *video_device;
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE); g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
g_return_val_if_fail (decoder_profiles != NULL, FALSE); g_return_val_if_fail (decoder_profiles != NULL, FALSE);
@ -471,9 +434,9 @@ gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Decoder * decoder,
g_return_val_if_fail (selected_profile != NULL, FALSE); g_return_val_if_fail (selected_profile != NULL, FALSE);
priv = decoder->priv; priv = decoder->priv;
video_device = priv->video_device;
available_profile_count = available_profile_count = video_device->GetVideoDecoderProfileCount ();
ID3D11VideoDevice_GetVideoDecoderProfileCount (priv->video_device);
if (available_profile_count == 0) { if (available_profile_count == 0) {
GST_WARNING_OBJECT (decoder, "No available decoder profile"); GST_WARNING_OBJECT (decoder, "No available decoder profile");
@ -482,11 +445,10 @@ gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Decoder * decoder,
GST_DEBUG_OBJECT (decoder, GST_DEBUG_OBJECT (decoder,
"Have %u available decoder profiles", available_profile_count); "Have %u available decoder profiles", available_profile_count);
guid_list = g_alloca (sizeof (GUID) * available_profile_count); guid_list = (GUID *) g_alloca (sizeof (GUID) * available_profile_count);
for (i = 0; i < available_profile_count; i++) { for (i = 0; i < available_profile_count; i++) {
hr = ID3D11VideoDevice_GetVideoDecoderProfile (priv->video_device, hr = video_device->GetVideoDecoderProfile (i, &guid_list[i]);
i, &guid_list[i]);
if (!gst_d3d11_result (hr, priv->device)) { if (!gst_d3d11_result (hr, priv->device)) {
GST_WARNING_OBJECT (decoder, "Failed to get %d th decoder profile", i); GST_WARNING_OBJECT (decoder, "Failed to get %d th decoder profile", i);
return FALSE; return FALSE;
@ -519,7 +481,7 @@ gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Decoder * decoder,
for (i = 0; i < profile_size; i++) { for (i = 0; i < profile_size; i++) {
for (j = 0; j < available_profile_count; j++) { for (j = 0; j < available_profile_count; j++) {
if (IsEqualGUID (decoder_profiles[i], &guid_list[j])) { if (IsEqualGUID (*decoder_profiles[i], guid_list[j])) {
profile = decoder_profiles[i]; profile = decoder_profiles[i];
break; break;
} }
@ -548,7 +510,7 @@ gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Decoder * decoder,
gboolean gboolean
gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec, gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
GstVideoInfo * info, guint coded_width, guint coded_height, GstVideoInfo * info, gint coded_width, gint coded_height,
guint dpb_size, const GUID ** decoder_profiles, guint profile_size) guint dpb_size, const GUID ** decoder_profiles, guint profile_size)
{ {
GstD3D11DecoderPrivate *priv; GstD3D11DecoderPrivate *priv;
@ -561,11 +523,12 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
D3D11_VIDEO_DECODER_DESC decoder_desc = { 0, }; D3D11_VIDEO_DECODER_DESC decoder_desc = { 0, };
D3D11_TEXTURE2D_DESC staging_desc = { 0, }; D3D11_TEXTURE2D_DESC staging_desc = { 0, };
GUID selected_profile; GUID selected_profile;
gint i; guint i;
guint aligned_width, aligned_height; gint aligned_width, aligned_height;
guint alignment; guint alignment;
GstD3D11DeviceVendor vendor; GstD3D11DeviceVendor vendor;
ID3D11Device *device_handle; ID3D11Device *device_handle;
ID3D11VideoDevice *video_device;
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE); g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
g_return_val_if_fail (codec > GST_D3D11_CODEC_NONE, FALSE); g_return_val_if_fail (codec > GST_D3D11_CODEC_NONE, FALSE);
@ -582,6 +545,7 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
priv->use_array_of_texture = FALSE; priv->use_array_of_texture = FALSE;
device_handle = gst_d3d11_device_get_device_handle (priv->device); device_handle = gst_d3d11_device_get_device_handle (priv->device);
video_device = priv->video_device;
d3d11_format = gst_d3d11_device_format_from_gst (priv->device, d3d11_format = gst_d3d11_device_format_from_gst (priv->device,
GST_VIDEO_INFO_FORMAT (info)); GST_VIDEO_INFO_FORMAT (info));
@ -597,8 +561,8 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
goto error; goto error;
} }
hr = ID3D11VideoDevice_CheckVideoDecoderFormat (priv->video_device, hr = video_device->CheckVideoDecoderFormat (&selected_profile,
&selected_profile, d3d11_format->dxgi_format, &can_support); d3d11_format->dxgi_format, &can_support);
if (!gst_d3d11_result (hr, priv->device) || !can_support) { if (!gst_d3d11_result (hr, priv->device) || !can_support) {
GST_ERROR_OBJECT (decoder, GST_ERROR_OBJECT (decoder,
"VideoDevice could not support dxgi format %d, hr: 0x%x", "VideoDevice could not support dxgi format %d, hr: 0x%x",
@ -660,8 +624,7 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
decoder_desc.OutputFormat = d3d11_format->dxgi_format; decoder_desc.OutputFormat = d3d11_format->dxgi_format;
decoder_desc.Guid = selected_profile; decoder_desc.Guid = selected_profile;
hr = ID3D11VideoDevice_GetVideoDecoderConfigCount (priv->video_device, hr = video_device->GetVideoDecoderConfigCount (&decoder_desc, &config_count);
&decoder_desc, &config_count);
if (!gst_d3d11_result (hr, priv->device) || config_count == 0) { if (!gst_d3d11_result (hr, priv->device) || config_count == 0) {
GST_ERROR_OBJECT (decoder, "Could not get decoder config count, hr: 0x%x", GST_ERROR_OBJECT (decoder, "Could not get decoder config count, hr: 0x%x",
(guint) hr); (guint) hr);
@ -670,11 +633,12 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
GST_DEBUG_OBJECT (decoder, "Total %d config available", config_count); GST_DEBUG_OBJECT (decoder, "Total %d config available", config_count);
config_list = g_alloca (sizeof (D3D11_VIDEO_DECODER_CONFIG) * config_count); config_list = (D3D11_VIDEO_DECODER_CONFIG *)
g_alloca (sizeof (D3D11_VIDEO_DECODER_CONFIG) * config_count);
for (i = 0; i < config_count; i++) { for (i = 0; i < config_count; i++) {
hr = ID3D11VideoDevice_GetVideoDecoderConfig (priv->video_device, hr = video_device->GetVideoDecoderConfig (&decoder_desc, i,
&decoder_desc, i, &config_list[i]); &config_list[i]);
if (!gst_d3d11_result (hr, priv->device)) { if (!gst_d3d11_result (hr, priv->device)) {
GST_ERROR_OBJECT (decoder, "Could not get decoder %dth config, hr: 0x%x", GST_ERROR_OBJECT (decoder, "Could not get decoder %dth config, hr: 0x%x",
i, (guint) hr); i, (guint) hr);
@ -725,8 +689,8 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
} }
#endif #endif
hr = ID3D11VideoDevice_CreateVideoDecoder (priv->video_device, hr = video_device->CreateVideoDecoder (&decoder_desc,
&decoder_desc, best_config, &priv->decoder); best_config, &priv->decoder);
if (!gst_d3d11_result (hr, priv->device) || !priv->decoder) { if (!gst_d3d11_result (hr, priv->device) || !priv->decoder) {
GST_ERROR_OBJECT (decoder, GST_ERROR_OBJECT (decoder,
"Could not create decoder object, hr: 0x%x", (guint) hr); "Could not create decoder object, hr: 0x%x", (guint) hr);
@ -748,8 +712,7 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
staging_desc.Usage = D3D11_USAGE_STAGING; staging_desc.Usage = D3D11_USAGE_STAGING;
staging_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; staging_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
hr = ID3D11Device_CreateTexture2D (device_handle, &staging_desc, NULL, hr = device_handle->CreateTexture2D (&staging_desc, NULL, &priv->staging);
&priv->staging);
if (!gst_d3d11_result (hr, priv->device)) { if (!gst_d3d11_result (hr, priv->device)) {
GST_ERROR_OBJECT (decoder, "Couldn't create staging texture"); GST_ERROR_OBJECT (decoder, "Couldn't create staging texture");
goto error; goto error;
@ -786,13 +749,17 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
* Need to VP8 here when VP8 support is added * Need to VP8 here when VP8 support is added
*/ */
if (codec == GST_D3D11_CODEC_VP9) { if (codec == GST_D3D11_CODEC_VP9) {
D3D11_TEXTURE2D_DESC texture_desc = { 0, }; D3D11_TEXTURE2D_DESC texture_desc;
D3D11_RENDER_TARGET_VIEW_DESC render_desc = { 0, }; D3D11_RENDER_TARGET_VIEW_DESC render_desc;
D3D11_SHADER_RESOURCE_VIEW_DESC resource_desc = { 0, }; D3D11_SHADER_RESOURCE_VIEW_DESC resource_desc;
ID3D11Device *device_handle; ID3D11Device *device_handle;
D3D11_VIEWPORT viewport; D3D11_VIEWPORT viewport;
priv->converter = gst_d3d11_color_converter_new (priv->device, info, info); memset (&texture_desc, 0, sizeof (texture_desc));
memset (&render_desc, 0, sizeof (render_desc));
memset (&resource_desc, 0, sizeof (resource_desc));
priv->converter = gst_d3d11_converter_new (priv->device, info, info);
viewport.TopLeftX = 0; viewport.TopLeftX = 0;
viewport.TopLeftY = 0; viewport.TopLeftY = 0;
@ -800,7 +767,7 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
viewport.Height = priv->display_height; viewport.Height = priv->display_height;
viewport.MinDepth = 0.0f; viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f; viewport.MaxDepth = 1.0f;
gst_d3d11_color_converter_update_viewport (priv->converter, &viewport); gst_d3d11_converter_update_viewport (priv->converter, &viewport);
device_handle = gst_d3d11_device_get_device_handle (priv->device); device_handle = gst_d3d11_device_get_device_handle (priv->device);
@ -813,7 +780,7 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
texture_desc.Usage = D3D11_USAGE_DEFAULT; texture_desc.Usage = D3D11_USAGE_DEFAULT;
texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET; texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
hr = ID3D11Device_CreateTexture2D (device_handle, &texture_desc, NULL, hr = device_handle->CreateTexture2D (&texture_desc, NULL,
&priv->fallback_shader_output_texture); &priv->fallback_shader_output_texture);
if (!gst_d3d11_result (hr, priv->device)) { if (!gst_d3d11_result (hr, priv->device)) {
GST_ERROR_OBJECT (decoder, "Couldn't create shader output texture"); GST_ERROR_OBJECT (decoder, "Couldn't create shader output texture");
@ -821,7 +788,7 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
} }
texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
hr = ID3D11Device_CreateTexture2D (device_handle, &texture_desc, NULL, hr = device_handle->CreateTexture2D (&texture_desc, NULL,
&priv->shader_resource_texture); &priv->shader_resource_texture);
if (!gst_d3d11_result (hr, priv->device)) { if (!gst_d3d11_result (hr, priv->device)) {
GST_ERROR_OBJECT (decoder, "Couldn't create shader input texture"); GST_ERROR_OBJECT (decoder, "Couldn't create shader input texture");
@ -865,9 +832,9 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
for (i = 0; i < priv->num_resource_views; i++) { for (i = 0; i < priv->num_resource_views; i++) {
render_desc.Format = priv->resource_formats[i]; render_desc.Format = priv->resource_formats[i];
hr = ID3D11Device_CreateRenderTargetView (device_handle, hr = device_handle->
(ID3D11Resource *) priv->fallback_shader_output_texture, &render_desc, CreateRenderTargetView (priv->fallback_shader_output_texture,
&priv->fallback_render_target_view[i]); &render_desc, &priv->fallback_render_target_view[i]);
if (!gst_d3d11_result (hr, priv->device)) { if (!gst_d3d11_result (hr, priv->device)) {
GST_ERROR_OBJECT (decoder, GST_ERROR_OBJECT (decoder,
"Failed to create %dth render target view (0x%x)", i, (guint) hr); "Failed to create %dth render target view (0x%x)", i, (guint) hr);
@ -880,9 +847,9 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec,
for (i = 0; i < priv->num_resource_views; i++) { for (i = 0; i < priv->num_resource_views; i++) {
resource_desc.Format = priv->resource_formats[i]; resource_desc.Format = priv->resource_formats[i];
hr = ID3D11Device_CreateShaderResourceView (device_handle, hr = device_handle->
(ID3D11Resource *) priv->shader_resource_texture, &resource_desc, CreateShaderResourceView (priv->shader_resource_texture,
&priv->shader_resource_view[i]); &resource_desc, &priv->shader_resource_view[i]);
if (!gst_d3d11_result (hr, priv->device)) { if (!gst_d3d11_result (hr, priv->device)) {
GST_ERROR_OBJECT (decoder, GST_ERROR_OBJECT (decoder,
@ -920,8 +887,8 @@ gst_d3d11_decoder_begin_frame (GstD3D11Decoder * decoder,
do { do {
GST_LOG_OBJECT (decoder, "Try begin frame, retry count %d", retry_count); GST_LOG_OBJECT (decoder, "Try begin frame, retry count %d", retry_count);
gst_d3d11_device_lock (priv->device); gst_d3d11_device_lock (priv->device);
hr = ID3D11VideoContext_DecoderBeginFrame (priv->video_context, hr = priv->video_context->DecoderBeginFrame (priv->decoder,
priv->decoder, output_view, content_key_size, content_key); output_view, content_key_size, content_key);
gst_d3d11_device_unlock (priv->device); gst_d3d11_device_unlock (priv->device);
/* HACK: Do 100 times retry with 1ms sleep per failure, since DXVA/D3D11 /* HACK: Do 100 times retry with 1ms sleep per failure, since DXVA/D3D11
@ -962,7 +929,7 @@ gst_d3d11_decoder_end_frame (GstD3D11Decoder * decoder)
priv = decoder->priv; priv = decoder->priv;
gst_d3d11_device_lock (priv->device); gst_d3d11_device_lock (priv->device);
hr = ID3D11VideoContext_DecoderEndFrame (priv->video_context, priv->decoder); hr = priv->video_context->DecoderEndFrame (priv->decoder);
gst_d3d11_device_unlock (priv->device); gst_d3d11_device_unlock (priv->device);
if (!gst_d3d11_result (hr, priv->device)) { if (!gst_d3d11_result (hr, priv->device)) {
@ -988,8 +955,8 @@ gst_d3d11_decoder_get_decoder_buffer (GstD3D11Decoder * decoder,
priv = decoder->priv; priv = decoder->priv;
gst_d3d11_device_lock (priv->device); gst_d3d11_device_lock (priv->device);
hr = ID3D11VideoContext_GetDecoderBuffer (priv->video_context, hr = priv->video_context->GetDecoderBuffer (priv->decoder,
priv->decoder, type, &size, &decoder_buffer); type, &size, &decoder_buffer);
gst_d3d11_device_unlock (priv->device); gst_d3d11_device_unlock (priv->device);
if (!gst_d3d11_result (hr, priv->device)) { if (!gst_d3d11_result (hr, priv->device)) {
@ -1016,8 +983,7 @@ gst_d3d11_decoder_release_decoder_buffer (GstD3D11Decoder * decoder,
priv = decoder->priv; priv = decoder->priv;
gst_d3d11_device_lock (priv->device); gst_d3d11_device_lock (priv->device);
hr = ID3D11VideoContext_ReleaseDecoderBuffer (priv->video_context, hr = priv->video_context->ReleaseDecoderBuffer (priv->decoder, type);
priv->decoder, type);
gst_d3d11_device_unlock (priv->device); gst_d3d11_device_unlock (priv->device);
if (!gst_d3d11_result (hr, priv->device)) { if (!gst_d3d11_result (hr, priv->device)) {
@ -1041,8 +1007,8 @@ gst_d3d11_decoder_submit_decoder_buffers (GstD3D11Decoder * decoder,
priv = decoder->priv; priv = decoder->priv;
gst_d3d11_device_lock (priv->device); gst_d3d11_device_lock (priv->device);
hr = ID3D11VideoContext_SubmitDecoderBuffers (priv->video_context, hr = priv->video_context->SubmitDecoderBuffers (priv->decoder, buffer_count,
priv->decoder, buffer_count, buffers); buffers);
gst_d3d11_device_unlock (priv->device); gst_d3d11_device_unlock (priv->device);
if (!gst_d3d11_result (hr, priv->device)) { if (!gst_d3d11_result (hr, priv->device)) {
@ -1142,7 +1108,7 @@ gst_d3d11_decoder_get_output_view_index (ID3D11VideoDecoderOutputView *
g_return_val_if_fail (view_handle != NULL, 0xff); g_return_val_if_fail (view_handle != NULL, 0xff);
ID3D11VideoDecoderOutputView_GetDesc (view_handle, &view_desc); view_handle->GetDesc (&view_desc);
return view_desc.Texture2D.ArraySlice; return view_desc.Texture2D.ArraySlice;
} }
@ -1154,7 +1120,7 @@ copy_to_system (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width,
{ {
GstD3D11DecoderPrivate *priv = self->priv; GstD3D11DecoderPrivate *priv = self->priv;
GstVideoFrame out_frame; GstVideoFrame out_frame;
gint i; guint i;
GstD3D11Memory *in_mem; GstD3D11Memory *in_mem;
D3D11_MAPPED_SUBRESOURCE map; D3D11_MAPPED_SUBRESOURCE map;
HRESULT hr; HRESULT hr;
@ -1206,9 +1172,8 @@ copy_to_system (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width,
/* copy decoded texture into shader resource texture */ /* copy decoded texture into shader resource texture */
GST_TRACE_OBJECT (self, GST_TRACE_OBJECT (self,
"Copy decoded texture to internal shader texture"); "Copy decoded texture to internal shader texture");
ID3D11DeviceContext_CopySubresourceRegion (device_context, device_context->CopySubresourceRegion (priv->shader_resource_texture,
(ID3D11Resource *) priv->shader_resource_texture, 0, 0, 0, 0, 0, 0, 0, 0, in_texture, in_subresource_index, &src_box);
(ID3D11Resource *) in_texture, in_subresource_index, &src_box);
for (i = 0; i < priv->num_resource_views; i++) for (i = 0; i < priv->num_resource_views; i++)
srv[i] = priv->shader_resource_view[i]; srv[i] = priv->shader_resource_view[i];
@ -1219,9 +1184,9 @@ copy_to_system (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width,
rect.right = display_width; rect.right = display_width;
rect.bottom = display_height; rect.bottom = display_height;
gst_d3d11_color_converter_update_src_rect (priv->converter, &rect); gst_d3d11_converter_update_src_rect (priv->converter, &rect);
if (!gst_d3d11_color_converter_convert_unlocked (priv->converter, if (!gst_d3d11_converter_convert_unlocked (priv->converter,
srv, priv->fallback_render_target_view, NULL, NULL)) { srv, priv->fallback_render_target_view, NULL, NULL)) {
GST_ERROR_OBJECT (self, "Failed to convert"); GST_ERROR_OBJECT (self, "Failed to convert");
goto error; goto error;
@ -1231,12 +1196,10 @@ copy_to_system (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width,
in_subresource_index = 0; in_subresource_index = 0;
} }
ID3D11DeviceContext_CopySubresourceRegion (device_context, device_context->CopySubresourceRegion (priv->staging, 0, 0, 0, 0,
(ID3D11Resource *) priv->staging, 0, 0, 0, 0, in_texture, in_subresource_index, NULL);
(ID3D11Resource *) in_texture, in_subresource_index, NULL);
hr = ID3D11DeviceContext_Map (device_context, hr = device_context->Map (priv->staging, 0, D3D11_MAP_READ, 0, &map);
(ID3D11Resource *) priv->staging, 0, D3D11_MAP_READ, 0, &map);
if (!gst_d3d11_result (hr, priv->device)) { if (!gst_d3d11_result (hr, priv->device)) {
GST_ERROR_OBJECT (self, "Failed to map, hr: 0x%x", (guint) hr); GST_ERROR_OBJECT (self, "Failed to map, hr: 0x%x", (guint) hr);
@ -1248,7 +1211,7 @@ copy_to_system (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width,
D3D11_TEXTURE2D_DESC desc; D3D11_TEXTURE2D_DESC desc;
gsize dummy; gsize dummy;
ID3D11Texture2D_GetDesc (priv->staging, &desc); priv->staging->GetDesc (&desc);
gst_d3d11_dxgi_format_get_size (desc.Format, desc.Width, desc.Height, gst_d3d11_dxgi_format_get_size (desc.Format, desc.Width, desc.Height,
map.RowPitch, priv->staging_texture_offset, map.RowPitch, priv->staging_texture_offset,
@ -1261,7 +1224,7 @@ copy_to_system (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width,
gint width; gint width;
src = (guint8 *) map.pData + priv->staging_texture_offset[i]; src = (guint8 *) map.pData + priv->staging_texture_offset[i];
dst = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, i); dst = (guint8 *) GST_VIDEO_FRAME_PLANE_DATA (&out_frame, i);
width = GST_VIDEO_FRAME_COMP_WIDTH (&out_frame, i) * width = GST_VIDEO_FRAME_COMP_WIDTH (&out_frame, i) *
GST_VIDEO_FRAME_COMP_PSTRIDE (&out_frame, i); GST_VIDEO_FRAME_COMP_PSTRIDE (&out_frame, i);
@ -1273,8 +1236,7 @@ copy_to_system (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width,
} }
gst_video_frame_unmap (&out_frame); gst_video_frame_unmap (&out_frame);
ID3D11DeviceContext_Unmap (device_context, (ID3D11Resource *) priv->staging, device_context->Unmap (priv->staging, 0);
0);
gst_d3d11_device_unlock (priv->device); gst_d3d11_device_unlock (priv->device);
return TRUE; return TRUE;
@ -1304,7 +1266,7 @@ copy_to_d3d11 (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width,
out_mem = (GstD3D11Memory *) gst_buffer_peek_memory (output, 0); out_mem = (GstD3D11Memory *) gst_buffer_peek_memory (output, 0);
if (!gst_memory_map (GST_MEMORY_CAST (out_mem), if (!gst_memory_map (GST_MEMORY_CAST (out_mem),
&out_map, GST_MAP_WRITE | GST_MAP_D3D11)) { &out_map, (GstMapFlags) (GST_MAP_WRITE | GST_MAP_D3D11))) {
GST_ERROR_OBJECT (self, "Couldn't map output d3d11 memory"); GST_ERROR_OBJECT (self, "Couldn't map output d3d11 memory");
return FALSE; return FALSE;
} }
@ -1358,9 +1320,8 @@ copy_to_d3d11 (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width,
/* copy decoded texture into shader resource texture */ /* copy decoded texture into shader resource texture */
GST_TRACE_OBJECT (self, GST_TRACE_OBJECT (self,
"Copy decoded texture to internal shader texture"); "Copy decoded texture to internal shader texture");
ID3D11DeviceContext_CopySubresourceRegion (device_context, device_context->CopySubresourceRegion (priv->shader_resource_texture,
(ID3D11Resource *) priv->shader_resource_texture, 0, 0, 0, 0, 0, 0, 0, 0, in_texture, in_subresource_index, &src_box);
(ID3D11Resource *) in_texture, in_subresource_index, &src_box);
for (i = 0; i < priv->num_resource_views; i++) for (i = 0; i < priv->num_resource_views; i++)
srv[i] = priv->shader_resource_view[i]; srv[i] = priv->shader_resource_view[i];
@ -1371,9 +1332,9 @@ copy_to_d3d11 (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width,
rect.right = display_width; rect.right = display_width;
rect.bottom = display_height; rect.bottom = display_height;
gst_d3d11_color_converter_update_src_rect (priv->converter, &rect); gst_d3d11_converter_update_src_rect (priv->converter, &rect);
if (!gst_d3d11_color_converter_convert_unlocked (priv->converter, if (!gst_d3d11_converter_convert_unlocked (priv->converter,
srv, rtv, NULL, NULL)) { srv, rtv, NULL, NULL)) {
GST_ERROR_OBJECT (self, "Failed to convert"); GST_ERROR_OBJECT (self, "Failed to convert");
ret = FALSE; ret = FALSE;
@ -1393,9 +1354,9 @@ copy_to_d3d11 (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width,
src_box.bottom = GST_ROUND_UP_2 (priv->display_height); src_box.bottom = GST_ROUND_UP_2 (priv->display_height);
out_subresource_index = gst_d3d11_memory_get_subresource_index (out_mem); out_subresource_index = gst_d3d11_memory_get_subresource_index (out_mem);
ID3D11DeviceContext_CopySubresourceRegion (device_context, device_context->CopySubresourceRegion ((ID3D11Resource *) out_map.data,
(ID3D11Resource *) out_map.data, out_subresource_index, 0, 0, 0, out_subresource_index, 0, 0, 0, in_texture, in_subresource_index,
(ID3D11Resource *) in_texture, in_subresource_index, &src_box); &src_box);
ret = TRUE; ret = TRUE;
@ -1628,7 +1589,8 @@ gst_d3d11_decoder_decide_allocation (GstVideoDecoder * decoder,
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config); d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
if (!d3d11_params) if (!d3d11_params)
d3d11_params = gst_d3d11_allocation_params_new (device, &vinfo, 0, 0); d3d11_params = gst_d3d11_allocation_params_new (device, &vinfo,
(GstD3D11AllocationFlags) 0, 0);
width = GST_VIDEO_INFO_WIDTH (&vinfo); width = GST_VIDEO_INFO_WIDTH (&vinfo);
height = GST_VIDEO_INFO_HEIGHT (&vinfo); height = GST_VIDEO_INFO_HEIGHT (&vinfo);
@ -1824,8 +1786,8 @@ gst_d3d11_decoder_supports_format (GstD3D11Decoder * decoder,
priv = decoder->priv; priv = decoder->priv;
hr = ID3D11VideoDevice_CheckVideoDecoderFormat (priv->video_device, hr = priv->video_device->CheckVideoDecoderFormat (decoder_profile, format,
decoder_profile, format, &can_support); &can_support);
if (!gst_d3d11_result (hr, priv->device) || !can_support) { if (!gst_d3d11_result (hr, priv->device) || !can_support) {
GST_DEBUG_OBJECT (decoder, GST_DEBUG_OBJECT (decoder,
"VideoDevice could not support dxgi format %d, hr: 0x%x", "VideoDevice could not support dxgi format %d, hr: 0x%x",
@ -1858,8 +1820,7 @@ gst_d3d11_decoder_supports_resolution (GstD3D11Decoder * decoder,
desc.OutputFormat = format; desc.OutputFormat = format;
desc.Guid = *decoder_profile; desc.Guid = *decoder_profile;
hr = ID3D11VideoDevice_GetVideoDecoderConfigCount (priv->video_device, hr = priv->video_device->GetVideoDecoderConfigCount (&desc, &config_count);
&desc, &config_count);
if (!gst_d3d11_result (hr, priv->device) || config_count == 0) { if (!gst_d3d11_result (hr, priv->device) || config_count == 0) {
GST_DEBUG_OBJECT (decoder, "Could not get decoder config count, hr: 0x%x", GST_DEBUG_OBJECT (decoder, "Could not get decoder config count, hr: 0x%x",
(guint) hr); (guint) hr);

View file

@ -72,8 +72,8 @@ GstD3D11Decoder * gst_d3d11_decoder_new (GstD3D11Device * device);
gboolean gst_d3d11_decoder_open (GstD3D11Decoder * decoder, gboolean gst_d3d11_decoder_open (GstD3D11Decoder * decoder,
GstD3D11Codec codec, GstD3D11Codec codec,
GstVideoInfo * info, GstVideoInfo * info,
guint codec_width, gint codec_width,
guint codec_height, gint codec_height,
guint dpb_size, guint dpb_size,
const GUID ** decoder_profiles, const GUID ** decoder_profiles,
guint profile_size); guint profile_size);

View file

@ -660,15 +660,8 @@ gst_d3d11_deinterlace_reset (GstD3D11Deinterlace * self)
self->fallback_out_pool = NULL; self->fallback_out_pool = NULL;
} }
if (self->video_enum) { GST_D3D11_CLEAR_COM (self->video_enum);
self->video_enum->Release (); GST_D3D11_CLEAR_COM (self->video_proc);
self->video_enum = NULL;
}
if (self->video_proc) {
self->video_proc->Release ();
self->video_proc = NULL;
}
gst_d3d11_deinterlace_reset_history (self); gst_d3d11_deinterlace_reset_history (self);
self->default_buffer_duration = GST_CLOCK_TIME_NONE; self->default_buffer_duration = GST_CLOCK_TIME_NONE;
@ -681,15 +674,8 @@ gst_d3d11_deinterlace_close (GstD3D11Deinterlace * self)
{ {
gst_d3d11_deinterlace_reset (self); gst_d3d11_deinterlace_reset (self);
if (self->video_device) { GST_D3D11_CLEAR_COM (self->video_device);
self->video_device->Release (); GST_D3D11_CLEAR_COM (self->video_context);
self->video_device = NULL;
}
if (self->video_context) {
self->video_context->Release ();
self->video_context = NULL;
}
gst_clear_object (&self->device); gst_clear_object (&self->device);
} }

View file

@ -48,6 +48,7 @@
#include "gstd3d11desktopdup.h" #include "gstd3d11desktopdup.h"
#include "gstd3d11shader.h" #include "gstd3d11shader.h"
#include "gstd3d11pluginutils.h"
#include <string.h> #include <string.h>
#include <wrl.h> #include <wrl.h>
@ -1620,10 +1621,7 @@ gst_d3d11_desktop_dup_dispose (GObject * object)
{ {
GstD3D11DesktopDup *self = GST_D3D11_DESKTOP_DUP (object); GstD3D11DesktopDup *self = GST_D3D11_DESKTOP_DUP (object);
if (self->texture) { GST_D3D11_CLEAR_COM (self->texture);
self->texture->Release ();
self->texture = nullptr;
}
if (self->dupl_obj) { if (self->dupl_obj) {
delete self->dupl_obj; delete self->dupl_obj;

View file

@ -42,9 +42,15 @@
#include <string.h> #include <string.h>
/* *INDENT-OFF* */
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_desktop_dup_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_desktop_dup_debug);
#define GST_CAT_DEFAULT gst_d3d11_desktop_dup_debug #define GST_CAT_DEFAULT gst_d3d11_desktop_dup_debug
G_END_DECLS
/* *INDENT-ON* */
enum enum
{ {
PROP_0, PROP_0,
@ -131,12 +137,14 @@ gst_d3d11_desktop_dup_src_class_init (GstD3D11DesktopDupSrcClass * klass)
g_param_spec_int ("monitor-index", "Monitor Index", g_param_spec_int ("monitor-index", "Monitor Index",
"Zero-based index for monitor to capture (-1 = primary monitor)", "Zero-based index for monitor to capture (-1 = primary monitor)",
-1, G_MAXINT, DEFAULT_MONITOR_INDEX, -1, G_MAXINT, DEFAULT_MONITOR_INDEX,
G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY | G_PARAM_STATIC_STRINGS); (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY |
G_PARAM_STATIC_STRINGS));
properties[PROP_SHOW_CURSOR] = properties[PROP_SHOW_CURSOR] =
g_param_spec_boolean ("show-cursor", g_param_spec_boolean ("show-cursor",
"Show Mouse Cursor", "Whether to show mouse cursor", "Show Mouse Cursor", "Whether to show mouse cursor",
DEFAULT_SHOW_CURSOR, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); DEFAULT_SHOW_CURSOR,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (gobject_class, PROP_LAST, properties); g_object_class_install_properties (gobject_class, PROP_LAST, properties);
@ -356,8 +364,8 @@ gst_d3d11_desktop_dup_src_decide_allocation (GstBaseSrc * bsrc,
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config); d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
if (!d3d11_params) { if (!d3d11_params) {
d3d11_params = gst_d3d11_allocation_params_new (self->device, &vinfo, 0, d3d11_params = gst_d3d11_allocation_params_new (self->device, &vinfo,
D3D11_BIND_RENDER_TARGET); (GstD3D11AllocationFlags) 0, D3D11_BIND_RENDER_TARGET);
} else { } else {
d3d11_params->desc[0].BindFlags |= D3D11_BIND_RENDER_TARGET; d3d11_params->desc[0].BindFlags |= D3D11_BIND_RENDER_TARGET;
} }
@ -497,7 +505,7 @@ gst_d3d11_desktop_dup_src_fill (GstPushSrc * pushsrc, GstBuffer * buffer)
GstClockTime latency; GstClockTime latency;
GstClockTime dur; GstClockTime dur;
gboolean update_latency = FALSE; gboolean update_latency = FALSE;
gint64 next_frame_no; guint64 next_frame_no;
gboolean draw_mouse; gboolean draw_mouse;
if (!self->dupl) { if (!self->dupl) {
@ -538,7 +546,7 @@ again:
if (next_frame_no == self->last_frame_no) { if (next_frame_no == self->last_frame_no) {
GstClockID id; GstClockID id;
GstClockReturn ret; GstClockReturn clock_ret;
/* Need to wait for the next frame */ /* Need to wait for the next frame */
next_frame_no += 1; next_frame_no += 1;
@ -556,13 +564,13 @@ again:
GST_LOG_OBJECT (self, "Waiting for next frame time %" GST_TIME_FORMAT, GST_LOG_OBJECT (self, "Waiting for next frame time %" GST_TIME_FORMAT,
GST_TIME_ARGS (next_capture_ts)); GST_TIME_ARGS (next_capture_ts));
ret = gst_clock_id_wait (id, NULL); clock_ret = gst_clock_id_wait (id, NULL);
GST_OBJECT_LOCK (self); GST_OBJECT_LOCK (self);
gst_clock_id_unref (id); gst_clock_id_unref (id);
self->clock_id = NULL; self->clock_id = NULL;
if (ret == GST_CLOCK_UNSCHEDULED) { if (clock_ret == GST_CLOCK_UNSCHEDULED) {
/* Got woken up by the unlock function */ /* Got woken up by the unlock function */
ret = GST_FLOW_FLUSHING; ret = GST_FLOW_FLUSHING;
GST_OBJECT_UNLOCK (self); GST_OBJECT_UNLOCK (self);
@ -599,7 +607,8 @@ again:
goto out; goto out;
} }
if (!gst_memory_map (mem, &info, GST_MAP_WRITE | GST_MAP_D3D11)) { if (!gst_memory_map (mem, &info,
(GstMapFlags) (GST_MAP_WRITE | GST_MAP_D3D11))) {
GST_ERROR_OBJECT (self, "Failed to map d3d11 memory"); GST_ERROR_OBJECT (self, "Failed to map d3d11 memory");
ret = GST_FLOW_ERROR; ret = GST_FLOW_ERROR;
goto out; goto out;

View file

@ -398,7 +398,7 @@ gst_d3d11_download_transform (GstBaseTransform * trans, GstBuffer * inbuf,
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
gboolean use_staging_buf; gboolean use_staging_buf;
GstBuffer *target_inbuf = inbuf; GstBuffer *target_inbuf = inbuf;
gint i; guint i;
use_staging_buf = gst_d3d11_download_can_use_staging_buffer (self, inbuf); use_staging_buf = gst_d3d11_download_can_use_staging_buffer (self, inbuf);
@ -417,11 +417,11 @@ gst_d3d11_download_transform (GstBaseTransform * trans, GstBuffer * inbuf,
} }
if (!gst_video_frame_map (&in_frame, &filter->in_info, target_inbuf, if (!gst_video_frame_map (&in_frame, &filter->in_info, target_inbuf,
GST_MAP_READ | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)) (GstMapFlags) (GST_MAP_READ | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)))
goto invalid_buffer; goto invalid_buffer;
if (!gst_video_frame_map (&out_frame, &filter->out_info, outbuf, if (!gst_video_frame_map (&out_frame, &filter->out_info, outbuf,
GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)) { (GstMapFlags) (GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF))) {
gst_video_frame_unmap (&in_frame); gst_video_frame_unmap (&in_frame);
goto invalid_buffer; goto invalid_buffer;
} }

View file

@ -79,9 +79,15 @@
#include <d3d9.h> #include <d3d9.h>
#include <dxva.h> #include <dxva.h>
/* *INDENT-OFF* */
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_h264_dec_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_h264_dec_debug);
#define GST_CAT_DEFAULT gst_d3d11_h264_dec_debug #define GST_CAT_DEFAULT gst_d3d11_h264_dec_debug
G_END_DECLS
/* *INDENT-ON* */
enum enum
{ {
PROP_0, PROP_0,
@ -106,10 +112,10 @@ typedef struct _GstD3D11H264Dec
GstD3D11Device *device; GstD3D11Device *device;
guint width, height; gint width, height;
guint coded_width, coded_height; gint coded_width, coded_height;
guint bitdepth; gint bitdepth;
guint chroma_format_idc; guint8 chroma_format_idc;
GstVideoFormat out_format; GstVideoFormat out_format;
gboolean interlaced; gboolean interlaced;
gint max_dpb_size; gint max_dpb_size;
@ -198,17 +204,17 @@ gst_d3d11_h264_dec_class_init (GstD3D11H264DecClass * klass, gpointer data)
g_param_spec_uint ("adapter", "Adapter", g_param_spec_uint ("adapter", "Adapter",
"DXGI Adapter index for creating device", "DXGI Adapter index for creating device",
0, G_MAXUINT32, cdata->adapter, 0, G_MAXUINT32, cdata->adapter,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_DEVICE_ID, g_object_class_install_property (gobject_class, PROP_DEVICE_ID,
g_param_spec_uint ("device-id", "Device Id", g_param_spec_uint ("device-id", "Device Id",
"DXGI Device ID", 0, G_MAXUINT32, 0, "DXGI Device ID", 0, G_MAXUINT32, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_VENDOR_ID, g_object_class_install_property (gobject_class, PROP_VENDOR_ID,
g_param_spec_uint ("vendor-id", "Vendor Id", g_param_spec_uint ("vendor-id", "Vendor Id",
"DXGI Vendor ID", 0, G_MAXUINT32, 0, "DXGI Vendor ID", 0, G_MAXUINT32, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
parent_class = g_type_class_peek_parent (klass); parent_class = (GstElementClass *) g_type_class_peek_parent (klass);
klass->adapter = cdata->adapter; klass->adapter = cdata->adapter;
klass->device_id = cdata->device_id; klass->device_id = cdata->device_id;
@ -450,7 +456,7 @@ gst_d3d11_h264_dec_new_sequence (GstH264Decoder * decoder,
if (self->bitdepth != sps->bit_depth_luma_minus8 + 8) { if (self->bitdepth != sps->bit_depth_luma_minus8 + 8) {
GST_INFO_OBJECT (self, "bitdepth changed"); GST_INFO_OBJECT (self, "bitdepth changed");
self->bitdepth = sps->bit_depth_luma_minus8 + 8; self->bitdepth = (guint) sps->bit_depth_luma_minus8 + 8;
modified = TRUE; modified = TRUE;
} }
@ -809,7 +815,8 @@ gst_d3d11_h264_dec_new_field_picture (GstH264Decoder * decoder,
GstD3D11H264Dec *self = GST_D3D11_H264_DEC (decoder); GstD3D11H264Dec *self = GST_D3D11_H264_DEC (decoder);
GstBuffer *view_buffer; GstBuffer *view_buffer;
view_buffer = gst_h264_picture_get_user_data ((GstH264Picture *) first_field); view_buffer = (GstBuffer *) gst_h264_picture_get_user_data ((GstH264Picture *)
first_field);
if (!view_buffer) { if (!view_buffer) {
GST_WARNING_OBJECT (self, "First picture does not have output view buffer"); GST_WARNING_OBJECT (self, "First picture does not have output view buffer");
@ -910,8 +917,8 @@ gst_d3d11_h264_dec_submit_slice_data (GstD3D11H264Dec * self)
gpointer buffer; gpointer buffer;
guint8 *data; guint8 *data;
gsize offset = 0; gsize offset = 0;
gint i; guint i;
D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[4] = { 0, }; D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[4];
gboolean ret; gboolean ret;
DXVA_Slice_H264_Short *slice_data; DXVA_Slice_H264_Short *slice_data;
@ -920,6 +927,8 @@ gst_d3d11_h264_dec_submit_slice_data (GstD3D11H264Dec * self)
return FALSE; return FALSE;
} }
memset (buffer_desc, 0, sizeof (buffer_desc));
slice_data = &g_array_index (self->slice_list, DXVA_Slice_H264_Short, slice_data = &g_array_index (self->slice_list, DXVA_Slice_H264_Short,
self->slice_list->len - 1); self->slice_list->len - 1);
@ -949,7 +958,7 @@ gst_d3d11_h264_dec_submit_slice_data (GstD3D11H264Dec * self)
return FALSE; return FALSE;
} }
data = buffer; data = (guint8 *) buffer;
for (i = 0; i < self->slice_list->len; i++) { for (i = 0; i < self->slice_list->len; i++) {
DXVA_Slice_H264_Short *slice_data = DXVA_Slice_H264_Short *slice_data =
&g_array_index (self->slice_list, DXVA_Slice_H264_Short, i); &g_array_index (self->slice_list, DXVA_Slice_H264_Short, i);
@ -1037,9 +1046,12 @@ gst_d3d11_h264_dec_picture_params_from_sps (GstD3D11H264Dec * self,
(params)->f = (sps)->f (params)->f = (sps)->f
params->wFrameWidthInMbsMinus1 = sps->pic_width_in_mbs_minus1; params->wFrameWidthInMbsMinus1 = sps->pic_width_in_mbs_minus1;
params->wFrameHeightInMbsMinus1 = if (!sps->frame_mbs_only_flag) {
((sps->pic_height_in_map_units_minus1 + 1) << !sps->frame_mbs_only_flag) params->wFrameHeightInMbsMinus1 =
- 1; ((sps->pic_height_in_map_units_minus1 + 1) << 1) - 1;
} else {
params->wFrameHeightInMbsMinus1 = sps->pic_height_in_map_units_minus1;
}
params->residual_colour_transform_flag = sps->separate_colour_plane_flag; params->residual_colour_transform_flag = sps->separate_colour_plane_flag;
params->MbaffFrameFlag = (sps->mb_adaptive_frame_field_flag && !field_pic); params->MbaffFrameFlag = (sps->mb_adaptive_frame_field_flag && !field_pic);
params->field_pic_flag = field_pic; params->field_pic_flag = field_pic;
@ -1356,7 +1368,7 @@ gst_d3d11_h264_dec_register (GstPlugin * plugin, GstD3D11Device * device,
} }
type = g_type_register_static (GST_TYPE_H264_DECODER, type = g_type_register_static (GST_TYPE_H264_DECODER,
type_name, &type_info, 0); type_name, &type_info, (GTypeFlags) 0);
/* make lower rank than default device */ /* make lower rank than default device */
if (rank > 0 && index != 0) if (rank > 0 && index != 0)

View file

@ -49,9 +49,15 @@
#include <d3d9.h> #include <d3d9.h>
#include <dxva.h> #include <dxva.h>
/* *INDENT-OFF* */
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_h265_dec_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_h265_dec_debug);
#define GST_CAT_DEFAULT gst_d3d11_h265_dec_debug #define GST_CAT_DEFAULT gst_d3d11_h265_dec_debug
G_END_DECLS
/* *INDENT-ON* */
enum enum
{ {
PROP_0, PROP_0,
@ -74,10 +80,10 @@ typedef struct _GstD3D11H265Dec
GstD3D11Device *device; GstD3D11Device *device;
guint width, height; gint width, height;
guint coded_width, coded_height; gint coded_width, coded_height;
guint bitdepth; guint bitdepth;
guint chroma_format_idc; guint8 chroma_format_idc;
GstVideoFormat out_format; GstVideoFormat out_format;
GstVideoInterlaceMode interlace_mode; GstVideoInterlaceMode interlace_mode;
@ -170,17 +176,17 @@ gst_d3d11_h265_dec_class_init (GstD3D11H265DecClass * klass, gpointer data)
g_param_spec_uint ("adapter", "Adapter", g_param_spec_uint ("adapter", "Adapter",
"DXGI Adapter index for creating device", "DXGI Adapter index for creating device",
0, G_MAXUINT32, cdata->adapter, 0, G_MAXUINT32, cdata->adapter,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_DEVICE_ID, g_object_class_install_property (gobject_class, PROP_DEVICE_ID,
g_param_spec_uint ("device-id", "Device Id", g_param_spec_uint ("device-id", "Device Id",
"DXGI Device ID", 0, G_MAXUINT32, 0, "DXGI Device ID", 0, G_MAXUINT32, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_VENDOR_ID, g_object_class_install_property (gobject_class, PROP_VENDOR_ID,
g_param_spec_uint ("vendor-id", "Vendor Id", g_param_spec_uint ("vendor-id", "Vendor Id",
"DXGI Vendor ID", 0, G_MAXUINT32, 0, "DXGI Vendor ID", 0, G_MAXUINT32, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
parent_class = g_type_class_peek_parent (klass); parent_class = (GstElementClass *) g_type_class_peek_parent (klass);
klass->adapter = cdata->adapter; klass->adapter = cdata->adapter;
klass->device_id = cdata->device_id; klass->device_id = cdata->device_id;
@ -398,7 +404,7 @@ gst_d3d11_h265_dec_new_sequence (GstH265Decoder * decoder,
modified = TRUE; modified = TRUE;
} }
if (self->bitdepth != sps->bit_depth_luma_minus8 + 8) { if (self->bitdepth != (guint) sps->bit_depth_luma_minus8 + 8) {
GST_INFO_OBJECT (self, "bitdepth changed"); GST_INFO_OBJECT (self, "bitdepth changed");
self->bitdepth = sps->bit_depth_luma_minus8 + 8; self->bitdepth = sps->bit_depth_luma_minus8 + 8;
modified = TRUE; modified = TRUE;
@ -528,7 +534,7 @@ gst_d3d11_h265_dec_get_output_view_from_picture (GstD3D11H265Dec * self,
static gint static gint
gst_d3d11_h265_dec_get_ref_index (GstD3D11H265Dec * self, gint view_id) gst_d3d11_h265_dec_get_ref_index (GstD3D11H265Dec * self, gint view_id)
{ {
gint i; guint i;
for (i = 0; i < G_N_ELEMENTS (self->ref_pic_list); i++) { for (i = 0; i < G_N_ELEMENTS (self->ref_pic_list); i++) {
if (self->ref_pic_list[i].Index7Bits == view_id) if (self->ref_pic_list[i].Index7Bits == view_id)
return i; return i;
@ -543,7 +549,7 @@ gst_d3d11_h265_dec_start_picture (GstH265Decoder * decoder,
{ {
GstD3D11H265Dec *self = GST_D3D11_H265_DEC (decoder); GstD3D11H265Dec *self = GST_D3D11_H265_DEC (decoder);
ID3D11VideoDecoderOutputView *view; ID3D11VideoDecoderOutputView *view;
gint i, j; guint i, j;
GArray *dpb_array; GArray *dpb_array;
GstH265SPS *sps; GstH265SPS *sps;
GstH265PPS *pps; GstH265PPS *pps;
@ -881,8 +887,8 @@ gst_d3d11_h265_dec_submit_slice_data (GstD3D11H265Dec * self)
gpointer buffer; gpointer buffer;
guint8 *data; guint8 *data;
gsize offset = 0; gsize offset = 0;
gint i; guint i;
D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[4] = { 0, }; D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[4];
gboolean ret; gboolean ret;
guint buffer_count = 0; guint buffer_count = 0;
DXVA_Slice_HEVC_Short *slice_data; DXVA_Slice_HEVC_Short *slice_data;
@ -892,6 +898,8 @@ gst_d3d11_h265_dec_submit_slice_data (GstD3D11H265Dec * self)
return FALSE; return FALSE;
} }
memset (buffer_desc, 0, sizeof (buffer_desc));
slice_data = &g_array_index (self->slice_list, DXVA_Slice_HEVC_Short, slice_data = &g_array_index (self->slice_list, DXVA_Slice_HEVC_Short,
self->slice_list->len - 1); self->slice_list->len - 1);
@ -921,7 +929,7 @@ gst_d3d11_h265_dec_submit_slice_data (GstD3D11H265Dec * self)
return FALSE; return FALSE;
} }
data = buffer; data = (guint8 *) buffer;
for (i = 0; i < self->slice_list->len; i++) { for (i = 0; i < self->slice_list->len; i++) {
slice_data = &g_array_index (self->slice_list, DXVA_Slice_HEVC_Short, i); slice_data = &g_array_index (self->slice_list, DXVA_Slice_HEVC_Short, i);
@ -1062,7 +1070,7 @@ static void
gst_d3d11_h265_dec_picture_params_from_pps (GstD3D11H265Dec * self, gst_d3d11_h265_dec_picture_params_from_pps (GstD3D11H265Dec * self,
const GstH265PPS * pps, DXVA_PicParams_HEVC * params) const GstH265PPS * pps, DXVA_PicParams_HEVC * params)
{ {
gint i; guint i;
#define COPY_FIELD(f) \ #define COPY_FIELD(f) \
(params)->f = (pps)->f (params)->f = (pps)->f
@ -1168,7 +1176,7 @@ static void
gst_d3d11_h265_dec_dump_pic_params (GstD3D11H265Dec * self, gst_d3d11_h265_dec_dump_pic_params (GstD3D11H265Dec * self,
DXVA_PicParams_HEVC * params) DXVA_PicParams_HEVC * params)
{ {
gint i; guint i;
GST_TRACE_OBJECT (self, "Dump current DXVA_PicParams_HEVC"); GST_TRACE_OBJECT (self, "Dump current DXVA_PicParams_HEVC");
@ -1587,7 +1595,7 @@ gst_d3d11_h265_dec_register (GstPlugin * plugin, GstD3D11Device * device,
} }
type = g_type_register_static (GST_TYPE_H265_DECODER, type = g_type_register_static (GST_TYPE_H265_DECODER,
type_name, &type_info, 0); type_name, &type_info, (GTypeFlags) 0);
/* make lower rank than default device */ /* make lower rank than default device */
if (rank > 0 && index != 0) if (rank > 0 && index != 0)

View file

@ -49,9 +49,15 @@
#include <d3d9.h> #include <d3d9.h>
#include <dxva.h> #include <dxva.h>
/* *INDENT-OFF* */
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_mpeg2_dec_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_mpeg2_dec_debug);
#define GST_CAT_DEFAULT gst_d3d11_mpeg2_dec_debug #define GST_CAT_DEFAULT gst_d3d11_mpeg2_dec_debug
G_END_DECLS
/* *INDENT-ON* */
enum enum
{ {
PROP_0, PROP_0,
@ -77,7 +83,7 @@ typedef struct _GstD3D11Mpeg2Dec
GstD3D11Device *device; GstD3D11Device *device;
GstD3D11Decoder *d3d11_decoder; GstD3D11Decoder *d3d11_decoder;
guint width, height; gint width, height;
guint width_in_mb, height_in_mb; guint width_in_mb, height_in_mb;
GstVideoFormat out_format; GstVideoFormat out_format;
GstMpegVideoSequenceHdr seq; GstMpegVideoSequenceHdr seq;
@ -162,17 +168,17 @@ gst_d3d11_mpeg2_dec_class_init (GstD3D11Mpeg2DecClass * klass, gpointer data)
g_param_spec_uint ("adapter", "Adapter", g_param_spec_uint ("adapter", "Adapter",
"DXGI Adapter index for creating device", "DXGI Adapter index for creating device",
0, G_MAXUINT32, cdata->adapter, 0, G_MAXUINT32, cdata->adapter,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_DEVICE_ID, g_object_class_install_property (gobject_class, PROP_DEVICE_ID,
g_param_spec_uint ("device-id", "Device Id", g_param_spec_uint ("device-id", "Device Id",
"DXGI Device ID", 0, G_MAXUINT32, 0, "DXGI Device ID", 0, G_MAXUINT32, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_VENDOR_ID, g_object_class_install_property (gobject_class, PROP_VENDOR_ID,
g_param_spec_uint ("vendor-id", "Vendor Id", g_param_spec_uint ("vendor-id", "Vendor Id",
"DXGI Vendor ID", 0, G_MAXUINT32, 0, "DXGI Vendor ID", 0, G_MAXUINT32, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
parent_class = g_type_class_peek_parent (klass); parent_class = (GstElementClass *) g_type_class_peek_parent (klass);
klass->adapter = cdata->adapter; klass->adapter = cdata->adapter;
klass->device_id = cdata->device_id; klass->device_id = cdata->device_id;
@ -398,7 +404,7 @@ gst_d3d11_mpeg2_dec_new_sequence (GstMpeg2Decoder * decoder,
mpeg_profile = GST_MPEG_VIDEO_PROFILE_MAIN; mpeg_profile = GST_MPEG_VIDEO_PROFILE_MAIN;
if (seq_ext) if (seq_ext)
mpeg_profile = seq_ext->profile; mpeg_profile = (GstMpegVideoProfile) seq_ext->profile;
if (mpeg_profile != GST_MPEG_VIDEO_PROFILE_MAIN && if (mpeg_profile != GST_MPEG_VIDEO_PROFILE_MAIN &&
mpeg_profile != GST_MPEG_VIDEO_PROFILE_SIMPLE) { mpeg_profile != GST_MPEG_VIDEO_PROFILE_SIMPLE) {
@ -470,7 +476,7 @@ gst_d3d11_mpeg2_dec_new_field_picture (GstMpeg2Decoder * decoder,
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder); GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstBuffer *view_buffer; GstBuffer *view_buffer;
view_buffer = view_buffer = (GstBuffer *)
gst_mpeg2_picture_get_user_data ((GstMpeg2Picture *) first_field); gst_mpeg2_picture_get_user_data ((GstMpeg2Picture *) first_field);
if (!view_buffer) { if (!view_buffer) {
@ -729,8 +735,8 @@ gst_d3d11_mpeg2_dec_submit_slice_data (GstD3D11Mpeg2Dec * self,
gpointer buffer; gpointer buffer;
guint8 *data; guint8 *data;
gsize offset = 0; gsize offset = 0;
gint i; guint i;
D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[4] = { 0, }; D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[4];
gboolean ret; gboolean ret;
guint buffer_count = 0; guint buffer_count = 0;
DXVA_SliceInfo *slice_data; DXVA_SliceInfo *slice_data;
@ -743,6 +749,8 @@ gst_d3d11_mpeg2_dec_submit_slice_data (GstD3D11Mpeg2Dec * self,
return FALSE; return FALSE;
} }
memset (buffer_desc, 0, sizeof (buffer_desc));
GST_TRACE_OBJECT (self, "Getting slice control buffer"); GST_TRACE_OBJECT (self, "Getting slice control buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder, if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
@ -751,7 +759,7 @@ gst_d3d11_mpeg2_dec_submit_slice_data (GstD3D11Mpeg2Dec * self,
return FALSE; return FALSE;
} }
data = buffer; data = (guint8 *) buffer;
for (i = 0; i < self->slice_list->len; i++) { for (i = 0; i < self->slice_list->len; i++) {
slice_data = &g_array_index (self->slice_list, DXVA_SliceInfo, i); slice_data = &g_array_index (self->slice_list, DXVA_SliceInfo, i);
@ -1038,7 +1046,7 @@ gst_d3d11_mpeg2_dec_register (GstPlugin * plugin, GstD3D11Device * device,
} }
type = g_type_register_static (GST_TYPE_MPEG2_DECODER, type = g_type_register_static (GST_TYPE_MPEG2_DECODER,
type_name, &type_info, 0); type_name, &type_info, (GTypeFlags) 0);
/* make lower rank than default device */ /* make lower rank than default device */
if (rank > 0 && index != 0) if (rank > 0 && index != 0)

View file

@ -23,11 +23,18 @@
#include "gstd3d11overlaycompositor.h" #include "gstd3d11overlaycompositor.h"
#include "gstd3d11shader.h" #include "gstd3d11shader.h"
#include "gstd3d11pluginutils.h"
#include <wrl.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_overlay_compositor_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_overlay_compositor_debug);
#define GST_CAT_DEFAULT gst_d3d11_overlay_compositor_debug #define GST_CAT_DEFAULT gst_d3d11_overlay_compositor_debug
/* *INDENT-OFF* */ G_END_DECLS
typedef struct typedef struct
{ {
struct { struct {
@ -108,11 +115,10 @@ gst_d3d11_composition_overlay_new (GstD3D11OverlayCompositor * self,
GstD3D11CompositionOverlay *overlay = NULL; GstD3D11CompositionOverlay *overlay = NULL;
gint x, y; gint x, y;
guint width, height; guint width, height;
D3D11_SUBRESOURCE_DATA subresource_data = { 0, }; D3D11_SUBRESOURCE_DATA subresource_data;
D3D11_TEXTURE2D_DESC texture_desc = { 0, }; D3D11_TEXTURE2D_DESC texture_desc;
D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc = { 0, }; D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
D3D11_BUFFER_DESC buffer_desc = { 0, }; D3D11_BUFFER_DESC buffer_desc;
ID3D11Buffer *vertex_buffer = NULL;
D3D11_MAPPED_SUBRESOURCE map; D3D11_MAPPED_SUBRESOURCE map;
VertexData *vertex_data; VertexData *vertex_data;
GstBuffer *buf; GstBuffer *buf;
@ -120,8 +126,6 @@ gst_d3d11_composition_overlay_new (GstD3D11OverlayCompositor * self,
GstMapInfo info; GstMapInfo info;
guint8 *data; guint8 *data;
gint stride; gint stride;
ID3D11Texture2D *texture = NULL;
ID3D11ShaderResourceView *srv = NULL;
HRESULT hr; HRESULT hr;
ID3D11Device *device_handle; ID3D11Device *device_handle;
ID3D11DeviceContext *context_handle; ID3D11DeviceContext *context_handle;
@ -129,9 +133,19 @@ gst_d3d11_composition_overlay_new (GstD3D11OverlayCompositor * self,
const guint index_count = 2 * 3; const guint index_count = 2 * 3;
FLOAT x1, y1, x2, y2; FLOAT x1, y1, x2, y2;
gdouble val; gdouble val;
/* *INDENT-OFF* */
ComPtr<ID3D11Texture2D> texture;
ComPtr<ID3D11ShaderResourceView> srv;
ComPtr<ID3D11Buffer> vertex_buffer;
/* *INDENT-ON* */
g_return_val_if_fail (overlay_rect != NULL, NULL); g_return_val_if_fail (overlay_rect != NULL, NULL);
memset (&subresource_data, 0, sizeof (subresource_data));
memset (&texture_desc, 0, sizeof (texture_desc));
memset (&srv_desc, 0, sizeof (srv_desc));
memset (&buffer_desc, 0, sizeof (buffer_desc));
device_handle = gst_d3d11_device_get_device_handle (device); device_handle = gst_d3d11_device_get_device_handle (device);
context_handle = gst_d3d11_device_get_device_context_handle (device); context_handle = gst_d3d11_device_get_device_context_handle (device);
@ -177,7 +191,7 @@ gst_d3d11_composition_overlay_new (GstD3D11OverlayCompositor * self,
texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
texture_desc.CPUAccessFlags = 0; texture_desc.CPUAccessFlags = 0;
hr = ID3D11Device_CreateTexture2D (device_handle, &texture_desc, hr = device_handle->CreateTexture2D (&texture_desc,
&subresource_data, &texture); &subresource_data, &texture);
gst_video_meta_unmap (vmeta, 0, &info); gst_video_meta_unmap (vmeta, 0, &info);
@ -189,11 +203,11 @@ gst_d3d11_composition_overlay_new (GstD3D11OverlayCompositor * self,
srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srv_desc.Texture2D.MipLevels = 1; srv_desc.Texture2D.MipLevels = 1;
hr = ID3D11Device_CreateShaderResourceView (device_handle, hr = device_handle->CreateShaderResourceView (texture.Get (), &srv_desc,
(ID3D11Resource *) texture, &srv_desc, &srv); &srv);
if (!gst_d3d11_result (hr, device) || !srv) { if (!gst_d3d11_result (hr, device) || !srv) {
GST_ERROR ("Failed to create shader resource view"); GST_ERROR ("Failed to create shader resource view");
goto clear; return NULL;
} }
buffer_desc.Usage = D3D11_USAGE_DYNAMIC; buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
@ -201,21 +215,20 @@ gst_d3d11_composition_overlay_new (GstD3D11OverlayCompositor * self,
buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
hr = ID3D11Device_CreateBuffer (device_handle, &buffer_desc, NULL, hr = device_handle->CreateBuffer (&buffer_desc, NULL, &vertex_buffer);
&vertex_buffer);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't create vertex buffer, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't create vertex buffer, hr: 0x%x", (guint) hr);
goto clear; return NULL;
} }
gst_d3d11_device_lock (device); gst_d3d11_device_lock (device);
hr = ID3D11DeviceContext_Map (context_handle, hr = context_handle->Map (vertex_buffer.Get (),
(ID3D11Resource *) vertex_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't map vertex buffer, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't map vertex buffer, hr: 0x%x", (guint) hr);
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
goto clear; return NULL;
} }
vertex_data = (VertexData *) map.pData; vertex_data = (VertexData *) map.pData;
@ -264,30 +277,18 @@ gst_d3d11_composition_overlay_new (GstD3D11OverlayCompositor * self,
vertex_data[3].texture.x = 1.0f; vertex_data[3].texture.x = 1.0f;
vertex_data[3].texture.y = 1.0f; vertex_data[3].texture.y = 1.0f;
ID3D11DeviceContext_Unmap (context_handle, context_handle->Unmap (vertex_buffer.Get (), 0);
(ID3D11Resource *) vertex_buffer, 0);
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
overlay = g_new0 (GstD3D11CompositionOverlay, 1); overlay = g_new0 (GstD3D11CompositionOverlay, 1);
overlay->overlay_rect = gst_video_overlay_rectangle_ref (overlay_rect); overlay->overlay_rect = gst_video_overlay_rectangle_ref (overlay_rect);
overlay->texture = texture; overlay->texture = texture.Detach ();
overlay->srv = srv; overlay->srv = srv.Detach ();
overlay->quad = gst_d3d11_quad_new (device, overlay->quad = gst_d3d11_quad_new (device,
self->ps, self->vs, self->layout, self->sampler, self->blend, NULL, NULL, self->ps, self->vs, self->layout, self->sampler, self->blend, NULL, NULL,
vertex_buffer, sizeof (VertexData), vertex_buffer.Get (), sizeof (VertexData),
self->index_buffer, DXGI_FORMAT_R16_UINT, index_count); self->index_buffer, DXGI_FORMAT_R16_UINT, index_count);
clear:
if (!overlay) {
if (srv)
ID3D11ShaderResourceView_Release (srv);
if (texture)
ID3D11Texture2D_Release (texture);
}
if (vertex_buffer)
ID3D11Buffer_Release (vertex_buffer);
return overlay; return overlay;
} }
@ -300,11 +301,8 @@ gst_d3d11_composition_overlay_free (GstD3D11CompositionOverlay * overlay)
if (overlay->overlay_rect) if (overlay->overlay_rect)
gst_video_overlay_rectangle_unref (overlay->overlay_rect); gst_video_overlay_rectangle_unref (overlay->overlay_rect);
if (overlay->srv) GST_D3D11_CLEAR_COM (overlay->srv);
ID3D11ShaderResourceView_Release (overlay->srv); GST_D3D11_CLEAR_COM (overlay->texture);
if (overlay->texture)
ID3D11Texture2D_Release (overlay->texture);
if (overlay->quad) if (overlay->quad)
gst_d3d11_quad_free (overlay->quad); gst_d3d11_quad_free (overlay->quad);
@ -317,22 +315,28 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self,
GstD3D11Device * device) GstD3D11Device * device)
{ {
HRESULT hr; HRESULT hr;
D3D11_SAMPLER_DESC sampler_desc = { 0, }; D3D11_SAMPLER_DESC sampler_desc;
D3D11_INPUT_ELEMENT_DESC input_desc[2] = { 0, }; D3D11_INPUT_ELEMENT_DESC input_desc[2];
D3D11_BUFFER_DESC buffer_desc = { 0, }; D3D11_BUFFER_DESC buffer_desc;
D3D11_BLEND_DESC blend_desc = { 0, }; D3D11_BLEND_DESC blend_desc;
D3D11_MAPPED_SUBRESOURCE map; D3D11_MAPPED_SUBRESOURCE map;
WORD *indices; WORD *indices;
ID3D11Device *device_handle; ID3D11Device *device_handle;
ID3D11DeviceContext *context_handle; ID3D11DeviceContext *context_handle;
ID3D11PixelShader *ps = NULL; /* *INDENT-OFF* */
ID3D11VertexShader *vs = NULL; ComPtr<ID3D11PixelShader> ps;
ID3D11InputLayout *layout = NULL; ComPtr<ID3D11VertexShader> vs;
ID3D11SamplerState *sampler = NULL; ComPtr<ID3D11InputLayout> layout;
ID3D11BlendState *blend = NULL; ComPtr<ID3D11SamplerState> sampler;
ID3D11Buffer *index_buffer = NULL; ComPtr<ID3D11BlendState> blend;
ComPtr<ID3D11Buffer> index_buffer;
/* *INDENT-ON* */
const guint index_count = 2 * 3; const guint index_count = 2 * 3;
gboolean ret = TRUE;
memset (&sampler_desc, 0, sizeof (sampler_desc));
memset (input_desc, 0, sizeof (input_desc));
memset (&buffer_desc, 0, sizeof (buffer_desc));
memset (&blend_desc, 0, sizeof (blend_desc));
device_handle = gst_d3d11_device_get_device_handle (device); device_handle = gst_d3d11_device_get_device_handle (device);
context_handle = gst_d3d11_device_get_device_context_handle (device); context_handle = gst_d3d11_device_get_device_context_handle (device);
@ -346,19 +350,17 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self,
sampler_desc.MinLOD = 0; sampler_desc.MinLOD = 0;
sampler_desc.MaxLOD = D3D11_FLOAT32_MAX; sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
hr = ID3D11Device_CreateSamplerState (device_handle, &sampler_desc, &sampler); hr = device_handle->CreateSamplerState (&sampler_desc, &sampler);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't create sampler state, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't create sampler state, hr: 0x%x", (guint) hr);
ret = FALSE; return FALSE;
goto clear;
} }
GST_LOG ("Create Pixel Shader \n%s", templ_pixel_shader); GST_LOG ("Create Pixel Shader \n%s", templ_pixel_shader);
if (!gst_d3d11_create_pixel_shader (device, templ_pixel_shader, &ps)) { if (!gst_d3d11_create_pixel_shader (device, templ_pixel_shader, &ps)) {
GST_ERROR ("Couldn't create pixel shader"); GST_ERROR ("Couldn't create pixel shader");
ret = FALSE; return FALSE;
goto clear;
} }
input_desc[0].SemanticName = "POSITION"; input_desc[0].SemanticName = "POSITION";
@ -380,8 +382,7 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self,
if (!gst_d3d11_create_vertex_shader (device, templ_vertex_shader, if (!gst_d3d11_create_vertex_shader (device, templ_vertex_shader,
input_desc, G_N_ELEMENTS (input_desc), &vs, &layout)) { input_desc, G_N_ELEMENTS (input_desc), &vs, &layout)) {
GST_ERROR ("Couldn't vertex pixel shader"); GST_ERROR ("Couldn't vertex pixel shader");
ret = FALSE; return FALSE;
goto clear;
} }
blend_desc.AlphaToCoverageEnable = FALSE; blend_desc.AlphaToCoverageEnable = FALSE;
@ -396,11 +397,10 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self,
blend_desc.RenderTarget[0].RenderTargetWriteMask = blend_desc.RenderTarget[0].RenderTargetWriteMask =
D3D11_COLOR_WRITE_ENABLE_ALL; D3D11_COLOR_WRITE_ENABLE_ALL;
hr = ID3D11Device_CreateBlendState (device_handle, &blend_desc, &blend); hr = device_handle->CreateBlendState (&blend_desc, &blend);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't create blend staten, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't create blend staten, hr: 0x%x", (guint) hr);
ret = FALSE; return FALSE;
goto clear;
} }
buffer_desc.Usage = D3D11_USAGE_DYNAMIC; buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
@ -408,23 +408,20 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self,
buffer_desc.BindFlags = D3D11_BIND_INDEX_BUFFER; buffer_desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
hr = ID3D11Device_CreateBuffer (device_handle, &buffer_desc, NULL, hr = device_handle->CreateBuffer (&buffer_desc, NULL, &index_buffer);
&index_buffer);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't create index buffer, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't create index buffer, hr: 0x%x", (guint) hr);
ret = FALSE; return FALSE;
goto clear;
} }
gst_d3d11_device_lock (device); gst_d3d11_device_lock (device);
hr = ID3D11DeviceContext_Map (context_handle, hr = context_handle->Map (index_buffer.Get (),
(ID3D11Resource *) index_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't map index buffer, hr: 0x%x", (guint) hr); GST_ERROR ("Couldn't map index buffer, hr: 0x%x", (guint) hr);
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
ret = FALSE; return FALSE;
goto clear;
} }
indices = (WORD *) map.pData; indices = (WORD *) map.pData;
@ -438,35 +435,17 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self,
indices[4] = 0; /* bottom left */ indices[4] = 0; /* bottom left */
indices[5] = 2; /* top right */ indices[5] = 2; /* top right */
ID3D11DeviceContext_Unmap (context_handle, context_handle->Unmap (index_buffer.Get (), 0);
(ID3D11Resource *) index_buffer, 0);
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
self->ps = ps; self->ps = ps.Detach ();
self->vs = vs; self->vs = vs.Detach ();
self->layout = layout; self->layout = layout.Detach ();
self->sampler = sampler; self->sampler = sampler.Detach ();
self->blend = blend; self->blend = blend.Detach ();
self->index_buffer = index_buffer; self->index_buffer = index_buffer.Detach ();
clear: return TRUE;
if (ret)
return TRUE;
if (ps)
ID3D11PixelShader_Release (ps);
if (vs)
ID3D11VertexShader_Release (vs);
if (layout)
ID3D11InputLayout_Release (layout);
if (sampler)
ID3D11SamplerState_Release (sampler);
if (blend)
ID3D11BlendState_Release (blend);
if (index_buffer)
ID3D11Buffer_Release (index_buffer);
return FALSE;
} }
@ -486,7 +465,7 @@ gst_d3d11_overlay_compositor_new (GstD3D11Device * device,
return NULL; return NULL;
} }
compositor->device = gst_object_ref (device); compositor->device = (GstD3D11Device *) gst_object_ref (device);
compositor->out_info = *out_info; compositor->out_info = *out_info;
compositor->viewport.TopLeftX = 0; compositor->viewport.TopLeftX = 0;
@ -506,18 +485,12 @@ gst_d3d11_overlay_compositor_free (GstD3D11OverlayCompositor * compositor)
gst_d3d11_overlay_compositor_free_overlays (compositor); gst_d3d11_overlay_compositor_free_overlays (compositor);
if (compositor->ps) GST_D3D11_CLEAR_COM (compositor->ps);
ID3D11PixelShader_Release (compositor->ps); GST_D3D11_CLEAR_COM (compositor->vs);
if (compositor->vs) GST_D3D11_CLEAR_COM (compositor->layout);
ID3D11VertexShader_Release (compositor->vs); GST_D3D11_CLEAR_COM (compositor->sampler);
if (compositor->layout) GST_D3D11_CLEAR_COM (compositor->blend);
ID3D11InputLayout_Release (compositor->layout); GST_D3D11_CLEAR_COM (compositor->index_buffer);
if (compositor->sampler)
ID3D11SamplerState_Release (compositor->sampler);
if (compositor->blend)
ID3D11BlendState_Release (compositor->blend);
if (compositor->index_buffer)
ID3D11Buffer_Release (compositor->index_buffer);
gst_clear_object (&compositor->device); gst_clear_object (&compositor->device);
g_free (compositor); g_free (compositor);

View file

@ -27,9 +27,15 @@
#include <windows.h> #include <windows.h>
#include <versionhelpers.h> #include <versionhelpers.h>
/* *INDENT-OFF* */
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_plugin_utils_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_plugin_utils_debug);
#define GST_CAT_DEFAULT gst_d3d11_plugin_utils_debug #define GST_CAT_DEFAULT gst_d3d11_plugin_utils_debug
G_END_DECLS
/* *INDENT-ON* */
/* Max Texture Dimension for feature level 11_0 ~ 12_1 */ /* Max Texture Dimension for feature level 11_0 ~ 12_1 */
static guint _gst_d3d11_texture_max_dimension = 16384; static guint _gst_d3d11_texture_max_dimension = 16384;
@ -100,7 +106,8 @@ gst_d3d11_get_device_vendor (GstD3D11Device * device)
gchar *desc = NULL; gchar *desc = NULL;
GstD3D11DeviceVendor vendor = GST_D3D11_DEVICE_VENDOR_UNKNOWN; GstD3D11DeviceVendor vendor = GST_D3D11_DEVICE_VENDOR_UNKNOWN;
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), FALSE); g_return_val_if_fail (GST_IS_D3D11_DEVICE (device),
GST_D3D11_DEVICE_VENDOR_UNKNOWN);
g_object_get (device, "device-id", &device_id, "vendor-id", &vendor_id, g_object_get (device, "device-id", &device_id, "vendor-id", &vendor_id,
"description", &desc, NULL); "description", &desc, NULL);
@ -455,7 +462,8 @@ static const GstDxgiColorSpace *
gst_d3d11_video_info_to_dxgi_color_space_rgb (GstVideoInfo * info) gst_d3d11_video_info_to_dxgi_color_space_rgb (GstVideoInfo * info)
{ {
gint best_score = G_MAXINT; gint best_score = G_MAXINT;
gint score, i; gint score;
guint i;
const GstDxgiColorSpace *colorspace = NULL; const GstDxgiColorSpace *colorspace = NULL;
for (i = 0; i < G_N_ELEMENTS (rgb_colorspace_map); i++) { for (i = 0; i < G_N_ELEMENTS (rgb_colorspace_map); i++) {
@ -477,7 +485,8 @@ static const GstDxgiColorSpace *
gst_d3d11_video_info_to_dxgi_color_space_yuv (GstVideoInfo * info) gst_d3d11_video_info_to_dxgi_color_space_yuv (GstVideoInfo * info)
{ {
gint best_score = G_MAXINT; gint best_score = G_MAXINT;
gint score, i; gint score;
guint i;
const GstDxgiColorSpace *colorspace = NULL; const GstDxgiColorSpace *colorspace = NULL;
for (i = 0; i < G_N_ELEMENTS (yuv_colorspace_map); i++) { for (i = 0; i < G_N_ELEMENTS (yuv_colorspace_map); i++) {
@ -515,7 +524,7 @@ gst_d3d11_find_swap_chain_color_space (GstVideoInfo * info,
{ {
const GstDxgiColorSpace *colorspace = NULL; const GstDxgiColorSpace *colorspace = NULL;
gint best_score = G_MAXINT; gint best_score = G_MAXINT;
gint i; guint i;
g_return_val_if_fail (info != NULL, FALSE); g_return_val_if_fail (info != NULL, FALSE);
g_return_val_if_fail (swapchain != NULL, FALSE); g_return_val_if_fail (swapchain != NULL, FALSE);
@ -529,8 +538,8 @@ gst_d3d11_find_swap_chain_color_space (GstVideoInfo * info,
UINT can_support = 0; UINT can_support = 0;
HRESULT hr; HRESULT hr;
gint score; gint score;
GST_DXGI_COLOR_SPACE_TYPE cur_type = DXGI_COLOR_SPACE_TYPE cur_type =
rgb_colorspace_map[i].dxgi_color_space_type; (DXGI_COLOR_SPACE_TYPE) rgb_colorspace_map[i].dxgi_color_space_type;
/* FIXME: Non-HDR colorspace with BT2020 primaries will break rendering. /* FIXME: Non-HDR colorspace with BT2020 primaries will break rendering.
* https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/1175 * https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/1175
@ -540,8 +549,7 @@ gst_d3d11_find_swap_chain_color_space (GstVideoInfo * info,
rgb_colorspace_map[i].primaries == GST_VIDEO_COLOR_PRIMARIES_BT2020) rgb_colorspace_map[i].primaries == GST_VIDEO_COLOR_PRIMARIES_BT2020)
continue; continue;
hr = IDXGISwapChain3_CheckColorSpaceSupport (swapchain, hr = swapchain->CheckColorSpaceSupport (cur_type, &can_support);
cur_type, &can_support);
if (FAILED (hr)) if (FAILED (hr))
continue; continue;
@ -570,7 +578,7 @@ gst_d3d11_allocate_staging_buffer (GstD3D11Allocator * allocator,
gboolean add_videometa) gboolean add_videometa)
{ {
GstBuffer *buffer; GstBuffer *buffer;
gint i; guint i;
gint stride[GST_VIDEO_MAX_PLANES] = { 0, }; gint stride[GST_VIDEO_MAX_PLANES] = { 0, };
gsize offset[GST_VIDEO_MAX_PLANES] = { 0, }; gsize offset[GST_VIDEO_MAX_PLANES] = { 0, };
GstMemory *mem; GstMemory *mem;
@ -586,8 +594,9 @@ gst_d3d11_allocate_staging_buffer (GstD3D11Allocator * allocator,
gsize size[GST_VIDEO_MAX_PLANES] = { 0, }; gsize size[GST_VIDEO_MAX_PLANES] = { 0, };
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (info); i++) { for (i = 0; i < GST_VIDEO_INFO_N_PLANES (info); i++) {
mem = gst_d3d11_allocator_alloc_staging (allocator, &desc[i], 0, mem =
&stride[i]); gst_d3d11_allocator_alloc_staging (allocator, &desc[i],
(GstD3D11AllocationFlags) 0, &stride[i]);
if (!mem) { if (!mem) {
GST_ERROR_OBJECT (allocator, "Couldn't allocate memory for plane %d", GST_ERROR_OBJECT (allocator, "Couldn't allocate memory for plane %d",
@ -604,8 +613,8 @@ gst_d3d11_allocate_staging_buffer (GstD3D11Allocator * allocator,
/* must be YUV semi-planar or single plane */ /* must be YUV semi-planar or single plane */
g_assert (GST_VIDEO_INFO_N_PLANES (info) <= 2); g_assert (GST_VIDEO_INFO_N_PLANES (info) <= 2);
mem = gst_d3d11_allocator_alloc_staging (allocator, &desc[0], 0, mem = gst_d3d11_allocator_alloc_staging (allocator, &desc[0],
&stride[0]); (GstD3D11AllocationFlags) 0, &stride[0]);
if (!mem) { if (!mem) {
GST_ERROR_OBJECT (allocator, "Couldn't allocate memory"); GST_ERROR_OBJECT (allocator, "Couldn't allocate memory");
@ -646,7 +655,7 @@ gst_d3d11_allocate_staging_buffer_for (GstBuffer * buffer,
GstD3D11Allocator *alloc = NULL; GstD3D11Allocator *alloc = NULL;
GstBuffer *staging_buffer = NULL; GstBuffer *staging_buffer = NULL;
D3D11_TEXTURE2D_DESC *desc; D3D11_TEXTURE2D_DESC *desc;
gint i; guint i;
for (i = 0; i < gst_buffer_n_memory (buffer); i++) { for (i = 0; i < gst_buffer_n_memory (buffer); i++) {
GstMemory *mem = gst_buffer_peek_memory (buffer, i); GstMemory *mem = gst_buffer_peek_memory (buffer, i);
@ -662,7 +671,7 @@ gst_d3d11_allocate_staging_buffer_for (GstBuffer * buffer,
device = dmem->device; device = dmem->device;
params = gst_d3d11_allocation_params_new (device, (GstVideoInfo *) info, params = gst_d3d11_allocation_params_new (device, (GstVideoInfo *) info,
0, 0); (GstD3D11AllocationFlags) 0, 0);
if (!params) { if (!params) {
GST_WARNING ("Couldn't create alloc params"); GST_WARNING ("Couldn't create alloc params");
@ -718,11 +727,11 @@ gst_d3d11_buffer_copy_into_fallback (GstBuffer * dst, GstBuffer * src,
gboolean ret; gboolean ret;
if (!gst_video_frame_map (&in_frame, (GstVideoInfo *) info, src, if (!gst_video_frame_map (&in_frame, (GstVideoInfo *) info, src,
GST_MAP_READ | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)) (GstMapFlags) (GST_MAP_READ | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)))
goto invalid_buffer; goto invalid_buffer;
if (!gst_video_frame_map (&out_frame, (GstVideoInfo *) info, dst, if (!gst_video_frame_map (&out_frame, (GstVideoInfo *) info, dst,
GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)) { (GstMapFlags) (GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF))) {
gst_video_frame_unmap (&in_frame); gst_video_frame_unmap (&in_frame);
goto invalid_buffer; goto invalid_buffer;
} }
@ -796,12 +805,14 @@ gst_d3d11_buffer_copy_into (GstBuffer * dst, GstBuffer * src,
device_context = gst_d3d11_device_get_device_context_handle (device); device_context = gst_d3d11_device_get_device_context_handle (device);
if (!gst_memory_map (dst_mem, &dst_info, GST_MAP_WRITE | GST_MAP_D3D11)) { if (!gst_memory_map (dst_mem, &dst_info,
(GstMapFlags) (GST_MAP_WRITE | GST_MAP_D3D11))) {
GST_ERROR ("Cannot map dst d3d11 memory"); GST_ERROR ("Cannot map dst d3d11 memory");
return FALSE; return FALSE;
} }
if (!gst_memory_map (src_mem, &src_info, GST_MAP_READ | GST_MAP_D3D11)) { if (!gst_memory_map (src_mem, &src_info,
(GstMapFlags) (GST_MAP_READ | GST_MAP_D3D11))) {
GST_ERROR ("Cannot map src d3d11 memory"); GST_ERROR ("Cannot map src d3d11 memory");
gst_memory_unmap (dst_mem, &dst_info); gst_memory_unmap (dst_mem, &dst_info);
return FALSE; return FALSE;
@ -823,8 +834,8 @@ gst_d3d11_buffer_copy_into (GstBuffer * dst, GstBuffer * src,
src_subidx = gst_d3d11_memory_get_subresource_index (src_dmem); src_subidx = gst_d3d11_memory_get_subresource_index (src_dmem);
gst_d3d11_device_lock (device); gst_d3d11_device_lock (device);
ID3D11DeviceContext_CopySubresourceRegion (device_context, device_context->CopySubresourceRegion (dst_texture, dst_subidx, 0, 0, 0,
dst_texture, dst_subidx, 0, 0, 0, src_texture, src_subidx, &src_box); src_texture, src_subidx, &src_box);
gst_d3d11_device_unlock (device); gst_d3d11_device_unlock (device);
gst_memory_unmap (src_mem, &src_info); gst_memory_unmap (src_mem, &src_info);
@ -888,7 +899,7 @@ gst_d3d11_buffer_map (GstBuffer * buffer, ID3D11Device * device,
GstMapInfo info[GST_VIDEO_MAX_PLANES], GstMapFlags flags) GstMapInfo info[GST_VIDEO_MAX_PLANES], GstMapFlags flags)
{ {
GstMapFlags map_flags; GstMapFlags map_flags;
gint num_mapped = 0; guint num_mapped = 0;
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
g_return_val_if_fail (info != NULL, FALSE); g_return_val_if_fail (info != NULL, FALSE);
@ -896,7 +907,7 @@ gst_d3d11_buffer_map (GstBuffer * buffer, ID3D11Device * device,
if (!gst_d3d11_buffer_can_access_device (buffer, device)) if (!gst_d3d11_buffer_can_access_device (buffer, device))
return FALSE; return FALSE;
map_flags = flags | GST_MAP_D3D11; map_flags = (GstMapFlags) (flags | GST_MAP_D3D11);
for (num_mapped = 0; num_mapped < gst_buffer_n_memory (buffer); num_mapped++) { for (num_mapped = 0; num_mapped < gst_buffer_n_memory (buffer); num_mapped++) {
GstMemory *mem = gst_buffer_peek_memory (buffer, num_mapped); GstMemory *mem = gst_buffer_peek_memory (buffer, num_mapped);
@ -911,7 +922,7 @@ gst_d3d11_buffer_map (GstBuffer * buffer, ID3D11Device * device,
error: error:
{ {
gint i; guint i;
for (i = 0; i < num_mapped; i++) { for (i = 0; i < num_mapped; i++) {
GstMemory *mem = gst_buffer_peek_memory (buffer, num_mapped); GstMemory *mem = gst_buffer_peek_memory (buffer, num_mapped);
gst_memory_unmap (mem, &info[i]); gst_memory_unmap (mem, &info[i]);
@ -925,7 +936,7 @@ gboolean
gst_d3d11_buffer_unmap (GstBuffer * buffer, gst_d3d11_buffer_unmap (GstBuffer * buffer,
GstMapInfo info[GST_VIDEO_MAX_PLANES]) GstMapInfo info[GST_VIDEO_MAX_PLANES])
{ {
gint i; guint i;
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
g_return_val_if_fail (info != NULL, FALSE); g_return_val_if_fail (info != NULL, FALSE);
@ -943,7 +954,7 @@ guint
gst_d3d11_buffer_get_shader_resource_view (GstBuffer * buffer, gst_d3d11_buffer_get_shader_resource_view (GstBuffer * buffer,
ID3D11ShaderResourceView * view[GST_VIDEO_MAX_PLANES]) ID3D11ShaderResourceView * view[GST_VIDEO_MAX_PLANES])
{ {
gint i; guint i;
guint num_views = 0; guint num_views = 0;
g_return_val_if_fail (GST_IS_BUFFER (buffer), 0); g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
@ -957,7 +968,7 @@ gst_d3d11_buffer_get_shader_resource_view (GstBuffer * buffer,
for (i = 0; i < gst_buffer_n_memory (buffer); i++) { for (i = 0; i < gst_buffer_n_memory (buffer); i++) {
GstD3D11Memory *mem = (GstD3D11Memory *) gst_buffer_peek_memory (buffer, i); GstD3D11Memory *mem = (GstD3D11Memory *) gst_buffer_peek_memory (buffer, i);
guint view_size; guint view_size;
gint j; guint j;
view_size = gst_d3d11_memory_get_shader_resource_view_size (mem); view_size = gst_d3d11_memory_get_shader_resource_view_size (mem);
if (!view_size) { if (!view_size) {
@ -982,7 +993,7 @@ guint
gst_d3d11_buffer_get_render_target_view (GstBuffer * buffer, gst_d3d11_buffer_get_render_target_view (GstBuffer * buffer,
ID3D11RenderTargetView * view[GST_VIDEO_MAX_PLANES]) ID3D11RenderTargetView * view[GST_VIDEO_MAX_PLANES])
{ {
gint i; guint i;
guint num_views = 0; guint num_views = 0;
g_return_val_if_fail (GST_IS_BUFFER (buffer), 0); g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
@ -996,7 +1007,7 @@ gst_d3d11_buffer_get_render_target_view (GstBuffer * buffer,
for (i = 0; i < gst_buffer_n_memory (buffer); i++) { for (i = 0; i < gst_buffer_n_memory (buffer); i++) {
GstD3D11Memory *mem = (GstD3D11Memory *) gst_buffer_peek_memory (buffer, i); GstD3D11Memory *mem = (GstD3D11Memory *) gst_buffer_peek_memory (buffer, i);
guint view_size; guint view_size;
gint j; guint j;
view_size = gst_d3d11_memory_get_render_target_view_size (mem); view_size = gst_d3d11_memory_get_render_target_view_size (mem);
if (!view_size) { if (!view_size) {

View file

@ -48,6 +48,13 @@ struct _GstDxgiColorSpace
GstVideoColorPrimaries primaries; GstVideoColorPrimaries primaries;
}; };
#define GST_D3D11_CLEAR_COM(obj) G_STMT_START { \
if (obj) { \
(obj)->Release (); \
(obj) = NULL; \
} \
} G_STMT_END
void gst_d3d11_plugin_utils_init (D3D_FEATURE_LEVEL feature_level); void gst_d3d11_plugin_utils_init (D3D_FEATURE_LEVEL feature_level);
GstCaps * gst_d3d11_get_updated_template_caps (GstStaticCaps * template_caps); GstCaps * gst_d3d11_get_updated_template_caps (GstStaticCaps * template_caps);

View file

@ -22,11 +22,21 @@
#endif #endif
#include "gstd3d11shader.h" #include "gstd3d11shader.h"
#include "gstd3d11pluginutils.h"
#include <gmodule.h> #include <gmodule.h>
#include <wrl.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_shader_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_shader_debug);
#define GST_CAT_DEFAULT gst_d3d11_shader_debug #define GST_CAT_DEFAULT gst_d3d11_shader_debug
G_END_DECLS
/* *INDENT-ON* */
static GModule *d3d_compiler_module = NULL; static GModule *d3d_compiler_module = NULL;
static pD3DCompile GstD3DCompileFunc = NULL; static pD3DCompile GstD3DCompileFunc = NULL;
@ -47,7 +57,7 @@ gst_d3d11_shader_init (void)
"d3dcompiler_44.dll", "d3dcompiler_44.dll",
"d3dcompiler_43.dll", "d3dcompiler_43.dll",
}; };
gint i; guint i;
for (i = 0; i < G_N_ELEMENTS (d3d_compiler_names); i++) { for (i = 0; i < G_N_ELEMENTS (d3d_compiler_names); i++) {
d3d_compiler_module = d3d_compiler_module =
g_module_open (d3d_compiler_names[i], G_MODULE_BIND_LAZY); g_module_open (d3d_compiler_names[i], G_MODULE_BIND_LAZY);
@ -74,27 +84,29 @@ gst_d3d11_shader_init (void)
g_once_init_leave (&_init, 1); g_once_init_leave (&_init, 1);
} }
return ! !GstD3DCompileFunc; return !!GstD3DCompileFunc;
} }
static ID3DBlob * static gboolean
compile_shader (GstD3D11Device * device, const gchar * shader_source, compile_shader (GstD3D11Device * device, const gchar * shader_source,
gboolean is_pixel_shader) gboolean is_pixel_shader, ID3DBlob ** blob)
{ {
ID3DBlob *ret;
ID3DBlob *error = NULL;
const gchar *shader_target; const gchar *shader_target;
D3D_FEATURE_LEVEL feature_level; D3D_FEATURE_LEVEL feature_level;
HRESULT hr; HRESULT hr;
ID3D11Device *device_handle; ID3D11Device *device_handle;
/* *INDENT-OFF* */
ComPtr<ID3DBlob> ret;
ComPtr<ID3DBlob> error;
/* *INDENT-ON* */
if (!gst_d3d11_shader_init ()) { if (!gst_d3d11_shader_init ()) {
GST_ERROR ("D3DCompiler is unavailable"); GST_ERROR ("D3DCompiler is unavailable");
return NULL; return FALSE;
} }
device_handle = gst_d3d11_device_get_device_handle (device); device_handle = gst_d3d11_device_get_device_handle (device);
feature_level = ID3D11Device_GetFeatureLevel (device_handle); feature_level = device_handle->GetFeatureLevel ();
if (is_pixel_shader) { if (is_pixel_shader) {
if (feature_level >= D3D_FEATURE_LEVEL_10_0) if (feature_level >= D3D_FEATURE_LEVEL_10_0)
@ -123,63 +135,52 @@ compile_shader (GstD3D11Device * device, const gchar * shader_source,
const gchar *err = NULL; const gchar *err = NULL;
if (error) if (error)
err = ID3D10Blob_GetBufferPointer (error); err = (const gchar *) error->GetBufferPointer ();
GST_ERROR ("could not compile source, hr: 0x%x, error detail %s", GST_ERROR ("could not compile source, hr: 0x%x, error detail %s",
(guint) hr, GST_STR_NULL (err)); (guint) hr, GST_STR_NULL (err));
return FALSE;
if (error)
ID3D10Blob_Release (error);
return NULL;
} }
if (error) { if (error) {
const gchar *err = ID3D10Blob_GetBufferPointer (error); const gchar *err = (const gchar *) error->GetBufferPointer ();
GST_DEBUG ("HLSL compiler warnings:\n%s\nShader code:\n%s", GST_DEBUG ("HLSL compiler warnings:\n%s\nShader code:\n%s",
GST_STR_NULL (err), GST_STR_NULL (shader_source)); GST_STR_NULL (err), GST_STR_NULL (shader_source));
ID3D10Blob_Release (error);
} }
return ret; *blob = ret.Detach ();
return TRUE;
} }
gboolean gboolean
gst_d3d11_create_pixel_shader (GstD3D11Device * device, gst_d3d11_create_pixel_shader (GstD3D11Device * device,
const gchar * source, ID3D11PixelShader ** shader) const gchar * source, ID3D11PixelShader ** shader)
{ {
ID3DBlob *ps_blob;
ID3D11Device *device_handle; ID3D11Device *device_handle;
HRESULT hr; HRESULT hr;
/* *INDENT-OFF* */
ComPtr<ID3DBlob> ps_blob;
/* *INDENT-ON* */
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), FALSE); g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), FALSE);
g_return_val_if_fail (source != NULL, FALSE); g_return_val_if_fail (source != NULL, FALSE);
g_return_val_if_fail (shader != NULL, FALSE); g_return_val_if_fail (shader != NULL, FALSE);
gst_d3d11_device_lock (device); if (!compile_shader (device, source, TRUE, &ps_blob)) {
ps_blob = compile_shader (device, source, TRUE);
if (!ps_blob) {
GST_ERROR ("Failed to compile pixel shader"); GST_ERROR ("Failed to compile pixel shader");
gst_d3d11_device_unlock (device);
return FALSE; return FALSE;
} }
device_handle = gst_d3d11_device_get_device_handle (device); device_handle = gst_d3d11_device_get_device_handle (device);
hr = ID3D11Device_CreatePixelShader (device_handle, hr = device_handle->CreatePixelShader (ps_blob->GetBufferPointer (),
(gpointer) ID3D10Blob_GetBufferPointer (ps_blob), ps_blob->GetBufferSize (), NULL, shader);
ID3D10Blob_GetBufferSize (ps_blob), NULL, shader);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("could not create pixel shader, hr: 0x%x", (guint) hr); GST_ERROR ("could not create pixel shader, hr: 0x%x", (guint) hr);
gst_d3d11_device_unlock (device);
return FALSE; return FALSE;
} }
ID3D10Blob_Release (ps_blob);
gst_d3d11_device_unlock (device);
return TRUE; return TRUE;
} }
@ -188,12 +189,13 @@ gst_d3d11_create_vertex_shader (GstD3D11Device * device, const gchar * source,
const D3D11_INPUT_ELEMENT_DESC * input_desc, guint desc_len, const D3D11_INPUT_ELEMENT_DESC * input_desc, guint desc_len,
ID3D11VertexShader ** shader, ID3D11InputLayout ** layout) ID3D11VertexShader ** shader, ID3D11InputLayout ** layout)
{ {
ID3DBlob *vs_blob;
ID3D11Device *device_handle; ID3D11Device *device_handle;
HRESULT hr; HRESULT hr;
ID3D11VertexShader *vshader = NULL; /* *INDENT-OFF* */
ID3D11InputLayout *in_layout = NULL; ComPtr<ID3DBlob> vs_blob;
gboolean ret = FALSE; ComPtr<ID3D11VertexShader> vs;
ComPtr<ID3D11InputLayout> in_layout;
/* *INDENT-ON* */
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), FALSE); g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), FALSE);
g_return_val_if_fail (source != NULL, FALSE); g_return_val_if_fail (source != NULL, FALSE);
@ -202,47 +204,31 @@ gst_d3d11_create_vertex_shader (GstD3D11Device * device, const gchar * source,
g_return_val_if_fail (shader != NULL, FALSE); g_return_val_if_fail (shader != NULL, FALSE);
g_return_val_if_fail (layout != NULL, FALSE); g_return_val_if_fail (layout != NULL, FALSE);
gst_d3d11_device_lock (device); if (!compile_shader (device, source, FALSE, &vs_blob)) {
vs_blob = compile_shader (device, source, FALSE);
if (!vs_blob) {
GST_ERROR ("Failed to compile shader code"); GST_ERROR ("Failed to compile shader code");
goto done; return FALSE;
} }
device_handle = gst_d3d11_device_get_device_handle (device); device_handle = gst_d3d11_device_get_device_handle (device);
hr = device_handle->CreateVertexShader (vs_blob->GetBufferPointer (),
hr = ID3D11Device_CreateVertexShader (device_handle, vs_blob->GetBufferSize (), NULL, &vs);
(gpointer) ID3D10Blob_GetBufferPointer (vs_blob),
ID3D10Blob_GetBufferSize (vs_blob), NULL, &vshader);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("could not create vertex shader, hr: 0x%x", (guint) hr); GST_ERROR ("could not create vertex shader, hr: 0x%x", (guint) hr);
ID3D10Blob_Release (vs_blob); return FALSE;
goto done;
} }
hr = ID3D11Device_CreateInputLayout (device_handle, input_desc, hr = device_handle->CreateInputLayout (input_desc,
desc_len, (gpointer) ID3D10Blob_GetBufferPointer (vs_blob), desc_len, vs_blob->GetBufferPointer (),
ID3D10Blob_GetBufferSize (vs_blob), &in_layout); vs_blob->GetBufferSize (), &in_layout);
if (!gst_d3d11_result (hr, device)) { if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("could not create input layout shader, hr: 0x%x", (guint) hr); GST_ERROR ("could not create input layout shader, hr: 0x%x", (guint) hr);
ID3D10Blob_Release (vs_blob); return FALSE;
ID3D11VertexShader_Release (vshader);
goto done;
} }
ID3D10Blob_Release (vs_blob); *shader = vs.Detach ();
*layout = in_layout.Detach ();
*shader = vshader; return TRUE;
*layout = in_layout;
ret = TRUE;
done:
gst_d3d11_device_unlock (device);
return ret;
} }
struct _GstD3D11Quad struct _GstD3D11Quad
@ -289,7 +275,7 @@ gst_d3d11_quad_new (GstD3D11Device * device, ID3D11PixelShader * pixel_shader,
quad = g_new0 (GstD3D11Quad, 1); quad = g_new0 (GstD3D11Quad, 1);
quad->device = gst_object_ref (device); quad->device = (GstD3D11Device *) gst_object_ref (device);
quad->ps = pixel_shader; quad->ps = pixel_shader;
quad->vs = vertex_shader; quad->vs = vertex_shader;
quad->layout = layout; quad->layout = layout;
@ -302,24 +288,25 @@ gst_d3d11_quad_new (GstD3D11Device * device, ID3D11PixelShader * pixel_shader,
quad->index_format = index_format; quad->index_format = index_format;
quad->index_count = index_count; quad->index_count = index_count;
ID3D11PixelShader_AddRef (pixel_shader); pixel_shader->AddRef ();
ID3D11VertexShader_AddRef (vertex_shader); vertex_shader->AddRef ();
ID3D11InputLayout_AddRef (layout); layout->AddRef ();
vertex_buffer->AddRef ();
index_buffer->AddRef ();
if (sampler) if (sampler)
ID3D11SamplerState_AddRef (sampler); sampler->AddRef ();
if (blend) if (blend)
ID3D11BlendState_AddRef (blend); blend->AddRef ();
if (depth_stencil) if (depth_stencil)
ID3D11DepthStencilState_AddRef (depth_stencil); depth_stencil->AddRef ();
if (const_buffer) { if (const_buffer) {
quad->const_buffer = const_buffer; quad->const_buffer = const_buffer;
ID3D11Buffer_AddRef (const_buffer); const_buffer->AddRef ();
} }
ID3D11Buffer_AddRef (vertex_buffer);
ID3D11Buffer_AddRef (index_buffer);
return quad; return quad;
} }
@ -329,24 +316,15 @@ gst_d3d11_quad_free (GstD3D11Quad * quad)
{ {
g_return_if_fail (quad != NULL); g_return_if_fail (quad != NULL);
if (quad->ps) GST_D3D11_CLEAR_COM (quad->ps);
ID3D11PixelShader_Release (quad->ps); GST_D3D11_CLEAR_COM (quad->vs);
if (quad->vs) GST_D3D11_CLEAR_COM (quad->layout);
ID3D11VertexShader_Release (quad->vs); GST_D3D11_CLEAR_COM (quad->sampler);
if (quad->layout) GST_D3D11_CLEAR_COM (quad->blend);
ID3D11InputLayout_Release (quad->layout); GST_D3D11_CLEAR_COM (quad->depth_stencil);
if (quad->sampler) GST_D3D11_CLEAR_COM (quad->const_buffer);
ID3D11SamplerState_Release (quad->sampler); GST_D3D11_CLEAR_COM (quad->vertex_buffer);
if (quad->blend) GST_D3D11_CLEAR_COM (quad->index_buffer);
ID3D11BlendState_Release (quad->blend);
if (quad->depth_stencil)
ID3D11DepthStencilState_Release (quad->depth_stencil);
if (quad->const_buffer)
ID3D11Buffer_Release (quad->const_buffer);
if (quad->vertex_buffer)
ID3D11Buffer_Release (quad->vertex_buffer);
if (quad->index_buffer)
ID3D11Buffer_Release (quad->index_buffer);
gst_clear_object (&quad->device); gst_clear_object (&quad->device);
g_free (quad); g_free (quad);
@ -380,7 +358,7 @@ gst_d3d11_draw_quad_unlocked (GstD3D11Quad * quad,
ID3D11DepthStencilView * dsv, ID3D11BlendState * blend, ID3D11DepthStencilView * dsv, ID3D11BlendState * blend,
gfloat blend_factor[4]) gfloat blend_factor[4])
{ {
ID3D11DeviceContext *context_handle; ID3D11DeviceContext *context;
UINT offsets = 0; UINT offsets = 0;
ID3D11ShaderResourceView *clear_view[GST_VIDEO_MAX_PLANES] = { NULL, }; ID3D11ShaderResourceView *clear_view[GST_VIDEO_MAX_PLANES] = { NULL, };
ID3D11BlendState *blend_state = blend; ID3D11BlendState *blend_state = blend;
@ -391,43 +369,36 @@ gst_d3d11_draw_quad_unlocked (GstD3D11Quad * quad,
g_return_val_if_fail (rtv != NULL, FALSE); g_return_val_if_fail (rtv != NULL, FALSE);
g_return_val_if_fail (num_rtv <= GST_VIDEO_MAX_PLANES, FALSE); g_return_val_if_fail (num_rtv <= GST_VIDEO_MAX_PLANES, FALSE);
context_handle = gst_d3d11_device_get_device_context_handle (quad->device); context = gst_d3d11_device_get_device_context_handle (quad->device);
ID3D11DeviceContext_IASetPrimitiveTopology (context_handle, context->IASetPrimitiveTopology (D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context->IASetInputLayout (quad->layout);
ID3D11DeviceContext_IASetInputLayout (context_handle, quad->layout); context->IASetVertexBuffers (0, 1, &quad->vertex_buffer, &quad->vertex_stride,
ID3D11DeviceContext_IASetVertexBuffers (context_handle, &offsets);
0, 1, &quad->vertex_buffer, &quad->vertex_stride, &offsets); context->IASetIndexBuffer (quad->index_buffer, quad->index_format, 0);
ID3D11DeviceContext_IASetIndexBuffer (context_handle,
quad->index_buffer, quad->index_format, 0);
if (quad->sampler) if (quad->sampler)
ID3D11DeviceContext_PSSetSamplers (context_handle, 0, 1, &quad->sampler); context->PSSetSamplers (0, 1, &quad->sampler);
ID3D11DeviceContext_VSSetShader (context_handle, quad->vs, NULL, 0); context->VSSetShader (quad->vs, NULL, 0);
ID3D11DeviceContext_PSSetShader (context_handle, quad->ps, NULL, 0); context->PSSetShader (quad->ps, NULL, 0);
ID3D11DeviceContext_RSSetViewports (context_handle, num_viewport, viewport); context->RSSetViewports (num_viewport, viewport);
if (quad->const_buffer) if (quad->const_buffer)
ID3D11DeviceContext_PSSetConstantBuffers (context_handle, context->PSSetConstantBuffers (0, 1, &quad->const_buffer);
0, 1, &quad->const_buffer);
if (srv) if (srv)
ID3D11DeviceContext_PSSetShaderResources (context_handle, 0, num_srv, srv); context->PSSetShaderResources (0, num_srv, srv);
ID3D11DeviceContext_OMSetRenderTargets (context_handle, num_rtv, rtv, dsv); context->OMSetRenderTargets (num_rtv, rtv, dsv);
if (!blend_state) if (!blend_state)
blend_state = quad->blend; blend_state = quad->blend;
ID3D11DeviceContext_OMSetBlendState (context_handle, context->OMSetBlendState (blend_state, blend_factor, 0xffffffff);
blend_state, blend_factor, 0xffffffff); context->OMSetDepthStencilState (quad->depth_stencil, 1);
ID3D11DeviceContext_OMSetDepthStencilState (context_handle,
quad->depth_stencil, 1);
ID3D11DeviceContext_DrawIndexed (context_handle, quad->index_count, 0, 0); context->DrawIndexed (quad->index_count, 0, 0);
if (srv) { if (srv)
ID3D11DeviceContext_PSSetShaderResources (context_handle, context->PSSetShaderResources (0, num_srv, clear_view);
0, num_srv, clear_view); context->OMSetRenderTargets (0, NULL, NULL);
}
ID3D11DeviceContext_OMSetRenderTargets (context_handle, 0, NULL, NULL);
return TRUE; return TRUE;
} }

View file

@ -441,7 +441,7 @@ gst_d3d11_upload_transform (GstBaseTransform * trans, GstBuffer * inbuf,
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
gboolean use_staging_buf; gboolean use_staging_buf;
GstBuffer *target_outbuf = outbuf; GstBuffer *target_outbuf = outbuf;
gint i; guint i;
use_staging_buf = gst_d3d11_upload_can_use_staging_buffer (self, outbuf); use_staging_buf = gst_d3d11_upload_can_use_staging_buffer (self, outbuf);
@ -451,11 +451,11 @@ gst_d3d11_upload_transform (GstBaseTransform * trans, GstBuffer * inbuf,
} }
if (!gst_video_frame_map (&in_frame, &filter->in_info, inbuf, if (!gst_video_frame_map (&in_frame, &filter->in_info, inbuf,
GST_MAP_READ | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)) (GstMapFlags) (GST_MAP_READ | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)))
goto invalid_buffer; goto invalid_buffer;
if (!gst_video_frame_map (&out_frame, &filter->out_info, target_outbuf, if (!gst_video_frame_map (&out_frame, &filter->out_info, target_outbuf,
GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)) { (GstMapFlags) (GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF))) {
gst_video_frame_unmap (&in_frame); gst_video_frame_unmap (&in_frame);
goto invalid_buffer; goto invalid_buffer;
} }

View file

@ -22,12 +22,19 @@
#endif #endif
#include "gstd3d11videoprocessor.h" #include "gstd3d11videoprocessor.h"
#include "gstd3d11pluginutils.h"
#include <string.h> #include <string.h>
/* *INDENT-OFF* */
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_video_processor_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_video_processor_debug);
#define GST_CAT_DEFAULT gst_d3d11_video_processor_debug #define GST_CAT_DEFAULT gst_d3d11_video_processor_debug
G_END_DECLS
/* *INDENT-ON* */
#if (GST_D3D11_HEADER_VERSION >= 1 && GST_D3D11_DXGI_HEADER_VERSION >= 4) #if (GST_D3D11_HEADER_VERSION >= 1 && GST_D3D11_DXGI_HEADER_VERSION >= 4)
#define HAVE_VIDEO_CONTEXT_ONE #define HAVE_VIDEO_CONTEXT_ONE
#endif #endif
@ -64,23 +71,23 @@ gst_d3d11_video_processor_new (GstD3D11Device * device, guint in_width,
ID3D11Device *device_handle; ID3D11Device *device_handle;
ID3D11DeviceContext *context_handle; ID3D11DeviceContext *context_handle;
HRESULT hr; HRESULT hr;
D3D11_VIDEO_PROCESSOR_CONTENT_DESC desc = { 0, }; D3D11_VIDEO_PROCESSOR_CONTENT_DESC desc;
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL); g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL);
memset (&desc, 0, sizeof (desc));
device_handle = gst_d3d11_device_get_device_handle (device); device_handle = gst_d3d11_device_get_device_handle (device);
context_handle = gst_d3d11_device_get_device_context_handle (device); context_handle = gst_d3d11_device_get_device_context_handle (device);
self = g_new0 (GstD3D11VideoProcessor, 1); self = g_new0 (GstD3D11VideoProcessor, 1);
self->device = gst_object_ref (device); self->device = (GstD3D11Device *) gst_object_ref (device);
hr = ID3D11Device_QueryInterface (device_handle, hr = device_handle->QueryInterface (IID_PPV_ARGS (&self->video_device));
&IID_ID3D11VideoDevice, (void **) &self->video_device);
if (!gst_d3d11_result (hr, device)) if (!gst_d3d11_result (hr, device))
goto fail; goto fail;
hr = ID3D11DeviceContext_QueryInterface (context_handle, hr = context_handle->QueryInterface (IID_PPV_ARGS (&self->video_context));
&IID_ID3D11VideoContext, (void **) &self->video_context);
if (!gst_d3d11_result (hr, device)) if (!gst_d3d11_result (hr, device))
goto fail; goto fail;
@ -93,38 +100,36 @@ gst_d3d11_video_processor_new (GstD3D11Device * device, guint in_width,
/* TODO: make option for this */ /* TODO: make option for this */
desc.Usage = D3D11_VIDEO_USAGE_PLAYBACK_NORMAL; desc.Usage = D3D11_VIDEO_USAGE_PLAYBACK_NORMAL;
hr = ID3D11VideoDevice_CreateVideoProcessorEnumerator (self->video_device, hr = self->video_device->CreateVideoProcessorEnumerator (&desc,
&desc, &self->enumerator); &self->enumerator);
if (!gst_d3d11_result (hr, device)) if (!gst_d3d11_result (hr, device))
goto fail; goto fail;
#ifdef HAVE_VIDEO_CONTEXT_ONE #ifdef HAVE_VIDEO_CONTEXT_ONE
hr = ID3D11VideoContext_QueryInterface (self->enumerator, hr = self->enumerator->QueryInterface (IID_PPV_ARGS (&self->enumerator1));
&IID_ID3D11VideoProcessorEnumerator1, (void **) &self->enumerator1);
if (gst_d3d11_result (hr, device)) { if (gst_d3d11_result (hr, device)) {
GST_DEBUG ("ID3D11VideoProcessorEnumerator1 interface available"); GST_DEBUG ("ID3D11VideoProcessorEnumerator1 interface available");
} }
#endif #endif
hr = ID3D11VideoProcessorEnumerator_GetVideoProcessorCaps (self->enumerator, hr = self->enumerator->GetVideoProcessorCaps (&self->processor_caps);
&self->processor_caps);
if (!gst_d3d11_result (hr, device)) if (!gst_d3d11_result (hr, device))
goto fail; goto fail;
hr = ID3D11VideoDevice_CreateVideoProcessor (self->video_device, hr = self->video_device->CreateVideoProcessor (self->enumerator, 0,
self->enumerator, 0, &self->processor); &self->processor);
if (!gst_d3d11_result (hr, device)) if (!gst_d3d11_result (hr, device))
goto fail; goto fail;
#ifdef HAVE_VIDEO_CONTEXT_ONE #ifdef HAVE_VIDEO_CONTEXT_ONE
hr = ID3D11VideoContext_QueryInterface (self->video_context, hr = self->video_context->
&IID_ID3D11VideoContext1, (void **) &self->video_context1); QueryInterface (IID_PPV_ARGS (&self->video_context1));
if (gst_d3d11_result (hr, device)) { if (gst_d3d11_result (hr, device)) {
GST_DEBUG ("ID3D11VideoContext1 interface available"); GST_DEBUG ("ID3D11VideoContext1 interface available");
} }
#endif #endif
#ifdef HAVE_VIDEO_CONTEXT_TWO #ifdef HAVE_VIDEO_CONTEXT_TWO
hr = ID3D11VideoContext_QueryInterface (self->video_context, hr = self->video_context->
&IID_ID3D11VideoContext2, (void **) &self->video_context2); QueryInterface (IID_PPV_ARGS (&self->video_context2));
if (gst_d3d11_result (hr, device)) { if (gst_d3d11_result (hr, device)) {
GST_DEBUG ("ID3D11VideoContext2 interface available"); GST_DEBUG ("ID3D11VideoContext2 interface available");
} }
@ -133,8 +138,8 @@ gst_d3d11_video_processor_new (GstD3D11Device * device, guint in_width,
/* Setting up default options */ /* Setting up default options */
gst_d3d11_device_lock (self->device); gst_d3d11_device_lock (self->device);
/* We don't want auto processing by driver */ /* We don't want auto processing by driver */
ID3D11VideoContext_VideoProcessorSetStreamAutoProcessingMode self->video_context->VideoProcessorSetStreamAutoProcessingMode
(self->video_context, self->processor, 0, FALSE); (self->processor, 0, FALSE);
gst_d3d11_device_unlock (self->device); gst_d3d11_device_unlock (self->device);
return self; return self;
@ -150,25 +155,18 @@ gst_d3d11_video_processor_free (GstD3D11VideoProcessor * processor)
{ {
g_return_if_fail (processor != NULL); g_return_if_fail (processor != NULL);
if (processor->video_device) GST_D3D11_CLEAR_COM (processor->video_device);
ID3D11VideoDevice_Release (processor->video_device); GST_D3D11_CLEAR_COM (processor->video_context);
if (processor->video_context)
ID3D11VideoContext_Release (processor->video_context);
#ifdef HAVE_VIDEO_CONTEXT_ONE #ifdef HAVE_VIDEO_CONTEXT_ONE
if (processor->video_context1) GST_D3D11_CLEAR_COM (processor->video_context1);
ID3D11VideoContext1_Release (processor->video_context1);
#endif #endif
#ifdef HAVE_VIDEO_CONTEXT_TWO #ifdef HAVE_VIDEO_CONTEXT_TWO
if (processor->video_context2) GST_D3D11_CLEAR_COM (processor->video_context2);
ID3D11VideoContext2_Release (processor->video_context2);
#endif #endif
if (processor->processor) GST_D3D11_CLEAR_COM (processor->processor);
ID3D11VideoProcessor_Release (processor->processor); GST_D3D11_CLEAR_COM (processor->enumerator);
if (processor->enumerator)
ID3D11VideoProcessorEnumerator_Release (processor->enumerator);
#ifdef HAVE_VIDEO_CONTEXT_ONE #ifdef HAVE_VIDEO_CONTEXT_ONE
if (processor->enumerator1) GST_D3D11_CLEAR_COM (processor->enumerator1);
ID3D11VideoProcessorEnumerator1_Release (processor->enumerator1);
#endif #endif
gst_clear_object (&processor->device); gst_clear_object (&processor->device);
@ -182,8 +180,7 @@ gst_d3d11_video_processor_supports_format (GstD3D11VideoProcessor *
HRESULT hr; HRESULT hr;
UINT flag = 0; UINT flag = 0;
hr = ID3D11VideoProcessorEnumerator_CheckVideoProcessorFormat hr = self->enumerator->CheckVideoProcessorFormat (format, &flag);
(self->enumerator, format, &flag);
if (!gst_d3d11_result (hr, self->device)) if (!gst_d3d11_result (hr, self->device))
return FALSE; return FALSE;
@ -281,8 +278,8 @@ gst_d3d11_video_processor_set_input_color_space (GstD3D11VideoProcessor *
video_processor_color_space_from_gst (processor, color, &color_space); video_processor_color_space_from_gst (processor, color, &color_space);
ID3D11VideoContext_VideoProcessorSetStreamColorSpace processor->video_context->VideoProcessorSetStreamColorSpace
(processor->video_context, processor->processor, 0, &color_space); (processor->processor, 0, &color_space);
return TRUE; return TRUE;
} }
@ -298,8 +295,8 @@ gst_d3d11_video_processor_set_output_color_space (GstD3D11VideoProcessor *
video_processor_color_space_from_gst (processor, color, &color_space); video_processor_color_space_from_gst (processor, color, &color_space);
ID3D11VideoContext_VideoProcessorSetOutputColorSpace processor->video_context->VideoProcessorSetOutputColorSpace
(processor->video_context, processor->processor, &color_space); (processor->processor, &color_space);
return TRUE; return TRUE;
} }
@ -319,9 +316,8 @@ gst_d3d11_video_processor_check_format_conversion (GstD3D11VideoProcessor *
if (!processor->enumerator1) if (!processor->enumerator1)
return FALSE; return FALSE;
hr = ID3D11VideoProcessorEnumerator1_CheckVideoProcessorFormatConversion hr = processor->enumerator1->CheckVideoProcessorFormatConversion
(processor->enumerator1, in_format, in_color_space, out_format, (in_format, in_color_space, out_format, out_color_space, &supported);
out_color_space, &supported);
if (!gst_d3d11_result (hr, processor->device)) { if (!gst_d3d11_result (hr, processor->device)) {
GST_WARNING ("Failed to check conversion support"); GST_WARNING ("Failed to check conversion support");
return FALSE; return FALSE;
@ -341,8 +337,8 @@ gst_d3d11_video_processor_set_input_dxgi_color_space (GstD3D11VideoProcessor *
#ifdef HAVE_VIDEO_CONTEXT_ONE #ifdef HAVE_VIDEO_CONTEXT_ONE
if (processor->video_context1) { if (processor->video_context1) {
ID3D11VideoContext1_VideoProcessorSetStreamColorSpace1 processor->video_context1->VideoProcessorSetStreamColorSpace1
(processor->video_context1, processor->processor, 0, color_space); (processor->processor, 0, color_space);
return TRUE; return TRUE;
} }
#endif #endif
@ -358,8 +354,8 @@ gst_d3d11_video_processor_set_output_dxgi_color_space (GstD3D11VideoProcessor *
#ifdef HAVE_VIDEO_CONTEXT_ONE #ifdef HAVE_VIDEO_CONTEXT_ONE
if (processor->video_context1) { if (processor->video_context1) {
ID3D11VideoContext1_VideoProcessorSetOutputColorSpace1 processor->video_context1->VideoProcessorSetOutputColorSpace1
(processor->video_context1, processor->processor, color_space); (processor->processor, color_space);
return TRUE; return TRUE;
} }
#endif #endif
@ -383,14 +379,13 @@ gst_d3d11_video_processor_set_input_hdr10_metadata (GstD3D11VideoProcessor *
if (processor->video_context2 && (processor->processor_caps.FeatureCaps & if (processor->video_context2 && (processor->processor_caps.FeatureCaps &
FEATURE_CAPS_METADATA_HDR10)) { FEATURE_CAPS_METADATA_HDR10)) {
if (hdr10_meta) { if (hdr10_meta) {
ID3D11VideoContext2_VideoProcessorSetStreamHDRMetaData processor->video_context2->VideoProcessorSetStreamHDRMetaData
(processor->video_context2, processor->processor, 0, (processor->processor, 0,
DXGI_HDR_METADATA_TYPE_HDR10, sizeof (DXGI_HDR_METADATA_HDR10), DXGI_HDR_METADATA_TYPE_HDR10, sizeof (DXGI_HDR_METADATA_HDR10),
hdr10_meta); hdr10_meta);
} else { } else {
ID3D11VideoContext2_VideoProcessorSetStreamHDRMetaData processor->video_context2->VideoProcessorSetStreamHDRMetaData
(processor->video_context2, processor->processor, 0, (processor->processor, 0, DXGI_HDR_METADATA_TYPE_NONE, 0, NULL);
DXGI_HDR_METADATA_TYPE_NONE, 0, NULL);
} }
return TRUE; return TRUE;
@ -410,14 +405,12 @@ gst_d3d11_video_processor_set_output_hdr10_metadata (GstD3D11VideoProcessor *
if (processor->video_context2 && (processor->processor_caps.FeatureCaps & if (processor->video_context2 && (processor->processor_caps.FeatureCaps &
FEATURE_CAPS_METADATA_HDR10)) { FEATURE_CAPS_METADATA_HDR10)) {
if (hdr10_meta) { if (hdr10_meta) {
ID3D11VideoContext2_VideoProcessorSetOutputHDRMetaData processor->video_context2->VideoProcessorSetOutputHDRMetaData
(processor->video_context2, processor->processor, (processor->processor, DXGI_HDR_METADATA_TYPE_HDR10,
DXGI_HDR_METADATA_TYPE_HDR10, sizeof (DXGI_HDR_METADATA_HDR10), sizeof (DXGI_HDR_METADATA_HDR10), hdr10_meta);
hdr10_meta);
} else { } else {
ID3D11VideoContext2_VideoProcessorSetOutputHDRMetaData processor->video_context2->VideoProcessorSetOutputHDRMetaData
(processor->video_context2, processor->processor, (processor->processor, DXGI_HDR_METADATA_TYPE_NONE, 0, NULL);
DXGI_HDR_METADATA_TYPE_NONE, 0, NULL);
} }
return TRUE; return TRUE;
@ -440,8 +433,8 @@ gst_d3d11_video_processor_create_input_view (GstD3D11VideoProcessor * processor,
g_return_val_if_fail (resource != NULL, FALSE); g_return_val_if_fail (resource != NULL, FALSE);
g_return_val_if_fail (view != NULL, FALSE); g_return_val_if_fail (view != NULL, FALSE);
hr = ID3D11VideoDevice_CreateVideoProcessorInputView (processor->video_device, hr = processor->video_device->CreateVideoProcessorInputView (resource,
resource, processor->enumerator, desc, view); processor->enumerator, desc, view);
if (!gst_d3d11_result (hr, processor->device)) if (!gst_d3d11_result (hr, processor->device))
return FALSE; return FALSE;
@ -468,8 +461,8 @@ gst_d3d11_video_processor_create_output_view (GstD3D11VideoProcessor *
g_return_val_if_fail (resource != NULL, FALSE); g_return_val_if_fail (resource != NULL, FALSE);
g_return_val_if_fail (view != NULL, FALSE); g_return_val_if_fail (view != NULL, FALSE);
hr = ID3D11VideoDevice_CreateVideoProcessorOutputView hr = processor->video_device->CreateVideoProcessorOutputView
(processor->video_device, resource, processor->enumerator, desc, view); (resource, processor->enumerator, desc, view);
if (!gst_d3d11_result (hr, processor->device)) if (!gst_d3d11_result (hr, processor->device))
return FALSE; return FALSE;
@ -484,26 +477,6 @@ gst_d3d11_video_processor_get_output_view (GstD3D11VideoProcessor *
processor->video_device, processor->enumerator); processor->video_device, processor->enumerator);
} }
void
gst_d3d11_video_processor_input_view_release (ID3D11VideoProcessorInputView *
view)
{
if (!view)
return;
ID3D11VideoProcessorInputView_Release (view);
}
void
gst_d3d11_video_processor_output_view_release (ID3D11VideoProcessorOutputView *
view)
{
if (!view)
return;
ID3D11VideoProcessorOutputView_Release (view);
}
gboolean gboolean
gst_d3d11_video_processor_render (GstD3D11VideoProcessor * processor, gst_d3d11_video_processor_render (GstD3D11VideoProcessor * processor,
RECT * in_rect, ID3D11VideoProcessorInputView * in_view, RECT * in_rect, ID3D11VideoProcessorInputView * in_view,
@ -530,6 +503,8 @@ gst_d3d11_video_processor_render_unlocked (GstD3D11VideoProcessor * processor,
{ {
HRESULT hr; HRESULT hr;
D3D11_VIDEO_PROCESSOR_STREAM stream = { 0, }; D3D11_VIDEO_PROCESSOR_STREAM stream = { 0, };
ID3D11VideoContext *context;
ID3D11VideoProcessor *proc;
g_return_val_if_fail (processor != NULL, FALSE); g_return_val_if_fail (processor != NULL, FALSE);
g_return_val_if_fail (in_view != NULL, FALSE); g_return_val_if_fail (in_view != NULL, FALSE);
@ -537,29 +512,24 @@ gst_d3d11_video_processor_render_unlocked (GstD3D11VideoProcessor * processor,
stream.Enable = TRUE; stream.Enable = TRUE;
stream.pInputSurface = in_view; stream.pInputSurface = in_view;
context = processor->video_context;
proc = processor->processor;
if (in_rect) { if (in_rect) {
ID3D11VideoContext_VideoProcessorSetStreamSourceRect context->VideoProcessorSetStreamSourceRect (proc, 0, TRUE, in_rect);
(processor->video_context, processor->processor, 0, TRUE, in_rect);
} else { } else {
ID3D11VideoContext_VideoProcessorSetStreamSourceRect context->VideoProcessorSetStreamSourceRect (proc, 0, FALSE, NULL);
(processor->video_context, processor->processor, 0, FALSE, NULL);
} }
if (out_rect) { if (out_rect) {
ID3D11VideoContext_VideoProcessorSetStreamDestRect context->VideoProcessorSetStreamDestRect (proc, 0, TRUE, out_rect);
(processor->video_context, processor->processor, 0, TRUE, out_rect); context->VideoProcessorSetOutputTargetRect (proc, TRUE, out_rect);
ID3D11VideoContext_VideoProcessorSetOutputTargetRect
(processor->video_context, processor->processor, TRUE, out_rect);
} else { } else {
ID3D11VideoContext_VideoProcessorSetStreamDestRect context->VideoProcessorSetStreamDestRect (proc, 0, FALSE, NULL);
(processor->video_context, processor->processor, 0, FALSE, NULL); context->VideoProcessorSetOutputTargetRect (proc, FALSE, NULL);
ID3D11VideoContext_VideoProcessorSetOutputTargetRect
(processor->video_context, processor->processor, FALSE, NULL);
} }
hr = ID3D11VideoContext_VideoProcessorBlt (processor->video_context, hr = context->VideoProcessorBlt (proc, out_view, 0, 1, &stream);
processor->processor, out_view, 0, 1, &stream);
if (!gst_d3d11_result (hr, processor->device)) if (!gst_d3d11_result (hr, processor->device))
return FALSE; return FALSE;

View file

@ -89,10 +89,6 @@ gboolean gst_d3d11_video_processor_create_output_view (GstD3D11VideoProcessor *
ID3D11VideoProcessorOutputView * gst_d3d11_video_processor_get_output_view (GstD3D11VideoProcessor * processor, ID3D11VideoProcessorOutputView * gst_d3d11_video_processor_get_output_view (GstD3D11VideoProcessor * processor,
GstD3D11Memory *mem); GstD3D11Memory *mem);
void gst_d3d11_video_processor_input_view_release (ID3D11VideoProcessorInputView * view);
void gst_d3d11_video_processor_output_view_release (ID3D11VideoProcessorOutputView * view);
gboolean gst_d3d11_video_processor_render (GstD3D11VideoProcessor * processor, gboolean gst_d3d11_video_processor_render (GstD3D11VideoProcessor * processor,
RECT *in_rect, RECT *in_rect,
ID3D11VideoProcessorInputView * in_view, ID3D11VideoProcessorInputView * in_view,

View file

@ -196,35 +196,36 @@ gst_d3d11_video_sink_class_init (GstD3D11VideoSinkClass * klass)
g_param_spec_int ("adapter", "Adapter", g_param_spec_int ("adapter", "Adapter",
"Adapter index for creating device (-1 for default)", "Adapter index for creating device (-1 for default)",
-1, G_MAXINT32, DEFAULT_ADAPTER, -1, G_MAXINT32, DEFAULT_ADAPTER,
G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY | (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO, g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO,
g_param_spec_boolean ("force-aspect-ratio", g_param_spec_boolean ("force-aspect-ratio",
"Force aspect ratio", "Force aspect ratio",
"When enabled, scaling will respect original aspect ratio", "When enabled, scaling will respect original aspect ratio",
DEFAULT_FORCE_ASPECT_RATIO, DEFAULT_FORCE_ASPECT_RATIO,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_ENABLE_NAVIGATION_EVENTS, g_object_class_install_property (gobject_class, PROP_ENABLE_NAVIGATION_EVENTS,
g_param_spec_boolean ("enable-navigation-events", g_param_spec_boolean ("enable-navigation-events",
"Enable navigation events", "Enable navigation events",
"When enabled, navigation events are sent upstream", "When enabled, navigation events are sent upstream",
DEFAULT_ENABLE_NAVIGATION_EVENTS, DEFAULT_ENABLE_NAVIGATION_EVENTS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_FULLSCREEN_TOGGLE_MODE, g_object_class_install_property (gobject_class, PROP_FULLSCREEN_TOGGLE_MODE,
g_param_spec_flags ("fullscreen-toggle-mode", g_param_spec_flags ("fullscreen-toggle-mode",
"Full screen toggle mode", "Full screen toggle mode",
"Full screen toggle mode used to trigger fullscreen mode change", "Full screen toggle mode used to trigger fullscreen mode change",
GST_D3D11_WINDOW_TOGGLE_MODE_GET_TYPE, DEFAULT_FULLSCREEN_TOGGLE_MODE, GST_D3D11_WINDOW_TOGGLE_MODE_GET_TYPE, DEFAULT_FULLSCREEN_TOGGLE_MODE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_FULLSCREEN, g_object_class_install_property (gobject_class, PROP_FULLSCREEN,
g_param_spec_boolean ("fullscreen", g_param_spec_boolean ("fullscreen",
"fullscreen", "fullscreen",
"Ignored when \"fullscreen-toggle-mode\" does not include \"property\"", "Ignored when \"fullscreen-toggle-mode\" does not include \"property\"",
DEFAULT_FULLSCREEN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_FULLSCREEN,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
#ifdef HAVE_DIRECT_WRITE #ifdef HAVE_DIRECT_WRITE
g_object_class_install_property (gobject_class, PROP_RENDER_STATS, g_object_class_install_property (gobject_class, PROP_RENDER_STATS,
@ -232,8 +233,9 @@ gst_d3d11_video_sink_class_init (GstD3D11VideoSinkClass * klass)
"Render Stats", "Render Stats",
"Render statistics data (e.g., average framerate) on window", "Render statistics data (e.g., average framerate) on window",
DEFAULT_RENDER_STATS, DEFAULT_RENDER_STATS,
GST_PARAM_CONDITIONALLY_AVAILABLE | GST_PARAM_MUTABLE_READY | (GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS)));
#endif #endif
/** /**
@ -262,8 +264,8 @@ gst_d3d11_video_sink_class_init (GstD3D11VideoSinkClass * klass)
"DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, and " "DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, and "
"DXGI_FORMAT_R10G10B10A2_UNORM.", "DXGI_FORMAT_R10G10B10A2_UNORM.",
DEFAULT_DRAW_ON_SHARED_TEXTURE, DEFAULT_DRAW_ON_SHARED_TEXTURE,
G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY | (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS)));
/** /**
* GstD3D11VideoSink::begin-draw: * GstD3D11VideoSink::begin-draw:
@ -301,7 +303,7 @@ gst_d3d11_video_sink_class_init (GstD3D11VideoSinkClass * klass)
*/ */
gst_d3d11_video_sink_signals[SIGNAL_DRAW] = gst_d3d11_video_sink_signals[SIGNAL_DRAW] =
g_signal_new ("draw", G_TYPE_FROM_CLASS (klass), g_signal_new ("draw", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, (GSignalFlags) (G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (GstD3D11VideoSinkClass, draw), NULL, NULL, NULL, G_STRUCT_OFFSET (GstD3D11VideoSinkClass, draw), NULL, NULL, NULL,
G_TYPE_BOOLEAN, 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT64, G_TYPE_BOOLEAN, 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT64,
G_TYPE_UINT64); G_TYPE_UINT64);
@ -335,7 +337,8 @@ gst_d3d11_video_sink_class_init (GstD3D11VideoSinkClass * klass)
klass->draw = gst_d3d11_video_sink_draw_action; klass->draw = gst_d3d11_video_sink_draw_action;
gst_type_mark_as_plugin_api (GST_D3D11_WINDOW_TOGGLE_MODE_GET_TYPE, 0); gst_type_mark_as_plugin_api (GST_D3D11_WINDOW_TOGGLE_MODE_GET_TYPE,
(GstPluginAPIFlags) 0);
} }
static void static void
@ -377,7 +380,8 @@ gst_d3d11_videosink_set_property (GObject * object, guint prop_id,
} }
break; break;
case PROP_FULLSCREEN_TOGGLE_MODE: case PROP_FULLSCREEN_TOGGLE_MODE:
self->fullscreen_toggle_mode = g_value_get_flags (value); self->fullscreen_toggle_mode =
(GstD3D11WindowFullscreenToggleMode) g_value_get_flags (value);
if (self->window) { if (self->window) {
g_object_set (self->window, g_object_set (self->window,
"fullscreen-toggle-mode", self->fullscreen_toggle_mode, NULL); "fullscreen-toggle-mode", self->fullscreen_toggle_mode, NULL);
@ -471,7 +475,7 @@ gst_d3d11_video_sink_get_supported_caps (GstD3D11VideoSink * self,
GstD3D11Device *device; GstD3D11Device *device;
ID3D11Device *d3d11_device; ID3D11Device *d3d11_device;
HRESULT hr; HRESULT hr;
gint i; guint i;
GValue v_list = G_VALUE_INIT; GValue v_list = G_VALUE_INIT;
GstCaps *supported_caps; GstCaps *supported_caps;
static const GstVideoFormat format_list[] = { static const GstVideoFormat format_list[] = {
@ -501,8 +505,8 @@ gst_d3d11_video_sink_get_supported_caps (GstD3D11VideoSink * self,
continue; continue;
format = d3d11_format->format; format = d3d11_format->format;
hr = ID3D11Device_CheckFormatSupport (d3d11_device, hr = d3d11_device->CheckFormatSupport (d3d11_format->dxgi_format,
d3d11_format->dxgi_format, &format_support); &format_support);
if (SUCCEEDED (hr) && ((format_support & flags) == flags)) { if (SUCCEEDED (hr) && ((format_support & flags) == flags)) {
GValue v_str = G_VALUE_INIT; GValue v_str = G_VALUE_INIT;
@ -539,7 +543,8 @@ gst_d3d11_video_sink_get_caps (GstBaseSink * sink, GstCaps * filter)
GstCapsFeatures *features; GstCapsFeatures *features;
caps = gst_d3d11_video_sink_get_supported_caps (self, caps = gst_d3d11_video_sink_get_supported_caps (self,
D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_DISPLAY); (D3D11_FORMAT_SUPPORT) (D3D11_FORMAT_SUPPORT_TEXTURE2D |
D3D11_FORMAT_SUPPORT_DISPLAY));
overlaycaps = gst_caps_copy (caps); overlaycaps = gst_caps_copy (caps);
features = gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY, features = gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY,
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, NULL); GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, NULL);
@ -684,7 +689,7 @@ gst_d3d11_video_sink_set_caps (GstBaseSink * sink, GstCaps * caps)
} }
d3d11_params = gst_d3d11_allocation_params_new (self->device, d3d11_params = gst_d3d11_allocation_params_new (self->device,
&self->info, 0, bind_flags); &self->info, (GstD3D11AllocationFlags) 0, bind_flags);
self->fallback_pool = gst_d3d11_buffer_pool_new_with_options (self->device, self->fallback_pool = gst_d3d11_buffer_pool_new_with_options (self->device,
caps, d3d11_params, 2, 0); caps, d3d11_params, 2, 0);
@ -909,8 +914,8 @@ gst_d3d11_video_sink_propose_allocation (GstBaseSink * sink, GstQuery * query)
GST_DEBUG_OBJECT (self, "create new pool"); GST_DEBUG_OBJECT (self, "create new pool");
d3d11_params = gst_d3d11_allocation_params_new (self->device, &info, 0, d3d11_params = gst_d3d11_allocation_params_new (self->device, &info,
D3D11_BIND_SHADER_RESOURCE); (GstD3D11AllocationFlags) 0, D3D11_BIND_SHADER_RESOURCE);
pool = gst_d3d11_buffer_pool_new_with_options (self->device, caps, pool = gst_d3d11_buffer_pool_new_with_options (self->device, caps,
d3d11_params, 2, 0); d3d11_params, 2, 0);
gst_d3d11_allocation_params_free (d3d11_params); gst_d3d11_allocation_params_free (d3d11_params);
@ -1001,11 +1006,11 @@ gst_d3d11_video_sink_upload_frame (GstD3D11VideoSink * self, GstBuffer * inbuf,
GST_LOG_OBJECT (self, "Copy to fallback buffer"); GST_LOG_OBJECT (self, "Copy to fallback buffer");
if (!gst_video_frame_map (&in_frame, &self->info, inbuf, if (!gst_video_frame_map (&in_frame, &self->info, inbuf,
GST_MAP_READ | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)) (GstMapFlags) (GST_MAP_READ | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)))
goto invalid_buffer; goto invalid_buffer;
if (!gst_video_frame_map (&out_frame, &self->info, outbuf, if (!gst_video_frame_map (&out_frame, &self->info, outbuf,
GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF)) { (GstMapFlags) (GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF))) {
gst_video_frame_unmap (&in_frame); gst_video_frame_unmap (&in_frame);
goto invalid_buffer; goto invalid_buffer;
} }

View file

@ -180,105 +180,111 @@ gst_d3d11_video_sink_bin_class_init (GstD3D11VideoSinkBinClass * klass)
/* basesink */ /* basesink */
g_object_class_install_property (gobject_class, PROP_SYNC, g_object_class_install_property (gobject_class, PROP_SYNC,
g_param_spec_boolean ("sync", "Sync", "Sync on the clock", DEFAULT_SYNC, g_param_spec_boolean ("sync", "Sync", "Sync on the clock", DEFAULT_SYNC,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_MAX_LATENESS, g_object_class_install_property (gobject_class, PROP_MAX_LATENESS,
g_param_spec_int64 ("max-lateness", "Max Lateness", g_param_spec_int64 ("max-lateness", "Max Lateness",
"Maximum number of nanoseconds that a buffer can be late before it " "Maximum number of nanoseconds that a buffer can be late before it "
"is dropped (-1 unlimited)", -1, G_MAXINT64, DEFAULT_MAX_LATENESS, "is dropped (-1 unlimited)", -1, G_MAXINT64, DEFAULT_MAX_LATENESS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_QOS, g_object_class_install_property (gobject_class, PROP_QOS,
g_param_spec_boolean ("qos", "Qos", g_param_spec_boolean ("qos", "Qos",
"Generate Quality-of-Service events upstream", DEFAULT_QOS, "Generate Quality-of-Service events upstream", DEFAULT_QOS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_ASYNC, g_object_class_install_property (gobject_class, PROP_ASYNC,
g_param_spec_boolean ("async", "Async", g_param_spec_boolean ("async", "Async",
"Go asynchronously to PAUSED", DEFAULT_ASYNC, "Go asynchronously to PAUSED", DEFAULT_ASYNC,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_TS_OFFSET, g_object_class_install_property (gobject_class, PROP_TS_OFFSET,
g_param_spec_int64 ("ts-offset", "TS Offset", g_param_spec_int64 ("ts-offset", "TS Offset",
"Timestamp offset in nanoseconds", G_MININT64, G_MAXINT64, "Timestamp offset in nanoseconds", G_MININT64, G_MAXINT64,
DEFAULT_TS_OFFSET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_TS_OFFSET,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_ENABLE_LAST_SAMPLE, g_object_class_install_property (gobject_class, PROP_ENABLE_LAST_SAMPLE,
g_param_spec_boolean ("enable-last-sample", "Enable Last Buffer", g_param_spec_boolean ("enable-last-sample", "Enable Last Buffer",
"Enable the last-sample property", DEFAULT_ENABLE_LAST_SAMPLE, "Enable the last-sample property", DEFAULT_ENABLE_LAST_SAMPLE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_LAST_SAMPLE, g_object_class_install_property (gobject_class, PROP_LAST_SAMPLE,
g_param_spec_boxed ("last-sample", "Last Sample", g_param_spec_boxed ("last-sample", "Last Sample",
"The last sample received in the sink", GST_TYPE_SAMPLE, "The last sample received in the sink", GST_TYPE_SAMPLE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_BLOCKSIZE, g_object_class_install_property (gobject_class, PROP_BLOCKSIZE,
g_param_spec_uint ("blocksize", "Block size", g_param_spec_uint ("blocksize", "Block size",
"Size in bytes to pull per buffer (0 = default)", 0, G_MAXUINT, "Size in bytes to pull per buffer (0 = default)", 0, G_MAXUINT,
DEFAULT_BLOCKSIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_BLOCKSIZE,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_RENDER_DELAY, g_object_class_install_property (gobject_class, PROP_RENDER_DELAY,
g_param_spec_uint64 ("render-delay", "Render Delay", g_param_spec_uint64 ("render-delay", "Render Delay",
"Additional render delay of the sink in nanoseconds", 0, G_MAXUINT64, "Additional render delay of the sink in nanoseconds", 0, G_MAXUINT64,
DEFAULT_RENDER_DELAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_RENDER_DELAY,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_THROTTLE_TIME, g_object_class_install_property (gobject_class, PROP_THROTTLE_TIME,
g_param_spec_uint64 ("throttle-time", "Throttle time", g_param_spec_uint64 ("throttle-time", "Throttle time",
"The time to keep between rendered buffers (0 = disabled)", 0, "The time to keep between rendered buffers (0 = disabled)", 0,
G_MAXUINT64, DEFAULT_THROTTLE_TIME, G_MAXUINT64, DEFAULT_THROTTLE_TIME,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_MAX_BITRATE, g_object_class_install_property (gobject_class, PROP_MAX_BITRATE,
g_param_spec_uint64 ("max-bitrate", "Max Bitrate", g_param_spec_uint64 ("max-bitrate", "Max Bitrate",
"The maximum bits per second to render (0 = disabled)", 0, "The maximum bits per second to render (0 = disabled)", 0,
G_MAXUINT64, DEFAULT_MAX_BITRATE, G_MAXUINT64, DEFAULT_MAX_BITRATE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_PROCESSING_DEADLINE, g_object_class_install_property (gobject_class, PROP_PROCESSING_DEADLINE,
g_param_spec_uint64 ("processing-deadline", "Processing deadline", g_param_spec_uint64 ("processing-deadline", "Processing deadline",
"Maximum processing deadline in nanoseconds", 0, G_MAXUINT64, "Maximum processing deadline in nanoseconds", 0, G_MAXUINT64,
DEFAULT_PROCESSING_DEADLINE, DEFAULT_PROCESSING_DEADLINE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_STATS, g_object_class_install_property (gobject_class, PROP_STATS,
g_param_spec_boxed ("stats", "Statistics", g_param_spec_boxed ("stats", "Statistics",
"Sink Statistics", GST_TYPE_STRUCTURE, "Sink Statistics", GST_TYPE_STRUCTURE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
/* videosink */ /* videosink */
g_object_class_install_property (gobject_class, PROP_SHOW_PREROLL_FRAME, g_object_class_install_property (gobject_class, PROP_SHOW_PREROLL_FRAME,
g_param_spec_boolean ("show-preroll-frame", "Show preroll frame", g_param_spec_boolean ("show-preroll-frame", "Show preroll frame",
"Whether to render video frames during preroll", "Whether to render video frames during preroll",
DEFAULT_SHOW_PREROLL_FRAME, DEFAULT_SHOW_PREROLL_FRAME,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS)));
/* d3d11videosink */ /* d3d11videosink */
g_object_class_install_property (gobject_class, PROP_ADAPTER, g_object_class_install_property (gobject_class, PROP_ADAPTER,
g_param_spec_int ("adapter", "Adapter", g_param_spec_int ("adapter", "Adapter",
"Adapter index for creating device (-1 for default)", "Adapter index for creating device (-1 for default)",
-1, G_MAXINT32, DEFAULT_ADAPTER, -1, G_MAXINT32, DEFAULT_ADAPTER,
G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY | (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO, g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO,
g_param_spec_boolean ("force-aspect-ratio", g_param_spec_boolean ("force-aspect-ratio",
"Force aspect ratio", "Force aspect ratio",
"When enabled, scaling will respect original aspect ratio", "When enabled, scaling will respect original aspect ratio",
DEFAULT_FORCE_ASPECT_RATIO, DEFAULT_FORCE_ASPECT_RATIO,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_ENABLE_NAVIGATION_EVENTS, g_object_class_install_property (gobject_class, PROP_ENABLE_NAVIGATION_EVENTS,
g_param_spec_boolean ("enable-navigation-events", g_param_spec_boolean ("enable-navigation-events",
"Enable navigation events", "Enable navigation events",
"When enabled, navigation events are sent upstream", "When enabled, navigation events are sent upstream",
DEFAULT_ENABLE_NAVIGATION_EVENTS, DEFAULT_ENABLE_NAVIGATION_EVENTS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_FULLSCREEN_TOGGLE_MODE, g_object_class_install_property (gobject_class, PROP_FULLSCREEN_TOGGLE_MODE,
g_param_spec_flags ("fullscreen-toggle-mode", g_param_spec_flags ("fullscreen-toggle-mode",
"Full screen toggle mode", "Full screen toggle mode",
"Full screen toggle mode used to trigger fullscreen mode change", "Full screen toggle mode used to trigger fullscreen mode change",
GST_D3D11_WINDOW_TOGGLE_MODE_GET_TYPE, DEFAULT_FULLSCREEN_TOGGLE_MODE, GST_D3D11_WINDOW_TOGGLE_MODE_GET_TYPE, DEFAULT_FULLSCREEN_TOGGLE_MODE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_FULLSCREEN, g_object_class_install_property (gobject_class, PROP_FULLSCREEN,
g_param_spec_boolean ("fullscreen", g_param_spec_boolean ("fullscreen",
"fullscreen", "fullscreen",
"Ignored when \"fullscreen-toggle-mode\" does not include \"property\"", "Ignored when \"fullscreen-toggle-mode\" does not include \"property\"",
DEFAULT_FULLSCREEN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_FULLSCREEN,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
#ifdef HAVE_DIRECT_WRITE #ifdef HAVE_DIRECT_WRITE
g_object_class_install_property (gobject_class, PROP_RENDER_STATS, g_object_class_install_property (gobject_class, PROP_RENDER_STATS,
g_param_spec_boolean ("render-stats", g_param_spec_boolean ("render-stats",
"Render Stats", "Render Stats",
"Render statistics data (e.g., average framerate) on window", "Render statistics data (e.g., average framerate) on window",
DEFAULT_RENDER_STATS, DEFAULT_RENDER_STATS,
GST_PARAM_CONDITIONALLY_AVAILABLE | GST_PARAM_MUTABLE_READY | (GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS)));
#endif #endif
/** /**
@ -307,8 +313,8 @@ gst_d3d11_video_sink_bin_class_init (GstD3D11VideoSinkBinClass * klass)
"DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, and " "DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, and "
"DXGI_FORMAT_R10G10B10A2_UNORM.", "DXGI_FORMAT_R10G10B10A2_UNORM.",
DEFAULT_DRAW_ON_SHARED_TEXTURE, DEFAULT_DRAW_ON_SHARED_TEXTURE,
G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY | (GParamFlags) (G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS)));
/** /**
* GstD3D11VideoSinkBin::begin-draw: * GstD3D11VideoSinkBin::begin-draw:
@ -346,7 +352,7 @@ gst_d3d11_video_sink_bin_class_init (GstD3D11VideoSinkBinClass * klass)
*/ */
gst_d3d11_video_sink_bin_signals[SIGNAL_DRAW] = gst_d3d11_video_sink_bin_signals[SIGNAL_DRAW] =
g_signal_new ("draw", G_TYPE_FROM_CLASS (klass), g_signal_new ("draw", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, (GSignalFlags) (G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (GstD3D11VideoSinkBinClass, draw), NULL, NULL, NULL, G_STRUCT_OFFSET (GstD3D11VideoSinkBinClass, draw), NULL, NULL, NULL,
G_TYPE_BOOLEAN, 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT64, G_TYPE_BOOLEAN, 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT64,
G_TYPE_UINT64); G_TYPE_UINT64);

View file

@ -49,9 +49,15 @@
#include <d3d9.h> #include <d3d9.h>
#include <dxva.h> #include <dxva.h>
/* *INDENT-OFF* */
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_vp8_dec_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_vp8_dec_debug);
#define GST_CAT_DEFAULT gst_d3d11_vp8_dec_debug #define GST_CAT_DEFAULT gst_d3d11_vp8_dec_debug
G_END_DECLS
/* *INDENT-ON* */
enum enum
{ {
PROP_0, PROP_0,
@ -138,17 +144,17 @@ gst_d3d11_vp8_dec_class_init (GstD3D11Vp8DecClass * klass, gpointer data)
g_param_spec_uint ("adapter", "Adapter", g_param_spec_uint ("adapter", "Adapter",
"DXGI Adapter index for creating device", "DXGI Adapter index for creating device",
0, G_MAXUINT32, cdata->adapter, 0, G_MAXUINT32, cdata->adapter,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_DEVICE_ID, g_object_class_install_property (gobject_class, PROP_DEVICE_ID,
g_param_spec_uint ("device-id", "Device Id", g_param_spec_uint ("device-id", "Device Id",
"DXGI Device ID", 0, G_MAXUINT32, 0, "DXGI Device ID", 0, G_MAXUINT32, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_VENDOR_ID, g_object_class_install_property (gobject_class, PROP_VENDOR_ID,
g_param_spec_uint ("vendor-id", "Vendor Id", g_param_spec_uint ("vendor-id", "Vendor Id",
"DXGI Vendor ID", 0, G_MAXUINT32, 0, "DXGI Vendor ID", 0, G_MAXUINT32, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
parent_class = g_type_class_peek_parent (klass); parent_class = (GstElementClass *) g_type_class_peek_parent (klass);
klass->adapter = cdata->adapter; klass->adapter = cdata->adapter;
klass->device_id = cdata->device_id; klass->device_id = cdata->device_id;
@ -660,9 +666,11 @@ gst_d3d11_vp8_dec_submit_picture_data (GstD3D11Vp8Dec * self,
gsize written_buffer_size; gsize written_buffer_size;
gboolean is_last = TRUE; gboolean is_last = TRUE;
DXVA_Slice_VPx_Short slice_short = { 0, }; DXVA_Slice_VPx_Short slice_short = { 0, };
D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[3] = { 0, }; D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[3];
gboolean bad_aligned_bitstream_buffer = FALSE; gboolean bad_aligned_bitstream_buffer = FALSE;
memset (buffer_desc, 0, sizeof (buffer_desc));
GST_TRACE_OBJECT (self, "Getting bitstream buffer"); GST_TRACE_OBJECT (self, "Getting bitstream buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder, if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM, &d3d11_buffer_size, D3D11_VIDEO_DECODER_BUFFER_BITSTREAM, &d3d11_buffer_size,
@ -929,7 +937,7 @@ gst_d3d11_vp8_dec_register (GstPlugin * plugin, GstD3D11Device * device,
} }
type = g_type_register_static (GST_TYPE_VP8_DECODER, type = g_type_register_static (GST_TYPE_VP8_DECODER,
type_name, &type_info, 0); type_name, &type_info, (GTypeFlags) 0);
/* make lower rank than default device */ /* make lower rank than default device */
if (rank > 0 && index != 0) if (rank > 0 && index != 0)

View file

@ -79,9 +79,15 @@
#include <d3d9.h> #include <d3d9.h>
#include <dxva.h> #include <dxva.h>
/* *INDENT-OFF* */
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_vp9_dec_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_vp9_dec_debug);
#define GST_CAT_DEFAULT gst_d3d11_vp9_dec_debug #define GST_CAT_DEFAULT gst_d3d11_vp9_dec_debug
G_END_DECLS
/* *INDENT-ON* */
enum enum
{ {
PROP_0, PROP_0,
@ -176,17 +182,17 @@ gst_d3d11_vp9_dec_class_init (GstD3D11Vp9DecClass * klass, gpointer data)
g_param_spec_uint ("adapter", "Adapter", g_param_spec_uint ("adapter", "Adapter",
"DXGI Adapter index for creating device", "DXGI Adapter index for creating device",
0, G_MAXUINT32, cdata->adapter, 0, G_MAXUINT32, cdata->adapter,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_DEVICE_ID, g_object_class_install_property (gobject_class, PROP_DEVICE_ID,
g_param_spec_uint ("device-id", "Device Id", g_param_spec_uint ("device-id", "Device Id",
"DXGI Device ID", 0, G_MAXUINT32, 0, "DXGI Device ID", 0, G_MAXUINT32, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_VENDOR_ID, g_object_class_install_property (gobject_class, PROP_VENDOR_ID,
g_param_spec_uint ("vendor-id", "Vendor Id", g_param_spec_uint ("vendor-id", "Vendor Id",
"DXGI Vendor ID", 0, G_MAXUINT32, 0, "DXGI Vendor ID", 0, G_MAXUINT32, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
parent_class = g_type_class_peek_parent (klass); parent_class = (GstElementClass *) g_type_class_peek_parent (klass);
klass->adapter = cdata->adapter; klass->adapter = cdata->adapter;
klass->device_id = cdata->device_id; klass->device_id = cdata->device_id;
@ -376,7 +382,7 @@ gst_d3d11_vp9_dec_new_sequence (GstVp9Decoder * decoder,
} }
if (self->profile != frame_hdr->profile) { if (self->profile != frame_hdr->profile) {
self->profile = frame_hdr->profile; self->profile = (GstVP9Profile) frame_hdr->profile;
GST_INFO_OBJECT (self, "profile changed %d", self->profile); GST_INFO_OBJECT (self, "profile changed %d", self->profile);
modified = TRUE; modified = TRUE;
} }
@ -452,7 +458,7 @@ gst_d3d11_vp9_dec_duplicate_picture (GstVp9Decoder * decoder,
GstBuffer *view_buffer; GstBuffer *view_buffer;
GstVp9Picture *new_picture; GstVp9Picture *new_picture;
view_buffer = gst_vp9_picture_get_user_data (picture); view_buffer = (GstBuffer *) gst_vp9_picture_get_user_data (picture);
if (!view_buffer) { if (!view_buffer) {
GST_ERROR_OBJECT (self, "Parent picture does not have output view buffer"); GST_ERROR_OBJECT (self, "Parent picture does not have output view buffer");
@ -499,9 +505,9 @@ gst_d3d11_vp9_dec_output_picture (GstVp9Decoder * decoder,
if (self->use_d3d11_output if (self->use_d3d11_output
&& GST_VIDEO_DECODER (self)->input_segment.rate > 0 && GST_VIDEO_DECODER (self)->input_segment.rate > 0
&& GST_VIDEO_INFO_WIDTH (&self->output_state->info) == && GST_VIDEO_INFO_WIDTH (&self->output_state->info) ==
picture->frame_hdr.width (gint) picture->frame_hdr.width
&& GST_VIDEO_INFO_HEIGHT (&self->output_state->info) == && GST_VIDEO_INFO_HEIGHT (&self->output_state->info) ==
picture->frame_hdr.height (gint) picture->frame_hdr.height
&& gst_d3d11_decoder_can_direct_render (self->d3d11_decoder, view_buffer, && gst_d3d11_decoder_can_direct_render (self->d3d11_decoder, view_buffer,
GST_MINI_OBJECT_CAST (picture))) { GST_MINI_OBJECT_CAST (picture))) {
direct_rendering = TRUE; direct_rendering = TRUE;
@ -895,9 +901,11 @@ gst_d3d11_vp9_dec_submit_picture_data (GstD3D11Vp9Dec * self,
gsize written_buffer_size; gsize written_buffer_size;
gboolean is_last = TRUE; gboolean is_last = TRUE;
DXVA_Slice_VPx_Short slice_short = { 0, }; DXVA_Slice_VPx_Short slice_short = { 0, };
D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[3] = { 0, }; D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[3];
gboolean bad_aligned_bitstream_buffer = FALSE; gboolean bad_aligned_bitstream_buffer = FALSE;
memset (buffer_desc, 0, sizeof (buffer_desc));
GST_TRACE_OBJECT (self, "Getting bitstream buffer"); GST_TRACE_OBJECT (self, "Getting bitstream buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder, if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM, &d3d11_buffer_size, D3D11_VIDEO_DECODER_BUFFER_BITSTREAM, &d3d11_buffer_size,
@ -1240,7 +1248,7 @@ gst_d3d11_vp9_dec_register (GstPlugin * plugin, GstD3D11Device * device,
} }
type = g_type_register_static (GST_TYPE_VP9_DECODER, type = g_type_register_static (GST_TYPE_VP9_DECODER,
type_name, &type_info, 0); type_name, &type_info, (GTypeFlags) 0);
/* make lower rank than default device */ /* make lower rank than default device */
if (rank > 0 && index != 0) if (rank > 0 && index != 0)

View file

@ -40,16 +40,17 @@
#include <sstream> #include <sstream>
#endif #endif
#if GST_D3D11_WINAPI_APP || defined(HAVE_DIRECT_WRITE)
#include <wrl.h> #include <wrl.h>
#include <wrl/wrappers/corewrappers.h> /* *INDENT-OFF* */
using namespace Microsoft::WRL; using namespace Microsoft::WRL;
#endif
extern "C" { G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_window_debug); GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_window_debug);
#define GST_CAT_DEFAULT gst_d3d11_window_debug #define GST_CAT_DEFAULT gst_d3d11_window_debug
}
G_END_DECLS
/* *INDENT-ON* */
struct _GstD3D11WindowPrivate struct _GstD3D11WindowPrivate
{ {
@ -297,35 +298,12 @@ gst_d3d11_window_release_dwrite_resources (GstD3D11Window * self)
{ {
GstD3D11WindowPrivate *priv = self->priv; GstD3D11WindowPrivate *priv = self->priv;
if (priv->d2d_device_context) { GST_D3D11_CLEAR_COM (priv->d2d_device_context);
priv->d2d_device_context->Release (); GST_D3D11_CLEAR_COM (priv->d2d_factory);
priv->d2d_device_context = NULL; GST_D3D11_CLEAR_COM (priv->d2d_device);
} GST_D3D11_CLEAR_COM (priv->d2d_brush);
GST_D3D11_CLEAR_COM (priv->dwrite_factory);
if (priv->d2d_factory) { GST_D3D11_CLEAR_COM (priv->dwrite_format);
priv->d2d_factory->Release ();
priv->d2d_factory = NULL;
}
if (priv->d2d_device) {
priv->d2d_device->Release ();
priv->d2d_device = NULL;
}
if (priv->d2d_brush) {
priv->d2d_brush->Release ();
priv->d2d_brush = NULL;
}
if (priv->dwrite_factory) {
priv->dwrite_factory->Release ();
priv->dwrite_factory = NULL;
}
if (priv->dwrite_format) {
priv->dwrite_format->Release ();
priv->dwrite_format = NULL;
}
} }
static void static void
@ -440,20 +418,9 @@ gst_d3d11_window_release_resources (GstD3D11Device * device,
gst_d3d11_window_release_dwrite_resources (window); gst_d3d11_window_release_dwrite_resources (window);
#endif #endif
if (window->rtv) { GST_D3D11_CLEAR_COM (window->rtv);
window->rtv->Release (); GST_D3D11_CLEAR_COM (window->pov);
window->rtv = NULL; GST_D3D11_CLEAR_COM (window->swap_chain);
}
if (window->pov) {
window->pov->Release ();
window->pov = NULL;
}
if (window->swap_chain) {
window->swap_chain->Release ();
window->swap_chain = NULL;
}
} }
static void static void
@ -466,7 +433,7 @@ gst_d3d11_window_dispose (GObject * object)
} }
g_clear_pointer (&self->processor, gst_d3d11_video_processor_free); g_clear_pointer (&self->processor, gst_d3d11_video_processor_free);
g_clear_pointer (&self->converter, gst_d3d11_color_converter_free); g_clear_pointer (&self->converter, gst_d3d11_converter_free);
g_clear_pointer (&self->compositor, gst_d3d11_overlay_compositor_free); g_clear_pointer (&self->compositor, gst_d3d11_overlay_compositor_free);
gst_clear_buffer (&self->cached_buffer); gst_clear_buffer (&self->cached_buffer);
@ -497,15 +464,8 @@ gst_d3d11_window_on_resize_default (GstD3D11Window * window, guint width,
device_handle = gst_d3d11_device_get_device_handle (window->device); device_handle = gst_d3d11_device_get_device_handle (window->device);
swap_chain = window->swap_chain; swap_chain = window->swap_chain;
if (window->rtv) { GST_D3D11_CLEAR_COM (window->rtv);
window->rtv->Release (); GST_D3D11_CLEAR_COM (window->pov);
window->rtv = NULL;
}
if (window->pov) {
window->pov->Release ();
window->pov = NULL;
}
#ifdef HAVE_DIRECT_WRITE #ifdef HAVE_DIRECT_WRITE
/* D2D bitmap need to be cleared before resizing swapchain buffer */ /* D2D bitmap need to be cleared before resizing swapchain buffer */
@ -593,8 +553,7 @@ gst_d3d11_window_on_resize_default (GstD3D11Window * window, guint width,
} }
done: done:
if (backbuffer) GST_D3D11_CLEAR_COM (backbuffer);
backbuffer->Release ();
gst_d3d11_device_unlock (window->device); gst_d3d11_device_unlock (window->device);
} }
@ -683,7 +642,7 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width,
/* Step 1: Clear old resources and objects */ /* Step 1: Clear old resources and objects */
gst_clear_buffer (&window->cached_buffer); gst_clear_buffer (&window->cached_buffer);
g_clear_pointer (&window->processor, gst_d3d11_video_processor_free); g_clear_pointer (&window->processor, gst_d3d11_video_processor_free);
g_clear_pointer (&window->converter, gst_d3d11_color_converter_free); g_clear_pointer (&window->converter, gst_d3d11_converter_free);
g_clear_pointer (&window->compositor, gst_d3d11_overlay_compositor_free); g_clear_pointer (&window->compositor, gst_d3d11_overlay_compositor_free);
/* Step 2: Decide display color format /* Step 2: Decide display color format
@ -958,7 +917,7 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width,
/* configure shader even if video processor is available for fallback */ /* configure shader even if video processor is available for fallback */
window->converter = window->converter =
gst_d3d11_color_converter_new (window->device, &window->info, gst_d3d11_converter_new (window->device, &window->info,
&window->render_info); &window->render_info);
if (!window->converter) { if (!window->converter) {
@ -1142,7 +1101,7 @@ gst_d3d111_window_present (GstD3D11Window * self, GstBuffer * buffer,
viewport.Height = self->render_rect.bottom - self->render_rect.top; viewport.Height = self->render_rect.bottom - self->render_rect.top;
viewport.MinDepth = 0.0f; viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f; viewport.MaxDepth = 1.0f;
gst_d3d11_color_converter_update_viewport (self->converter, gst_d3d11_converter_update_viewport (self->converter,
&viewport); &viewport);
gst_d3d11_overlay_compositor_update_viewport (self->compositor, gst_d3d11_overlay_compositor_update_viewport (self->compositor,
&viewport); &viewport);
@ -1158,7 +1117,7 @@ gst_d3d111_window_present (GstD3D11Window * self, GstBuffer * buffer,
GST_TRACE_OBJECT (self, "Rendered using processor"); GST_TRACE_OBJECT (self, "Rendered using processor");
} }
} else { } else {
if (!gst_d3d11_color_converter_convert_unlocked (self->converter, if (!gst_d3d11_converter_convert_unlocked (self->converter,
srv, &rtv, NULL, NULL)) { srv, &rtv, NULL, NULL)) {
GST_ERROR_OBJECT (self, "Couldn't render to backbuffer using converter"); GST_ERROR_OBJECT (self, "Couldn't render to backbuffer using converter");
ret = GST_FLOW_ERROR; ret = GST_FLOW_ERROR;

View file

@ -25,7 +25,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h> #include <gst/video/video.h>
#include <gst/d3d11/gstd3d11.h> #include <gst/d3d11/gstd3d11.h>
#include "gstd3d11colorconverter.h" #include "gstd3d11converter.h"
#include "gstd3d11overlaycompositor.h" #include "gstd3d11overlaycompositor.h"
#include "gstd3d11videoprocessor.h" #include "gstd3d11videoprocessor.h"
#include "gstd3d11pluginutils.h" #include "gstd3d11pluginutils.h"
@ -99,7 +99,7 @@ struct _GstD3D11Window
GstVideoInfo info; GstVideoInfo info;
GstVideoInfo render_info; GstVideoInfo render_info;
GstD3D11VideoProcessor *processor; GstD3D11VideoProcessor *processor;
GstD3D11ColorConverter *converter; GstD3D11Converter *converter;
GstD3D11OverlayCompositor *compositor; GstD3D11OverlayCompositor *compositor;
/* calculated rect with aspect ratio and window area */ /* calculated rect with aspect ratio and window area */

View file

@ -23,6 +23,7 @@
#endif #endif
#include "gstd3d11window_dummy.h" #include "gstd3d11window_dummy.h"
#include "gstd3d11pluginutils.h"
#include <wrl.h> #include <wrl.h>
using namespace Microsoft::WRL; using namespace Microsoft::WRL;
@ -88,7 +89,7 @@ gst_d3d11_window_dummy_prepare (GstD3D11Window * window,
gboolean * video_processor_available, GError ** error) gboolean * video_processor_available, GError ** error)
{ {
g_clear_pointer (&window->processor, gst_d3d11_video_processor_free); g_clear_pointer (&window->processor, gst_d3d11_video_processor_free);
g_clear_pointer (&window->converter, gst_d3d11_color_converter_free); g_clear_pointer (&window->converter, gst_d3d11_converter_free);
g_clear_pointer (&window->compositor, gst_d3d11_overlay_compositor_free); g_clear_pointer (&window->compositor, gst_d3d11_overlay_compositor_free);
/* We are supporting only RGBA, BGRA or RGB10A2_LE formats but we don't know /* We are supporting only RGBA, BGRA or RGB10A2_LE formats but we don't know
@ -174,7 +175,7 @@ gst_d3d11_window_dummy_prepare (GstD3D11Window * window,
*video_processor_available = !!window->processor; *video_processor_available = !!window->processor;
window->converter = window->converter =
gst_d3d11_color_converter_new (window->device, &window->info, gst_d3d11_converter_new (window->device, &window->info,
&window->render_info); &window->render_info);
if (!window->converter) { if (!window->converter) {
@ -206,20 +207,9 @@ error:
static void static void
gst_d3d11_window_dummy_clear_resources (GstD3D11WindowDummy * self) gst_d3d11_window_dummy_clear_resources (GstD3D11WindowDummy * self)
{ {
if (self->fallback_pov) { GST_D3D11_CLEAR_COM (self->fallback_pov);
self->fallback_pov->Release (); GST_D3D11_CLEAR_COM (self->fallback_rtv);
self->fallback_pov = nullptr; GST_D3D11_CLEAR_COM (self->fallback_texture);
}
if (self->fallback_rtv) {
self->fallback_rtv->Release ();
self->fallback_rtv = nullptr;
}
if (self->fallback_texture) {
self->fallback_texture->Release ();
self->fallback_texture = nullptr;
}
} }
static void static void
@ -450,14 +440,10 @@ gst_d3d11_window_dummy_open_shared_handle (GstD3D11Window * window,
return TRUE; return TRUE;
out: out:
if (texture) GST_D3D11_CLEAR_COM (texture);
texture->Release (); GST_D3D11_CLEAR_COM (keyed_mutex);
if (keyed_mutex) GST_D3D11_CLEAR_COM (pov);
keyed_mutex->Release (); GST_D3D11_CLEAR_COM (rtv);
if (pov)
pov->Release ();
if (rtv)
rtv->Release ();
return FALSE; return FALSE;
} }
@ -527,12 +513,9 @@ gst_d3d11_window_dummy_release_shared_handle (GstD3D11Window * window,
} }
} }
if (data->rtv) GST_D3D11_CLEAR_COM (data->rtv);
data->rtv->Release (); GST_D3D11_CLEAR_COM (data->pov);
if (data->pov) GST_D3D11_CLEAR_COM (data->texture);
data->pov->Release ();
if (data->texture)
data->texture->Release ();
return TRUE; return TRUE;
} }

View file

@ -1,29 +1,29 @@
d3d11_sources = [ d3d11_sources = [
'gstd3d11basefilter.c', 'gstd3d11basefilter.cpp',
'gstd3d11colorconvert.c', 'gstd3d11convert.cpp',
'gstd3d11colorconverter.c', 'gstd3d11converter.cpp',
'gstd3d11compositor.c', 'gstd3d11compositor.cpp',
'gstd3d11compositorbin.c', 'gstd3d11compositorbin.cpp',
'gstd3d11download.c', 'gstd3d11download.cpp',
'gstd3d11overlaycompositor.c', 'gstd3d11overlaycompositor.cpp',
'gstd3d11pluginutils.c', 'gstd3d11pluginutils.cpp',
'gstd3d11shader.c', 'gstd3d11shader.cpp',
'gstd3d11upload.c', 'gstd3d11upload.cpp',
'gstd3d11videoprocessor.c', 'gstd3d11videoprocessor.cpp',
'gstd3d11videosink.c', 'gstd3d11videosink.cpp',
'gstd3d11videosinkbin.c', 'gstd3d11videosinkbin.cpp',
'gstd3d11window.cpp', 'gstd3d11window.cpp',
'gstd3d11window_dummy.cpp', 'gstd3d11window_dummy.cpp',
'plugin.c', 'plugin.c',
] ]
d3d11_dec_sources = [ d3d11_dec_sources = [
'gstd3d11decoder.c', 'gstd3d11decoder.cpp',
'gstd3d11h264dec.c', 'gstd3d11h264dec.cpp',
'gstd3d11vp9dec.c', 'gstd3d11vp9dec.cpp',
'gstd3d11h265dec.c', 'gstd3d11h265dec.cpp',
'gstd3d11mpeg2dec.c', 'gstd3d11mpeg2dec.cpp',
'gstd3d11vp8dec.c', 'gstd3d11vp8dec.cpp',
] ]
extra_c_args = ['-DCOBJMACROS', '-DGST_USE_UNSTABLE_API'] extra_c_args = ['-DCOBJMACROS', '-DGST_USE_UNSTABLE_API']
@ -81,7 +81,7 @@ if d3d11_winapi_desktop
# Desktop Duplication API is unavailable for UWP # Desktop Duplication API is unavailable for UWP
# and MinGW is not supported due to some missing headers # and MinGW is not supported due to some missing headers
extra_c_args += ['-DHAVE_DXGI_DESKTOP_DUP'] extra_c_args += ['-DHAVE_DXGI_DESKTOP_DUP']
d3d11_sources += ['gstd3d11desktopdup.cpp', 'gstd3d11desktopdupsrc.c'] d3d11_sources += ['gstd3d11desktopdup.cpp', 'gstd3d11desktopdupsrc.cpp']
message('Enable D3D11 Desktop Duplication API') message('Enable D3D11 Desktop Duplication API')
endif endif
endif endif

View file

@ -26,7 +26,7 @@
#include "gstd3d11videosink.h" #include "gstd3d11videosink.h"
#include "gstd3d11upload.h" #include "gstd3d11upload.h"
#include "gstd3d11download.h" #include "gstd3d11download.h"
#include "gstd3d11colorconvert.h" #include "gstd3d11convert.h"
#include "gstd3d11videosinkbin.h" #include "gstd3d11videosinkbin.h"
#include "gstd3d11shader.h" #include "gstd3d11shader.h"
#include "gstd3d11compositor.h" #include "gstd3d11compositor.h"
@ -47,7 +47,7 @@
GST_DEBUG_CATEGORY (gst_d3d11_debug); GST_DEBUG_CATEGORY (gst_d3d11_debug);
GST_DEBUG_CATEGORY (gst_d3d11_shader_debug); GST_DEBUG_CATEGORY (gst_d3d11_shader_debug);
GST_DEBUG_CATEGORY (gst_d3d11_colorconverter_debug); GST_DEBUG_CATEGORY (gst_d3d11_converter_debug);
GST_DEBUG_CATEGORY (gst_d3d11_plugin_utils_debug); GST_DEBUG_CATEGORY (gst_d3d11_plugin_utils_debug);
GST_DEBUG_CATEGORY (gst_d3d11_format_debug); GST_DEBUG_CATEGORY (gst_d3d11_format_debug);
GST_DEBUG_CATEGORY (gst_d3d11_device_debug); GST_DEBUG_CATEGORY (gst_d3d11_device_debug);
@ -84,8 +84,8 @@ plugin_init (GstPlugin * plugin)
GST_DEBUG_CATEGORY_INIT (gst_d3d11_debug, "d3d11", 0, "direct3d 11 plugin"); GST_DEBUG_CATEGORY_INIT (gst_d3d11_debug, "d3d11", 0, "direct3d 11 plugin");
GST_DEBUG_CATEGORY_INIT (gst_d3d11_shader_debug, GST_DEBUG_CATEGORY_INIT (gst_d3d11_shader_debug,
"d3d11shader", 0, "d3d11shader"); "d3d11shader", 0, "d3d11shader");
GST_DEBUG_CATEGORY_INIT (gst_d3d11_colorconverter_debug, GST_DEBUG_CATEGORY_INIT (gst_d3d11_converter_debug,
"d3d11colorconverter", 0, "d3d11colorconverter"); "d3d11converter", 0, "d3d11converter");
GST_DEBUG_CATEGORY_INIT (gst_d3d11_plugin_utils_debug, GST_DEBUG_CATEGORY_INIT (gst_d3d11_plugin_utils_debug,
"d3d11pluginutils", 0, "d3d11 plugin utility functions"); "d3d11pluginutils", 0, "d3d11 plugin utility functions");
GST_DEBUG_CATEGORY_INIT (gst_d3d11_overlay_compositor_debug, GST_DEBUG_CATEGORY_INIT (gst_d3d11_overlay_compositor_debug,