From 6aed0506a7d1841c41ee889ebaa62c5bd73e041e Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Sun, 11 Jun 2023 12:04:26 -0400 Subject: [PATCH] MT#55283 generalise output_new Adopt the logic for flexible output names from single output files also for mixed output files. Refactor both code paths into a single shared function. Updates #1667 Change-Id: I8ff4ea0a169dc39ae384e9c1e601ceded325d5df --- recording-daemon/metafile.c | 2 +- recording-daemon/output.c | 28 ++++++++++++++++++++++++++-- recording-daemon/output.h | 3 +-- recording-daemon/packet.c | 27 ++++----------------------- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/recording-daemon/metafile.c b/recording-daemon/metafile.c index 48fe4007a..1262632d6 100644 --- a/recording-daemon/metafile.c +++ b/recording-daemon/metafile.c @@ -88,7 +88,7 @@ static void meta_stream_interface(metafile_t *mf, unsigned long snum, char *cont if (output_enabled && output_mixed && mf->recording_on) { pthread_mutex_lock(&mf->mix_lock); if (!mf->mix) { - mf->mix_out = output_new(output_dir, mf->parent, "mix", "mixed", "mix"); + mf->mix_out = output_new_ext(mf, "mix", "mixed", "mix"); if (mix_method == MM_CHANNELS) mf->mix_out->channel_mult = mix_num_inputs; mf->mix = mix_new(); diff --git a/recording-daemon/output.c b/recording-daemon/output.c index 4fa115375..bdff466eb 100644 --- a/recording-daemon/output.c +++ b/recording-daemon/output.c @@ -100,7 +100,9 @@ static output_t *output_alloc(const char *path, const char *name) { return ret; } -output_t *output_new(const char *path, const char *call, const char *type, const char *kind, const char *label) { +static output_t *output_new(const char *path, const char *call, const char *type, const char *kind, + const char *label) +{ // construct output file name struct timeval now; struct tm tm; @@ -189,7 +191,7 @@ done:; return ret; } -output_t *output_new_from_full_path(const char *path, char *name, const char *kind) { +static output_t *output_new_from_full_path(const char *path, char *name, const char *kind) { output_t *ret = output_alloc(path, name); create_parent_dirs(ret->full_filename); ret->kind = kind; @@ -197,6 +199,28 @@ output_t *output_new_from_full_path(const char *path, char *name, const char *ki return ret; } +output_t *output_new_ext(metafile_t *mf, const char *type, const char *kind, const char *label) { + output_t *ret; + dbg("Metadata %s, output destination %s", mf->metadata, mf->output_dest); + if (mf->output_dest) { + char *path = g_strdup(mf->output_dest); + char *sep = strrchr(path, '/'); + if (sep) { + char *filename = sep + 1; + *sep = 0; + ret = output_new_from_full_path(path, filename, kind); + ret->skip_filename_extension = TRUE; + } + else + ret = output_new_from_full_path(output_dir, path, kind); + g_free(path); + } + else + ret = output_new(output_dir, mf->parent, type, kind, label); + + return ret; +} + int output_config(output_t *output, const format_t *requested_format, format_t *actual_format) { const char *err; int av_ret = 0; diff --git a/recording-daemon/output.h b/recording-daemon/output.h index c4af6cf79..28d39f2ed 100644 --- a/recording-daemon/output.h +++ b/recording-daemon/output.h @@ -10,8 +10,7 @@ extern int mp3_bitrate; void output_init(const char *format); -output_t *output_new(const char *path, const char *call, const char *type, const char *kind, const char *label); -output_t *output_new_from_full_path(const char *path, char *name, const char *kind); +output_t *output_new_ext(metafile_t *, const char *type, const char *kind, const char *label); void output_close(metafile_t *, output_t *, tag_t *, bool discard); int output_config(output_t *output, const format_t *requested_format, format_t *actual_format); diff --git a/recording-daemon/packet.c b/recording-daemon/packet.c index a0a28557e..57d2e034f 100644 --- a/recording-daemon/packet.c +++ b/recording-daemon/packet.c @@ -235,29 +235,10 @@ 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) { - dbg("Metadata %s, output destination %s", mf->metadata, mf->output_dest); - if (mf->output_dest) { - char path[PATH_MAX]; - size_t copied = g_strlcpy(path, mf->output_dest, sizeof(path)); - if (G_UNLIKELY(copied >= sizeof(path))) - ilog(LOG_ERR, "Output file path truncated: %s", mf->output_dest); - char *sep = strrchr(path, '/'); - if (sep) { - char *filename = sep + 1; - *sep = 0; - ret->output = output_new_from_full_path(path, filename, "single"); - ret->output->skip_filename_extension = TRUE; - } - else { - ret->output = output_new_from_full_path(output_dir, path, "single"); - } - } - else { - char buf[16]; - snprintf(buf, sizeof(buf), "%08lx", ssrc); - tag_t *tag = tag_get(mf, stream->tag); - ret->output = output_new(output_dir, mf->parent, buf, "single", tag->label); - } + char buf[16]; + snprintf(buf, sizeof(buf), "%08lx", ssrc); + tag_t *tag = tag_get(mf, stream->tag); + ret->output = output_new_ext(mf, buf, "single", tag->label); db_do_stream(mf, ret->output, stream, ssrc); } if ((stream->forwarding_on || mf->forwarding_on) && !ret->tls_fwd_stream && tls_send_to_ep.port) {