[rbp/omxplayer] Fix bugs with jpeg parsing
authorpopcornmix <popcornmix@gmail.com>
Sat, 21 Sep 2013 20:30:04 +0000 (21:30 +0100)
committerpopcornmix <popcornmix@gmail.com>
Sun, 6 Oct 2013 17:52:33 +0000 (18:52 +0100)
I was finding GetCodingType to sometimes take 200ms for a single jpeg.
That was a mixture of the slow bit oriented parsing, but more significantly some bugs in the parsing.

The SOF blocks skipped the wrong number of bytes, resulting in us parsing junk.
The M_TEM, M_DRI, M_SOI and M_EOI tags when seen (usually due to the junk) can only escape by slowly parsing until end of file.
Also, after a M_SOS, there is the variable sized jpeg block which we can't parse, so best to give up then, rather than misparsing
the remaining jpeg data

xbmc/cores/omxplayer/OMXImage.cpp

index 50b093d..5a98a97 100644 (file)
@@ -250,15 +250,6 @@ OMX_IMAGE_CODINGTYPE COMXImage::GetCodingType()
     {
       switch(marker)
       {
-        case M_TEM:
-        case M_DRI:
-          CBitstreamConverter::skip_bits(&br, 16);
-          continue;
-        case M_SOI:
-        case M_EOI:
-          continue;
-        
-        case M_SOS:
         case M_DQT:
         case M_DNL:
         case M_DHP:
@@ -321,6 +312,7 @@ OMX_IMAGE_CODINGTYPE COMXImage::GetCodingType()
           nMarker = true;
           break;
 
+        case M_SOS:
         default:
           nMarker = false;
           break;
@@ -337,10 +329,14 @@ OMX_IMAGE_CODINGTYPE COMXImage::GetCodingType()
         {
           m_progressive = true;
         }
+        int readBits = 2;
         SKIPN(p, 1);
+        readBits ++;
         m_omx_image.nFrameHeight = READ16(p);
+        readBits += 2;
         m_omx_image.nFrameWidth = READ16(p);
-        SKIPN(p, 1 * (block_size - 9));
+        readBits += 2;
+        SKIPN(p, 1 * (block_size - readBits));
       }
       else if(marker == M_APP1)
       {