From fc2dd2c7ac9f26ae4449623875746bb1f350f08f Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 26 Sep 2011 15:06:33 -0400 Subject: [PATCH 1/9] ogg/celt: do not set sample_fmt in the demuxer --- libavformat/oggparsecelt.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavformat/oggparsecelt.c b/libavformat/oggparsecelt.c index 82a842c612..6a0c308e41 100644 --- a/libavformat/oggparsecelt.c +++ b/libavformat/oggparsecelt.c @@ -68,7 +68,6 @@ static int celt_header(AVFormatContext *s, int idx) st->codec->sample_rate = sample_rate; st->codec->channels = nb_channels; st->codec->frame_size = frame_size; - st->codec->sample_fmt = AV_SAMPLE_FMT_S16; st->codec->extradata = extradata; st->codec->extradata_size = 2 * sizeof(uint32_t); if (sample_rate) From 291d74a46d32183653db07818c7b3407fd50a288 Mon Sep 17 00:00:00 2001 From: Laurent Aimar Date: Sat, 1 Oct 2011 00:45:05 +0200 Subject: [PATCH 2/9] Check for out of bound writes in the QDM2 decoder. Signed-off-by: Michael Niedermayer Signed-off-by: Justin Ruggles --- libavcodec/qdm2.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c index 2a45495c7c..4c7f881e2b 100644 --- a/libavcodec/qdm2.c +++ b/libavcodec/qdm2.c @@ -77,6 +77,7 @@ do { \ #define SAMPLES_NEEDED_2(why) \ av_log (NULL,AV_LOG_INFO,"This file triggers some missing code. Please contact the developers.\nPosition: %s\n",why); +#define QDM2_MAX_FRAME_SIZE 512 typedef int8_t sb_int8_array[2][30][64]; @@ -169,7 +170,7 @@ typedef struct { /// I/O data const uint8_t *compressed_data; int compressed_size; - float output_buffer[1024]; + float output_buffer[QDM2_MAX_FRAME_SIZE * 2]; /// Synthesis filter MPADSPContext mpadsp; @@ -1798,6 +1799,8 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx) avctx->channels = s->nb_channels = s->channels = AV_RB32(extradata); extradata += 4; + if (s->channels > MPA_MAX_CHANNELS) + return AVERROR_INVALIDDATA; avctx->sample_rate = AV_RB32(extradata); extradata += 4; @@ -1819,6 +1822,8 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx) // something like max decodable tones s->group_order = av_log2(s->group_size) + 1; s->frame_size = s->group_size / 16; // 16 iterations per super block + if (s->frame_size > QDM2_MAX_FRAME_SIZE) + return AVERROR_INVALIDDATA; s->sub_sampling = s->fft_order - 7; s->frequency_range = 255 / (1 << (2 - s->sub_sampling)); From 5a19acb17ceb71657b0eec51dac651953520e5c8 Mon Sep 17 00:00:00 2001 From: Laurent Aimar Date: Sat, 1 Oct 2011 00:45:04 +0200 Subject: [PATCH 3/9] Fix out of bound reads in the QDM2 decoder. Signed-off-by: Michael Niedermayer Signed-off-by: Justin Ruggles --- libavcodec/qdm2.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c index 4c7f881e2b..b68197de17 100644 --- a/libavcodec/qdm2.c +++ b/libavcodec/qdm2.c @@ -1355,6 +1355,8 @@ static void qdm2_fft_decode_tones (QDM2Context *q, int duration, GetBitContext * return; local_int_14 = (offset >> local_int_8); + if (local_int_14 >= FF_ARRAY_ELEMS(fft_level_index_table)) + return; if (q->nb_channels > 1) { channel = get_bits1(gb); From 7d49f79f1cd47783a963a757a6563b9cac29db62 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 14 Sep 2011 13:57:04 -0400 Subject: [PATCH 4/9] qdm2: check output buffer size before decoding --- libavcodec/qdm2.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c index b68197de17..5068e675cb 100644 --- a/libavcodec/qdm2.c +++ b/libavcodec/qdm2.c @@ -1960,13 +1960,20 @@ static int qdm2_decode_frame(AVCodecContext *avctx, int buf_size = avpkt->size; QDM2Context *s = avctx->priv_data; int16_t *out = data; - int i; + int i, out_size; if(!buf) return 0; if(buf_size < s->checksum_size) return -1; + out_size = 16 * s->channels * s->frame_size * + av_get_bytes_per_sample(avctx->sample_fmt); + if (*data_size < out_size) { + av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n"); + return AVERROR(EINVAL); + } + av_log(avctx, AV_LOG_DEBUG, "decode(%d): %p[%d] -> %p[%d]\n", buf_size, buf, s->checksum_size, data, *data_size); @@ -1976,7 +1983,7 @@ static int qdm2_decode_frame(AVCodecContext *avctx, out += s->channels * s->frame_size; } - *data_size = (uint8_t*)out - (uint8_t*)data; + *data_size = out_size; return s->checksum_size; } From 12bd8532cf09883e5d1f1ec817c18a376147deb8 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Fri, 30 Sep 2011 17:28:28 +0200 Subject: [PATCH 5/9] Synchronize various 4CCs and codec tags from FFmpeg. --- libavcodec/avcodec.h | 2 ++ libavcodec/raw.c | 4 +++- libavformat/isom.c | 5 +++++ libavformat/riff.c | 7 +++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 4d61f44e9c..2e37f5a1b1 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -210,6 +210,8 @@ enum CodecID { CODEC_ID_DFA, CODEC_ID_WMV3IMAGE, CODEC_ID_VC1IMAGE, + CODEC_ID_G723_1, + CODEC_ID_G729, /* various PCM "codecs" */ CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs diff --git a/libavcodec/raw.c b/libavcodec/raw.c index aa1ea308b0..cdd217536e 100644 --- a/libavcodec/raw.c +++ b/libavcodec/raw.c @@ -36,6 +36,7 @@ const PixelFormatTag ff_raw_pix_fmt_tags[] = { { PIX_FMT_YUV411P, MKTAG('Y', '4', '1', 'B') }, { PIX_FMT_YUV422P, MKTAG('Y', '4', '2', 'B') }, { PIX_FMT_YUV422P, MKTAG('P', '4', '2', '2') }, + { PIX_FMT_YUV422P, MKTAG('Y', 'V', '1', '6') }, /* yuvjXXX formats are deprecated hacks specific to libav*, they are identical to yuvXXX */ { PIX_FMT_YUVJ420P, MKTAG('I', '4', '2', '0') }, /* Planar formats */ @@ -44,7 +45,7 @@ const PixelFormatTag ff_raw_pix_fmt_tags[] = { { PIX_FMT_YUVJ422P, MKTAG('Y', '4', '2', 'B') }, { PIX_FMT_YUVJ422P, MKTAG('P', '4', '2', '2') }, { PIX_FMT_GRAY8, MKTAG('Y', '8', '0', '0') }, - { PIX_FMT_GRAY8, MKTAG(' ', ' ', 'Y', '8') }, + { PIX_FMT_GRAY8, MKTAG('Y', '8', ' ', ' ') }, { PIX_FMT_YUYV422, MKTAG('Y', 'U', 'Y', '2') }, /* Packed formats */ { PIX_FMT_YUYV422, MKTAG('Y', '4', '2', '2') }, @@ -135,6 +136,7 @@ const PixelFormatTag ff_raw_pix_fmt_tags[] = { /* special */ { PIX_FMT_RGB565LE,MKTAG( 3 , 0 , 0 , 0 ) }, /* flipped RGB565LE */ + { PIX_FMT_YUV444P, MKTAG('Y', 'V', '2', '4') }, /* YUV444P, swapped UV */ { PIX_FMT_NONE, 0 }, }; diff --git a/libavformat/isom.c b/libavformat/isom.c index 896730c5a6..d7c0af101e 100644 --- a/libavformat/isom.c +++ b/libavformat/isom.c @@ -204,6 +204,8 @@ const AVCodecTag codec_movvideo_tags[] = { { CODEC_ID_DIRAC, MKTAG('d', 'r', 'a', 'c') }, { CODEC_ID_DNXHD, MKTAG('A', 'V', 'd', 'n') }, /* AVID DNxHD */ + { CODEC_ID_FLV1, MKTAG('H', '2', '6', '3') }, /* Flash Media Server */ + { CODEC_ID_MSMPEG4V3, MKTAG('3', 'I', 'V', 'D') }, /* 3ivx DivX Doctor */ { CODEC_ID_RAWVIDEO, MKTAG('A', 'V', '1', 'x') }, /* AVID 1:1x */ { CODEC_ID_RAWVIDEO, MKTAG('A', 'V', 'u', 'p') }, { CODEC_ID_SGI, MKTAG('s', 'g', 'i', ' ') }, /* SGI */ @@ -259,6 +261,7 @@ const AVCodecTag codec_movaudio_tags[] = { { CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, /* AMR-WB 3gp */ { CODEC_ID_GSM, MKTAG('a', 'g', 's', 'm') }, + { CODEC_ID_NELLYMOSER, MKTAG('n', 'm', 'o', 's') }, /* Flash Media Server */ { CODEC_ID_ALAC, MKTAG('a', 'l', 'a', 'c') }, /* Apple Lossless */ { CODEC_ID_QCELP, MKTAG('Q','c','l','p') }, @@ -271,6 +274,8 @@ const AVCodecTag codec_movaudio_tags[] = { { CODEC_ID_DVAUDIO, MKTAG('v', 'd', 'v', 'a') }, { CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'c', 'a') }, + { CODEC_ID_SPEEX, MKTAG('s','p','e','x') }, /* Flash Media Server */ + { CODEC_ID_WMAV2, MKTAG('W', 'M', 'A', '2') }, { CODEC_ID_NONE, 0 }, diff --git a/libavformat/riff.c b/libavformat/riff.c index 4b81eb3431..fec3c8851a 100644 --- a/libavformat/riff.c +++ b/libavformat/riff.c @@ -87,6 +87,7 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_MPEG4, MKTAG('G', 'E', 'O', 'V') }, { CODEC_ID_MPEG4, MKTAG('S', 'I', 'P', 'P') }, /* Samsung SHR-6040 */ { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'X') }, + { CODEC_ID_MPEG4, MKTAG('D', 'r', 'e', 'X') }, { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') }, { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3') }, { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') }, @@ -173,10 +174,13 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', 's') }, { CODEC_ID_RAWVIDEO, MKTAG('P', '4', '2', '2') }, { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '2') }, + { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '6') }, + { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '2', '4') }, { CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'V', 'Y') }, { CODEC_ID_RAWVIDEO, MKTAG('V', 'Y', 'U', 'Y') }, { CODEC_ID_RAWVIDEO, MKTAG('I', 'Y', 'U', 'V') }, { CODEC_ID_RAWVIDEO, MKTAG('Y', '8', '0', '0') }, + { CODEC_ID_RAWVIDEO, MKTAG('Y', '8', ' ', ' ') }, { CODEC_ID_RAWVIDEO, MKTAG('H', 'D', 'Y', 'C') }, { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', 'U', '9') }, { CODEC_ID_RAWVIDEO, MKTAG('V', 'D', 'T', 'Z') }, /* SoftLab-NSK VideoTizer */ @@ -254,6 +258,8 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_CAVS, MKTAG('C', 'A', 'V', 'S') }, { CODEC_ID_JPEG2000, MKTAG('m', 'j', 'p', '2') }, { CODEC_ID_JPEG2000, MKTAG('M', 'J', '2', 'C') }, + { CODEC_ID_JPEG2000, MKTAG('L', 'J', '2', 'C') }, + { CODEC_ID_JPEG2000, MKTAG('L', 'J', '2', 'K') }, { CODEC_ID_VMNC, MKTAG('V', 'M', 'n', 'c') }, { CODEC_ID_TARGA, MKTAG('t', 'g', 'a', ' ') }, { CODEC_ID_PNG, MKTAG('M', 'P', 'N', 'G') }, @@ -318,6 +324,7 @@ const AVCodecTag ff_codec_wav_tags[] = { { CODEC_ID_PCM_MULAW, 0x6c75 }, { CODEC_ID_AAC, 0x706d }, { CODEC_ID_AAC, 0x4143 }, + { CODEC_ID_SPEEX, 0xA109 }, { CODEC_ID_FLAC, 0xF1AC }, { CODEC_ID_ADPCM_SWF, ('S'<<8)+'F' }, { CODEC_ID_VORBIS, ('V'<<8)+'o' }, //HACK/FIXME, does vorbis in WAV/AVI have an (in)official id? From 1b5a189f06879338088809b3049ea7620f4e7e78 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 20 Sep 2011 15:27:44 -0400 Subject: [PATCH 6/9] sipr: fix the output data size check and only calculate it once. --- libavcodec/sipr.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c index c9fccb2d3a..f57ec4fd2a 100644 --- a/libavcodec/sipr.c +++ b/libavcodec/sipr.c @@ -509,7 +509,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap, GetBitContext gb; float *data = datap; int subframe_size = ctx->mode == MODE_16k ? L_SUBFR_16k : SUBFR_SIZE; - int i; + int i, out_size; ctx->avctx = avctx; if (avpkt->size < (mode_par->bits_per_frame >> 3)) { @@ -520,7 +520,11 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap, *data_size = 0; return -1; } - if (*data_size < subframe_size * mode_par->subframe_count * sizeof(float)) { + + out_size = mode_par->frames_per_packet * subframe_size * + mode_par->subframe_count * + av_get_bytes_per_sample(avctx->sample_fmt); + if (*data_size < out_size) { av_log(avctx, AV_LOG_ERROR, "Error processing packet: output buffer (%d) too small\n", *data_size); @@ -542,8 +546,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap, data += subframe_size * mode_par->subframe_count; } - *data_size = mode_par->frames_per_packet * subframe_size * - mode_par->subframe_count * sizeof(float); + *data_size = out_size; return mode_par->bits_per_frame >> 3; } From bde25700134b98068e2ad21c1f92955a4b489cdc Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Wed, 7 Sep 2011 10:17:30 +0100 Subject: [PATCH 7/9] qcelpdec: fix the return value of qcelp_decode_frame(). Signed-off-by: Justin Ruggles --- libavcodec/qcelpdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c index 5942a03072..477eaee8c6 100644 --- a/libavcodec/qcelpdec.c +++ b/libavcodec/qcelpdec.c @@ -839,7 +839,7 @@ erasure: *data_size = 160 * sizeof(*outbuffer); - return *data_size; + return buf_size; } AVCodec ff_qcelp_decoder = From e43dd3d2a8e106169e707484090a2d973ece2184 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 14 Sep 2011 13:38:07 -0400 Subject: [PATCH 8/9] qcelp: check output buffer size before decoding --- libavcodec/qcelpdec.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c index 477eaee8c6..a8a65fce06 100644 --- a/libavcodec/qcelpdec.c +++ b/libavcodec/qcelpdec.c @@ -738,11 +738,17 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size, int buf_size = avpkt->size; QCELPContext *q = avctx->priv_data; float *outbuffer = data; - int i; + int i, out_size; float quantized_lspf[10], lpc[10]; float gain[16]; float *formant_mem; + out_size = 160 * av_get_bytes_per_sample(avctx->sample_fmt); + if (*data_size < out_size) { + av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n"); + return AVERROR(EINVAL); + } + if((q->bitrate = determine_bitrate(avctx, buf_size, &buf)) == I_F_Q) { warn_insufficient_frame_quality(avctx, "bitrate cannot be determined."); @@ -837,7 +843,7 @@ erasure: memcpy(q->prev_lspf, quantized_lspf, sizeof(q->prev_lspf)); q->prev_bitrate = q->bitrate; - *data_size = 160 * sizeof(*outbuffer); + *data_size = out_size; return buf_size; } From dd376b1a1235fdf65e8d1ce7b7874915011c4798 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 14 Sep 2011 13:46:48 -0400 Subject: [PATCH 9/9] qcelpdec: cosmetics: do not add line break before opening bracket in 'for', 'while', 'if/else', and 'switch' statements. also fixes some spacing, but only if already changing a line --- libavcodec/qcelpdec.c | 180 ++++++++++++++---------------------------- 1 file changed, 60 insertions(+), 120 deletions(-) diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c index a8a65fce06..9e7e13118b 100644 --- a/libavcodec/qcelpdec.c +++ b/libavcodec/qcelpdec.c @@ -117,18 +117,15 @@ static int decode_lspf(QCELPContext *q, float *lspf) float tmp_lspf, smooth, erasure_coeff; const float *predictors; - if(q->bitrate == RATE_OCTAVE || q->bitrate == I_F_Q) - { + if (q->bitrate == RATE_OCTAVE || q->bitrate == I_F_Q) { predictors = (q->prev_bitrate != RATE_OCTAVE && q->prev_bitrate != I_F_Q ? q->prev_lspf : q->predictor_lspf); - if(q->bitrate == RATE_OCTAVE) - { + if (q->bitrate == RATE_OCTAVE) { q->octave_count++; - for(i=0; i<10; i++) - { + for (i=0; i<10; i++) { q->predictor_lspf[i] = lspf[i] = (q->frame.lspv[i] ? QCELP_LSP_SPREAD_FACTOR : -QCELP_LSP_SPREAD_FACTOR) @@ -136,8 +133,7 @@ static int decode_lspf(QCELPContext *q, float *lspf) + (i + 1) * ((1 - QCELP_LSP_OCTAVE_PREDICTOR)/11); } smooth = (q->octave_count < 10 ? .875 : 0.1); - }else - { + } else { erasure_coeff = QCELP_LSP_OCTAVE_PREDICTOR; assert(q->bitrate == I_F_Q); @@ -145,8 +141,7 @@ static int decode_lspf(QCELPContext *q, float *lspf) if(q->erasure_count > 1) erasure_coeff *= (q->erasure_count < 4 ? 0.9 : 0.7); - for(i=0; i<10; i++) - { + for(i = 0; i < 10; i++) { q->predictor_lspf[i] = lspf[i] = (i + 1) * ( 1 - erasure_coeff)/11 + erasure_coeff * predictors[i]; @@ -165,27 +160,23 @@ static int decode_lspf(QCELPContext *q, float *lspf) // Low-pass filter the LSP frequencies. ff_weighted_vector_sumf(lspf, lspf, q->prev_lspf, smooth, 1.0-smooth, 10); - }else - { + } else { q->octave_count = 0; tmp_lspf = 0.; - for(i=0; i<5 ; i++) - { + for (i = 0; i < 5; i++) { lspf[2*i+0] = tmp_lspf += qcelp_lspvq[i][q->frame.lspv[i]][0] * 0.0001; lspf[2*i+1] = tmp_lspf += qcelp_lspvq[i][q->frame.lspv[i]][1] * 0.0001; } // Check for badly received packets. - if(q->bitrate == RATE_QUARTER) - { + if (q->bitrate == RATE_QUARTER) { if(lspf[9] <= .70 || lspf[9] >= .97) return -1; for(i=3; i<10; i++) if(fabs(lspf[i] - lspf[i-2]) < .08) return -1; - }else - { + } else { if(lspf[9] <= .66 || lspf[9] >= .985) return -1; for(i=4; i<10; i++) @@ -209,26 +200,21 @@ static void decode_gain_and_index(QCELPContext *q, int i, subframes_count, g1[16]; float slope; - if(q->bitrate >= RATE_QUARTER) - { - switch(q->bitrate) - { + if (q->bitrate >= RATE_QUARTER) { + switch (q->bitrate) { case RATE_FULL: subframes_count = 16; break; case RATE_HALF: subframes_count = 4; break; default: subframes_count = 5; } - for(i=0; iframe.cbgain[i]; - if(q->bitrate == RATE_FULL && !((i+1) & 3)) - { + if (q->bitrate == RATE_FULL && !((i+1) & 3)) { g1[i] += av_clip((g1[i-1] + g1[i-2] + g1[i-3]) / 3 - 6, 0, 32); } gain[i] = qcelp_g12ga[g1[i]]; - if(q->frame.cbsign[i]) - { + if (q->frame.cbsign[i]) { gain[i] = -gain[i]; q->frame.cindex[i] = (q->frame.cindex[i]-89) & 127; } @@ -238,8 +224,7 @@ static void decode_gain_and_index(QCELPContext *q, q->prev_g1[1] = g1[i-1]; q->last_codebook_gain = qcelp_g12ga[g1[i-1]]; - if(q->bitrate == RATE_QUARTER) - { + if (q->bitrate == RATE_QUARTER) { // Provide smoothing of the unvoiced excitation energy. gain[7] = gain[4]; gain[6] = 0.4*gain[3] + 0.6*gain[4]; @@ -249,20 +234,16 @@ static void decode_gain_and_index(QCELPContext *q, gain[2] = gain[1]; gain[1] = 0.6*gain[0] + 0.4*gain[1]; } - }else if (q->bitrate != SILENCE) - { - if(q->bitrate == RATE_OCTAVE) - { + } else if (q->bitrate != SILENCE) { + if (q->bitrate == RATE_OCTAVE) { g1[0] = 2 * q->frame.cbgain[0] + av_clip((q->prev_g1[0] + q->prev_g1[1]) / 2 - 5, 0, 54); subframes_count = 8; - }else - { + } else { assert(q->bitrate == I_F_Q); g1[0] = q->prev_g1[1]; - switch(q->erasure_count) - { + switch (q->erasure_count) { case 1 : break; case 2 : g1[0] -= 1; break; case 3 : g1[0] -= 2; break; @@ -296,8 +277,7 @@ static int codebook_sanity_check_for_rate_quarter(const uint8_t *cbgain) { int i, diff, prev_diff=0; - for(i=1; i<5; i++) - { + for(i=1; i<5; i++) { diff = cbgain[i] - cbgain[i-1]; if(FFABS(diff) > 10) return -1; @@ -336,11 +316,9 @@ static void compute_svector(QCELPContext *q, const float *gain, uint16_t cbseed, cindex; float *rnd, tmp_gain, fir_filter_value; - switch(q->bitrate) - { + switch (q->bitrate) { case RATE_FULL: - for(i=0; i<16; i++) - { + for (i = 0; i < 16; i++) { tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO; cindex = -q->frame.cindex[i]; for(j=0; j<10; j++) @@ -348,8 +326,7 @@ static void compute_svector(QCELPContext *q, const float *gain, } break; case RATE_HALF: - for(i=0; i<4; i++) - { + for (i = 0; i < 4; i++) { tmp_gain = gain[i] * QCELP_RATE_HALF_CODEBOOK_RATIO; cindex = -q->frame.cindex[i]; for (j = 0; j < 40; j++) @@ -363,11 +340,9 @@ static void compute_svector(QCELPContext *q, const float *gain, (0x0007 & q->frame.lspv[1])<< 3 | (0x0038 & q->frame.lspv[0])>> 3 ; rnd = q->rnd_fir_filter_mem + 20; - for(i=0; i<8; i++) - { + for (i = 0; i < 8; i++) { tmp_gain = gain[i] * (QCELP_SQRT1887 / 32768.0); - for(k=0; k<20; k++) - { + for (k = 0; k < 20; k++) { cbseed = 521 * cbseed + 259; *rnd = (int16_t)cbseed; @@ -386,11 +361,9 @@ static void compute_svector(QCELPContext *q, const float *gain, break; case RATE_OCTAVE: cbseed = q->first16bits; - for(i=0; i<8; i++) - { + for (i = 0; i < 8; i++) { tmp_gain = gain[i] * (QCELP_SQRT1887 / 32768.0); - for(j=0; j<20; j++) - { + for (j = 0; j < 20; j++) { cbseed = 521 * cbseed + 259; *cdn_vector++ = tmp_gain * (int16_t)cbseed; } @@ -398,8 +371,7 @@ static void compute_svector(QCELPContext *q, const float *gain, break; case I_F_Q: cbseed = -44; // random codebook index - for(i=0; i<4; i++) - { + for (i = 0; i < 4; i++) { tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO; for(j=0; j<40; j++) *cdn_vector++ = tmp_gain * qcelp_rate_full_codebook[cbseed++ & 127]; @@ -459,15 +431,11 @@ static const float *do_pitchfilter(float memory[303], const float v_in[160], v_out = memory + 143; // Output vector starts at memory[143]. - for(i=0; i<4; i++) - { - if(gain[i]) - { + for (i = 0; i < 4; i++) { + if (gain[i]) { v_lag = memory + 143 + 40 * i - lag[i]; - for(v_len=v_in+40; v_inbitrate >= RATE_HALF || q->bitrate == SILENCE || - (q->bitrate == I_F_Q && (q->prev_bitrate >= RATE_HALF))) - { + (q->bitrate == I_F_Q && (q->prev_bitrate >= RATE_HALF))) { - if(q->bitrate >= RATE_HALF) - { + if(q->bitrate >= RATE_HALF) { // Compute gain & lag for the whole frame. - for(i=0; i<4; i++) - { + for (i = 0; i < 4; i++) { q->pitch_gain[i] = q->frame.plag[i] ? (q->frame.pgain[i] + 1) * 0.25 : 0.0; q->pitch_lag[i] = q->frame.plag[i] + 16; } - }else - { + } else { float max_pitch_gain; - if (q->bitrate == I_F_Q) - { + if (q->bitrate == I_F_Q) { if (q->erasure_count < 3) max_pitch_gain = 0.9 - 0.3 * (q->erasure_count - 1); else max_pitch_gain = 0.0; - }else - { + } else { assert(q->bitrate == SILENCE); max_pitch_gain = 1.0; } @@ -553,8 +514,7 @@ static void apply_pitch_filters(QCELPContext *q, float *cdn_vector) q->frame.pfrac); apply_gain_ctrl(cdn_vector, v_synthesis_filtered, v_pre_filtered); - }else - { + } else { memcpy(q->pitch_synthesis_filter_mem, cdn_vector + 17, 143 * sizeof(float)); memcpy(q->pitch_pre_filter_mem, cdn_vector + 17, 143 * sizeof(float)); @@ -586,8 +546,7 @@ static void lspf2lpc(const float *lspf, float *lpc) ff_acelp_lspd2lpc(lsp, lpc, 5); - for (i=0; i<10; i++) - { + for (i = 0; i < 10; i++) { lpc[i] *= bandwidth_expansion_coeff; bandwidth_expansion_coeff *= QCELP_BANDWIDTH_EXPANSION_COEFF; } @@ -617,8 +576,7 @@ static void interpolate_lpc(QCELPContext *q, const float *curr_lspf, else weight = 1.0; - if(weight != 1.0) - { + if (weight != 1.0) { ff_weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf, weight, 1.0 - weight, 10); lspf2lpc(interpolated_lspf, lpc); @@ -631,8 +589,7 @@ static void interpolate_lpc(QCELPContext *q, const float *curr_lspf, static qcelp_packet_rate buf_size2bitrate(const int buf_size) { - switch(buf_size) - { + switch (buf_size) { case 35: return RATE_FULL; case 17: return RATE_HALF; case 8: return RATE_QUARTER; @@ -660,34 +617,28 @@ static qcelp_packet_rate determine_bitrate(AVCodecContext *avctx, const int buf_ { qcelp_packet_rate bitrate; - if((bitrate = buf_size2bitrate(buf_size)) >= 0) - { - if(bitrate > **buf) - { + if ((bitrate = buf_size2bitrate(buf_size)) >= 0) { + if (bitrate > **buf) { QCELPContext *q = avctx->priv_data; - if (!q->warned_buf_mismatch_bitrate) - { + if (!q->warned_buf_mismatch_bitrate) { av_log(avctx, AV_LOG_WARNING, "Claimed bitrate and buffer size mismatch.\n"); q->warned_buf_mismatch_bitrate = 1; } bitrate = **buf; - }else if(bitrate < **buf) - { + } else if (bitrate < **buf) { av_log(avctx, AV_LOG_ERROR, "Buffer is too small for the claimed bitrate.\n"); return I_F_Q; } (*buf)++; - }else if((bitrate = buf_size2bitrate(buf_size + 1)) >= 0) - { + } else if ((bitrate = buf_size2bitrate(buf_size + 1)) >= 0) { av_log(avctx, AV_LOG_WARNING, "Bitrate byte is missing, guessing the bitrate from packet size.\n"); }else return I_F_Q; - if(bitrate == SILENCE) - { + if (bitrate == SILENCE) { //FIXME: Remove experimental warning when tested with samples. av_log_ask_for_sample(avctx, "'Blank frame handling is experimental."); } @@ -749,21 +700,18 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size, return AVERROR(EINVAL); } - if((q->bitrate = determine_bitrate(avctx, buf_size, &buf)) == I_F_Q) - { + if ((q->bitrate = determine_bitrate(avctx, buf_size, &buf)) == I_F_Q) { warn_insufficient_frame_quality(avctx, "bitrate cannot be determined."); goto erasure; } if(q->bitrate == RATE_OCTAVE && - (q->first16bits = AV_RB16(buf)) == 0xFFFF) - { + (q->first16bits = AV_RB16(buf)) == 0xFFFF) { warn_insufficient_frame_quality(avctx, "Bitrate is 1/8 and first 16 bits are on."); goto erasure; } - if(q->bitrate > SILENCE) - { + if (q->bitrate > SILENCE) { const QCELPBitmap *bitmaps = qcelp_unpacking_bitmaps_per_rate[q->bitrate]; const QCELPBitmap *bitmaps_end = qcelp_unpacking_bitmaps_per_rate[q->bitrate] + qcelp_unpacking_bitmaps_lengths[q->bitrate]; @@ -777,24 +725,19 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size, unpacked_data[bitmaps->index] |= get_bits(&q->gb, bitmaps->bitlen) << bitmaps->bitpos; // Check for erasures/blanks on rates 1, 1/4 and 1/8. - if(q->frame.reserved) - { + if (q->frame.reserved) { warn_insufficient_frame_quality(avctx, "Wrong data in reserved frame area."); goto erasure; } if(q->bitrate == RATE_QUARTER && - codebook_sanity_check_for_rate_quarter(q->frame.cbgain)) - { + codebook_sanity_check_for_rate_quarter(q->frame.cbgain)) { warn_insufficient_frame_quality(avctx, "Codebook gain sanity check failed."); goto erasure; } - if(q->bitrate >= RATE_HALF) - { - for(i=0; i<4; i++) - { - if(q->frame.pfrac[i] && q->frame.plag[i] >= 124) - { + if (q->bitrate >= RATE_HALF) { + for (i = 0; i < 4; i++) { + if (q->frame.pfrac[i] && q->frame.plag[i] >= 124) { warn_insufficient_frame_quality(avctx, "Cannot initialize pitch filter."); goto erasure; } @@ -805,8 +748,7 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size, decode_gain_and_index(q, gain); compute_svector(q, gain, outbuffer); - if(decode_lspf(q, quantized_lspf) < 0) - { + if (decode_lspf(q, quantized_lspf) < 0) { warn_insufficient_frame_quality(avctx, "Badly received packets in frame."); goto erasure; } @@ -814,8 +756,7 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size, apply_pitch_filters(q, outbuffer); - if(q->bitrate == I_F_Q) - { + if (q->bitrate == I_F_Q) { erasure: q->bitrate = I_F_Q; q->erasure_count++; @@ -827,8 +768,7 @@ erasure: q->erasure_count = 0; formant_mem = q->formant_mem + 10; - for(i=0; i<4; i++) - { + for (i = 0; i < 4; i++) { interpolate_lpc(q, quantized_lspf, lpc, i); ff_celp_lp_synthesis_filterf(formant_mem, lpc, outbuffer + i * 40, 40, 10);