Browse Source

deps/media-playback: Handle discontinuities to fix video stalls

If there is a PTS discontinuity in the playback stream that causes the PTS to
reset, it is likely that new audio frames will come in while there are still
video frames waiting to be dequeued. This will cause the audio frames to be
played while the video frames wait for the PTS to get back up to where they
were before the discontinuity.
Eric Lindvall 4 years ago
parent
commit
ef34a5f765
1 changed files with 5 additions and 1 deletions
  1. 5 1
      deps/media-playback/media-playback/media.c

+ 5 - 1
deps/media-playback/media-playback/media.c

@@ -301,9 +301,13 @@ static inline int64_t mp_media_get_base_pts(mp_media_t *m)
 	return base_ts;
 }
 
+/* maximum timestamp variance in nanoseconds */
+#define MAX_TS_VAR 2000000000LL
+
 static inline bool mp_media_can_play_frame(mp_media_t *m, struct mp_decode *d)
 {
-	return d->frame_ready && d->frame_pts <= m->next_pts_ns;
+	return d->frame_ready && (d->frame_pts <= m->next_pts_ns ||
+				  (d->frame_pts - m->next_pts_ns > MAX_TS_VAR));
 }
 
 static void mp_media_next_audio(mp_media_t *m)