gstreamer: update translations
[platform/upstream/gstreamer.git] / subprojects / gst-rtsp-server / 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     g_option_context_free (optctx);
53     g_clear_error (&error);
54     return -1;
55   }
56
57   if (argc < 2) {
58     g_print ("%s\n", g_option_context_get_help (optctx, TRUE, NULL));
59     return 1;
60   }
61   g_option_context_free (optctx);
62
63   loop = g_main_loop_new (NULL, FALSE);
64
65   /* create a server instance */
66   server = gst_rtsp_server_new ();
67
68   g_object_set (server, "service", port, NULL);
69
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);
73
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);
83
84   /* attach the test factory to the /test url */
85   gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
86
87   /* don't need the ref to the mapper anymore */
88   g_object_unref (mounts);
89
90   /* attach the server to the default maincontext */
91   gst_rtsp_server_attach (server, NULL);
92
93   /* start serving */
94   g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port);
95   g_print ("On the sender, send a stream with rtspclientsink:\n"
96       "  gst-launch-1.0 videotestsrc ! x264enc ! rtspclientsink location=rtsp://127.0.0.1:%s/test\n",
97       port);
98   g_main_loop_run (loop);
99
100   return 0;
101 }