{
gst_d3dvideosink_clear (sink);
- sink->d3d_swap_chain_lock = g_mutex_new ();
+ sink->d3d_device_lock = g_mutex_new ();
sink->par = g_new0 (GValue, 1);
g_value_init (sink->par, GST_TYPE_FRACTION);
sink->par = NULL;
}
- g_mutex_free (sink->d3d_swap_chain_lock);
- sink->d3d_swap_chain_lock = NULL;
+ g_mutex_free (sink->d3d_device_lock);
+ sink->d3d_device_lock = NULL;
G_OBJECT_CLASS (parent_class)->finalize (gobject);
}
shared.hidden_window_handle = hWnd;
shared.device_lost_timer = 0;
+ shared.device_lost = FALSE;
gst_d3dvideosink_shared_hidden_window_created (sink);
{
shared.device_lost_sink = NULL;
GST_DEBUG ("Initializing Direct3D");
- GST_D3DVIDEOSINK_SWAP_CHAIN_LOCK (sink);
- gst_d3dvideosink_initialize_d3d_device (sink);
- GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK (sink);
- GST_DEBUG ("Direct3D initialization complete");
+ if (!gst_d3dvideosink_initialize_d3d_device (sink))
+ gst_d3dvideosink_notify_device_lost(sink);
+ else
+ GST_DEBUG ("Direct3D initialization complete");
break;
}
case WM_DIRECTX_D3D_INIT_DEVICELOST:
{
- if (!shared.device_lost) {
+ if (shared.device_lost)
+ break;
- shared.device_lost = TRUE;
- shared.device_lost_sink = sink;
+ shared.device_lost = TRUE;
+ GST_D3DVIDEOSINK_D3D_DEVICE_LOCK (sink);
- /* Handle device lost by creating a timer and posting WM_D3D_DEVICELOST twice a second */
- /* Create a timer to periodically check the d3d device and attempt to recreate it */
- shared.device_lost_timer = SetTimer (hWnd, IDT_DEVICELOST, 500, NULL);
- /* Try it once immediately */
- SendMessage (hWnd, WM_DIRECTX_D3D_DEVICELOST, 0, (LPARAM) sink);
- }
+ /* Handle device lost by creating a timer and posting WM_D3D_DEVICELOST twice a second */
+ /* Create a timer to periodically check the d3d device and attempt to recreate it */
+ shared.device_lost_timer = SetTimer (hWnd, IDT_DEVICELOST, 500, NULL);
+ shared.device_lost_sink = sink;
+
+ /* Try it once immediately */
+ SendMessage (hWnd, WM_DIRECTX_D3D_DEVICELOST, 0, (LPARAM) sink);
break;
}
case WM_TIMER:
}
case WM_DIRECTX_D3D_END_DEVICELOST:
{
- if (shared.device_lost) {
- /* gst_d3dvideosink_notify_device_reset() sends this message. */
- if (shared.device_lost_timer != 0)
- KillTimer (hWnd, shared.device_lost_timer);
+ if (!shared.device_lost)
+ break;
- shared.device_lost_timer = 0;
- shared.device_lost = FALSE;
+ /* gst_d3dvideosink_notify_device_reset() sends this message. */
+ if (shared.device_lost_timer != 0)
+ KillTimer (hWnd, shared.device_lost_timer);
- /* Refresh the video with the last buffer */
- gst_d3dvideosink_update_all (sink);
+ shared.device_lost_timer = 0;
+ shared.device_lost = FALSE;
- /* Then redraw just in case we don't have a last buffer */
- gst_d3dvideosink_refresh_all (sink);
+ GST_D3DVIDEOSINK_D3D_DEVICE_UNLOCK (sink);
+
+ /* Refresh the video with the last buffer */
+ gst_d3dvideosink_update_all (sink);
+
+ /* Then redraw just in case we don't have a last buffer */
+ gst_d3dvideosink_refresh_all (sink);
- }
shared.device_lost_sink = NULL;
break;
}
return;
}
+ GST_D3DVIDEOSINK_D3D_DEVICE_LOCK (sink);
/* If we're already playing/paused, then we need to lock the swap chain, and recreate it with the new window. */
if (sink->d3ddev != NULL) {
- GST_D3DVIDEOSINK_SWAP_CHAIN_LOCK (sink);
/* Close our existing window if there is one */
gst_d3dvideosink_close_window (sink);
/* Save our window id */
sink->window_closed = FALSE;
gst_d3dvideosink_notify_device_reinit (sink);
- GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK (sink);
- //gst_d3dvideosink_notify_device_init(sink);
-
} else {
sink->window_handle = hWnd;
}
-/*success:*/
+ GST_D3DVIDEOSINK_D3D_DEVICE_UNLOCK (sink);
+
GST_DEBUG_OBJECT (sink, "Direct3D window id successfully changed to %p",
hWnd);
* and create (and use) our own window, if we didn't create
* one before */
if (sink->window_handle && sink->is_new_window) {
- gst_d3dvideosink_release_d3d_device (sink);
+ GST_D3DVIDEOSINK_D3D_DEVICE_LOCK(sink);
+ gst_d3dvideosink_release_d3d_device(sink);
+ GST_D3DVIDEOSINK_D3D_DEVICE_UNLOCK(sink);
} else if (sink->window_handle) {
gst_d3dvideosink_set_window_for_renderer (sink);
} else {
gst_d3dvideosink_create_default_window (sink);
}
+ GST_D3DVIDEOSINK_D3D_DEVICE_LOCK(sink);
gst_d3dvideosink_notify_device_init (sink);
+ GST_D3DVIDEOSINK_D3D_DEVICE_UNLOCK(sink);
}
static GstStateChangeReturn
GstD3DVideoSink *sink = GST_D3DVIDEOSINK (vsink);
LPDIRECT3DSURFACE9 drawSurface = NULL;
- GST_D3DVIDEOSINK_SWAP_CHAIN_LOCK (sink);
+ if (!GST_D3DVIDEOSINK_D3D_DEVICE_TRYLOCK (sink))
+ return GST_FLOW_OK;
if (!sink->d3ddev) {
if (!shared.device_lost) {
GST_ERROR_OBJECT (sink, "No Direct3D device has been created, stopping");
IDirect3DDevice9_EndScene (sink->d3ddev);
}
success:
- GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK (sink);
+ GST_D3DVIDEOSINK_D3D_DEVICE_UNLOCK (sink);
gst_d3dvideosink_refresh (sink);
return GST_FLOW_OK;
#if 0
/* return GST_FLOW_UNEXPECTED; */
#endif
error:
- GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK (sink);
+ GST_D3DVIDEOSINK_D3D_DEVICE_UNLOCK (sink);
return GST_FLOW_ERROR;
}
static gboolean
gst_d3dvideosink_refresh (GstD3DVideoSink * sink)
{
- GST_D3DVIDEOSINK_SWAP_CHAIN_LOCK (sink);
+ if (!GST_D3DVIDEOSINK_D3D_DEVICE_TRYLOCK (sink))
+ return TRUE;
{
HRESULT hr;
LPDIRECT3DSURFACE9 backBuffer;
}
/*success:*/
- GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK (sink);
+ GST_D3DVIDEOSINK_D3D_DEVICE_UNLOCK (sink);
return TRUE;
error:
- GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK (sink);
+ GST_D3DVIDEOSINK_D3D_DEVICE_UNLOCK (sink);
return FALSE;
}
if (shared.element_count > 0)
goto success;
- GST_D3DVIDEOSINK_SWAP_CHAIN_LOCK (sink);
+ GST_D3DVIDEOSINK_D3D_DEVICE_LOCK (sink);
gst_d3dvideosink_release_d3d_device (sink);
- GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK (sink);
+ GST_D3DVIDEOSINK_D3D_DEVICE_UNLOCK (sink);
+
if (shared.d3d) {
int ref_count;
ref_count = IDirect3D9_Release (shared.d3d);