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

Alexandru Munteanu m at ioalex.net
Thu Sep 26 13:48:36 PDT 2013


Hello,

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" ?

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.

-- 
Alex



More information about the gstreamer-devel mailing list