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.
23 #include <gst/net/gstnettimeprovider.h>
24 #include <gst/rtsp-server/rtsp-server.h>
26 GstClock *global_clock;
28 #define TEST_TYPE_RTSP_MEDIA_FACTORY (test_rtsp_media_factory_get_type ())
29 #define TEST_TYPE_RTSP_MEDIA (test_rtsp_media_get_type ())
31 GType test_rtsp_media_get_type (void);
33 typedef struct TestRTSPMediaClass TestRTSPMediaClass;
34 typedef struct TestRTSPMedia TestRTSPMedia;
36 struct TestRTSPMediaClass
38 GstRTSPMediaClass parent;
46 static gboolean custom_setup_rtpbin (GstRTSPMedia * media, GstElement * rtpbin);
48 G_DEFINE_TYPE (TestRTSPMedia, test_rtsp_media, GST_TYPE_RTSP_MEDIA);
51 test_rtsp_media_class_init (TestRTSPMediaClass * test_klass)
53 GstRTSPMediaClass *klass = (GstRTSPMediaClass *) (test_klass);
54 klass->setup_rtpbin = custom_setup_rtpbin;
58 test_rtsp_media_init (TestRTSPMedia * media)
63 custom_setup_rtpbin (GstRTSPMedia * media, GstElement * rtpbin)
65 g_object_set (rtpbin, "ntp-time-source", 3, NULL);
70 main (int argc, char *argv[])
73 GstRTSPServer *server;
74 GstRTSPMountPoints *mounts;
75 GstRTSPMediaFactory *factory;
77 gst_init (&argc, &argv);
80 g_print ("usage: %s <launch line> \n"
81 "example: %s \"( videotestsrc is-live=true ! x264enc ! rtph264pay name=pay0 pt=96 )\"\n"
82 "Pipeline must be live for synchronisation to work properly with this method!\n",
87 loop = g_main_loop_new (NULL, FALSE);
89 global_clock = gst_system_clock_obtain ();
90 gst_net_time_provider_new (global_clock, "0.0.0.0", 8554);
92 /* create a server instance */
93 server = gst_rtsp_server_new ();
95 /* get the mount points for this server, every server has a default object
96 * that be used to map uri mount points to media factories */
97 mounts = gst_rtsp_server_get_mount_points (server);
99 /* make a media factory for a test stream. The default media factory can use
100 * gst-launch syntax to create pipelines.
101 * any launch line works as long as it contains elements named pay%d. Each
102 * element with pay%d names will be a stream */
103 factory = gst_rtsp_media_factory_new ();
104 gst_rtsp_media_factory_set_launch (factory, argv[1]);
105 gst_rtsp_media_factory_set_shared (factory, TRUE);
106 gst_rtsp_media_factory_set_media_gtype (factory, TEST_TYPE_RTSP_MEDIA);
107 gst_rtsp_media_factory_set_clock (factory, global_clock);
109 /* attach the test factory to the /test url */
110 gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
112 /* don't need the ref to the mapper anymore */
113 g_object_unref (mounts);
115 /* attach the server to the default maincontext */
116 gst_rtsp_server_attach (server, NULL);
119 g_print ("stream ready at rtsp://127.0.0.1:8554/test\n");
120 g_main_loop_run (loop);