Changeset 1088
- Timestamp:
- 07/01/09 23:40:26 (8 months ago)
- Files:
-
- trunk/MatroskaCodecIDs.cpp (modified) (4 diffs)
- trunk/MatroskaImportPrivate.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/MatroskaCodecIDs.cpp
r1083 r1088 365 365 {"A_AAC/MPEG2/MAIN", 1}, 366 366 {"A_AAC/MPEG2/LC", 2}, 367 {"A_AAC/MPEG2/LC/SBR", 5},367 {"A_AAC/MPEG2/LC/SBR", 2}, 368 368 {"A_AAC/MPEG2/SSR", 3}, 369 369 {"A_AAC/MPEG4/MAIN", 1}, 370 370 {"A_AAC/MPEG4/LC", 2}, 371 {"A_AAC/MPEG4/LC/SBR", 5},371 {"A_AAC/MPEG4/LC/SBR", 2}, 372 372 {"A_AAC/MPEG4/SSR", 3}, 373 373 {"A_AAC/MPEG4/LTP", 4} … … 379 379 }; 380 380 381 static int FindAACFreqIndex(double freq) 382 { 383 unsigned ifreq = freq; 384 385 for (int i = 0; i < sizeof(kAACFrequencyIndexes)/sizeof(unsigned); i++) { 386 if (kAACFrequencyIndexes[i] == ifreq) return i; 387 } 388 389 return 15; 390 } 391 381 392 static void RecreateAACVOS(KaxTrackEntry *tr_entry, uint8_t *vosBuf, size_t *vosLen) 382 393 { 383 unsigned char profile = 2, freq_index = 15;384 394 KaxCodecID *tr_codec = FindChild<KaxCodecID>(*tr_entry); 385 395 KaxTrackAudio & audioTrack = GetChild<KaxTrackAudio>(*tr_entry); 386 396 KaxAudioSamplingFreq & sampleFreq = GetChild<KaxAudioSamplingFreq>(audioTrack); 387 397 KaxAudioChannels & numChannels = GetChild<KaxAudioChannels>(audioTrack); 388 unsigned freq = unsigned((double)sampleFreq), channels = unsigned(numChannels); 389 398 KaxAudioOutputSamplingFreq * outputFreq = FindChild<KaxAudioOutputSamplingFreq>(audioTrack); 399 unsigned channels = unsigned(numChannels); 400 unsigned profile = 2, freq_index = FindAACFreqIndex(sampleFreq); 401 uint8_t *vosStart = vosBuf; 390 402 string codecString(*tr_codec); 391 403 … … 395 407 } 396 408 397 for (int i = 0; i < sizeof(kAACFrequencyIndexes)/sizeof(unsigned); i++) { 398 if (kAACFrequencyIndexes[i] == freq) {freq_index = i; break;} 399 } 400 401 if (profile == 5) 402 profile = 2; // disable SBR 403 404 if (freq_index != 15) { 405 *vosBuf++ = (profile << 3) | (freq_index >> 1); 406 *vosBuf++ = (freq_index << 7) | (channels << 3); 407 *vosLen = 2; 408 } else { 409 *vosBuf++ = (profile << 3) | (freq_index >> 1); 410 *vosBuf++ = (freq_index << 7) | (freq >> (24 - 7)); 411 *vosBuf++ = (freq >> (24 - 7 - 8)); 412 *vosBuf++ = (freq >> (24 - 7 - 16)); 413 *vosBuf++ = ((freq & 1) << 7) | (channels << 3); 414 *vosLen = 5; 415 } 416 417 //FIXME for when SBR is supported: 418 //write the extension data here 419 //(see libavformat matroskadec.c) 409 *vosBuf++ = (profile << 3) | (freq_index >> 1); 410 *vosBuf++ = (freq_index << 7) | (channels << 3); 411 412 if (freq_index == 15) 413 Codecprintf(NULL, "unrecognized AAC frequency not supported\n"); 414 415 if (outputFreq) { 416 unsigned output_freq_index = FindAACFreqIndex(*outputFreq); 417 418 //SBR extension 419 //not sure why we still use object type 2 (LC) instead of 5 (HE) 420 *vosBuf++ = 0x56; 421 *vosBuf++ = 0xE5; 422 *vosBuf++ = 0x80 | (output_freq_index << 3); 423 } 424 425 *vosLen = vosBuf - vosStart; 420 426 } 421 427 … … 520 526 size_t esdsLen; 521 527 522 // QT doesn't like most SBR setup data (5 bytes) so pretend it's LC 523 if (audio && (!vosBuf || vosLen > 2)) { 528 if (audio && !vosBuf) { 524 529 RecreateAACVOS(tr_entry, aacBuf, &vosLen); 525 530 vosBuf = aacBuf; 526 531 } else if (!audio && !vosBuf) 527 532 return NULL; 528 533 529 534 uint8_t *esds = CreateEsdsFromSetupData(vosBuf, vosLen, &esdsLen, trackID, audio, !audio); 530 535 trunk/MatroskaImportPrivate.cpp
r1021 r1088 517 517 asbd.mSampleRate = Float64(sampleFreq); 518 518 asbd.mChannelsPerFrame = uint32(numChannels); 519 asbd.mFramesPerPacket = 1; // needed for mp3 and v1 SoundDescription, maybe others520 519 521 520 MkvFinishAudioDescriptions(&kaxTrack, &asbd, &acl); … … 525 524 if(asbd.mChannelsPerFrame == 0) 526 525 asbd.mChannelsPerFrame = 1; // avoid a div by zero 526 if(asbd.mFramesPerPacket == 0) 527 asbd.mFramesPerPacket = 1; //in case of PCM or broken codecs 528 //note: this is completely wrong, but less so than 0 529 527 530 528 531 // FIXME mChannelLayoutTag == 0 is valid
