Initial release including wifi display based on gst-rtsp-server-1.4.1
[platform/upstream/gstreamer.git] / examples / test-wfd.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., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include <glib-unix.h>
21 #include <gst/gst.h>
22
23 #include <gst/rtsp-server/rtsp-server-wfd.h>
24 #include <gst/rtsp-server/rtsp-media-factory-wfd.h>
25
26 #if 1
27 #define VIDEO_PIPELINE "ximagesrc ! videorate ! videoscale ! videoconvert ! " \
28   "video/x-raw,width=640,height=480,framerate=30/1 ! " \
29   "x264enc aud=false byte-stream=true bitrate=512 ! video/x-h264,profile=baseline ! mpegtsmux wfd-mode=TRUE ! " \
30   "rtpmp2tpay name=pay0 pt=33"
31 #define AUDIO_PIPELINE "pulsesrc device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor ! audioconvert ! " \
32   "faac ! mpegtsmux wfd-mode=TRUE ! " \
33   "rtpmp2tpay name=pay0 pt=33"
34 #else
35 #define VIDEO_PIPELINE "ximagesrc ! videoscale ! videoconvert ! " \
36   "video/x-raw,width=640,height=480,framerate=60/1 ! " \
37   "x264enc aud=false byte-stream=true bitrate=512 ! video/x-h264,profile=baseline ! mpegtsmux name=mux " \
38   "pulsesrc device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor ! audioconvert ! " \
39   "faac ! mux. mux. ! " \
40   "rtpmp2tpay name=pay0 pt=33"
41 #if 0
42 #define VIDEO_PIPELINE "ximagesrc startx=0 starty=0 endx=1919 endy=1079 ! videorate ! videoscale ! video/x-raw,width=1280,height=720,framerate=30/1 ! videoconvert ! " \
43   "x264enc aud=false byte-stream=true bitrate=512 ! video/x-h264,profile=baseline ! mpegtsmux name=mux wfd-mode=TRUE " \
44   "pulsesrc device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor ! audioconvert ! " \
45   "faac ! mux. mux. ! " \
46   "rtpmp2tpay name=pay0 pt=33"
47 #endif
48 /*
49 #define VIDEO_PIPELINE "ximagesrc do-timestamp=true ! videoscale ! video/x-raw,width=1280,height=720,framerate=30/1 ! videoconvert ! " \
50   "x264enc aud=false byte-stream=true bitrate=512 ! video/x-h264,profile=baseline ! mpegtsmux name=mux wfd-mode=TRUE " \
51   "pulsesrc device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor provide-clock=false ! audioconvert ! " \
52   "faac ! mux. mux. ! " \
53   "rtpmp2tpay name=pay0 pt=33"
54 */
55 #endif
56
57 #define WFD_RTSP_PORT "2022"
58 #define TEST_MOUNT_POINT  "/wfd1.0/streamid=0"
59
60 GMainLoop *loop;
61
62 static gboolean
63 teardown(gpointer data)
64 {
65   GstRTSPWFDServer *server = NULL;
66   server = (GstRTSPWFDServer *) data;
67
68   g_print("teardown\n");
69
70   if (server == NULL) return FALSE;
71
72   gst_rtsp_wfd_server_trigger_request (GST_RTSP_SERVER(server), WFD_TRIGGER_TEARDOWN);
73
74   return FALSE;
75 }
76
77 int main (int argc, char *argv[])
78 {
79   GstRTSPWFDServer *server;
80   guint id;
81   GstRTSPMountPoints *mounts;
82   GstRTSPMediaFactoryWFD *factory;
83   GMainContext *context = NULL;
84   GSource * signal_handler_src = NULL;
85
86   gst_init (&argc, &argv);
87
88   loop = g_main_loop_new (NULL, FALSE);
89   context = g_main_loop_get_context(loop);
90
91   /* create a server instance */
92   server = gst_rtsp_wfd_server_new ();
93
94   gst_rtsp_server_set_address(GST_RTSP_SERVER(server), "192.168.3.100"); 
95   //gst_rtsp_server_set_address(GST_RTSP_SERVER(server), "192.168.49.194"); 
96   //gst_rtsp_server_set_address(GST_RTSP_SERVER(server), "192.168.49.20"); 
97   gst_rtsp_server_set_service(GST_RTSP_SERVER(server), WFD_RTSP_PORT);
98   mounts = gst_rtsp_server_get_mount_points (GST_RTSP_SERVER(server));
99
100   factory = gst_rtsp_media_factory_wfd_new ();
101
102   gst_rtsp_media_factory_set_launch (GST_RTSP_MEDIA_FACTORY(factory),
103       "( " VIDEO_PIPELINE " )");
104   g_object_ref (factory);
105   gst_rtsp_mount_points_add_factory (mounts, TEST_MOUNT_POINT, GST_RTSP_MEDIA_FACTORY(factory));
106   g_object_unref (mounts);
107
108   /* attach the server to the default maincontext */
109   if ((id = gst_rtsp_server_attach (GST_RTSP_SERVER_CAST(server), NULL)) == 0)
110     goto failed;
111
112   signal_handler_src = (GSource *)g_unix_signal_source_new (SIGINT);
113   /* Set callback to be called when socket is readable */
114   g_source_set_callback(signal_handler_src, teardown, server, NULL);
115   g_source_attach(signal_handler_src, context);
116
117   /* start serving */
118   g_main_loop_run (loop);
119
120   /* cleanup */
121   g_source_remove (id);
122   g_object_unref (server);
123   g_main_loop_unref (loop);
124
125   return 0;
126
127   /* ERRORS */
128 failed:
129   {
130     g_print ("failed to attach the server\n");
131     return -1;
132   }
133 }