void client_connection (GstRTSPServer *gstrtspserver, GstRTSPClient *arg1, gpointer user_data) { GstRTSPConnection * conn = (GstRTSPConnection*) gst_rtsp_client_get_connection (arg1); g_print ("Local ip %s\n", gst_rtsp_connection_get_ip (conn)); gint * port = (gint*) user_data; g_print ("Port %d\n", *port); if (global_clock == NULL) { g_print ("No clocks already available\n"); } else { g_print ("A clock was present, unref it!.\n"); } global_clock = gst_net_client_clock_new ("net_clock", gst_rtsp_connection_get_ip (conn), 8554, 0); if (global_clock == NULL) { g_print ("Failed to create net clock client for %s:%d\n", "192.168.0.1", 8554); return; } g_print ("Waiting clock..."); /* Wait for the clock to stabilise */ gst_clock_wait_for_sync (global_clock, GST_CLOCK_TIME_NONE); g_print ("Synked!\n"); }
gint main (gint argc, gchar ** argv) { GOptionContext *opt_ctx; GstClock *clock; GError *err = NULL; opt_ctx = g_option_context_new ("- GStreamer PTP clock test app"); g_option_context_add_main_entries (opt_ctx, opt_entries, NULL); g_option_context_add_group (opt_ctx, gst_init_get_option_group ()); if (!g_option_context_parse (opt_ctx, &argc, &argv, &err)) g_error ("Error parsing options: %s", err->message); g_clear_error (&err); g_option_context_free (opt_ctx); if (!gst_ptp_init (GST_PTP_CLOCK_ID_NONE, NULL)) g_error ("failed to init ptp"); if (stats) gst_ptp_statistics_callback_add (stats_cb, NULL, NULL); clock = gst_ptp_clock_new ("test-clock", domain); gst_clock_wait_for_sync (GST_CLOCK (clock), GST_CLOCK_TIME_NONE); while (TRUE) { GstClockTime local, remote; GstClockTimeDiff diff; local = g_get_real_time () * 1000; remote = gst_clock_get_time (clock); diff = GST_CLOCK_DIFF (local, remote); g_print ("local: %" GST_TIME_FORMAT " ptp: %" GST_TIME_FORMAT " diff: %s%" GST_TIME_FORMAT "\n", GST_TIME_ARGS (local), GST_TIME_ARGS (remote), (diff < 0 ? "-" : " "), GST_TIME_ARGS (ABS (diff))); g_usleep (100000); } return 0; }