gstreamer with playbin: how to pause 'now' or pause at exact time

Alexandru Munteanu m at ioalex.net
Thu Sep 26 14:12:35 PDT 2013


On 21:59 Thu 26 Sep     , Tim-Philipp Müller wrote:
> On Thu, 2013-09-26 at 22:48 +0200, Alexandru Munteanu wrote:
> 
> Hi,

Hi,

Thank you for the quick reply.

> > I am using gstreamer 1.0.10 (packages from debian testing) with the playbin element
> > (for mp3splt-gtk).
> > 
> > When I set the element to GST_STATE_PAUSED, I always have a lag between the moment I call
> > gst_element_set_state() and the time when the pause occurs.
> > Is there a way to "pause right now" or "pause at a precise time in the future" ?
> 
> Sorry for not answering your question, but let me ask you first: what
> are you trying to achieve with that? What's the big picture?

I just want to pause at a precise time (say for example at 1 minute, 3
seconds and 57 hundreths of seconds).
You can see in the following screenshot two green circles and I want the
player to pause exactly at middle of the second green circle:
http://mp3splt.sourceforge.net/mp3splt_page/screenshots/mp3splt-gtk_0.7.3.png

And I set the state to GST_STATE_PAUSED when gst_element_query() with 
GST_FORMAT_TIME gives me the time I want to stop at. But when I query again
after the pause, I don't have the same time as when I paused it.

I hope it is a little bit more clear now.

-- 
Alex

>  Cheers
>   -Tim
> 
> > Details follow.
> > 
> > I have those two functions:
> > 
> >     void gstreamer_get_time_elapsed(ui_state *ui)
> >     {
> >       GstQuery *query = gst_query_new_position(GST_FORMAT_TIME);
> >       gint64 time = 0;
> >   
> >       if (gst_element_query(ui->pi->play, query))
> >       {
> >         gst_query_parse_position(query, NULL, &time);
> >       }
> >   
> >       gst_query_unref(query);
> >     
> >       fprintf(stdout, "position = %ld\n", time);
> >       fprintf(stdout, "position / MSECOND = %ld\n", time / GST_MSECOND);
> >       fflush(stdout);
> >     }
> > 
> >     void gstreamer_pause(ui_state *ui)
> >     {
> >       GstState state;
> >       gst_element_get_state(ui->pi->play, &state, NULL, GST_CLOCK_TIME_NONE);
> > 
> >       fprintf(stdout, "time before pause\n");
> >       gstreamer_get_time_elapsed(ui);
> > 
> >       fprintf(stdout, "setting pause ...\n");
> >       fflush(stdout);
> >       GstStateChangeReturn ret = gst_element_set_state(ui->pi->play, GST_STATE_PAUSED);
> >       if (ret == GST_STATE_CHANGE_ASYNC)
> >       {
> >         fprintf(stdout, "async!\n");
> >         fflush(stdout);
> >       }
> >       else if (ret == GST_STATE_CHANGE_SUCCESS)
> >       {
> >         fprintf(stdout, "success!\n");
> >         fflush(stdout);
> >       }
> > 
> >       fprintf(stdout, "time after pause ...\n");
> >       fflush(stdout);
> >       gstreamer_get_time_elapsed(ui);
> >     }
> > 
> > and when I call gstreamer_pause(), I get the following output:
> > 
> >     time before pause
> >     position = 90017369614
> >     position / MSECOND = 90017
> >     setting pause ...
> >     success!
> >     time after pause ...
> >     position = 90343673468
> >     position / MSECOND = 90343
> > 
> > There is a difference of about 0.3 second between the moment just before I pause
> > and the moment the pause is triggered.
> > Any idea how I can handle this issue ?
> > 
> > Thank you.



More information about the gstreamer-devel mailing list