diff --git a/app/src/recorder.c b/app/src/recorder.c index f71f6322..c52bbb4d 100644 --- a/app/src/recorder.c +++ b/app/src/recorder.c @@ -138,6 +138,10 @@ run_recorder(void *data) { int64_t pts_origin = AV_NOPTS_VALUE; + // We can write a packet only once we received the next one so that we can + // set its duration (next_pts - current_pts) + struct sc_record_packet *previous = NULL; + for (;;) { sc_mutex_lock(&recorder->mutex); @@ -150,7 +154,7 @@ run_recorder(void *data) { if (recorder->stopped && sc_queue_is_empty(&recorder->queue)) { sc_mutex_unlock(&recorder->mutex); - struct sc_record_packet *last = recorder->previous; + struct sc_record_packet *last = previous; if (last) { // assign an arbitrary duration to the last packet last->packet->duration = 100000; @@ -183,12 +187,9 @@ run_recorder(void *data) { rec->packet->dts = rec->packet->pts; } - // recorder->previous is only written from this thread, no need to lock - struct sc_record_packet *previous = recorder->previous; - recorder->previous = rec; - if (!previous) { // we just received the first packet + previous = rec; continue; } @@ -212,6 +213,8 @@ run_recorder(void *data) { sc_mutex_unlock(&recorder->mutex); break; } + + previous = rec; } if (!recorder->failed) { @@ -256,7 +259,6 @@ sc_recorder_open(struct sc_recorder *recorder, const AVCodec *input_codec) { recorder->stopped = false; recorder->failed = false; recorder->header_written = false; - recorder->previous = NULL; const char *format_name = sc_recorder_get_format_name(recorder->format); assert(format_name); diff --git a/app/src/recorder.h b/app/src/recorder.h index 373278e6..05d3857e 100644 --- a/app/src/recorder.h +++ b/app/src/recorder.h @@ -34,12 +34,6 @@ struct sc_recorder { bool stopped; // set on recorder_close() bool failed; // set on packet write failure struct sc_recorder_queue queue; - - // we can write a packet only once we received the next one so that we can - // set its duration (next_pts - current_pts) - // "previous" is only accessed from the recorder thread, so it does not - // need to be protected by the mutex - struct sc_record_packet *previous; }; bool