Commit 1dc1e5e3 authored by Jakub Adam's avatar Jakub Adam
Browse files

Receive input SRT stream

parent d4591301
......@@ -3,9 +3,20 @@ Build:
meson build
ninja -C build
Run the stream server with the latest GStreamer in uninstalled environment:
To run the stream server with the latest GStreamer in uninstalled environment:
ninja -C build uninstalled
./build/src/multistream-server
Open http://localhost:8080 in a browser to watch the stream.
The server will wait for incoming SRT stream on 127.0.0.1:7001. You can stream
to the server for example using this pipeline:
gst-launch-1.0 v4l2src ! videoconvert ! clockoverlay ! x264enc ! mpegtsmux ! srtsink uri=srt://127.0.0.1:7001
Open http://localhost:8080 in a browser to watch forwarded HLS stream of the
input.
Application options:
-u, --srt-uri=srt://address:port SRT stream URI.
Default: srt://127.0.0.1:7001?mode=listener.
......@@ -3,6 +3,17 @@
#include <glib-unix.h>
#include <gst/gst.h>
#define DEFAULT_SRT_URI "srt://127.0.0.1:7001?mode=listener"
static gchar *srt_uri = NULL;
static GOptionEntry options[] = {
{ "srt-uri", 'u', 0, G_OPTION_ARG_STRING, &srt_uri,
"SRT stream URI. Default: " DEFAULT_SRT_URI ".", "srt://address:port"
},
{ NULL }
};
static gboolean
sigint_handler (gpointer user_data)
{
......@@ -10,19 +21,40 @@ sigint_handler (gpointer user_data)
return G_SOURCE_REMOVE;
}
static gboolean
gst_bus_cb (GstBus * bus, GstMessage * message, gpointer data)
{
return TRUE;
}
int main (int argc, char *argv[])
{
GOptionContext *option_context;
GMainLoop *loop;
MssHttpServer *http_server;
gchar *pipeline_str;
GstElement *pipeline;
GError *error = NULL;
GstBus *bus;
option_context = g_option_context_new (NULL);
g_option_context_add_main_entries (option_context, options, NULL);
if (!g_option_context_parse (option_context, &argc, &argv, &error)) {
g_print ("option parsing failed: %s\n", error->message);
exit (1);
}
if (!srt_uri) {
srt_uri = g_strdup(DEFAULT_SRT_URI);
}
http_server = mss_http_server_new ();
pipeline_str = g_strdup_printf ("videotestsrc is-live=true ! x264enc ! "
"mpegtsmux ! hlssink location=%s/segment%%05d.ts "
pipeline_str = g_strdup_printf ("srtsrc uri=%s ! tsdemux ! mpegtsmux ! "
"hlssink location=%s/segment%%05d.ts "
"playlist-location=%s/playlist.m3u8",
srt_uri,
mss_http_server_get_hls_dir (http_server),
mss_http_server_get_hls_dir (http_server));
......@@ -32,14 +64,21 @@ int main (int argc, char *argv[])
g_assert_no_error (error);
g_free (pipeline_str);
bus = gst_element_get_bus (pipeline);
gst_bus_add_watch (bus, gst_bus_cb, NULL);
gst_object_unref (bus);
loop = g_main_loop_new (NULL, FALSE);
g_unix_signal_add (SIGINT, sigint_handler, loop);
g_print ("Open http://localhost:8080 in a browser to watch HLS stream\n");
g_print ("Input SRT URI is %s.\n"
"Open http://localhost:8080 in a browser to watch HLS stream.\n",
srt_uri);
g_main_loop_run (loop);
g_main_loop_unref (loop);
gst_clear_object (&pipeline);
g_clear_object (&http_server);
g_clear_pointer(&srt_uri, g_free);
}
......@@ -6,18 +6,17 @@
<body>
<script src="https://cdn.jsdelivr.net/npm/hls.js"></script>
<center>
<video id="video" controls></video>
<video id="video" autoplay></video>
</center>
<script>
if(Hls.isSupported()) {
var video = document.getElementById('video');
var hls = new Hls();
var hls = new Hls({
liveDurationInfinity: true
});
hls.loadSource('hls/playlist.m3u8');
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED,function() {
video.play();
});
}
</script>
</body>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment