Add some code to detect Atmos in EAC3, thanks to Priit Varik.
This commit is contained in:
7 files changed
+1364
-78
No files matched your search
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
@property(nonatomic, readwrite) UInt32 channels;
|
@property(nonatomic, readwrite) UInt32 channels;
|
||||||
@property(nonatomic, readwrite) UInt32 channelLayoutTag;
|
@property(nonatomic, readwrite) UInt32 channelLayoutTag;
|
||||||
|
@property(nonatomic, readwrite) MP42EmbeddedAudioCodecType embeddedAudioFormat;
|
||||||
|
|
||||||
@property(nonatomic, readonly) MP42TrackId fallbackTrackId;
|
@property(nonatomic, readonly) MP42TrackId fallbackTrackId;
|
||||||
@property(nonatomic, readonly) MP42TrackId followsTrackId;
|
@property(nonatomic, readonly) MP42TrackId followsTrackId;
|
||||||
|
|||||||
+13
-3
@@ -77,8 +77,12 @@
|
|||||||
else if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.ec-3.dec3")) {
|
else if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.ec-3.dec3")) {
|
||||||
uint8_t *ppValue;
|
uint8_t *ppValue;
|
||||||
uint32_t pValueSize;
|
uint32_t pValueSize;
|
||||||
MP4GetTrackBytesProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.ec-3.dec3.content", &ppValue, &pValueSize);
|
UInt8 numObjects = 0;
|
||||||
readEAC3Config(ppValue, pValueSize, &_channels, &_channelLayoutTag);
|
MP4GetTrackBytesProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.ec-3.dec3.content", &ppValue, &pValueSize);
|
||||||
|
readEAC3Config(ppValue, pValueSize, &_channels, &_channelLayoutTag, &numObjects);
|
||||||
|
if (numObjects > 0) {
|
||||||
|
_embeddedAudioFormat = kMP42EmbeddedAudioCodecType_Atmos;
|
||||||
|
}
|
||||||
free(ppValue);
|
free(ppValue);
|
||||||
}
|
}
|
||||||
else if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.alac")) {
|
else if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.alac")) {
|
||||||
@@ -245,7 +249,13 @@
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (_channels > 0) {
|
if (_channels > 0) {
|
||||||
return [NSString stringWithFormat:@"%@, %u ch", localizedDisplayName(self.mediaType, self.format), (unsigned int)_channels];
|
if (_embeddedAudioFormat) {
|
||||||
|
return [NSString stringWithFormat:@"%@ + %@, %u ch", localizedDisplayName(self.mediaType, self.format),
|
||||||
|
localizedDisplayName(self.mediaType, self.embeddedAudioFormat),
|
||||||
|
(unsigned int)_channels];
|
||||||
|
} else {
|
||||||
|
return [NSString stringWithFormat:@"%@, %u ch", localizedDisplayName(self.mediaType, self.format), (unsigned int)_channels];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return [NSString stringWithFormat:@"%@", localizedDisplayName(self.mediaType, self.format)];
|
return [NSString stringWithFormat:@"%@", localizedDisplayName(self.mediaType, self.format)];
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ extern "C" {
|
|||||||
UInt32 getDefaultChannelLayout(UInt32 channelsCount);
|
UInt32 getDefaultChannelLayout(UInt32 channelsCount);
|
||||||
|
|
||||||
int readAC3Config(uint64_t acmod, uint64_t lfeon, UInt32 *channelsCount, UInt32 *channelLayoutTag);
|
int readAC3Config(uint64_t acmod, uint64_t lfeon, UInt32 *channelsCount, UInt32 *channelLayoutTag);
|
||||||
int readEAC3Config(const uint8_t *cookie, uint32_t cookieLen, UInt32 *channelsCount, UInt32 *channelLayoutTag);
|
int readEAC3Config(const uint8_t *cookie, uint32_t cookieLen, UInt32 *channelsCount, UInt32 *channelLayoutTag, UInt8 *numAtmosObjects);
|
||||||
|
|
||||||
int analyze_EAC3(void **context ,uint8_t *frame, uint32_t size);
|
int analyze_EAC3(void **context ,uint8_t *frame, uint32_t size);
|
||||||
CFDataRef createCookie_EAC3(void *context);
|
CFDataRef createCookie_EAC3(void *context);
|
||||||
|
uint8_t get_num_objects_EAC3(void *context);
|
||||||
void free_EAC3_context(void *context);
|
void free_EAC3_context(void *context);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -72,6 +73,42 @@ extern "C" {
|
|||||||
int frame_length_short;
|
int frame_length_short;
|
||||||
} MPEG4AudioConfig;
|
} MPEG4AudioConfig;
|
||||||
|
|
||||||
|
struct eac3_info {
|
||||||
|
uint8_t *frame;
|
||||||
|
uint32_t size;
|
||||||
|
|
||||||
|
uint8_t ec3_done;
|
||||||
|
uint8_t num_blocks;
|
||||||
|
|
||||||
|
/* Layout of the EC3SpecificBox */
|
||||||
|
/* maximum bitrate */
|
||||||
|
uint16_t data_rate;
|
||||||
|
/* number of independent substreams */
|
||||||
|
uint8_t num_ind_sub;
|
||||||
|
uint8_t num_objects_oamd; //OAMD>0 && JOC>0 indicates Atmos
|
||||||
|
uint8_t num_objects_joc; //OAMD>0 && JOC>0 indicates Atmos
|
||||||
|
struct {
|
||||||
|
/* sample rate code (see ff_ac3_sample_rate_tab) 2 bits */
|
||||||
|
uint8_t fscod;
|
||||||
|
/* bit stream identification 5 bits */
|
||||||
|
uint8_t bsid;
|
||||||
|
/* one bit reserved */
|
||||||
|
/* audio service mixing (not supported yet) 1 bit */
|
||||||
|
/* bit stream mode 3 bits */
|
||||||
|
uint8_t bsmod;
|
||||||
|
/* audio coding mode 3 bits */
|
||||||
|
uint8_t acmod;
|
||||||
|
/* sub woofer on 1 bit */
|
||||||
|
uint8_t lfeon;
|
||||||
|
/* 3 bits reserved */
|
||||||
|
/* number of dependent substreams associated with this substream 4 bits */
|
||||||
|
uint8_t num_dep_sub;
|
||||||
|
/* channel locations of the dependent substream(s), if any, 9 bits */
|
||||||
|
uint16_t chan_loc;
|
||||||
|
/* if there is no dependent substream, then one bit reserved instead */
|
||||||
|
} substream[1]; /* TODO: support 8 independent substreams */
|
||||||
|
};
|
||||||
|
|
||||||
int analyze_ESDS(MPEG4AudioConfig *c, const uint8_t *cookie, uint32_t cookieLen);
|
int analyze_ESDS(MPEG4AudioConfig *c, const uint8_t *cookie, uint32_t cookieLen);
|
||||||
|
|
||||||
int analyze_AVC(const uint8_t *cookie, uint32_t cookieLen);
|
int analyze_AVC(const uint8_t *cookie, uint32_t cookieLen);
|
||||||
|
|||||||
+1246
-68
File diff suppressed because it is too large.
Load diff
@@ -161,6 +161,13 @@ enum : MP42AudioCodecType
|
|||||||
kMP42AudioCodecType_FairPlay_AC3 = 'pac3'
|
kMP42AudioCodecType_FairPlay_AC3 = 'pac3'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Audio Format
|
||||||
|
typedef FourCharCode MP42EmbeddedAudioCodecType;
|
||||||
|
enum : MP42EmbeddedAudioCodecType
|
||||||
|
{
|
||||||
|
kMP42EmbeddedAudioCodecType_Atmos = 'atmo',
|
||||||
|
};
|
||||||
|
|
||||||
// Subtitle Format
|
// Subtitle Format
|
||||||
typedef FourCharCode MP42SubtitleCodecType;
|
typedef FourCharCode MP42SubtitleCodecType;
|
||||||
enum : MP42SubtitleCodecType
|
enum : MP42SubtitleCodecType
|
||||||
|
|||||||
@@ -286,6 +286,10 @@ NSString *localizedAudioDisplayName(FourCharCode mediaSubtype)
|
|||||||
result = NSLocalizedString(@"PCM", nil);
|
result = NSLocalizedString(@"PCM", nil);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case kMP42EmbeddedAudioCodecType_Atmos:
|
||||||
|
result = NSLocalizedString(@"Atmos", nil);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+55
-6
@@ -286,6 +286,9 @@ static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, ui
|
|||||||
audioTrack.channels = mkvTrack->AV.Audio.Channels;
|
audioTrack.channels = mkvTrack->AV.Audio.Channels;
|
||||||
audioTrack.channelLayoutTag = channelLayout(mkvTrack);
|
audioTrack.channelLayoutTag = channelLayout(mkvTrack);
|
||||||
audioTrack.alternateGroup = 1;
|
audioTrack.alternateGroup = 1;
|
||||||
|
audioTrack.sourceId = i;
|
||||||
|
audioTrack.embeddedAudioFormat = [self numObjectsForAudioTrack:audioTrack mkvTrack:mkvTrack] > 0
|
||||||
|
? kMP42EmbeddedAudioCodecType_Atmos : 0;
|
||||||
|
|
||||||
for (MP42Track *track in self.tracks) {
|
for (MP42Track *track in self.tracks) {
|
||||||
if ([track isMemberOfClass:[MP42AudioTrack class]]) {
|
if ([track isMemberOfClass:[MP42AudioTrack class]]) {
|
||||||
@@ -673,7 +676,7 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
uint64_t StartTime, EndTime, FilePos;
|
uint64_t StartTime, EndTime, FilePos;
|
||||||
uint32_t rt, FrameSize, FrameFlags;
|
uint32_t rt, FrameSize, FrameFlags;
|
||||||
uint8_t *frame = NULL;
|
uint8_t *frame = NULL;
|
||||||
NSData *magicCookie = nil;
|
NSData *magicCookie = nil;
|
||||||
|
|
||||||
if (!strcmp(trackInfo->CodecID, "A_AC3")) {
|
if (!strcmp(trackInfo->CodecID, "A_AC3")) {
|
||||||
// read first header to create track
|
// read first header to create track
|
||||||
@@ -723,15 +726,19 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (!strcmp(trackInfo->CodecID, "A_EAC3")) {
|
else if (!strcmp(trackInfo->CodecID, "A_EAC3")) {
|
||||||
|
#ifdef DEBUG_PARSER
|
||||||
|
uint16_t mkvpktnum = 0;
|
||||||
|
#endif
|
||||||
void *context = NULL;
|
void *context = NULL;
|
||||||
SegmentInfo *segInfo = mkv_GetFileInfo(_matroskaFile);
|
SegmentInfo *segInfo = mkv_GetFileInfo(_matroskaFile);
|
||||||
|
|
||||||
while (!mkv_ReadFrame(_matroskaFile, 0, &rt, &StartTime, &EndTime, &FilePos, &FrameSize, &FrameFlags) &&
|
while (!mkv_ReadFrame(_matroskaFile, 0, &rt, &StartTime, &EndTime, &FilePos, &FrameSize, &FrameFlags) && StartTime < (segInfo->Duration / 64))
|
||||||
StartTime < (segInfo->Duration / 64)) {
|
{
|
||||||
|
|
||||||
if (readMkvPacket(_ioStream, trackInfo, FilePos, &frame, &FrameSize)) {
|
if (readMkvPacket(_ioStream, trackInfo, FilePos, &frame, &FrameSize)) {
|
||||||
analyze_EAC3(&context, frame, FrameSize);
|
#ifdef DEBUG_PARSER
|
||||||
|
printf("\n\nAnalyzing MKV EAC3 packet number %d at filepos 0x%llX (%llu) with size 0x%X (%u) bits\n", mkvpktnum++, FilePos, FilePos, FrameSize * 8, FrameSize * 8);
|
||||||
|
#endif
|
||||||
|
analyze_EAC3(&context, frame, FrameSize); //PV take atmos tracks from mp42track already!!
|
||||||
free(frame);
|
free(frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -769,6 +776,48 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (uint8_t)numObjectsForAudioTrack:(MP42Track *)track mkvTrack:(TrackInfo *)trackInfo
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_PARSER
|
||||||
|
uint16_t mkvpktnum = 0;
|
||||||
|
#endif
|
||||||
|
//TrackInfo *trackInfo = mkv_GetTrackInfo(_matroskaFile, track.trackId);
|
||||||
|
struct eac3_info *context = NULL;
|
||||||
|
uint8_t num_hits = 0;
|
||||||
|
uint8_t num_objects = 0;
|
||||||
|
|
||||||
|
if (!strcmp(trackInfo->CodecID, "A_EAC3"))
|
||||||
|
{
|
||||||
|
mkv_SetTrackMask(_matroskaFile, ~(1l << track.sourceId));
|
||||||
|
|
||||||
|
uint64_t StartTime, EndTime, FilePos;
|
||||||
|
uint32_t rt, FrameSize, FrameFlags;
|
||||||
|
uint8_t *frame = NULL;
|
||||||
|
|
||||||
|
SegmentInfo *segInfo = mkv_GetFileInfo(_matroskaFile);
|
||||||
|
while (!mkv_ReadFrame(_matroskaFile, 0, &rt, &StartTime, &EndTime, &FilePos, &FrameSize, &FrameFlags) && StartTime < (segInfo->Duration / 10))
|
||||||
|
{
|
||||||
|
if (readMkvPacket(_ioStream, trackInfo, FilePos, &frame, &FrameSize))
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_PARSER
|
||||||
|
printf("\n\nAnalyzing MKV EAC3 packet number %d at filepos 0x%llX (%llu) with size 0x%X (%u) bits\n", mkvpktnum++, FilePos, FilePos, FrameSize * 8, FrameSize * 8);
|
||||||
|
#endif
|
||||||
|
analyze_EAC3((void *)&context, frame, FrameSize);
|
||||||
|
if(context->num_objects_joc && context->num_objects_oamd) //count frames with positive Atmos identification
|
||||||
|
num_hits++;
|
||||||
|
}
|
||||||
|
if (num_hits > 2) //to speed up process, lets consider 3 hits sufficient
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context) {
|
||||||
|
num_objects = get_num_objects_EAC3(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
return num_objects;
|
||||||
|
}
|
||||||
|
|
||||||
- (AudioStreamBasicDescription)audioDescriptionForTrack:(MP42AudioTrack *)track
|
- (AudioStreamBasicDescription)audioDescriptionForTrack:(MP42AudioTrack *)track
|
||||||
{
|
{
|
||||||
TrackInfo *trackInfo = mkv_GetTrackInfo(_matroskaFile, track.sourceId);
|
TrackInfo *trackInfo = mkv_GetTrackInfo(_matroskaFile, track.sourceId);
|
||||||
|
|||||||
Reference in new issue
Block a user