diff --git a/MP42/MP42AC3Importer.m b/MP42/MP42AC3Importer.m index b62f1ae..c83b716 100644 --- a/MP42/MP42AC3Importer.m +++ b/MP42/MP42AC3Importer.m @@ -278,8 +278,8 @@ static bool GetFirstHeader(FILE* inFile) // collect all the necessary meta information UInt32 channels = 0, channelLayoutTag = 0; - uint32_t fscod, frmsizecod, bsid, bsmod, acmod, lfeon; - uint32_t lfe_offset = 4; + uint64_t fscod, frmsizecod, bsid, bsmod, acmod, lfeon; + uint64_t lfe_offset = 4; if (!GetFirstHeader(inFile)) { fprintf(stderr, diff --git a/MP42/MP42AVFImporter.m b/MP42/MP42AVFImporter.m index 0772b0d..ec86c3d 100644 --- a/MP42/MP42AVFImporter.m +++ b/MP42/MP42AVFImporter.m @@ -43,7 +43,7 @@ @implementation MP42AVFImporter + (NSArray *)supportedFileFormats { - return @[@"mov", @"m2ts", @"ts", @"mts", @"eac3"]; + return @[@"mov", @"m2ts", @"ts", @"mts", @"ac3", @"eac3"]; } - (NSString *)formatForTrack:(AVAssetTrack *)track { @@ -672,15 +672,16 @@ OSStatus err = noErr; size_t channelLayoutSize = 0; const AudioStreamBasicDescription *asbd = CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription); - const AudioChannelLayout* channelLayout = CMAudioFormatDescriptionGetChannelLayout(formatDescription, &channelLayoutSize); + const AudioChannelLayout *channelLayout = CMAudioFormatDescriptionGetChannelLayout(formatDescription, &channelLayoutSize); UInt32 bitmapSize = sizeof(UInt32); UInt32 channelBitmap; err = AudioFormatGetProperty(kAudioFormatProperty_BitmapForLayoutTag, sizeof(AudioChannelLayoutTag), &channelLayout->mChannelLayoutTag, &bitmapSize, &channelBitmap); - if (err && AudioChannelLayoutTag_GetNumberOfChannels(channelLayout->mChannelLayoutTag) == 6) + if (err && AudioChannelLayoutTag_GetNumberOfChannels(channelLayout->mChannelLayoutTag) == 6) { channelBitmap = 0x3F; + } uint64_t fscod = 0; uint64_t bsid = 8; @@ -841,27 +842,31 @@ CMItemCount timingArrayEntries = 0; CMItemCount timingArrayEntriesNeededOut = 0; err = CMSampleBufferGetSampleTimingInfoArray(sampleBuffer, timingArrayEntries, NULL, &timingArrayEntriesNeededOut); - if (err) + if (err) { continue; + } CMSampleTimingInfo *timingArrayOut = malloc(sizeof(CMSampleTimingInfo) * timingArrayEntriesNeededOut); timingArrayEntries = timingArrayEntriesNeededOut; err = CMSampleBufferGetSampleTimingInfoArray(sampleBuffer, timingArrayEntries, timingArrayOut, &timingArrayEntriesNeededOut); - if (err) + if (err) { continue; + } // Then the array with the size of each sample CMItemCount sizeArrayEntries = 0; CMItemCount sizeArrayEntriesNeededOut = 0; err = CMSampleBufferGetSampleSizeArray(sampleBuffer, sizeArrayEntries, NULL, &sizeArrayEntriesNeededOut); - if (err) + if (err) { continue; + } size_t *sizeArrayOut = malloc(sizeof(size_t) * sizeArrayEntriesNeededOut); sizeArrayEntries = sizeArrayEntriesNeededOut; err = CMSampleBufferGetSampleSizeArray(sampleBuffer, sizeArrayEntries, sizeArrayOut, &sizeArrayEntriesNeededOut); - if (err) + if (err) { continue; + } // Get CMBlockBufferRef to extract the actual data later CMBlockBufferRef buffer = CMSampleBufferGetDataBuffer(sampleBuffer); @@ -944,10 +949,9 @@ currentDataLength += sampleSize; } - if (timingArrayOut) - free(timingArrayOut); - if (sizeArrayOut) - free(sizeArrayOut); + free(timingArrayOut); + free(sizeArrayOut); + } CFRelease(sampleBuffer); diff --git a/MP42/MP42AudioConverter.m b/MP42/MP42AudioConverter.m index 06e7442..6d60770 100644 --- a/MP42/MP42AudioConverter.m +++ b/MP42/MP42AudioConverter.m @@ -395,10 +395,10 @@ OSStatus DecoderDataProc(AudioConverterRef inAudioConverter, } - if (ichanmap != &hb_qt_chan_map ) { + if (ichanmap != &hb_qt_chan_map ) { hb_layout_remap( ichanmap, &hb_qt_chan_map, layout, (float *)outputBuffer, - ioOutputDataPackets ); + ioOutputDataPackets); } // Dowmnix the audio if needed if (downmix) { @@ -489,7 +489,13 @@ OSStatus DecoderDataProc(AudioConverterRef inAudioConverter, if (([track.sourceFormat isEqualToString:MP42AudioFormatTrueHD] || [track.sourceFormat isEqualToString:MP42AudioFormatAC3]) && inputChannelsCount == 6 ) { - ichanmap = &hb_smpte_chan_map; + if (NSAppKitVersionNumber <= NSAppKitVersionNumber10_10_Max) { + ichanmap = &hb_smpte_chan_map; + } + else + { + ichanmap = &hb_ac3_2_chan_map; + } layout = HB_INPUT_CH_LAYOUT_3F2R | HB_INPUT_CH_LAYOUT_HAS_LFE; } else { diff --git a/MP42/QTKitDecrap.h b/MP42/QTKitDecrap.h index 6621d69..91be952 100644 --- a/MP42/QTKitDecrap.h +++ b/MP42/QTKitDecrap.h @@ -12,7 +12,7 @@ extern NSString * const QTTrackLanguageAttribute; // NSNumber (long) @interface QTMovie (QTMovieSublerExtras) -- (QTTrack*) trackWithTrackID:(NSInteger)trackID; +- (QTTrack *)trackWithTrackID:(NSInteger)trackID; @end diff --git a/MP42/muxer/downmix.c b/MP42/muxer/downmix.c index 1e40642..6820f6a 100644 --- a/MP42/muxer/downmix.c +++ b/MP42/muxer/downmix.c @@ -1138,6 +1138,73 @@ hb_chan_map_t hb_ac3_chan_map = } }; +hb_chan_map_t hb_ac3_2_chan_map = +{ +{ + {{ CH_C, }, + { CH_C, CH_LFE, }}, // MONO + + {{ CH_L, CH_R, }, + { CH_L, CH_R, CH_LFE, }}, // STEREO + + {{ CH_L, CH_C, CH_R, }, + { CH_L, CH_C, CH_R, CH_LFE, }}, // 3F + + {{ CH_L, CH_R, CH_CS, }, + { CH_L, CH_R, CH_CS, CH_LFE, }}, // 2F1R + + {{ CH_L, CH_C, CH_R, CH_CS, }, + { CH_L, CH_C, CH_R, CH_CS, CH_LFE, }}, // 3F1R + + {{ CH_L, CH_R, CH_LS, CH_RS, }, + { CH_L, CH_R, CH_LS, CH_RS, CH_LFE, }}, // 2F2R + + {{ CH_L, CH_C, CH_R, CH_LS, CH_RS, }, + { CH_L, CH_C, CH_R, CH_LS, CH_RS, CH_LFE, }}, // 3F2R + + {{ CH_L, CH_C, CH_R, CH_LS, CH_RS, CH_Rls, CH_Rrs, }, + { CH_L, CH_C, CH_R, CH_LS, CH_RS, CH_Rls, CH_Rrs, CH_LFE, }}, // 3F4R + + {{ CH_L, CH_R, }, + { CH_L, CH_R, }}, // DOLBY + + {{ CH_L, CH_R, }, + { CH_L, CH_R, }} // DPLII +}, +{ + // CH_C CH_L CH_R CH_LS/CS CH_RS CH_Rls CH_Rrs CH_LFE + {{ 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 1 }}, // MONO + + {{ 0, 0, 1, 0, 0, 0, 0, 0 }, + { 0, 0, 1, 0, 0, 0, 0, 2 }}, // STEREO + + {{ 1, 0, 2, 0, 0, 0, 0, 0 }, + { 1, 0, 2, 0, 0, 0, 0, 3 }}, // 3F + + {{ 0, 0, 1, 2, 0, 0, 0, 0 }, + { 0, 0, 1, 2, 0, 0, 0, 3 }}, // 2F1R + + {{ 1, 0, 2, 3, 0, 0, 0, 0 }, + { 1, 0, 2, 3, 0, 0, 0, 4 }}, // 3F1R + + {{ 0, 0, 1, 2, 3, 0, 0, 0 }, + { 0, 0, 1, 2, 3, 0, 0, 4 }}, // 2F2R + + {{ 1, 0, 2, 3, 4, 0, 0, 0 }, + { 1, 0, 2, 3, 4, 0, 0, 5 }}, // 3F2R + + {{ 1, 0, 2, 3, 4, 5, 6, 0 }, + { 1, 0, 2, 3, 4, 5, 6, 7 }}, // 3F4R + + {{ 0, 0, 1, 0, 0, 0, 0, 0 }, + { 0, 0, 1, 0, 0, 0, 0, 0 }}, // DOLBY + + {{ 0, 0, 1, 0, 0, 0, 0, 0 }, + { 0, 0, 1, 0, 0, 0, 0, 0 }} // DPLII +} +}; + static const uint8_t nchans_tbl[] = {1, 2, 3, 3, 4, 4, 5, 7, 2, 2}; // Takes a set of samples and remaps the channel layout diff --git a/MP42/muxer/downmix.h b/MP42/muxer/downmix.h index 8f87a67..3597266 100644 --- a/MP42/muxer/downmix.h +++ b/MP42/muxer/downmix.h @@ -84,6 +84,7 @@ typedef struct // Map Indicies are mode, lfe, channel respectively extern hb_chan_map_t hb_smpte_chan_map; extern hb_chan_map_t hb_ac3_chan_map; +extern hb_chan_map_t hb_ac3_2_chan_map; extern hb_chan_map_t hb_qt_chan_map; hb_downmix_t * hb_downmix_init(int layout, int mixdown);