<div dir="ltr">Sorry, I hit send accidentally.<div><br></div><div><div style="font-family:arial,sans-serif;font-size:13px">I think I managed to do that.</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div>

<div style="font-family:arial,sans-serif;font-size:13px">I'm using <span class="" style>GStreamer</span> 0.10 targeting an embedded environment.</div><div style="font-family:arial,sans-serif;font-size:13px">But, for now, I'm testing it in a PC running Arch Linux.</div>

<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">The formats I'm using are: <span class="" style>Ogg</span> <span class="" style>Vorbis</span> (Audio/Video), Mp3 and H.264.</div>

<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">That's my solution:</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div>
<div style="font-family:arial,sans-serif;font-size:13px">
To set the start time, I do this (when entered the PAUSE state):</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap">        </span><span class="" style>GstEvent</span> *<span class="" style>ev</span> = <span class="" style>gst</span>_event_new_step(<span class="" style>GST</span>_FORMAT_TIME, <span class="" style>startTimePosition</span>, 1.0, TRUE, FALSE);</div>

</div><div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">      </span><span class="" style>gst</span>_element_send_event(pipeline, <span class="" style>ev</span>);</font></div><div style="font-family:arial,sans-serif;font-size:13px">

<br></div></div><div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">Just change the event creation instruction when creating SAMPLE and FRAME events:</span></font></div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">      </span><span class="" style>GstEvent</span> *<span class="" style>ev</span> = <span class="" style>gst</span>_event_new_step(<span class="" style>GST</span>_FORMAT_DEFAULT, <span class="" style>startSamplePosition</span>, 1.0, TRUE, FALSE);</font></div>

<div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">  </span></font><span style="font-family:arial,sans-serif"><span class="" style>GstEvent</span> *<span class="" style>ev</span> = </span><font face="arial, sans-serif"><span class="" style>gst</span>_event_new_step(<span class="" style>GST</span>_FORMAT_BUFFERS, <span class="" style>startFramePosition</span>, 1.0, TRUE, FALSE);</font></div>

<div style="font-family:arial,sans-serif;font-size:13px"><br></div></div></div><div style="font-family:arial,sans-serif;font-size:13px">To get the current frame, I intercept <span class="" style>GST</span>_MESSAGE_<span class="" style>QOS</span> and increment the current frame.</div>

<div style="font-family:arial,sans-serif;font-size:13px">So, in the bus callback, I use something like this:</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">   </span>switch (<span class="" style>GST</span>_MESSAGE_TYPE (<span class="" style>msg</span>)) {</font></div>

<div><font face="arial, sans-serif"><span class="" style="white-space:pre">             </span>case <span class="" style>GST</span>_MESSAGE_<span class="" style>QOS</span>: {</font></div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">                    </span>++<span class="" style>currentFrame</span>;</font></div>

<div><font face="arial, sans-serif"><span class="" style="white-space:pre">                     </span>break;</font></div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">         </span>}</font></div><div><span class="" style="font-family:arial,sans-serif;white-space:pre">                </span><span style="font-family:arial,sans-serif">case <span class="" style>GST</span>_MESSAGE_STEP_DONE: {</span><br>

</div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">                 </span><span class="" style>GstFormat</span> format;</font></div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">                    </span>guint64 amount;</font></div>

<div><font face="arial, sans-serif"><span class="" style="white-space:pre">                     </span><span class="" style>gdouble</span> rate;</font></div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">                        </span><span class="" style>gboolean</span> flush, intermediate;</font></div>

<div><font face="arial, sans-serif"><span class="" style="white-space:pre">                     </span>guint64 duration;</font></div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">                      </span><span class="" style>gboolean</span> <span class="" style>eos</span>;</font></div>

<div><span class="" style="font-family:arial,sans-serif;white-space:pre">                       </span><span style="font-family:arial,sans-serif"><span class="" style>gst</span>_message_parse_step_done (<span class="" style>msg</span>, &format, &amount, &rate, &flush, &intermediate, &duration, &<span class="" style>eos</span>);</span><br>

</div><div><span class="" style="font-family:arial,sans-serif;white-space:pre">                   </span><span style="font-family:arial,sans-serif"><span class="" style>timeOffset</span> = duration;</span><br></div><div><span class="" style="font-family:arial,sans-serif;white-space:pre">                    </span><span style="font-family:arial,sans-serif">break;</span><br>

</div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">         </span>}</font></div><div><span class="" style="font-family:arial,sans-serif;white-space:pre">                </span><span style="font-family:arial,sans-serif">default:</span><br>

</div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">                 </span>break;</font></div><div><font face="arial, sans-serif"><span class="" style="white-space:pre"> </span>}</font></div><div style="font-family:arial,sans-serif;font-size:13px">

<br></div></div><div style="font-family:arial,sans-serif;font-size:13px">To keep counting the current frame, I do something like this (when entered the READY state):</div><div style="font-family:arial,sans-serif;font-size:13px">

<br></div><div><div><font face="arial, sans-serif"><span class="" style="white-space:pre">    </span><span class="" style>GstElement</span> *<span class="" style>videoSink</span> = <span class="" style>gst</span>_bin_get_by_name(<span class="" style>GST</span>_BIN(pipeline), "<span class="" style>videosink</span>");</font></div>

<div><span class="" style="font-family:arial,sans-serif;white-space:pre">       <span class="" style>GstPad</span> *v</span><span style="font-family:arial,sans-serif"><span class="" style>ideoSinkPad</span> = <span class="" style>gst</span>_element_get_static_pad(<span class="" style>videoSink</span>, "sink");</span><br>

</div><div><span class="" style="font-family:arial,sans-serif;white-space:pre">   </span><span style="font-family:arial,sans-serif"><span class="" style>bufferProbeID</span> = <span class="" style>gst</span>_pad_add_buffer_probe(<span class="" style>videoSinkPad</span>, (<span class="" style>GCallback</span>)<span class="" style>IncCurrentFrame</span>, NULL);</span><br>

</div><div><br></div></div><div>The <span class="" style>IncCurrentFrame</span> function simply increments the <span class="" style>currentFrame</span> variable.</div><div><br></div><div>This way, frame alarms can compare the current frame to their target frames using a pad probe (same <span class="" style>logics</span> used above).</div>

<div>Every Frame alarm adds a buffer probe and the callback simply does the comparing.</div><div><br></div><div>The difference in frame numbers were related to dropped packages. That's why is necessary to keep counting <span class="" style>QOS</span> messages after finishing the STEP phase.</div>

<div>This solution seems to work well.</div><div><br></div><div>The <span class="" style>timeOffset</span> set in the STEP_DONE event is used by Time Alarms and Frame alarms.</div><div>I register single shot clock_id's as soon as I enter the PLAYING state. Do you think it is a good solution? Time seems to be accurate.</div>

<div><br></div><div>Sample alarms fall back to the TIME implementation, since I use the RATE (got from caps) to convert Samples to time.</div><div><br></div><div>Do you think I'm going to have trouble with something in the future?</div>

<div><br></div><div>I provided as much details as I'm allowed to. Sorry if it is confusing.</div><div><br></div><div><br></div><div>Thanks very much for your answer.<br></div><div>I appreciate that.</div><div style="font-family:arial,sans-serif;font-size:13px">

<br></div><div style="font-family:arial,sans-serif;font-size:13px">Marcus</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Nov 12, 2013 at 11:25 AM, Sebastian Dröge <span dir="ltr"><<a href="mailto:sebastian@centricular.com" target="_blank">sebastian@centricular.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mo, 2013-11-11 at 18:56 -0200, Marcus Nascimento wrote:<br>
> I'm working on a media platform and I have to implement a wrapper to<br>
> GStreamer that offers the following interface:<br>
><br>
> - SetStartTime: Set the start position (in time)<br>
> - SetEndTime: Set the end position (in time)<br>
> - SetStartFrame: Set the start position (in frames)<br>
> - SetEndFrame: Set the end position (in frames)<br>
> - SetStartSample: Set the start position (in samples)<br>
> - SetEndSample: Set the end position (in samples)<br>
> - AddTimeAlarm: A listener will be notified when a given time is reached.<br>
> - AddFrameAlarm: A listener will be notified when a given frame is reached.<br>
> - AddSampleAlarm: A listener will be notified when a given sample is<br>
> reached.<br>
><br>
> I'll never play streamming media nor remote media, but only local files.<br>
><br>
> The biggest problem up to now cames from the fact it is possible to set<br>
> Start/End position in time, and add frame alarms, for instance.<br>
><br>
> I'm using STEP events to set the start position. It is just a matter of<br>
> using gst_event_new_step passing the right parameters for that<br>
> (GST_FORMAT_TIME for time, GST_FORMAT_DEFAULT for samples and<br>
> GST_FORMAT_BUFFERS for frames).<br>
><br>
> In any case, I need to know which frame corresponds to the step destination.<br>
> To do that, I'm incrementing the frame counter everytime I receive a QOS<br>
> message durring the STEP execution. I do that until I receive a STEP_DONE<br>
> message. By that time, I know what is the current time and current frame.<br>
> It seems to work fine. Does anyone know if that is not correct?<br>
><br>
> After the STEP is complete, I'm using a pad probe (buffer probe) to keep<br>
> counting the frames.<br>
> This way, I can know for sure when a frame alarm has expired.<br>
><br>
> Strange thing is: When I set the StartFrame to 300, the corresponding time<br>
> is a little after 9s.<br>
> But, when I schedule an alarm to the same frame 300, the corresponding time<br>
> is around 7s.<br>
> It is very strange for me.<br>
><br>
> Can anyone help me understanding what's going on?<br>
<br>
</div></div>It would be useful to have some test case to explain what exactly you do<br>
how and to have a way to reproduce it. Also which file formats are you<br>
using and which GStreamer version on which platform? :)<br>
<br>
How do you get "the corresponding time" when you do StartFrame(300)? And<br>
how for the alarms? The alarms are counting the frames via a pad probe<br>
and you get the buffer timestamp from there?<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Sebastian Dröge <<a href="mailto:sebastian@centricular.com">sebastian@centricular.com</a>><br>
Centricular Ltd - <a href="http://www.centricular.com" target="_blank">http://www.centricular.com</a><br>
Expertise, Straight from the Source<br>
</font></span><br>_______________________________________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Marcus Nascimento<br><br>
</div>