Move last packet recording

Write the last packet at the end.
This commit is contained in:
Romain Vimont 2023-02-18 12:07:05 +01:00
parent 3c407773e9
commit 4b246cd963

View file

@ -220,19 +220,6 @@ sc_recorder_process_packets(struct sc_recorder *recorder) {
if (recorder->stopped && sc_queue_is_empty(&recorder->queue)) { if (recorder->stopped && sc_queue_is_empty(&recorder->queue)) {
sc_mutex_unlock(&recorder->mutex); 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; break;
} }
@ -283,6 +270,21 @@ sc_recorder_process_packets(struct sc_recorder *recorder) {
return false; 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); int ret = av_write_trailer(recorder->ctx);
if (ret < 0) { if (ret < 0) {
LOGE("Failed to write trailer to %s", recorder->filename); LOGE("Failed to write trailer to %s", recorder->filename);