Re: Ogg encapsulation

Glenn Randers-Pehrson <[email protected]> Thu, 01 Apr 2004 07:05:44 -0500
Newsgroups gmane.comp.graphics.mng.general
Message-ID <[email protected]>
At 11:50 AM 4/1/2004 +0200, you wrote:
> the alternative would be to add a 
>simple API function to set an internal flag whether or not to expect the CRC as 
>part of the data. It would still need the 4-byte length in the data-stream, as 
>that's the way the libmng-reader functions at the moment, but we'd get 
>around the double re-calculation of the CRC and save a lot of cpu.

It's really trivial to do this, two places in libmng_read.c, plus
adding the bIgnoreCRC member to pData, and a subroutine for setting
bIgnoreCRC (and function query-support for the new subroutine).  It
will save *some* cpu, not a lot, since crc is pretty
fast and getting much faster in zlib-1.2.1.  I've put code in pngcrush
to skip CRC calculation and it doesn't save much time, percentage wise.

            if (iRead != iBuflen)      /* did we get all the data ? */
              iRetcode = MNG_UNEXPECTEDEOF;
            else
            {
              mng_uint32 iL = iBuflen - (mng_uint32)(sizeof (iCrc));
                                       /* calculate the crc */
#ifdef MNG_IGNORE_CRC_SUPPORTED
              if (pData->bIgnoreCRC)
                iRetcode = process_raw_chunk (pData, pBuf, iL);
              else
              {
#endif
              iCrc = mng_crc (pData, pBuf, iL);
                                       /* and check it */
              if (!(iCrc == mng_get_uint32 (pBuf + iL)))
                iRetcode = MNG_INVALIDCRC;
              else
                iRetcode = process_raw_chunk (pData, pBuf, iL);
#ifdef MNG_IGNORE_CRC_SUPPORTED
              }
#endif

This code expects a dummy 4-byte CRC to be present, but Ogg could
omit it from Ogg/MNG files and supply a 4-byte zero on-the-fly while
decoding.

Having libmng receive length info from Ogg directly gets
complicated, so it would be best for Ogg to insert a length word into the
stream before handing it to libmng, if the length word is omitted from
Ogg/MNG files.

Glenn



--
Send the message body "help" to [email protected]