Hi, gstreamer-devel:<br><br>&nbsp;&nbsp;&nbsp; Basically, in gstreamer, ASYNC state changing is used by sink elements to perform preroll. So let source element performs a ASYNC state change is not a good idea. <br><br>&nbsp;&nbsp;&nbsp; And the ASYNC state changing typically happens during READY-&gt;PAUSED while not NULL-&gt;READY.<br>
<br>&nbsp;&nbsp;&nbsp; So my opinion is you&#39;d better think your design again to try to follow the gstreamer&#39;s design patterns. If your source element want to fetch something in network -- just do it, there is no need to return ASYNC. For example, I am working on rtsp/rtp stuffs now and the rtspsrc will do a lot of works during NULL-&gt;READY and READY-&gt;PAUSED to communicate with RTSP server.<br>
<br>Eric Zhang<br><br><div class="gmail_quote">2008/12/2 John Grossman <span dir="ltr">&lt;<a href="mailto:johngro@google.com">johngro@google.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
bump...<br><br>Still looking for some help with this issue; does anyone have an idea of what might be going on?&nbsp; Alternatively, does anyone know of a good example of how to properly implement an element which performs async state changes which I could use to set myself straight?<br>

<br>TIA<br><br>peace<br><font color="#888888">-john</font><div><div></div><div class="Wj3C7c"><br><br><div class="gmail_quote">On Tue, Nov 25, 2008 at 7:28 PM, John Grossman <span dir="ltr">&lt;<a href="mailto:johngro@google.com" target="_blank">johngro@google.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>Hello, my name is John and I am a developer currently working on writing a gstreamer plugin to act as a source element.&nbsp; I&#39;m having some trouble with async state changes and I was hoping that someone on this list could provide some insight.&nbsp; Basically, my element needs to make the transition from NULL to READY asynchronously.&nbsp; After my element has transitioned to READY, downstream elements expect me to answer questions like, &quot;how long is the source in bytes&quot;.&nbsp; I am actually fetching the source over a network, but I want to provide a pull interface to make file oriented demux elements happy.&nbsp; It will take me some time to get this information from the network so it is important for me to make the transition asynchronously.<br>


<br>I have overridden the change_state, get_state and set_state methods of my element so that I can have some control over the process.&nbsp; My change state just calls to the base element&#39;s change_state for any transition except for NULL_TO_READY.&nbsp; When I see the NULL_TO_READY change, I kick off my network fetch and return GST_STATE_CHANGE_ASYNC.<br>


<br>My set state method always calls the base element&#39;s set_state; I pretty much just have it hooked so that I can see what the base element is returning to the rest of the framework.<br><br>My get_state implementation will return the base element&#39;s get_state, unless I am in an asynchronous transition from NULL to READY.&nbsp; In this case, it waits for the signal from the rest of my code that has managed to fetch the required info from the network.&nbsp; If the get times out, it will return ASYNC again.&nbsp; If something goes wrong fetching the file over the net, it will return FAILURE, and if everything went well it will return SUCCESS (and my element should officially be in the READY state).<br>


<br>Unfortunately, things do not seem to be working as I expected.&nbsp; Even though I return ASYNC at the appropriate time in my implementation of change_state, the base implementation of set_state is simply returning SUCCESS.&nbsp; I am working with the 0.10.21 version of GStreamer, and I think I have tracked the issue down to the implementation of gst_element_change_state in gstelement.c at line 2412.&nbsp; This function calls my implementation of change_state and then switches on the return value I give back.&nbsp; The handler for GST_STATE_CHANGE_ASYNC looks like the following...<br>


<br><font face="courier new,monospace">case GST_STATE_CHANGE_ASYNC:<br>{<br>&nbsp; GstState target;<br><br>&nbsp; GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;element will change state ASYNC&quot;);<br><br>&nbsp; target = GST_STATE_TARGET (element);<br>


<br>&nbsp; if (target &gt; GST_STATE_READY)<br>&nbsp;&nbsp;&nbsp; goto async;<br><br>&nbsp; /* else we just continue the state change downwards */<br>&nbsp; GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;forcing commit state %s &lt;= %s&quot;,<br>


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gst_element_state_get_name (target),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gst_element_state_get_name (GST_STATE_READY));<br><br>&nbsp; ret = gst_element_continue_state (element, GST_STATE_CHANGE_SUCCESS);<br>&nbsp; break;<br>}<br></font><br>Essentially, what seems to be killing me is the &quot;if (target &gt; GST_STATE_READY) statement&quot;.&nbsp; The system is attempting to go from NULL to READY, and this line seems to be saying that asynchronous transitions can only be made if the target state is either PAUSED or PLAYING.&nbsp; (BTW - I am seeing both the &quot;element will change state ASYNC&quot; and the &quot;forcing commit state&quot; messages in my debug logs).&nbsp; I couldn&#39;t make sense of the comment following the if statement so I did some research in the CVS archives to see if I could track down where this if statement came from.&nbsp; You can check out the diffs here<br>


<a href="http://webcvs.freedesktop.org/gstreamer/gstreamer/gst/gstelement.c?r1=1.448&amp;r2=1.449" target="_blank">http://webcvs.freedesktop.org/gstreamer/gstreamer/gst/gstelement.c?r1=1.448&amp;r2=1.449</a><br>but to save you some time, here is what the code used to look like (about 20 months ago)<br>


<br><font face="courier new,monospace">case GST_STATE_CHANGE_ASYNC:<br>&nbsp;&nbsp; GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;element will change state ASYNC&quot;);<br><br>&nbsp;&nbsp; /* if we go upwards, we give the app a change to wait for<br>


&nbsp;&nbsp;&nbsp; * completion */<br>&nbsp;&nbsp; if (current &lt; next)<br>&nbsp;&nbsp;&nbsp;&nbsp; goto async;<br><br>&nbsp;&nbsp; /* else we just continue the state change downwards */<br>&nbsp;&nbsp; GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;forcing commit state %s &lt; %s&quot;,<br>


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gst_element_state_get_name (current),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gst_element_state_get_name (next));<br><br>&nbsp;&nbsp; ret = gst_element_continue_state (element, GST_STATE_CHANGE_SUCCESS);<br>&nbsp;&nbsp; break;<br></font><br>Essentially, it looked like the code used to allow async state changes while moving up in the state sequence, but not while moving down.&nbsp; I suspect this was to prevent element from blocking shutdown by never completing their state changes.&nbsp; With the code change present in 1.449, it looks like elements are allowed to make an async state change to either PLAYING or PAUSED, but not if their target is NULL or READY.<br>


<br>This is where I get confused...&nbsp; If I had set the target state of my pipeline directly to PLAYING instead of just READY, it looks like this code would have allowed me to make the async change from NULL to READY.&nbsp; So if the purpose of this code is to force the change from NULL to READY to be synchronous, it seems like there are ways of wiggling around it.<br>


<br>If the behavior of this code was supposed to be the same as before (allowing async in the up direction instead of down), then it seems like &quot;if (current &lt; target)&quot; is the appropriate change, instead of &quot;if (target &gt; READY)&quot;.<br>


<br>It has also occurred to me that the intention might have been to allow async changes in both directions instead of just up, but not if the target state is set to NULL (in which case the pipeline is tearing down and should do so with all haste).&nbsp; If that is the case, then the if statement present here might just have a typo (&quot;if (target &gt; GST_STATE_READY)&quot; instead of &quot;if (target &gt;= GST_STATE_READY)&quot;)<br>


<br>Does anyone know what the intention was here?&nbsp; If the intent was to actually prevent elements from transitioning from NULL to READY asynchronously, then does anyone know how I should be approaching my problem instead?&nbsp; I suppose I could build my graph by adding just my source element, setting it to ready, and then waiting for a bus message from the async part of my element indicating that it has fetched the initial data.&nbsp; That really didn&#39;t seem to be in the spirit of things, however, since it would mean that my application needed to be aware of my source&#39;s particular requirements.<br>


<br>Thanks in advance for any help anyone out there can provide.<br><font color="#888888"><br>-john<br>
</font></blockquote></div><br>
</div></div><br>-------------------------------------------------------------------------<br>
This SF.Net email is sponsored by the Moblin Your Move Developer&#39;s challenge<br>
Build the coolest Linux based applications with Moblin SDK &amp; win great prizes<br>
Grand prize is a trip for two to an Open Source event anywhere in the world<br>
<a href="http://moblin-contest.org/redirect.php?banner_id=100&amp;url=/" target="_blank">http://moblin-contest.org/redirect.php?banner_id=100&amp;url=/</a><br>_______________________________________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.sourceforge.net">gstreamer-devel@lists.sourceforge.net</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/gstreamer-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/gstreamer-devel</a><br>
<br></blockquote></div><br>