From faa40944bf787e07ef668a2dab5066369c43ca65 Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 24 Sep 2015 00:19:04 +0200 Subject: [PATCH] changed handling of SBR/PS AAC extension --- matroska/matroskatrack.cpp | 5 +++-- mediaformat.cpp | 31 +++++++++++++++++++++++++++---- mediaformat.h | 3 +-- mp4/mp4ids.cpp | 8 +++++++- mp4/mp4track.cpp | 15 +++------------ 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/matroska/matroskatrack.cpp b/matroska/matroskatrack.cpp index 8c69ebc..a945594 100644 --- a/matroska/matroskatrack.cpp +++ b/matroska/matroskatrack.cpp @@ -138,7 +138,7 @@ MediaFormat MatroskaTrack::codecIdToMediaFormat(const string &codecId) } else if(part3 == "LC") { fmt.sub = SubFormats::AacMpeg2LowComplexityProfile; } else if(part3 == "SBR") { - fmt.sub = SubFormats::AacMpeg2SpectralBandReplicationProfile; + fmt.sub = SubFormats::AacMpeg2LowComplexityProfile; fmt.extension = ExtensionFormats::SpectralBandReplication; } else if(part3 == "SSR") { fmt.sub = SubFormats::AacMpeg2ScalableSamplingRateProfile; @@ -149,7 +149,8 @@ MediaFormat MatroskaTrack::codecIdToMediaFormat(const string &codecId) } else if(part3 == "LC") { fmt.sub = SubFormats::AacMpeg4LowComplexityProfile; } else if(part3 == "SBR") { - fmt.sub = SubFormats::AacMpeg4SpectralBandReplicationProfile; + fmt.sub = SubFormats::AacMpeg4LowComplexityProfile; + fmt.extension = ExtensionFormats::SpectralBandReplication; } else if(part3 == "SSR") { fmt.sub = SubFormats::AacMpeg4ScalableSamplingRateProfile; } else if(part3 == "LTP") { diff --git a/mediaformat.cpp b/mediaformat.cpp index accdc73..970a6c7 100644 --- a/mediaformat.cpp +++ b/mediaformat.cpp @@ -21,11 +21,9 @@ const char *MediaFormat::name() const switch(sub) { case AacMpeg2MainProfile: return "Advanced Audio Coding Main Profile"; case AacMpeg2LowComplexityProfile: return "Advanced Audio Coding Low Complexity Profile"; - case AacMpeg2SpectralBandReplicationProfile: return "Advanced Audio Coding Low Complexity with Spectral Band Replication Profile"; case AacMpeg2ScalableSamplingRateProfile: return "Advanced Audio Coding Scalable Sampling Rate Profile"; case AacMpeg4MainProfile: return "Advanced Audio Coding Main Profile"; case AacMpeg4LowComplexityProfile: return "Advanced Audio Coding Low Complexity Profile"; - case AacMpeg4SpectralBandReplicationProfile: return "Advanced Audio Coding Low Complexity with Spectral Band Replication Profile"; case AacMpeg4ScalableSamplingRateProfile: return "Advanced Audio Coding Scaleable Sampling Rate Profile"; case AacMpeg4LongTermPrediction: return "Advanced Audio Coding Long Term Predicition"; case AacMpeg4ERLowComplecityProfile: return "Advanced Audio Coding Error Resilient Low Complexity Profile"; @@ -238,11 +236,9 @@ const char *MediaFormat::abbreviation() const switch(sub) { case AacMpeg2MainProfile: return "MPEG-2 AAC Main"; case AacMpeg2LowComplexityProfile: return "MPEG-2 AAC-LC"; - case AacMpeg2SpectralBandReplicationProfile: return "MPEG-2-SBR"; case AacMpeg2ScalableSamplingRateProfile: return "MPEG-2 AAC-SSR"; case AacMpeg4MainProfile: return "MPEG-4 AAC Main"; case AacMpeg4LowComplexityProfile: return "MPEG-4 AAC-LC"; - case AacMpeg4SpectralBandReplicationProfile: return "MPEG-4 HE-AAC"; case AacMpeg4ScalableSamplingRateProfile: return "MPEG-4 AAC-SSR"; case AacMpeg4LongTermPrediction: return "MPEG-4 AAC-LTP"; case AacMpeg4ERLowComplecityProfile: return "MPEG-4 ER AAC-LC"; @@ -387,4 +383,31 @@ const char *MediaFormat::abbreviation() const } } +/*! + * \brief Returns the abbreviation of the media format as C-style string. + * + * Returns an empty string if no abbreviation is available. + */ +const char *MediaFormat::extensionName() const +{ + switch(general) { + using namespace ExtensionFormats; + case GeneralMediaFormat::Aac: + switch(extension) { + case SpectralBandReplication: + return "Spectral Band Replication / HE-AAC"; + case ParametricStereo: + return "Parametric Stereo / HE-AAC v2"; // PS never comes alone? + case (SpectralBandReplication | ParametricStereo): + return "Spectral Band Replication and Parametric Stereo / HE-AAC v2"; + default: + ; + } + break; + default: + ; + } + return ""; +} + } diff --git a/mediaformat.h b/mediaformat.h index 2ed6043..64bf337 100644 --- a/mediaformat.h +++ b/mediaformat.h @@ -108,11 +108,9 @@ enum Mpeg1AudioLayer : unsigned char { enum AacProfile : unsigned char { AacMpeg2MainProfile = 1, AacMpeg2LowComplexityProfile, - AacMpeg2SpectralBandReplicationProfile, AacMpeg2ScalableSamplingRateProfile, AacMpeg4MainProfile, AacMpeg4LowComplexityProfile, - AacMpeg4SpectralBandReplicationProfile, AacMpeg4ScalableSamplingRateProfile, AacMpeg4LongTermPrediction, AacMpeg4ERLowComplecityProfile, @@ -248,6 +246,7 @@ public: const char *name() const; const char *abbreviation() const; + const char *extensionName() const; operator bool() const; MediaFormat &operator+=(const MediaFormat &other); diff --git a/mp4/mp4ids.cpp b/mp4/mp4ids.cpp index b490eaa..26bd6b0 100644 --- a/mp4/mp4ids.cpp +++ b/mp4/mp4ids.cpp @@ -236,7 +236,7 @@ LIB_EXPORT MediaFormat idToMediaFormat(byte mpeg4AudioObjectId, bool sbrPresent, fmt = MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4MainProfile); break; case AacLc: - fmt = MediaFormat(GeneralMediaFormat::Aac, sbrPresent ? SubFormats::AacMpeg4SpectralBandReplicationProfile : SubFormats::AacMpeg4LowComplexityProfile); + fmt = MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4LowComplexityProfile); break; case AacSsr: fmt = MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4ScalableSamplingRateProfile); @@ -244,6 +244,9 @@ LIB_EXPORT MediaFormat idToMediaFormat(byte mpeg4AudioObjectId, bool sbrPresent, case AacLtp: fmt = MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4LongTermPrediction); break; + case Sbr: + fmt = MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4LowComplexityProfile, ExtensionFormats::SpectralBandReplication); + break; case AacScalable: fmt = MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4ScalableSamplingRateProfile); break; @@ -256,6 +259,9 @@ LIB_EXPORT MediaFormat idToMediaFormat(byte mpeg4AudioObjectId, bool sbrPresent, case ErAacLd: fmt = MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4ERLowDelay); break; + case Ps: + fmt = MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4LowComplexityProfile, ExtensionFormats::ParametricStereo); + break; case Layer1: fmt = MediaFormat(GeneralMediaFormat::Mpeg1Audio, SubFormats::Mpeg1Layer1); break; diff --git a/mp4/mp4track.cpp b/mp4/mp4track.cpp index 63b5524..1b491f1 100644 --- a/mp4/mp4track.cpp +++ b/mp4/mp4track.cpp @@ -26,15 +26,6 @@ namespace Media { DateTime startDate = DateTime::fromDate(1904, 1, 1); -MediaFormat fmtTable[] = { - GeneralMediaFormat::Unknown, - MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4MainProfile), - MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4LowComplexityProfile), - MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4ScalableSamplingRateProfile), - MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4LongTermPrediction), - MediaFormat(GeneralMediaFormat::Aac, SubFormats::AacMpeg4SpectralBandReplicationProfile) -}; - Mpeg4AudioSpecificConfig::Mpeg4AudioSpecificConfig() : audioObjectType(0), sampleFrequencyIndex(0xF), @@ -610,7 +601,7 @@ unique_ptr Mp4Track::parseAudioSpecificConfig(StatusPr switch(audioCfg->audioObjectType) { case Sbr: case Ps: - audioCfg->extensionAudioObjectType = Sbr; + audioCfg->extensionAudioObjectType = audioCfg->audioObjectType; audioCfg->sbrPresent = true; if((audioCfg->extensionSampleFrequencyIndex = bitReader.readBits(4)) == 0xF) { audioCfg->extensionSampleFrequency = bitReader.readBits(24); @@ -620,7 +611,7 @@ unique_ptr Mp4Track::parseAudioSpecificConfig(StatusPr } break; } - switch(audioCfg->audioObjectType) { + switch(audioCfg->extensionAudioObjectType) { case Ps: audioCfg->psPresent = true; break; @@ -681,7 +672,7 @@ unique_ptr Mp4Track::parseAudioSpecificConfig(StatusPr } break; } - if(audioCfg->extensionAudioObjectType != 5 && bitReader.bitsAvailable() >= 16) { + if(audioCfg->extensionAudioObjectType != Sbr && audioCfg->extensionAudioObjectType != Ps && bitReader.bitsAvailable() >= 16) { uint16 syncExtensionType = bitReader.readBits(11); if(syncExtensionType == 0x2B7) { if((audioCfg->extensionAudioObjectType = getAudioObjectType()) == Sbr) {