mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 10:11:08 +00:00
d3d11window: Reuse ID3D11VideoProcessorInputView if possible
GstMemory object could be disposed if GstBuffer is not allocated by GstD3D11BufferPool such as via gst_buffer_copy() and/or gst_buffer_make_writable(). So attaching qdata on GstMemory object would cause unnecessary view alloc/free. By using view pool which is implemented in GstD3D11Allocator, we can avoid redundant view alloc/free. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1716>
This commit is contained in:
parent
6c09cdd32b
commit
35ed7c7811
3 changed files with 15 additions and 56 deletions
|
@ -40,32 +40,6 @@ GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_video_processor_debug);
|
|||
#define HAVE_VIDEO_CONTEXT_TWO
|
||||
#endif
|
||||
|
||||
GQuark
|
||||
gst_d3d11_video_processor_input_view_quark (void)
|
||||
{
|
||||
static volatile gsize quark = 0;
|
||||
|
||||
if (g_once_init_enter (&quark)) {
|
||||
GQuark q = g_quark_from_static_string ("GstD3D11VideoProcessorInputView");
|
||||
g_once_init_leave (&quark, (gsize) q);
|
||||
}
|
||||
|
||||
return (GQuark) quark;
|
||||
}
|
||||
|
||||
GQuark
|
||||
gst_d3d11_video_processor_output_view_quark (void)
|
||||
{
|
||||
static volatile gsize quark = 0;
|
||||
|
||||
if (g_once_init_enter (&quark)) {
|
||||
GQuark q = g_quark_from_static_string ("GstD3D11VideoProcessorOutputView");
|
||||
g_once_init_leave (&quark, (gsize) q);
|
||||
}
|
||||
|
||||
return (GQuark) quark;
|
||||
}
|
||||
|
||||
struct _GstD3D11VideoProcessor
|
||||
{
|
||||
GstD3D11Device *device;
|
||||
|
@ -425,6 +399,14 @@ gst_d3d11_video_processor_create_input_view (GstD3D11VideoProcessor * processor,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_d3d11_video_processor_ensure_input_view (GstD3D11VideoProcessor * processor,
|
||||
GstD3D11Memory * mem)
|
||||
{
|
||||
return gst_d3d11_memory_ensure_processor_input_view (mem,
|
||||
processor->video_device, processor->enumerator);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_d3d11_video_processor_create_output_view (GstD3D11VideoProcessor *
|
||||
processor, D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC * desc,
|
||||
|
|
|
@ -28,9 +28,6 @@ G_BEGIN_DECLS
|
|||
|
||||
typedef struct _GstD3D11VideoProcessor GstD3D11VideoProcessor;
|
||||
|
||||
GQuark gst_d3d11_video_processor_input_view_quark (void);
|
||||
GQuark gst_d3d11_video_processor_output_view_quark (void);
|
||||
|
||||
GstD3D11VideoProcessor * gst_d3d11_video_processor_new (GstD3D11Device * device,
|
||||
guint in_width,
|
||||
guint in_height,
|
||||
|
@ -75,6 +72,9 @@ gboolean gst_d3d11_video_processor_create_input_view (GstD3D11VideoProcessor *
|
|||
ID3D11Resource *resource,
|
||||
ID3D11VideoProcessorInputView ** view);
|
||||
|
||||
gboolean gst_d3d11_video_processor_ensure_input_view (GstD3D11VideoProcessor * processor,
|
||||
GstD3D11Memory *mem);
|
||||
|
||||
gboolean gst_d3d11_video_processor_create_output_view (GstD3D11VideoProcessor * processor,
|
||||
D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC * desc,
|
||||
ID3D11Resource *resource,
|
||||
|
|
|
@ -837,8 +837,6 @@ gst_d3d11_window_buffer_ensure_processor_input (GstD3D11Window * self,
|
|||
GstBuffer * buffer, ID3D11VideoProcessorInputView ** in_view)
|
||||
{
|
||||
GstD3D11Memory *mem;
|
||||
ID3D11VideoProcessorInputView *view;
|
||||
GQuark quark;
|
||||
|
||||
if (!self->processor)
|
||||
return FALSE;
|
||||
|
@ -853,33 +851,12 @@ gst_d3d11_window_buffer_ensure_processor_input (GstD3D11Window * self,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
quark = gst_d3d11_video_processor_input_view_quark ();
|
||||
view = (ID3D11VideoProcessorInputView *)
|
||||
gst_mini_object_get_qdata (GST_MINI_OBJECT (mem), quark);
|
||||
|
||||
if (!view) {
|
||||
D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC in_desc;
|
||||
|
||||
in_desc.FourCC = 0;
|
||||
in_desc.ViewDimension = D3D11_VPIV_DIMENSION_TEXTURE2D;
|
||||
in_desc.Texture2D.MipSlice = 0;
|
||||
in_desc.Texture2D.ArraySlice = mem->subresource_index;
|
||||
|
||||
GST_TRACE_OBJECT (self, "Create new processor input view");
|
||||
|
||||
if (!gst_d3d11_video_processor_create_input_view (self->processor,
|
||||
&in_desc, mem->texture, &view)) {
|
||||
GST_LOG_OBJECT (self, "Failed to create processor input view");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gst_mini_object_set_qdata (GST_MINI_OBJECT (mem), quark, view,
|
||||
(GDestroyNotify) gst_d3d11_video_processor_input_view_release);
|
||||
} else {
|
||||
GST_TRACE_OBJECT (self, "Reuse existing processor input view %p", view);
|
||||
if (!gst_d3d11_video_processor_ensure_input_view (self->processor, mem)) {
|
||||
GST_LOG_OBJECT (self, "Failed to create processor input view");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*in_view = view;
|
||||
*in_view = mem->processor_input_view;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue