* 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
*/
typedef struct AMRContext {
AVClass *av_class;
- int frame_count;
void *dec_state;
void *enc_state;
int enc_bitrate;
{
AMRContext *s = avctx->priv_data;
- s->frame_count = 0;
s->dec_state = Decoder_Interface_init();
if (!s->dec_state) {
av_log(avctx, AV_LOG_ERROR, "Decoder_Interface_init error\n");
AMRContext *s = avctx->priv_data;
static const uint8_t block_size[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 };
enum Mode dec_mode;
- int packet_size;
+ int packet_size, out_size;
av_dlog(avctx, "amr_decode_frame buf=%p buf_size=%d frame_count=%d!!\n",
- buf, buf_size, s->frame_count);
+ buf, buf_size, avctx->frame_number);
+
+ 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);
+ }
dec_mode = (buf[0] >> 3) & 0x000F;
packet_size = block_size[dec_mode] + 1;
return AVERROR_INVALIDDATA;
}
- s->frame_count++;
av_dlog(avctx, "packet_size=%d buf= 0x%X %X %X %X\n",
packet_size, buf[0], buf[1], buf[2], buf[3]);
/* call decoder */
Decoder_Interface_Decode(s->dec_state, buf, data, 0);
- *data_size = 160 * 2;
+ *data_size = out_size;
return packet_size;
}
{
AMRContext *s = avctx->priv_data;
- s->frame_count = 0;
-
if (avctx->sample_rate != 8000) {
av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n");
return AVERROR(ENOSYS);
int buf_size = avpkt->size;
AMRWBContext *s = avctx->priv_data;
int mode;
- int packet_size;
+ int packet_size, out_size;
static const uint8_t block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1};
- if (!buf_size)
- /* nothing to do */
- return 0;
+ out_size = 320 * 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);
+ }
mode = (buf[0] >> 3) & 0x000F;
packet_size = block_size[mode];
}
D_IF_decode(s->state, buf, data, _good_frame);
- *data_size = 320 * 2;
+ *data_size = out_size;
return packet_size;
}