diff --git a/src/common/aac_common.cpp b/src/common/aac_common.cpp index c39d2a261..76b20d720 100644 --- a/src/common/aac_common.cpp +++ b/src/common/aac_common.cpp @@ -222,7 +222,7 @@ parse_aac_data(unsigned char *data, if (size == 5) { output_sample_rate = aac_sampling_freq[(data[4] & 0x7f) >> 3]; sbr = true; - } else if (sample_rate < 44100) { + } else if (sample_rate <= 24000) { output_sample_rate = 2 * sample_rate; sbr = true; } else diff --git a/src/common/matroska.h b/src/common/matroska.h index cd1fd3430..3535457a0 100644 --- a/src/common/matroska.h +++ b/src/common/matroska.h @@ -27,6 +27,7 @@ #define MKV_A_AAC_4SSR "A_AAC/MPEG4/SSR" #define MKV_A_AAC_4LTP "A_AAC/MPEG4/LTP" #define MKV_A_AAC_4SBR "A_AAC/MPEG4/LC/SBR" +#define MKV_A_AAC "A_AAC" #define MKV_A_AC3 "A_AC3" #define MKV_A_DTS "A_DTS" #define MKV_A_MP3 "A_MPEG/L3" diff --git a/src/input/r_matroska.cpp b/src/input/r_matroska.cpp index 272f576a6..6edbf36ac 100644 --- a/src/input/r_matroska.cpp +++ b/src/input/r_matroska.cpp @@ -443,8 +443,7 @@ kax_reader_c::verify_tracks() { c = (unsigned char *)t->private_data; if (c[0] != 2) { if (verbose) - mxwarn(PFX "Vorbis track does not " - "contain valid headers.\n"); + mxwarn(PFX "Vorbis track does not contain valid headers.\n"); continue; } @@ -458,8 +457,7 @@ kax_reader_c::verify_tracks() { } if (offset >= (t->private_size - 1)) { if (verbose) - mxwarn(PFX "Vorbis track does not " - "contain valid headers.\n"); + mxwarn(PFX "Vorbis track does not contain valid headers.\n"); continue; } length += c[offset]; @@ -497,8 +495,15 @@ kax_reader_c::verify_tracks() { (t->codec_id == MKV_A_AAC_2SBR) || (t->codec_id == MKV_A_AAC_4SBR)) t->a_formattag = FOURCC('M', 'P', '4', 'A'); - else if (starts_with(t->codec_id, MKV_A_REAL_COOK, - strlen("A_REAL/"))) + else if (t->codec_id == MKV_A_AAC) { + if ((t->private_data == NULL) || (t->private_size < 2)) { + mxwarn(PFX "The AAC track number %u is missing its private " + "data. Ignoring this track.\n", t->tnum); + continue; + } + t->a_formattag = FOURCC('M', 'P', '4', 'A'); + } else if (starts_with(t->codec_id, MKV_A_REAL_COOK, + strlen("A_REAL/"))) t->a_formattag = FOURCC('r', 'e', 'a', 'l'); else if (t->codec_id == MKV_A_FLAC) { #if defined(HAVE_FLAC_FORMAT_H) @@ -1651,7 +1656,19 @@ kax_reader_c::create_packetizer(int64_t tid) { id = 0; profile = 0; if (t->a_formattag == FOURCC('M', 'P', '4', 'A')) { - if (!parse_aac_codec_id(string(t->codec_id), id, profile)) + int channels, sfreq, osfreq; + bool sbr; + + if (t->codec_id == MKV_A_AAC) { + id = AAC_ID_MPEG4; + if (!parse_aac_data((unsigned char *)t->private_data, + t->private_size, profile, channels, sfreq, + osfreq, sbr)) + mxerror(FMT_TID "Malformed AAC codec initialization data " + "found.\n", ti->fname.c_str(), (int64_t)t->tnum); + if (sbr) + profile = AAC_PROFILE_SBR; + } else if (!parse_aac_codec_id(string(t->codec_id), id, profile)) mxerror(FMT_TID "Malformed codec id '%s'.\n", ti->fname.c_str(), (int64_t)t->tnum, t->codec_id.c_str()); } else { diff --git a/src/input/r_qtmp4.cpp b/src/input/r_qtmp4.cpp index aad9c122a..7820cff97 100644 --- a/src/input/r_qtmp4.cpp +++ b/src/input/r_qtmp4.cpp @@ -1208,8 +1208,7 @@ qtmp4_reader_c::create_packetizer(int64_t tid) { int profile, sample_rate, channels, output_sample_rate; bool sbraac; - if ((dmx->esds.decoder_config_len == 2) || - (dmx->esds.decoder_config_len == 5)) { + if (dmx->esds.decoder_config_len >= 2) { parse_aac_data(dmx->esds.decoder_config, dmx->esds.decoder_config_len, profile, channels, sample_rate, output_sample_rate, sbraac); @@ -1218,6 +1217,8 @@ qtmp4_reader_c::create_packetizer(int64_t tid) { channels, output_sample_rate, (int)sbraac); if (sbraac) profile = AAC_PROFILE_SBR; + ti->private_data = dmx->esds.decoder_config; + ti->private_size = dmx->esds.decoder_config_len; dmx->ptzr = add_packetizer(new aac_packetizer_c(this, AAC_ID_MPEG4, profile, sample_rate, channels, ti, @@ -1227,6 +1228,8 @@ qtmp4_reader_c::create_packetizer(int64_t tid) { set_audio_output_sampling_freq(output_sample_rate); mxinfo(FMT_TID "Using the AAC output module.\n", ti->fname.c_str(), (int64_t)dmx->id); + ti->private_data = NULL; + ti->private_size = 0; } else mxerror(FMT_TID "AAC found, but decoder config data has length %u." diff --git a/src/output/p_aac.cpp b/src/output/p_aac.cpp index d11528329..9219c6a43 100644 --- a/src/output/p_aac.cpp +++ b/src/output/p_aac.cpp @@ -126,7 +126,10 @@ aac_packetizer_c::get_aac_packet(unsigned long *header, void aac_packetizer_c::set_headers() { - if (id == AAC_ID_MPEG4) { + if ((ti->private_size > 0) && (ti->private_size != 2) && + (ti->private_size != 5)) + set_codec_id(MKV_A_AAC); + else if (id == AAC_ID_MPEG4) { if (profile == AAC_PROFILE_MAIN) set_codec_id(MKV_A_AAC_4MAIN); else if (profile == AAC_PROFILE_LC) @@ -154,6 +157,9 @@ aac_packetizer_c::set_headers() { set_audio_sampling_freq((float)samples_per_sec); set_audio_channels(channels); + if ((ti->private_data != NULL) && (ti->private_size > 0)) + set_codec_private(ti->private_data, ti->private_size); + generic_packetizer_c::set_headers(); }