[MOVED FROM GOOD] sys/: Wait until the window is created before using it; guard unist...
authorSergey Scobich <sergey.scobich@gmail.com>
Wed, 1 Nov 2006 10:19:18 +0000 (10:19 +0000)
committerJan Schmidt <thaytan@noraisin.net>
Sat, 16 May 2009 00:29:15 +0000 (01:29 +0100)
Original commit message from CVS:
Patch by: Sergey Scobich  <sergey dot scobich at gmail com>
* sys/directdraw/gstdirectdrawsink.c:
(gst_directdrawsink_window_thread),
(gst_directdrawsink_create_default_window):
* sys/directdraw/gstdirectdrawsink.h:
* sys/directsound/gstdirectsoundsink.c:
Wait until the window is created before using it; guard unistd.h
includes with HAVE_UNISTD_H. (#366523)
* win32/vs8/libgstdirectdraw.vcproj:
* win32/vs8/libgstdirectsound.vcproj:
Update project files.

sys/directdraw/gstdirectdrawsink.c
sys/directdraw/gstdirectdrawsink.h

index fbccb80..ec449c7 100644 (file)
@@ -28,7 +28,9 @@
 
 #include <fcntl.h>
 #include <errno.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <string.h>
 
 GST_DEBUG_CATEGORY_STATIC (directdrawsink_debug);
@@ -1366,6 +1368,8 @@ gst_directdrawsink_window_thread (GstDirectDrawSink * ddrawsink)
   if (ddrawsink->video_window == NULL)
     return FALSE;
 
+  ReleaseSemaphore (ddrawsink->window_created_signal, 1, NULL);
+
   /*start message loop processing our default window messages */
   while (1) {
     MSG msg;
@@ -1381,15 +1385,27 @@ gst_directdrawsink_window_thread (GstDirectDrawSink * ddrawsink)
 static gboolean
 gst_directdrawsink_create_default_window (GstDirectDrawSink * ddrawsink)
 {
+  ddrawsink->window_created_signal = CreateSemaphore (NULL, 0, 1, NULL);
+  if (ddrawsink->window_created_signal == NULL)
+    return FALSE;
+
   ddrawsink->window_thread = g_thread_create (
       (GThreadFunc) gst_directdrawsink_window_thread, ddrawsink, TRUE, NULL);
 
   if (ddrawsink->window_thread == NULL)
-    return FALSE;
+    goto failed;
 
-  /*TODO:wait for the window to be created with timeout */
+  /* wait maximum 10 seconds for windows creating */
+  if (WaitForSingleObject (ddrawsink->window_created_signal,
+          10000) != WAIT_OBJECT_0)
+    goto failed;
 
+  CloseHandle (ddrawsink->window_created_signal);
   return TRUE;
+
+failed:
+  CloseHandle (ddrawsink->window_created_signal);
+  return FALSE;
 }
 
 static gboolean
index f11c95e..f9d4c86 100644 (file)
@@ -104,6 +104,7 @@ struct _GstDirectDrawSink
 
   /*handle of the video window */
   HWND video_window;
+  HANDLE window_created_signal;
   gboolean resize_window;
 
   /*video properties */