David Engel <[EMAIL PROTECTED]> writes:

> That's the case.  If it can happen, it will happen.

*sigh*.  So on average you lose the count of one frame ever 18 minutes...

>> > I know ID::ReadWrite is a mess, but could you try to do a full fix for
>> > this?  If not, I'll try to get to it in the next couple of days.
>> 
>> What does a "full fix" imply?  I'm not even sure I know what it means.
>
> Adjusting the buffering to make sure the extra bytes will always be in
> the buffer when needed.

Perhaps something like the attached patch?  I think this will do the
proper buffering so it always has an "extra byte" at the end of the
buffer for the check.  A quick test-run with this change seems to work
okay.

-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 20:37:52 -0000
@@ -255,7 +255,9 @@
     unsigned char *bufptr = buf + start;
     unsigned int v = 0;
     
-    while (bufptr < buf + len)
+    // Don't consume the last byte in the buffer; we need an extra byte
+    // to test the picture start type.
+    while (bufptr < buf + len - 1)
     {
         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 byte
+        // so let's not lose the last byte when we shift the buffer.
+        vidscan = vidread - 1;
+        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