David Engel <[EMAIL PROTECTED]> writes:

>> *sigh*.  So on average you lose the count of one frame ever 18 minutes...
>
> I know, but it's still a bug!

True, but it's much lesser of an evil than the current code.  The
current code is nearly unusable watching LiveTV.  But eh, I don't have
commit access.

>> Perhaps something like the attached patch?  I think this will do the
>
> Yes, like that, but I think you need to allow for a 2-byte pad.
> bufptr is incremented before we access bufptr[1], so it's actually the
> second byte after the end of buffer check.

picky picky picky.  Here's another version with some updated comments.

-derek

Index: libs/libmythtv/ivtvdecoder.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/ivtvdecoder.cpp,v
retrieving revision 1.36
diff -u -r1.36 ivtvdecoder.cpp
--- libs/libmythtv/ivtvdecoder.cpp	29 Jan 2005 00:06:57 -0000	1.36
+++ libs/libmythtv/ivtvdecoder.cpp	16 Feb 2005 21:38:37 -0000
@@ -255,7 +255,9 @@
     unsigned char *bufptr = buf + start;
     unsigned int v = 0;
     
-    while (bufptr < buf + len)
+    // Don't consume the last two bytes in the buffer; we need thos extra bytes
+    // to test the picture start type.
+    while (bufptr < buf + len - 2)
     {
         v = *bufptr++;
 
@@ -337,8 +339,10 @@
                 }
                 case PICTURE_START:
                 {
-                    //int type = (bufptr[1] >> 3) & 7;
-                    //if (type >= 1 && type <= 3)
+                    // Make sure this is a real picture.  Otherwise we could
+                    // lose time sync and cause all sorts of WAF issues.
+                    int type = (bufptr[1] >> 3) & 7;
+                    if (type >= 1 && type <= 3)
                     {
                         framesScanned++;
                         if (exitafterdecoded)
@@ -450,15 +454,17 @@
     }
     else
     {
-        vidscan = vidread;
-        if (vidread - vidwrite > 3)
+        // MpegPreProcessPkt checks up to (but not including) the last two bytes
+        // so let's not lose those last bytes when we shift the buffer.
+        vidscan = vidread - 2;
+        if (vidscan - vidwrite > 3)
         {
-            vid2write = vidread - 3 - vidwrite;
+            vid2write = vidscan - 3 - vidwrite;
             videndofframe = 0;
         }
         else
         {
-            vid2write = vidread - vidwrite;
+            vid2write = vidscan - vidwrite;
             videndofframe = 1;
         }
     }
-- 
       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       [EMAIL PROTECTED]                        PGP key available
_______________________________________________
mythtv-dev mailing list
[email protected]
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev

Reply via email to