printf("lost c frame %d\n", f->cfrm[i].id);
av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n", f->cfrm[i].id);
static int decode_frame(AVCodecContext *avctx,                         void *data, int *data_size,                        uint8_t *buf, int buf_size){    FourXContext * const f = avctx->priv_data;    AVFrame *picture = data;    AVFrame *p, temp;    int i, frame_4cc, frame_size;    *data_size = 0;    /* special case for last picture */    if (buf_size == 0) {        return 0;    }    frame_4cc= get32(buf);    if(buf_size != get32(buf+4)+8){        fprintf(stderr, "size missmatch %d %d\n", buf_size, get32(buf+4));    }    if(frame_4cc == ff_get_fourcc("cfrm")){        int free_index=-1;        const int data_size= buf_size - 20;        const int id= get32(buf+12);        const int whole_size= get32(buf+16);        CFrameBuffer *cfrm;        for(i=0; i<CFRAME_BUFFER_COUNT; i++){            if(f->cfrm[i].id && f->cfrm[i].id < avctx->frame_number)                printf("lost c frame %d\n", f->cfrm[i].id);        }                for(i=0; i<CFRAME_BUFFER_COUNT; i++){            if(f->cfrm[i].id   == id) break;            if(f->cfrm[i].size == 0 ) free_index= i;        }        if(i>=CFRAME_BUFFER_COUNT){            i= free_index;            f->cfrm[i].id= id;        }        cfrm= &f->cfrm[i];                cfrm->data= av_fast_realloc(cfrm->data, &cfrm->allocated_size, cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE);                memcpy(cfrm->data + cfrm->size, buf+20, data_size);        cfrm->size += data_size;                if(cfrm->size >= whole_size){            buf= cfrm->data;            frame_size= cfrm->size;                        if(id != avctx->frame_number){                printf("cframe id missmatch %d %d\n", id, avctx->frame_number);            }                        cfrm->size= cfrm->id= 0;            frame_4cc= ff_get_fourcc("pfrm");        }else            return buf_size;    }else{        buf= buf + 12;        frame_size= buf_size - 12;    }        temp= f->current_picture;    f->current_picture= f->last_picture;    f->last_picture= temp;    p= &f->current_picture;    avctx->coded_frame= p;    avctx->flags |= CODEC_FLAG_EMU_EDGE; // alternatively we would have to use our own buffer management    if(p->data[0])        avctx->release_buffer(avctx, p);    p->reference= 1;    if(avctx->get_buffer(avctx, p) < 0){        fprintf(stderr, "get_buffer() failed\n");        return -1;    }    if(frame_4cc == ff_get_fourcc("ifrm")){        p->pict_type= I_TYPE;        if(decode_i_frame(f, buf, frame_size) < 0)            return -1;    }else if(frame_4cc == ff_get_fourcc("pfrm")){        p->pict_type= P_TYPE;        if(decode_p_frame(f, buf, frame_size) < 0)            return -1;    }else if(frame_4cc == ff_get_fourcc("snd_")){        printf("ignoring snd_ chunk length:%d\n", buf_size);    }else{        printf("ignoring unknown chunk length:%d\n", buf_size);    }#if 0for(i=0; i<20; i++){    printf("%2X %c ", buf[i], clip(buf[i],16,126));}#endif    p->key_frame= p->pict_type == I_TYPE;    *picture= *p;    *data_size = sizeof(AVPicture);    emms_c();        return buf_size;}