From e4630eb53c5586b977f2ee20993b569fa006a7d4 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 3 Jan 2024 13:55:37 -0500 Subject: [PATCH] MT#59069 add option to override rec file pattern Change-Id: Ibcdd09d3913b3f9e13e74082b5618815e05dc740 --- daemon/call_interfaces.c | 6 ++++++ daemon/recording.c | 2 ++ daemon/redis.c | 4 ++++ docs/ng_control_protocol.md | 10 ++++++++-- include/call.h | 1 + include/call_interfaces.h | 1 + recording-daemon/metafile.c | 2 ++ recording-daemon/output.c | 4 +++- recording-daemon/types.h | 1 + 9 files changed, 28 insertions(+), 3 deletions(-) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 7c2ac05c8..9a8de2da8 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -1779,6 +1779,12 @@ static void call_ng_main_flags(sdp_ng_flags *out, str *key, bencode_item_t *valu case CSH_LOOKUP("output-folder"): out->recording_path = s; break; + case CSH_LOOKUP("recording pattern"): + case CSH_LOOKUP("recording-pattern"): + case CSH_LOOKUP("output pattern"): + case CSH_LOOKUP("output-pattern"): + out->recording_pattern = s; + break; case CSH_LOOKUP("repeat-times"): out->repeat_times = bencode_get_integer_str(value, out->repeat_times); break; diff --git a/daemon/recording.c b/daemon/recording.c index 996349fcf..5bb642672 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -290,6 +290,8 @@ void update_metadata_call(call_t *call, const sdp_ng_flags *flags) { update_call_field(call, &call->metadata, flags ? &flags->metadata : NULL, "METADATA"); update_call_field(call, &call->recording_file, flags ? &flags->recording_file : NULL, "RECORDING_FILE"); update_call_field(call, &call->recording_path, flags ? &flags->recording_path : NULL, "RECORDING_PATH"); + update_call_field(call, &call->recording_pattern, flags ? &flags->recording_pattern : NULL, + "RECORDING_PATTERN"); } // lock must be held diff --git a/daemon/redis.c b/daemon/redis.c index efe618d56..194d46e9c 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -2083,6 +2083,8 @@ static void json_restore_call(struct redis *r, const str *callid, bool foreign) call_str_cpy(c, &c->recording_file, &s); redis_hash_get_str(&s, &call, "recording_path"); call_str_cpy(c, &c->recording_path, &s); + redis_hash_get_str(&s, &call, "recording_pattern"); + call_str_cpy(c, &c->recording_pattern, &s); recording_start(c); } @@ -2376,6 +2378,8 @@ char* redis_encode_json(call_t *c) { JSON_SET_SIMPLE_STR("recording_file", &c->recording_file); if (c->recording_path.len) JSON_SET_SIMPLE_STR("recording_path", &c->recording_path); + if (c->recording_pattern.len) + JSON_SET_SIMPLE_STR("recording_pattern", &c->recording_pattern); } json_builder_end_object(builder); diff --git a/docs/ng_control_protocol.md b/docs/ng_control_protocol.md index 4c6489111..aa3f31461 100644 --- a/docs/ng_control_protocol.md +++ b/docs/ng_control_protocol.md @@ -1749,8 +1749,14 @@ option of the recording daemon. The value should refer to an existing directory given as an absolute path. Setting this key does not affect the names of the files that will be created in the directory. -If both `recording-file` and `recording-dir` are set, then `recording-file` -takes precedence. +If the optional `recording-pattern` key is set, then its value will be used as +the pattern to generate the output file name(s), overriding the +`output-pattern` config option of the recording daemon. Note that no validity +checking is performed on the given string, so make sure that the given pattern +does not yield duplicate file names. + +The option `recording-file` takes precedence over both `recording-dir` and +`recording-pattern` if multiple options are set. ## `stop recording` Message diff --git a/include/call.h b/include/call.h index 9b9e65a9a..8322e2fce 100644 --- a/include/call.h +++ b/include/call.h @@ -709,6 +709,7 @@ struct call { str recording_file; str recording_random_tag; str recording_path; + str recording_pattern; struct call_iterator_entry iterator[NUM_CALL_ITERATORS]; int cpu_affinity; diff --git a/include/call_interfaces.h b/include/call_interfaces.h index c1dc0275f..b3daed48f 100644 --- a/include/call_interfaces.h +++ b/include/call_interfaces.h @@ -36,6 +36,7 @@ struct sdp_ng_flags { str record_call_str; str recording_file; str recording_path; + str recording_pattern; str metadata; str label; str set_label; diff --git a/recording-daemon/metafile.c b/recording-daemon/metafile.c index d0dd3efb5..bed0f666c 100644 --- a/recording-daemon/metafile.c +++ b/recording-daemon/metafile.c @@ -222,6 +222,8 @@ static void meta_section(metafile_t *mf, char *section, char *content, unsigned mf->output_dest = g_string_chunk_insert(mf->gsc, content); else if (!strcmp(section, "RECORDING_PATH")) mf->output_path = g_string_chunk_insert(mf->gsc, content); + else if (!strcmp(section, "RECORDING_PATTERN")) + mf->output_pattern = g_string_chunk_insert(mf->gsc, content); } diff --git a/recording-daemon/output.c b/recording-daemon/output.c index adfce13db..11a3e6049 100644 --- a/recording-daemon/output.c +++ b/recording-daemon/output.c @@ -113,7 +113,9 @@ static output_t *output_new(const char *path, const metafile_t *mf, const char * localtime_r(&now.tv_sec, &tm); g_autoptr(GString) f = g_string_new(""); - for (const char *p = output_pattern; *p; p++) { + const char *pattern = mf->output_pattern ?: output_pattern; + + for (const char *p = pattern; *p; p++) { if (*p != '%') { g_string_append_c(f, *p); continue; diff --git a/recording-daemon/types.h b/recording-daemon/types.h index 5227d9d9d..b50fc7e6e 100644 --- a/recording-daemon/types.h +++ b/recording-daemon/types.h @@ -118,6 +118,7 @@ struct metafile_s { char *metadata_db; char *output_dest; char *output_path; + char *output_pattern; off_t pos; unsigned long long db_id; unsigned int db_streams;