Fix possible race condition on video_buffer end

The video_buffer thread clears the queue once it is stopped, but new
frames might still be pushed asynchronously.

To avoid the problem, do not push any frame once the video_buffer is
stopped.
This commit is contained in:
Romain Vimont 2023-03-01 18:24:31 +01:00
parent 6f38c6311b
commit a3703340fc

View file

@ -99,6 +99,8 @@ run_buffering(void *data) {
}
stopped:
assert(vb->b.stopped);
// Flush queue
while (!sc_vecdeque_is_empty(&vb->b.queue)) {
struct sc_video_buffer_frame *p = sc_vecdeque_popref(&vb->b.queue);
@ -206,6 +208,11 @@ sc_video_buffer_push(struct sc_video_buffer *vb, const AVFrame *frame) {
sc_mutex_lock(&vb->b.mutex);
if (vb->b.stopped) {
sc_mutex_unlock(&vb->b.mutex);
return false;
}
sc_tick pts = SC_TICK_FROM_US(frame->pts);
sc_clock_update(&vb->b.clock, sc_tick_now(), pts);
sc_cond_signal(&vb->b.wait_cond);