From 740b191a47c70e725d3b088ff377bb332b009ec0 Mon Sep 17 00:00:00 2001 From: Mark Calderbank Date: Wed, 24 May 2006 20:40:33 +0000 Subject: [PATCH] Bug in audio seek code --- demuxer.cc | 25 ++++++++++++++++++------- demuxer.h | 6 +++--- stream.h | 6 +++--- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/demuxer.cc b/demuxer.cc index 89c41e4..e90d4f0 100644 --- a/demuxer.cc +++ b/demuxer.cc @@ -33,7 +33,7 @@ #define DEMUXER_SEQ_HEAD 0xB3010000 #endif - +#define SEEK_THRESHOLD 150000 // About 1.5 seconds const int Demuxer::FrameRates[9] = { 0, 23, 24, 25, 29, 30, 50, 59, 60 }; @@ -68,7 +68,8 @@ int Demuxer::init(Callback* tcallback, DrainTarget* audio, DrainTarget* video) if ( !videostream.init(video, demuxMemoryV) || !audiostream.init(audio, demuxMemoryA)) { - Log::getInstance()->log("Demuxer", Log::CRIT, "Failed to initialize demuxer"); + Log::getInstance()->log("Demuxer", Log::CRIT, + "Failed to initialize demuxer"); shutdown(); return 0; } @@ -128,7 +129,8 @@ void Demuxer::setAspectRatio(enum AspectRatio ar) { if (aspect_ratio != ar) { - Log::getInstance()->log("Demux", Log::DEBUG, "Aspect ratio difference signalled"); + Log::getInstance()->log("Demux", Log::DEBUG, + "Aspect ratio difference signalled"); if (++arcnt > 3) // avoid changing aspect ratio if glitch in signal { arcnt = 0; @@ -197,7 +199,7 @@ int Demuxer::PESPacket::submit(ULLONG cur_pos) #ifndef NEW_DEMUXER sent = dx->videostream.put(data+submitted, size-submitted); #else - sent = dx->videostream.put(data+submitted, size-submitted,cur_pos); + sent = dx->videostream.put(data+submitted, size-submitted,cur_pos); #endif else sent = size-submitted; @@ -234,13 +236,22 @@ void Demuxer::PESPacket::parseDetails() // Extract audio PTS if it exists if ( data[7] & 0x80 ) // PTS_DTS_flags indicate that PTS is present { - dx->audio_pts = ( (ULLONG)(data[9] & 0x0E) << 29 ) | + dx->audio_pts = ( (ULLONG)(data[9] & 0x0E) << 29 ) | ( (ULLONG)(data[10]) << 22 ) | ( (ULLONG)(data[11] & 0xFE) << 14 ) | ( (ULLONG)(data[12]) << 7 ) | ( (ULLONG)(data[13] & 0xFE) >> 1 ); + + // We continue to seek on the audio if the video PTS that we + // are trying to match is ahead of the audio PTS by at most + // SEEK_THRESHOLD. We consider the possibility of PTS wrap. if (dx->aud_seeking && !dx->vid_seeking && - dx->audio_pts >= dx->video_pts_seek) + !( (dx->video_pts_seek > dx->audio_pts && + dx->video_pts_seek - dx->audio_pts < SEEK_THRESHOLD) + || + (dx->video_pts_seek < dx->audio_pts && + dx->video_pts_seek + (1LL<<33) - + dx->audio_pts < SEEK_THRESHOLD) )) { dx->aud_seeking = 0; Log::getInstance()->log("Demuxer", Log::DEBUG, @@ -253,7 +264,7 @@ void Demuxer::PESPacket::parseDetails() // Extract video PTS if it exists if ( data[7] & 0x80 ) // PTS_DTS_flags indicate that PTS is present { - dx->video_pts = ( (ULLONG)(data[9] & 0x0E) << 29 ) | + dx->video_pts = ( (ULLONG)(data[9] & 0x0E) << 29 ) | ( (ULLONG)(data[10]) << 22 ) | ( (ULLONG)(data[11] & 0xFE) << 14 ) | ( (ULLONG)(data[12]) << 7 ) | diff --git a/demuxer.h b/demuxer.h index ba64324..7487c38 100644 --- a/demuxer.h +++ b/demuxer.h @@ -40,7 +40,7 @@ however, no code was copied verbatim. class Demuxer { -public: //MS Visual C++ need this, private does not work for DemuxerVDR, Marten +protected: class PESPacket { public: @@ -50,7 +50,7 @@ public: //MS Visual C++ need this, private does not work for DemuxerVDR, Marten #ifndef NEW_DEMUXER int submit(); #else - int submit(ULLONG cur_pos); + int submit(ULLONG cur_pos); #endif private: UCHAR data[0x10000]; @@ -81,7 +81,7 @@ public: //MS Visual C++ need this, private does not work for DemuxerVDR, Marten #ifndef NEW_DEMUXER virtual int put(UCHAR* buf, int len) = 0; #else - virtual int put(UCHAR* buf, int len,ULLONG cur_pos) = 0; + virtual int put(UCHAR* buf, int len,ULLONG cur_pos) = 0; #endif int getHorizontalSize() { return horizontal_size; } diff --git a/stream.h b/stream.h index db7e80c..6d33cf0 100644 --- a/stream.h +++ b/stream.h @@ -57,10 +57,10 @@ class Stream #ifndef WIN32 pthread_mutex_t mutex; #else - HANDLE mutex; + HANDLE mutex; #endif - void lock(); - void unLock(); + void lock(); + void unLock(); #endif DrainTarget* draintarget; -- 2.39.5