From f5219720f8917145cb2e0d9258b3233de1a6fb19 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 27 Nov 2013 20:54:56 +0100 Subject: video: refactor PTS code, add fall back heuristic to DTS Refactor the PTS handling code to make it cleaner, and to separate the bits that use PTS sorting. Add a heuristic to fall back to DTS if the PTS us non-monotonic. This code is based on what FFmpeg/Libav use for ffplay/avplay and also best_effort_timestamp (which is only in FFmpeg). Basically, this 1. just uses the DTS if PTS is unset, and 2. ignores PTS entirely if PTS is non- monotonic, but DTS is sorted. The code is pretty much the same as in Libav [1]. I'm not sure if all of it is really needed, or if it does more than what the paragraph above mentions. But maybe it's fine to cargo-cult this. This heuristic fixes playback of mpeg4 in ogm, which returns packets with PTS==DTS, even though the PTS timestamps should follow codec reordering. This is probably a libavformat demuxer bug, but good luck trying to fix it. The way vd_lavc.c returns the frame PTS and DTS to dec_video.c is a bit inelegant, but maybe better than trying to mess the PTS back into the decoder callback again. [1] https://git.libav.org/?p=libav.git;a=blob;f=cmdutils.c;h=3f1c667075724c5cde69d840ed5ed7d992898334;hb=fa515c2088e1d082d45741bbd5c05e13b0500804#l1431 --- video/decode/dec_video.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'video/decode/dec_video.h') diff --git a/video/decode/dec_video.h b/video/decode/dec_video.h index cb4724af33..9117fceefd 100644 --- a/video/decode/dec_video.h +++ b/video/decode/dec_video.h @@ -40,18 +40,31 @@ struct dec_video { char *decoder_desc; - void *priv; + void *priv; // for free use by vd_driver + // Last PTS from decoder (set with each vd_driver->decode() call) + double codec_pts; + int num_codec_pts_problems; + + // Last packet DTS from decoder (passed through from source packets) + double codec_dts; + int num_codec_dts_problems; + + // PTS sorting (obscure, non-default) double buffered_pts[32]; int num_buffered_pts; - double codec_reordered_pts; - double prev_codec_reordered_pts; - int num_reordered_pts_problems; double sorted_pts; - double prev_sorted_pts; int num_sorted_pts_problems; + double unsorted_pts; + int num_unsorted_pts_problems; int pts_assoc_mode; + // PTS or DTS of packet last read + double last_packet_pdts; + + // Final PTS of previously decoded image + double decoded_pts; + // PTS of the last decoded frame (often overwritten by player) double pts; @@ -60,7 +73,6 @@ struct dec_video { float fps; // FPS from demuxer or from user override float initial_decoder_aspect; - double last_packet_pdts; // State used only by player/video.c double last_pts; }; -- cgit v1.2.3