<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<p>Hi all!</p>
<p><br>
</p>
<p>I would like to know what the correct way to wait for a state change in gstreamer.</p>
<p>I'm using a typical code doing a polling after the '<span>gst_element_set_state</span>' call but</p>
<p>sometimes, with the machine under a heavy load, I get a timeout but gstreamer</p>
<p>is still working and finally changes the state.</p>
<p><br>
</p>
<p>Is there a better way? Is it possible to wait without timeout and look for some</p>
<p>error trying to change the state? What timeout is considered safe?</p>
<p><br>
</p>
<p><br>
</p>
<p>The code waiting for a state change with a 10 seconds timeout</p>
<p><br>
</p>
<p></p>
<div>bool poll_for_state_change( GstState new_state )<br>
{<br>
  GTimeVal tfthen, tfnow;<br>
  GstClockTimeDiff diff;<br>
  GstStateChangeReturn result = GST_STATE_CHANGE_FAILURE;<br>
  GstState current;<br>
  gint32 timeescap = 0;<br>
<br>
  gst_element_get_state( pipeline, &current, NULL, GST_SECOND );<br>
  printf( "%s - change state from %s to %s\n",<br>
            __FUNCTION__, gst_element_state_get_name( current ),<br>
            gst_element_state_get_name( new_state ) );<br>
  if( current == new_state )<br>
    return true;<br>
<br>
  g_get_current_time( &tfthen );<br>
  result = gst_element_set_state( pipeline, new_state );<br>
  if( result == GST_STATE_CHANGE_FAILURE )<br>
    return false;<br>
<br>
  while( 1 ) {<br>
    gst_element_get_state( pipeline, &current, NULL, GST_SECOND );<br>
    g_get_current_time( &tfnow );<br>
    diff = GST_TIMEVAL_TO_TIME( tfnow ) - GST_TIMEVAL_TO_TIME( tfthen );<br>
    diff /= (1000 * 1000);<br>
    timeescap = (unsigned int) diff;<br>
<br>
    if( new_state == current )<br>
      break;<br>
<br>
    if( timeescap > 10000 ) {<br>
      printf( "%s - Time out in state transferring from %s to %s\n",<br>
              __FUNCTION__, gst_element_state_get_name( current ),<br>
              gst_element_state_get_name( new_state ) );<br>
      return false;<br>
    }<br>
  }<br>
<br>
  return true;<br>
}<br>
</div>
<p></p>
<p><br>
</p>
<p>Thanks!</p>
<p>Jorge</p>
<p><br>
</p>
</div>
</body>
</html>