From: Nirbheek Chauhan Date: Tue, 30 Dec 2014 12:43:49 +0000 (+0530) Subject: examples: Add command-line parsing and take a 'port' argument X-Git-Tag: 1.19.3~495^2~710 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e0d3807cbbba6c24d24b6a9cf8e8e11005b74c51;p=platform%2Fupstream%2Fgstreamer.git examples: Add command-line parsing and take a 'port' argument This allows users to run multiple servers on different ports for testing. Only done for examples that actually take arguments and hence are capable of outputting different streams for each instance on each port. https://bugzilla.gnome.org/show_bug.cgi?id=742115 --- diff --git a/examples/test-launch.c b/examples/test-launch.c index 0466224..663391c 100644 --- a/examples/test-launch.c +++ b/examples/test-launch.c @@ -21,6 +21,16 @@ #include +#define DEFAULT_RTSP_PORT "8554" + +static char *port = (char *) DEFAULT_RTSP_PORT; + +static GOptionEntry entries[] = { + {"port", 'p', 0, G_OPTION_ARG_STRING, &port, + "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"}, + {NULL} +}; + int main (int argc, char *argv[]) { @@ -28,20 +38,26 @@ main (int argc, char *argv[]) GstRTSPServer *server; GstRTSPMountPoints *mounts; GstRTSPMediaFactory *factory; + GOptionContext *optctx; + GError *error = NULL; gst_init (&argc, &argv); - if (argc < 2) { - g_print ("usage: %s \n" - "example: %s \"( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )\"\n", - argv[0], argv[0]); + optctx = g_option_context_new (" - Test RTSP Server, Launch\n\n" + "Example: \"( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )\""); + g_option_context_add_main_entries (optctx, entries, NULL); + g_option_context_add_group (optctx, gst_init_get_option_group ()); + if (!g_option_context_parse (optctx, &argc, &argv, &error)) { + g_printerr ("Error parsing options: %s\n", error->message); return -1; } + g_option_context_free (optctx); loop = g_main_loop_new (NULL, FALSE); /* create a server instance */ server = gst_rtsp_server_new (); + g_object_set (server, "service", port, NULL); /* get the mount points for this server, every server has a default object * that be used to map uri mount points to media factories */ @@ -64,7 +80,7 @@ main (int argc, char *argv[]) gst_rtsp_server_attach (server, NULL); /* start serving */ - g_print ("stream ready at rtsp://127.0.0.1:8554/test\n"); + g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port); g_main_loop_run (loop); return 0; diff --git a/examples/test-mp4.c b/examples/test-mp4.c index bf88abe..3ca0060 100644 --- a/examples/test-mp4.c +++ b/examples/test-mp4.c @@ -21,6 +21,16 @@ #include +#define DEFAULT_RTSP_PORT "8554" + +static char *port = (char *) DEFAULT_RTSP_PORT; + +static GOptionEntry entries[] = { + {"port", 'p', 0, G_OPTION_ARG_STRING, &port, + "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"}, + {NULL} +}; + /* called when a stream has received an RTCP packet from the client */ static void on_ssrc_active (GObject * session, GObject * source, GstRTSPMedia * media) @@ -83,19 +93,26 @@ main (int argc, char *argv[]) GstRTSPServer *server; GstRTSPMountPoints *mounts; GstRTSPMediaFactory *factory; + GOptionContext *optctx; + GError *error = NULL; gchar *str; gst_init (&argc, &argv); - if (argc < 2) { - g_message ("usage: %s ", argv[0]); + optctx = g_option_context_new (" - Test RTSP Server, MP4"); + g_option_context_add_main_entries (optctx, entries, NULL); + g_option_context_add_group (optctx, gst_init_get_option_group ()); + if (!g_option_context_parse (optctx, &argc, &argv, &error)) { + g_printerr ("Error parsing options: %s\n", error->message); return -1; } + g_option_context_free (optctx); loop = g_main_loop_new (NULL, FALSE); /* create a server instance */ server = gst_rtsp_server_new (); + g_object_set (server, "service", port, NULL); /* get the mount points for this server, every server has a default object * that be used to map uri mount points to media factories */ @@ -126,7 +143,7 @@ main (int argc, char *argv[]) gst_rtsp_server_attach (server, NULL); /* start serving */ - g_print ("stream ready at rtsp://127.0.0.1:8554/test\n"); + g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port); g_main_loop_run (loop); return 0; diff --git a/examples/test-ogg.c b/examples/test-ogg.c index f4d104c..f3e26b4 100644 --- a/examples/test-ogg.c +++ b/examples/test-ogg.c @@ -21,6 +21,16 @@ #include +#define DEFAULT_RTSP_PORT "8554" + +static char *port = (char *) DEFAULT_RTSP_PORT; + +static GOptionEntry entries[] = { + {"port", 'p', 0, G_OPTION_ARG_STRING, &port, + "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"}, + {NULL} +}; + int main (int argc, char *argv[]) { @@ -28,19 +38,26 @@ main (int argc, char *argv[]) GstRTSPServer *server; GstRTSPMountPoints *mounts; GstRTSPMediaFactory *factory; + GOptionContext *optctx; + GError *error = NULL; gchar *str; gst_init (&argc, &argv); - if (argc < 2) { - g_message ("usage: %s ", argv[0]); + optctx = g_option_context_new (" - Test RTSP Server, OGG"); + g_option_context_add_main_entries (optctx, entries, NULL); + g_option_context_add_group (optctx, gst_init_get_option_group ()); + if (!g_option_context_parse (optctx, &argc, &argv, &error)) { + g_printerr ("Error parsing options: %s\n", error->message); return -1; } + g_option_context_free (optctx); loop = g_main_loop_new (NULL, FALSE); /* create a server instance */ server = gst_rtsp_server_new (); + g_object_set (server, "service", port, NULL); /* get the mount points for this server, every server has a default object * that be used to map uri mount points to media factories */ @@ -69,7 +86,7 @@ main (int argc, char *argv[]) gst_rtsp_server_attach (server, NULL); /* start serving */ - g_print ("stream ready at rtsp://127.0.0.1:8554/test\n"); + g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port); g_main_loop_run (loop); return 0; diff --git a/examples/test-uri.c b/examples/test-uri.c index b0daebc..fb6deb7 100644 --- a/examples/test-uri.c +++ b/examples/test-uri.c @@ -22,6 +22,16 @@ #include #include +#define DEFAULT_RTSP_PORT "8554" + +static char *port = (char *) DEFAULT_RTSP_PORT; + +static GOptionEntry entries[] = { + {"port", 'p', 0, G_OPTION_ARG_STRING, &port, + "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"}, + {NULL} +}; + static gboolean timeout (GstRTSPServer * server) @@ -55,18 +65,25 @@ main (int argc, char *argv[]) GstRTSPServer *server; GstRTSPMountPoints *mounts; GstRTSPMediaFactoryURI *factory; + GOptionContext *optctx; + GError *error = NULL; gst_init (&argc, &argv); - if (argc < 2) { - g_message ("usage: %s ", argv[0]); + optctx = g_option_context_new (" - Test RTSP Server, URI"); + g_option_context_add_main_entries (optctx, entries, NULL); + g_option_context_add_group (optctx, gst_init_get_option_group ()); + if (!g_option_context_parse (optctx, &argc, &argv, &error)) { + g_printerr ("Error parsing options: %s\n", error->message); return -1; } + g_option_context_free (optctx); loop = g_main_loop_new (NULL, FALSE); /* create a server instance */ server = gst_rtsp_server_new (); + g_object_set (server, "service", port, NULL); /* get the mount points for this server, every server has a default object * that be used to map uri mount points to media factories */ @@ -100,7 +117,7 @@ main (int argc, char *argv[]) g_timeout_add_seconds (10, (GSourceFunc) remove_map, server); /* start serving */ - g_print ("stream ready at rtsp://127.0.0.1:8554/test\n"); + g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port); g_main_loop_run (loop); return 0;