From 11128bff4966af64caec995c8084985e6a476552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Ned=C5=BEibovi=C4=87?= Date: Wed, 9 Jun 2021 13:19:10 +0200 Subject: [PATCH] Implement support for seting an output file and folder per recording. --- recording-daemon/metafile.c | 22 ++++++++++++++++++++++ recording-daemon/output.c | 1 + recording-daemon/packet.c | 24 ++++++++++++++++++++---- recording-daemon/types.h | 2 ++ 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/recording-daemon/metafile.c b/recording-daemon/metafile.c index 86e570753..43346be55 100644 --- a/recording-daemon/metafile.c +++ b/recording-daemon/metafile.c @@ -149,11 +149,33 @@ static void meta_ptime(metafile_t *mf, unsigned long mnum, int ptime) mf->media_ptimes[mnum] = ptime; } +static char *get_output_path(metafile_t *mf) { + char *res = NULL; + str all_meta; + str_init(&all_meta, mf->metadata); + while (all_meta.len > 1) { + str token; + if (str_token_sep(&token, &all_meta, '|')) + break; + str key; + if (str_token(&key, &token, ':')) { + // key:value separator not found, skip + continue; + } + if (strncmp(key.s, "output-dir", 10) >= 0) { + ilog(LOG_INFO, "Metadata output-dir found token=%s", token.s); + res = token.s; + break; + } + } + return res; +} // mf is locked static void meta_metadata(metafile_t *mf, char *content) { mf->metadata = g_string_chunk_insert(mf->gsc, content); mf->metadata_db = mf->metadata; + mf->output_dest = get_output_path(mf); db_do_call(mf); if (forward_to) start_forwarding_capture(mf, content); diff --git a/recording-daemon/output.c b/recording-daemon/output.c index 166c09e89..f3f1933b4 100644 --- a/recording-daemon/output.c +++ b/recording-daemon/output.c @@ -241,6 +241,7 @@ int output_config(output_t *output, const format_t *requested_format, format_t * full_fn = g_strdup_printf("%s%s.%s", output->full_filename, suff, output->file_format); if (!g_file_test(full_fn, G_FILE_TEST_EXISTS)) goto got_fn; + ilog(LOG_INFO, "Storing record in %s", full_fn); snprintf(suff, sizeof(suff), "-%i", i); g_free(full_fn); } diff --git a/recording-daemon/packet.c b/recording-daemon/packet.c index 9ba50901f..88c879f21 100644 --- a/recording-daemon/packet.c +++ b/recording-daemon/packet.c @@ -152,7 +152,6 @@ void ssrc_free(void *p) { g_slice_free1(sizeof(*s), s); } - // mf must be unlocked; returns ssrc locked static ssrc_t *ssrc_get(stream_t *stream, unsigned long ssrc) { metafile_t *mf = stream->metafile; @@ -177,9 +176,26 @@ out: dbg("Init for SSRC %s%lx%s of stream #%lu", FMT_M(ret->ssrc), stream->id); if (mf->recording_on && !ret->output && output_single) { - char buf[16]; - snprintf(buf, sizeof(buf), "%08lx", ssrc); - ret->output = output_new(output_dir, mf->parent, buf); + ilog(LOG_INFO, "Metadata %s and output %s", mf->metadata, mf->output_dest); + if (mf->output_dest) { + char path[256]; + strncpy(path, mf->output_dest, sizeof(path)); + char *sep = strrchr(path, '/'); + if (sep) { + char *filename = sep + 1; + *sep = 0; + ret->output = output_new(path, mf->parent, filename); + ret->output->skip_filename_extension = TRUE; + } + else { + ret->output = output_new(output_dir, mf->parent, path); + } + } + else { + char buf[16]; + snprintf(buf, sizeof(buf), "%08lx", ssrc); + ret->output = output_new(output_dir, mf->parent, buf); + } db_do_stream(mf, ret->output, "single", stream, ssrc); } if ((stream->forwarding_on || mf->forwarding_on) && !ret->tls_fwd_stream) { diff --git a/recording-daemon/types.h b/recording-daemon/types.h index 9fa6ab0f4..b4e8c09a5 100644 --- a/recording-daemon/types.h +++ b/recording-daemon/types.h @@ -111,6 +111,7 @@ struct metafile_s { char *call_id; char *metadata; char *metadata_db; + char *output_dest; off_t pos; unsigned long long db_id; @@ -146,6 +147,7 @@ struct output_s { *filename; // path + filename + suffix const char *file_format; unsigned long long db_id; + gboolean skip_filename_extension; unsigned int channel_mult; AVFormatContext *fmtctx;