[FFmpeg-devel] [PATCH]Ticket 55, v2
Carl Eugen Hoyos
cehoyos at ag.or.at
Thu Jun 9 10:30:41 CEST 2011
Hi!
On Wednesday 08 June 2011 09:28:09 pm Baptiste Coudurier wrote:
> > +static const uint8_t channel_maps[][AAC_MAX_CHANNELS] = {
> > + { 0 },
> > + { 0, 1 },
> > + { 2, 0, 1 },
> > + { 2, 0, 1, 3 },
> > + { 2, 0, 1, 3, 4 },
> > + { 2, 0, 1, 4, 5, 3 },
> > +};
>
> Can we use #defines for this ?
Could you elaborate?
I suspect attached is not what you suggested or am I wrong?
Thank you, Carl Eugen
-------------- next part --------------
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 66af2b1..c639df9 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -135,6 +135,10 @@ static const uint8_t aac_chan_configs[6][5] = {
{4, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_LFE}, // 6 channels - front center + stereo + back stereo + LFE
};
+static const uint8_t channel_maps[][AAC_MAX_CHANNELS] = {
+ AAC_CHANNEL_MAPS
+};
+
/**
* Make AAC audio config object.
* @see 1.6.2.1 "Syntax - AudioSpecificConfig"
@@ -499,15 +503,24 @@ static int aac_encode_frame(AVCodecContext *avctx,
return 0;
if (data) {
if (!s->psypp) {
+ if (avctx->channels <= 2) {
memcpy(s->samples + 1024 * avctx->channels, data,
1024 * avctx->channels * sizeof(s->samples[0]));
+ } else {
+ for (i = 0; i < 1024; i++)
+ for (ch = 0; ch < avctx->channels; ch++)
+ s->samples[(i + 1024) * avctx->channels + ch] =
+ ((int16_t*)data)[i * avctx->channels +
+ channel_maps[avctx->channels-1][ch]];
+ }
} else {
start_ch = 0;
samples2 = s->samples + 1024 * avctx->channels;
for (i = 0; i < chan_map[0]; i++) {
tag = chan_map[i+1];
chans = tag == TYPE_CPE ? 2 : 1;
- ff_psy_preprocess(s->psypp, (uint16_t*)data + start_ch,
+ ff_psy_preprocess(s->psypp,
+ (uint16_t*)data + channel_maps[avctx->channels-1][start_ch],
samples2 + start_ch, start_ch, chans);
start_ch += chans;
}
diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h
index 44ad50b..e17c633 100644
--- a/libavcodec/aacenc.h
+++ b/libavcodec/aacenc.h
@@ -73,4 +73,12 @@ typedef struct AACEncContext {
DECLARE_ALIGNED(32, float, scoefs)[1024]; ///< scaled coefficients
} AACEncContext;
+#define AAC_CHANNEL_MAPS \
+ { 0 }, \
+ { 0, 1 }, \
+ { 2, 0, 1 }, \
+ { 2, 0, 1, 3 }, \
+ { 2, 0, 1, 3, 4 }, \
+ { 2, 0, 1, 4, 5, 3 }, \
+
#endif /* AVCODEC_AACENC_H */
-------------- next part --------------
diff --git a/libavcodec/libfaac.c b/libavcodec/libfaac.c
index af85587..83f9d19 100644
--- a/libavcodec/libfaac.c
+++ b/libavcodec/libfaac.c
@@ -25,12 +25,19 @@
*/
#include "avcodec.h"
+#include "aacenc.h"
#include <faac.h>
typedef struct FaacAudioContext {
faacEncHandle faac_handle;
} FaacAudioContext;
+#define MAX_FAAC_CHANNELS 6
+
+static const int channel_maps[][MAX_FAAC_CHANNELS] = {
+ AAC_CHANNEL_MAPS
+};
+
static av_cold int Faac_encode_init(AVCodecContext *avctx)
{
FaacAudioContext *s = avctx->priv_data;
@@ -38,7 +45,7 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx)
unsigned long samples_input, max_bytes_output;
/* number of channels */
- if (avctx->channels < 1 || avctx->channels > 6) {
+ if (avctx->channels < 1 || avctx->channels > MAX_FAAC_CHANNELS) {
av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed\n", avctx->channels);
return -1;
}
@@ -86,6 +93,9 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx)
}
faac_cfg->outputFormat = 1;
faac_cfg->inputFormat = FAAC_INPUT_16BIT;
+ if (avctx->channels > 2)
+ memcpy(faac_cfg->channel_map, channel_maps[avctx->channels-1],
+ MAX_FAAC_CHANNELS * sizeof(int));
avctx->frame_size = samples_input / avctx->channels;
More information about the ffmpeg-devel
mailing list