Clock Synchronization

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Clock Synchronization

Trenton Miller

Project Description: 

Streaming live audio over a point-to-point network (WiFi, 2.4GHz) using UDP/RTP.

       Attributes of highest priority:
       Audio quality (44.1KHz@16bits)
       Latency (< 30 ms)

Currently, the application successfully streams audio between host and target via WiFi with an initial latency (delay) in the range of 160 - 20 ms between host (input) and target (output). Aside from the initial delay, the latency will slowly increase (latency_drift, ~ 30 ms / min).

I have been attempting to synchronize the host and target pipeline clocks in the hope that it will stabilize the initial_latency and eliminate the latency_drift. However, I have been unsuccessful.

I have attempted to synchronize the pipeline clocks by implementing the GstNetTimeProvider and GstNetClientClock structures. I'm not sure if this method requires the use of the GstRTSPServer and GstRTSPMediaFactory structures or not. Audio failed to stream after implementation.

I added the GstRTSPServer and GstRTSPMediaFactory structures to the previous implementation, using the following programs as a guide:

Audio failed to stream after implementation.

Below is a snippet of the host application:

main_loop = g_main_loop_new (NULL, FALSE);
data.loop = main_loop;
data.pipe = pipe;

clock = gst_system_clock_obtain();

gst_net_time_provider_new(clock, "", 5000);

/* create a server instance */
server = gst_rtsp_server_new ();

mounts = gst_rtsp_server_get_mount_points (server);

factory = gst_rtsp_media_factory_new ();
gst_rtsp_media_factory_set_launch (factory, "alsasrc buffer-time=200000 latency-time=5000                                                                    provide-clock=fasle ! audioconvert ! audio/x-raw,                                                                                channels=1, depth=16, width=16, rate=44100 !                                                                                  rtpL16pay ! udpsink host= port=5000");
gst_rtsp_media_factory_set_shared (factory, TRUE);
gst_rtsp_media_factory_set_clock (factory, clock);
gst_rtsp_mount_points_add_factory(mounts, "/tmp", factory);


gst_rtsp_server_attach(server, NULL);

Below is a snippet of the target application:

/* Create Pipeline */
pipeline = gst_pipeline_new("my-pipeline");

/* Get Pipeline Clock from Host */
clock = gst_net_client_clock_new("clock", "rtsp://", 5000, 0);
if (clock == NULL){
g_print("Failed to create net clock client");
return 1;

/* Wait for the clock to stabilize */
gst_clock_wait_for_sync(clock, GST_CLOCK_TIME_NONE);

gst_pipeline_use_clock(GST_PIPELINE(pipeline), clock);

/* Create Elements */
network = gst_element_factory_make("udpsrc", "network");
filter = gst_element_factory_make("capsfilter", "capsfilter");
packet = gst_element_factory_make("rtpL16depay", "packet");
convert = gst_element_factory_make("audioconvert", "audioconvert");
sink = gst_element_factory_make("alsasink", "sink");

Is this the best method for synchronizing the pipeline clocks?

Do I need to create a SDP file in the /tmp directory?

Any advice is greatly appreciated.

Thank you,


gstreamer-devel mailing list
[hidden email]