Pacing sink with gst_base_sink_wait_clock()

Max Paklin mpaklin at
Thu Jan 12 10:29:48 PST 2012

I am trying to figure out the right way to do custom pipeline pacing in my
For variety of reasons default sync behavior does not work for me, so my
sink has it off with gst_base_sink_set_sync(FALSE).

After processing a buffer I calculate for how long the sink needs to block
and then it needs to do a pipeline-friendly version of sleep().
Can anyone suggest how it can be done?

Obviously calling sleep() works, but it delays state transitions by the time
of the sleep (worst case), which is not what anyone would want.
I saw gst_base_sink_wait_clock(), which seemed like the right thing to use,
but it only works when the synchronization for the sink is on.

To hack something together I wrote this

void my_sink_sleep(GstBaseSink* basesink, guint delay_ms)
    GstClock* clock;
    GstClockTime time;
    if ((clock = GST_ELEMENT_CLOCK(basesink)) != NULL)
        /* Get current clock time */
        time = gst_clock_get_time(clock);
        /* Add our sleep time */
        time += GST_MSECOND * delay_ms;
        /* Subtract base time as this is what gst_base_sink_wait_clock()
will add */
        time -= GST_ELEMENT_CAST(basesink)->base_time;

        /* BUGBUG: this does not look right, but it does what I need */
        gst_base_sink_set_sync(basesink, TRUE);
        gst_base_sink_wait_clock(basesink, time, NULL);
        gst_base_sink_set_sync(basesink, FALSE);

This works, but it does not look right.
Any ideas?

-- Max.

More information about the gstreamer-devel mailing list