printf("Error while decoding slice\n");
fprintf(stderr,"Error while decoding slice\n");
static int mpeg_decode_frame(AVCodecContext *avctx,                              void *data, int *data_size,                             UINT8 *buf, int buf_size){    Mpeg1Context *s = avctx->priv_data;    UINT8 *buf_end, *buf_ptr, *buf_start;    int len, start_code_found, ret, code, start_code, input_size;    AVPicture *picture = data;    MpegEncContext *s2 = &s->mpeg_enc_ctx;                dprintf("fill_buffer\n");    *data_size = 0;    /* special case for last picture */    if (buf_size == 0) {        if (s2->picture_number > 0) {            picture->data[0] = s2->next_picture[0];            picture->data[1] = s2->next_picture[1];            picture->data[2] = s2->next_picture[2];            picture->linesize[0] = s2->linesize;            picture->linesize[1] = s2->uvlinesize;            picture->linesize[2] = s2->uvlinesize;            *data_size = sizeof(AVPicture);        }        return 0;    }    buf_ptr = buf;    buf_end = buf + buf_size;#if 0        if (s->repeat_field % 2 == 1) {         s->repeat_field++;        //fprintf(stderr,"\nRepeating last frame: %d -> %d! pict: %d %d", avctx->frame_number-1, avctx->frame_number,        //        s2->picture_number, s->repeat_field);        if (avctx->flags & CODEC_FLAG_REPEAT_FIELD) {            *data_size = sizeof(AVPicture);            goto the_end;        }    }#endif    while (buf_ptr < buf_end) {        buf_start = buf_ptr;        /* find start next code */        code = find_start_code(&buf_ptr, buf_end, &s->header_state);        if (code >= 0) {            start_code_found = 1;        } else {            start_code_found = 0;        }        /* copy to buffer */        len = buf_ptr - buf_start;        if (len + (s->buf_ptr - s->buffer) > s->buffer_size) {            /* data too big : flush */            s->buf_ptr = s->buffer;            if (start_code_found)                s->start_code = code;        } else {            memcpy(s->buf_ptr, buf_start, len);            s->buf_ptr += len;            if(   (!(s2->flags&CODEC_FLAG_TRUNCATED)) && (!start_code_found)                && s->buf_ptr+4<s->buffer+s->buffer_size){                start_code_found= 1;                code= 0x1FF;                s->header_state=0xFF;                s->buf_ptr[0]=0;                s->buf_ptr[1]=0;                s->buf_ptr[2]=1;                s->buf_ptr[3]=0xFF;                s->buf_ptr+=4;            }            if (start_code_found) {                /* prepare data for next start code */                input_size = s->buf_ptr - s->buffer;                start_code = s->start_code;                s->buf_ptr = s->buffer;                s->start_code = code;                switch(start_code) {                case SEQ_START_CODE:                    mpeg1_decode_sequence(avctx, s->buffer,                                           input_size);                    break;                                            case PICTURE_START_CODE:                    /* we have a complete image : we try to decompress it */                    mpeg1_decode_picture(avctx,                                          s->buffer, input_size);                    break;                case EXT_START_CODE:                    mpeg_decode_extension(avctx,                                          s->buffer, input_size);                    break;                default:                    if (start_code >= SLICE_MIN_START_CODE &&                        start_code <= SLICE_MAX_START_CODE && avctx->hurry_up<5) {                        ret = mpeg_decode_slice(avctx, picture,                                                start_code, s->buffer, input_size);                        if (ret == DECODE_SLICE_EOP) {                            /* got a picture: exit */                            /* first check if we must repeat the frame */                            avctx->repeat_pict = 0;#if 0                            if (s2->progressive_frame && s2->repeat_first_field) {                                //fprintf(stderr,"\nRepeat this frame: %d! pict: %d",avctx->frame_number,s2->picture_number);                                //s2->repeat_first_field = 0;                                //s2->progressive_frame = 0;                                if (++s->repeat_field > 2)                                    s->repeat_field = 0;                                avctx->repeat_pict = 1;                            }#endif                                                  if (s2->repeat_first_field) {                                if (s2->progressive_sequence) {                                    if (s2->top_field_first)                                        avctx->repeat_pict = 4;                                    else                                        avctx->repeat_pict = 2;                                } else if (s2->progressive_frame) {                                    avctx->repeat_pict = 1;                                }                            }                                     *data_size = sizeof(AVPicture);                            goto the_end;                        }else if(ret<0){                            printf("Error while decoding slice\n");			    if(ret==DECODE_SLICE_FATAL_ERROR) return -1;                        }                    }                    break;                }            }        }    } the_end:    return buf_ptr - buf;}