gst_element_set_state question
Jorge Fernandez Monteagudo
jorgefm at cirsa.com
Tue Apr 4 10:58:30 UTC 2017
Hi all!
I would like to know what the correct way to wait for a state change in gstreamer.
I'm using a typical code doing a polling after the 'gst_element_set_state' call but
sometimes, with the machine under a heavy load, I get a timeout but gstreamer
is still working and finally changes the state.
Is there a better way? Is it possible to wait without timeout and look for some
error trying to change the state? What timeout is considered safe?
The code waiting for a state change with a 10 seconds timeout
bool poll_for_state_change( GstState new_state )
{
GTimeVal tfthen, tfnow;
GstClockTimeDiff diff;
GstStateChangeReturn result = GST_STATE_CHANGE_FAILURE;
GstState current;
gint32 timeescap = 0;
gst_element_get_state( pipeline, ¤t, NULL, GST_SECOND );
printf( "%s - change state from %s to %s\n",
__FUNCTION__, gst_element_state_get_name( current ),
gst_element_state_get_name( new_state ) );
if( current == new_state )
return true;
g_get_current_time( &tfthen );
result = gst_element_set_state( pipeline, new_state );
if( result == GST_STATE_CHANGE_FAILURE )
return false;
while( 1 ) {
gst_element_get_state( pipeline, ¤t, NULL, GST_SECOND );
g_get_current_time( &tfnow );
diff = GST_TIMEVAL_TO_TIME( tfnow ) - GST_TIMEVAL_TO_TIME( tfthen );
diff /= (1000 * 1000);
timeescap = (unsigned int) diff;
if( new_state == current )
break;
if( timeescap > 10000 ) {
printf( "%s - Time out in state transferring from %s to %s\n",
__FUNCTION__, gst_element_state_get_name( current ),
gst_element_state_get_name( new_state ) );
return false;
}
}
return true;
}
Thanks!
Jorge
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20170404/68de23d0/attachment.html>
More information about the gstreamer-devel
mailing list