2 * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
3 * Copyright (C) 2014 Jan Schmidt <jan@centricular.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
24 #include <gst/net/gstnet.h>
26 #define PLAYBACK_DELAY_MS 40
29 source_created (GstElement * pipe, GstElement * source)
31 g_object_set (source, "latency", PLAYBACK_DELAY_MS,
32 "ntp-time-source", 3, "buffer-mode", 4, "ntp-sync", TRUE, NULL);
36 message (GstBus * bus, GstMessage * message, gpointer user_data)
38 GMainLoop *loop = user_data;
40 switch (GST_MESSAGE_TYPE (message)) {
41 case GST_MESSAGE_ERROR:{
43 gchar *name, *debug = NULL;
45 name = gst_object_get_path_string (message->src);
46 gst_message_parse_error (message, &err, &debug);
48 g_printerr ("ERROR: from element %s: %s\n", name, err->message);
50 g_printerr ("Additional debug info:\n%s\n", debug);
56 g_main_loop_quit (loop);
59 case GST_MESSAGE_WARNING:{
61 gchar *name, *debug = NULL;
63 name = gst_object_get_path_string (message->src);
64 gst_message_parse_warning (message, &err, &debug);
66 g_printerr ("ERROR: from element %s: %s\n", name, err->message);
68 g_printerr ("Additional debug info:\n%s\n", debug);
76 g_print ("Got EOS\n");
77 g_main_loop_quit (loop);
87 main (int argc, char *argv[])
95 gst_init (&argc, &argv);
98 g_print ("usage: %s rtsp://URI clock-IP clock-PORT\n"
99 "example: %s rtsp://localhost:8554/test 127.0.0.1 8554\n",
105 clock_port = atoi (argv[3]);
107 net_clock = gst_net_client_clock_new ("net_clock", server, clock_port, 0);
108 if (net_clock == NULL) {
109 g_print ("Failed to create net clock client for %s:%d\n",
114 /* Wait for the clock to stabilise */
115 gst_clock_wait_for_sync (net_clock, GST_CLOCK_TIME_NONE);
117 loop = g_main_loop_new (NULL, FALSE);
119 pipe = gst_element_factory_make ("playbin", NULL);
120 g_object_set (pipe, "uri", argv[1], NULL);
121 g_signal_connect (pipe, "source-setup", G_CALLBACK (source_created), NULL);
123 gst_pipeline_use_clock (GST_PIPELINE (pipe), net_clock);
125 /* Set this high enough so that it's higher than the minimum latency
126 * on all receivers */
127 gst_pipeline_set_latency (GST_PIPELINE (pipe), 500 * GST_MSECOND);
129 if (gst_element_set_state (pipe,
130 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
131 g_print ("Failed to set state to PLAYING\n");
135 gst_bus_add_signal_watch (GST_ELEMENT_BUS (pipe));
136 g_signal_connect (GST_ELEMENT_BUS (pipe), "message", G_CALLBACK (message),
139 g_main_loop_run (loop);
142 gst_element_set_state (pipe, GST_STATE_NULL);
143 gst_object_unref (pipe);
144 g_main_loop_unref (loop);