Changeset 811

Show
Ignore:
Timestamp:
02/18/08 18:37:08 (7 months ago)
Author:
astrange
Message:

Properly generate the VOS for AAC in Matroska files without one.
Untested in the case of custom frequencies.
(This should probably be backported to 1.1)

Fix Development build.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/MatroskaCodecIDs.cpp

    r806 r811  
    2727#include <matroska/KaxTracks.h> 
    2828#include <matroska/KaxTrackEntryData.h> 
     29#include <matroska/KaxTrackAudio.h> 
    2930#include "MatroskaCodecIDs.h" 
    3031#include "CommonUtils.h" 
     
    341342        } 
    342343        return noErr; 
     344} 
     345 
     346// c.f. http://wiki.multimedia.cx/index.php?title=Understanding_AAC 
     347 
     348struct MatroskaQT_AACProfileName 
     349{ 
     350        char *name; 
     351        char profile; 
     352}; 
     353 
     354static const MatroskaQT_AACProfileName kMatroskaAACProfiles[] = { 
     355        {"A_AAC/MPEG2/MAIN", 1}, 
     356        {"A_AAC/MPEG2/LC", 2}, 
     357        {"A_AAC/MPEG2/LC/SBR", 5}, 
     358        {"A_AAC/MPEG2/SSR", 3}, 
     359        {"A_AAC/MPEG4/MAIN", 1}, 
     360        {"A_AAC/MPEG4/LC", 2}, 
     361        {"A_AAC/MPEG4/LC/SBR", 5}, 
     362        {"A_AAC/MPEG4/SSR", 3}, 
     363        {"A_AAC/MPEG4/LTP", 4} 
     364}; 
     365 
     366static const unsigned kAACFrequencyIndexes[] = { 
     367        96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 
     368        11025, 8000, 7350 
     369}; 
     370 
     371static void RecreateAACVOS(KaxTrackEntry *tr_entry, uint8_t *vosBuf, size_t *vosLen) 
     372{ 
     373        unsigned char profile = 0, freq_index = 15; 
     374        KaxCodecID *tr_codec = FindChild<KaxCodecID>(*tr_entry); 
     375        KaxTrackAudio & audioTrack = GetChild<KaxTrackAudio>(*tr_entry); 
     376        KaxAudioSamplingFreq & sampleFreq = GetChild<KaxAudioSamplingFreq>(audioTrack); 
     377        KaxAudioChannels & numChannels = GetChild<KaxAudioChannels>(audioTrack); 
     378        unsigned freq = unsigned((double)sampleFreq), channels = unsigned(numChannels); 
     379 
     380        string codecString(*tr_codec); 
     381 
     382        for (int i = 0; i < sizeof(kMatroskaAACProfiles)/sizeof(MatroskaQT_AACProfileName); i++) { 
     383                const MatroskaQT_AACProfileName *prof = &kMatroskaAACProfiles[i]; 
     384                if (strcmp(codecString.c_str(), prof->name) == 0) {profile = prof->profile; break;} 
     385        } 
     386         
     387        for (int i = 0; i < sizeof(kAACFrequencyIndexes)/sizeof(unsigned); i++) { 
     388                if (kAACFrequencyIndexes[i] == freq) {freq_index = i; break;} 
     389        } 
     390         
     391        if (freq_index != 15) { 
     392                *vosBuf++ = (profile << 3) | (freq_index >> 1); 
     393                *vosBuf++ = (freq_index << 7) | (channels << 3); 
     394                *vosLen = 2; 
     395        } else { 
     396                freq = EndianU32_NtoB(freq); 
     397                 
     398                *vosBuf++ = (profile << 3) | (freq_index >> 1); 
     399                *vosBuf++ = (freq_index << 7) | (freq >> (24 - 7)); 
     400                *vosBuf++ = (freq >> (24 - 7 - 8)) & 0xff; 
     401                *vosBuf++ = (freq >> (24 - 7 - 16)) & 0xff; 
     402                *vosBuf++ = ((freq & 1) << 7) | (channels << 3); 
     403                *vosLen = 5; 
     404        } 
    343405} 
    344406 
     
    427489} 
    428490 
    429 static const unsigned char aac_lc_vos[] = {0x11, 0x90}; 
    430  
    431491static Handle CreateEsdsExt(KaxTrackEntry *tr_entry, bool audio) 
    432492{ 
     
    434494        KaxTrackNumber *trackNum = FindChild<KaxTrackNumber>(*tr_entry); 
    435495         
    436         int vosLen = codecPrivate ? codecPrivate->GetSize() : 0; 
     496        size_t vosLen = codecPrivate ? codecPrivate->GetSize() : 0; 
    437497        int trackID = trackNum ? uint16(*trackNum) : 1; 
    438     uint8_t *vosBuf = codecPrivate ? codecPrivate->GetBuffer() : NULL; 
     498        uint8_t aacBuf[5] = {0}; 
     499        uint8_t *vosBuf = codecPrivate ? codecPrivate->GetBuffer() : NULL; 
    439500        size_t esdsLen; 
    440501         
    441         if (!vosBuf) { // minimal AAC-LC descriptor 
    442                 vosBuf = (uint8_t*)aac_lc_vos
    443                 vosLen = 2
     502        if (audio && !vosBuf) { 
     503                RecreateAACVOS(tr_entry, aacBuf, &vosLen)
     504                vosBuf = aacBuf
    444505        } 
    445506 
  • trunk/Perian.xcodeproj/project.pbxproj

    r806 r811  
    18561856                        buildSettings = { 
    18571857                                COPY_PHASE_STRIP = NO; 
    1858                                 DEAD_CODE_STRIPPING = NO
     1858                                DEAD_CODE_STRIPPING = YES
    18591859                                EXPORTED_SYMBOLS_FILE = "$(SOURCE_ROOT)/exportedSymbols"; 
    18601860                                GCC_DYNAMIC_NO_PIC = NO; 
     
    18911891                                OTHER_REZFLAGS = "-rd -d ppc_$(ppc) -d i386_$(i386) -d TARGET_REZ_CARBON_MACHO=1"; 
    18921892                                PREBINDING = NO; 
    1893                                 PRESERVE_DEAD_CODE_INITS_AND_TERMS = NO; 
    18941893                                PRODUCT_NAME = Perian; 
    18951894                                REZ_PREPROCESSOR_DEFINITIONS = "";