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_factory_get_type (void);
32 GType test_rtsp_media_get_type (void);
34 static GstRTSPMediaFactory *test_rtsp_media_factory_new (void);
35 static GstElement *create_pipeline (GstRTSPMediaFactory * factory,
36 GstRTSPMedia * media);
38 typedef struct TestRTSPMediaFactoryClass TestRTSPMediaFactoryClass;
39 typedef struct TestRTSPMediaFactory TestRTSPMediaFactory;
41 struct TestRTSPMediaFactoryClass
43 GstRTSPMediaFactoryClass parent;
46 struct TestRTSPMediaFactory
48 GstRTSPMediaFactory parent;
51 typedef struct TestRTSPMediaClass TestRTSPMediaClass;
52 typedef struct TestRTSPMedia TestRTSPMedia;
54 struct TestRTSPMediaClass
56 GstRTSPMediaClass parent;
65 test_rtsp_media_factory_new (void)
67 GstRTSPMediaFactory *result;
69 result = g_object_new (TEST_TYPE_RTSP_MEDIA_FACTORY, NULL);
74 G_DEFINE_TYPE (TestRTSPMediaFactory, test_rtsp_media_factory,
75 GST_TYPE_RTSP_MEDIA_FACTORY);
77 static gboolean custom_setup_rtpbin (GstRTSPMedia * media, GstElement * rtpbin);
80 test_rtsp_media_factory_class_init (TestRTSPMediaFactoryClass * test_klass)
82 GstRTSPMediaFactoryClass *mf_klass =
83 (GstRTSPMediaFactoryClass *) (test_klass);
84 mf_klass->create_pipeline = create_pipeline;
88 test_rtsp_media_factory_init (TestRTSPMediaFactory * factory)
93 create_pipeline (GstRTSPMediaFactory * factory, GstRTSPMedia * media)
97 pipeline = gst_pipeline_new ("media-pipeline");
98 gst_pipeline_use_clock (GST_PIPELINE (pipeline), global_clock);
99 gst_element_set_base_time (pipeline, 0);
100 gst_element_set_start_time (pipeline, GST_CLOCK_TIME_NONE);
101 gst_rtsp_media_take_pipeline (media, GST_PIPELINE_CAST (pipeline));
106 G_DEFINE_TYPE (TestRTSPMedia, test_rtsp_media, GST_TYPE_RTSP_MEDIA);
109 test_rtsp_media_class_init (TestRTSPMediaClass * test_klass)
111 GstRTSPMediaClass *klass = (GstRTSPMediaClass *) (test_klass);
112 klass->setup_rtpbin = custom_setup_rtpbin;
116 test_rtsp_media_init (TestRTSPMedia * media)
121 custom_setup_rtpbin (GstRTSPMedia * media, GstElement * rtpbin)
123 g_object_set (rtpbin, "use-pipeline-clock", TRUE, NULL);
128 main (int argc, char *argv[])
131 GstRTSPServer *server;
132 GstRTSPMountPoints *mounts;
133 GstRTSPMediaFactory *factory;
135 gst_init (&argc, &argv);
138 g_print ("usage: %s <launch line> \n"
139 "example: %s \"( videotestsrc is-live=true ! x264enc ! rtph264pay name=pay0 pt=96 )\"\n"
140 "Pipeline must be live for synchronisation to work properly with this method!\n",
145 loop = g_main_loop_new (NULL, FALSE);
147 global_clock = gst_system_clock_obtain ();
148 gst_net_time_provider_new (global_clock, "0.0.0.0", 8554);
150 /* create a server instance */
151 server = gst_rtsp_server_new ();
153 /* get the mount points for this server, every server has a default object
154 * that be used to map uri mount points to media factories */
155 mounts = gst_rtsp_server_get_mount_points (server);
157 /* make a media factory for a test stream. The default media factory can use
158 * gst-launch syntax to create pipelines.
159 * any launch line works as long as it contains elements named pay%d. Each
160 * element with pay%d names will be a stream */
161 factory = test_rtsp_media_factory_new ();
162 gst_rtsp_media_factory_set_launch (factory, argv[1]);
163 gst_rtsp_media_factory_set_shared (GST_RTSP_MEDIA_FACTORY (factory), TRUE);
164 gst_rtsp_media_factory_set_media_gtype (GST_RTSP_MEDIA_FACTORY (factory),
165 TEST_TYPE_RTSP_MEDIA);
167 /* attach the test factory to the /test url */
168 gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
170 /* don't need the ref to the mapper anymore */
171 g_object_unref (mounts);
173 /* attach the server to the default maincontext */
174 gst_rtsp_server_attach (server, NULL);
177 g_print ("stream ready at rtsp://127.0.0.1:8554/test\n");
178 g_main_loop_run (loop);