comparison libmpdemux/demux_mkv.c @ 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 9081ae3a702c
children 6ff3379a0862
comparison
equal deleted inserted replaced
16911:a3d705105e01 16912:4dea8b8f3b65
2777 * Example: The track with 25 FPS contains four frames with the timecodes 2777 * Example: The track with 25 FPS contains four frames with the timecodes
2778 * I at 0ms, P at 120ms, B at 40ms and B at 80ms. As soon as the next I 2778 * I at 0ms, P at 120ms, B at 40ms and B at 80ms. As soon as the next I
2779 * or P frame arrives these timecodes can be changed to I at 0ms, P at 40ms, 2779 * or P frame arrives these timecodes can be changed to I at 0ms, P at 40ms,
2780 * B at 80ms and B at 120ms. 2780 * B at 80ms and B at 120ms.
2781 * 2781 *
2782 * This works for simple H.264 B-frame pyramids, but not for arbitrary orders.
2783 *
2782 * \param demuxer The Matroska demuxer struct for this instance. 2784 * \param demuxer The Matroska demuxer struct for this instance.
2783 * \param track The track structure whose cache should be handled. 2785 * \param track The track structure whose cache should be handled.
2784 */ 2786 */
2785 static void 2787 static void
2786 flush_cached_dps (demuxer_t *demuxer, mkv_track_t *track) 2788 flush_cached_dps (demuxer_t *demuxer, mkv_track_t *track)
2787 { 2789 {
2788 float tmp_pts; 2790 int i, ok;
2789 int i;
2790 2791
2791 if (track->num_cached_dps == 0) 2792 if (track->num_cached_dps == 0)
2792 return; 2793 return;
2793 tmp_pts = track->cached_dps[0]->pts; 2794
2794 for (i = 1; i < track->num_cached_dps; i++) 2795 do {
2795 track->cached_dps[i - 1]->pts = track->cached_dps[i]->pts; 2796 ok = 1;
2796 track->cached_dps[track->num_cached_dps - 1]->pts = tmp_pts; 2797 for (i = 1; i < track->num_cached_dps; i++)
2798 if (track->cached_dps[i - 1]->pts > track->cached_dps[i]->pts) {
2799 float tmp_pts = track->cached_dps[i - 1]->pts;
2800 track->cached_dps[i - 1]->pts = track->cached_dps[i]->pts;
2801 track->cached_dps[i]->pts = tmp_pts;
2802 ok = 0;
2803 }
2804 } while (!ok);
2797 2805
2798 for (i = 0; i < track->num_cached_dps; i++) 2806 for (i = 0; i < track->num_cached_dps; i++)
2799 ds_add_packet (demuxer->video, track->cached_dps[i]); 2807 ds_add_packet (demuxer->video, track->cached_dps[i]);
2800 track->num_cached_dps = 0; 2808 track->num_cached_dps = 0;
2801 } 2809 }