diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2014-12-30 18:13:49 +0530 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2014-12-30 16:04:14 +0000 |
commit | e0d3807cbbba6c24d24b6a9cf8e8e11005b74c51 (patch) | |
tree | 0265ab5f7585e93bc7439956d83ffc00b98563ab /examples | |
parent | 79e41bc2bee8223db5278fe85e14348b3a45aa40 (diff) |
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
Diffstat (limited to 'examples')
-rw-r--r-- | examples/test-launch.c | 26 | ||||
-rw-r--r-- | examples/test-mp4.c | 23 | ||||
-rw-r--r-- | examples/test-ogg.c | 23 | ||||
-rw-r--r-- | examples/test-uri.c | 23 |
4 files changed, 81 insertions, 14 deletions
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 <gst/rtsp-server/rtsp-server.h> +#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 <launch line> \n" - "example: %s \"( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )\"\n", - argv[0], argv[0]); + optctx = g_option_context_new ("<launch line> - 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 <gst/rtsp-server/rtsp-server.h> +#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 <filename.mp4>", argv[0]); + optctx = g_option_context_new ("<filename.mp4> - 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 <gst/rtsp-server/rtsp-server.h> +#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 <filename.ogg>", argv[0]); + optctx = g_option_context_new ("<filename.ogg> - 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 <gst/rtsp-server/rtsp-server.h> #include <gst/rtsp-server/rtsp-media-factory-uri.h> +#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 <uri>", argv[0]); + optctx = g_option_context_new ("<uri> - 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; |