diff --git a/config_example b/config_example index c817629..ca7fe8b 100644 --- a/config_example +++ b/config_example @@ -1,7 +1,8 @@ mix_room MixRoom mix_url / mix_token_host TOKENHOST # can start record -mix_token_download TOKENDOWNLOAD # protected download folder -mix_token_guests TOKENGUEST # invite url +mix_token_download TOKENDOWNLOAD # protected download folder +mix_token_guests TOKENGUEST # invite url mix_token_api TOKENAPI # api token #mix_path /opt/slmix/ +#mix_stream_url rtmp://example.net/stream diff --git a/include/mix.h b/include/mix.h index be79b22..5732148 100644 --- a/include/mix.h +++ b/include/mix.h @@ -43,6 +43,7 @@ struct mix { char token_guests[TOKEN_SZ]; char token_listeners[TOKEN_SZ]; char token_download[TOKEN_SZ]; + char stream_url[URL_SZ]; struct rtc_configuration pc_config; mix_rec_h *audio_rec_h; mix_rec_h *video_rec_h; diff --git a/modules/vmix/record.c b/modules/vmix/record.c index b9e6985..8c7b6b4 100644 --- a/modules/vmix/record.c +++ b/modules/vmix/record.c @@ -10,8 +10,6 @@ #include #include -#include -#include #include #include #include @@ -19,8 +17,9 @@ #include #include #include "vmix.h" +#include -#define STREAM 0 +#define STREAM 1 static struct { RE_ATOMIC bool run; @@ -51,7 +50,6 @@ struct record_entry { }; #if STREAM -static const char *stream_url = "rtmp://example.net/stream"; static AVRational timebase_audio = {1, 48000}; #endif static AVRational timebase_video = {1, 1000000}; @@ -88,8 +86,16 @@ static int init_stream(void) /* av_log_set_level(AV_LOG_DEBUG); */ + if (str_isset(slmix()->stream_url)) { + info("streaming enabled: %s\n", slmix()->stream_url); + } + else { + info("streaming disabled\n"); + return 0; + } + ret = avformat_alloc_output_context2(&rec.streamFormatContext, NULL, - "flv", stream_url); + "flv", slmix()->stream_url); if (ret < 0) return EINVAL; @@ -117,14 +123,14 @@ static int init_stream(void) avcodec_parameters_from_context(audioStream->codecpar, rec.audioCodecCtx); - ret = avio_open(&rec.streamFormatContext->pb, stream_url, + ret = avio_open(&rec.streamFormatContext->pb, slmix()->stream_url, AVIO_FLAG_WRITE); if (ret < 0) { warning("avio_open stream error\n"); return EINVAL; } - av_dump_format(rec.streamFormatContext, 0, stream_url, 1); + av_dump_format(rec.streamFormatContext, 0, slmix()->stream_url, 1); AVDictionary *opts = NULL; av_dict_set(&opts, "flvflags", "no_duration_filesize", 0); @@ -164,7 +170,7 @@ static int write_stream(AVPacket *pkt, AVRational *time_base_src, if (!re_atomic_rlx(&rec.run_stream)) return 0; - int err = 0; + int err = 0; AVPacket *packet = av_packet_clone(pkt); packet->pts = diff --git a/src/mix.c b/src/mix.c index a7ceb12..13880d5 100644 --- a/src/mix.c +++ b/src/mix.c @@ -14,7 +14,8 @@ static struct mix mix = {.room = "main", .token_host = "", .token_guests = "", .token_listeners = "", - .token_download = ""}; + .token_download = "", + .stream_url = ""}; static struct tmr tmr_room_update; static uint64_t last_room_update = 0; @@ -213,6 +214,9 @@ int slmix_config(char *file) conf_get_str(conf, "mix_token_download", mix.token_download, sizeof(mix.token_download)); + conf_get_str(conf, "mix_stream_url", mix.stream_url, + sizeof(mix.stream_url)); + err = conf_get_str(conf, "mix_path", mix.path, sizeof(mix.path)); if (err) { if (!getcwd(mix.path, sizeof(mix.path))) {