ms_off is the default, until Mid/Side is no longer buggy.
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
| ... | ... |
@@ -30,6 +30,7 @@ |
| 30 | 30 |
* add temporal noise shaping |
| 31 | 31 |
***********************************/ |
| 32 | 32 |
|
| 33 |
+#include "libavutil/opt.h" |
|
| 33 | 34 |
#include "avcodec.h" |
| 34 | 35 |
#include "put_bits.h" |
| 35 | 36 |
#include "dsputil.h" |
| ... | ... |
@@ -489,7 +490,7 @@ static int aac_encode_frame(AVCodecContext *avctx, |
| 489 | 489 |
AACEncContext *s = avctx->priv_data; |
| 490 | 490 |
int16_t *samples = s->samples, *samples2, *la; |
| 491 | 491 |
ChannelElement *cpe; |
| 492 |
- int i, ch, w, chans, tag, start_ch; |
|
| 492 |
+ int i, ch, w, g, chans, tag, start_ch; |
|
| 493 | 493 |
const uint8_t *chan_map = aac_chan_configs[avctx->channels-1]; |
| 494 | 494 |
int chan_el_counter[4]; |
| 495 | 495 |
FFPsyWindowInfo windows[AAC_MAX_CHANNELS]; |
| ... | ... |
@@ -587,8 +588,16 @@ static int aac_encode_frame(AVCodecContext *avctx, |
| 587 | 587 |
} |
| 588 | 588 |
} |
| 589 | 589 |
s->cur_channel = start_ch; |
| 590 |
- if (cpe->common_window && s->coder->search_for_ms) |
|
| 591 |
- s->coder->search_for_ms(s, cpe, s->lambda); |
|
| 590 |
+ if (s->options.stereo_mode && cpe->common_window) {
|
|
| 591 |
+ if (s->options.stereo_mode > 0) {
|
|
| 592 |
+ IndividualChannelStream *ics = &cpe->ch[0].ics; |
|
| 593 |
+ for (w = 0; w < ics->num_windows; w += ics->group_len[w]) |
|
| 594 |
+ for (g = 0; g < ics->num_swb; g++) |
|
| 595 |
+ cpe->ms_mask[w*16+g] = 1; |
|
| 596 |
+ } else if (s->coder->search_for_ms) {
|
|
| 597 |
+ s->coder->search_for_ms(s, cpe, s->lambda); |
|
| 598 |
+ } |
|
| 599 |
+ } |
|
| 592 | 600 |
adjust_frame_information(s, cpe, chans); |
| 593 | 601 |
if (chans == 2) {
|
| 594 | 602 |
put_bits(&s->pb, 1, cpe->common_window); |
| ... | ... |
@@ -645,6 +654,22 @@ static av_cold int aac_encode_end(AVCodecContext *avctx) |
| 645 | 645 |
return 0; |
| 646 | 646 |
} |
| 647 | 647 |
|
| 648 |
+#define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM |
|
| 649 |
+static const AVOption aacenc_options[] = {
|
|
| 650 |
+ {"stereo_mode", "Stereo coding method", offsetof(AACEncContext, options.stereo_mode), FF_OPT_TYPE_INT, {.dbl = 0}, -1, 1, AACENC_FLAGS, "stereo_mode"},
|
|
| 651 |
+ {"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
|
|
| 652 |
+ {"ms_off", "Disable Mid/Side coding", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
|
|
| 653 |
+ {"ms_force", "Force Mid/Side for the whole frame if possible", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
|
|
| 654 |
+ {NULL}
|
|
| 655 |
+}; |
|
| 656 |
+ |
|
| 657 |
+static const AVClass aacenc_class = {
|
|
| 658 |
+ "AAC encoder", |
|
| 659 |
+ av_default_item_name, |
|
| 660 |
+ aacenc_options, |
|
| 661 |
+ LIBAVUTIL_VERSION_INT, |
|
| 662 |
+}; |
|
| 663 |
+ |
|
| 648 | 664 |
AVCodec ff_aac_encoder = {
|
| 649 | 665 |
"aac", |
| 650 | 666 |
AVMEDIA_TYPE_AUDIO, |
| ... | ... |
@@ -656,4 +681,5 @@ AVCodec ff_aac_encoder = {
|
| 656 | 656 |
.capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, |
| 657 | 657 |
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
|
| 658 | 658 |
.long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"),
|
| 659 |
+ .priv_class = &aacenc_class, |
|
| 659 | 660 |
}; |
| ... | ... |
@@ -30,6 +30,10 @@ |
| 30 | 30 |
|
| 31 | 31 |
#include "psymodel.h" |
| 32 | 32 |
|
| 33 |
+typedef struct AACEncOptions {
|
|
| 34 |
+ int stereo_mode; |
|
| 35 |
+} AACEncOptions; |
|
| 36 |
+ |
|
| 33 | 37 |
struct AACEncContext; |
| 34 | 38 |
|
| 35 | 39 |
typedef struct AACCoefficientsEncoder {
|
| ... | ... |
@@ -48,6 +52,8 @@ extern AACCoefficientsEncoder ff_aac_coders[]; |
| 48 | 48 |
* AAC encoder context |
| 49 | 49 |
*/ |
| 50 | 50 |
typedef struct AACEncContext {
|
| 51 |
+ AVClass *av_class; |
|
| 52 |
+ AACEncOptions options; ///< encoding options |
|
| 51 | 53 |
PutBitContext pb; |
| 52 | 54 |
FFTContext mdct1024; ///< long (1024 samples) frame transform context |
| 53 | 55 |
FFTContext mdct128; ///< short (128 samples) frame transform context |