]> git.vomp.tv Git - vompclient-marten.git/commitdiff
Bug in audio seek code
authorMark Calderbank <mark@vomp.tv>
Wed, 24 May 2006 20:40:33 +0000 (20:40 +0000)
committerMark Calderbank <mark@vomp.tv>
Wed, 24 May 2006 20:40:33 +0000 (20:40 +0000)
demuxer.cc
demuxer.h
stream.h

index 89c41e4b019fc65deb64aa696fade95cdf2e57ce..e90d4f0bcb1b0037a1e3917799d723b9b4fa6102 100644 (file)
@@ -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 ) |
index ba643243c6e5764ed772d5636153a7ee26d26c1f..7487c3863fa572ee527fa9efa6b514c836ea45ab 100644 (file)
--- 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; }
index db7e80ccf4dbb087af2681e441216f165032ca0c..6d33cf0df339250be009ec2b704e1a5a412d0cc0 100644 (file)
--- 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;