changeset 16912:4dea8b8f3b65

sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
author lorenm
date Sat, 05 Nov 2005 04:56:23 +0000
parents a3d705105e01
children 57610089c932
files libmpdemux/demux_mkv.c
diffstat 1 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_mkv.c	Sat Nov 05 01:27:38 2005 +0000
+++ b/libmpdemux/demux_mkv.c	Sat Nov 05 04:56:23 2005 +0000
@@ -2779,21 +2779,29 @@
  * or P frame arrives these timecodes can be changed to I at 0ms, P at 40ms,
  * B at 80ms and B at 120ms.
  *
+ * This works for simple H.264 B-frame pyramids, but not for arbitrary orders.
+ *
  * \param demuxer The Matroska demuxer struct for this instance.
  * \param track The track structure whose cache should be handled.
  */
 static void
 flush_cached_dps (demuxer_t *demuxer, mkv_track_t *track)
 {
-  float tmp_pts;
-  int i;
+  int i, ok;
 
   if (track->num_cached_dps == 0)
     return;
-  tmp_pts = track->cached_dps[0]->pts;
-  for (i = 1; i < track->num_cached_dps; i++)
-    track->cached_dps[i - 1]->pts = track->cached_dps[i]->pts;
-  track->cached_dps[track->num_cached_dps - 1]->pts = tmp_pts;
+
+  do {
+    ok = 1;
+    for (i = 1; i < track->num_cached_dps; i++)
+      if (track->cached_dps[i - 1]->pts > track->cached_dps[i]->pts) {
+        float tmp_pts = track->cached_dps[i - 1]->pts;
+        track->cached_dps[i - 1]->pts = track->cached_dps[i]->pts;
+        track->cached_dps[i]->pts = tmp_pts;
+        ok = 0;
+      }
+  } while (!ok);
 
   for (i = 0; i < track->num_cached_dps; i++)
     ds_add_packet (demuxer->video, track->cached_dps[i]);