AW: gst_element_set_state question

Thornton, Keith keith.thornton at zeiss.com
Wed Apr 5 05:41:40 UTC 2017


Yes, do both.

Von: gstreamer-devel [mailto:gstreamer-devel-bounces at lists.freedesktop.org] Im Auftrag von Jorge Fernandez Monteagudo
Gesendet: Dienstag, 4. April 2017 14:35
An: Discussion of the development of and with GStreamer <gstreamer-devel at lists.freedesktop.org>
Betreff: Re: gst_element_set_state question


Hi!



Thanks for your answer! And is there any way to check if the state change has hit an error? Maybe capturing the

'GST_MESSAGE_ERROR' event? I supposse I have to wait until the pipeline has change its state, isn't it?

________________________________
De: gstreamer-devel <gstreamer-devel-bounces at lists.freedesktop.org<mailto:gstreamer-devel-bounces at lists.freedesktop.org>> en nombre de Thornton, Keith <keith.thornton at zeiss.com<mailto:keith.thornton at zeiss.com>>
Enviado: martes, 4 de abril de 2017 14:30:31
Para: Discussion of the development of and with GStreamer
Asunto: AW: gst_element_set_state question

Hi, you should create a listener for the message bus. Every element posts its state changed message on the bus. When complete, the pipeline also posts a state changed message on the bus. There are examples in the user manual

Von: gstreamer-devel [mailto:gstreamer-devel-bounces at lists.freedesktop.org] Im Auftrag von Jorge Fernandez Monteagudo
Gesendet: Dienstag, 4. April 2017 12:59
An: gstreamer-devel at lists.freedesktop.org<mailto:gstreamer-devel at lists.freedesktop.org>
Betreff: gst_element_set_state question


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, &current, 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, &current, 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/20170405/434be659/attachment.html>


More information about the gstreamer-devel mailing list