#include <windows.h>
#include <versionhelpers.h>
+#include <d3d10.h>
/**
* SECTION:gstd3d11device
ID3D11VideoDevice *video_device;
ID3D11VideoContext *video_context;
+ ID3D10Multithread *multi_thread;
IDXGIFactory1 *factory;
GstD3D11Format format_table[GST_D3D11_N_FORMATS];
- GRecMutex extern_lock;
GMutex resource_lock;
#if HAVE_D3D11SDKLAYERS_H
priv = gst_d3d11_device_get_instance_private (self);
priv->adapter = DEFAULT_ADAPTER;
- g_rec_mutex_init (&priv->extern_lock);
g_mutex_init (&priv->resource_lock);
self->priv = priv;
goto error;
}
+ hr = ID3D11Device_QueryInterface (priv->device, &IID_ID3D10Multithread,
+ (void **) &priv->multi_thread);
+ if (!gst_d3d11_result (hr, NULL)) {
+ GST_ERROR_OBJECT (self, "ID3D10Multithread interface is not available");
+ ID3D11Device_Release (priv->device);
+ priv->device = NULL;
+
+ ID3D11DeviceContext_Release (priv->device_context);
+ priv->device_context = NULL;
+ goto error;
+ }
+
+ ID3D10Multithread_SetMultithreadProtected (priv->multi_thread, TRUE);
+
priv->factory = factory;
#if HAVE_D3D11SDKLAYERS_H
GST_LOG_OBJECT (self, "dispose");
+ if (priv->multi_thread) {
+ ID3D10Multithread_Release (priv->multi_thread);
+ priv->multi_thread = NULL;
+ }
+
if (priv->video_device) {
ID3D11VideoDevice_Release (priv->video_device);
priv->video_device = NULL;
GST_LOG_OBJECT (self, "finalize");
- g_rec_mutex_clear (&priv->extern_lock);
g_mutex_clear (&priv->resource_lock);
g_free (priv->description);
priv = device->priv;
GST_TRACE_OBJECT (device, "device locking");
- g_rec_mutex_lock (&priv->extern_lock);
+ ID3D10Multithread_Enter (priv->multi_thread);
GST_TRACE_OBJECT (device, "device locked");
}
g_return_if_fail (GST_IS_D3D11_DEVICE (device));
priv = device->priv;
+ ID3D10Multithread_Leave (priv->multi_thread);
- g_rec_mutex_unlock (&priv->extern_lock);
GST_TRACE_OBJECT (device, "device unlocked");
}
ID3D11DeviceContext *device_context =
gst_d3d11_device_get_device_context_handle (dmem->device);
- gst_d3d11_device_lock (dmem->device);
if (GST_MEMORY_FLAG_IS_SET (dmem, GST_D3D11_MEMORY_TRANSFER_NEED_DOWNLOAD)) {
ID3D11DeviceContext_CopySubresourceRegion (device_context,
staging, 0, 0, 0, 0, texture, priv->subresource_index, NULL);
ret = FALSE;
}
- gst_d3d11_device_unlock (dmem->device);
-
return ret;
}
map_type = gst_map_flags_to_d3d11 (flags);
- gst_d3d11_device_lock (dmem->device);
hr = ID3D11DeviceContext_Map (device_context,
(ID3D11Resource *) priv->texture, 0, map_type, 0, &priv->map);
if (!gst_d3d11_result (hr, dmem->device)) {
"Failed to map staging texture (0x%x)", (guint) hr);
ret = FALSE;
}
- gst_d3d11_device_unlock (dmem->device);
if (!ret) {
GST_D3D11_MEMORY_UNLOCK (dmem);
ID3D11DeviceContext *device_context =
gst_d3d11_device_get_device_context_handle (dmem->device);
- gst_d3d11_device_lock (dmem->device);
ID3D11DeviceContext_CopySubresourceRegion (device_context,
(ID3D11Resource *) priv->texture, priv->subresource_index, 0, 0, 0,
(ID3D11Resource *) priv->staging, 0, NULL);
- gst_d3d11_device_unlock (dmem->device);
}
GST_MEMORY_FLAG_UNSET (dmem, GST_D3D11_MEMORY_TRANSFER_NEED_UPLOAD);
if (priv->type == GST_D3D11_MEMORY_TYPE_STAGING)
staging = (ID3D11Resource *) priv->texture;
- gst_d3d11_device_lock (dmem->device);
ID3D11DeviceContext_Unmap (device_context, staging, 0);
- gst_d3d11_device_unlock (dmem->device);
}
static void
ID3D11DeviceContext *device_context =
gst_d3d11_device_get_device_context_handle (device);
- gst_d3d11_device_lock (device);
hr = ID3D11DeviceContext_Map (device_context,
(ID3D11Resource *) texture, 0, map_type, 0, &map);
desc->Width, desc->Height, map.RowPitch, offset, stride, size);
ID3D11DeviceContext_Unmap (device_context, (ID3D11Resource *) texture, 0);
- gst_d3d11_device_unlock (device);
return ret;
}
endif
endforeach
-have_d3d11 = d3d11_lib.found() and dxgi_lib.found() and have_d3d11_header and have_dxgi_header
+have_d3d11 = d3d11_lib.found() and dxgi_lib.found() and have_d3d11_header and have_dxgi_header and cc.has_header('d3d10.h')
if not have_d3d11
if d3d11_option.enabled()
error('The d3d11 was enabled explicitly, but required dependencies were not found.')
ret = GST_FLOW_ERROR;
goto done;
}
+ gst_d3d11_device_unlock (self->device);
GST_OBJECT_LOCK (self);
}
}
- if (!gst_d3d11_converter_convert_unlocked (cpad->convert, srv, rtv,
+ if (!gst_d3d11_converter_convert(cpad->convert, srv, rtv,
cpad->blend, cpad->blend_factor)) {
GST_ERROR_OBJECT (self, "Couldn't convert frame");
ret = GST_FLOW_ERROR;
}
}
GST_OBJECT_UNLOCK (self);
- gst_d3d11_device_unlock (self->device);
if (ret != GST_FLOW_OK)
goto done;
}
}
- gst_d3d11_device_lock (device);
clear_rtv_color_all (self, info, context_handle, view);
- gst_d3d11_device_unlock (device);
self->num_output_view = i;
gboolean hardware = FALSE;
GstD3D11VideoProcessor *processor = NULL;
- gst_d3d11_device_lock (filter->device);
g_object_get (filter->device, "hardware", &hardware, NULL);
if (hardware) {
processor = gst_d3d11_video_processor_new (filter->device,
}
self->processor = processor;
- gst_d3d11_device_unlock (filter->device);
}
#endif
return FALSE;
}
- gst_d3d11_device_lock (bfilter->device);
clear_rtv_color_all (self, &bfilter->out_info, context_handle, render_view);
- gst_d3d11_device_unlock (bfilter->device);
}
return gst_d3d11_video_processor_render (self->processor,
}
copy_input = TRUE;
- gst_d3d11_device_lock (device);
for (i = 0; i < gst_buffer_n_memory (inbuf); i++) {
GstD3D11Memory *mem =
(GstD3D11Memory *) gst_buffer_peek_memory (inbuf, i);
context_handle->CopySubresourceRegion (self->in_texture[i], 0, 0, 0, 0,
(ID3D11Resource *) in_map[i].data, subidx, &src_box);
}
- gst_d3d11_device_unlock (device);
}
/* Ensure render target views */
* area. Likely output texture was initialized with zeros which is fine for
* RGB, but it's not black color in case of YUV */
if (self->borders_w || self->borders_h) {
- gst_d3d11_device_lock (device);
clear_rtv_color_all (self, &filter->out_info, context_handle, target_rtv);
- gst_d3d11_device_unlock (device);
}
if (!gst_d3d11_converter_convert (self->converter,
}
if (copy_output) {
- gst_d3d11_device_lock (device);
for (i = 0; i < gst_buffer_n_memory (outbuf); i++) {
GstD3D11Memory *mem =
(GstD3D11Memory *) gst_buffer_peek_memory (outbuf, i);
context_handle->CopySubresourceRegion ((ID3D11Resource *) out_map[i].data,
subidx, 0, 0, 0, self->out_texture[i], 0, &src_box);
}
- gst_d3d11_device_unlock (device);
}
gst_d3d11_buffer_unmap (inbuf, in_map);
return FALSE;
}
- gst_d3d11_device_lock (device);
hr = context_handle->Map (const_buffer.Get (),
0, D3D11_MAP_WRITE_DISCARD, 0, &map);
if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't map constant buffer, hr: 0x%x", (guint) hr);
- gst_d3d11_device_unlock (device);
return FALSE;
}
sizeof (PixelShaderColorTransform));
context_handle->Unmap (const_buffer.Get (), 0);
- gst_d3d11_device_unlock (device);
}
input_desc[0].SemanticName = "POSITION";
return FALSE;
}
- gst_d3d11_device_lock (device);
hr = context_handle->Map (vertex_buffer.Get (), 0, D3D11_MAP_WRITE_DISCARD, 0,
&map);
if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't map vertex buffer, hr: 0x%x", (guint) hr);
- gst_d3d11_device_unlock (device);
return FALSE;
}
if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't map index buffer, hr: 0x%x", (guint) hr);
context_handle->Unmap (vertex_buffer.Get (), 0);
- gst_d3d11_device_unlock (device);
return FALSE;
}
context_handle->Unmap (vertex_buffer.Get (), 0);
context_handle->Unmap (index_buffer.Get (), 0);
- gst_d3d11_device_unlock (device);
self->quad[0] = gst_d3d11_quad_new (device,
ps[0].Get (), vs.Get (), layout.Get (), sampler.Get (), NULL, NULL,
video_device = self->video_device;
- gst_d3d11_device_lock (self->device);
if (!gst_d3d11_decoder_get_supported_decoder_profile (self,
self->codec, GST_VIDEO_INFO_FORMAT (info), &selected_profile)) {
goto error;
self->downstream_min_buffers = 0;
self->opened = TRUE;
- gst_d3d11_device_unlock (self->device);
return TRUE;
error:
gst_d3d11_decoder_reset (self);
- gst_d3d11_device_unlock (self->device);
return FALSE;
}
do {
GST_LOG_OBJECT (decoder, "Try begin frame, retry count %d", retry_count);
- gst_d3d11_device_lock (decoder->device);
hr = video_context->DecoderBeginFrame (decoder->decoder_handle,
output_view, content_key_size, content_key);
- gst_d3d11_device_unlock (decoder->device);
/* HACK: Do 100 times retry with 1ms sleep per failure, since DXVA/D3D11
* doesn't provide API for "GPU-IS-READY-TO-DECODE" like signal.
video_context = decoder->video_context;
- gst_d3d11_device_lock (decoder->device);
hr = video_context->DecoderEndFrame (decoder->decoder_handle);
- gst_d3d11_device_unlock (decoder->device);
if (!gst_d3d11_result (hr, decoder->device)) {
GST_WARNING_OBJECT (decoder, "EndFrame failed, hr: 0x%x", (guint) hr);
video_context = decoder->video_context;
- gst_d3d11_device_lock (decoder->device);
hr = video_context->GetDecoderBuffer (decoder->decoder_handle,
type, &size, &decoder_buffer);
- gst_d3d11_device_unlock (decoder->device);
if (!gst_d3d11_result (hr, decoder->device)) {
GST_WARNING_OBJECT (decoder, "Getting buffer type %d error, hr: 0x%x",
video_context = decoder->video_context;
- gst_d3d11_device_lock (decoder->device);
hr = video_context->ReleaseDecoderBuffer (decoder->decoder_handle, type);
- gst_d3d11_device_unlock (decoder->device);
if (!gst_d3d11_result (hr, decoder->device)) {
GST_WARNING_OBJECT (decoder, "ReleaseDecoderBuffer failed, hr: 0x%x",
video_context = decoder->video_context;
- gst_d3d11_device_lock (decoder->device);
hr = video_context->SubmitDecoderBuffers (decoder->decoder_handle,
buffer_count, buffers);
- gst_d3d11_device_unlock (decoder->device);
if (!gst_d3d11_result (hr, decoder->device)) {
GST_WARNING_OBJECT (decoder, "SubmitDecoderBuffers failed, hr: 0x%x",
in_texture = gst_d3d11_memory_get_texture_handle (in_mem);
in_subresource_index = gst_d3d11_memory_get_subresource_index (in_mem);
- gst_d3d11_device_lock (self->device);
device_context->CopySubresourceRegion (self->staging, 0, 0, 0, 0,
in_texture, in_subresource_index, NULL);
if (!gst_d3d11_result (hr, self->device)) {
GST_ERROR_OBJECT (self, "Failed to map, hr: 0x%x", (guint) hr);
- gst_d3d11_device_unlock (self->device);
gst_video_frame_unmap (&out_frame);
return FALSE;
gst_video_frame_unmap (&out_frame);
device_context->Unmap (self->staging, 0);
- gst_d3d11_device_unlock (self->device);
return TRUE;
}
return FALSE;
}
- gst_d3d11_device_lock (self->device);
in_texture = gst_d3d11_memory_get_texture_handle (in_mem);
in_subresource_index = gst_d3d11_memory_get_subresource_index (in_mem);
out_subresource_index, 0, 0, 0, in_texture, in_subresource_index,
&src_box);
- gst_d3d11_device_unlock (self->device);
gst_memory_unmap (GST_MEMORY_CAST (out_mem), &out_map);
return TRUE;
if (self->method == GST_D3D11_DEINTERLACE_METHOD_BLEND)
output_rate = D3D11_VIDEO_PROCESSOR_OUTPUT_RATE_HALF;
- gst_d3d11_device_lock (self->device);
self->video_context->VideoProcessorSetStreamSourceRect (self->video_proc,
0, TRUE, &rect);
self->video_context->VideoProcessorSetStreamDestRect (self->video_proc,
VideoProcessorSetStreamAutoProcessingMode (self->video_proc, 0, FALSE);
self->video_context->VideoProcessorSetStreamOutputRate (self->video_proc, 0,
output_rate, TRUE, NULL);
- gst_d3d11_device_unlock (self->device);
return TRUE;
}
proc_stream.ppPastSurfaces = past_surfaces;
}
- gst_d3d11_device_lock (self->device);
self->video_context->VideoProcessorSetStreamFrameFormat (self->video_proc, 0,
frame_foramt);
hr = self->video_context->VideoProcessorBlt (self->video_proc, pov, 0,
1, &proc_stream);
- gst_d3d11_device_unlock (self->device);
if (!gst_d3d11_result (hr, self->device)) {
GST_ERROR_OBJECT (self, "Failed to perform deinterlacing");
return ret;
}
- gst_d3d11_device_lock (desktop->device);
ret = desktop->dupl_obj->Capture (draw_mouse);
if (ret != GST_FLOW_OK) {
- gst_d3d11_device_unlock (desktop->device);
delete desktop->dupl_obj;
desktop->dupl_obj = nullptr;
GST_ERROR_OBJECT (desktop, "Unexpected failure during capture");
}
- g_rec_mutex_unlock (&desktop->lock);
return ret;
}
desktop->texture, 0, nullptr);
if (draw_mouse)
desktop->dupl_obj->DrawMouse (rtv);
- gst_d3d11_device_unlock (desktop->device);
g_rec_mutex_unlock (&desktop->lock);
return GST_FLOW_OK;
return NULL;
}
- gst_d3d11_device_lock (device);
hr = context_handle->Map (vertex_buffer.Get (),
0, D3D11_MAP_WRITE_DISCARD, 0, &map);
if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't map vertex buffer, hr: 0x%x", (guint) hr);
- gst_d3d11_device_unlock (device);
return NULL;
}
vertex_data[3].texture.y = 1.0f;
context_handle->Unmap (vertex_buffer.Get (), 0);
- gst_d3d11_device_unlock (device);
overlay = g_new0 (GstD3D11CompositionOverlay, 1);
overlay->overlay_rect = gst_video_overlay_rectangle_ref (overlay_rect);
return FALSE;
}
- gst_d3d11_device_lock (device);
hr = context_handle->Map (index_buffer.Get (),
0, D3D11_MAP_WRITE_DISCARD, 0, &map);
if (!gst_d3d11_result (hr, device)) {
GST_ERROR ("Couldn't map index buffer, hr: 0x%x", (guint) hr);
- gst_d3d11_device_unlock (device);
return FALSE;
}
indices[5] = 2; /* top right */
context_handle->Unmap (index_buffer.Get (), 0);
- gst_d3d11_device_unlock (device);
self->ps = ps.Detach ();
self->vs = vs.Detach ();
dst_subidx = gst_d3d11_memory_get_subresource_index (dst_dmem);
src_subidx = gst_d3d11_memory_get_subresource_index (src_dmem);
- gst_d3d11_device_lock (device);
device_context->CopySubresourceRegion (dst_texture, dst_subidx, 0, 0, 0,
src_texture, src_subidx, &src_box);
- gst_d3d11_device_unlock (device);
gst_memory_unmap (src_mem, &src_info);
gst_memory_unmap (dst_mem, &dst_info);
#endif
/* Setting up default options */
- gst_d3d11_device_lock (self->device);
/* We don't want auto processing by driver */
self->video_context->VideoProcessorSetStreamAutoProcessingMode
(self->processor, 0, FALSE);
- gst_d3d11_device_unlock (self->device);
return self;
g_return_val_if_fail (in_view != NULL, FALSE);
g_return_val_if_fail (out_view != NULL, FALSE);
- gst_d3d11_device_lock (processor->device);
ret = gst_d3d11_video_processor_render_unlocked (processor, in_rect, in_view,
out_rect, out_view);
- gst_d3d11_device_unlock (processor->device);
return ret;
}
/* redraw the last scene if cached buffer exits */
if (window->cached_buffer) {
+ gst_d3d11_device_unlock (window->device);
gst_d3d111_window_present (window, window->cached_buffer, NULL,
window->pov, window->rtv);
+ gst_d3d11_device_lock (window->device);
}
done:
GST_D3D11_CLEAR_COM (backbuffer);
-
gst_d3d11_device_unlock (window->device);
}
swapchain_flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING;
}
- gst_d3d11_device_lock (window->device);
window->dxgi_format = chosen_format->dxgi_format;
klass = GST_D3D11_WINDOW_GET_CLASS (window);
if (window->render_stats)
gst_d3d11_window_prepare_dwrite_device (window);
#endif
- gst_d3d11_device_unlock (window->device);
/* call resize to allocated resources */
klass->on_resize (window, display_width, display_height);
return TRUE;
error:
- gst_d3d11_device_unlock (window->device);
return FALSE;
}
return GST_FLOW_ERROR;
}
- gst_d3d11_device_lock (window->device);
gst_buffer_replace (&window->cached_buffer, buffer);
ret = gst_d3d111_window_present (window, window->cached_buffer, stats,
window->pov, window->rtv);
- gst_d3d11_device_unlock (window->device);
if (stats)
gst_structure_free (stats);
data.acquire_key = acquire_key;
data.release_key = release_key;
- gst_d3d11_device_lock (window->device);
if (!klass->open_shared_handle (window, &data)) {
GST_ERROR_OBJECT (window, "Couldn't open shared handle");
- gst_d3d11_device_unlock (window->device);
return GST_FLOW_OK;
}
ret = gst_d3d111_window_present (window, buffer, NULL, pov, rtv);
klass->release_shared_handle (window, &data);
- gst_d3d11_device_unlock (window->device);
return ret;
}
if (klass->unlock_stop)
ret = klass->unlock_stop (window);
- gst_d3d11_device_lock (window->device);
gst_clear_buffer (&window->cached_buffer);
- gst_d3d11_device_unlock (window->device);
return ret;
}
return NULL;
}
- gst_d3d11_device_lock (device);
hr = factory2->CreateSwapChainForCoreWindow ((IUnknown *) device_handle,
(IUnknown *) core_window, desc, output, &swap_chain);
- gst_d3d11_device_unlock (device);
if (!gst_d3d11_result (hr, device)) {
GST_WARNING_OBJECT (self, "Cannot create SwapChain Object: 0x%x",
window->render_info.colorimetry.transfer = GST_VIDEO_TRANSFER_BT709;
window->render_info.colorimetry.range = GST_VIDEO_COLOR_RANGE_0_255;
- gst_d3d11_device_lock (window->device);
-
#if (GST_D3D11_DXGI_HEADER_VERSION >= 4)
{
const GstDxgiColorSpace *in_color_space =
goto error;
}
- gst_d3d11_device_unlock (window->device);
-
return TRUE;
error:
return NULL;
}
- gst_d3d11_device_lock (device);
hr = factory2->CreateSwapChainForComposition ((IUnknown *) device_handle,
desc, output, &swap_chain);
- gst_d3d11_device_unlock (device);
if (!gst_d3d11_result (hr, device)) {
GST_WARNING_OBJECT (self, "Cannot create SwapChain Object: 0x%x",
ID3D11Device *device_handle = gst_d3d11_device_get_device_handle (device);
IDXGIFactory1 *factory = gst_d3d11_device_get_dxgi_factory_handle (device);
- gst_d3d11_device_lock (device);
hr = factory->CreateSwapChain ((IUnknown *) device_handle, desc, &swap_chain);
- gst_d3d11_device_unlock (device);
if (!gst_d3d11_result (hr, device)) {
GST_WARNING_OBJECT (self, "Cannot create SwapChain Object: 0x%x",
return NULL;
}
- gst_d3d11_device_lock (device);
hr = factory2->CreateSwapChainForHwnd (
(IUnknown *) device_handle, hwnd, desc, fullscreen_desc,
output, &swap_chain);
- gst_d3d11_device_unlock (device);
if (!gst_d3d11_result (hr, device)) {
GST_WARNING_OBJECT (self, "Cannot create SwapChain Object: 0x%x",
}
/* disable alt+enter here. It should be manually handled */
- gst_d3d11_device_lock (device);
gst_d3d11_window_win32_disable_alt_enter (self,
device, new_swapchain, desc.OutputWindow);
- gst_d3d11_device_unlock (device);
*swap_chain = new_swapchain;
return FALSE;
}
- gst_d3d11_device_lock (dmem->device);
context_handle->CopySubresourceRegion (shared_texture.Get (), 0, 0, 0, 0,
texture, subidx, &src_box);
context_handle->End (query.Get());
if (!gst_d3d11_result (hr, dmem->device)) {
GST_ERROR_OBJECT (self, "Couldn't sync GPU operation");
- gst_d3d11_device_unlock (dmem->device);
gst_memory_unmap (mem, &info);
return FALSE;
}
- gst_d3d11_device_unlock (dmem->device);
gst_memory_unmap (mem, &info);
*sample = new_sample.Detach ();