Make the server handle arbitrary pipelines
[platform/upstream/gstreamer.git] / examples / main.c
1 /* GStreamer
2  * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gst/gst.h>
21
22 #include <gst/rtsp-server/rtsp-server.h>
23
24 int
25 main (int argc, char *argv[])
26 {
27   GMainLoop *loop;
28   GstRTSPServer *server;
29   GstRTSPMediaMapping *mapping;
30   GstRTSPMediaFactory *factory;
31
32   gst_init (&argc, &argv);
33
34   loop = g_main_loop_new (NULL, FALSE);
35
36   /* create a server instance */
37   server = gst_rtsp_server_new ();
38
39   /* get the mapping for this server, every server has a default mapper object
40    * that be used to map uri mount points to media factories */
41   mapping = gst_rtsp_server_get_media_mapping (server);
42
43   /* make a media factory for a webcam. The default media factory can use
44    * gst-launch syntax to create pipelines. */
45   factory = gst_rtsp_media_factory_new ();
46 #if 0
47   gst_rtsp_media_factory_set_launch (factory, "( "
48     "v4l2src ! video/x-raw-yuv,width=352,height=288,framerate=15/1 ! "
49     "queue ! videorate ! ffmpegcolorspace ! "
50     "x264enc bitrate=300 ! rtph264pay name=pay0 pt=96 "
51     "alsasrc ! audio/x-raw-int,rate=8000 ! queue ! "
52     "amrnbenc ! rtpamrpay name=pay1 pt=97 "
53     ")");
54 #endif
55   /* any launch line works as long as it contains elements named pay%d. Each
56    * element with pay%d names will be a stream */
57   gst_rtsp_media_factory_set_launch (factory, "( "
58     "videotestsrc ! video/x-raw-yuv,width=352,height=288,framerate=15/1 ! "
59     "x264enc bitrate=300 ! rtph264pay name=pay0 pt=96 "
60     "audiotestsrc ! audio/x-raw-int,rate=8000 ! "
61     "alawenc ! rtppcmapay name=pay1 pt=97 "
62     ")");
63
64   /* attach the factory to the /camera url */
65   gst_rtsp_media_mapping_add_factory (mapping, "/camera", factory);
66
67   /* don't need the ref to the mapper anymore */
68   g_object_unref (mapping);
69
70   /* attach the server to the default maincontext */
71   gst_rtsp_server_attach (server, NULL);
72
73   /* start serving */
74   g_main_loop_run (loop);
75
76   return 0;
77 }