The "gst_clock_id_wait_async()" function invokes its callback thousands of times back-to-back at first.
Using version 1.19.0.1
on Windows 10, the following testcase causes the test_func()
callback function to be called thousands of times back-to-back at first, despite the interval being set to 1 second. After these rapid consecutive calls, the callback begins to function appropriately, being called once per second.
#include <gst/gst.h>
static gboolean test_func(GstClock* clock, GstClockTime time, GstClockID id, gpointer ctx) {
static gulong i = 0;
g_print("Test func called! %d\n", i++);
return TRUE;
}
int main() {
// Init 'gstreamer', launch a pipeline, and start the pipeline "PLAYING".
gst_init(NULL, NULL);
GstElement* pipeline = gst_parse_launch("fakesrc ! fakesink", NULL);
GMainLoop* main_loop = g_main_loop_new(NULL, FALSE);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
// Set up the periodic callback based on a clock in the pipeline that was launched.
GstClock* clock = gst_pipeline_get_clock(GST_PIPELINE_CAST(pipeline));
GstClockID periodic_id = gst_clock_new_periodic_id(clock, 0, 1'000'000'000);
GstClockReturn clock_return = gst_clock_id_wait_async(periodic_id, (GstClockCallback)test_func, NULL, NULL);
gst_object_unref(clock);
// Run the main loop and then unref everything afterwards.
g_main_loop_run(main_loop);
gst_element_set_state(pipeline, GST_STATE_NULL);
g_object_unref(pipeline);
}