rtsp-auth: Add support for Digest authentication
[platform/upstream/gstreamer.git] / examples / test-netclock.c
1 /* GStreamer
2  * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
3  * Copyright (C) 2014 Jan Schmidt <jan@centricular.com>
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include <gst/gst.h>
22
23 #include <gst/net/gstnettimeprovider.h>
24 #include <gst/rtsp-server/rtsp-server.h>
25
26 GstClock *global_clock;
27
28 #define TEST_TYPE_RTSP_MEDIA_FACTORY      (test_rtsp_media_factory_get_type ())
29 #define TEST_TYPE_RTSP_MEDIA              (test_rtsp_media_get_type ())
30
31 GType test_rtsp_media_get_type (void);
32
33 typedef struct TestRTSPMediaClass TestRTSPMediaClass;
34 typedef struct TestRTSPMedia TestRTSPMedia;
35
36 struct TestRTSPMediaClass
37 {
38   GstRTSPMediaClass parent;
39 };
40
41 struct TestRTSPMedia
42 {
43   GstRTSPMedia parent;
44 };
45
46 static gboolean custom_setup_rtpbin (GstRTSPMedia * media, GstElement * rtpbin);
47
48 G_DEFINE_TYPE (TestRTSPMedia, test_rtsp_media, GST_TYPE_RTSP_MEDIA);
49
50 static void
51 test_rtsp_media_class_init (TestRTSPMediaClass * test_klass)
52 {
53   GstRTSPMediaClass *klass = (GstRTSPMediaClass *) (test_klass);
54   klass->setup_rtpbin = custom_setup_rtpbin;
55 }
56
57 static void
58 test_rtsp_media_init (TestRTSPMedia * media)
59 {
60 }
61
62 static gboolean
63 custom_setup_rtpbin (GstRTSPMedia * media, GstElement * rtpbin)
64 {
65   g_object_set (rtpbin, "ntp-time-source", 3, NULL);
66   return TRUE;
67 }
68
69 int
70 main (int argc, char *argv[])
71 {
72   GMainLoop *loop;
73   GstRTSPServer *server;
74   GstRTSPMountPoints *mounts;
75   GstRTSPMediaFactory *factory;
76
77   gst_init (&argc, &argv);
78
79   if (argc < 2) {
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",
83         argv[0], argv[0]);
84     return -1;
85   }
86
87   loop = g_main_loop_new (NULL, FALSE);
88
89   global_clock = gst_system_clock_obtain ();
90   gst_net_time_provider_new (global_clock, "0.0.0.0", 8554);
91
92   /* create a server instance */
93   server = gst_rtsp_server_new ();
94
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);
98
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);
108
109   /* attach the test factory to the /test url */
110   gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
111
112   /* don't need the ref to the mapper anymore */
113   g_object_unref (mounts);
114
115   /* attach the server to the default maincontext */
116   gst_rtsp_server_attach (server, NULL);
117
118   /* start serving */
119   g_print ("stream ready at rtsp://127.0.0.1:8554/test\n");
120   g_main_loop_run (loop);
121
122   return 0;
123 }