From 4b246cd963ebe0cafa2fe2743e4f9b066dcec293 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sat, 18 Feb 2023 12:07:05 +0100 Subject: [PATCH] Move last packet recording Write the last packet at the end. --- app/src/recorder.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/app/src/recorder.c b/app/src/recorder.c index aa3aea0e..85f0fd2a 100644 --- a/app/src/recorder.c +++ b/app/src/recorder.c @@ -220,19 +220,6 @@ sc_recorder_process_packets(struct sc_recorder *recorder) { if (recorder->stopped && sc_queue_is_empty(&recorder->queue)) { sc_mutex_unlock(&recorder->mutex); - struct sc_record_packet *last = previous; - if (last) { - // assign an arbitrary duration to the last packet - last->packet->duration = 100000; - bool ok = sc_recorder_write(recorder, last->packet); - if (!ok) { - // failing to write the last frame is not very serious, no - // future frame may depend on it, so the resulting file - // will still be valid - LOGW("Could not record last packet"); - } - sc_record_packet_delete(last); - } break; } @@ -283,6 +270,21 @@ sc_recorder_process_packets(struct sc_recorder *recorder) { return false; } + // Write the last packet + struct sc_record_packet *last = previous; + if (last) { + // assign an arbitrary duration to the last packet + last->packet->duration = 100000; + bool ok = sc_recorder_write(recorder, last->packet); + if (!ok) { + // failing to write the last frame is not very serious, no + // future frame may depend on it, so the resulting file + // will still be valid + LOGW("Could not record last packet"); + } + sc_record_packet_delete(last); + } + int ret = av_write_trailer(recorder->ctx); if (ret < 0) { LOGE("Failed to write trailer to %s", recorder->filename);