Browse Source

TT#111357 switch to dynamically allocated strings for file names

Change-Id: I3299ffb10083dc8390ca60d810d1359f77215737
pull/1218/head
Richard Fuchs 5 years ago
parent
commit
7c25d39f70
2 changed files with 15 additions and 10 deletions
  1. +11
    -6
      recording-daemon/output.c
  2. +4
    -4
      recording-daemon/types.h

+ 11
- 6
recording-daemon/output.c View File

@ -48,9 +48,9 @@ int output_add(output_t *output, AVFrame *frame) {
output_t *output_new(const char *path, const char *filename) { output_t *output_new(const char *path, const char *filename) {
output_t *ret = g_slice_alloc0(sizeof(*ret)); output_t *ret = g_slice_alloc0(sizeof(*ret));
g_strlcpy(ret->file_path, path, sizeof(ret->file_path));
g_strlcpy(ret->file_name, filename, sizeof(ret->file_name));
snprintf(ret->full_filename, sizeof(ret->full_filename), "%s/%s", path, filename);
ret->file_path = g_strdup(path);
ret->file_name = g_strdup(filename);
ret->full_filename = g_strdup_printf("%s/%s", path, filename);
ret->file_format = output_file_format; ret->file_format = output_file_format;
ret->encoder = encoder_new(); ret->encoder = encoder_new();
return ret; return ret;
@ -101,20 +101,21 @@ int output_config(output_t *output, const format_t *requested_format, format_t *
avcodec_parameters_from_context(output->avst->codecpar, output->encoder->u.avc.avcctx); avcodec_parameters_from_context(output->avst->codecpar, output->encoder->u.avc.avcctx);
#endif #endif
char full_fn[PATH_MAX*2];
char *full_fn = NULL;
char suff[16] = ""; char suff[16] = "";
for (int i = 1; i < 20; i++) { for (int i = 1; i < 20; i++) {
snprintf(full_fn, sizeof(full_fn), "%s%s.%s", output->full_filename, suff, output->file_format);
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)) if (!g_file_test(full_fn, G_FILE_TEST_EXISTS))
goto got_fn; goto got_fn;
snprintf(suff, sizeof(suff), "-%i", i); snprintf(suff, sizeof(suff), "-%i", i);
g_free(full_fn);
} }
err = "failed to find unused output file number"; err = "failed to find unused output file number";
goto err; goto err;
got_fn: got_fn:
g_strlcpy(output->filename, full_fn, sizeof(output->filename));
output->filename = full_fn;
err = "failed to open avio"; err = "failed to open avio";
av_ret = avio_open(&output->fmtctx->pb, full_fn, AVIO_FLAG_WRITE); av_ret = avio_open(&output->fmtctx->pb, full_fn, AVIO_FLAG_WRITE);
if (av_ret < 0) if (av_ret < 0)
@ -168,6 +169,10 @@ static int output_shutdown(output_t *output) {
output->fmtctx = NULL; output->fmtctx = NULL;
output->avst = NULL; output->avst = NULL;
g_clear_pointer(&output->full_filename, g_free);
g_clear_pointer(&output->file_path, g_free);
g_clear_pointer(&output->file_name, g_free);
g_clear_pointer(&output->filename, g_free);
return ret; return ret;
} }


+ 4
- 4
recording-daemon/types.h View File

@ -140,10 +140,10 @@ struct metafile_s {
struct output_s { struct output_s {
char full_filename[PATH_MAX], // path + filename
file_path[PATH_MAX],
file_name[PATH_MAX],
filename[PATH_MAX * 2]; // path + filename + suffix
char *full_filename, // path + filename
*file_path,
*file_name,
*filename; // path + filename + suffix
const char *file_format; const char *file_format;
unsigned long long db_id; unsigned long long db_id;


Loading…
Cancel
Save