diff options
Diffstat (limited to 'libavcodec/libopencore-amr.c')
-rw-r--r-- | libavcodec/libopencore-amr.c | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c index 27ab7d2..8545ffe 100644 --- a/libavcodec/libopencore-amr.c +++ b/libavcodec/libopencore-amr.c @@ -2,20 +2,20 @@ * AMR Audio decoder stub * Copyright (c) 2003 The FFmpeg project * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify 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, + * FFmpeg 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. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -33,7 +33,8 @@ static int amr_decode_fix_avctx(AVCodecContext *avctx) { const int is_amr_wb = 1 + (avctx->codec_id == AV_CODEC_ID_AMR_WB); - avctx->sample_rate = 8000 * is_amr_wb; + if (!avctx->sample_rate) + avctx->sample_rate = 8000 * is_amr_wb; if (avctx->channels > 1) { avpriv_report_missing_feature(avctx, "multi-channel AMR"); @@ -105,10 +106,8 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void *data, /* get output buffer */ frame->nb_samples = 160; - if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) { - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; - } dec_mode = (buf[0] >> 3) & 0x000F; packet_size = block_size[dec_mode] + 1; @@ -183,7 +182,7 @@ static const AVOption options[] = { { NULL } }; -static const AVClass class = { +static const AVClass amrnb_class = { "libopencore_amrnb", av_default_item_name, options, LIBAVUTIL_VERSION_INT }; @@ -191,7 +190,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx) { AMRContext *s = avctx->priv_data; - if (avctx->sample_rate != 8000) { + if (avctx->sample_rate != 8000 && avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n"); return AVERROR(ENOSYS); } @@ -239,14 +238,12 @@ static int amr_nb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, s->enc_bitrate = avctx->bit_rate; } - if ((ret = ff_alloc_packet(avpkt, 32))) { - av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); + if ((ret = ff_alloc_packet2(avctx, avpkt, 32, 0)) < 0) return ret; - } if (frame) { if (frame->nb_samples < avctx->frame_size) { - flush_buf = av_mallocz(avctx->frame_size * sizeof(*flush_buf)); + flush_buf = av_mallocz_array(avctx->frame_size, sizeof(*flush_buf)); if (!flush_buf) return AVERROR(ENOMEM); memcpy(flush_buf, samples, frame->nb_samples * sizeof(*flush_buf)); @@ -261,7 +258,7 @@ static int amr_nb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } else { if (s->enc_last_frame < 0) return 0; - flush_buf = av_mallocz(avctx->frame_size * sizeof(*flush_buf)); + flush_buf = av_mallocz_array(avctx->frame_size, sizeof(*flush_buf)); if (!flush_buf) return AVERROR(ENOMEM); samples = flush_buf; @@ -270,8 +267,8 @@ static int amr_nb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, samples, avpkt->data, 0); - ff_dlog(avctx, "amr_nb_encode_frame encoded %d bytes, bitrate %d, first byte was %#02"PRIx8"\n", - written, s->enc_mode, *frame->data[0]); + ff_dlog(avctx, "amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n", + written, s->enc_mode, avpkt->data[0]); /* Get the next frame pts/duration */ ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts, @@ -295,7 +292,7 @@ AVCodec ff_libopencore_amrnb_encoder = { .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SMALL_LAST_FRAME, .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, - .priv_class = &class, + .priv_class = &amrnb_class, }; #endif /* CONFIG_LIBOPENCORE_AMRNB_ENCODER */ @@ -337,10 +334,8 @@ static int amr_wb_decode_frame(AVCodecContext *avctx, void *data, /* get output buffer */ frame->nb_samples = 320; - if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) { - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; - } mode = (buf[0] >> 3) & 0x000F; packet_size = block_size[mode]; @@ -350,6 +345,10 @@ static int amr_wb_decode_frame(AVCodecContext *avctx, void *data, buf_size, packet_size + 1); return AVERROR_INVALIDDATA; } + if (!packet_size) { + av_log(avctx, AV_LOG_ERROR, "amr packet_size invalid\n"); + return AVERROR_INVALIDDATA; + } D_IF_decode(s->state, buf, (short *)frame->data[0], _good_frame); |