Fix ac3 channel layout on 10.11
This commit is contained in:
1 parent
10b77b2587
commit
98689e43a9
6 files changed
+95
-17
No files matched your search
@@ -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,
|
||||
|
||||
+15
-11
@@ -43,7 +43,7 @@
|
||||
@implementation MP42AVFImporter
|
||||
|
||||
+ (NSArray<NSString *> *)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);
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ extern NSString * const QTTrackLanguageAttribute; // NSNumber (long)
|
||||
|
||||
@interface QTMovie (QTMovieSublerExtras)
|
||||
|
||||
- (QTTrack*) trackWithTrackID:(NSInteger)trackID;
|
||||
- (QTTrack *)trackWithTrackID:(NSInteger)trackID;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user