1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

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>
This commit is contained in:
Michael Niedermayer 2012-11-02 14:15:28 +01:00
commit 6788350281
21 changed files with 142 additions and 101 deletions

View File

@ -44,7 +44,6 @@
typedef struct DPCMContext { typedef struct DPCMContext {
AVFrame frame; AVFrame frame;
int channels;
int16_t roq_square_array[256]; int16_t roq_square_array[256];
int sample[2]; ///< previous sample (for SOL_DPCM) int sample[2]; ///< previous sample (for SOL_DPCM)
const int8_t *sol_table; ///< delta table 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); return AVERROR(EINVAL);
} }
s->channels = avctx->channels;
s->sample[0] = s->sample[1] = 0; s->sample[0] = s->sample[1] = 0;
switch(avctx->codec->id) { switch(avctx->codec->id) {
@ -179,7 +177,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
int out = 0, ret; int out = 0, ret;
int predictor[2]; int predictor[2];
int ch = 0; int ch = 0;
int stereo = s->channels - 1; int stereo = avctx->channels - 1;
int16_t *output_samples, *samples_end; int16_t *output_samples, *samples_end;
GetByteContext gb; GetByteContext gb;
@ -193,10 +191,10 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
out = buf_size - 8; out = buf_size - 8;
break; break;
case AV_CODEC_ID_INTERPLAY_DPCM: case AV_CODEC_ID_INTERPLAY_DPCM:
out = buf_size - 6 - s->channels; out = buf_size - 6 - avctx->channels;
break; break;
case AV_CODEC_ID_XAN_DPCM: case AV_CODEC_ID_XAN_DPCM:
out = buf_size - 2 * s->channels; out = buf_size - 2 * avctx->channels;
break; break;
case AV_CODEC_ID_SOL_DPCM: case AV_CODEC_ID_SOL_DPCM:
if (avctx->codec_tag != 3) 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"); av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
if (out % s->channels) { if (out % avctx->channels) {
av_log(avctx, AV_LOG_WARNING, "channels have differing number of samples\n"); av_log(avctx, AV_LOG_WARNING, "channels have differing number of samples\n");
} }
/* get output buffer */ /* 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) { if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret; return ret;
@ -248,7 +246,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
case AV_CODEC_ID_INTERPLAY_DPCM: case AV_CODEC_ID_INTERPLAY_DPCM:
bytestream2_skipu(&gb, 6); /* skip over the stream mask and stream length */ 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); predictor[ch] = sign_extend(bytestream2_get_le16u(&gb), 16);
*output_samples++ = predictor[ch]; *output_samples++ = predictor[ch];
} }
@ -268,7 +266,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
{ {
int shift[2] = { 4, 4 }; 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); predictor[ch] = sign_extend(bytestream2_get_le16u(&gb), 16);
ch = 0; ch = 0;

View File

@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/audioconvert.h"
#include "libavutil/crc.h" #include "libavutil/crc.h"
#include "libavutil/log.h" #include "libavutil/log.h"
#include "bytestream.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 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) static int64_t get_utf8(GetBitContext *gb)
{ {
int64_t val; int64_t val;
@ -181,6 +191,14 @@ int avpriv_flac_is_extradata_valid(AVCodecContext *avctx,
return 1; 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, void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
const uint8_t *buffer) const uint8_t *buffer)
{ {
@ -205,6 +223,7 @@ void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *
avctx->channels = s->channels; avctx->channels = s->channels;
avctx->sample_rate = s->samplerate; avctx->sample_rate = s->samplerate;
avctx->bits_per_raw_sample = s->bps; avctx->bits_per_raw_sample = s->bps;
ff_flac_set_channel_layout(avctx);
s->samples = get_bits_longlong(&gb, 36); s->samples = get_bits_longlong(&gb, 36);

View File

@ -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, int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
FLACFrameInfo *fi, int log_level_offset); FLACFrameInfo *fi, int log_level_offset);
void ff_flac_set_channel_layout(AVCodecContext *avctx);
#endif /* AVCODEC_FLAC_H */ #endif /* AVCODEC_FLAC_H */

View File

@ -459,6 +459,7 @@ static int get_best_header(FLACParseContext* fpc, const uint8_t **poutbuf,
fpc->avctx->sample_rate = header->fi.samplerate; fpc->avctx->sample_rate = header->fi.samplerate;
fpc->avctx->channels = header->fi.channels; fpc->avctx->channels = header->fi.channels;
ff_flac_set_channel_layout(fpc->avctx);
fpc->pc->duration = header->fi.blocksize; fpc->pc->duration = header->fi.blocksize;
*poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size, *poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size,
&fpc->wrap_buf, &fpc->wrap_buf,

View File

@ -58,20 +58,13 @@ typedef struct FLACContext {
int got_streaminfo; ///< indicates if the STREAMINFO has been read int got_streaminfo; ///< indicates if the STREAMINFO has been read
int32_t *decoded[FLAC_MAX_CHANNELS]; ///< decoded samples int32_t *decoded[FLAC_MAX_CHANNELS]; ///< decoded samples
uint8_t *decoded_buffer;
unsigned int decoded_buffer_size;
FLACDSPContext dsp; FLACDSPContext dsp;
} FLACContext; } FLACContext;
static const int64_t flac_channel_layouts[6] = { static int allocate_buffers(FLACContext *s);
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 void flac_set_bps(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; enum FLACExtradataFormat format;
uint8_t *streaminfo; uint8_t *streaminfo;
int ret;
FLACContext *s = avctx->priv_data; FLACContext *s = avctx->priv_data;
s->avctx = avctx; s->avctx = avctx;
@ -112,7 +106,9 @@ static av_cold int flac_decode_init(AVCodecContext *avctx)
/* initialize based on the demuxer-supplied streamdata header */ /* initialize based on the demuxer-supplied streamdata header */
avpriv_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo); avpriv_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo);
allocate_buffers(s); ret = allocate_buffers(s);
if (ret < 0)
return ret;
flac_set_bps(s); flac_set_bps(s);
ff_flacdsp_init(&s->dsp, avctx->sample_fmt, s->bps); ff_flacdsp_init(&s->dsp, avctx->sample_fmt, s->bps);
s->got_streaminfo = 1; s->got_streaminfo = 1;
@ -120,9 +116,6 @@ static av_cold int flac_decode_init(AVCodecContext *avctx)
avcodec_get_frame_defaults(&s->frame); avcodec_get_frame_defaults(&s->frame);
avctx->coded_frame = &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; 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); 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); av_assert0(s->max_blocksize);
for (i = 0; i < s->channels; i++) { buf_size = av_samples_get_buffer_size(NULL, s->channels, s->max_blocksize,
s->decoded[i] = av_malloc(sizeof(int32_t)*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) 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) { if (buf_size < FLAC_STREAMINFO_SIZE+8) {
/* need more data */ /* need more data */
@ -167,7 +169,9 @@ static int parse_streaminfo(FLACContext *s, const uint8_t *buf, int buf_size)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
avpriv_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, &buf[8]); 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); flac_set_bps(s);
ff_flacdsp_init(&s->dsp, s->avctx->sample_fmt, s->bps); ff_flacdsp_init(&s->dsp, s->avctx->sample_fmt, s->bps);
s->got_streaminfo = 1; s->got_streaminfo = 1;
@ -403,7 +407,7 @@ static inline int decode_subframe(FLACContext *s, int channel)
static int decode_frame(FLACContext *s) static int decode_frame(FLACContext *s)
{ {
int i; int i, ret;
GetBitContext *gb = &s->gb; GetBitContext *gb = &s->gb;
FLACFrameInfo fi; FLACFrameInfo fi;
@ -412,12 +416,15 @@ static int decode_frame(FLACContext *s)
return -1; return -1;
} }
if (s->channels && fi.channels != s->channels) { if (s->channels && fi.channels != s->channels && s->got_streaminfo) {
av_log(s->avctx, AV_LOG_ERROR, "switching channel layout mid-stream " s->channels = s->avctx->channels = fi.channels;
"is not supported\n"); ff_flac_set_channel_layout(s->avctx);
return -1; ret = allocate_buffers(s);
if (ret < 0)
return ret;
} }
s->channels = s->avctx->channels = fi.channels; s->channels = s->avctx->channels = fi.channels;
ff_flac_set_channel_layout(s->avctx);
s->ch_mode = fi.ch_mode; s->ch_mode = fi.ch_mode;
if (!s->bps && !fi.bps) { if (!s->bps && !fi.bps) {
@ -451,16 +458,14 @@ static int decode_frame(FLACContext *s)
" or frame header\n"); " or frame header\n");
return -1; return -1;
} }
if (fi.samplerate == 0) { if (fi.samplerate == 0)
fi.samplerate = s->samplerate; 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; s->samplerate = s->avctx->sample_rate = fi.samplerate;
if (!s->got_streaminfo) { 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); ff_flacdsp_init(&s->dsp, s->avctx->sample_fmt, s->bps);
s->got_streaminfo = 1; s->got_streaminfo = 1;
dump_headers(s->avctx, (FLACStreaminfo *)s); 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) static av_cold int flac_decode_close(AVCodecContext *avctx)
{ {
FLACContext *s = avctx->priv_data; FLACContext *s = avctx->priv_data;
int i;
for (i = 0; i < s->channels; i++) { av_freep(&s->decoded_buffer);
av_freep(&s->decoded[i]);
}
return 0; return 0;
} }

View File

@ -22,6 +22,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <limits.h> #include <limits.h>
#include "libavutil/audioconvert.h"
#include "libavutil/avassert.h" #include "libavutil/avassert.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "avcodec.h" #include "avcodec.h"
@ -418,18 +420,8 @@ static av_cold int g726_decode_init(AVCodecContext *avctx)
{ {
G726Context* c = avctx->priv_data; G726Context* c = avctx->priv_data;
if (avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT && avctx->channels = 1;
avctx->sample_rate != 8000) { avctx->channel_layout = AV_CH_LAYOUT_MONO;
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);
}
c->code_size = avctx->bits_per_coded_sample; c->code_size = avctx->bits_per_coded_sample;
if (c->code_size < 2 || c->code_size > 5) { if (c->code_size < 2 || c->code_size > 5) {

View File

@ -24,6 +24,7 @@
* GSM decoder * GSM decoder
*/ */
#include "libavutil/audioconvert.h"
#include "avcodec.h" #include "avcodec.h"
#include "get_bits.h" #include "get_bits.h"
#include "msgsmdec.h" #include "msgsmdec.h"
@ -34,10 +35,10 @@ static av_cold int gsm_init(AVCodecContext *avctx)
{ {
GSMContext *s = avctx->priv_data; GSMContext *s = avctx->priv_data;
avctx->channels = 1; avctx->channels = 1;
if (!avctx->sample_rate) avctx->channel_layout = AV_CH_LAYOUT_MONO;
avctx->sample_rate = 8000; avctx->sample_rate = 8000;
avctx->sample_fmt = AV_SAMPLE_FMT_S16; avctx->sample_fmt = AV_SAMPLE_FMT_S16;
switch (avctx->codec_id) { switch (avctx->codec_id) {
case AV_CODEC_ID_GSM: case AV_CODEC_ID_GSM:

View File

@ -176,8 +176,10 @@ static av_cold int imc_decode_init(AVCodecContext *avctx)
IMCContext *q = avctx->priv_data; IMCContext *q = avctx->priv_data;
double r1, r2; double r1, r2;
if ((avctx->codec_id == AV_CODEC_ID_IMC && avctx->channels != 1) if (avctx->codec_id == AV_CODEC_ID_IMC)
|| (avctx->codec_id == AV_CODEC_ID_IAC && avctx->channels > 2)) { avctx->channels = 1;
if (avctx->channels > 2) {
av_log_ask_for_sample(avctx, "Number of channels is not supported\n"); av_log_ask_for_sample(avctx, "Number of channels is not supported\n");
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
} }

View File

@ -29,6 +29,7 @@
#include <gsm/gsm.h> #include <gsm/gsm.h>
#include "libavutil/audioconvert.h"
#include "avcodec.h" #include "avcodec.h"
#include "internal.h" #include "internal.h"
#include "gsm.h" #include "gsm.h"
@ -153,19 +154,10 @@ typedef struct LibGSMDecodeContext {
static av_cold int libgsm_decode_init(AVCodecContext *avctx) { static av_cold int libgsm_decode_init(AVCodecContext *avctx) {
LibGSMDecodeContext *s = avctx->priv_data; LibGSMDecodeContext *s = avctx->priv_data;
if (avctx->channels > 1) { avctx->channels = 1;
av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n", avctx->channel_layout = AV_CH_LAYOUT_MONO;
avctx->channels); avctx->sample_rate = 8000;
return -1; avctx->sample_fmt = AV_SAMPLE_FMT_S16;
}
if (!avctx->channels)
avctx->channels = 1;
if (!avctx->sample_rate)
avctx->sample_rate = 8000;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
s->state = gsm_create(); s->state = gsm_create();

View File

@ -21,6 +21,7 @@
#include <ilbc.h> #include <ilbc.h>
#include "libavutil/audioconvert.h"
#include "avcodec.h" #include "avcodec.h"
#include "libavutil/common.h" #include "libavutil/common.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
@ -71,9 +72,10 @@ static av_cold int ilbc_decode_init(AVCodecContext *avctx)
avcodec_get_frame_defaults(&s->frame); avcodec_get_frame_defaults(&s->frame);
avctx->coded_frame = &s->frame; avctx->coded_frame = &s->frame;
avctx->channels = 1; avctx->channels = 1;
avctx->sample_rate = 8000; avctx->channel_layout = AV_CH_LAYOUT_MONO;
avctx->sample_fmt = AV_SAMPLE_FMT_S16; avctx->sample_rate = 8000;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
return 0; return 0;
} }

View File

@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/audioconvert.h"
#include "avcodec.h" #include "avcodec.h"
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/common.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); 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) if (avctx->channels > 1) {
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 #if CONFIG_LIBOPENCORE_AMRNB

View File

@ -129,6 +129,7 @@ static av_cold int decode_init(AVCodecContext * avctx) {
if (!ff_sine_128[127]) if (!ff_sine_128[127])
ff_init_ff_sine_windows(7); ff_init_ff_sine_windows(7);
avctx->channels = 1;
avctx->channel_layout = AV_CH_LAYOUT_MONO; avctx->channel_layout = AV_CH_LAYOUT_MONO;
avcodec_get_frame_defaults(&s->frame); avcodec_get_frame_defaults(&s->frame);

View File

@ -29,6 +29,7 @@
#include <stddef.h> #include <stddef.h>
#include "libavutil/audioconvert.h"
#include "avcodec.h" #include "avcodec.h"
#include "internal.h" #include "internal.h"
#include "get_bits.h" #include "get_bits.h"
@ -89,7 +90,9 @@ static av_cold int qcelp_decode_init(AVCodecContext *avctx)
QCELPContext *q = avctx->priv_data; QCELPContext *q = avctx->priv_data;
int i; 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++) for (i = 0; i < 10; i++)
q->prev_lspf[i] = (i + 1) / 11.; q->prev_lspf[i] = (i + 1) / 11.;

View File

@ -36,6 +36,7 @@
#include <stdio.h> #include <stdio.h>
#define BITSTREAM_READER_LE #define BITSTREAM_READER_LE
#include "libavutil/audioconvert.h"
#include "avcodec.h" #include "avcodec.h"
#include "get_bits.h" #include "get_bits.h"
#include "dsputil.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 i, sb, ch, sb_used;
int tmp, tab; int tmp, tab;
// This should never happen
if (q->nb_channels <= 0)
return;
for (ch = 0; ch < q->nb_channels; ch++) for (ch = 0; ch < q->nb_channels; ch++)
for (sb = 0; sb < 30; sb++) for (sb = 0; sb < 30; sb++)
for (i = 0; i < 8; i++) { 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; int add1, add2, add3, add4;
int64_t multres; int64_t multres;
// This should never happen
if (nb_channels <= 0)
return;
if (!superblocktype_2_3) { if (!superblocktype_2_3) {
/* This case is untested, no samples available */ /* This case is untested, no samples available */
SAMPLES_NEEDED 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); avctx->channels = s->nb_channels = s->channels = AV_RB32(extradata);
extradata += 4; extradata += 4;
if (s->channels > MPA_MAX_CHANNELS) { if (s->channels <= 0 || s->channels > MPA_MAX_CHANNELS) {
av_log(avctx, AV_LOG_ERROR, "Too many channels\n"); av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
AV_CH_LAYOUT_MONO;
avctx->sample_rate = AV_RB32(extradata); avctx->sample_rate = AV_RB32(extradata);
extradata += 4; extradata += 4;

View File

@ -22,6 +22,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/audioconvert.h"
#include "libavutil/intmath.h" #include "libavutil/intmath.h"
#include "avcodec.h" #include "avcodec.h"
#include "get_bits.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[0] = ractx->lpc_tables[0];
ractx->lpc_coef[1] = ractx->lpc_tables[1]; 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); avcodec_get_frame_defaults(&ractx->frame);
avctx->coded_frame = &ractx->frame; avctx->coded_frame = &ractx->frame;

View File

@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/audioconvert.h"
#include "libavutil/float_dsp.h" #include "libavutil/float_dsp.h"
#include "avcodec.h" #include "avcodec.h"
#define BITSTREAM_READER_LE #define BITSTREAM_READER_LE
@ -61,7 +62,11 @@ typedef struct {
static av_cold int ra288_decode_init(AVCodecContext *avctx) static av_cold int ra288_decode_init(AVCodecContext *avctx)
{ {
RA288Context *ractx = avctx->priv_data; 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); avpriv_float_dsp_init(&ractx->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
avcodec_get_frame_defaults(&ractx->frame); avcodec_get_frame_defaults(&ractx->frame);

View File

@ -340,7 +340,7 @@ static int read_header(ShortenContext *s)
s->internal_ftype = get_uint(s, TYPESIZE); s->internal_ftype = get_uint(s, TYPESIZE);
s->channels = get_uint(s, CHANSIZE); 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); av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels);
return -1; return -1;
} }

View File

@ -25,6 +25,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include "libavutil/audioconvert.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "avcodec.h" #include "avcodec.h"
#define BITSTREAM_READER_LE #define BITSTREAM_READER_LE
@ -509,7 +510,9 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx)
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
ctx->energy_history[i] = -14; 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); avcodec_get_frame_defaults(&ctx->frame);
avctx->coded_frame = &ctx->frame; avctx->coded_frame = &ctx->frame;

View File

@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/audioconvert.h"
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "avcodec.h" #include "avcodec.h"
#include "dsputil.h" #include "dsputil.h"
@ -66,7 +67,8 @@ static av_cold int truespeech_decode_init(AVCodecContext * avctx)
return AVERROR(EINVAL); 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); ff_dsputil_init(&c->dsp, avctx);

View File

@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/audioconvert.h"
#include "libavutil/float_dsp.h" #include "libavutil/float_dsp.h"
#include "avcodec.h" #include "avcodec.h"
#include "get_bits.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->channels = AV_RB32(avctx->extradata ) + 1;
avctx->bit_rate = AV_RB32(avctx->extradata + 4) * 1000; avctx->bit_rate = AV_RB32(avctx->extradata + 4) * 1000;
isampf = AV_RB32(avctx->extradata + 8); 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) { switch (isampf) {
case 44: avctx->sample_rate = 44100; break; case 44: avctx->sample_rate = 44100; break;
case 22: avctx->sample_rate = 22050; 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; 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", av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n",
avctx->channels); avctx->channels);
return -1; return -1;
} }
avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
AV_CH_LAYOUT_STEREO;
ibps = avctx->bit_rate / (1000 * avctx->channels); ibps = avctx->bit_rate / (1000 * avctx->channels);
switch ((isampf << 8) + ibps) { switch ((isampf << 8) + ibps) {

View File

@ -43,6 +43,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "libavutil/audioconvert.h"
#include "libavutil/common.h" #include "libavutil/common.h"
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "avcodec.h" #include "avcodec.h"
@ -501,6 +502,9 @@ static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
AV_CH_LAYOUT_STEREO;
if (avctx->bits_per_coded_sample == 16) if (avctx->bits_per_coded_sample == 16)
avctx->sample_fmt = AV_SAMPLE_FMT_S16; avctx->sample_fmt = AV_SAMPLE_FMT_S16;
else else