From e3a9f6b4e2a48fa88ff9f997a06349de75e07b29 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Wed, 30 Aug 2017 10:58:55 +0200 Subject: [PATCH] Do not try to read the esds if there isn't one. --- MP42/MP42AudioTrack.m | 67 ++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/MP42/MP42AudioTrack.m b/MP42/MP42AudioTrack.m index 397d8ee..a087b6b 100644 --- a/MP42/MP42AudioTrack.m +++ b/MP42/MP42AudioTrack.m @@ -34,45 +34,48 @@ if (self) { MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.volume", &_volume); + const char *dataName = MP4GetTrackMediaDataName(fileHandle, self.trackId); - u_int8_t audioType = MP4GetTrackEsdsObjectTypeId(fileHandle, self.trackId); + if (dataName && !strcmp(dataName, "mp4a")) { + u_int8_t audioType = MP4GetTrackEsdsObjectTypeId(fileHandle, self.trackId); - if (audioType != MP4_INVALID_AUDIO_TYPE) { - if (MP4_IS_AAC_AUDIO_TYPE(audioType)) { - u_int8_t* pAacConfig = NULL; - u_int32_t aacConfigLength; + if (audioType != MP4_INVALID_AUDIO_TYPE) { + if (MP4_IS_AAC_AUDIO_TYPE(audioType)) { + u_int8_t* pAacConfig = NULL; + u_int32_t aacConfigLength; - if (MP4GetTrackESConfiguration(fileHandle, - self.trackId, - &pAacConfig, - &aacConfigLength) == true) - if (pAacConfig != NULL || aacConfigLength >= 2) { - MPEG4AudioConfig c = {0}; - analyze_ESDS(&c, pAacConfig, aacConfigLength); - _channels = c.channels; - free(pAacConfig); + if (MP4GetTrackESConfiguration(fileHandle, + self.trackId, + &pAacConfig, + &aacConfigLength) == true) + if (pAacConfig != NULL || aacConfigLength >= 2) { + MPEG4AudioConfig c = {0}; + analyze_ESDS(&c, pAacConfig, aacConfigLength); + _channels = c.channels; + free(pAacConfig); + } + } + else if ((audioType == MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE) || + (audioType == MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE)) { + + u_int32_t samplesPerFrame = + MP4GetSampleSize(fileHandle, self.trackId, 1) / 2; + + MP4Duration frameDuration = + MP4GetSampleDuration(fileHandle, self.trackId, 1); + + if (frameDuration != 0) { + // assumes track time scale == sampling rate + _channels = samplesPerFrame / frameDuration; } - } - else if ((audioType == MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE) || - (audioType == MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE)) { - - u_int32_t samplesPerFrame = - MP4GetSampleSize(fileHandle, self.trackId, 1) / 2; - - MP4Duration frameDuration = - MP4GetSampleDuration(fileHandle, self.trackId, 1); - - if (frameDuration != 0) { - // assumes track time scale == sampling rate - _channels = samplesPerFrame / frameDuration; } } - } - if (audioType == 0xA9) { - uint64_t channels_count = 0; - MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.mp4a.channels", &channels_count); - _channels = channels_count; + if (audioType == 0xA9) { + uint64_t channels_count = 0; + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.mp4a.channels", &channels_count); + _channels = channels_count; + } } else if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.ac-3.dac3")) { uint64_t acmod, lfeon;