rtsp-server: Use single-include rtsp header to make sure we get all definitions
[platform/upstream/gstreamer.git] / examples / test-record.c
1 /* GStreamer
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>
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 #include <gst/gst.h>
23
24 #include <gst/rtsp-server/rtsp-server.h>
25
26 #define DEFAULT_RTSP_PORT "8554"
27
28 static char *port = (char *) DEFAULT_RTSP_PORT;
29
30 static GOptionEntry entries[] = {
31   {"port", 'p', 0, G_OPTION_ARG_STRING, &port,
32       "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"},
33   {NULL}
34 };
35
36 int
37 main (int argc, char *argv[])
38 {
39   GMainLoop *loop;
40   GstRTSPServer *server;
41   GstRTSPMountPoints *mounts;
42   GstRTSPMediaFactory *factory;
43   GOptionContext *optctx;
44   GError *error = NULL;
45
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     return -1;
53   }
54   g_option_context_free (optctx);
55
56   loop = g_main_loop_new (NULL, FALSE);
57
58   /* create a server instance */
59   server = gst_rtsp_server_new ();
60
61   /* get the mount points for this server, every server has a default object
62    * that be used to map uri mount points to media factories */
63   mounts = gst_rtsp_server_get_mount_points (server);
64
65   /* make a media factory for a test stream. The default media factory can use
66    * gst-launch syntax to create pipelines.
67    * any launch line works as long as it contains elements named depay%d. Each
68    * element with depay%d names will be a stream */
69   factory = gst_rtsp_media_factory_new ();
70   gst_rtsp_media_factory_set_transport_mode (factory,
71       GST_RTSP_TRANSPORT_MODE_RECORD);
72   gst_rtsp_media_factory_set_launch (factory, argv[1]);
73   gst_rtsp_media_factory_set_latency (factory, 2000);
74
75   /* attach the test factory to the /test url */
76   gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
77
78   /* don't need the ref to the mapper anymore */
79   g_object_unref (mounts);
80
81   /* attach the server to the default maincontext */
82   gst_rtsp_server_attach (server, NULL);
83
84   /* start serving */
85   g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port);
86   g_main_loop_run (loop);
87
88   return 0;
89 }