diff options
Diffstat (limited to 'libavcodec/g722enc.c')
-rw-r--r-- | libavcodec/g722enc.c | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c index 545825b..25b61df 100644 --- a/libavcodec/g722enc.c +++ b/libavcodec/g722enc.c @@ -5,20 +5,20 @@ * Copyright (c) 2009 Kenan Gillet * Copyright (c) 2010 Martin Storsjo * - * 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 */ @@ -27,6 +27,7 @@ * G.722 ADPCM audio encoder */ +#include "libavutil/avassert.h" #include "avcodec.h" #include "internal.h" #include "g722.h" @@ -60,11 +61,6 @@ static av_cold int g722_encode_init(AVCodecContext * avctx) G722Context *c = avctx->priv_data; int ret; - if (avctx->channels != 1) { - av_log(avctx, AV_LOG_ERROR, "Only mono tracks are allowed.\n"); - return AVERROR_INVALIDDATA; - } - c->band[0].scale_factor = 8; c->band[1].scale_factor = 2; c->prev_samples_pos = 22; @@ -74,9 +70,9 @@ static av_cold int g722_encode_init(AVCodecContext * avctx) int max_paths = frontier * FREEZE_INTERVAL; int i; for (i = 0; i < 2; i++) { - c->paths[i] = av_mallocz(max_paths * sizeof(**c->paths)); - c->node_buf[i] = av_mallocz(2 * frontier * sizeof(**c->node_buf)); - c->nodep_buf[i] = av_mallocz(2 * frontier * sizeof(**c->nodep_buf)); + c->paths[i] = av_mallocz_array(max_paths, sizeof(**c->paths)); + c->node_buf[i] = av_mallocz_array(frontier, 2 * sizeof(**c->node_buf)); + c->nodep_buf[i] = av_mallocz_array(frontier, 2 * sizeof(**c->nodep_buf)); if (!c->paths[i] || !c->node_buf[i] || !c->nodep_buf[i]) { ret = AVERROR(ENOMEM); goto error; @@ -238,7 +234,7 @@ static void g722_encode_trellis(G722Context *c, int trellis, continue;\ if (heap_pos[index] < frontier) {\ pos = heap_pos[index]++;\ - assert(pathn[index] < FREEZE_INTERVAL * frontier);\ + av_assert2(pathn[index] < FREEZE_INTERVAL * frontier);\ node = nodes_next[index][pos] = next[index]++;\ node->path = pathn[index]++;\ } else {\ @@ -357,10 +353,8 @@ static int g722_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int nb_samples, out_size, ret; out_size = (frame->nb_samples + 1) / 2; - if ((ret = ff_alloc_packet(avpkt, out_size))) { - av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); + if ((ret = ff_alloc_packet2(avctx, avpkt, out_size, 0)) < 0) return ret; - } nb_samples = frame->nb_samples - (frame->nb_samples & 1); @@ -382,15 +376,15 @@ static int g722_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } AVCodec ff_adpcm_g722_encoder = { - .name = "g722", - .long_name = NULL_IF_CONFIG_SMALL("G.722 ADPCM"), - .type = AVMEDIA_TYPE_AUDIO, - .id = AV_CODEC_ID_ADPCM_G722, - .priv_data_size = sizeof(G722Context), - .init = g722_encode_init, - .close = g722_encode_close, - .encode2 = g722_encode_frame, - .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME, - .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, - AV_SAMPLE_FMT_NONE }, + .name = "g722", + .long_name = NULL_IF_CONFIG_SMALL("G.722 ADPCM"), + .type = AVMEDIA_TYPE_AUDIO, + .id = AV_CODEC_ID_ADPCM_G722, + .priv_data_size = sizeof(G722Context), + .init = g722_encode_init, + .close = g722_encode_close, + .encode2 = g722_encode_frame, + .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME, + .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, + .channel_layouts = (const uint64_t[]){ AV_CH_LAYOUT_MONO, 0 }, }; |