Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: Nasty bug in StillPicture()



Stefan Huelswitt schrieb:
On 17 Oct 2003 Klaus Schmidinger <Klaus.Schmidinger@cadsoft.de> wrote:

Jut a few comments:

<snip>

                   while (offs < Length && len > 0 && Data[offs] == 0xFF) {
                         offs++;
                         len--;
                         }

This skips the stuffing bytes. I think mpeg2 can have stuffing
bytes too, so IMO this should be moved before the mpeg1/mpeg2
decision (before skip header extension).

Hm, are you sure? I haven't found it yet - maybe I'm misinterpreting the specs?

If the stuffing bytes are placed similarly for MPEG-1 and MPEG-2 streams, we should move the stuff accordingly.


                   if ((Data[offs] & 0xC0) == 0x40) {
                      offs += 2;
                      len -= 2;
                      }

                   if ((Data[offs] & 0xF0) == 0x20) {
                      offs += 5;
                      len -= 5;
                      }
                   else if ((Data[offs] & 0xF0) == 0x30) {
                      offs += 10;
                      len -= 10;
                      }
                   else if (Data[offs] == 0x0F) {
                      offs++;
                      len--;
                      }

This skips the PTS/DTS infos. To be prepared for faulty streams
the last "else if" should be a simple "else" (the indicator byte has
to be skipped in any case).

Right, good point. Have a look at the attached patch. It also avoids len<0 (faulty streams etc.).

Thomas
--- dvbdevice.c.orig	2003-09-06 15:19:33.000000000 +0200
+++ dvbdevice.c	2003-10-18 14:03:39.000000000 +0200
@@ -921,12 +921,36 @@
               int offs = i + 6;
               int len = Data[i + 4] * 256 + Data[i + 5];
               // skip header extension
-              if ((Data[i + 6] & 0xC0) == 0x80) {
+              if ((Data[i + 6] & 0xC0) == 0x80 && len >= Data[i + 8]) {
+                 // MPEG-2 PES header
                  offs += 3;
                  offs += Data[i + 8];
                  len -= 3;
                  len -= Data[i + 8];
                  }
+              else {
+                 // MPEG-1 PES header
+                 while (Data[offs] == 0xFF && len > 0) {
+                    offs++;
+                    len--;
+                    }
+                 if ((Data[offs] & 0xC0) == 0x40 && len >= 2) {
+                    offs += 2;
+                    len -= 2;
+                    }
+                 if ((Data[offs] & 0xF0) == 0x20 && len >= 5) {
+                    offs += 5;
+                    len -= 5;
+                    }
+                 else if ((Data[offs] & 0xF0) == 0x30 && len >= 10) {
+                    offs += 10;
+                    len -= 10;
+                    }
+                 else if (len > 0) {
+                    offs++;
+                    len--;
+                    }
+                 }
               memcpy(&buf[blen], &Data[offs], len);
               i = offs + len;
               blen += len;

Home | Main Index | Thread Index