webrtc: allow to specify ice-servers on command line

This commit is contained in:
Kamil Trzcinski 2023-06-02 11:09:46 +02:00
parent 589c5fa602
commit e8ffe47343
6 changed files with 30 additions and 1 deletions

View File

@ -8,6 +8,7 @@
- http: add `/control` to provide simple JS interface to live edit camera settings
- http: change `/option` to accept `device=`, `key=`, and `value=`
- device: show stddev estimates to measure frame pacing
- webrtc: allow to specify `--webrtc-ice_servers=` on command line
## Variants

View File

@ -131,6 +131,8 @@ option_t all_options[] = {
DEFINE_OPTION_DEFAULT(rtsp, port, uint, "8554", "Set the RTSP server port (default: 8854)."),
DEFINE_OPTION_PTR(webrtc, ice_servers, list, "Specify ICE servers: [(stun|turn|turns)(:|://)][username:password@]hostname[:port][?transport=udp|tcp|tls)]."),
DEFINE_OPTION_DEFAULT(log, debug, bool, "1", "Enable debug logging."),
DEFINE_OPTION_DEFAULT(log, verbose, bool, "1", "Enable verbose logging."),
DEFINE_OPTION_DEFAULT(log, stats, uint, "1", "Print statistics every duration."),

View File

@ -9,9 +9,12 @@ extern "C" {
#include "util/opts/log.h"
#include "util/opts/fourcc.h"
#include "util/opts/control.h"
#include "util/opts/opts.h"
#include "device/buffer.h"
};
#include "util/opts/helpers.hh"
#ifdef USE_LIBDATACHANNEL
#include <string>
@ -37,7 +40,7 @@ static std::mutex webrtc_clients_lock;
static const auto webrtc_client_lock_timeout = 3 * 1000ms;
static const auto webrtc_client_max_json_body = 10 * 1024;
static const auto webrtc_client_video_payload_type = 102; // H264
static const rtc::Configuration webrtc_configuration = {
static rtc::Configuration webrtc_configuration = {
// .iceServers = { rtc::IceServer("stun:stun.l.google.com:19302") },
.disableAutoNegotiation = true
};
@ -390,6 +393,10 @@ extern "C" void http_webrtc_offer(http_worker_t *worker, FILE *stream)
extern "C" int webrtc_server(webrtc_options_t *options)
{
for (const auto &ice_server : str_split(options->ice_servers, OPTION_VALUE_LIST_SEP_CHAR)) {
webrtc_configuration.iceServers.push_back(rtc::IceServer(ice_server));
}
buffer_lock_register_check_streaming(&video_lock, webrtc_h264_needs_buffer);
buffer_lock_register_notify_buffer(&video_lock, webrtc_h264_capture);
options->running = true;

View File

@ -2,11 +2,14 @@
#include <stdio.h>
#define WEBRTC_OPTIONS_LENGTH 4096
typedef struct http_worker_s http_worker_t;
typedef struct webrtc_options_s {
bool running;
bool disabled;
char ice_servers[WEBRTC_OPTIONS_LENGTH];
} webrtc_options_t;
// WebRTC

15
util/opts/helpers.hh Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <string>
#include <vector>
#include <sstream>
inline std::vector<std::string> str_split(const std::string& in, const char seperator)
{
std::vector<std::string> output;
std::istringstream stream(in);
for (std::string s; std::getline(stream, s, seperator); ) {
output.push_back(s);
}
return output;
}

View File

@ -26,6 +26,7 @@ typedef struct options_s {
const char *description;
} option_t;
#define OPTION_VALUE_LIST_SEP_CHAR ';'
#define OPTION_VALUE_LIST_SEP ";"
#define OPTION_FORMAT_uint "%u"