Commits

Christian Lippka  committed 062ffd6

#161254# adding timeout for get state to prevent freeze

  • Participants
  • Parent commits 30d88cc

Comments (0)

Files changed (2)

File avmedia/source/gstreamer/gstplayer.cxx

 #include <gst/gstelement.h>
 #include <gst/interfaces/xoverlay.h>
 
+
+// maximum timeout time in nanoseconds
+#define GST_MAX_TIMEOUT 500000000
+
 using namespace ::com::sun::star;
 
 namespace avmedia
     mnVolumeDB( 0 ),
     mnLooping( 0 ),
     mnQuit( 0 ),
-    mnVideoWindowSet( 0 )
+    mnVideoWindowSet( 0 ),
+	mnInitFail( 0 )
 {
     // initialize GStreamer framework only once
     static bool bGstInitialized = false;
 
     if( mpPlayer )
     {
-        gst_element_get_state( mpPlayer, &aState, NULL, GST_CLOCK_TIME_NONE );
+        gst_element_get_state( mpPlayer, &aState, NULL, GST_MAX_TIMEOUT );
     }
 
     return( GST_STATE_PLAYING == aState );
                 GstState aOldState = GST_STATE_NULL;
 
                 mpPlayerWindow = pPlayerWindow;
-                gst_element_get_state( mpPlayer, &aOldState, NULL, GST_CLOCK_TIME_NONE );
+                gst_element_get_state( mpPlayer, &aOldState, NULL, GST_MAX_TIMEOUT );
                 gst_element_set_state( mpPlayer, GST_STATE_READY );
                 g_object_set( mpPlayer, "video-sink", pVideoSink, NULL );
                 gst_element_set_state( mpPlayer, aOldState );
 {
     bool bRet = false;
 
-    if( mpPlayer )
+    if( mpPlayer && (mnInitFail < 3) )
     {
         GstState aState = GST_STATE_NULL;
 
-        if( gst_element_get_state( mpPlayer, &aState, NULL, GST_CLOCK_TIME_NONE ) == GST_STATE_CHANGE_SUCCESS )
+        if( gst_element_get_state( mpPlayer, &aState, NULL, GST_MAX_TIMEOUT ) == GST_STATE_CHANGE_SUCCESS )
         {
             bRet = ( GST_STATE_PAUSED == aState ) || ( GST_STATE_PLAYING == aState );
 
             {
                 gst_element_set_state( mpPlayer, GST_STATE_PAUSED );
                 bRet = ( gst_element_get_state( mpPlayer, &aState, NULL,
-                                                GST_CLOCK_TIME_NONE ) == GST_STATE_CHANGE_SUCCESS ) &&
+                                                GST_MAX_TIMEOUT ) == GST_STATE_CHANGE_SUCCESS ) &&
                     ( GST_STATE_PAUSED == aState );
             }
         }
+
+		if( ! bRet )
+			mnInitFail++;
     }
 
     return( bRet );

File avmedia/source/gstreamer/gstplayer.hxx

     gint mnLooping;
     gint mnQuit;
     gint mnVideoWindowSet;
+	gint mnInitFail;
 };
 }     // namespace gst
 } // namespace avmedia