aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-11-02 13:39:53 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-11-02 13:43:57 +0100
commitdb9f426caba574719c58de12e68742063c8e7979 (patch)
tree4d61a4a10f3b96e3bbc20a01f3d597d68b4181e5 /libavcodec
parenta5f6720f13c7678c61be1413debf3e11e678781c (diff)
parent8ac0f6767bf63d3e6b308ee6648ff02598b81e03 (diff)
downloadffmpeg-db9f426caba574719c58de12e68742063c8e7979.tar.gz
Merge commit '8ac0f6767bf63d3e6b308ee6648ff02598b81e03'
* commit '8ac0f6767bf63d3e6b308ee6648ff02598b81e03': dcadec: allow the decoder to change the channel layout mid-stream cook: use av_dlog() for debug logging instead of av_log() with AV_LOG_ERROR cook: move samples_per_frame from COOKSubpacket to where it is used cook: use av_get_channel_layout_nb_channels() instead of cook_count_channels() cook: reverse a condition so that the code makes more sense cook: remove unneeded COOKContext variable, sample_rate cook: remove unneeded COOKContext variable, bit_rate cook: use AVCodecContext.channels instead of keeping a private copy bmvaudio: set channel layout at init() rather than validating it atrac1: do not keep a copy of channel count in the private context dsicinaudio: set channels and channel layout g722dec: set channel layout at initialization instead of validating it amrwbdec: set channels, channel_layout, and sample_rate amrnbdec: set channels, channel_layout, and sample_rate dca_parser: allow the parser to change the sample rate lavc: check channel count after decoder init lavc: move SANE_NB_CHANNELS to internal.h and use it in the PCM decoders Conflicts: libavcodec/dcadec.c libavcodec/pcm.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/amrnbdec.c11
-rw-r--r--libavcodec/amrwbdec.c11
-rw-r--r--libavcodec/atrac1.c6
-rw-r--r--libavcodec/bmv.c10
-rw-r--r--libavcodec/cook.c60
-rw-r--r--libavcodec/dca_parser.c3
-rw-r--r--libavcodec/dsicinav.c12
-rw-r--r--libavcodec/g722dec.c9
-rw-r--r--libavcodec/internal.h2
-rw-r--r--libavcodec/pcm.c4
-rw-r--r--libavcodec/utils.c8
11 files changed, 66 insertions, 70 deletions
diff --git a/libavcodec/amrnbdec.c b/libavcodec/amrnbdec.c
index 6ba6fbe3ad..95deee63f2 100644
--- a/libavcodec/amrnbdec.c
+++ b/libavcodec/amrnbdec.c
@@ -43,6 +43,7 @@
#include <string.h>
#include <math.h>
+#include "libavutil/audioconvert.h"
#include "avcodec.h"
#include "dsputil.h"
#include "libavutil/common.h"
@@ -161,7 +162,15 @@ static av_cold int amrnb_decode_init(AVCodecContext *avctx)
AMRContext *p = avctx->priv_data;
int i;
- avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
+ if (avctx->channels > 1) {
+ av_log_missing_feature(avctx, "multi-channel AMR", 0);
+ return AVERROR_PATCHWELCOME;
+ }
+
+ avctx->channels = 1;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ avctx->sample_rate = 8000;
+ avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
// p->excitation always points to the same position in p->excitation_buf
p->excitation = &p->excitation_buf[PITCH_DELAY_MAX + LP_FILTER_ORDER + 1];
diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index eaaf66bf00..79a9f14a1c 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -24,6 +24,7 @@
* AMR wideband decoder
*/
+#include "libavutil/audioconvert.h"
#include "libavutil/common.h"
#include "libavutil/lfg.h"
@@ -97,7 +98,15 @@ static av_cold int amrwb_decode_init(AVCodecContext *avctx)
AMRWBContext *ctx = avctx->priv_data;
int i;
- avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
+ if (avctx->channels > 1) {
+ av_log_missing_feature(avctx, "multi-channel AMR", 0);
+ return AVERROR_PATCHWELCOME;
+ }
+
+ avctx->channels = 1;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ avctx->sample_rate = 16000;
+ avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
av_lfg_init(&ctx->prng, 1);
diff --git a/libavcodec/atrac1.c b/libavcodec/atrac1.c
index 86d371e8c8..26f5cb1739 100644
--- a/libavcodec/atrac1.c
+++ b/libavcodec/atrac1.c
@@ -80,7 +80,6 @@ typedef struct {
DECLARE_ALIGNED(32, float, high)[512];
float* bands[3];
FFTContext mdct_ctx[3];
- int channels;
DSPContext dsp;
} AT1Ctx;
@@ -280,7 +279,7 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
GetBitContext gb;
- if (buf_size < 212 * q->channels) {
+ if (buf_size < 212 * avctx->channels) {
av_log(avctx, AV_LOG_ERROR, "Not enough data to decode!\n");
return AVERROR_INVALIDDATA;
}
@@ -292,7 +291,7 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
return ret;
}
- for (ch = 0; ch < q->channels; ch++) {
+ for (ch = 0; ch < avctx->channels; ch++) {
AT1SUCtx* su = &q->SUs[ch];
init_get_bits(&gb, &buf[212 * ch], 212 * 8);
@@ -343,7 +342,6 @@ static av_cold int atrac1_decode_init(AVCodecContext *avctx)
avctx->channels);
return AVERROR(EINVAL);
}
- q->channels = avctx->channels;
/* Init the mdct transforms */
if ((ret = ff_mdct_init(&q->mdct_ctx[0], 6, 1, -1.0/ (1 << 15))) ||
diff --git a/libavcodec/bmv.c b/libavcodec/bmv.c
index c9066dfa5c..b05bd49038 100644
--- a/libavcodec/bmv.c
+++ b/libavcodec/bmv.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 "bytestream.h"
#include "libavutil/avassert.h"
@@ -311,12 +312,9 @@ static av_cold int bmv_aud_decode_init(AVCodecContext *avctx)
{
BMVAudioDecContext *c = avctx->priv_data;
- if (avctx->channels != 2) {
- av_log(avctx, AV_LOG_INFO, "invalid number of channels\n");
- return AVERROR(EINVAL);
- }
-
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ avctx->channels = 2;
+ avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
avcodec_get_frame_defaults(&c->frame);
avctx->coded_frame = &c->frame;
diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index ea8aad62ef..118d1afbad 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -72,7 +72,6 @@ typedef struct {
int size;
int num_channels;
int cookversion;
- int samples_per_frame;
int subbands;
int js_subband_start;
int js_vlc_bits;
@@ -126,9 +125,6 @@ typedef struct cook {
AVFrame frame;
GetBitContext gb;
/* stream data */
- int nb_channels;
- int bit_rate;
- int sample_rate;
int num_vectors;
int samples_per_channel;
/* states */
@@ -1028,19 +1024,18 @@ static int cook_decode_frame(AVCodecContext *avctx, void *data,
static void dump_cook_context(COOKContext *q)
{
//int i=0;
-#define PRINT(a, b) av_log(q->avctx, AV_LOG_ERROR, " %s = %d\n", a, b);
- av_log(q->avctx, AV_LOG_ERROR, "COOKextradata\n");
- av_log(q->avctx, AV_LOG_ERROR, "cookversion=%x\n", q->subpacket[0].cookversion);
+#define PRINT(a, b) av_dlog(q->avctx, " %s = %d\n", a, b);
+ av_dlog(q->avctx, "COOKextradata\n");
+ av_dlog(q->avctx, "cookversion=%x\n", q->subpacket[0].cookversion);
if (q->subpacket[0].cookversion > STEREO) {
PRINT("js_subband_start", q->subpacket[0].js_subband_start);
PRINT("js_vlc_bits", q->subpacket[0].js_vlc_bits);
}
- av_log(q->avctx, AV_LOG_ERROR, "COOKContext\n");
- PRINT("nb_channels", q->nb_channels);
- PRINT("bit_rate", q->bit_rate);
- PRINT("sample_rate", q->sample_rate);
+ av_dlog(q->avctx, "COOKContext\n");
+ PRINT("nb_channels", q->avctx->channels);
+ PRINT("bit_rate", q->avctx->bit_rate);
+ PRINT("sample_rate", q->avctx->sample_rate);
PRINT("samples_per_channel", q->subpacket[0].samples_per_channel);
- PRINT("samples_per_frame", q->subpacket[0].samples_per_frame);
PRINT("subbands", q->subpacket[0].subbands);
PRINT("js_subband_start", q->subpacket[0].js_subband_start);
PRINT("log2_numvector_size", q->subpacket[0].log2_numvector_size);
@@ -1049,16 +1044,6 @@ static void dump_cook_context(COOKContext *q)
}
#endif
-static av_cold int cook_count_channels(unsigned int mask)
-{
- int i;
- int channels = 0;
- for (i = 0; i < 32; i++)
- if (mask & (1 << i))
- ++channels;
- return channels;
-}
-
/**
* Cook initialization
*
@@ -1072,6 +1057,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
int extradata_size = avctx->extradata_size;
int s = 0;
unsigned int channel_mask = 0;
+ int samples_per_frame;
int ret;
q->avctx = avctx;
@@ -1083,10 +1069,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_DEBUG, "codecdata_length=%d\n", avctx->extradata_size);
/* Take data from the AVCodecContext (RM container). */
- q->sample_rate = avctx->sample_rate;
- q->nb_channels = avctx->channels;
- q->bit_rate = avctx->bit_rate;
- if (!q->nb_channels) {
+ if (!avctx->channels) {
av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
return AVERROR_INVALIDDATA;
}
@@ -1101,7 +1084,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
Swap to right endianness so we don't need to care later on. */
if (extradata_size >= 8) {
q->subpacket[s].cookversion = bytestream_get_be32(&edata_ptr);
- q->subpacket[s].samples_per_frame = bytestream_get_be16(&edata_ptr);
+ samples_per_frame = bytestream_get_be16(&edata_ptr);
q->subpacket[s].subbands = bytestream_get_be16(&edata_ptr);
extradata_size -= 8;
}
@@ -1113,7 +1096,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
}
/* Initialize extradata related variables. */
- q->subpacket[s].samples_per_channel = q->subpacket[s].samples_per_frame / q->nb_channels;
+ q->subpacket[s].samples_per_channel = samples_per_frame / avctx->channels;
q->subpacket[s].bits_per_subpacket = avctx->block_align * 8;
/* Initialize default data states. */
@@ -1128,21 +1111,21 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
q->subpacket[s].joint_stereo = 0;
switch (q->subpacket[s].cookversion) {
case MONO:
- if (q->nb_channels != 1) {
+ if (avctx->channels != 1) {
av_log_ask_for_sample(avctx, "Container channels != 1.\n");
return AVERROR_PATCHWELCOME;
}
av_log(avctx, AV_LOG_DEBUG, "MONO\n");
break;
case STEREO:
- if (q->nb_channels != 1) {
+ if (avctx->channels != 1) {
q->subpacket[s].bits_per_subpdiv = 1;
q->subpacket[s].num_channels = 2;
}
av_log(avctx, AV_LOG_DEBUG, "STEREO\n");
break;
case JOINT_STEREO:
- if (q->nb_channels != 2) {
+ if (avctx->channels != 2) {
av_log_ask_for_sample(avctx, "Container channels != 2.\n");
return AVERROR_PATCHWELCOME;
}
@@ -1165,12 +1148,12 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
if (extradata_size >= 4)
channel_mask |= q->subpacket[s].channel_mask = bytestream_get_be32(&edata_ptr);
- if (cook_count_channels(q->subpacket[s].channel_mask) > 1) {
+ if (av_get_channel_layout_nb_channels(q->subpacket[s].channel_mask) > 1) {
q->subpacket[s].total_subbands = q->subpacket[s].subbands +
q->subpacket[s].js_subband_start;
q->subpacket[s].joint_stereo = 1;
q->subpacket[s].num_channels = 2;
- q->subpacket[s].samples_per_channel = q->subpacket[s].samples_per_frame >> 1;
+ q->subpacket[s].samples_per_channel = samples_per_frame >> 1;
if (q->subpacket[s].samples_per_channel > 256) {
q->subpacket[s].log2_numvector_size = 6;
@@ -1179,7 +1162,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
q->subpacket[s].log2_numvector_size = 7;
}
} else
- q->subpacket[s].samples_per_channel = q->subpacket[s].samples_per_frame;
+ q->subpacket[s].samples_per_channel = samples_per_frame;
break;
default:
@@ -1219,8 +1202,8 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
q->subpacket[s].gains2.now = q->subpacket[s].gain_3;
q->subpacket[s].gains2.previous = q->subpacket[s].gain_4;
- if (q->num_subpackets + q->subpacket[s].num_channels > q->nb_channels) {
- av_log(avctx, AV_LOG_ERROR, "Too many subpackets %d for channels %d\n", q->num_subpackets, q->nb_channels);
+ if (q->num_subpackets + q->subpacket[s].num_channels > q->avctx->channels) {
+ av_log(avctx, AV_LOG_ERROR, "Too many subpackets %d for channels %d\n", q->num_subpackets, q->avctx->channels);
return AVERROR_INVALIDDATA;
}
@@ -1267,9 +1250,8 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
}
/* Try to catch some obviously faulty streams, othervise it might be exploitable */
- if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512)
- || (q->samples_per_channel == 1024)) {
- } else {
+ if (q->samples_per_channel != 256 && q->samples_per_channel != 512 &&
+ q->samples_per_channel != 1024) {
av_log_ask_for_sample(avctx,
"unknown amount of samples_per_channel = %d\n",
q->samples_per_channel);
diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index 5ccaaccf11..266520f36c 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -190,8 +190,7 @@ static int dca_parse(AVCodecParserContext * s,
/* read the duration and sample rate from the frame header */
if (!dca_parse_params(buf, buf_size, &duration, &sample_rate)) {
s->duration = duration;
- if (!avctx->sample_rate)
- avctx->sample_rate = sample_rate;
+ avctx->sample_rate = sample_rate;
} else
s->duration = 0;
diff --git a/libavcodec/dsicinav.c b/libavcodec/dsicinav.c
index ddec868baa..fec267f98e 100644
--- a/libavcodec/dsicinav.c
+++ b/libavcodec/dsicinav.c
@@ -24,6 +24,7 @@
* Delphine Software International CIN audio/video decoders
*/
+#include "libavutil/audioconvert.h"
#include "avcodec.h"
#include "bytestream.h"
#include "mathops.h"
@@ -341,14 +342,11 @@ static av_cold int cinaudio_decode_init(AVCodecContext *avctx)
{
CinAudioContext *cin = avctx->priv_data;
- if (avctx->channels != 1) {
- av_log_ask_for_sample(avctx, "Number of channels is not supported\n");
- return AVERROR_PATCHWELCOME;
- }
-
cin->initial_decode_frame = 1;
- cin->delta = 0;
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ cin->delta = 0;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ avctx->channels = 1;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
avcodec_get_frame_defaults(&cin->frame);
avctx->coded_frame = &cin->frame;
diff --git a/libavcodec/g722dec.c b/libavcodec/g722dec.c
index 974ba25e19..6c505d93b9 100644
--- a/libavcodec/g722dec.c
+++ b/libavcodec/g722dec.c
@@ -34,6 +34,7 @@
* respectively of each byte are ignored.
*/
+#include "libavutil/audioconvert.h"
#include "avcodec.h"
#include "get_bits.h"
#include "g722.h"
@@ -57,11 +58,9 @@ static av_cold int g722_decode_init(AVCodecContext * avctx)
{
G722Context *c = avctx->priv_data;
- if (avctx->channels != 1) {
- av_log(avctx, AV_LOG_ERROR, "Only mono tracks are allowed.\n");
- return AVERROR_INVALIDDATA;
- }
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ avctx->channels = 1;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
c->band[0].scale_factor = 8;
c->band[1].scale_factor = 2;
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 9a8b4bc336..a5e52b0c10 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -30,6 +30,8 @@
#include "libavutil/pixfmt.h"
#include "avcodec.h"
+#define FF_SANE_NB_CHANNELS 128U
+
typedef struct InternalBuffer {
uint8_t *base[AV_NUM_DATA_POINTERS];
uint8_t *data[AV_NUM_DATA_POINTERS];
diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 7f4db373fb..c00f0b0cb8 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -31,8 +31,6 @@
#include "mathops.h"
#include "pcm_tablegen.h"
-#define MAX_CHANNELS 64
-
static av_cold int pcm_encode_init(AVCodecContext *avctx)
{
avctx->frame_size = 0;
@@ -208,7 +206,7 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx)
PCMDecode *s = avctx->priv_data;
int i;
- if (avctx->channels <= 0 || avctx->channels > MAX_CHANNELS) {
+ if (avctx->channels <= 0) {
av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
return AVERROR(EINVAL);
}
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 2cc33ba717..2b7ab46f2a 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -907,8 +907,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
if (av_codec_is_decoder(codec))
av_freep(&avctx->subtitle_header);
-#define SANE_NB_CHANNELS 128U
- if (avctx->channels > SANE_NB_CHANNELS) {
+ if (avctx->channels > FF_SANE_NB_CHANNELS) {
ret = AVERROR(EINVAL);
goto free_and_end;
}
@@ -1091,6 +1090,11 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
avctx->channel_layout = 0;
}
}
+ if (avctx->channels && avctx->channels < 0 ||
+ avctx->channels > FF_SANE_NB_CHANNELS) {
+ ret = AVERROR(EINVAL);
+ goto free_and_end;
+ }
}
end:
entangled_thread_counter--;