diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-01-08 01:29:15 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-01-08 03:34:22 +0100 |
commit | 757473831c3e1cc231fb985bcaed622d66fd6b2e (patch) | |
tree | d3c83c1e3726c24b91bf9970b06fd1a83921fff0 /libavcodec | |
parent | a407baba85c2999707868e975c98b5a9de50f46d (diff) | |
parent | badb195d139f15dc189dd3f78930c9cbfce89c24 (diff) | |
download | ffmpeg-757473831c3e1cc231fb985bcaed622d66fd6b2e.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master: (29 commits)
cabac: Move code only used within the CABAC test program into the test program.
vp56: Drop unnecessary cabac.h #include.
h264-test: Initialize AVCodecContext.av_class.
build: Skip compiling network.h and rtsp.h if networking is not enabled.
cosmetics: drop some pointless parentheses
Disable annoying warning without changing behavior
faq: Solutions for common problems with sample paths when running FATE.
avcodec: attempt to clarify the CODEC_CAP_DELAY documentation
avcodec: fix avcodec_encode_audio() documentation.
FATE: xmv-demux test; exercise the XMV demuxer without decoding the perceptual codecs inside.
vqf: recognize more metadata chunks
FATE test: BMV demuxer and associated video and audio decoders.
FATE: indeo4 video decoder test.
FATE: update xxan-wc4 test to a sample with more code coverage.
Change the recent h264_mp4toannexb bitstream filter test to output to an elementary stream rather than a program stream.
g722enc: validate AVCodecContext.trellis
g722enc: set frame_size, and also handle an odd number of input samples
g722enc: split encoding into separate functions for trellis vs. no trellis
mpegaudiodec: Use clearer pointer math
tta: Fix returned error code at EOF
...
Conflicts:
libavcodec/h264.c
libavcodec/indeo3.c
libavcodec/interplayvideo.c
libavcodec/ivi_common.c
libavcodec/libxvidff.c
libavcodec/mpegvideo.c
libavcodec/ppc/mpegvideo_altivec.c
libavcodec/tta.c
libavcodec/utils.c
libavfilter/vsrc_buffer.c
libavformat/Makefile
tests/fate/indeo.mak
tests/ref/acodec/g722
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/ac3dec.c | 4 | ||||
-rw-r--r-- | libavcodec/avcodec.h | 31 | ||||
-rw-r--r-- | libavcodec/cabac.c | 25 | ||||
-rw-r--r-- | libavcodec/cabac.h | 25 | ||||
-rw-r--r-- | libavcodec/cavs.c | 4 | ||||
-rw-r--r-- | libavcodec/cavsdec.c | 2 | ||||
-rw-r--r-- | libavcodec/error_resilience.c | 8 | ||||
-rw-r--r-- | libavcodec/g722enc.c | 103 | ||||
-rw-r--r-- | libavcodec/h264.c | 1 | ||||
-rw-r--r-- | libavcodec/indeo3.c | 24 | ||||
-rw-r--r-- | libavcodec/interplayvideo.c | 9 | ||||
-rw-r--r-- | libavcodec/ivi_common.c | 2 | ||||
-rw-r--r-- | libavcodec/libdiracenc.c | 6 | ||||
-rw-r--r-- | libavcodec/libschroedingerenc.c | 2 | ||||
-rw-r--r-- | libavcodec/libxvidff.c | 6 | ||||
-rw-r--r-- | libavcodec/mpeg12.c | 2 | ||||
-rw-r--r-- | libavcodec/mpegvideo.c | 12 | ||||
-rw-r--r-- | libavcodec/ppc/mpegvideo_altivec.c | 10 | ||||
-rw-r--r-- | libavcodec/pthread.c | 2 | ||||
-rw-r--r-- | libavcodec/tscc.c | 10 | ||||
-rw-r--r-- | libavcodec/tta.c | 6 | ||||
-rw-r--r-- | libavcodec/utils.c | 84 | ||||
-rw-r--r-- | libavcodec/vc1dec.c | 2 | ||||
-rw-r--r-- | libavcodec/vorbisdec.c | 7 | ||||
-rw-r--r-- | libavcodec/vp56.h | 1 | ||||
-rw-r--r-- | libavcodec/zmbv.c | 6 | ||||
-rw-r--r-- | libavcodec/zmbvenc.c | 6 |
27 files changed, 247 insertions, 153 deletions
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index 0cb7c67a1f..325d23bb3d 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -223,7 +223,7 @@ static int ac3_parse_header(AC3DecodeContext *s) int i; /* read the rest of the bsi. read twice for dual mono mode. */ - i = !(s->channel_mode); + i = !s->channel_mode; do { skip_bits(gbc, 5); // skip dialog normalization if (get_bits1(gbc)) @@ -792,7 +792,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) } /* dynamic range */ - i = !(s->channel_mode); + i = !s->channel_mode; do { if (get_bits1(gbc)) { s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)] - 1.0) * diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 2b7ac65c13..69e541a8f0 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -745,10 +745,22 @@ typedef struct RcOverride{ /* Codec can export data for HW decoding (XvMC). */ #define CODEC_CAP_HWACCEL 0x0010 /** - * Codec has a nonzero delay and needs to be fed with avpkt->data=NULL, + * Encoder or decoder requires flushing with NULL input at the end in order to + * give the complete and correct output. + * + * NOTE: If this flag is not set, the codec is guaranteed to never be fed with + * with NULL data. The user can still send NULL data to the public encode + * or decode function, but libavcodec will not pass it along to the codec + * unless this flag is set. + * + * Decoders: + * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL, * avpkt->size=0 at the end to get the delayed data until the decoder no longer - * returns frames. If this is not set, the codec is guaranteed to never be fed - * with NULL data. + * returns frames. + * + * Encoders: + * The encoder needs to be fed with NULL data at the end of encoding until the + * encoder no longer returns data. */ #define CODEC_CAP_DELAY 0x0020 /** @@ -4318,9 +4330,9 @@ void avsubtitle_free(AVSubtitle *sub); * Encode an audio frame from samples into buf. * * @note The output buffer should be at least FF_MIN_BUFFER_SIZE bytes large. - * However, for PCM audio the user will know how much space is needed - * because it depends on the value passed in buf_size as described - * below. In that case a lower value can be used. + * However, for codecs with avctx->frame_size equal to 0 (e.g. PCM) the user + * will know how much space is needed because it depends on the value passed + * in buf_size as described below. In that case a lower value can be used. * * @param avctx the codec context * @param[out] buf the output buffer @@ -4328,8 +4340,11 @@ void avsubtitle_free(AVSubtitle *sub); * @param[in] samples the input buffer containing the samples * The number of samples read from this buffer is frame_size*channels, * both of which are defined in avctx. - * For PCM audio the number of samples read from samples is equal to - * buf_size * input_sample_size / output_sample_size. + * For codecs which have avctx->frame_size equal to 0 (e.g. PCM) the number of + * samples read from samples is equal to: + * buf_size * 8 / (avctx->channels * av_get_bits_per_sample(avctx->codec_id)) + * This also implies that av_get_bits_per_sample() must not return 0 for these + * codecs. * @return On error a negative value is returned, on success zero or the number * of bytes used to encode the data read from the input buffer. */ diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c index c603dafddd..983614581d 100644 --- a/libavcodec/cabac.c +++ b/libavcodec/cabac.c @@ -166,6 +166,31 @@ void ff_init_cabac_states(CABACContext *c){ #include "avcodec.h" #include "cabac.h" +static inline void put_cabac_bit(CABACContext *c, int b){ + put_bits(&c->pb, 1, b); + for(;c->outstanding_count; c->outstanding_count--){ + put_bits(&c->pb, 1, 1-b); + } +} + +static inline void renorm_cabac_encoder(CABACContext *c){ + while(c->range < 0x100){ + //FIXME optimize + if(c->low<0x100){ + put_cabac_bit(c, 0); + }else if(c->low<0x200){ + c->outstanding_count++; + c->low -= 0x100; + }else{ + put_cabac_bit(c, 1); + c->low -= 0x200; + } + + c->range+= c->range; + c->low += c->low; + } +} + static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state]; diff --git a/libavcodec/cabac.h b/libavcodec/cabac.h index 0ee8e315f4..8065ae0f45 100644 --- a/libavcodec/cabac.h +++ b/libavcodec/cabac.h @@ -62,31 +62,6 @@ void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size); void ff_init_cabac_states(CABACContext *c); -static inline void put_cabac_bit(CABACContext *c, int b){ - put_bits(&c->pb, 1, b); - for(;c->outstanding_count; c->outstanding_count--){ - put_bits(&c->pb, 1, 1-b); - } -} - -static inline void renorm_cabac_encoder(CABACContext *c){ - while(c->range < 0x100){ - //FIXME optimize - if(c->low<0x100){ - put_cabac_bit(c, 0); - }else if(c->low<0x200){ - c->outstanding_count++; - c->low -= 0x100; - }else{ - put_cabac_bit(c, 1); - c->low -= 0x200; - } - - c->range+= c->range; - c->low += c->low; - } -} - static void refill(CABACContext *c){ #if CABAC_BITS == 16 c->low+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1); diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c index 47fc5a5da8..adaf797cde 100644 --- a/libavcodec/cavs.c +++ b/libavcodec/cavs.c @@ -658,8 +658,8 @@ void ff_cavs_init_top_lines(AVSContext *h) { h->top_mv[1] = av_malloc((h->mb_width*2+1)*sizeof(cavs_vector)); h->top_pred_Y = av_malloc( h->mb_width*2*sizeof(*h->top_pred_Y)); h->top_border_y = av_malloc((h->mb_width+1)*16); - h->top_border_u = av_malloc((h->mb_width)*10); - h->top_border_v = av_malloc((h->mb_width)*10); + h->top_border_u = av_malloc( h->mb_width * 10); + h->top_border_v = av_malloc( h->mb_width * 10); /* alloc space for co-located MVs and types */ h->col_mv = av_malloc( h->mb_width*h->mb_height*4*sizeof(cavs_vector)); diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index 2bf968ba22..16e5474d84 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -491,7 +491,7 @@ static int decode_pic(AVSContext *h) { skip_bits(&s->gb,24);//time_code /* old sample clips were all progressive and no low_delay, bump stream revision if detected otherwise */ - if((s->low_delay) || !(show_bits(&s->gb,9) & 1)) + if (s->low_delay || !(show_bits(&s->gb,9) & 1)) h->stream_revision = 1; /* similarly test top_field_first and repeat_first_field */ else if(show_bits(&s->gb,11) & 3) diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c index 638215f7d8..d296a78148 100644 --- a/libavcodec/error_resilience.c +++ b/libavcodec/error_resilience.c @@ -109,8 +109,8 @@ static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t for(y=0; y<8; y++){ int x; for(x=0; x<8; x++){ - dest_cb[x + y*(s->uvlinesize)]= dcu/8; - dest_cr[x + y*(s->uvlinesize)]= dcv/8; + dest_cb[x + y * s->uvlinesize] = dcu / 8; + dest_cr[x + y * s->uvlinesize] = dcv / 8; } } } @@ -1120,8 +1120,8 @@ void ff_er_frame_end(MpegEncContext *s){ for(y=0; y<8; y++){ int x; for(x=0; x<8; x++){ - dcu+=dest_cb[x + y*(s->uvlinesize)]; - dcv+=dest_cr[x + y*(s->uvlinesize)]; + dcu += dest_cb[x + y * s->uvlinesize]; + dcv += dest_cr[x + y * s->uvlinesize]; } } s->dc_val[1][mb_x + mb_y*s->mb_stride]= (dcu+4)>>3; diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c index 1eed784a72..1cb0070649 100644 --- a/libavcodec/g722enc.c +++ b/libavcodec/g722enc.c @@ -32,6 +32,15 @@ #define FREEZE_INTERVAL 128 +/* This is an arbitrary value. Allowing insanely large values leads to strange + problems, so we limit it to a reasonable value */ +#define MAX_FRAME_SIZE 32768 + +/* We clip the value of avctx->trellis to prevent data type overflows and + undefined behavior. Using larger values is insanely slow anyway. */ +#define MIN_TRELLIS 0 +#define MAX_TRELLIS 16 + static av_cold int g722_encode_init(AVCodecContext * avctx) { G722Context *c = avctx->priv_data; @@ -56,6 +65,40 @@ static av_cold int g722_encode_init(AVCodecContext * avctx) } } + if (avctx->frame_size) { + /* validate frame size */ + if (avctx->frame_size & 1 || avctx->frame_size > MAX_FRAME_SIZE) { + int new_frame_size; + + if (avctx->frame_size == 1) + new_frame_size = 2; + else if (avctx->frame_size > MAX_FRAME_SIZE) + new_frame_size = MAX_FRAME_SIZE; + else + new_frame_size = avctx->frame_size - 1; + + av_log(avctx, AV_LOG_WARNING, "Requested frame size is not " + "allowed. Using %d instead of %d\n", new_frame_size, + avctx->frame_size); + avctx->frame_size = new_frame_size; + } + } else { + /* This is arbitrary. We use 320 because it's 20ms @ 16kHz, which is + a common packet size for VoIP applications */ + avctx->frame_size = 320; + } + + if (avctx->trellis) { + /* validate trellis */ + if (avctx->trellis < MIN_TRELLIS || avctx->trellis > MAX_TRELLIS) { + int new_trellis = av_clip(avctx->trellis, MIN_TRELLIS, MAX_TRELLIS); + av_log(avctx, AV_LOG_WARNING, "Requested trellis value is not " + "allowed. Using %d instead of %d\n", new_trellis, + avctx->trellis); + avctx->trellis = new_trellis; + } + } + return 0; } @@ -117,13 +160,12 @@ static inline int encode_low(const struct G722Band* state, int xlow) return (diff < 0 ? (i < 2 ? 63 : 33) : 61) - i; } -static int g722_encode_trellis(AVCodecContext *avctx, - uint8_t *dst, int buf_size, void *data) +static void g722_encode_trellis(G722Context *c, int trellis, + uint8_t *dst, int nb_samples, + const int16_t *samples) { - G722Context *c = avctx->priv_data; - const int16_t *samples = data; int i, j, k; - int frontier = 1 << avctx->trellis; + int frontier = 1 << trellis; struct TrellisNode **nodes[2]; struct TrellisNode **nodes_next[2]; int pathn[2] = {0, 0}, froze = -1; @@ -139,7 +181,7 @@ static int g722_encode_trellis(AVCodecContext *avctx, nodes[i][0]->state = c->band[i]; } - for (i = 0; i < buf_size; i++) { + for (i = 0; i < nb_samples >> 1; i++) { int xlow, xhigh; struct TrellisNode *next[2]; int heap_pos[2] = {0, 0}; @@ -271,8 +313,28 @@ static int g722_encode_trellis(AVCodecContext *avctx, } c->band[0] = nodes[0][0]->state; c->band[1] = nodes[1][0]->state; +} + +static av_always_inline void encode_byte(G722Context *c, uint8_t *dst, + const int16_t *samples) +{ + int xlow, xhigh, ilow, ihigh; + filter_samples(c, samples, &xlow, &xhigh); + ihigh = encode_high(&c->band[1], xhigh); + ilow = encode_low (&c->band[0], xlow); + ff_g722_update_high_predictor(&c->band[1], c->band[1].scale_factor * + ff_g722_high_inv_quant[ihigh] >> 10, ihigh); + ff_g722_update_low_predictor(&c->band[0], ilow >> 2); + *dst = ihigh << 6 | ilow; +} - return i; +static void g722_encode_no_trellis(G722Context *c, + uint8_t *dst, int nb_samples, + const int16_t *samples) +{ + int i; + for (i = 0; i < nb_samples; i += 2) + encode_byte(c, dst++, &samples[i]); } static int g722_encode_frame(AVCodecContext *avctx, @@ -280,22 +342,22 @@ static int g722_encode_frame(AVCodecContext *avctx, { G722Context *c = avctx->priv_data; const int16_t *samples = data; - int i; + int nb_samples; - if (avctx->trellis) - return g722_encode_trellis(avctx, dst, buf_size, data); + nb_samples = avctx->frame_size - (avctx->frame_size & 1); - for (i = 0; i < buf_size; i++) { - int xlow, xhigh, ihigh, ilow; - filter_samples(c, &samples[2*i], &xlow, &xhigh); - ihigh = encode_high(&c->band[1], xhigh); - ilow = encode_low(&c->band[0], xlow); - ff_g722_update_high_predictor(&c->band[1], c->band[1].scale_factor * - ff_g722_high_inv_quant[ihigh] >> 10, ihigh); - ff_g722_update_low_predictor(&c->band[0], ilow >> 2); - *dst++ = ihigh << 6 | ilow; + if (avctx->trellis) + g722_encode_trellis(c, avctx->trellis, dst, nb_samples, samples); + else + g722_encode_no_trellis(c, dst, nb_samples, samples); + + /* handle last frame with odd frame_size */ + if (nb_samples < avctx->frame_size) { + int16_t last_samples[2] = { samples[nb_samples], samples[nb_samples] }; + encode_byte(c, &dst[nb_samples >> 1], last_samples); } - return i; + + return (avctx->frame_size + 1) >> 1; } AVCodec ff_adpcm_g722_encoder = { @@ -306,6 +368,7 @@ AVCodec ff_adpcm_g722_encoder = { .init = g722_encode_init, .close = g722_encode_close, .encode = g722_encode_frame, + .capabilities = CODEC_CAP_SMALL_LAST_FRAME, .long_name = NULL_IF_CONFIG_SMALL("G.722 ADPCM"), .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, }; diff --git a/libavcodec/h264.c b/libavcodec/h264.c index e4d6ee10a9..98eac17f66 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -4170,7 +4170,6 @@ int main(void){ uint8_t temp[SIZE]; PutBitContext pb; GetBitContext gb; -// int int_temp[10000]; DSPContext dsp; AVCodecContext avctx; diff --git a/libavcodec/indeo3.c b/libavcodec/indeo3.c index 83c97bb96d..ce84d72f8b 100644 --- a/libavcodec/indeo3.c +++ b/libavcodec/indeo3.c @@ -89,6 +89,7 @@ typedef struct Indeo3DecodeContext { const uint8_t *next_cell_data; const uint8_t *last_byte; const int8_t *mc_vectors; + unsigned num_vectors; ///< number of motion vectors in mc_vectors int16_t width, height; uint32_t frame_num; ///< current frame number (zero-based) @@ -767,11 +768,17 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx, break; case INTER_DATA: if (!curr_cell.tree) { /* MC tree INTER code */ + unsigned mv_idx; /* get motion vector index and setup the pointer to the mv set */ if (!ctx->need_resync) ctx->next_cell_data = &ctx->gb.buffer[(get_bits_count(&ctx->gb) + 7) >> 3]; if(ctx->mc_vectors) - curr_cell.mv_ptr = &ctx->mc_vectors[*(ctx->next_cell_data++) << 1]; + mv_idx = *(ctx->next_cell_data++) << 1; + if (mv_idx >= ctx->num_vectors) { + av_log(avctx, AV_LOG_ERROR, "motion vector index out of range\n"); + return AVERROR_INVALIDDATA; + } + curr_cell.mv_ptr = &ctx->mc_vectors[mv_idx]; curr_cell.tree = 1; /* enter the VQ tree */ UPDATE_BITPOS(8); } else { /* VQ tree DATA code */ @@ -801,19 +808,24 @@ static int decode_plane(Indeo3DecodeContext *ctx, AVCodecContext *avctx, int32_t strip_width) { Cell curr_cell; - uint32_t num_vectors; + unsigned num_vectors; /* each plane data starts with mc_vector_count field, */ /* an optional array of motion vectors followed by the vq data */ num_vectors = bytestream_get_le32(&data); - if(num_vectors >= data_size/2) + if (num_vectors > 256) { + av_log(ctx->avctx, AV_LOG_ERROR, + "Read invalid number of motion vectors %d\n", num_vectors); return AVERROR_INVALIDDATA; + } + if (num_vectors * 2 >= data_size) + return AVERROR_INVALIDDATA; + + ctx->num_vectors = num_vectors; ctx->mc_vectors = num_vectors ? data : 0; - data += num_vectors * 2; - data_size-= num_vectors * 2; /* init the bitreader */ - init_get_bits(&ctx->gb, data, data_size << 3); + init_get_bits(&ctx->gb, &data[num_vectors * 2], (data_size - num_vectors * 2) << 3); ctx->skip_bits = 0; ctx->need_resync = 0; diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c index d27c9ba9c7..68aa966208 100644 --- a/libavcodec/interplayvideo.c +++ b/libavcodec/interplayvideo.c @@ -1019,12 +1019,10 @@ static av_cold int ipvideo_decode_init(AVCodecContext *avctx) dsputil_init(&s->dsp, avctx); - /* decoding map contains 4 bits of information per 8x8 block */ - s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2); - avcodec_get_frame_defaults(&s->second_last_frame); avcodec_get_frame_defaults(&s->last_frame); avcodec_get_frame_defaults(&s->current_frame); + s->current_frame.data[0] = s->last_frame.data[0] = s->second_last_frame.data[0] = NULL; @@ -1039,6 +1037,9 @@ static int ipvideo_decode_frame(AVCodecContext *avctx, int buf_size = avpkt->size; IpvideoContext *s = avctx->priv_data; + /* decoding map contains 4 bits of information per 8x8 block */ + s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2); + /* compressed buffer needs to be large enough to at least hold an entire * decoding map */ if (buf_size < s->decoding_map_size) @@ -1099,6 +1100,6 @@ AVCodec ff_interplay_video_decoder = { .init = ipvideo_decode_init, .close = ipvideo_decode_end, .decode = ipvideo_decode_frame, - .capabilities = CODEC_CAP_DR1, + .capabilities = CODEC_CAP_DR1 | CODEC_CAP_PARAM_CHANGE, .long_name = NULL_IF_CONFIG_SMALL("Interplay MVE video"), }; diff --git a/libavcodec/ivi_common.c b/libavcodec/ivi_common.c index f917b3a826..c75769ec31 100644 --- a/libavcodec/ivi_common.c +++ b/libavcodec/ivi_common.c @@ -613,7 +613,7 @@ void ff_ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch) const int16_t *src = plane->bands[0].buf; uint32_t pitch = plane->bands[0].pitch; - if(!src) + if (!src) return; for (y = 0; y < plane->height; y++) { diff --git a/libavcodec/libdiracenc.c b/libavcodec/libdiracenc.c index cd0b131745..385bce9018 100644 --- a/libavcodec/libdiracenc.c +++ b/libavcodec/libdiracenc.c @@ -136,7 +136,7 @@ static av_cold int libdirac_encode_init(AVCodecContext *avccontext) preset = GetDiracVideoFormatPreset(avccontext); /* initialize the encoder context */ - dirac_encoder_context_init(&(p_dirac_params->enc_ctx), preset); + dirac_encoder_context_init(&p_dirac_params->enc_ctx, preset); p_dirac_params->enc_ctx.src_params.chroma = GetDiracChromaFormat(avccontext->pix_fmt); @@ -199,7 +199,7 @@ static av_cold int libdirac_encode_init(AVCodecContext *avccontext) * irrespective of the type of source material */ p_dirac_params->enc_ctx.enc_params.picture_coding_mode = 1; - p_dirac_params->p_encoder = dirac_encoder_init(&(p_dirac_params->enc_ctx), + p_dirac_params->p_encoder = dirac_encoder_init(&p_dirac_params->enc_ctx, verbose); if (!p_dirac_params->p_encoder) { @@ -221,7 +221,7 @@ static void DiracFreeFrame(void *data) { DiracSchroEncodedFrame *enc_frame = data; - av_freep(&(enc_frame->p_encbuf)); + av_freep(&enc_frame->p_encbuf); av_free(enc_frame); } diff --git a/libavcodec/libschroedingerenc.c b/libavcodec/libschroedingerenc.c index 96a9812233..27267cd0e9 100644 --- a/libavcodec/libschroedingerenc.c +++ b/libavcodec/libschroedingerenc.c @@ -258,7 +258,7 @@ static void SchroedingerFreeFrame(void *data) { DiracSchroEncodedFrame *enc_frame = data; - av_freep(&(enc_frame->p_encbuf)); + av_freep(&enc_frame->p_encbuf); av_free(enc_frame); } diff --git a/libavcodec/libxvidff.c b/libavcodec/libxvidff.c index f7aa7fd44e..1501b44135 100644 --- a/libavcodec/libxvidff.c +++ b/libavcodec/libxvidff.c @@ -232,7 +232,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { rc2pass2.version = XVID_VERSION; rc2pass2.bitrate = avctx->bit_rate; - fd = av_tempfile("xvidff.", &(x->twopassfile), 0, avctx); + fd = av_tempfile("xvidff.", &x->twopassfile, 0, avctx); if( fd == -1 ) { av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot write 2-pass pipe\n"); @@ -376,7 +376,7 @@ static int xvid_encode_frame(AVCodecContext *avctx, char *tmp; struct xvid_context *x = avctx->priv_data; AVFrame *picture = data; - AVFrame *p = &(x->encoded_picture); + AVFrame *p = &x->encoded_picture; xvid_enc_frame_t xvid_enc_frame; xvid_enc_stats_t xvid_enc_stats; @@ -538,7 +538,7 @@ int xvid_strip_vol_header(AVCodecContext *avctx, } /* Less dangerous now, memmove properly copies the two chunks of overlapping data */ - memmove(frame, &(frame[vo_len]), frame_len - vo_len); + memmove(frame, &frame[vo_len], frame_len - vo_len); return frame_len - vo_len; } else return frame_len; diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index fcbea5429d..2677713cce 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1273,7 +1273,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx) /* low_delay may be forced, in this case we will have B-frames * that behave like P-frames. */ - avctx->has_b_frames = !(s->low_delay); + avctx->has_b_frames = !s->low_delay; assert((avctx->sub_id == 1) == (avctx->codec_id == CODEC_ID_MPEG1VIDEO)); if (avctx->codec_id == CODEC_ID_MPEG1VIDEO) { diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 90eb737ec7..490a7cc751 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -704,9 +704,9 @@ av_cold int MPV_common_init(MpegEncContext *s) mb_array_size = s->mb_height * s->mb_stride; mv_table_size = (s->mb_height + 2) * s->mb_stride + 1; - /* set chroma shifts */ - avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift), - &(s->chroma_y_shift) ); + /* set chroma shifts */ + avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &s->chroma_x_shift, + &s->chroma_y_shift); /* set default edge pos, will be overriden in decode_header if needed */ s->h_edge_pos = s->mb_width * 16; @@ -2318,7 +2318,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], } dct_linesize = linesize << s->interlaced_dct; - dct_offset =(s->interlaced_dct)? linesize : linesize*block_size; + dct_offset = s->interlaced_dct ? linesize : linesize * block_size; if(readable){ dest_y= s->dest[0]; @@ -2414,7 +2414,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], }else{ //chroma422 dct_linesize = uvlinesize << s->interlaced_dct; - dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*block_size; + dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size; add_dct(s, block[4], 4, dest_cb, dct_linesize); add_dct(s, block[5], 5, dest_cr, dct_linesize); @@ -2466,7 +2466,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM 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]); diff --git a/libavcodec/ppc/mpegvideo_altivec.c b/libavcodec/ppc/mpegvideo_altivec.c index 0ba532ec26..297e7fefce 100644 --- a/libavcodec/ppc/mpegvideo_altivec.c +++ b/libavcodec/ppc/mpegvideo_altivec.c @@ -269,14 +269,14 @@ static int dct_quantize_altivec(MpegEncContext* s, if(n<4){ qmat = (vector signed int*)s->q_intra_matrix[qscale]; - biasAddr = &(s->intra_quant_bias); + biasAddr = &s->intra_quant_bias; }else{ qmat = (vector signed int*)s->q_chroma_intra_matrix[qscale]; - biasAddr = &(s->intra_quant_bias); + biasAddr = &s->intra_quant_bias; } } else { qmat = (vector signed int*)s->q_inter_matrix[qscale]; - biasAddr = &(s->inter_quant_bias); + biasAddr = &s->inter_quant_bias; } // Load the bias vector (We add 0.5 to the bias so that we're @@ -366,8 +366,8 @@ static int dct_quantize_altivec(MpegEncContext* s, vector signed int max_q_int, min_q_int; vector signed short max_q, min_q; - LOAD4(max_q_int, &(s->max_qcoeff)); - LOAD4(min_q_int, &(s->min_qcoeff)); + LOAD4(max_q_int, &s->max_qcoeff); + LOAD4(min_q_int, &s->min_qcoeff); max_q = vec_pack(max_q_int, max_q_int); min_q = vec_pack(min_q_int, min_q_int); diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index d545f140ac..fe3dbdad5a 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -845,7 +845,7 @@ static int frame_thread_init(AVCodecContext *avctx) err = AVERROR(ENOMEM); goto error; } - *(copy->internal) = *(src->internal); + *copy->internal = *src->internal; copy->internal->is_copy = 1; if (codec->init_thread_copy) diff --git a/libavcodec/tscc.c b/libavcodec/tscc.c index 16b987e7c7..c07f3a87f7 100644 --- a/libavcodec/tscc.c +++ b/libavcodec/tscc.c @@ -88,7 +88,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac return -1; } - zret = inflateReset(&(c->zstream)); + zret = inflateReset(&c->zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); return -1; @@ -97,7 +97,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac c->zstream.avail_in = len; c->zstream.next_out = c->decomp_buf; c->zstream.avail_out = c->decomp_size; - zret = inflate(&(c->zstream), Z_FINISH); + zret = inflate(&c->zstream, Z_FINISH); // Z_DATA_ERROR means empty picture if ((zret != Z_OK) && (zret != Z_STREAM_END) && (zret != Z_DATA_ERROR)) { av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); @@ -144,7 +144,7 @@ static av_cold int decode_init(AVCodecContext *avctx) avcodec_get_frame_defaults(&c->pic); // Needed if zlib unused or init aborted before inflateInit - memset(&(c->zstream), 0, sizeof(z_stream)); + memset(&c->zstream, 0, sizeof(z_stream)); switch(avctx->bits_per_coded_sample){ case 8: avctx->pix_fmt = PIX_FMT_PAL8; break; case 16: avctx->pix_fmt = PIX_FMT_RGB555; break; @@ -170,7 +170,7 @@ static av_cold int decode_init(AVCodecContext *avctx) c->zstream.zalloc = Z_NULL; c->zstream.zfree = Z_NULL; c->zstream.opaque = Z_NULL; - zret = inflateInit(&(c->zstream)); + zret = inflateInit(&c->zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); return 1; @@ -194,7 +194,7 @@ static av_cold int decode_end(AVCodecContext *avctx) if (c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); - inflateEnd(&(c->zstream)); + inflateEnd(&c->zstream); return 0; } diff --git a/libavcodec/tta.c b/libavcodec/tta.c index a388cfde96..857b895e7a 100644 --- a/libavcodec/tta.c +++ b/libavcodec/tta.c @@ -324,6 +324,10 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, return ret; } + // decode directly to output buffer for 24-bit sample format + if (s->bps == 3) + s->decode_buffer = s->frame.data[0]; + // init per channel states for (i = 0; i < s->channels; i++) { s->ch_ctx[i].predictor = 0; @@ -429,7 +433,7 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, // shift samples for 24-bit sample format int32_t *samples = (int32_t *)s->frame.data[0]; for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) - *samples++ = *p<<8; + *samples++ <<= 8; // reset decode buffer s->decode_buffer = NULL; break; diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 619b70f3fb..b79e23e1c1 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -935,6 +935,48 @@ static int64_t guess_correct_pts(AVCodecContext *ctx, return pts; } +static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt) +{ + int size = 0; + const uint8_t *data; + uint32_t flags; + + if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE)) + return; + + data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size); + if (!data || size < 4) + return; + flags = bytestream_get_le32(&data); + size -= 4; + if (size < 4) /* Required for any of the changes */ + return; + if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) { + avctx->channels = bytestream_get_le32(&data); + size -= 4; + } + if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) { + if (size < 8) + return; + avctx->channel_layout = bytestream_get_le64(&data); + size -= 8; + } + if (size < 4) + return; + if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) { + avctx->sample_rate = bytestream_get_le32(&data); + size -= 4; + } + if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) { + if (size < 8) + return; + avctx->width = bytestream_get_le32(&data); + avctx->height = bytestream_get_le32(&data); + avcodec_set_dimensions(avctx, avctx->width, avctx->height); + size -= 8; + } +} + int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt) @@ -947,6 +989,7 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){ av_packet_split_side_data(avpkt); + apply_param_change(avctx, avpkt); avctx->pkt = avpkt; if (HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME) ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr, @@ -1031,47 +1074,6 @@ int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *sa } #endif -static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt) -{ - int size = 0; - const uint8_t *data; - uint32_t flags; - - if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE)) - return; - - data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size); - if (!data || size < 4) - return; - flags = bytestream_get_le32(&data); - size -= 4; - if (size < 4) /* Required for any of the changes */ - return; - if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) { - avctx->channels = bytestream_get_le32(&data); - size -= 4; - } - if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) { - if (size < 8) - return; - avctx->channel_layout = bytestream_get_le64(&data); - size -= 8; - } - if (size < 4) - return; - if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) { - avctx->sample_rate = bytestream_get_le32(&data); - size -= 4; - } - if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) { - if (size < 8) - return; - avctx->width = bytestream_get_le32(&data); - avctx->height = bytestream_get_le32(&data); - size -= 8; - } -} - int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 1469d815ce..109c009338 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -5342,7 +5342,7 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx) if (v->profile == PROFILE_ADVANCED) avctx->level = v->level; - avctx->has_b_frames = !!(avctx->max_b_frames); + avctx->has_b_frames = !!avctx->max_b_frames; s->mb_width = (avctx->coded_width + 15) >> 4; s->mb_height = (avctx->coded_height + 15) >> 4; diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c index 1bd7a0ba12..6bf785ec25 100644 --- a/libavcodec/vorbisdec.c +++ b/libavcodec/vorbisdec.c @@ -820,8 +820,7 @@ static void create_map(vorbis_context *vc, unsigned floor_number) for (idx = 0; idx < n; ++idx) { map[idx] = floor(BARK((vf->rate * idx) / (2.0f * n)) * - ((vf->bark_map_size) / - BARK(vf->rate / 2.0f))); + (vf->bark_map_size / BARK(vf->rate / 2.0f))); if (vf->bark_map_size-1 < map[idx]) map[idx] = vf->bark_map_size - 1; } @@ -979,7 +978,7 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext) int headers_len = avccontext->extradata_size; uint8_t *header_start[3]; int header_len[3]; - GetBitContext *gb = &(vc->gb); + GetBitContext *gb = &vc->gb; int hdr_type, ret; vc->avccontext = avccontext; @@ -1642,7 +1641,7 @@ static int vorbis_decode_frame(AVCodecContext *avccontext, void *data, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; vorbis_context *vc = avccontext->priv_data; - GetBitContext *gb = &(vc->gb); + GetBitContext *gb = &vc->gb; const float *channel_ptrs[255]; int i, len, ret; diff --git a/libavcodec/vp56.h b/libavcodec/vp56.h index b16a00054b..e135718d20 100644 --- a/libavcodec/vp56.h +++ b/libavcodec/vp56.h @@ -30,7 +30,6 @@ #include "dsputil.h" #include "get_bits.h" #include "bytestream.h" -#include "cabac.h" #include "vp56dsp.h" typedef struct vp56_context VP56Context; diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c index 6f89c7e3ad..a68e42d789 100644 --- a/libavcodec/zmbv.c +++ b/libavcodec/zmbv.c @@ -618,7 +618,7 @@ static av_cold int decode_init(AVCodecContext *avctx) c->bpp = avctx->bits_per_coded_sample; // Needed if zlib unused or init aborted before inflateInit - memset(&(c->zstream), 0, sizeof(z_stream)); + memset(&c->zstream, 0, sizeof(z_stream)); avctx->pix_fmt = PIX_FMT_RGB24; c->decomp_size = (avctx->width + 255) * 4 * (avctx->height + 64); @@ -635,7 +635,7 @@ static av_cold int decode_init(AVCodecContext *avctx) c->zstream.zalloc = Z_NULL; c->zstream.zfree = Z_NULL; c->zstream.opaque = Z_NULL; - zret = inflateInit(&(c->zstream)); + zret = inflateInit(&c->zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); return 1; @@ -659,7 +659,7 @@ static av_cold int decode_end(AVCodecContext *avctx) if (c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); - inflateEnd(&(c->zstream)); + inflateEnd(&c->zstream); av_freep(&c->cur); av_freep(&c->prev); diff --git a/libavcodec/zmbvenc.c b/libavcodec/zmbvenc.c index ce65ce4dc0..4b51fb167d 100644 --- a/libavcodec/zmbvenc.c +++ b/libavcodec/zmbvenc.c @@ -269,7 +269,7 @@ static av_cold int encode_init(AVCodecContext *avctx) } // Needed if zlib unused or init aborted before deflateInit - memset(&(c->zstream), 0, sizeof(z_stream)); + memset(&c->zstream, 0, sizeof(z_stream)); c->comp_size = avctx->width * avctx->height + 1024 + ((avctx->width + ZMBV_BLOCK - 1) / ZMBV_BLOCK) * ((avctx->height + ZMBV_BLOCK - 1) / ZMBV_BLOCK) * 2 + 4; if ((c->work_buf = av_malloc(c->comp_size)) == NULL) { @@ -294,7 +294,7 @@ static av_cold int encode_init(AVCodecContext *avctx) c->zstream.zalloc = Z_NULL; c->zstream.zfree = Z_NULL; c->zstream.opaque = Z_NULL; - zret = deflateInit(&(c->zstream), lvl); + zret = deflateInit(&c->zstream, lvl); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); return -1; @@ -317,7 +317,7 @@ static av_cold int encode_end(AVCodecContext *avctx) av_freep(&c->comp_buf); av_freep(&c->work_buf); - deflateEnd(&(c->zstream)); + deflateEnd(&c->zstream); av_freep(&c->prev); return 0; |