From 1c2a8c7f14a5030367b7f7287667e380935cb706 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 24 Apr 2002 01:24:06 +0000 Subject: [PATCH] avcodec_flush_buffers() Originally committed as revision 420 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/avcodec.h | 6 ++++-- libavcodec/h263.c | 4 ++-- libavcodec/h263dec.c | 15 +++++++++++---- libavcodec/mpegvideo.c | 2 ++ libavcodec/mpegvideo.h | 1 + libavcodec/utils.c | 9 +++++++++ 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 26e1b19abf..8cb62ce706 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -5,8 +5,8 @@ #define LIBAVCODEC_VERSION_INT 0x000406 #define LIBAVCODEC_VERSION "0.4.6" -#define LIBAVCODEC_BUILD 4602 -#define LIBAVCODEC_BUILD_STR "4602" +#define LIBAVCODEC_BUILD 4603 +#define LIBAVCODEC_BUILD_STR "4603" enum CodecID { CODEC_ID_NONE, @@ -340,6 +340,8 @@ int avcodec_close(AVCodecContext *avctx); void avcodec_register_all(void); +void avcodec_flush_buffers(AVCodecContext *avctx); + #ifdef FF_POSTPROCESS #ifndef MBC #define MBC 128 diff --git a/libavcodec/h263.c b/libavcodec/h263.c index 2694f96808..b7619a3e19 100644 --- a/libavcodec/h263.c +++ b/libavcodec/h263.c @@ -1034,7 +1034,7 @@ static void mpeg4_encode_vol_header(MpegEncContext * s) if(s->low_delay){ put_bits(&s->pb, 1, 1); /* vol control parameters= yes */ - put_bits(&s->pb, 2, 1); /* chroma format 422 */ + put_bits(&s->pb, 2, 1); /* chroma format YUV 420/YV12 */ put_bits(&s->pb, 1, s->low_delay); put_bits(&s->pb, 1, 0); /* vbv parameters= no */ }else{ @@ -2602,7 +2602,7 @@ int mpeg4_decode_picture_header(MpegEncContext * s) } else { vo_ver_id = 1; } - +//printf("vo type:%d\n",s->vo_type); s->aspect_ratio_info= get_bits(&s->gb, 4); if(s->aspect_ratio_info == EXTENDET_PAR){ skip_bits(&s->gb, 8); //par_width diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 9b8606d5e7..7c450f9edd 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -135,7 +135,6 @@ static int h263_decode_frame(AVCodecContext *avctx, } else { ret = h263_decode_picture_header(s); } - if(ret==FRAME_SKIPED) return 0; /* After H263 & mpeg4 header decode we have the height, width,*/ /* and other parameters. So then we could init the picture */ @@ -154,9 +153,12 @@ static int h263_decode_frame(AVCodecContext *avctx, return -1; } + if(ret==FRAME_SKIPED) return 0; if (ret < 0) return -1; - + /* skip b frames if we dont have reference frames */ + if(s->num_available_buffers<2 && s->pict_type==B_TYPE) return 0; + MPV_frame_start(s); #ifdef DEBUG @@ -222,7 +224,8 @@ static int h263_decode_frame(AVCodecContext *avctx, } MPV_decode_mb(s, s->block); } - if (avctx->draw_horiz_band) { + if ( avctx->draw_horiz_band + && (s->num_available_buffers>=1 || (!s->has_b_frames)) ) { UINT8 *src_ptr[3]; int y, h, offset; y = s->mb_y * 16; @@ -279,7 +282,11 @@ static int h263_decode_frame(AVCodecContext *avctx, /* we substract 1 because it is added on utils.c */ avctx->frame_number = s->picture_number - 1; - *data_size = sizeof(AVPicture); + /* dont output the last pic after seeking + note we allready added +1 for the current pix in MPV_frame_end(s) */ + if(s->num_available_buffers>=2 || (!s->has_b_frames)) + *data_size = sizeof(AVPicture); + return buf_size; } diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index c1a2cf746a..7eaa18111c 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -629,6 +629,8 @@ void MPV_frame_end(MpegEncContext *s) s->last_non_b_pict_type= s->pict_type; s->last_non_b_qscale= s->qscale; s->last_non_b_mc_mb_var= s->mc_mb_var; + s->num_available_buffers++; + if(s->num_available_buffers>2) s->num_available_buffers= 2; } } diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 6b67823342..69b9fb8d0e 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -129,6 +129,7 @@ typedef struct MpegEncContext { UINT8 *aux_picture[3]; /* aux picture (for B frames only) */ UINT8 *aux_picture_base[3]; /* real start of the picture */ UINT8 *current_picture[3]; /* buffer to store the decompressed current picture */ + int num_available_buffers; /* is 0 at the start & after seeking, after the first I frame its 1 after next I/P 2 */ int last_dc[3]; /* last DC values for MPEG1 */ INT16 *dc_val[3]; /* used for mpeg4 DC prediction, all 3 arrays must be continuous */ int y_dc_scale, c_dc_scale; diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 7240f2096a..c15b5674ce 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -22,6 +22,7 @@ #include "common.h" #include "dsputil.h" #include "avcodec.h" +#include "mpegvideo.h" #ifdef HAVE_MALLOC_H #include #else @@ -479,6 +480,14 @@ PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw); #undef PCM_CODEC } +/* this should be called after seeking and before trying to decode the next frame */ +void avcodec_flush_buffers(AVCodecContext *avctx) +{ + MpegEncContext *s = avctx->priv_data; + s->num_available_buffers=0; +} + + static int encode_init(AVCodecContext *s) { return 0;