gst_element_set_state question

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

gst_element_set_state question

Jorge

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



_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: gst_element_set_state question

Thornton, Keith

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:[hidden email]] Im Auftrag von Jorge Fernandez Monteagudo
Gesendet: Dienstag, 4. April 2017 12:59
An: [hidden email]
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

 


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gst_element_set_state question

Jorge

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 <[hidden email]> en nombre de Thornton, Keith <[hidden email]>
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:[hidden email]] Im Auftrag von Jorge Fernandez Monteagudo
Gesendet: Dienstag, 4. April 2017 12:59
An: [hidden email]
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

 


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: gst_element_set_state question

Thornton, Keith

Yes, do both.

 

Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von Jorge Fernandez Monteagudo
Gesendet: Dienstag, 4. April 2017 14:35
An: Discussion of the development of and with GStreamer <[hidden email]>
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 <[hidden email]> en nombre de Thornton, Keith <[hidden email]>
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 [[hidden email]] Im Auftrag von Jorge Fernandez Monteagudo
Gesendet: Dienstag, 4. April 2017 12:59
An: [hidden email]
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

 


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Loading...