[FFmpeg-devel] [PATCH] png parser

Michael Niedermayer michaelni
Wed Jun 24 14:21:06 CEST 2009


On Tue, Jun 23, 2009 at 08:51:12AM +0200, Peter Holik wrote:
> Michael Niedermayer schrieb:
[...]

> +static int png_parse(AVCodecParserContext *s, AVCodecContext *avctx,
> +                     const uint8_t **poutbuf, int *poutbuf_size,
> +                     const uint8_t *buf, int buf_size)
> +{
> +    PNGParseContext *ppc = s->priv_data;
> +    uint32_t *state_ptr;
> +    int next = END_NOT_FOUND;
> +    int i = 0;
> +
> +    *poutbuf_size = 0;
> +    if (buf_size == 0)
> +        return 0;
> +
> +    if (!ppc->pc.frame_start_found) {
> +        uint64_t *state64_ptr = &ppc->pc.state64;
> +
> +        for (; i < buf_size; i++) {
> +            *state64_ptr = (*state64_ptr << 8) | buf[i];

using a local state64 likely is faster than the repeated pointer deref
i suspect gcc fails to do that optim itself ...


> +            if (*state64_ptr == PNGSIG || *state64_ptr == MNGSIG) {
> +                i++;
> +                if (ppc->pc.index) {
> +                    i -= 8;
> +                    next = i;
> +                } else {
> +                    ppc->pc.frame_start_found = 1;
> +                    ppc->chunk_index = 1;
> +                    if (i == 8)
> +                        break;
> +                    else if (i > 8) {
> +                        buf += i - 8;
> +                        buf_size = 8;
> +                    } else /* if (i < 8) */
> +                        buf_size = i;
> +                }
> +                ff_combine_frame(&ppc->pc, next, &buf, &buf_size);
> +                return i;

could you explain why this is not just looking like lets say mpeg4:

    if(!vop_found){
        for(i=0; i<buf_size; i++){
            state= (state<<8) | buf[i];
            if(state == 0x1B6){
                i++;
                vop_found=1;
                break;
            }
        }
    }

?
what is the point of all the special cases?

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090624/f09776cd/attachment.pgp>



More information about the ffmpeg-devel mailing list