Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 7340c73604eec66a58cc2bc9bbb6a3a346af09da Mon Sep 17 00:00:00 2001
- From: unknown <Konstantin@RED.(none)>
- Date: Wed, 30 Nov 2011 22:55:45 +0200
- Subject: [PATCH] mpegvideo.c : Code cleanup
- ---
- libavcodec/mpegvideo.c | 2622 +++++++++++++++++++++++++++---------------------
- 1 files changed, 1486 insertions(+), 1136 deletions(-)
- diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
- index dcef706..2c2adc7 100644
- --- a/libavcodec/mpegvideo.c
- +++ b/libavcodec/mpegvideo.c
- @@ -1,25 +1,25 @@
- /*
- * The simplest mpeg encoder (well, it was the simplest!)
- * Copyright (c) 2000,2001 Fabrice Bellard
- - * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- + * Copyright (c) 2002-2004 Michael Niedermayer < michaelni@gmx.at>
- *
- - * 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
- + * 4MV & hq & B-frame encoding stuff by Michael Niedermayer < michaelni@gmx.at>
- *
- * This file is part of Libav.
- *
- * Libav is free software; you can redistribute it and/or
- - * modify it under the terms of the GNU Lesser General Public
- + * modif y it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * Libav is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- - * Lesser General Public License for more details.
- + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- + * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- - * License along with Libav; if not, write to the Free Software
- - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- + * License along with Libav; if not, write to the Free Software
- + * Foundation, Inc., 51 Franklin Street, Fif th Floor, Boston, MA 02110-1301 USA
- */
- /**
- @@ -39,10 +39,10 @@
- #include "faandct.h"
- #include "xvmc_internal.h"
- #include "thread.h"
- -#include <limits.h>
- +#include < limits.h>
- //#undef NDEBUG
- -//#include <assert.h>
- +//#include < assert.h>
- static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale);
- @@ -60,50 +60,72 @@ static void dct_unquantize_h263_inter_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale);
- -/* enable all paranoid tests for rounding, overflows, etc... */
- +/* enable all paranoid tests for rounding, overflows, etc... */
- //#define PARANOID
- //#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 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
- +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
- +// 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,
- + 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
- };
- -const uint8_t ff_mpeg1_dc_scale_table[128]={
- -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- +const uint8_t ff_mpeg1_dc_scale_table[128] = {
- +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- +// 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- };
- -static const uint8_t mpeg2_dc_scale_table1[128]={
- -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- +static const uint8_t mpeg2_dc_scale_table1[128] = {
- +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- +// 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- };
- -static const uint8_t mpeg2_dc_scale_table2[128]={
- -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- +static const uint8_t mpeg2_dc_scale_table2[128] = {
- +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- +// 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- };
- -static const uint8_t mpeg2_dc_scale_table3[128]={
- -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- +static const uint8_t mpeg2_dc_scale_table3[128] = {
- +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- +// 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- };
- -const uint8_t * const ff_mpeg2_dc_scale_table[4]={
- +const uint8_t * const ff_mpeg2_dc_scale_table[4] = {
- ff_mpeg1_dc_scale_table,
- mpeg2_dc_scale_table1,
- mpeg2_dc_scale_table2,
- @@ -123,37 +145,39 @@ const enum PixelFormat ff_hwaccel_pixfmt_list_420[] = {
- PIX_FMT_NONE
- };
- -const uint8_t *avpriv_mpv_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){
- +const uint8_t *avpriv_mpv_find_start_code(const uint8_t * restrict p,
- + const uint8_t *end,
- + uint32_t * restrict state){
- int i;
- - assert(p<=end);
- - if(p>=end)
- + 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)
- + 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++;
- + 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++;
- + p + + ;
- break;
- }
- }
- - p= FFMIN(p, end)-4;
- - *state= AV_RB32(p);
- + p = FFMIN(p, end)-4;
- + *state = AV_RB32(p);
- - return p+4;
- + return p + 4;
- }
- -/* init common dct for both encoder and decoder */
- +/* init common dct for both encoder and decoder */
- av_cold int ff_dct_common_init(MpegEncContext *s)
- {
- dsputil_init(&s->dsp, s->avctx);
- @@ -163,11 +187,11 @@ av_cold int ff_dct_common_init(MpegEncContext *s)
- s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c;
- s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c;
- s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c;
- - if(s->flags & CODEC_FLAG_BITEXACT)
- + if (s->flags & CODEC_FLAG_BITEXACT)
- s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact;
- s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c;
- -#if HAVE_MMX
- +#if HAVE_MMX
- MPV_common_init_mmx(s);
- #elif ARCH_ALPHA
- MPV_common_init_axp(s);
- @@ -184,9 +208,9 @@ av_cold int ff_dct_common_init(MpegEncContext *s)
- #endif
- /* load & permutate scantables
- - note: only wmv uses different ones
- + note: only wmv uses dif ferent ones
- */
- - if(s->alternate_scan){
- + if (s->alternate_scan){
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
- }else{
- @@ -201,7 +225,7 @@ av_cold int ff_dct_common_init(MpegEncContext *s)
- void ff_copy_picture(Picture *dst, Picture *src){
- *dst = *src;
- - dst->f.type= FF_BUFFER_TYPE_COPY;
- + dst->f.type = FF_BUFFER_TYPE_COPY;
- }
- /**
- @@ -209,9 +233,9 @@ void ff_copy_picture(Picture *dst, Picture *src){
- */
- static void free_frame_buffer(MpegEncContext *s, Picture *pic)
- {
- - /* Windows Media Image codecs allocate internal buffers with different
- - dimensions; ignore user defined callbacks for these */
- - if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
- + /* Windows Media Image codecs allocate internal buffers with dif ferent
- + dimensions; ignore user defined callbacks for these */
- + if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
- ff_thread_release_buffer(s->avctx, (AVFrame*)pic);
- else
- avcodec_default_release_buffer(s->avctx, (AVFrame*)pic);
- @@ -225,37 +249,40 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
- {
- int r;
- - if (s->avctx->hwaccel) {
- + if (s->avctx->hwaccel) {
- assert(!pic->f.hwaccel_picture_private);
- - if (s->avctx->hwaccel->priv_data_size) {
- + if (s->avctx->hwaccel->priv_data_size) {
- pic->f.hwaccel_picture_private = av_mallocz(s->avctx->hwaccel->priv_data_size);
- - if (!pic->f.hwaccel_picture_private) {
- + if (!pic->f.hwaccel_picture_private) {
- av_log(s->avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n");
- return -1;
- }
- }
- }
- - if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
- + if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
- r = ff_thread_get_buffer(s->avctx, (AVFrame*)pic);
- else
- r = avcodec_default_get_buffer(s->avctx, (AVFrame*)pic);
- - if (r < 0 || !pic->f.age || !pic->f.type || !pic->f.data[0]) {
- + if (r < 0 || !pic->f.age || !pic->f.type || !pic->f.data[0]) {
- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %d %p)\n",
- r, pic->f.age, pic->f.type, pic->f.data[0]);
- av_freep(&pic->f.hwaccel_picture_private);
- return -1;
- }
- - if (s->linesize && (s->linesize != pic->f.linesize[0] || s->uvlinesize != pic->f.linesize[1])) {
- - av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n");
- + if (s->linesize && (s->linesize != pic->f.linesize[0] ||
- + s->uvlinesize != pic->f.linesize[1])) {
- + av_log(s->avctx, AV_LOG_ERROR,
- + "get_buffer() failed (stride changed)\n");
- free_frame_buffer(s, pic);
- return -1;
- }
- - if (pic->f.linesize[1] != pic->f.linesize[2]) {
- - av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n");
- + if (pic->f.linesize[1] != pic->f.linesize[2]) {
- + av_log(s->avctx, AV_LOG_ERROR,
- + "get_buffer() failed (uv stride mismatch)\n");
- free_frame_buffer(s, pic);
- return -1;
- }
- @@ -265,75 +292,97 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
- /**
- * allocates a Picture
- - * The pixels are allocated/set by calling get_buffer() if shared=0
- + * The pixels are allocated/set by calling get_buffer() if shared = 0
- */
- int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){
- - const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) does not sig11
- - const int mb_array_size= s->mb_stride*s->mb_height;
- - const int b8_array_size= s->b8_stride*s->mb_height*2;
- - const int b4_array_size= s->b4_stride*s->mb_height*4;
- + const int big_mb_num = s->mb_stride*(s->mb_height + 1) + 1;
- +
- + //the + 1 is needed so memset(,,stride*height) does not sig11
- +
- + const int mb_array_size = s->mb_stride*s->mb_height;
- + const int b8_array_size = s->b8_stride*s->mb_height*2;
- + const int b4_array_size = s->b4_stride*s->mb_height*4;
- int i;
- - int r= -1;
- + int r = -1;
- - if(shared){
- + if (shared){
- assert(pic->f.data[0]);
- assert(pic->f.type == 0 || pic->f.type == FF_BUFFER_TYPE_SHARED);
- pic->f.type = FF_BUFFER_TYPE_SHARED;
- }else{
- assert(!pic->f.data[0]);
- - if (alloc_frame_buffer(s, pic) < 0)
- + if (alloc_frame_buffer(s, pic) < 0)
- return -1;
- - s->linesize = pic->f.linesize[0];
- + s->linesize = pic->f.linesize[0];
- s->uvlinesize = pic->f.linesize[1];
- }
- - if (pic->f.qscale_table == NULL) {
- - if (s->encoding) {
- - FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_var , mb_array_size * sizeof(int16_t) , fail)
- - FF_ALLOCZ_OR_GOTO(s->avctx, pic->mc_mb_var, mb_array_size * sizeof(int16_t) , fail)
- - FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_mean , mb_array_size * sizeof(int8_t ) , fail)
- - }
- -
- - FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.mbskip_table, mb_array_size * sizeof(uint8_t) + 2, fail) //the +2 is for the slice end check
- - FF_ALLOCZ_OR_GOTO(s->avctx, pic->qscale_table_base , (big_mb_num + s->mb_stride) * sizeof(uint8_t) , fail)
- - FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_type_base , (big_mb_num + s->mb_stride) * sizeof(uint32_t), fail)
- - pic->f.mb_type = pic->mb_type_base + 2*s->mb_stride + 1;
- - pic->f.qscale_table = pic->qscale_table_base + 2*s->mb_stride + 1;
- - if(s->out_format == FMT_H264){
- - for(i=0; i<2; i++){
- - FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b4_array_size+4) * sizeof(int16_t), fail)
- - pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
- - FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail)
- + if (pic->f.qscale_table == NULL) {
- + if (s->encoding) {
- + FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_var ,
- + mb_array_size * sizeof(int16_t) , fail)
- + FF_ALLOCZ_OR_GOTO(s->avctx, pic->mc_mb_var,
- + mb_array_size * sizeof(int16_t) , fail)
- + FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_mean ,
- + mb_array_size * sizeof(int8_t ) , fail)
- + }
- +
- + FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.mbskip_table,
- + mb_array_size * sizeof(uint8_t) + 2, fail)
- + //the + 2 is for the slice end check
- + FF_ALLOCZ_OR_GOTO(s->avctx, pic->qscale_table_base ,
- + (big_mb_num + s->mb_stride) * sizeof(uint8_t),
- + fail)
- + FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_type_base ,
- + (big_mb_num + s->mb_stride) * sizeof(uint32_t),
- + fail)
- + pic->f.mb_type = pic->mb_type_base + 2*s->mb_stride + 1;
- + pic->f.qscale_table = pic->qscale_table_base + 2*s->mb_stride + 1;
- + if (s->out_format == FMT_H264){
- + for (i = 0; i < 2; i++ ){
- + FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 *
- + (b4_array_size + 4) * sizeof(int16_t), fail)
- + pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
- + FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.ref_index[i], 4*mb_array_size *
- + sizeof(uint8_t), fail)
- }
- pic->f.motion_subsample_log2 = 2;
- - }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){
- - for(i=0; i<2; i++){
- - FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b8_array_size+4) * sizeof(int16_t), fail)
- - pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
- - FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail)
- + }else if (s->out_format == FMT_H263 || s->encoding ||
- + (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){
- + for (i = 0; i < 2; i++ ){
- + FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 *
- + (b8_array_size + 4) * sizeof(int16_t), fail)
- + pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
- + FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.ref_index[i],
- + 4*mb_array_size * sizeof(uint8_t), fail)
- }
- pic->f.motion_subsample_log2 = 3;
- }
- - if(s->avctx->debug&FF_DEBUG_DCT_COEFF) {
- - FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.dct_coeff, 64 * mb_array_size * sizeof(DCTELEM) * 6, fail)
- + if (s->avctx->debug&FF_DEBUG_DCT_COEFF) {
- + FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.dct_coeff, 64 * mb_array_size *
- + sizeof(DCTELEM) * 6, fail)
- }
- pic->f.qstride = s->mb_stride;
- - FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.pan_scan , 1 * sizeof(AVPanScan), fail)
- + FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.pan_scan , 1 *
- + sizeof(AVPanScan), fail)
- }
- - /* It might be nicer if the application would keep track of these
- + /* It might be nicer if the application would keep track of these
- * but it would require an API change. */
- - memmove(s->prev_pict_types+1, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE-1);
- - s->prev_pict_types[0]= s->dropable ? AV_PICTURE_TYPE_B : s->pict_type;
- - if (pic->f.age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->f.age] == AV_PICTURE_TYPE_B)
- - pic->f.age = INT_MAX; // Skipped MBs in B-frames are quite rare in MPEG-1/2 and it is a bit tricky to skip them anyway.
- + memmove(s->prev_pict_types + 1, s->prev_pict_types,
- + PREV_PICT_TYPES_BUFFER_SIZE-1);
- + s->prev_pict_types[0] = s->dropable ? AV_PICTURE_TYPE_B : s->pict_type;
- + if (pic->f.age < PREV_PICT_TYPES_BUFFER_SIZE &&
- + s->prev_pict_types[pic->f.age] == AV_PICTURE_TYPE_B)
- + pic->f.age = INT_MAX; // Skipped MBs in B-frames are quite rare in MPEG-1/2
- + // and it is a bit tricky to skip them anyway.
- pic->owner2 = s;
- return 0;
- -fail: //for the FF_ALLOCZ_OR_GOTO macro
- - if(r>=0)
- +fail: //for the FF_ALLOCZ_OR_GOTO macro
- + if (r> = 0)
- free_frame_buffer(s, pic);
- return -1;
- }
- @@ -344,7 +393,7 @@ fail: //for the FF_ALLOCZ_OR_GOTO macro
- static void free_picture(MpegEncContext *s, Picture *pic){
- int i;
- - if (pic->f.data[0] && pic->f.type != FF_BUFFER_TYPE_SHARED) {
- + if (pic->f.data[0] && pic->f.type != FF_BUFFER_TYPE_SHARED) {
- free_frame_buffer(s, pic);
- }
- @@ -357,14 +406,14 @@ static void free_picture(MpegEncContext *s, Picture *pic){
- av_freep(&pic->f.dct_coeff);
- av_freep(&pic->f.pan_scan);
- pic->f.mb_type = NULL;
- - for(i=0; i<2; i++){
- + for (i = 0; i < 2; i++ ){
- av_freep(&pic->motion_val_base[i]);
- av_freep(&pic->f.ref_index[i]);
- }
- - if (pic->f.type == FF_BUFFER_TYPE_SHARED) {
- - for(i=0; i<4; i++){
- - pic->f.base[i] =
- + if (pic->f.type == FF_BUFFER_TYPE_SHARED) {
- + for (i = 0; i < 4; i++ ){
- + pic->f.base[i] =
- pic->f.data[i] = NULL;
- }
- pic->f.type = 0;
- @@ -372,40 +421,49 @@ static void free_picture(MpegEncContext *s, Picture *pic){
- }
- static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){
- - int y_size = s->b8_stride * (2 * s->mb_height + 1);
- - int c_size = s->mb_stride * (s->mb_height + 1);
- - int yc_size = y_size + 2 * c_size;
- + int y_size = s->b8_stride * (2 * s->mb_height + 1);
- + int c_size = s->mb_stride * (s->mb_height + 1);
- + int yc_size = y_size + 2 * c_size;
- int i;
- - // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264)
- - FF_ALLOCZ_OR_GOTO(s->avctx, s->edge_emu_buffer, (s->width+64)*2*21*2, fail); //(width + edge + align)*interlaced*MBsize*tolerance
- -
- - //FIXME should be linesize instead of s->width*2 but that is not known before get_buffer()
- - FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t), fail)
- - s->me.temp= s->me.scratchpad;
- - s->rd_scratchpad= s->me.scratchpad;
- - s->b_scratchpad= s->me.scratchpad;
- - s->obmc_scratchpad= s->me.scratchpad + 16;
- - if (s->encoding) {
- - FF_ALLOCZ_OR_GOTO(s->avctx, s->me.map , ME_MAP_SIZE*sizeof(uint32_t), fail)
- - FF_ALLOCZ_OR_GOTO(s->avctx, s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t), fail)
- - if(s->avctx->noise_reduction){
- - FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_error_sum, 2 * 64 * sizeof(int), fail)
- + // edge emu needs blocksize + filter length - 1
- + //( = 17x17 for halfpel / 21x21 for h264)
- + FF_ALLOCZ_OR_GOTO(s->avctx, s->edge_emu_buffer,
- + (s->width + 64)*2*21*2, fail);
- + //(width + edge + align)*interlaced*MBsize*tolerance
- +
- + // FIXME should be linesize instead of s->width*2
- + // but that is not known befor e get_buffer()
- + FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad,
- +
Add Comment
Please, Sign In to add comment