2 * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
3 * Copyright (C) 2015 Centricular Ltd
4 * Author: Sebastian Dröge <sebastian@centricular.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
24 #include <gst/rtsp-server/rtsp-server.h>
26 #define DEFAULT_RTSP_PORT "8554"
28 static char *port = (char *) DEFAULT_RTSP_PORT;
30 static GOptionEntry entries[] = {
31 {"port", 'p', 0, G_OPTION_ARG_STRING, &port,
32 "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"},
37 main (int argc, char *argv[])
40 GstRTSPServer *server;
41 GstRTSPMountPoints *mounts;
42 GstRTSPMediaFactory *factory;
43 GOptionContext *optctx;
46 optctx = g_option_context_new ("<launch line> - Test RTSP Server, Launch\n\n"
47 "Example: \"( decodebin name=depay0 ! autovideosink )\"");
48 g_option_context_add_main_entries (optctx, entries, NULL);
49 g_option_context_add_group (optctx, gst_init_get_option_group ());
50 if (!g_option_context_parse (optctx, &argc, &argv, &error)) {
51 g_printerr ("Error parsing options: %s\n", error->message);
52 g_option_context_free (optctx);
53 g_clear_error (&error);
58 g_print ("%s\n", g_option_context_get_help (optctx, TRUE, NULL));
61 g_option_context_free (optctx);
63 loop = g_main_loop_new (NULL, FALSE);
65 /* create a server instance */
66 server = gst_rtsp_server_new ();
68 g_object_set (server, "service", port, NULL);
70 /* get the mount points for this server, every server has a default object
71 * that be used to map uri mount points to media factories */
72 mounts = gst_rtsp_server_get_mount_points (server);
74 /* make a media factory for a test stream. The default media factory can use
75 * gst-launch syntax to create pipelines.
76 * any launch line works as long as it contains elements named depay%d. Each
77 * element with depay%d names will be a stream */
78 factory = gst_rtsp_media_factory_new ();
79 gst_rtsp_media_factory_set_transport_mode (factory,
80 GST_RTSP_TRANSPORT_MODE_RECORD);
81 gst_rtsp_media_factory_set_launch (factory, argv[1]);
82 gst_rtsp_media_factory_set_latency (factory, 2000);
84 /* attach the test factory to the /test url */
85 gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
87 /* don't need the ref to the mapper anymore */
88 g_object_unref (mounts);
90 /* attach the server to the default maincontext */
91 gst_rtsp_server_attach (server, NULL);
94 g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port);
95 g_main_loop_run (loop);