Implement support for seting an output file and folder per recording.

pull/1278/head
Damir Nedžibović 4 years ago
parent 94a5feea7d
commit 11128bff49

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

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

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

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

Loading…
Cancel
Save