X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Flibopencore-amr.c;h=efe87cd0fa2b1ed0f09379de6796320ec1eb0b3d;hb=03b078721c8e42c413da75f553e740d235092dad;hp=aa6dfa62ec4ac08e96bfad6c3ff77633c3fe6e97;hpb=8748472f399604e41fc86bf66526f467b6ad6a23;p=ffmpeg diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c index aa6dfa62ec4..efe87cd0fa2 100644 --- a/libavcodec/libopencore-amr.c +++ b/libavcodec/libopencore-amr.c @@ -19,24 +19,30 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "avcodec.h" #include "libavutil/avstring.h" +#include "libavutil/channel_layout.h" #include "libavutil/common.h" #include "libavutil/opt.h" +#include "avcodec.h" #include "audio_frame_queue.h" #include "internal.h" -static void amr_decode_fix_avctx(AVCodecContext *avctx) +static int amr_decode_fix_avctx(AVCodecContext *avctx) { const int is_amr_wb = 1 + (avctx->codec_id == AV_CODEC_ID_AMR_WB); if (!avctx->sample_rate) avctx->sample_rate = 8000 * is_amr_wb; - if (!avctx->channels) - avctx->channels = 1; + if (avctx->channels > 1) { + av_log_missing_feature(avctx, "multi-channel AMR", 0); + return AVERROR_PATCHWELCOME; + } - avctx->sample_fmt = AV_SAMPLE_FMT_S16; + avctx->channels = 1; + avctx->channel_layout = AV_CH_LAYOUT_MONO; + avctx->sample_fmt = AV_SAMPLE_FMT_S16; + return 0; } #if CONFIG_LIBOPENCORE_AMRNB @@ -103,6 +109,10 @@ static const AVClass class = { static av_cold int amr_nb_decode_init(AVCodecContext *avctx) { AMRContext *s = avctx->priv_data; + int ret; + + if ((ret = amr_decode_fix_avctx(avctx)) < 0) + return ret; s->dec_state = Decoder_Interface_init(); if (!s->dec_state) { @@ -110,13 +120,6 @@ static av_cold int amr_nb_decode_init(AVCodecContext *avctx) return -1; } - amr_decode_fix_avctx(avctx); - - if (avctx->channels > 1) { - av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n"); - return AVERROR(ENOSYS); - } - avcodec_get_frame_defaults(&s->frame); avctx->coded_frame = &s->frame; @@ -188,7 +191,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); } @@ -275,7 +278,7 @@ static int amr_nb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, samples, avpkt->data, 0); av_dlog(avctx, "amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n", - written, s->enc_mode, frame[0]); + written, s->enc_mode, avpkt->data[0]); /* Get the next frame pts/duration */ ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts, @@ -318,15 +321,12 @@ typedef struct AMRWBContext { static av_cold int amr_wb_decode_init(AVCodecContext *avctx) { AMRWBContext *s = avctx->priv_data; + int ret; - s->state = D_IF_init(); - - amr_decode_fix_avctx(avctx); + if ((ret = amr_decode_fix_avctx(avctx)) < 0) + return ret; - if (avctx->channels > 1) { - av_log(avctx, AV_LOG_ERROR, "amr_wb: multichannel decoding not supported\n"); - return AVERROR(ENOSYS); - } + s->state = D_IF_init(); avcodec_get_frame_defaults(&s->frame); avctx->coded_frame = &s->frame;