diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-12-29 12:19:38 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-12-29 12:19:38 +0000 |
| commit | f7813a5324be39d13ab536c245d15dfc602a7849 (patch) | |
| tree | fad99148b88823d34a5df2f0a25881a002eb291b /ffmpeg/libavcodec/mpegvideo.c | |
| parent | b7a5a477b8ff4d4e3028b9dfb9a9df0a41463f92 (diff) | |
basic type mechanism working
Diffstat (limited to 'ffmpeg/libavcodec/mpegvideo.c')
| -rw-r--r-- | ffmpeg/libavcodec/mpegvideo.c | 416 |
1 files changed, 164 insertions, 252 deletions
diff --git a/ffmpeg/libavcodec/mpegvideo.c b/ffmpeg/libavcodec/mpegvideo.c index 46f829c..cf71784 100644 --- a/ffmpeg/libavcodec/mpegvideo.c +++ b/ffmpeg/libavcodec/mpegvideo.c @@ -27,8 +27,10 @@ * The simplest mpeg encoder (well, it was the simplest!). */ +#include "libavutil/attributes.h" #include "libavutil/avassert.h" #include "libavutil/imgutils.h" +#include "libavutil/internal.h" #include "avcodec.h" #include "dsputil.h" #include "h264chroma.h" @@ -37,13 +39,9 @@ #include "mpegvideo.h" #include "mjpegenc.h" #include "msmpeg4.h" -#include "xvmc_internal.h" #include "thread.h" #include <limits.h> -//#undef NDEBUG -//#include <assert.h> - static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, int16_t *block, int n, int qscale); static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s, @@ -59,10 +57,6 @@ static void dct_unquantize_h263_intra_c(MpegEncContext *s, static void dct_unquantize_h263_inter_c(MpegEncContext *s, int16_t *block, int n, int qscale); - -//#define DEBUG - - static const uint8_t ff_default_chroma_qscale_table[32] = { // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, @@ -152,43 +146,11 @@ static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, s->dest[1] = s->current_picture.f.data[1] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift); s->dest[2] = s->current_picture.f.data[2] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift); - assert(ref == 0); + if (ref) + av_log(s->avctx, AV_LOG_DEBUG, "Interlaced error concealment is not fully implemented\n"); ff_MPV_decode_mb(s, s->block); } -const uint8_t *avpriv_mpv_find_start_code(const uint8_t *av_restrict p, - const uint8_t *end, - uint32_t *av_restrict state) -{ - int i; - - assert(p <= end); - if (p >= end) - return end; - - for (i = 0; i < 3; i++) { - uint32_t tmp = *state << 8; - *state = tmp + *(p++); - if (tmp == 0x100 || p == end) - return p; - } - - while (p < end) { - if (p[-1] > 1 ) p += 3; - else if (p[-2] ) p += 2; - else if (p[-3]|(p[-1]-1)) p++; - else { - p++; - break; - } - } - - p = FFMIN(p, end) - 4; - *state = AV_RB32(p); - - return p + 4; -} - /* init common dct for both encoder and decoder */ av_cold int ff_dct_common_init(MpegEncContext *s) { @@ -206,17 +168,16 @@ av_cold int ff_dct_common_init(MpegEncContext *s) s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact; s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c; -#if ARCH_X86 - ff_MPV_common_init_x86(s); -#elif ARCH_ALPHA - ff_MPV_common_init_axp(s); -#elif ARCH_ARM - ff_MPV_common_init_arm(s); -#elif HAVE_ALTIVEC - ff_MPV_common_init_altivec(s); -#elif ARCH_BFIN - ff_MPV_common_init_bfin(s); -#endif + if (ARCH_ALPHA) + ff_MPV_common_init_axp(s); + if (ARCH_ARM) + ff_MPV_common_init_arm(s); + if (ARCH_BFIN) + ff_MPV_common_init_bfin(s); + if (ARCH_PPC) + ff_MPV_common_init_ppc(s); + if (ARCH_X86) + ff_MPV_common_init_x86(s); /* load & permutate scantables * note: only wmv uses different ones @@ -234,7 +195,7 @@ av_cold int ff_dct_common_init(MpegEncContext *s) return 0; } -int ff_mpv_frame_size_alloc(MpegEncContext *s, int linesize) +static int frame_size_alloc(MpegEncContext *s, int linesize) { int alloc_size = FFALIGN(FFABS(linesize) + 64, 32); @@ -279,7 +240,7 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic) r = avcodec_default_get_buffer2(s->avctx, &pic->f, 0); } - if (r < 0 || !pic->f.data[0]) { + if (r < 0 || !pic->f.buf[0]) { av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %p)\n", r, pic->f.data[0]); return -1; @@ -313,7 +274,7 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic) } if (!s->edge_emu_buffer && - (ret = ff_mpv_frame_size_alloc(s, pic->f.linesize[0])) < 0) { + (ret = frame_size_alloc(s, pic->f.linesize[0])) < 0) { av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed to allocate context scratch buffers.\n"); ff_mpeg_unref_picture(s, pic); @@ -323,10 +284,13 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic) return 0; } -static void free_picture_tables(Picture *pic) +void ff_free_picture_tables(Picture *pic) { int i; + pic->alloc_mb_width = + pic->alloc_mb_height = 0; + av_buffer_unref(&pic->mb_var_buf); av_buffer_unref(&pic->mc_mb_var_buf); av_buffer_unref(&pic->mb_mean_buf); @@ -363,8 +327,7 @@ static int alloc_picture_tables(MpegEncContext *s, Picture *pic) return AVERROR(ENOMEM); } - if (s->out_format == FMT_H263 || s->encoding || - (s->avctx->debug & FF_DEBUG_MV) || s->avctx->debug_mv) { + if (s->out_format == FMT_H263 || s->encoding || s->avctx->debug_mv) { int mv_size = 2 * (b8_array_size + 4) * sizeof(int16_t); int ref_index_size = 4 * mb_array_size; @@ -376,6 +339,9 @@ static int alloc_picture_tables(MpegEncContext *s, Picture *pic) } } + pic->alloc_mb_width = s->mb_width; + pic->alloc_mb_height = s->mb_height; + return 0; } @@ -413,15 +379,15 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared) int i, ret; if (pic->qscale_table_buf) - if (pic->mbskip_table_buf->size < s->mb_stride * s->mb_height + 2 || - pic->qscale_table_buf->size < s->mb_stride * (s->mb_height + 1) + 1 + s->mb_stride) - free_picture_tables(pic); + if ( pic->alloc_mb_width != s->mb_width + || pic->alloc_mb_height != s->mb_height) + ff_free_picture_tables(pic); if (shared) { - assert(pic->f.data[0]); + av_assert0(pic->f.data[0]); pic->shared = 1; } else { - assert(!pic->f.data[0]); + av_assert0(!pic->f.buf[0]); if (alloc_frame_buffer(s, pic) < 0) return -1; @@ -458,7 +424,7 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared) fail: av_log(s->avctx, AV_LOG_ERROR, "Error allocating a picture.\n"); ff_mpeg_unref_picture(s, pic); - free_picture_tables(pic); + ff_free_picture_tables(pic); return AVERROR(ENOMEM); } @@ -468,7 +434,6 @@ fail: void ff_mpeg_unref_picture(MpegEncContext *s, Picture *pic) { int off = offsetof(Picture, mb_mean) + sizeof(pic->mb_mean); - pic->period_since_free = 0; pic->tf.f = &pic->f; /* WM Image / Screen codecs allocate internal buffers with different @@ -482,6 +447,9 @@ void ff_mpeg_unref_picture(MpegEncContext *s, Picture *pic) av_buffer_unref(&pic->hwaccel_priv_buf); + if (pic->needs_realloc) + ff_free_picture_tables(pic); + memset((uint8_t*)pic + off, 0, sizeof(*pic) - off); } @@ -496,7 +464,7 @@ do {\ av_buffer_unref(&dst->table);\ dst->table = av_buffer_ref(src->table);\ if (!dst->table) {\ - free_picture_tables(dst);\ + ff_free_picture_tables(dst);\ return AVERROR(ENOMEM);\ }\ }\ @@ -524,6 +492,9 @@ do {\ dst->ref_index[i] = src->ref_index[i]; } + dst->alloc_mb_width = src->alloc_mb_width; + dst->alloc_mb_height = src->alloc_mb_height; + return 0; } @@ -565,6 +536,15 @@ fail: return ret; } +static void exchange_uv(MpegEncContext *s) +{ + int16_t (*tmp)[64]; + + tmp = s->pblocks[4]; + s->pblocks[4] = s->pblocks[5]; + s->pblocks[5] = tmp; +} + static int init_duplicate_context(MpegEncContext *s) { int y_size = s->b8_stride * (2 * s->mb_height + 1); @@ -595,6 +575,8 @@ static int init_duplicate_context(MpegEncContext *s) for (i = 0; i < 12; i++) { s->pblocks[i] = &s->block[i]; } + if (s->avctx->codec_tag == AV_RL32("VCR2")) + exchange_uv(s); if (s->out_format == FMT_H263) { /* ac values */ @@ -669,8 +651,10 @@ int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src) for (i = 0; i < 12; i++) { dst->pblocks[i] = &dst->block[i]; } + if (dst->avctx->codec_tag == AV_RL32("VCR2")) + exchange_uv(dst); if (!dst->edge_emu_buffer && - (ret = ff_mpv_frame_size_alloc(dst, dst->linesize)) < 0) { + (ret = frame_size_alloc(dst, dst->linesize)) < 0) { av_log(dst->avctx, AV_LOG_ERROR, "failed to allocate context " "scratch buffers.\n"); return ret; @@ -726,21 +710,20 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, s->coded_picture_number = s1->coded_picture_number; s->picture_number = s1->picture_number; - s->input_picture_number = s1->input_picture_number; av_assert0(!s->picture || s->picture != s1->picture); + if(s->picture) for (i = 0; i < MAX_PICTURE_COUNT; i++) { ff_mpeg_unref_picture(s, &s->picture[i]); - if (s1->picture[i].f.data[0] && + if (s1->picture[i].f.buf[0] && (ret = ff_mpeg_ref_picture(s, &s->picture[i], &s1->picture[i])) < 0) return ret; - s->picture[i].period_since_free ++; } #define UPDATE_PICTURE(pic)\ do {\ ff_mpeg_unref_picture(s, &s->pic);\ - if (s1->pic.f.data[0])\ + if (s1->pic.f.buf[0])\ ret = ff_mpeg_ref_picture(s, &s->pic, &s1->pic);\ else\ ret = update_picture_tables(&s->pic, &s1->pic);\ @@ -762,8 +745,9 @@ do {\ s->padding_bug_score = s1->padding_bug_score; // MPEG4 timing info - memcpy(&s->time_increment_bits, &s1->time_increment_bits, - (char *) &s1->shape - (char *) &s1->time_increment_bits); + memcpy(&s->last_time_base, &s1->last_time_base, + (char *) &s1->pb_field_time + sizeof(s1->pb_field_time) - + (char *) &s1->last_time_base); // B-frame info s->max_b_frames = s1->max_b_frames; @@ -789,7 +773,7 @@ do {\ // linesize dependend scratch buffer allocation if (!s->edge_emu_buffer) if (s1->linesize) { - if (ff_mpv_frame_size_alloc(s, s1->linesize) < 0) { + if (frame_size_alloc(s, s1->linesize) < 0) { av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate context " "scratch buffers.\n"); return AVERROR(ENOMEM); @@ -807,10 +791,6 @@ do {\ s->last_pict_type = s1->pict_type; if (s1->current_picture_ptr) s->last_lambda_for[s1->pict_type] = s1->current_picture_ptr->f.quality; - - if (s1->pict_type != AV_PICTURE_TYPE_B) { - s->last_non_b_pict_type = s1->pict_type; - } } return 0; @@ -833,9 +813,6 @@ void ff_MPV_common_defaults(MpegEncContext *s) s->coded_picture_number = 0; s->picture_number = 0; - s->input_picture_number = 0; - - s->picture_in_gop_number = 0; s->f_code = 1; s->b_code = 1; @@ -1057,47 +1034,26 @@ av_cold int ff_MPV_common_init(MpegEncContext *s) s->flags2 = s->avctx->flags2; /* set chroma shifts */ - avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift); + avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, + &s->chroma_x_shift, + &s->chroma_y_shift); /* convert fourcc to upper case */ - s->codec_tag = avpriv_toupper4(s->avctx->codec_tag); - s->stream_codec_tag = avpriv_toupper4(s->avctx->stream_codec_tag); - - s->avctx->coded_frame = &s->current_picture.f; - - if (s->encoding) { - if (s->msmpeg4_version) { - FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_stats, - 2 * 2 * (MAX_LEVEL + 1) * - (MAX_RUN + 1) * 2 * sizeof(int), fail); - } - FF_ALLOCZ_OR_GOTO(s->avctx, s->avctx->stats_out, 256, fail); + s->codec_tag = avpriv_toupper4(s->avctx->codec_tag); - FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix, 64 * 32 * sizeof(int), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->q_chroma_intra_matrix, 64 * 32 * sizeof(int), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix, 64 * 32 * sizeof(int), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix16, 64 * 32 * 2 * sizeof(uint16_t), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->q_chroma_intra_matrix16, 64 * 32 * 2 * sizeof(uint16_t), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix16, 64 * 32 * 2 * sizeof(uint16_t), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture *), fail) - FF_ALLOCZ_OR_GOTO(s->avctx, s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture *), fail) - - if (s->avctx->noise_reduction) { - FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_offset, 2 * 64 * sizeof(uint16_t), fail); - } - } + s->stream_codec_tag = avpriv_toupper4(s->avctx->stream_codec_tag); FF_ALLOCZ_OR_GOTO(s->avctx, s->picture, MAX_PICTURE_COUNT * sizeof(Picture), fail); for (i = 0; i < MAX_PICTURE_COUNT; i++) { - avcodec_get_frame_defaults(&s->picture[i].f); + av_frame_unref(&s->picture[i].f); } memset(&s->next_picture, 0, sizeof(s->next_picture)); memset(&s->last_picture, 0, sizeof(s->last_picture)); memset(&s->current_picture, 0, sizeof(s->current_picture)); - avcodec_get_frame_defaults(&s->next_picture.f); - avcodec_get_frame_defaults(&s->last_picture.f); - avcodec_get_frame_defaults(&s->current_picture.f); + av_frame_unref(&s->next_picture.f); + av_frame_unref(&s->last_picture.f); + av_frame_unref(&s->current_picture.f); if (init_context_frame(s)) goto fail; @@ -1251,7 +1207,8 @@ int ff_MPV_common_frame_size_change(MpegEncContext *s) (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices; } } else { - if (init_duplicate_context(s) < 0) + err = init_duplicate_context(s); + if (err < 0) goto fail; s->start_mb_y = 0; s->end_mb_y = s->mb_height; @@ -1286,36 +1243,19 @@ void ff_MPV_common_end(MpegEncContext *s) av_freep(&s->bitstream_buffer); s->allocated_bitstream_buffer_size = 0; - av_freep(&s->avctx->stats_out); - av_freep(&s->ac_stats); - - if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix); - if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16); - s->q_chroma_intra_matrix= NULL; - s->q_chroma_intra_matrix16= NULL; - av_freep(&s->q_intra_matrix); - av_freep(&s->q_inter_matrix); - av_freep(&s->q_intra_matrix16); - av_freep(&s->q_inter_matrix16); - av_freep(&s->input_picture); - av_freep(&s->reordered_input_picture); - av_freep(&s->dct_offset); - if (s->picture) { for (i = 0; i < MAX_PICTURE_COUNT; i++) { - free_picture_tables(&s->picture[i]); + ff_free_picture_tables(&s->picture[i]); ff_mpeg_unref_picture(s, &s->picture[i]); } } av_freep(&s->picture); - free_picture_tables(&s->last_picture); + ff_free_picture_tables(&s->last_picture); ff_mpeg_unref_picture(s, &s->last_picture); - free_picture_tables(&s->current_picture); + ff_free_picture_tables(&s->current_picture); ff_mpeg_unref_picture(s, &s->current_picture); - free_picture_tables(&s->next_picture); + ff_free_picture_tables(&s->next_picture); ff_mpeg_unref_picture(s, &s->next_picture); - free_picture_tables(&s->new_picture); - ff_mpeg_unref_picture(s, &s->new_picture); free_context_frame(s); @@ -1326,8 +1266,8 @@ void ff_MPV_common_end(MpegEncContext *s) s->linesize = s->uvlinesize = 0; } -void ff_init_rl(RLTable *rl, - uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3]) +av_cold void ff_init_rl(RLTable *rl, + uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3]) { int8_t max_level[MAX_RUN + 1], max_run[MAX_LEVEL + 1]; uint8_t index_run[MAX_RUN + 1]; @@ -1378,7 +1318,7 @@ void ff_init_rl(RLTable *rl, } } -void ff_init_vlc_rl(RLTable *rl) +av_cold void ff_init_vlc_rl(RLTable *rl) { int i, q; @@ -1418,28 +1358,22 @@ void ff_init_vlc_rl(RLTable *rl) } } -void ff_release_unused_pictures(MpegEncContext*s, int remove_current) +static void release_unused_pictures(MpegEncContext *s) { int i; /* release non reference frames */ for (i = 0; i < MAX_PICTURE_COUNT; i++) { - if (!s->picture[i].reference && - (remove_current || &s->picture[i] != s->current_picture_ptr)) { + if (!s->picture[i].reference) ff_mpeg_unref_picture(s, &s->picture[i]); - } } } static inline int pic_is_unused(MpegEncContext *s, Picture *pic) { - if ( (s->avctx->active_thread_type & FF_THREAD_FRAME) - && pic->f.qscale_table //check if the frame has anything allocated - && pic->period_since_free < s->avctx->thread_count) - return 0; if (pic == s->last_picture_ptr) return 0; - if (pic->f.data[0] == NULL) + if (pic->f.buf[0] == NULL) return 1; if (pic->needs_realloc && !(pic->reference & DELAYED_PIC_REF)) return 1; @@ -1452,7 +1386,7 @@ static int find_unused_picture(MpegEncContext *s, int shared) if (shared) { for (i = 0; i < MAX_PICTURE_COUNT; i++) { - if (s->picture[i].f.data[0] == NULL && &s->picture[i] != s->last_picture_ptr) + if (s->picture[i].f.buf[0] == NULL && &s->picture[i] != s->last_picture_ptr) return i; } } else { @@ -1486,9 +1420,8 @@ int ff_find_unused_picture(MpegEncContext *s, int shared) if (ret >= 0 && ret < MAX_PICTURE_COUNT) { if (s->picture[ret].needs_realloc) { s->picture[ret].needs_realloc = 0; - free_picture_tables(&s->picture[ret]); + ff_free_picture_tables(&s->picture[ret]); ff_mpeg_unref_picture(s, &s->picture[ret]); - avcodec_get_frame_defaults(&s->picture[ret].f); } } return ret; @@ -1533,7 +1466,7 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) /* mark & release old frames */ if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr && s->last_picture_ptr != s->next_picture_ptr && - s->last_picture_ptr->f.data[0]) { + s->last_picture_ptr->f.buf[0]) { ff_mpeg_unref_picture(s, s->last_picture_ptr); } @@ -1552,11 +1485,13 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) } } + ff_mpeg_unref_picture(s, &s->current_picture); + if (!s->encoding) { - ff_release_unused_pictures(s, 1); + release_unused_pictures(s); if (s->current_picture_ptr && - s->current_picture_ptr->f.data[0] == NULL) { + s->current_picture_ptr->f.buf[0] == NULL) { // we already have a unused image // (maybe it was set before reading the header) pic = s->current_picture_ptr; @@ -1599,7 +1534,6 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) // s->current_picture_ptr->quality = s->new_picture_ptr->quality; s->current_picture_ptr->f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; - ff_mpeg_unref_picture(s, &s->current_picture); if ((ret = ff_mpeg_ref_picture(s, &s->current_picture, s->current_picture_ptr)) < 0) return ret; @@ -1617,17 +1551,20 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) s->pict_type, s->droppable); if ((s->last_picture_ptr == NULL || - s->last_picture_ptr->f.data[0] == NULL) && + s->last_picture_ptr->f.buf[0] == NULL) && (s->pict_type != AV_PICTURE_TYPE_I || s->picture_structure != PICT_FRAME)) { int h_chroma_shift, v_chroma_shift; av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); - if (s->pict_type != AV_PICTURE_TYPE_I) + if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f.buf[0]) + av_log(avctx, AV_LOG_DEBUG, + "allocating dummy last picture for B frame\n"); + else if (s->pict_type != AV_PICTURE_TYPE_I) av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n"); else if (s->picture_structure != PICT_FRAME) - av_log(avctx, AV_LOG_INFO, + av_log(avctx, AV_LOG_DEBUG, "allocate dummy last picture for field based first keyframe\n"); /* Allocate a dummy frame */ @@ -1661,7 +1598,7 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 1); } if ((s->next_picture_ptr == NULL || - s->next_picture_ptr->f.data[0] == NULL) && + s->next_picture_ptr->f.buf[0] == NULL) && s->pict_type == AV_PICTURE_TYPE_B) { /* Allocate a dummy frame */ i = ff_find_unused_picture(s, 0); @@ -1685,21 +1622,21 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) #endif if (s->last_picture_ptr) { ff_mpeg_unref_picture(s, &s->last_picture); - if (s->last_picture_ptr->f.data[0] && + if (s->last_picture_ptr->f.buf[0] && (ret = ff_mpeg_ref_picture(s, &s->last_picture, s->last_picture_ptr)) < 0) return ret; } if (s->next_picture_ptr) { ff_mpeg_unref_picture(s, &s->next_picture); - if (s->next_picture_ptr->f.data[0] && + if (s->next_picture_ptr->f.buf[0] && (ret = ff_mpeg_ref_picture(s, &s->next_picture, s->next_picture_ptr)) < 0) return ret; } - assert(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr && - s->last_picture_ptr->f.data[0])); + av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr && + s->last_picture_ptr->f.buf[0])); if (s->picture_structure!= PICT_FRAME) { int i; @@ -1731,34 +1668,25 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) } if (s->dct_error_sum) { - assert(s->avctx->noise_reduction && s->encoding); + av_assert2(s->avctx->noise_reduction && s->encoding); update_noise_reduction(s); } - if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) - return ff_xvmc_field_start(s, avctx); - return 0; } -/* generic function for encode/decode called after a - * frame has been coded/decoded. */ +/* called after a frame has been decoded. */ void ff_MPV_frame_end(MpegEncContext *s) { - int i; - /* redraw edges for the frame if decoding didn't complete */ - // just to make sure that all data is rendered. - if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) { - ff_xvmc_field_end(s); - } else if ((s->er.error_count || s->encoding || !(s->avctx->codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND)) && - !s->avctx->hwaccel && - !(s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) && - s->unrestricted_mv && - s->current_picture.reference && - !s->intra_only && - !(s->flags & CODEC_FLAG_EMU_EDGE) && - !s->avctx->lowres - ) { + if ((s->er.error_count || !(s->avctx->codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND)) && + !s->avctx->hwaccel && + !(s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) && + s->unrestricted_mv && + s->current_picture.reference && + !s->intra_only && + !(s->flags & CODEC_FLAG_EMU_EDGE) && + !s->avctx->lowres + ) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt); int hshift = desc->log2_chroma_w; int vshift = desc->log2_chroma_h; @@ -1778,37 +1706,6 @@ void ff_MPV_frame_end(MpegEncContext *s) emms_c(); - s->last_pict_type = s->pict_type; - s->last_lambda_for [s->pict_type] = s->current_picture_ptr->f.quality; - if (s->pict_type!= AV_PICTURE_TYPE_B) { - s->last_non_b_pict_type = s->pict_type; - } -#if 0 - /* copy back current_picture variables */ - for (i = 0; i < MAX_PICTURE_COUNT; i++) { - if (s->picture[i].f.data[0] == s->current_picture.f.data[0]) { - s->picture[i] = s->current_picture; - break; - } - } - assert(i < MAX_PICTURE_COUNT); -#endif - - if (s->encoding) { - /* release non-reference frames */ - for (i = 0; i < MAX_PICTURE_COUNT; i++) { - if (!s->picture[i].reference) - ff_mpeg_unref_picture(s, &s->picture[i]); - } - } - // clear copies, to avoid confusion -#if 0 - memset(&s->last_picture, 0, sizeof(Picture)); - memset(&s->next_picture, 0, sizeof(Picture)); - memset(&s->current_picture, 0, sizeof(Picture)); -#endif - s->avctx->coded_frame = &s->current_picture_ptr->f; - if (s->current_picture.reference) ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0); } @@ -2212,13 +2109,13 @@ static inline int hpel_motion_lowres(MpegEncContext *s, uint8_t *dest, uint8_t *src, int field_based, int field_select, int src_x, int src_y, - int width, int height, int stride, + int width, int height, ptrdiff_t stride, int h_edge_pos, int v_edge_pos, int w, int h, h264_chroma_mc_func *pix_op, int motion_x, int motion_y) { const int lowres = s->avctx->lowres; - const int op_index = FFMIN(lowres, 2); + const int op_index = FFMIN(lowres, 3); const int s_mask = (2 << lowres) - 1; int emu = 0; int sx, sy; @@ -2237,11 +2134,11 @@ static inline int hpel_motion_lowres(MpegEncContext *s, if ((unsigned)src_x > FFMAX( h_edge_pos - (!!sx) - w, 0) || (unsigned)src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) { - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w + 1, - (h + 1) << field_based, src_x, - src_y << field_based, - h_edge_pos, - v_edge_pos); + s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src, + s->linesize, s->linesize, + w + 1, (h + 1) << field_based, + src_x, src_y << field_based, + h_edge_pos, v_edge_pos); src = s->edge_emu_buffer; emu = 1; } @@ -2268,10 +2165,10 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, int h, int mb_y) { uint8_t *ptr_y, *ptr_cb, *ptr_cr; - int mx, my, src_x, src_y, uvsrc_x, uvsrc_y, uvlinesize, linesize, sx, sy, - uvsx, uvsy; + int mx, my, src_x, src_y, uvsrc_x, uvsrc_y, sx, sy, uvsx, uvsy; + ptrdiff_t uvlinesize, linesize; const int lowres = s->avctx->lowres; - const int op_index = FFMIN(lowres-1+s->chroma_x_shift, 2); + const int op_index = FFMIN(lowres-1+s->chroma_x_shift, 3); const int block_s = 8>>lowres; const int s_mask = (2 << lowres) - 1; const int h_edge_pos = s->h_edge_pos >> lowres; @@ -2337,21 +2234,24 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; - if ((unsigned) src_x > FFMAX( h_edge_pos - (!!sx) - 2 * block_s, 0) || + if ((unsigned) src_x > FFMAX( h_edge_pos - (!!sx) - 2 * block_s, 0) || uvsrc_y<0 || (unsigned) src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) { s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, - linesize >> field_based, 17, 17 + field_based, + linesize >> field_based, linesize >> field_based, + 17, 17 + field_based, src_x, src_y << field_based, h_edge_pos, v_edge_pos); ptr_y = s->edge_emu_buffer; if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { uint8_t *uvbuf = s->edge_emu_buffer + 18 * s->linesize; - s->vdsp.emulated_edge_mc(uvbuf , ptr_cb, uvlinesize >> field_based, 9, - 9 + field_based, + s->vdsp.emulated_edge_mc(uvbuf, ptr_cb, + uvlinesize >> field_based, uvlinesize >> field_based, + 9, 9 + field_based, uvsrc_x, uvsrc_y << field_based, h_edge_pos >> 1, v_edge_pos >> 1); - s->vdsp.emulated_edge_mc(uvbuf + 16, ptr_cr, uvlinesize >> field_based, 9, - 9 + field_based, + s->vdsp.emulated_edge_mc(uvbuf + 16, ptr_cr, + uvlinesize >> field_based,uvlinesize >> field_based, + 9, 9 + field_based, uvsrc_x, uvsrc_y << field_based, h_edge_pos >> 1, v_edge_pos >> 1); ptr_cb = uvbuf; @@ -2377,11 +2277,12 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, pix_op[lowres - 1](dest_y, ptr_y, linesize, h, sx, sy); if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { + int hc = s->chroma_y_shift ? (h+1-bottom_field)>>1 : h; uvsx = (uvsx << 2) >> lowres; uvsy = (uvsy << 2) >> lowres; - if (h >> s->chroma_y_shift) { - pix_op[op_index](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); - pix_op[op_index](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); + if (hc) { + pix_op[op_index](dest_cb, ptr_cb, uvlinesize, hc, uvsx, uvsy); + pix_op[op_index](dest_cr, ptr_cr, uvlinesize, hc, uvsx, uvsy); } } // FIXME h261 lowres loop filter @@ -2394,12 +2295,13 @@ static inline void chroma_4mv_motion_lowres(MpegEncContext *s, int mx, int my) { const int lowres = s->avctx->lowres; - const int op_index = FFMIN(lowres, 2); + const int op_index = FFMIN(lowres, 3); const int block_s = 8 >> lowres; const int s_mask = (2 << lowres) - 1; const int h_edge_pos = s->h_edge_pos >> lowres + 1; const int v_edge_pos = s->v_edge_pos >> lowres + 1; - int emu = 0, src_x, src_y, offset, sx, sy; + int emu = 0, src_x, src_y, sx, sy; + ptrdiff_t offset; uint8_t *ptr; if (s->quarter_sample) { @@ -2419,14 +2321,14 @@ static inline void chroma_4mv_motion_lowres(MpegEncContext *s, offset = src_y * s->uvlinesize + src_x; ptr = ref_picture[1] + offset; - if (s->flags & CODEC_FLAG_EMU_EDGE) { - if ((unsigned) src_x > FFMAX(h_edge_pos - (!!sx) - block_s, 0) || - (unsigned) src_y > FFMAX(v_edge_pos - (!!sy) - block_s, 0)) { - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, - 9, 9, src_x, src_y, h_edge_pos, v_edge_pos); - ptr = s->edge_emu_buffer; - emu = 1; - } + if ((unsigned) src_x > FFMAX(h_edge_pos - (!!sx) - block_s, 0) || + (unsigned) src_y > FFMAX(v_edge_pos - (!!sy) - block_s, 0)) { + s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, + s->uvlinesize, s->uvlinesize, + 9, 9, + src_x, src_y, h_edge_pos, v_edge_pos); + ptr = s->edge_emu_buffer; + emu = 1; } sx = (sx << 2) >> lowres; sy = (sy << 2) >> lowres; @@ -2434,8 +2336,10 @@ static inline void chroma_4mv_motion_lowres(MpegEncContext *s, ptr = ref_picture[2] + offset; if (emu) { - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, - src_x, src_y, h_edge_pos, v_edge_pos); + s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, + s->uvlinesize, s->uvlinesize, + 9, 9, + src_x, src_y, h_edge_pos, v_edge_pos); ptr = s->edge_emu_buffer; } pix_op[op_index](dest_cr, ptr, s->uvlinesize, block_s, sx, sy); @@ -2696,8 +2600,10 @@ void MPV_decode_mb_internal(MpegEncContext *s, int16_t block[12][64], int lowres_flag, int is_mpeg12) { const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; - if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration){ - ff_xvmc_decode_mb(s);//xvmc uses pblocks + + if (CONFIG_XVMC && + s->avctx->hwaccel && s->avctx->hwaccel->decode_mb) { + s->avctx->hwaccel->decode_mb(s);//xvmc uses pblocks return; } @@ -2729,7 +2635,9 @@ void MPV_decode_mb_internal(MpegEncContext *s, int16_t block[12][64], else if (!is_mpeg12 && (s->h263_pred || s->h263_aic)) s->mbintra_table[mb_xy]=1; - if ((s->flags&CODEC_FLAG_PSNR) || !(s->encoding && (s->intra_only || s->pict_type==AV_PICTURE_TYPE_B) && s->avctx->mb_decision != FF_MB_DECISION_RD)) { //FIXME precalc + if ( (s->flags&CODEC_FLAG_PSNR) + || s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor + || !(s->encoding && (s->intra_only || s->pict_type==AV_PICTURE_TYPE_B) && s->avctx->mb_decision != FF_MB_DECISION_RD)) { //FIXME precalc uint8_t *dest_y, *dest_cb, *dest_cr; int dct_linesize, dct_offset; op_pixels_func (*op_pix)[4]; @@ -2797,7 +2705,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, int16_t block[12][64], MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix); } }else{ - op_qpix= s->me.qpel_put; + op_qpix = s->me.qpel_put; if ((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){ op_pix = s->hdsp.put_pixels_tab; }else{ @@ -2908,7 +2816,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, int16_t block[12][64], }else{ dct_linesize = uvlinesize << s->interlaced_dct; - dct_offset = s->interlaced_dct? uvlinesize : uvlinesize*block_size; + dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size; s->dsp.idct_put(dest_cb, dct_linesize, block[4]); s->dsp.idct_put(dest_cr, dct_linesize, block[5]); @@ -3025,8 +2933,8 @@ void ff_draw_horiz_band(AVCodecContext *avctx, DSPContext *dsp, Picture *cur, void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h) { int draw_edges = s->unrestricted_mv && !s->intra_only; - ff_draw_horiz_band(s->avctx, &s->dsp, &s->current_picture, - &s->last_picture, y, h, s->picture_structure, + ff_draw_horiz_band(s->avctx, &s->dsp, s->current_picture_ptr, + s->last_picture_ptr, y, h, s->picture_structure, s->first_field, draw_edges, s->low_delay, s->v_edge_pos, s->h_edge_pos); } @@ -3103,6 +3011,10 @@ void ff_mpeg_flush(AVCodecContext *avctx){ ff_mpeg_unref_picture(s, &s->picture[i]); s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL; + ff_mpeg_unref_picture(s, &s->current_picture); + ff_mpeg_unref_picture(s, &s->last_picture); + ff_mpeg_unref_picture(s, &s->next_picture); + s->mb_x= s->mb_y= 0; s->closed_gop= 0; @@ -3269,7 +3181,7 @@ static void dct_unquantize_h263_intra_c(MpegEncContext *s, int i, level, qmul, qadd; int nCoeffs; - assert(s->block_last_index[n]>=0); + av_assert2(s->block_last_index[n]>=0 || s->h263_aic); qmul = qscale << 1; @@ -3303,7 +3215,7 @@ static void dct_unquantize_h263_inter_c(MpegEncContext *s, int i, level, qmul, qadd; int nCoeffs; - assert(s->block_last_index[n]>=0); + av_assert2(s->block_last_index[n]>=0); qadd = (qscale - 1) | 1; qmul = qscale << 1; |
