diff --git a/cmd/camera-streamer/opts.c b/cmd/camera-streamer/opts.c index d5352224..fed6da5d 100644 --- a/cmd/camera-streamer/opts.c +++ b/cmd/camera-streamer/opts.c @@ -135,6 +135,7 @@ option_t all_options[] = { DEFINE_OPTION_PTR(webrtc, ice_servers, list, "Specify ICE servers: [(stun|turn|turns)(:|://)][username:password@]hostname[:port][?transport=udp|tcp|tls)]."), DEFINE_OPTION_DEFAULT(webrtc, disable_client_ice, bool, "1", "Ignore ICE servers provided in '/webrtc' request."), + DEFINE_OPTION_DEFAULT(webrtc, timeout_s, ulong, "3600", "Set how long to keep a WebRTC stream alive before disconnecting by default."), DEFINE_OPTION_DEFAULT(log, debug, bool, "1", "Enable debug logging."), DEFINE_OPTION_DEFAULT(log, verbose, bool, "1", "Enable verbose logging."), diff --git a/html/index.html b/html/index.html index 1245c239..1a465ac6 100644 --- a/html/index.html +++ b/html/index.html @@ -37,6 +37,8 @@
diff --git a/html/webrtc.html b/html/webrtc.html index 599b35aa..78fabba2 100644 --- a/html/webrtc.html +++ b/html/webrtc.html @@ -57,11 +57,18 @@ const params = Object.fromEntries(urlSearchParams.entries()); fetch(window.location.href, { - body: JSON.stringify({ + body: JSON.stringify( + params.hasOwnProperty('timeout_s')? { type: 'request', res: params.res, iceServers: iceServers, - keepAlive: true + keepAlive: true, + timeout_s: parseInt(params.timeout_s) + } : { + type: 'request', + res: params.res, + iceServers: iceServers, + keepAlive: true, }), headers: { 'Content-Type': 'application/json' diff --git a/output/webrtc/webrtc.cc b/output/webrtc/webrtc.cc index 4eedcea9..211c8332 100644 --- a/output/webrtc/webrtc.cc +++ b/output/webrtc/webrtc.cc @@ -18,7 +18,6 @@ extern "C" { #define DEFAULT_PING_INTERVAL_US (1 * 1000 * 1000) #define DEFAULT_PONG_INTERVAL_US (30 * 1000 * 1000) -#define DEFAULT_TIMEOUT_S (60 * 60) #ifdef USE_LIBDATACHANNEL @@ -332,7 +331,7 @@ static std::shared_ptr webrtc_peer_connection(rtc::Configuration config, LOG_INFO(client.get(), "Client does not support Keep-Alives. This might result in stale streams."); } - int64_t timeout_s = message.value("timeout_s", DEFAULT_TIMEOUT_S); + int64_t timeout_s = message.value("timeout_s", webrtc_options->timeout_s); if (timeout_s > 0) { LOG_INFO(client.get(), "The stream will auto-close in %" PRId64 "s.", timeout_s); client->deadline_us = get_monotonic_time_us(NULL, NULL) + timeout_s * 1000 * 1000; diff --git a/output/webrtc/webrtc.h b/output/webrtc/webrtc.h index ebb85192..c545a183 100644 --- a/output/webrtc/webrtc.h +++ b/output/webrtc/webrtc.h @@ -11,6 +11,7 @@ typedef struct webrtc_options_s { bool disabled; char ice_servers[WEBRTC_OPTIONS_LENGTH]; bool disable_client_ice; + unsigned long timeout_s; } webrtc_options_t; // WebRTC diff --git a/util/opts/opts.h b/util/opts/opts.h index 81fa35e9..6d86cf3f 100644 --- a/util/opts/opts.h +++ b/util/opts/opts.h @@ -14,6 +14,7 @@ typedef struct options_s { union { unsigned *value; unsigned *value_uint; + unsigned long *value_ulong; unsigned *value_hex; bool *value_bool; float *value_float; @@ -30,6 +31,7 @@ typedef struct options_s { #define OPTION_VALUE_LIST_SEP ";" #define OPTION_FORMAT_uint "%u" +#define OPTION_FORMAT_ulong "%lu" #define OPTION_FORMAT_hex "%08x" #define OPTION_FORMAT_bool "%d" #define OPTION_FORMAT_float "%f"