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, GParamSpec * pspec)
33 g_object_get (pipe, "source", &source, NULL);
34 g_assert (source != NULL);
36 g_object_set (source, "latency", PLAYBACK_DELAY_MS,
37 "use-pipeline-clock", TRUE, "buffer-mode", 1, NULL);
39 gst_object_unref (source);
43 main (int argc, char *argv[])
51 gst_init (&argc, &argv);
54 g_print ("usage: %s rtsp://URI clock-IP clock-PORT\n"
55 "example: %s rtsp://localhost:8554/test 127.0.0.1 8554\n",
61 clock_port = atoi (argv[3]);
63 net_clock = gst_net_client_clock_new ("net_clock", server, clock_port, 0);
64 if (net_clock == NULL) {
65 g_print ("Failed to create net clock client for %s:%d\n",
70 /* Wait 0.5 seconds for the clock to stabilise */
71 g_usleep (G_USEC_PER_SEC / 2);
73 pipe = gst_element_factory_make ("playbin", NULL);
74 g_object_set (pipe, "uri", argv[1], NULL);
75 g_signal_connect (pipe, "notify::source", (GCallback) source_created, NULL);
77 gst_element_set_start_time (pipe, GST_CLOCK_TIME_NONE);
78 gst_element_set_base_time (pipe, 0);
79 gst_pipeline_use_clock (GST_PIPELINE (pipe), net_clock);
81 if (gst_element_set_state (pipe,
82 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
83 g_print ("Failed to set state to PLAYING\n");
87 msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipe),
88 GST_CLOCK_TIME_NONE, GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
90 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
93 gst_message_parse_error (msg, &err, &debug);
94 g_print ("\nERROR: %s\n%s\n\n", err->message, debug);
98 gst_message_unref (msg);
101 gst_element_set_state (pipe, GST_STATE_NULL);
102 gst_object_unref (pipe);