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
pull/1678/head^2
Richard Fuchs 2 years ago
parent 3eb8ea716c
commit 6aed0506a7

@ -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();

@ -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;

@ -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);

@ -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) {

Loading…
Cancel
Save