mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-21 15:56:42 +00:00
d3d11converter: Objectify converter
... and set conversion options via property Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2622>
This commit is contained in:
parent
3ed94c2dde
commit
59f39724b7
9 changed files with 696 additions and 504 deletions
|
@ -1322,7 +1322,6 @@ gst_d3d11_compositor_pad_setup_converter (GstVideoAggregatorPad * pad,
|
|||
{
|
||||
GstD3D11CompositorPad *cpad = GST_D3D11_COMPOSITOR_PAD (pad);
|
||||
GstD3D11Compositor *self = GST_D3D11_COMPOSITOR (vagg);
|
||||
RECT rect;
|
||||
gint width, height;
|
||||
GstVideoInfo *info = &vagg->info;
|
||||
GstVideoRectangle frame_rect;
|
||||
|
@ -1333,36 +1332,20 @@ gst_d3d11_compositor_pad_setup_converter (GstVideoAggregatorPad * pad,
|
|||
#endif
|
||||
|
||||
if (!cpad->convert || self->reconfigured) {
|
||||
GstStructure *config;
|
||||
|
||||
if (cpad->convert)
|
||||
gst_d3d11_converter_free (cpad->convert);
|
||||
|
||||
config = gst_structure_new_empty ("config");
|
||||
if (cpad->alpha <= 1.0) {
|
||||
gst_structure_set (config, GST_D3D11_CONVERTER_OPT_ALPHA_VALUE,
|
||||
G_TYPE_DOUBLE, cpad->alpha, nullptr);
|
||||
}
|
||||
gst_clear_object (&cpad->convert);
|
||||
|
||||
cpad->convert =
|
||||
gst_d3d11_converter_new (self->device, &pad->info, &vagg->info, config);
|
||||
|
||||
gst_d3d11_converter_new (self->device, &pad->info, &vagg->info);
|
||||
if (!cpad->convert) {
|
||||
GST_ERROR_OBJECT (pad, "Couldn't create converter");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_object_set (cpad->convert, "alpha", cpad->alpha, nullptr);
|
||||
|
||||
is_first = TRUE;
|
||||
} else if (cpad->alpha_updated) {
|
||||
GstStructure *config;
|
||||
|
||||
config = gst_structure_new_empty ("config");
|
||||
if (cpad->alpha <= 1.0) {
|
||||
gst_structure_set (config, GST_D3D11_CONVERTER_OPT_ALPHA_VALUE,
|
||||
G_TYPE_DOUBLE, cpad->alpha, nullptr);
|
||||
}
|
||||
|
||||
gst_d3d11_converter_update_config (cpad->convert, config);
|
||||
g_object_set (cpad->convert, "alpha", cpad->alpha, nullptr);
|
||||
cpad->alpha_updated = FALSE;
|
||||
}
|
||||
|
||||
|
@ -1387,6 +1370,12 @@ gst_d3d11_compositor_pad_setup_converter (GstVideoAggregatorPad * pad,
|
|||
}
|
||||
|
||||
cpad->blend = blend;
|
||||
g_object_set (cpad->convert, "blend-state", blend,
|
||||
"blend-factor-red", cpad->blend_factor[0],
|
||||
"blend-factor-green", cpad->blend_factor[1],
|
||||
"blend-factor-blue", cpad->blend_factor[2],
|
||||
"blend-factor-alpha", cpad->blend_factor[3],
|
||||
"blend-sample-mask", 0xffffffff, nullptr);
|
||||
}
|
||||
|
||||
if (!is_first && !cpad->position_updated)
|
||||
|
@ -1398,26 +1387,25 @@ gst_d3d11_compositor_pad_setup_converter (GstVideoAggregatorPad * pad,
|
|||
frame_rect = clamp_rectangle (cpad->xpos + x_offset, cpad->ypos + y_offset,
|
||||
width, height, GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info));
|
||||
|
||||
rect.left = frame_rect.x;
|
||||
rect.top = frame_rect.y;
|
||||
rect.right = frame_rect.x + frame_rect.w;
|
||||
rect.bottom = frame_rect.y + frame_rect.h;
|
||||
|
||||
#ifndef GST_DISABLE_GST_DEBUG
|
||||
g_object_get (pad, "zorder", &zorder, NULL);
|
||||
|
||||
GST_LOG_OBJECT (pad, "Update position, pad-xpos %d, pad-ypos %d, "
|
||||
"pad-zorder %d, pad-width %d, pad-height %d, in-resolution %dx%d, "
|
||||
"out-resoution %dx%d, dst-{left,top,right,bottom} %d-%d-%d-%d",
|
||||
"out-resoution %dx%d, dst-{x,y,width,height} %d-%d-%d-%d",
|
||||
cpad->xpos, cpad->ypos, zorder, cpad->width, cpad->height,
|
||||
GST_VIDEO_INFO_WIDTH (&pad->info), GST_VIDEO_INFO_HEIGHT (&pad->info),
|
||||
GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info),
|
||||
(gint) rect.left, (gint) rect.top, (gint) rect.right, (gint) rect.bottom);
|
||||
frame_rect.x, frame_rect.y, frame_rect.w, frame_rect.h);
|
||||
#endif
|
||||
|
||||
cpad->position_updated = FALSE;
|
||||
|
||||
return gst_d3d11_converter_update_dest_rect (cpad->convert, &rect);
|
||||
g_object_set (cpad->convert, "dest-x", frame_rect.x,
|
||||
"dest-y", frame_rect.y, "dest-width", frame_rect.w,
|
||||
"dest-height", frame_rect.h, nullptr);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstStaticCaps pad_template_caps =
|
||||
|
@ -1681,7 +1669,7 @@ gst_d3d11_compositor_pad_clear_resource (GstD3D11Compositor * self,
|
|||
gst_buffer_pool_set_active (cpad->fallback_pool, FALSE);
|
||||
gst_clear_object (&cpad->fallback_pool);
|
||||
}
|
||||
g_clear_pointer (&cpad->convert, gst_d3d11_converter_free);
|
||||
gst_clear_object (&cpad->convert);
|
||||
GST_D3D11_CLEAR_COM (cpad->blend);
|
||||
|
||||
return TRUE;
|
||||
|
@ -2420,8 +2408,7 @@ gst_d3d11_compositor_aggregate_frames (GstVideoAggregator * vagg,
|
|||
}
|
||||
}
|
||||
|
||||
if (!gst_d3d11_converter_convert_unlocked (cpad->convert, srv, rtv,
|
||||
cpad->blend, cpad->blend_factor)) {
|
||||
if (!gst_d3d11_converter_convert_unlocked (cpad->convert, srv, rtv)) {
|
||||
GST_ERROR_OBJECT (self, "Couldn't convert frame");
|
||||
ret = GST_FLOW_ERROR;
|
||||
break;
|
||||
|
|
|
@ -305,7 +305,7 @@ gst_d3d11_base_convert_clear_shader_resource (GstD3D11BaseConvert * self)
|
|||
GST_D3D11_CLEAR_COM (self->out_texture[i]);
|
||||
}
|
||||
|
||||
g_clear_pointer (&self->converter, gst_d3d11_converter_free);
|
||||
gst_clear_object (&self->converter);
|
||||
g_clear_pointer (&self->processor, gst_d3d11_video_processor_free);
|
||||
|
||||
self->processor_in_use = FALSE;
|
||||
|
@ -1720,7 +1720,6 @@ gst_d3d11_base_convert_set_info (GstD3D11BaseFilter * filter,
|
|||
GstD3D11BaseConvert *self = GST_D3D11_BASE_CONVERT (filter);
|
||||
const GstVideoInfo *unknown_info;
|
||||
gint from_dar_n, from_dar_d, to_dar_n, to_dar_d;
|
||||
D3D11_VIEWPORT view_port;
|
||||
gint border_offset_x = 0;
|
||||
gint border_offset_y = 0;
|
||||
|
||||
|
@ -1799,9 +1798,7 @@ gst_d3d11_base_convert_set_info (GstD3D11BaseFilter * filter,
|
|||
goto format_unknown;
|
||||
}
|
||||
|
||||
self->converter =
|
||||
gst_d3d11_converter_new (filter->device, in_info, out_info, nullptr);
|
||||
|
||||
self->converter = gst_d3d11_converter_new (filter->device, in_info, out_info);
|
||||
if (!self->converter) {
|
||||
GST_ERROR_OBJECT (self, "couldn't set converter");
|
||||
return FALSE;
|
||||
|
@ -1891,14 +1888,11 @@ gst_d3d11_base_convert_set_info (GstD3D11BaseFilter * filter,
|
|||
self->out_rect.bottom = GST_VIDEO_INFO_HEIGHT (out_info);
|
||||
}
|
||||
|
||||
view_port.TopLeftX = border_offset_x;
|
||||
view_port.TopLeftY = border_offset_y;
|
||||
view_port.Width = GST_VIDEO_INFO_WIDTH (out_info) - self->borders_w;
|
||||
view_port.Height = GST_VIDEO_INFO_HEIGHT (out_info) - self->borders_h;
|
||||
view_port.MinDepth = 0.0f;
|
||||
view_port.MaxDepth = 1.0f;
|
||||
|
||||
gst_d3d11_converter_update_viewport (self->converter, &view_port);
|
||||
g_object_set (self->converter, "dest-x", (gint) self->out_rect.left,
|
||||
"dest-y", (gint) self->out_rect.top,
|
||||
"dest-width", (gint) (self->out_rect.right - self->out_rect.left),
|
||||
"dest-height", (gint) (self->out_rect.bottom - self->out_rect.top),
|
||||
nullptr);
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
@ -2137,7 +2131,7 @@ gst_d3d11_base_convert_transform (GstBaseTransform * trans,
|
|||
|
||||
if (!gst_d3d11_converter_convert (self->converter,
|
||||
copy_input ? self->shader_resource_view : resource_view,
|
||||
target_rtv, NULL, NULL)) {
|
||||
target_rtv)) {
|
||||
goto conversion_failed;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -26,46 +26,50 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GstD3D11Converter GstD3D11Converter;
|
||||
#define GST_TYPE_D3D11_CONVERTER (gst_d3d11_converter_get_type())
|
||||
#define GST_D3D11_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_D3D11_CONVERTER,GstD3D11Converter))
|
||||
#define GST_D3D11_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_D3D11_CONVERTER,GstD3D11ConverterClass))
|
||||
#define GST_D3D11_CONVERTER_GET_CLASS(obj) (GST_D3D11_CONVERTER_CLASS(G_OBJECT_GET_CLASS(obj)))
|
||||
#define GST_IS_D3D11_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_D3D11_CONVERTER))
|
||||
#define GST_IS_D3D11_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_D3D11_CONVERTER))
|
||||
#define GST_D3D11_CONVERTER_CAST(obj) ((GstD3D11Converter*)(obj))
|
||||
|
||||
/**
|
||||
* GST_D3D11_CONVERTER_OPT_ALPHA_VALUE
|
||||
*
|
||||
* #G_TYPE_FLOAT, the alpha value color value to use.
|
||||
* Default is 1.0
|
||||
*/
|
||||
#define GST_D3D11_CONVERTER_OPT_ALPHA_VALUE "GstD3D11Converter.alpha-value"
|
||||
typedef struct _GstD3D11Converter GstD3D11Converter;
|
||||
typedef struct _GstD3D11ConverterClass GstD3D11ConverterClass;
|
||||
typedef struct _GstD3D11ConverterPrivate GstD3D11ConverterPrivate;
|
||||
|
||||
struct _GstD3D11Converter
|
||||
{
|
||||
GstObject parent;
|
||||
|
||||
GstD3D11Device *device;
|
||||
|
||||
/*< private >*/
|
||||
GstD3D11ConverterPrivate *priv;
|
||||
gpointer _gst_reserved[GST_PADDING];
|
||||
};
|
||||
|
||||
struct _GstD3D11ConverterClass
|
||||
{
|
||||
GstObjectClass parent_class;
|
||||
|
||||
/*< private >*/
|
||||
gpointer _gst_reserved[GST_PADDING];
|
||||
};
|
||||
|
||||
GType gst_d3d11_converter_get_type (void);
|
||||
|
||||
GstD3D11Converter * gst_d3d11_converter_new (GstD3D11Device * device,
|
||||
const GstVideoInfo * in_info,
|
||||
const GstVideoInfo * out_info,
|
||||
GstStructure * config);
|
||||
|
||||
void gst_d3d11_converter_free (GstD3D11Converter * converter);
|
||||
const GstVideoInfo * out_info);
|
||||
|
||||
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]);
|
||||
ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES]);
|
||||
|
||||
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,
|
||||
const D3D11_VIEWPORT * viewport);
|
||||
|
||||
gboolean gst_d3d11_converter_update_src_rect (GstD3D11Converter * converter,
|
||||
const RECT * src_rect);
|
||||
|
||||
gboolean gst_d3d11_converter_update_dest_rect (GstD3D11Converter * converter,
|
||||
const RECT * dest_rect);
|
||||
|
||||
gboolean gst_d3d11_converter_update_config (GstD3D11Converter * converter,
|
||||
GstStructure * config);
|
||||
ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES]);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -1283,7 +1283,7 @@ gst_d3d11_test_src_clear_resource (GstD3D11TestSrc * self)
|
|||
}
|
||||
|
||||
g_clear_pointer (&self->render, gst_d3d11_test_src_render_free);
|
||||
g_clear_pointer (&self->converter, gst_d3d11_converter_free);
|
||||
gst_clear_object (&self->converter);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -1297,7 +1297,7 @@ gst_d3d11_test_src_setup_resource (GstD3D11TestSrc * self, GstCaps * caps)
|
|||
gst_video_info_set_format (&draw_info, GST_VIDEO_FORMAT_RGBA,
|
||||
self->info.width, self->info.height);
|
||||
self->converter = gst_d3d11_converter_new (self->device,
|
||||
&draw_info, &self->info, nullptr);
|
||||
&draw_info, &self->info);
|
||||
|
||||
if (!self->converter) {
|
||||
GST_ERROR_OBJECT (self, "Failed to create converter");
|
||||
|
@ -1775,7 +1775,7 @@ gst_d3d11_test_src_create (GstBaseSrc * bsrc, guint64 offset,
|
|||
gst_d3d11_device_lock (self->device);
|
||||
gst_d3d11_test_src_draw_pattern (self, context_handle, pattern_rtv);
|
||||
gst_d3d11_converter_convert_unlocked (self->converter, pattern_srv,
|
||||
convert_rtv, nullptr, nullptr);
|
||||
convert_rtv);
|
||||
gst_d3d11_device_unlock (self->device);
|
||||
|
||||
gst_memory_unmap (mem, &render_info);
|
||||
|
|
|
@ -265,13 +265,12 @@ gst_d3d11_window_dispose (GObject * object)
|
|||
{
|
||||
GstD3D11Window *self = GST_D3D11_WINDOW (object);
|
||||
|
||||
if (self->device) {
|
||||
if (self->device)
|
||||
gst_d3d11_window_release_resources (self->device, self);
|
||||
}
|
||||
|
||||
g_clear_pointer (&self->processor, gst_d3d11_video_processor_free);
|
||||
g_clear_pointer (&self->converter, gst_d3d11_converter_free);
|
||||
g_clear_pointer (&self->compositor, gst_d3d11_overlay_compositor_free);
|
||||
gst_clear_object (&self->converter);
|
||||
|
||||
gst_clear_buffer (&self->cached_buffer);
|
||||
gst_clear_object (&self->device);
|
||||
|
@ -460,8 +459,8 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width,
|
|||
/* Step 1: Clear old resources and objects */
|
||||
gst_clear_buffer (&window->cached_buffer);
|
||||
g_clear_pointer (&window->processor, gst_d3d11_video_processor_free);
|
||||
g_clear_pointer (&window->converter, gst_d3d11_converter_free);
|
||||
g_clear_pointer (&window->compositor, gst_d3d11_overlay_compositor_free);
|
||||
gst_clear_object (&window->converter);
|
||||
|
||||
window->processor_in_use = FALSE;
|
||||
|
||||
|
@ -576,6 +575,8 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width,
|
|||
window->input_rect.right = GST_VIDEO_INFO_WIDTH (&window->info);
|
||||
window->input_rect.bottom = GST_VIDEO_INFO_HEIGHT (&window->info);
|
||||
|
||||
window->prev_input_rect = window->input_rect;
|
||||
|
||||
/* Step 4: Decide render color space and set it on converter/processor */
|
||||
{
|
||||
GstVideoMasteringDisplayInfo minfo;
|
||||
|
@ -721,7 +722,7 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width,
|
|||
/* configure shader even if video processor is available for fallback */
|
||||
window->converter =
|
||||
gst_d3d11_converter_new (window->device, &window->info,
|
||||
&window->render_info, nullptr);
|
||||
&window->render_info);
|
||||
|
||||
if (!window->converter) {
|
||||
GST_ERROR_OBJECT (window, "Cannot create converter");
|
||||
|
@ -846,13 +847,19 @@ gst_d3d11_window_do_convert (GstD3D11Window * self,
|
|||
ID3D11ShaderResourceView * srv[GST_VIDEO_MAX_PLANES],
|
||||
ID3D11RenderTargetView * rtv, RECT * input_rect)
|
||||
{
|
||||
if (!gst_d3d11_converter_update_src_rect (self->converter, input_rect)) {
|
||||
GST_ERROR_OBJECT (self, "Failed to update src rect");
|
||||
return FALSE;
|
||||
RECT *prev = &self->prev_input_rect;
|
||||
|
||||
if (input_rect->left != prev->left || input_rect->top != prev->top ||
|
||||
input_rect->right != prev->right || input_rect->bottom != prev->bottom) {
|
||||
g_object_set (self->converter, "src-x", (gint) input_rect->left,
|
||||
"src-y", (gint) input_rect->top,
|
||||
"src-width", (gint) (input_rect->right - input_rect->left),
|
||||
"src-height", (gint) (input_rect->bottom - input_rect->top), nullptr);
|
||||
|
||||
*prev = *input_rect;
|
||||
}
|
||||
|
||||
if (!gst_d3d11_converter_convert_unlocked (self->converter,
|
||||
srv, &rtv, NULL, NULL)) {
|
||||
if (!gst_d3d11_converter_convert_unlocked (self->converter, srv, &rtv)) {
|
||||
GST_ERROR_OBJECT (self, "Couldn't render to backbuffer using converter");
|
||||
return FALSE;
|
||||
} else {
|
||||
|
@ -934,7 +941,13 @@ gst_d3d111_window_present (GstD3D11Window * self, GstBuffer * buffer,
|
|||
viewport.Height = self->render_rect.bottom - self->render_rect.top;
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
gst_d3d11_converter_update_viewport (self->converter, &viewport);
|
||||
|
||||
g_object_set (self->converter, "dest-x", (gint) self->render_rect.left,
|
||||
"dest-y", (gint) self->render_rect.top,
|
||||
"dest-width",
|
||||
(gint) (self->render_rect.right - self->render_rect.left),
|
||||
"dest-height",
|
||||
(gint) (self->render_rect.bottom - self->render_rect.top), nullptr);
|
||||
gst_d3d11_overlay_compositor_update_viewport (self->compositor,
|
||||
&viewport);
|
||||
}
|
||||
|
|
|
@ -108,6 +108,7 @@ struct _GstD3D11Window
|
|||
|
||||
/* input resolution */
|
||||
RECT input_rect;
|
||||
RECT prev_input_rect;
|
||||
|
||||
/* requested rect via gst_d3d11_window_render */
|
||||
GstVideoRectangle rect;
|
||||
|
|
|
@ -86,8 +86,8 @@ gst_d3d11_window_dummy_prepare (GstD3D11Window * window,
|
|||
gboolean * video_processor_available, GError ** error)
|
||||
{
|
||||
g_clear_pointer (&window->processor, gst_d3d11_video_processor_free);
|
||||
g_clear_pointer (&window->converter, gst_d3d11_converter_free);
|
||||
g_clear_pointer (&window->compositor, gst_d3d11_overlay_compositor_free);
|
||||
gst_clear_object (&window->converter);
|
||||
|
||||
/* We are supporting only RGBA, BGRA or RGB10A2_LE formats but we don't know
|
||||
* which format texture will be used at this moment */
|
||||
|
@ -172,7 +172,7 @@ gst_d3d11_window_dummy_prepare (GstD3D11Window * window,
|
|||
|
||||
window->converter =
|
||||
gst_d3d11_converter_new (window->device, &window->info,
|
||||
&window->render_info, nullptr);
|
||||
&window->render_info);
|
||||
|
||||
if (!window->converter) {
|
||||
GST_ERROR_OBJECT (window, "Cannot create converter");
|
||||
|
|
|
@ -85,7 +85,6 @@
|
|||
|
||||
GST_DEBUG_CATEGORY (gst_d3d11_debug);
|
||||
GST_DEBUG_CATEGORY (gst_d3d11_shader_debug);
|
||||
GST_DEBUG_CATEGORY (gst_d3d11_converter_debug);
|
||||
GST_DEBUG_CATEGORY (gst_d3d11_plugin_utils_debug);
|
||||
GST_DEBUG_CATEGORY (gst_d3d11_format_debug);
|
||||
GST_DEBUG_CATEGORY (gst_d3d11_device_debug);
|
||||
|
@ -119,8 +118,6 @@ plugin_init (GstPlugin * plugin)
|
|||
GST_DEBUG_CATEGORY_INIT (gst_d3d11_debug, "d3d11", 0, "direct3d 11 plugin");
|
||||
GST_DEBUG_CATEGORY_INIT (gst_d3d11_shader_debug,
|
||||
"d3d11shader", 0, "d3d11shader");
|
||||
GST_DEBUG_CATEGORY_INIT (gst_d3d11_converter_debug,
|
||||
"d3d11converter", 0, "d3d11converter");
|
||||
GST_DEBUG_CATEGORY_INIT (gst_d3d11_plugin_utils_debug,
|
||||
"d3d11pluginutils", 0, "d3d11 plugin utility functions");
|
||||
GST_DEBUG_CATEGORY_INIT (gst_d3d11_overlay_compositor_debug,
|
||||
|
|
Loading…
Reference in a new issue