1 /*
2 * This file is part of Wireless Display Software for Linux OS
3 *
4 * Copyright (C) 2014 Intel Corporation.
5 *
6 * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 */
23
24
25 #include <glib.h>
26 #include <iostream>
27 #include <memory>
28
29 #include <glib-unix.h>
30
31 #include "mirac-gst-test-source.hpp"
32 #include "mirac-gst-sink.hpp"
33 #include "mirac-glib-logging.hpp"
34
_sig_handler(gpointer data_ptr)35 static gboolean _sig_handler (gpointer data_ptr)
36 {
37 GMainLoop *ml = (GMainLoop *) data_ptr;
38
39 g_main_loop_quit(ml);
40
41 return G_SOURCE_CONTINUE;
42 }
43
44
main(int argc,char * argv[])45 int main (int argc, char *argv[])
46 {
47 InitGlibLogging();
48
49 GError *error = NULL;
50 GOptionContext *context;
51 GMainLoop* ml = NULL;
52
53 gchar* wfd_device_option = NULL;
54 gchar* wfd_stream_option = NULL;
55 gchar* hostname_option = NULL;
56 gint port = 0;
57
58 GOptionEntry main_entries[] =
59 {
60 { "device", 0, 0, G_OPTION_ARG_STRING, &wfd_device_option, "Specify WFD device type: testsource or sink", "(testsource|sink)"},
61 { "stream", 0, 0, G_OPTION_ARG_STRING, &wfd_stream_option, "Specify WFD stream type for testsource: audio, video, both or desktop capture", "(audio|video|both|desktop)"},
62 { "hostname", 0, 0, G_OPTION_ARG_STRING, &hostname_option, "Specify optional hostname or ip address to stream to or listen on", "host"},
63 { "port", 0, 0, G_OPTION_ARG_INT, &port, "Specify optional UDP port number to stream to or listen on", "port"},
64 { NULL }
65 };
66
67 context = g_option_context_new ("- WFD source/sink demo application\n\nExample:\ngst-test --device=testsource --stream=both --hostname=127.0.0.1 --port=5000\ngst-test --device=sink --port=5000");
68 g_option_context_add_main_entries (context, main_entries, NULL);
69
70 if (!g_option_context_parse (context, &argc, &argv, &error)) {
71 WDS_ERROR ("option parsing failed: %s", error->message);
72 g_option_context_free(context);
73 exit (1);
74 }
75 g_option_context_free(context);
76
77 wfd_test_stream_t wfd_stream = WFD_UNKNOWN_STREAM;
78 if (g_strcmp0(wfd_stream_option, "audio") == 0)
79 wfd_stream = WFD_TEST_AUDIO;
80 else if (g_strcmp0(wfd_stream_option, "video") == 0)
81 wfd_stream = WFD_TEST_VIDEO;
82 else if (g_strcmp0(wfd_stream_option, "both") == 0)
83 wfd_stream = WFD_TEST_BOTH;
84 else if (g_strcmp0(wfd_stream_option, "desktop") == 0)
85 wfd_stream = WFD_DESKTOP;
86
87 std::string hostname;
88 if (hostname_option)
89 hostname = hostname_option;
90
91 g_free(wfd_stream_option);
92 g_free(hostname_option);
93
94 gst_init (&argc, &argv);
95
96 std::unique_ptr<MiracGstSink> sink_pipeline;
97 std::unique_ptr<MiracGstTestSource> source_pipeline;
98
99 if (g_strcmp0(wfd_device_option, "testsource") == 0) {
100 source_pipeline.reset(new MiracGstTestSource(wfd_stream, hostname, port));
101 source_pipeline->SetState(GST_STATE_PLAYING);
102 WDS_LOG("Source UDP port: %d", source_pipeline->UdpSourcePort());
103 } else if (g_strcmp0(wfd_device_option, "sink") == 0) {
104 sink_pipeline.reset(new MiracGstSink(hostname, port));
105 WDS_LOG("Listening on port %d", sink_pipeline->sink_udp_port());
106 }
107
108 g_free(wfd_device_option);
109
110 ml = g_main_loop_new(NULL, TRUE);
111 g_unix_signal_add(SIGINT, _sig_handler, ml);
112 g_unix_signal_add(SIGTERM, _sig_handler, ml);
113
114 g_main_loop_run(ml);
115
116 g_main_loop_unref(ml);
117
118 return 0;
119 }
120
121