Changeset 156

Show
Ignore:
Timestamp:
10/13/06 19:00:51 (2 years ago)
Author:
dconrad
Message:

Move Matroska Codec ID -> FourCC routine to MatroskaCodecIDs.cpp
Movie ISO 639-2 to QT lang conversion to new file
Add ISO 639-1 entries

Files:

Legend:

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

    r141 r156  
    2727#include <matroska/KaxTracks.h> 
    2828#include <matroska/KaxTrackEntryData.h> 
     29#include <matroska/KaxContentEncoding.h> 
    2930#include "MatroskaCodecIDs.h" 
     31#include "CommonUtils.h" 
    3032#include <string> 
     33 
    3134using namespace std; 
    3235using namespace libmatroska; 
     
    218221                memcpy(*imgDescExt, codecPrivate->GetBuffer(), codecPrivate->GetSize()); 
    219222                 
    220                 AddImageDescriptionExtension(imgDesc, imgDescExt, '.IDX'); 
     223                AddImageDescriptionExtension(imgDesc, imgDescExt, kSampleDescriptionExtensionVobSubIdx); 
    221224                 
    222225                DisposeHandle((Handle) imgDescExt); 
     
    324327} 
    325328 
    326 long GetTrackLanguage(KaxTrackEntry *tr_entry) { 
     329short GetTrackLanguage(KaxTrackEntry *tr_entry) { 
    327330        KaxTrackLanguage *trLang = FindChild<KaxTrackLanguage>(*tr_entry); 
    328331        if (trLang != NULL) { 
    329                 string lang(*trLang); 
    330                 int i; 
    331                  
    332                 for (i = 0; i < sizeof(MkvAndQTLanguagePairs) / sizeof(LanguagePair); i++) { 
    333                         if (lang.compare(MkvAndQTLanguagePairs[i].mkvLang) == 0) 
    334                                 return MkvAndQTLanguagePairs[i].qtLang; 
    335                 } 
     332                char lang[4]; 
     333                string langStr(*trLang); 
     334                strncpy(lang, langStr.c_str(), 3); 
     335                lang[3] = '\0'; 
     336                 
     337                return ThreeCharLangCodeToQTLangCode(lang); 
    336338        } 
    337339        return langUnspecified; 
    338340} 
     341 
     342 
     343 
     344typedef struct { 
     345        OSType cType; 
     346        char *mkvID; 
     347} MatroskaQT_Codec; 
     348 
     349// the first matching pair is used for conversion 
     350static const MatroskaQT_Codec kMatroskaCodecIDs[] = { 
     351        { kRawCodecType, "V_UNCOMPRESSED" }, 
     352        { kMPEG4VisualCodecType, "V_MPEG4/ISO/ASP" }, 
     353        { kMPEG4VisualCodecType, "V_MPEG4/ISO/SP" }, 
     354        { kMPEG4VisualCodecType, "V_MPEG4/ISO/AP" }, 
     355        { kH264CodecType, "V_MPEG4/ISO/AVC" }, 
     356        { kVideoFormatMSMPEG4v3, "V_MPEG4/MS/V3" }, 
     357        { kMPEG1VisualCodecType, "V_MPEG1" }, 
     358        { kMPEG2VisualCodecType, "V_MPEG2" }, 
     359        { kVideoFormatReal5, "V_REAL/RV10" }, 
     360        { kVideoFormatRealG2, "V_REAL/RV20" }, 
     361        { kVideoFormatReal8, "V_REAL/RV30" }, 
     362        { kVideoFormatReal9, "V_REAL/RV40" }, 
     363        { kVideoFormatXiphTheora, "V_THEORA" }, 
     364         
     365        { kAudioFormatMPEG4AAC, "A_AAC/MPEG4/LC" }, 
     366        { kAudioFormatMPEG4AAC, "A_AAC/MPEG4/MAIN" }, 
     367        { kAudioFormatMPEG4AAC, "A_AAC/MPEG4/LC/SBR" }, 
     368        { kAudioFormatMPEG4AAC, "A_AAC/MPEG4/SSR" }, 
     369        { kAudioFormatMPEG4AAC, "A_AAC/MPEG4/LTP" }, 
     370        { kAudioFormatMPEG4AAC, "A_AAC/MPEG2/LC" }, 
     371        { kAudioFormatMPEG4AAC, "A_AAC/MPEG2/MAIN" }, 
     372        { kAudioFormatMPEG4AAC, "A_AAC/MPEG2/LC/SBR" }, 
     373        { kAudioFormatMPEG4AAC, "A_AAC/MPEG2/SSR" }, 
     374        { kAudioFormatMPEGLayer1, "A_MPEG/L1" }, 
     375        { kAudioFormatMPEGLayer2, "A_MPEG/L2" }, 
     376        { kAudioFormatMPEGLayer3, "A_MPEG/L3" }, 
     377        { kAudioFormatAC3, "A_AC3" }, 
     378        { kAudioFormatAC3MS, "A_AC3" }, 
     379        // anything special for these two? 
     380        { kAudioFormatAC3, "A_AC3/BSID9" }, 
     381        { kAudioFormatAC3, "A_AC3/BSID10" }, 
     382        { kAudioFormatXiphVorbis, "A_VORBIS" }, 
     383        { kAudioFormatXiphFLAC, "A_FLAC" }, 
     384        { kAudioFormatLinearPCM, "A_PCM/INT/LIT" }, 
     385        { kAudioFormatLinearPCM, "A_PCM/INT/BIG" }, 
     386        { kAudioFormatLinearPCM, "A_PCM/FLOAT/IEEE" }, 
     387        { kAudioFormatDTS, "A_DTS" }, 
     388        { kAudioFormatTTA, "A_TTA1" }, 
     389        { kAudioFormatWavepack, "A_WAVPACK4" }, 
     390        { kAudioFormatReal1, "A_REAL/14_4" }, 
     391        { kAudioFormatReal2, "A_REAL/28_8" }, 
     392        { kAudioFormatRealCook, "A_REAL/COOK" }, 
     393        { kAudioFormatRealSipro, "A_REAL/SIPR" }, 
     394        { kAudioFormatRealLossless, "A_REAL/RALF" }, 
     395        { kAudioFormatRealAtrac3, "A_REAL/ATRC" }, 
     396         
     397#if 0 
     398        { kBMPCodecType, "S_IMAGE/BMP" }, 
     399        { kSubFormatSSA, "S_TEXT/SSA" }, 
     400        { kSubFormatASS, "S_TEXT/ASS" }, 
     401        { kSubFormatUSF, "S_TEXT/USF" }, 
     402#endif 
     403        { kSubFormatUTF8, "S_TEXT/UTF8" }, 
     404        { kSubFormatVobSub, "S_VOBSUB" }, 
     405}; 
     406 
     407 
     408FourCharCode GetFourCC(KaxTrackEntry *tr_entry) 
     409{ 
     410        KaxCodecID *tr_codec = FindChild<KaxCodecID>(*tr_entry); 
     411        if (tr_codec == NULL) 
     412                return 0; 
     413         
     414        string codecString(*tr_codec); 
     415         
     416        // how should we handle compressed tracks in general? 
     417        KaxContentEncodings *contentEncs = FindChild<KaxContentEncodings>(*tr_entry); 
     418        if (contentEncs) { 
     419                OSType subtype = 0; 
     420                for (int i = 0; i < sizeof(kMatroskaCodecIDs) / sizeof(MatroskaQT_Codec); i++) { 
     421                        if (codecString == kMatroskaCodecIDs[i].mkvID) 
     422                                subtype = kMatroskaCodecIDs[i].cType; 
     423                } 
     424                else 
     425                        return 'COMP'; 
     426        } 
     427         
     428        if (codecString == MKV_V_MS) { 
     429                // avi compatibility mode, 4cc is in private info 
     430                KaxCodecPrivate *codecPrivate = FindChild<KaxCodecPrivate>(*tr_entry); 
     431                if (codecPrivate == NULL) 
     432                        return 0; 
     433                 
     434                // offset to biCompression in BITMAPINFO 
     435                unsigned char *p = (unsigned char *) codecPrivate->GetBuffer() + 16; 
     436                return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; 
     437                 
     438        } else if (codecString == MKV_V_QT) { 
     439                // QT compatibility mode, private info is the ImageDescription structure, big endian 
     440                KaxCodecPrivate *codecPrivate = FindChild<KaxCodecPrivate>(*tr_entry); 
     441                if (codecPrivate == NULL) 
     442                        return 0; 
     443                 
     444                // starts at the 4CC 
     445                unsigned char *p = (unsigned char *) codecPrivate->GetBuffer(); 
     446                return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; 
     447                 
     448        } else { 
     449                for (int i = 0; i < sizeof(kMatroskaCodecIDs) / sizeof(MatroskaQT_Codec); i++) { 
     450                        if (codecString == kMatroskaCodecIDs[i].mkvID) 
     451                                return kMatroskaCodecIDs[i].cType; 
     452                } 
     453        } 
     454        return 0; 
     455} 
  • trunk/MatroskaCodecIDs.h

    r141 r156  
    6464 
    6565enum { 
    66     kSampleDescriptionExtensionTheora = 'XdxT' 
     66        kSampleDescriptionExtensionTheora = 'XdxT', 
     67        kSampleDescriptionExtensionVobSubIdx = '.IDX', 
    6768}; 
    6869 
     
    103104 
    104105 
    105 typedef struct { 
    106         OSType cType; 
    107         char *mkvID; 
    108 } MatroskaQT_Codec; 
    109  
    110 // the first matching pair is used for conversion 
    111 static const MatroskaQT_Codec kMatroskaCodecIDs[] = { 
    112         { kRawCodecType, "V_UNCOMPRESSED" }, 
    113         { kMPEG4VisualCodecType, "V_MPEG4/ISO/ASP" }, 
    114         { kMPEG4VisualCodecType, "V_MPEG4/ISO/SP" }, 
    115         { kMPEG4VisualCodecType, "V_MPEG4/ISO/AP" }, 
    116         { kH264CodecType, "V_MPEG4/ISO/AVC" }, 
    117         { kVideoFormatMSMPEG4v3, "V_MPEG4/MS/V3" }, 
    118         { kMPEG1VisualCodecType, "V_MPEG1" }, 
    119         { kMPEG2VisualCodecType, "V_MPEG2" }, 
    120         { kVideoFormatReal5, "V_REAL/RV10" }, 
    121         { kVideoFormatRealG2, "V_REAL/RV20" }, 
    122         { kVideoFormatReal8, "V_REAL/RV30" }, 
    123         { kVideoFormatReal9, "V_REAL/RV40" }, 
    124         { kVideoFormatXiphTheora, "V_THEORA" }, 
    125          
    126         { kAudioFormatMPEG4AAC, "A_AAC/MPEG4/LC" }, 
    127         { kAudioFormatMPEG4AAC, "A_AAC/MPEG4/MAIN" }, 
    128         { kAudioFormatMPEG4AAC, "A_AAC/MPEG4/LC/SBR" }, 
    129         { kAudioFormatMPEG4AAC, "A_AAC/MPEG4/SSR" }, 
    130         { kAudioFormatMPEG4AAC, "A_AAC/MPEG4/LTP" }, 
    131         { kAudioFormatMPEG4AAC, "A_AAC/MPEG2/LC" }, 
    132         { kAudioFormatMPEG4AAC, "A_AAC/MPEG2/MAIN" }, 
    133         { kAudioFormatMPEG4AAC, "A_AAC/MPEG2/LC/SBR" }, 
    134         { kAudioFormatMPEG4AAC, "A_AAC/MPEG2/SSR" }, 
    135         { kAudioFormatMPEGLayer1, "A_MPEG/L1" }, 
    136         { kAudioFormatMPEGLayer2, "A_MPEG/L2" }, 
    137         { kAudioFormatMPEGLayer3, "A_MPEG/L3" }, 
    138         { kAudioFormatAC3, "A_AC3" }, 
    139         { kAudioFormatAC3MS, "A_AC3" }, 
    140         // anything special for these two? 
    141         { kAudioFormatAC3, "A_AC3/BSID9" }, 
    142         { kAudioFormatAC3, "A_AC3/BSID10" }, 
    143         { kAudioFormatXiphVorbis, "A_VORBIS" }, 
    144         { kAudioFormatXiphFLAC, "A_FLAC" }, 
    145         { kAudioFormatLinearPCM, "A_PCM/INT/LIT" }, 
    146         { kAudioFormatLinearPCM, "A_PCM/INT/BIG" }, 
    147         { kAudioFormatLinearPCM, "A_PCM/FLOAT/IEEE" }, 
    148         { kAudioFormatDTS, "A_DTS" }, 
    149         { kAudioFormatTTA, "A_TTA1" }, 
    150         { kAudioFormatWavepack, "A_WAVPACK4" }, 
    151         { kAudioFormatReal1, "A_REAL/14_4" }, 
    152         { kAudioFormatReal2, "A_REAL/28_8" }, 
    153         { kAudioFormatRealCook, "A_REAL/COOK" }, 
    154         { kAudioFormatRealSipro, "A_REAL/SIPR" }, 
    155         { kAudioFormatRealLossless, "A_REAL/RALF" }, 
    156         { kAudioFormatRealAtrac3, "A_REAL/ATRC" }, 
    157          
    158 #if 0 
    159         { kBMPCodecType, "S_IMAGE/BMP" }, 
    160         { kSubFormatSSA, "S_TEXT/SSA" }, 
    161         { kSubFormatASS, "S_TEXT/ASS" }, 
    162         { kSubFormatUSF, "S_TEXT/USF" }, 
    163 #endif 
    164         { kSubFormatUTF8, "S_TEXT/UTF8" }, 
    165         { kSubFormatVobSub, "S_VOBSUB" }, 
    166 }; 
    167  
    168106// these CodecIDs need special handling since they correspond to many fourccs 
    169107#define MKV_V_MS "V_MS/VFW/FOURCC" 
     
    194132 
    195133 
    196  
    197134typedef enum { 
    198135        kToKaxTrackEntry, 
     
    215152        { kAudioFormatXiphVorbis, DescExt_XiphVorbis }, 
    216153        { kAudioFormatXiphFLAC, DescExt_XiphFLAC }, 
    217         { kSubFormatVobSub, DescExt_VobSub } 
     154        { kSubFormatVobSub, DescExt_VobSub }, 
    218155}; 
    219156 
    220  
    221  
    222 struct LanguagePair { 
    223         char mkvLang[4];        // (ISO 639-2 3 char code) 
    224         long qtLang; 
    225 }; 
    226  
    227 // don't think there's a function already to do ISO 639-2 -> language code  
    228 // that SetMediaLanguage accepts 
    229 static const struct LanguagePair MkvAndQTLanguagePairs[] = { 
    230         { "afr", langAfrikaans }, 
    231         { "alb", langAlbanian }, 
    232         { "amh", langAmharic }, 
    233         { "ara", langArabic }, 
    234         { "arm", langArmenian }, 
    235         { "asm", langAssamese },  
    236         { "aym", langAymara }, 
    237         { "aze", langAzerbaijani }, 
    238         { "baq", langBasque }, 
    239         { "ben", langBengali }, 
    240         { "bre", langBreton }, 
    241         { "bul", langBulgarian }, 
    242         { "bur", langBurmese }, 
    243         { "cat", langCatalan }, 
    244         { "chi", langTradChinese }, 
    245         { "cze", langCzech }, 
    246         { "dan", langDanish }, 
    247         { "dut", langDutch }, 
    248         { "dzo", langDzongkha }, 
    249         { "eng", langEnglish }, 
    250         { "epo", langEsperanto }, 
    251         { "est", langEstonian }, 
    252         { "fao", langFaroese }, 
    253         { "fin", langFinnish }, 
    254         { "fre", langFrench }, 
    255         { "geo", langGeorgian }, 
    256         { "ger", langGerman }, 
    257         { "gig", langGalician }, 
    258         { "gla", langScottishGaelic }, 
    259         { "gle", langIrishGaelic }, 
    260         { "glv", langManxGaelic }, 
    261         { "grc", langGreekAncient }, 
    262         { "gre", langGreek }, 
    263         { "grn", langGuarani }, 
    264         { "guj", langGujarati }, 
    265         { "heb", langHebrew }, 
    266         { "hin", langHindi }, 
    267         { "hmn", langHungarian }, 
    268         { "ice", langIcelandic }, 
    269         { "ind", langIndonesian }, 
    270         { "ita", langItalian }, 
    271         { "jav", langJavaneseRom }, 
    272         { "jpn", langJapanese }, 
    273         { "kal", langGreenlandic }, 
    274         { "kan", langKannada }, 
    275         { "kas", langKashmiri }, 
    276         { "kaz", langKazakh }, 
    277         { "khm", langKhmer }, 
    278         { "kin", langKinyarwanda }, 
    279         { "kir", langKirghiz }, 
    280         { "kor", langKorean }, 
    281         { "kur", langKurdish }, 
    282         { "lao", langLao }, 
    283         { "lat", langLatin }, 
    284         { "lav", langLatvian }, 
    285         { "lit", langLithuanian }, 
    286         { "mac", langMacedonian }, 
    287         { "mal", langMalayalam }, 
    288         { "mar", langMarathi }, 
    289         { "may", langMalayRoman }, 
    290         { "mlg", langMalagasy }, 
    291         { "mlt", langMaltese }, 
    292         { "mol", langMoldavian }, 
    293         { "mon", langMongolian }, 
    294         { "nep", langNepali }, 
    295         { "nob", langNorwegian },       // Norwegian BokmÃ¥l 
    296         { "nor", langNorwegian }, 
    297         { "nno", langNynorsk }, 
    298         { "nya", langNyanja }, 
    299         { "ori", langOriya }, 
    300         { "orm", langOromo }, 
    301         { "pan", langPunjabi }, 
    302         { "per", langPersian }, 
    303         { "pol", langPolish }, 
    304         { "por", langPortuguese }, 
    305         { "que", langQuechua }, 
    306         { "rum", langRomanian }, 
    307         { "run", langRundi }, 
    308         { "rus", langRussian }, 
    309         { "san", langSanskrit }, 
    310         { "scc", langSerbian }, 
    311         { "scr", langCroatian }, 
    312         { "sin", langSinhalese }, 
    313         { "sit", langTibetan },         // Sino-Tibetan (Other) 
    314         { "slo", langSlovak }, 
    315         { "slv", langSlovenian }, 
    316         { "sme", langSami }, 
    317         { "smi", langSami },            // Sami languages (Other) 
    318         { "snd", langSindhi }, 
    319         { "som", langSomali }, 
    320         { "spa", langSpanish }, 
    321         { "sun", langSundaneseRom }, 
    322         { "swa", langSwahili }, 
    323         { "swe", langSwedish }, 
    324         { "tam", langTamil }, 
    325         { "tat", langTatar }, 
    326         { "tel", langTelugu }, 
    327         { "tgk", langTajiki }, 
    328         { "tgl", langTagalog }, 
    329         { "tha", langThai }, 
    330         { "tib", langTibetan }, 
    331         { "tir", langTigrinya }, 
    332         { "tog", langTongan },          // Tonga (Nyasa) 
    333         { "tog", langTongan },          // Tonga (Tonga Islands) 
    334         { "tur", langTurkish }, 
    335         { "tuk", langTurkmen }, 
    336         { "uig", langUighur }, 
    337         { "ukr", langUkrainian }, 
    338         { "und", langUnspecified }, 
    339         { "urd", langUrdu }, 
    340         { "uzb", langUzbek }, 
    341         { "vie", langVietnamese }, 
    342         { "wel", langWelsh }, 
    343         { "yid", langYiddish } 
    344 }; 
    345  
    346 long GetTrackLanguage(KaxTrackEntry *tr_entry); 
     157short GetTrackLanguage(KaxTrackEntry *tr_entry); 
     158FourCharCode GetFourCC(KaxTrackEntry *tr_entry); 
    347159 
    348160#endif 
  • trunk/MkvMovieSetup.cpp

    r150 r156  
    5858ComponentResult MkvCreateSubtitleTrack(MkvTrackPtr mkvTrack, KaxTrackEntry *tracks,  
    5959                                                                           Movie theMovie, Handle dataRef, OSType dataRefType); 
    60 FourCharCode GetFourCC(KaxTrackEntry *tr_entry); 
    6160int GetAACProfile(KaxTrackEntry *tr_entry); 
    6261UInt32 GetDefaultChannelLayout(AudioStreamBasicDescription &asbd); 
     
    613612} 
    614613 
    615 FourCharCode GetFourCC(KaxTrackEntry *tr_entry) 
    616 { 
    617         KaxCodecID *tr_codec = FindChild<KaxCodecID>(*tr_entry); 
    618         if (tr_codec == NULL) 
    619                 return 0; 
    620          
    621         // how should we handle compressed tracks? 
    622         KaxContentEncodings *contentEncs = FindChild<KaxContentEncodings>(*tr_entry); 
    623         if (contentEncs) { 
    624                 return 'COMP'; 
    625         } 
    626          
    627         string codecString(*tr_codec); 
    628          
    629         if (codecString == MKV_V_MS) { 
    630                 // avi compatibility mode, 4cc is in private info 
    631                 KaxCodecPrivate *codecPrivate = FindChild<KaxCodecPrivate>(*tr_entry); 
    632                 if (codecPrivate == NULL) 
    633                         return 0; 
    634                  
    635                 // offset to biCompression in BITMAPINFO 
    636                 unsigned char *p = (unsigned char *) codecPrivate->GetBuffer() + 16; 
    637                 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; 
    638                  
    639         } else if (codecString == MKV_V_QT) { 
    640                 // QT compatibility mode, private info is the ImageDescription structure, big endian 
    641                 KaxCodecPrivate *codecPrivate = FindChild<KaxCodecPrivate>(*tr_entry); 
    642                 if (codecPrivate == NULL) 
    643                         return 0; 
    644                  
    645                 // starts at the 4CC 
    646                 unsigned char *p = (unsigned char *) codecPrivate->GetBuffer(); 
    647                 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; 
    648                  
    649         } else { 
    650                 for (int i = 0; i < sizeof(kMatroskaCodecIDs) / sizeof(MatroskaQT_Codec); i++) { 
    651                         if (codecString == kMatroskaCodecIDs[i].mkvID) 
    652                                 return kMatroskaCodecIDs[i].cType; 
    653                 } 
    654         } 
    655         return 0; 
    656 } 
    657  
    658614int GetAACProfile(KaxTrackEntry *tr_entry) { 
    659615        KaxCodecID *tr_codec = FindChild<KaxCodecID>(*tr_entry);