aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-11-02 14:15:28 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-11-02 14:20:33 +0100
commit6788350281c418f0f395a8279eee82f7abe7c63b (patch)
tree69cd76f699eff929f5b13f76b42eabc7f25f9355
parent00aa7fa786e41b5fc8404732453869aa3c14e33a (diff)
parent50a65e7a540ce6747f81d6dbf6a602ad35be77ff (diff)
downloadffmpeg-6788350281c418f0f395a8279eee82f7abe7c63b.tar.gz
Merge commit '50a65e7a540ce6747f81d6dbf6a602ad35be77ff'
* commit '50a65e7a540ce6747f81d6dbf6a602ad35be77ff': (24 commits) vmdaudio: set channel layout twinvq: validate sample rate code twinvq: set channel layout twinvq: validate that channels is not <= 0 truespeech: set channel layout sipr: set channel layout shorten: validate that the channel count in the header is not <= 0 ra288dec: set channel layout ra144dec: set channel layout qdm2: remove unneeded checks for channel count qdm2: make sure channels is not <= 0 and set channel layout qcelpdec: set channel layout nellymoserdec: set channels to 1 libopencore-amr: set channel layout for amr-nb or if not set by the user libilbc: set channel layout dpcm: use AVCodecContext.channels instead of keeping a private copy imc: set channels to 1 instead of validating it gsmdec: always set channel layout and sample rate at initialization libgsmdec: always set channel layout and sample rate at initialization g726dec: do not validate sample rate ... Conflicts: libavcodec/dpcm.c libavcodec/qdm2.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/dpcm.c16
-rw-r--r--libavcodec/flac.c19
-rw-r--r--libavcodec/flac.h3
-rw-r--r--libavcodec/flac_parser.c1
-rw-r--r--libavcodec/flacdec.c74
-rw-r--r--libavcodec/g726.c16
-rw-r--r--libavcodec/gsmdec.c9
-rw-r--r--libavcodec/imc.c6
-rw-r--r--libavcodec/libgsm.c18
-rw-r--r--libavcodec/libilbc.c8
-rw-r--r--libavcodec/libopencore-amr.c14
-rw-r--r--libavcodec/nellymoserdec.c1
-rw-r--r--libavcodec/qcelpdec.c5
-rw-r--r--libavcodec/qdm2.c15
-rw-r--r--libavcodec/ra144dec.c5
-rw-r--r--libavcodec/ra288.c7
-rw-r--r--libavcodec/shorten.c2
-rw-r--r--libavcodec/sipr.c5
-rw-r--r--libavcodec/truespeech.c4
-rw-r--r--libavcodec/twinvq.c11
-rw-r--r--libavcodec/vmdav.c4
21 files changed, 142 insertions, 101 deletions
diff --git a/libavcodec/dpcm.c b/libavcodec/dpcm.c
index a7c9bb1911..1875a55efe 100644
--- a/libavcodec/dpcm.c
+++ b/libavcodec/dpcm.c
@@ -44,7 +44,6 @@
typedef struct DPCMContext {
AVFrame frame;
- int channels;
int16_t roq_square_array[256];
int sample[2]; ///< previous sample (for SOL_DPCM)
const int8_t *sol_table; ///< delta table for SOL_DPCM
@@ -123,7 +122,6 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- s->channels = avctx->channels;
s->sample[0] = s->sample[1] = 0;
switch(avctx->codec->id) {
@@ -179,7 +177,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
int out = 0, ret;
int predictor[2];
int ch = 0;
- int stereo = s->channels - 1;
+ int stereo = avctx->channels - 1;
int16_t *output_samples, *samples_end;
GetByteContext gb;
@@ -193,10 +191,10 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
out = buf_size - 8;
break;
case AV_CODEC_ID_INTERPLAY_DPCM:
- out = buf_size - 6 - s->channels;
+ out = buf_size - 6 - avctx->channels;
break;
case AV_CODEC_ID_XAN_DPCM:
- out = buf_size - 2 * s->channels;
+ out = buf_size - 2 * avctx->channels;
break;
case AV_CODEC_ID_SOL_DPCM:
if (avctx->codec_tag != 3)
@@ -209,12 +207,12 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
return AVERROR(EINVAL);
}
- if (out % s->channels) {
+ if (out % avctx->channels) {
av_log(avctx, AV_LOG_WARNING, "channels have differing number of samples\n");
}
/* get output buffer */
- s->frame.nb_samples = (out + s->channels - 1) / s->channels;
+ s->frame.nb_samples = (out + avctx->channels - 1) / avctx->channels;
if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
@@ -248,7 +246,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
case AV_CODEC_ID_INTERPLAY_DPCM:
bytestream2_skipu(&gb, 6); /* skip over the stream mask and stream length */
- for (ch = 0; ch < s->channels; ch++) {
+ for (ch = 0; ch < avctx->channels; ch++) {
predictor[ch] = sign_extend(bytestream2_get_le16u(&gb), 16);
*output_samples++ = predictor[ch];
}
@@ -268,7 +266,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
{
int shift[2] = { 4, 4 };
- for (ch = 0; ch < s->channels; ch++)
+ for (ch = 0; ch < avctx->channels; ch++)
predictor[ch] = sign_extend(bytestream2_get_le16u(&gb), 16);
ch = 0;
diff --git a/libavcodec/flac.c b/libavcodec/flac.c
index b07e4f8705..4c1bc58408 100644
--- a/libavcodec/flac.c
+++ b/libavcodec/flac.c
@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/audioconvert.h"
#include "libavutil/crc.h"
#include "libavutil/log.h"
#include "bytestream.h"
@@ -28,6 +29,15 @@
static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 };
+static const int64_t flac_channel_layouts[6] = {
+ AV_CH_LAYOUT_MONO,
+ AV_CH_LAYOUT_STEREO,
+ AV_CH_LAYOUT_SURROUND,
+ AV_CH_LAYOUT_QUAD,
+ AV_CH_LAYOUT_5POINT0,
+ AV_CH_LAYOUT_5POINT1
+};
+
static int64_t get_utf8(GetBitContext *gb)
{
int64_t val;
@@ -181,6 +191,14 @@ int avpriv_flac_is_extradata_valid(AVCodecContext *avctx,
return 1;
}
+void ff_flac_set_channel_layout(AVCodecContext *avctx)
+{
+ if (avctx->channels <= FF_ARRAY_ELEMS(flac_channel_layouts))
+ avctx->channel_layout = flac_channel_layouts[avctx->channels - 1];
+ else
+ avctx->channel_layout = 0;
+}
+
void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
const uint8_t *buffer)
{
@@ -205,6 +223,7 @@ void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *
avctx->channels = s->channels;
avctx->sample_rate = s->samplerate;
avctx->bits_per_raw_sample = s->bps;
+ ff_flac_set_channel_layout(avctx);
s->samples = get_bits_longlong(&gb, 36);
diff --git a/libavcodec/flac.h b/libavcodec/flac.h
index 94444f8a67..13e863b87e 100644
--- a/libavcodec/flac.h
+++ b/libavcodec/flac.h
@@ -137,4 +137,7 @@ int ff_flac_get_max_frame_size(int blocksize, int ch, int bps);
*/
int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
FLACFrameInfo *fi, int log_level_offset);
+
+void ff_flac_set_channel_layout(AVCodecContext *avctx);
+
#endif /* AVCODEC_FLAC_H */
diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c
index f38d7aae67..7d3c5c4973 100644
--- a/libavcodec/flac_parser.c
+++ b/libavcodec/flac_parser.c
@@ -459,6 +459,7 @@ static int get_best_header(FLACParseContext* fpc, const uint8_t **poutbuf,
fpc->avctx->sample_rate = header->fi.samplerate;
fpc->avctx->channels = header->fi.channels;
+ ff_flac_set_channel_layout(fpc->avctx);
fpc->pc->duration = header->fi.blocksize;
*poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size,
&fpc->wrap_buf,
diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
index 992127713c..05793c961d 100644
--- a/libavcodec/flacdec.c
+++ b/libavcodec/flacdec.c
@@ -58,20 +58,13 @@ typedef struct FLACContext {
int got_streaminfo; ///< indicates if the STREAMINFO has been read
int32_t *decoded[FLAC_MAX_CHANNELS]; ///< decoded samples
+ uint8_t *decoded_buffer;
+ unsigned int decoded_buffer_size;
FLACDSPContext dsp;
} FLACContext;
-static const int64_t flac_channel_layouts[6] = {
- AV_CH_LAYOUT_MONO,
- AV_CH_LAYOUT_STEREO,
- AV_CH_LAYOUT_SURROUND,
- AV_CH_LAYOUT_QUAD,
- AV_CH_LAYOUT_5POINT0,
- AV_CH_LAYOUT_5POINT1
-};
-
-static void allocate_buffers(FLACContext *s);
+static int allocate_buffers(FLACContext *s);
static void flac_set_bps(FLACContext *s)
{
@@ -99,6 +92,7 @@ static av_cold int flac_decode_init(AVCodecContext *avctx)
{
enum FLACExtradataFormat format;
uint8_t *streaminfo;
+ int ret;
FLACContext *s = avctx->priv_data;
s->avctx = avctx;
@@ -112,7 +106,9 @@ static av_cold int flac_decode_init(AVCodecContext *avctx)
/* initialize based on the demuxer-supplied streamdata header */
avpriv_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo);
- allocate_buffers(s);
+ ret = allocate_buffers(s);
+ if (ret < 0)
+ return ret;
flac_set_bps(s);
ff_flacdsp_init(&s->dsp, avctx->sample_fmt, s->bps);
s->got_streaminfo = 1;
@@ -120,9 +116,6 @@ static av_cold int flac_decode_init(AVCodecContext *avctx)
avcodec_get_frame_defaults(&s->frame);
avctx->coded_frame = &s->frame;
- if (avctx->channels <= FF_ARRAY_ELEMS(flac_channel_layouts))
- avctx->channel_layout = flac_channel_layouts[avctx->channels - 1];
-
return 0;
}
@@ -135,15 +128,24 @@ static void dump_headers(AVCodecContext *avctx, FLACStreaminfo *s)
av_log(avctx, AV_LOG_DEBUG, " Bits: %d\n", s->bps);
}
-static void allocate_buffers(FLACContext *s)
+static int allocate_buffers(FLACContext *s)
{
- int i;
+ int buf_size;
av_assert0(s->max_blocksize);
- for (i = 0; i < s->channels; i++) {
- s->decoded[i] = av_malloc(sizeof(int32_t)*s->max_blocksize);
- }
+ buf_size = av_samples_get_buffer_size(NULL, s->channels, s->max_blocksize,
+ AV_SAMPLE_FMT_S32P, 0);
+ if (buf_size < 0)
+ return buf_size;
+
+ av_fast_malloc(&s->decoded_buffer, &s->decoded_buffer_size, buf_size);
+ if (!s->decoded_buffer)
+ return AVERROR(ENOMEM);
+
+ return av_samples_fill_arrays((uint8_t **)s->decoded, NULL,
+ s->decoded_buffer, s->channels,
+ s->max_blocksize, AV_SAMPLE_FMT_S32P, 0);
}
/**
@@ -155,7 +157,7 @@ static void allocate_buffers(FLACContext *s)
*/
static int parse_streaminfo(FLACContext *s, const uint8_t *buf, int buf_size)
{
- int metadata_type, metadata_size;
+ int metadata_type, metadata_size, ret;
if (buf_size < FLAC_STREAMINFO_SIZE+8) {
/* need more data */
@@ -167,7 +169,9 @@ static int parse_streaminfo(FLACContext *s, const uint8_t *buf, int buf_size)
return AVERROR_INVALIDDATA;
}
avpriv_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, &buf[8]);
- allocate_buffers(s);
+ ret = allocate_buffers(s);
+ if (ret < 0)
+ return ret;
flac_set_bps(s);
ff_flacdsp_init(&s->dsp, s->avctx->sample_fmt, s->bps);
s->got_streaminfo = 1;
@@ -403,7 +407,7 @@ static inline int decode_subframe(FLACContext *s, int channel)
static int decode_frame(FLACContext *s)
{
- int i;
+ int i, ret;
GetBitContext *gb = &s->gb;
FLACFrameInfo fi;
@@ -412,12 +416,15 @@ static int decode_frame(FLACContext *s)
return -1;
}
- if (s->channels && fi.channels != s->channels) {
- av_log(s->avctx, AV_LOG_ERROR, "switching channel layout mid-stream "
- "is not supported\n");
- return -1;
+ if (s->channels && fi.channels != s->channels && s->got_streaminfo) {
+ s->channels = s->avctx->channels = fi.channels;
+ ff_flac_set_channel_layout(s->avctx);
+ ret = allocate_buffers(s);
+ if (ret < 0)
+ return ret;
}
s->channels = s->avctx->channels = fi.channels;
+ ff_flac_set_channel_layout(s->avctx);
s->ch_mode = fi.ch_mode;
if (!s->bps && !fi.bps) {
@@ -451,16 +458,14 @@ static int decode_frame(FLACContext *s)
" or frame header\n");
return -1;
}
- if (fi.samplerate == 0) {
+ if (fi.samplerate == 0)
fi.samplerate = s->samplerate;
- } else if (s->samplerate && fi.samplerate != s->samplerate) {
- av_log(s->avctx, AV_LOG_WARNING, "sample rate changed from %d to %d\n",
- s->samplerate, fi.samplerate);
- }
s->samplerate = s->avctx->sample_rate = fi.samplerate;
if (!s->got_streaminfo) {
- allocate_buffers(s);
+ ret = allocate_buffers(s);
+ if (ret < 0)
+ return ret;
ff_flacdsp_init(&s->dsp, s->avctx->sample_fmt, s->bps);
s->got_streaminfo = 1;
dump_headers(s->avctx, (FLACStreaminfo *)s);
@@ -550,11 +555,8 @@ static int flac_decode_frame(AVCodecContext *avctx, void *data,
static av_cold int flac_decode_close(AVCodecContext *avctx)
{
FLACContext *s = avctx->priv_data;
- int i;
- for (i = 0; i < s->channels; i++) {
- av_freep(&s->decoded[i]);
- }
+ av_freep(&s->decoded_buffer);
return 0;
}
diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index b2f21fd6ca..609882ed7d 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -22,6 +22,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <limits.h>
+
+#include "libavutil/audioconvert.h"
#include "libavutil/avassert.h"
#include "libavutil/opt.h"
#include "avcodec.h"
@@ -418,18 +420,8 @@ static av_cold int g726_decode_init(AVCodecContext *avctx)
{
G726Context* c = avctx->priv_data;
- if (avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT &&
- avctx->sample_rate != 8000) {
- av_log(avctx, AV_LOG_ERROR, "Only 8kHz sample rate is allowed when "
- "the compliance level is strict. Reduce the compliance level "
- "if you wish to decode the stream anyway.\n");
- return AVERROR(EINVAL);
- }
-
- if(avctx->channels != 1){
- av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n");
- return AVERROR(EINVAL);
- }
+ avctx->channels = 1;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
c->code_size = avctx->bits_per_coded_sample;
if (c->code_size < 2 || c->code_size > 5) {
diff --git a/libavcodec/gsmdec.c b/libavcodec/gsmdec.c
index fc042fbd7b..f51a083085 100644
--- a/libavcodec/gsmdec.c
+++ b/libavcodec/gsmdec.c
@@ -24,6 +24,7 @@
* GSM decoder
*/
+#include "libavutil/audioconvert.h"
#include "avcodec.h"
#include "get_bits.h"
#include "msgsmdec.h"
@@ -34,10 +35,10 @@ static av_cold int gsm_init(AVCodecContext *avctx)
{
GSMContext *s = avctx->priv_data;
- avctx->channels = 1;
- if (!avctx->sample_rate)
- avctx->sample_rate = 8000;
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ avctx->channels = 1;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ avctx->sample_rate = 8000;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
switch (avctx->codec_id) {
case AV_CODEC_ID_GSM:
diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index 9da769ba38..ba39d41c98 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -176,8 +176,10 @@ static av_cold int imc_decode_init(AVCodecContext *avctx)
IMCContext *q = avctx->priv_data;
double r1, r2;
- if ((avctx->codec_id == AV_CODEC_ID_IMC && avctx->channels != 1)
- || (avctx->codec_id == AV_CODEC_ID_IAC && avctx->channels > 2)) {
+ if (avctx->codec_id == AV_CODEC_ID_IMC)
+ avctx->channels = 1;
+
+ if (avctx->channels > 2) {
av_log_ask_for_sample(avctx, "Number of channels is not supported\n");
return AVERROR_PATCHWELCOME;
}
diff --git a/libavcodec/libgsm.c b/libavcodec/libgsm.c
index 97f8abe10a..0ce174ac5f 100644
--- a/libavcodec/libgsm.c
+++ b/libavcodec/libgsm.c
@@ -29,6 +29,7 @@
#include <gsm/gsm.h>
+#include "libavutil/audioconvert.h"
#include "avcodec.h"
#include "internal.h"
#include "gsm.h"
@@ -153,19 +154,10 @@ typedef struct LibGSMDecodeContext {
static av_cold int libgsm_decode_init(AVCodecContext *avctx) {
LibGSMDecodeContext *s = avctx->priv_data;
- if (avctx->channels > 1) {
- av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n",
- avctx->channels);
- return -1;
- }
-
- if (!avctx->channels)
- avctx->channels = 1;
-
- if (!avctx->sample_rate)
- avctx->sample_rate = 8000;
-
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ avctx->channels = 1;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ avctx->sample_rate = 8000;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
s->state = gsm_create();
diff --git a/libavcodec/libilbc.c b/libavcodec/libilbc.c
index fe1fa39718..462622a2d5 100644
--- a/libavcodec/libilbc.c
+++ b/libavcodec/libilbc.c
@@ -21,6 +21,7 @@
#include <ilbc.h>
+#include "libavutil/audioconvert.h"
#include "avcodec.h"
#include "libavutil/common.h"
#include "libavutil/opt.h"
@@ -71,9 +72,10 @@ static av_cold int ilbc_decode_init(AVCodecContext *avctx)
avcodec_get_frame_defaults(&s->frame);
avctx->coded_frame = &s->frame;
- avctx->channels = 1;
- avctx->sample_rate = 8000;
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ avctx->channels = 1;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ avctx->sample_rate = 8000;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
return 0;
}
diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index aa6dfa62ec..2a7d252c67 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/audioconvert.h"
#include "avcodec.h"
#include "libavutil/avstring.h"
#include "libavutil/common.h"
@@ -30,13 +31,16 @@ static void 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;
+ 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;
}
#if CONFIG_LIBOPENCORE_AMRNB
diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c
index ae98bf5c31..8413ea5ce7 100644
--- a/libavcodec/nellymoserdec.c
+++ b/libavcodec/nellymoserdec.c
@@ -129,6 +129,7 @@ static av_cold int decode_init(AVCodecContext * avctx) {
if (!ff_sine_128[127])
ff_init_ff_sine_windows(7);
+ avctx->channels = 1;
avctx->channel_layout = AV_CH_LAYOUT_MONO;
avcodec_get_frame_defaults(&s->frame);
diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c
index 7f27081d26..9cc30f6397 100644
--- a/libavcodec/qcelpdec.c
+++ b/libavcodec/qcelpdec.c
@@ -29,6 +29,7 @@
#include <stddef.h>
+#include "libavutil/audioconvert.h"
#include "avcodec.h"
#include "internal.h"
#include "get_bits.h"
@@ -89,7 +90,9 @@ static av_cold int qcelp_decode_init(AVCodecContext *avctx)
QCELPContext *q = avctx->priv_data;
int i;
- avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
+ avctx->channels = 1;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
for (i = 0; i < 10; i++)
q->prev_lspf[i] = (i + 1) / 11.;
diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c
index 3a77e7fe06..1d0fb3774e 100644
--- a/libavcodec/qdm2.c
+++ b/libavcodec/qdm2.c
@@ -36,6 +36,7 @@
#include <stdio.h>
#define BITSTREAM_READER_LE
+#include "libavutil/audioconvert.h"
#include "avcodec.h"
#include "get_bits.h"
#include "dsputil.h"
@@ -550,10 +551,6 @@ static void fill_tone_level_array (QDM2Context *q, int flag)
int i, sb, ch, sb_used;
int tmp, tab;
- // This should never happen
- if (q->nb_channels <= 0)
- return;
-
for (ch = 0; ch < q->nb_channels; ch++)
for (sb = 0; sb < 30; sb++)
for (i = 0; i < 8; i++) {
@@ -649,10 +646,6 @@ static void fill_coding_method_array (sb_int8_array tone_level_idx, sb_int8_arra
int add1, add2, add3, add4;
int64_t multres;
- // This should never happen
- if (nb_channels <= 0)
- return;
-
if (!superblocktype_2_3) {
/* This case is untested, no samples available */
SAMPLES_NEEDED
@@ -1792,10 +1785,12 @@ 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) {
- av_log(avctx, AV_LOG_ERROR, "Too many channels\n");
+ if (s->channels <= 0 || s->channels > MPA_MAX_CHANNELS) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
return AVERROR_INVALIDDATA;
}
+ avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
+ AV_CH_LAYOUT_MONO;
avctx->sample_rate = AV_RB32(extradata);
extradata += 4;
diff --git a/libavcodec/ra144dec.c b/libavcodec/ra144dec.c
index 9d44776d2e..acf6247c06 100644
--- a/libavcodec/ra144dec.c
+++ b/libavcodec/ra144dec.c
@@ -22,6 +22,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/audioconvert.h"
#include "libavutil/intmath.h"
#include "avcodec.h"
#include "get_bits.h"
@@ -37,7 +38,9 @@ static av_cold int ra144_decode_init(AVCodecContext * avctx)
ractx->lpc_coef[0] = ractx->lpc_tables[0];
ractx->lpc_coef[1] = ractx->lpc_tables[1];
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ avctx->channels = 1;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
avcodec_get_frame_defaults(&ractx->frame);
avctx->coded_frame = &ractx->frame;
diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c
index 28606e8628..41364f36bc 100644
--- a/libavcodec/ra288.c
+++ b/libavcodec/ra288.c
@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/audioconvert.h"
#include "libavutil/float_dsp.h"
#include "avcodec.h"
#define BITSTREAM_READER_LE
@@ -61,7 +62,11 @@ typedef struct {
static av_cold int ra288_decode_init(AVCodecContext *avctx)
{
RA288Context *ractx = avctx->priv_data;
- avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
+
+ avctx->channels = 1;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
+
avpriv_float_dsp_init(&ractx->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
avcodec_get_frame_defaults(&ractx->frame);
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index 45bc635cd0..7f067d9b61 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -340,7 +340,7 @@ static int read_header(ShortenContext *s)
s->internal_ftype = get_uint(s, TYPESIZE);
s->channels = get_uint(s, CHANSIZE);
- if (s->channels > MAX_CHANNELS) {
+ if (s->channels <= 0 || s->channels > MAX_CHANNELS) {
av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels);
return -1;
}
diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c
index fc03259b0b..986310dda9 100644
--- a/libavcodec/sipr.c
+++ b/libavcodec/sipr.c
@@ -25,6 +25,7 @@
#include <stdint.h>
#include <string.h>
+#include "libavutil/audioconvert.h"
#include "libavutil/mathematics.h"
#include "avcodec.h"
#define BITSTREAM_READER_LE
@@ -509,7 +510,9 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx)
for (i = 0; i < 4; i++)
ctx->energy_history[i] = -14;
- avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
+ avctx->channels = 1;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
avcodec_get_frame_defaults(&ctx->frame);
avctx->coded_frame = &ctx->frame;
diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c
index 6a1e439adf..686bf080ec 100644
--- a/libavcodec/truespeech.c
+++ b/libavcodec/truespeech.c
@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/audioconvert.h"
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#include "dsputil.h"
@@ -66,7 +67,8 @@ static av_cold int truespeech_decode_init(AVCodecContext * avctx)
return AVERROR(EINVAL);
}
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
ff_dsputil_init(&c->dsp, avctx);
diff --git a/libavcodec/twinvq.c b/libavcodec/twinvq.c
index f47f4c30f1..f4eba4d906 100644
--- a/libavcodec/twinvq.c
+++ b/libavcodec/twinvq.c
@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/audioconvert.h"
#include "libavutil/float_dsp.h"
#include "avcodec.h"
#include "get_bits.h"
@@ -1119,6 +1120,11 @@ static av_cold int twin_decode_init(AVCodecContext *avctx)
avctx->channels = AV_RB32(avctx->extradata ) + 1;
avctx->bit_rate = AV_RB32(avctx->extradata + 4) * 1000;
isampf = AV_RB32(avctx->extradata + 8);
+
+ if (isampf < 8 || isampf > 44) {
+ av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate\n");
+ return AVERROR_INVALIDDATA;
+ }
switch (isampf) {
case 44: avctx->sample_rate = 44100; break;
case 22: avctx->sample_rate = 22050; break;
@@ -1126,11 +1132,14 @@ static av_cold int twin_decode_init(AVCodecContext *avctx)
default: avctx->sample_rate = isampf * 1000; break;
}
- if (avctx->channels > CHANNELS_MAX) {
+ if (avctx->channels <= 0 || avctx->channels > CHANNELS_MAX) {
av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n",
avctx->channels);
return -1;
}
+ avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
+ AV_CH_LAYOUT_STEREO;
+
ibps = avctx->bit_rate / (1000 * avctx->channels);
switch ((isampf << 8) + ibps) {
diff --git a/libavcodec/vmdav.c b/libavcodec/vmdav.c
index 2b298fedef..1ecf211582 100644
--- a/libavcodec/vmdav.c
+++ b/libavcodec/vmdav.c
@@ -43,6 +43,7 @@
#include <stdlib.h>
#include <string.h>
+#include "libavutil/audioconvert.h"
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
@@ -501,6 +502,9 @@ static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
+ avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
+ AV_CH_LAYOUT_STEREO;
+
if (avctx->bits_per_coded_sample == 16)
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
else