Guess a layout for PCM tracks if none is set.
This commit is contained in:
1 parent
72c721db22
commit
69cb3ea22c
7 files changed
+69
-7
No files matched your search
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#import "mp4v2.h"
|
#import "mp4v2.h"
|
||||||
#import "MP42PrivateUtilities.h"
|
#import "MP42PrivateUtilities.h"
|
||||||
|
#import "MP42FormatUtilites.h"
|
||||||
#import "MP42Track+Muxer.h"
|
#import "MP42Track+Muxer.h"
|
||||||
#import "MP42Track+Private.h"
|
#import "MP42Track+Private.h"
|
||||||
|
|
||||||
@@ -183,8 +184,10 @@
|
|||||||
audioTrack.channelLayoutTag = layout->mChannelLayoutTag;
|
audioTrack.channelLayoutTag = layout->mChannelLayoutTag;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
audioTrack.channels = 1;
|
// Guess the layout.
|
||||||
audioTrack.channelLayoutTag = kAudioChannelLayoutTag_Mono;
|
const AudioStreamBasicDescription *asbd = CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription);
|
||||||
|
audioTrack.channels = asbd->mChannelsPerFrame;
|
||||||
|
audioTrack.channelLayoutTag = getDefaultChannelLayout(asbd->mChannelsPerFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newTrack = audioTrack;
|
newTrack = audioTrack;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
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);
|
||||||
|
|||||||
@@ -11,6 +11,32 @@
|
|||||||
|
|
||||||
#import <CoreAudio/CoreAudio.h>
|
#import <CoreAudio/CoreAudio.h>
|
||||||
|
|
||||||
|
UInt32 getDefaultChannelLayout(UInt32 channelsCount)
|
||||||
|
{
|
||||||
|
// Guess a channel layout
|
||||||
|
switch (channelsCount) {
|
||||||
|
case 1:
|
||||||
|
return kAudioChannelLayoutTag_Mono;
|
||||||
|
case 2:
|
||||||
|
return kAudioChannelLayoutTag_Stereo;
|
||||||
|
case 3:
|
||||||
|
return kAudioChannelLayoutTag_MPEG_3_0_A;
|
||||||
|
case 4:
|
||||||
|
return kAudioChannelLayoutTag_MPEG_4_0_A;
|
||||||
|
case 5:
|
||||||
|
return kAudioChannelLayoutTag_MPEG_5_0_A;
|
||||||
|
case 6:
|
||||||
|
return kAudioChannelLayoutTag_MPEG_5_1_A;
|
||||||
|
case 7:
|
||||||
|
return kAudioChannelLayoutTag_MPEG_6_1_A;
|
||||||
|
case 8:
|
||||||
|
return kAudioChannelLayoutTag_MPEG_7_1_A;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return kAudioChannelLayoutTag_Mono;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - AC3
|
#pragma mark - AC3
|
||||||
|
|
||||||
static const int ac3_layout_no_lfe[8] = {
|
static const int ac3_layout_no_lfe[8] = {
|
||||||
|
|||||||
+32
-2
@@ -215,7 +215,8 @@ static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, ui
|
|||||||
// Audio
|
// Audio
|
||||||
else if (mkvTrack->Type == TT_AUDIO) {
|
else if (mkvTrack->Type == TT_AUDIO) {
|
||||||
newTrack = [[MP42AudioTrack alloc] init];
|
newTrack = [[MP42AudioTrack alloc] init];
|
||||||
[(MP42AudioTrack*)newTrack setChannels:mkvTrack->AV.Audio.Channels];
|
[(MP42AudioTrack *)newTrack setChannels:mkvTrack->AV.Audio.Channels];
|
||||||
|
[(MP42AudioTrack *)newTrack setChannelLayoutTag:getDefaultChannelLayout(mkvTrack->AV.Audio.Channels)];
|
||||||
[newTrack setAlternate_group:1];
|
[newTrack setAlternate_group:1];
|
||||||
|
|
||||||
for (MP42Track *audioTrack in self.tracks) {
|
for (MP42Track *audioTrack in self.tracks) {
|
||||||
@@ -443,7 +444,10 @@ static const struct {
|
|||||||
{ "A_MPEG/L1", kMP42AudioCodecType_MPEGLayer1 },
|
{ "A_MPEG/L1", kMP42AudioCodecType_MPEGLayer1 },
|
||||||
{ "A_MPEG/L2", kMP42AudioCodecType_MPEGLayer2 },
|
{ "A_MPEG/L2", kMP42AudioCodecType_MPEGLayer2 },
|
||||||
{ "A_MPEG/L3", kMP42AudioCodecType_MPEGLayer3 },
|
{ "A_MPEG/L3", kMP42AudioCodecType_MPEGLayer3 },
|
||||||
{ "A_TTA1", kMP42AudioCodecType_TTA },
|
{ "A_PCM/INT/BIG", kMP42AudioCodecType_LinearPCM },
|
||||||
|
{ "A_PCM/INT/LIT", kMP42AudioCodecType_LinearPCM },
|
||||||
|
{ "A_PCM/FLOAT/IEEE", kMP42AudioCodecType_LinearPCM },
|
||||||
|
|
||||||
|
|
||||||
{ "S_TEXT/UTF8", kMP42SubtitleCodecType_Text },
|
{ "S_TEXT/UTF8", kMP42SubtitleCodecType_Text },
|
||||||
{ "S_TEXT/WEBVTT", kMP42SubtitleCodecType_WebVTT },
|
{ "S_TEXT/WEBVTT", kMP42SubtitleCodecType_WebVTT },
|
||||||
@@ -632,6 +636,32 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (AudioStreamBasicDescription)audioDescriptionForTrack:(MP42AudioTrack *)track
|
||||||
|
{
|
||||||
|
TrackInfo *trackInfo = mkv_GetTrackInfo(_matroskaFile, track.sourceId);
|
||||||
|
|
||||||
|
AudioStreamBasicDescription result;
|
||||||
|
bzero(&result, sizeof(AudioStreamBasicDescription));
|
||||||
|
|
||||||
|
result.mSampleRate = mkv_TruncFloat(trackInfo->AV.Audio.SamplingFreq);
|
||||||
|
result.mBitsPerChannel = trackInfo->AV.Audio.BitDepth;
|
||||||
|
result.mChannelsPerFrame = trackInfo->AV.Audio.Channels;
|
||||||
|
|
||||||
|
if (!strcmp(trackInfo->CodecID, "A_PCM/INT/BIG")) {
|
||||||
|
result.mFormatID = kAudioFormatLinearPCM;
|
||||||
|
result.mFormatFlags += kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked | kAudioFormatFlagIsBigEndian;
|
||||||
|
}
|
||||||
|
else if (!strcmp(trackInfo->CodecID, "A_PCM/INT/LIT")) {
|
||||||
|
result.mFormatID = kAudioFormatLinearPCM;
|
||||||
|
result.mFormatFlags += kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
|
||||||
|
}
|
||||||
|
else if (!strcmp(trackInfo->CodecID, "A_PCM/FLOAT/IEEE")) {
|
||||||
|
result.mFormatID = kAudioFormatLinearPCM;
|
||||||
|
result.mFormatFlags += kAudioFormatFlagIsFloat | kLinearPCMFormatFlagIsPacked;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// Methods to extract all the samples from the active tracks at the same time
|
// Methods to extract all the samples from the active tracks at the same time
|
||||||
- (void)demux
|
- (void)demux
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ NSString* getFilenameLanguage(CFStringRef filename);
|
|||||||
uint8_t *CreateEsdsFromSetupData(uint8_t *codecPrivate, size_t vosLen, size_t *esdsLen, int trackID, bool audio, bool write_version);
|
uint8_t *CreateEsdsFromSetupData(uint8_t *codecPrivate, size_t vosLen, size_t *esdsLen, int trackID, bool audio, bool write_version);
|
||||||
ComponentResult ReadESDSDescExt(void* descExt, UInt8 **buffer, int *size, int versionFlags);
|
ComponentResult ReadESDSDescExt(void* descExt, UInt8 **buffer, int *size, int versionFlags);
|
||||||
|
|
||||||
|
MP4Duration getTrackDuration(MP4FileHandle fileHandle, MP4TrackId trackId);
|
||||||
|
|
||||||
int64_t getTrackStartOffset(MP4FileHandle fileHandle, MP4TrackId Id);
|
int64_t getTrackStartOffset(MP4FileHandle fileHandle, MP4TrackId Id);
|
||||||
void setTrackStartOffset(MP4FileHandle fileHandle, MP4TrackId Id, int64_t offset);
|
void setTrackStartOffset(MP4FileHandle fileHandle, MP4TrackId Id, int64_t offset);
|
||||||
int copyTrackEditLists (MP4FileHandle fileHandle, MP4TrackId srcTrackId, MP4TrackId dstTrackId);
|
int copyTrackEditLists (MP4FileHandle fileHandle, MP4TrackId srcTrackId, MP4TrackId dstTrackId);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include "intreadwrite.h"
|
#include "intreadwrite.h"
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
|
|
||||||
NSString* SRTStringFromTime( long long time, long timeScale , const char separator)
|
NSString * SRTStringFromTime( long long time, long timeScale , const char separator)
|
||||||
{
|
{
|
||||||
NSString *SRT_string;
|
NSString *SRT_string;
|
||||||
int hour, minute, second, msecond;
|
int hour, minute, second, msecond;
|
||||||
|
|||||||
+2
-2
@@ -86,13 +86,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_bitrate = MP4GetTrackBitRate(fileHandle, _trackId);
|
_timescale = MP4GetTrackTimeScale(fileHandle, _trackId);
|
||||||
_duration = MP4ConvertFromTrackDuration(fileHandle, _trackId,
|
_duration = MP4ConvertFromTrackDuration(fileHandle, _trackId,
|
||||||
MP4GetTrackDuration(fileHandle, _trackId),
|
MP4GetTrackDuration(fileHandle, _trackId),
|
||||||
MP4_MSECS_TIME_SCALE);
|
MP4_MSECS_TIME_SCALE);
|
||||||
_timescale = MP4GetTrackTimeScale(fileHandle, _trackId);
|
|
||||||
_startOffset = getTrackStartOffset(fileHandle, _trackId);
|
_startOffset = getTrackStartOffset(fileHandle, _trackId);
|
||||||
|
|
||||||
|
_bitrate = MP4GetTrackBitRate(fileHandle, _trackId);
|
||||||
_dataLength = getTrackSize(fileHandle, _trackId);
|
_dataLength = getTrackSize(fileHandle, _trackId);
|
||||||
|
|
||||||
// Track flags
|
// Track flags
|
||||||
|
|||||||
Reference in new issue
Block a user