<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.E-MailFormatvorlage18
        {mso-style-type:personal;
        font-family:"Arial",sans-serif;
        color:windowtext;}
span.E-MailFormatvorlage19
        {mso-style-type:personal-reply;
        font-family:"Arial",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif">Yes, do both.
<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Von:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> gstreamer-devel [mailto:gstreamer-devel-bounces@lists.freedesktop.org]
<b>Im Auftrag von </b>Jorge Fernandez Monteagudo<br>
<b>Gesendet:</b> Dienstag, 4. April 2017 14:35<br>
<b>An:</b> Discussion of the development of and with GStreamer <gstreamer-devel@lists.freedesktop.org><br>
<b>Betreff:</b> Re: gst_element_set_state question<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div id="divtagdefaultwrapper">
<p><span style="color:black">Hi!<o:p></o:p></span></p>
<p><span style="color:black"><o:p> </o:p></span></p>
<p><span style="color:black">Thanks for your answer! And is there any way to check if the state change has hit an error? Maybe capturing the<o:p></o:p></span></p>
<p><span style="color:black">'GST_MESSAGE_ERROR' event? I supposse I have to wait until the pipeline has change its state, isn't it?<o:p></o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">De:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black"> gstreamer-devel <<a href="mailto:gstreamer-devel-bounces@lists.freedesktop.org">gstreamer-devel-bounces@lists.freedesktop.org</a>>
 en nombre de Thornton, Keith <<a href="mailto:keith.thornton@zeiss.com">keith.thornton@zeiss.com</a>><br>
<b>Enviado:</b> martes, 4 de abril de 2017 14:30:31<br>
<b>Para:</b> Discussion of the development of and with GStreamer<br>
<b>Asunto:</b> AW: gst_element_set_state question</span> <o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial",sans-serif">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<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Von:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> gstreamer-devel [<a href="mailto:gstreamer-devel-bounces@lists.freedesktop.org">mailto:gstreamer-devel-bounces@lists.freedesktop.org</a>]
<b>Im Auftrag von </b>Jorge Fernandez Monteagudo<br>
<b>Gesendet:</b> Dienstag, 4. April 2017 12:59<br>
<b>An:</b> <a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a><br>
<b>Betreff:</b> gst_element_set_state question<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div id="divtagdefaultwrapper">
<p><span style="font-family:"Calibri",sans-serif;color:black">Hi all!<o:p></o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black">I would like to know what the correct way to wait for a state change in gstreamer.<o:p></o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black">I'm using a typical code doing a polling after the 'gst_element_set_state' call but<o:p></o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black">sometimes, with the machine under a heavy load, I get a timeout but gstreamer<o:p></o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black">is still working and finally changes the state.<o:p></o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black">Is there a better way? Is it possible to wait without timeout and look for some<o:p></o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black">error trying to change the state? What timeout is considered safe?<o:p></o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black">The code waiting for a state change with a 10 seconds timeout<o:p></o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;color:black">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>
}<o:p></o:p></span></p>
</div>
<p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black">Thanks!<o:p></o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black">Jorge<o:p></o:p></span></p>
<p><span style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
</div>
</div>
</body>
</html>