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
#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[])
{
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 */
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;
#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)
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 */
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;
#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[])
{
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 */
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;
#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)
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 */
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;