Skip to content

Commit

Permalink
video_export: increment number frame index first
Browse files Browse the repository at this point in the history
Actually the value+1 (so 1 for first frame) is can be incremented
directly, this also removes the need to increment it in failed paths.
Here the behavior has been inconsistent, because if queue was full,
the index was incremented but on incompatible description it wasn't.
Now it is always incremented.
  • Loading branch information
MartinPulec committed Feb 19, 2024
1 parent 3efd418 commit af19124
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/video_export.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Martin Pulec <[email protected]>
*/
/*
* Copyright (c) 2012-2016 CESNET, z. s. p. o.
* Copyright (c) 2012-2024 CESNET, z. s. p. o.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -214,6 +214,7 @@ void video_export(struct video_export *s, struct video_frame *frame)
}

assert(frame != NULL);
s->total += 1;

if(s->saved_desc.width == 0) {
s->saved_desc = video_desc_from_frame(frame);
Expand All @@ -235,10 +236,14 @@ void video_export(struct video_export *s, struct video_frame *frame)
entry->next = NULL;

if(frame->tile_count == 1) {
snprintf(entry->filename, 512, "%s/%08d.%s", s->path, s->total + 1, get_codec_file_extension(frame->color_spec));
snprintf(entry->filename, 512, "%s/%08d.%s", s->path,
s->total,
get_codec_file_extension(frame->color_spec));
} else {
// add also tile index
snprintf(entry->filename, 512, "%s/%08d_%d.%s", s->path, s->total + 1, i, get_codec_file_extension(frame->color_spec));
snprintf(entry->filename, 512, "%s/%08d_%d.%s", s->path,
s->total, i,
get_codec_file_extension(frame->color_spec));
}
memcpy(entry->data, frame->tiles[i].data, entry->data_len);

Expand All @@ -248,7 +253,7 @@ void video_export(struct video_export *s, struct video_frame *frame)
if(s->queue_len >= MAX_QUEUE_SIZE) {
fprintf(stderr, "[Video export] Maximal queue size (%d) exceeded, not saving frame %d.\n",
MAX_QUEUE_SIZE,
s->total++); // we increment total size to keep the index
s->total); // we increment total size to keep the index
pthread_mutex_unlock(&s->lock);
free(entry->data);
free(entry);
Expand All @@ -267,7 +272,5 @@ void video_export(struct video_export *s, struct video_frame *frame)

platform_sem_post(&s->semaphore);
}

s->total += 1;
}

0 comments on commit af19124

Please sign in to comment.