Skip to content

Display and control your Android device

Fix possible race condition on video_buffer end

Romain Vimonta3703340fc5f
diff --git a/app/src/video_buffer.c b/app/src/video_buffer.c
index b3b29098..a8f7f20a 100644
--- a/app/src/video_buffer.c
+++ b/app/src/video_buffer.c
@@ -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);