Fix PCM reading performance in MP42AVFoundation importer.
This commit is contained in:
1 parent
c9b59d96f0
commit
c1e174996b
2 files changed
+55
-1
No files matched your search
+2
-1
@@ -3,7 +3,8 @@
|
||||
// MP42Foundation
|
||||
//
|
||||
// Created by Damiano Galassi on 23/07/2016.
|
||||
// Copyright © 2016 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
// Useful utilites from FFmpeg source code.
|
||||
//
|
||||
|
||||
#include "FFmpegUtils.h"
|
||||
|
||||
@@ -184,6 +184,7 @@
|
||||
}
|
||||
else {
|
||||
audioTrack.channels = 1;
|
||||
audioTrack.channelLayoutTag = kAudioChannelLayoutTag_Mono;
|
||||
}
|
||||
}
|
||||
newTrack = audioTrack;
|
||||
@@ -898,6 +899,57 @@
|
||||
CMBlockBufferRef buffer = CMSampleBufferGetDataBuffer(sampleBuffer);
|
||||
size_t bufferSize = CMBlockBufferGetDataLength(buffer);
|
||||
|
||||
// Don't split the buffer if the format is PCM
|
||||
if (track.format == kMP42AudioCodecType_LinearPCM) {
|
||||
size_t sampleSize = bufferSize;
|
||||
void *sampleData = malloc(sampleSize);
|
||||
|
||||
CMBlockBufferCopyDataBytes(buffer, 0, sampleSize, sampleData);
|
||||
|
||||
CMTime duration = CMSampleBufferGetDuration(sampleBuffer);
|
||||
CMTime decodeTimeStamp = CMSampleBufferGetDecodeTimeStamp(sampleBuffer);
|
||||
CMTime presentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
|
||||
CMTime presentationOutputTimeStamp = CMSampleBufferGetOutputPresentationTimeStamp(sampleBuffer);
|
||||
CMTime currentOutputTimeStamp = CMTimeConvertScale(presentationOutputTimeStamp, duration.timescale, kCMTimeRoundingMethod_QuickTime);
|
||||
|
||||
// Read sample attachment, sync to mark the frame as sync
|
||||
BOOL sync = 1;
|
||||
BOOL doNotDisplay = NO;
|
||||
CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, NO);
|
||||
if (attachmentsArray) {
|
||||
for (NSDictionary *dict in (NSArray *)attachmentsArray) {
|
||||
if ([dict valueForKey:(NSString *)kCMSampleAttachmentKey_NotSync]) {
|
||||
sync = 0;
|
||||
}
|
||||
if ([dict valueForKey:(NSString*)kCMSampleAttachmentKey_DoNotDisplay]) {
|
||||
doNotDisplay = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enqueues the new sample
|
||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||
sample->data = sampleData;
|
||||
sample->size = sampleSize;
|
||||
sample->duration = duration.value;
|
||||
sample->offset = -decodeTimeStamp.value + presentationTimeStamp.value;
|
||||
sample->presentationTimestamp = presentationTimeStamp.value;
|
||||
sample->presentationOutputTimestamp = currentOutputTimeStamp.value;
|
||||
sample->timescale = duration.timescale;
|
||||
sample->flags |= sync ? MP42SampleBufferFlagIsSync : 0;
|
||||
sample->flags |= doNotDisplay ? MP42SampleBufferFlagDoNotDisplay : 0;
|
||||
sample->trackId = track.sourceId;
|
||||
|
||||
sample->attachments = (void *)attachments;
|
||||
|
||||
[demuxHelper->editsConstructor addSample:sample];
|
||||
[self enqueue:sample];
|
||||
[sample release];
|
||||
|
||||
demuxHelper->currentTime += duration.value;
|
||||
currentDataLength += sampleSize;
|
||||
}
|
||||
else {
|
||||
int pos = 0;
|
||||
for (int i = 0; i < samplesNum; i++) {
|
||||
CMSampleTimingInfo sampleTimingInfo;
|
||||
@@ -987,6 +1039,7 @@
|
||||
demuxHelper->currentTime += sampleTimingInfo.duration.value;
|
||||
currentDataLength += sampleSize;
|
||||
}
|
||||
}
|
||||
|
||||
free(timingArrayOut);
|
||||
free(sizeArrayOut);
|
||||
|
||||
Reference in new issue
Block a user