rpicamsrc: Attempt to workaround MMAL timeout bug
authorJan Schmidt <thaytan@noraisin.net>
Mon, 16 Jul 2018 09:49:21 +0000 (19:49 +1000)
committerTim-Philipp Müller <tim@centricular.com>
Fri, 10 Jul 2020 15:46:33 +0000 (16:46 +0100)
mmal_queue_timedwait() might spuriously return immediately
if called at exactly the wrong instant due to an internal
off-by-one bug. Attempt to work around that and just retry.

sys/rpicamsrc/RaspiCapture.c

index 96c4692..975078f 100644 (file)
@@ -937,9 +937,16 @@ raspi_capture_fill_buffer(RASPIVID_STATE *state, GstBuffer **bufp,
   /* No timestamps if no clockm or invalid PTS */
   GstClockTime gst_pts = GST_CLOCK_TIME_NONE;
 
-  /* FIXME: Use our own interruptible cond wait: */
-
-  buffer = mmal_queue_timedwait(state->encoded_buffer_q, 500);
+  do {
+    buffer = mmal_queue_timedwait(state->encoded_buffer_q, 500);
+    // Work around a bug where mmal_queue_timedwait() might return
+    // immediately if the internal timeout time aligns exactly
+    // with a 1 second rollover boundary by checking errno.
+    if (errno == EINVAL) {
+      GST_WARNING ("Retrying mmal_queue_timedwait() due to spurious failure.");
+      continue;
+    }
+  } while (0);
 
   if (G_UNLIKELY(buffer == NULL)) {
       return GST_FLOW_ERROR_TIMEOUT;