From a5b5b68a1a1a5453b9aa8025e3a95cc10d0718d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Andersson?= Date: Tue, 26 Jun 2018 19:16:28 +0200 Subject: [PATCH] VIDEO: Use all video PTS's Sometimes (only at the very start of a movie?) there will be a video packet that has a PTS but no frame to display. Save that PTS and use it for the next frame. This doesn't actually improve anything, as far as I can tell, but feels right. --- video/mpegps_decoder.cpp | 17 ++++++++++++----- video/mpegps_decoder.h | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/video/mpegps_decoder.cpp b/video/mpegps_decoder.cpp index ee71ce268d3..01db2b4e8ab 100644 --- a/video/mpegps_decoder.cpp +++ b/video/mpegps_decoder.cpp @@ -440,6 +440,7 @@ MPEGPSDecoder::MPEGVideoTrack::MPEGVideoTrack(Common::SeekableReadStream *firstP _surface = 0; _endOfTrack = false; _curFrame = -1; + _framePts = 0xFFFFFFFF; _nextFrameStartTime = Audio::Timestamp(0, 27000000); // 27 MHz timer findDimensions(firstPacket, format); @@ -481,21 +482,27 @@ const Graphics::Surface *MPEGPSDecoder::MPEGVideoTrack::decodeNextFrame() { bool MPEGPSDecoder::MPEGVideoTrack::sendPacket(Common::SeekableReadStream *packet, uint32 pts, uint32 dts) { #ifdef USE_MPEG2 + if (pts != 0xFFFFFFFF) { + _framePts = pts; + } + uint32 framePeriod; bool foundFrame = _mpegDecoder->decodePacket(*packet, framePeriod, _surface); if (foundFrame) { _curFrame++; - // If there is a presentation timestamp, use that for sync. Almost all - // packets with a presentation timestamp will have a found frame, so - // it is probably not worth the trouble worrying about when they don't. + // If there has been a timestamp since the previous frame, use that for + // syncing. Usually it will be the timestamp from the current packet, + // but it might not be. - if (pts != 0xFFFFFFFF) { - _nextFrameStartTime = Audio::Timestamp(pts / 90, 27000000); + if (_framePts != 0xFFFFFFFF) { + _nextFrameStartTime = Audio::Timestamp(_framePts / 90, 27000000); } else { _nextFrameStartTime = _nextFrameStartTime.addFrames(framePeriod); } + + _framePts = 0xFFFFFFFF; } #endif diff --git a/video/mpegps_decoder.h b/video/mpegps_decoder.h index 74167a714f9..6111fe8b453 100644 --- a/video/mpegps_decoder.h +++ b/video/mpegps_decoder.h @@ -100,6 +100,7 @@ private: private: bool _endOfTrack; int _curFrame; + uint32 _framePts; Audio::Timestamp _nextFrameStartTime; Graphics::Surface *_surface;