Remove the aac priming delay from the edit list media time.

This commit is contained in:
Damiano Galassi committed 2015-11-09 17:35:52 +01:00
1 parent f710cf7ac2
commit 4e0d573c5b
3 files changed
+53 -22

No files matched your search

+5 -4
View File
@@ -768,7 +768,7 @@
track.muxer_helper->demuxer_context = [[AVFDemuxHelper alloc] init];
demuxHelper = track.muxer_helper->demuxer_context;
demuxHelper->assetReaderOutput = assetReaderOutput;
demuxHelper->editsConstructor = [[MP42EditListsReconstructor alloc] init];
demuxHelper->editsConstructor = [[MP42EditListsReconstructor alloc] initWithMediaFormat:track.format];
totalDataLength += [track dataLength];
}
@@ -819,7 +819,7 @@
}
}
CMTime currentOutputTimeStamp = CMTimeConvertScale(presentationOutputTimeStamp, duration.timescale, kCMTimeRoundingMethod_Default);
CMTime currentOutputTimeStamp = CMTimeConvertScale(presentationOutputTimeStamp, duration.timescale, kCMTimeRoundingMethod_QuickTime);
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(NULL, sampleBuffer, kCMAttachmentMode_ShouldPropagate);
#ifdef SB_AVF_DEBUG
@@ -1033,11 +1033,12 @@
// Add back the new constructed edit lists.
for (uint64_t i = 0; i < helper->editsConstructor.editsCount; i++) {
CMTimeRange timeRange = helper->editsConstructor.edits[i];
CMTime duration = CMTimeConvertScale(timeRange.duration, timescale, kCMTimeRoundingMethod_Default);
CMTime duration = CMTimeConvertScale(timeRange.duration, timescale, kCMTimeRoundingMethod_QuickTime);
trackDuration += duration.value;
MP4AddTrackEdit(fileHandle, trackId, MP4_INVALID_EDIT_ID, timeRange.start.value - helper->minDisplayOffset,
MP4AddTrackEdit(fileHandle, trackId, MP4_INVALID_EDIT_ID,
timeRange.start.value - helper->minDisplayOffset,
duration.value, 0);
}
+10 -3
View File
@@ -26,12 +26,19 @@
int64_t _delta;
CMTimeRange *_edits;
uint64_t _editsCount;
uint64_t _editsSize;
CMTimeRange *_edits;
uint64_t _editsCount;
uint64_t _editsSize;
BOOL _editOpen;
FourCharCode _format;
uint64_t _priming;
BOOL _primingUsed;
}
- (instancetype)initWithMediaFormat:(NSString *)format;
- (void)addSample:(MP42SampleBuffer *)sample;
- (void)done;
+38 -15
View File
@@ -7,6 +7,7 @@
//
#import "MP42EditListsReconstructor.h"
#import "MP42MediaFormat.h"
@implementation MP42EditListsReconstructor
@@ -14,11 +15,25 @@
@synthesize editsCount = _editsCount;
- (instancetype)init {
self = [self initWithMediaFormat:0];
return self;
}
- (instancetype)initWithMediaFormat:(NSString *)format {
self = [super init];
if (self) {
_priorityQueue = [[MP42Heap alloc] initWithCapacity:32 andComparator:^NSComparisonResult(MP42SampleBuffer * obj1, MP42SampleBuffer * obj2) {
return obj2->presentationTimestamp - obj1->presentationTimestamp;
}];
if ([format isEqualToString:MP42AudioFormatAAC]) {
_priming = 2112;
}
else if ([format isEqualToString:MP42AudioFormatHEAAC])
{
_priming = 4224;
}
}
return self;
}
@@ -36,14 +51,6 @@
[_priorityQueue insert:sample];
if (_timescale == 0) {
_timescale = sample->timescale;
// Re-align things if the first sample pts is not 0
if (sample->presentationTimestamp != 0) {
_currentTime += sample->presentationTimestamp;
}
}
if ([_priorityQueue isFull]) {
MP42SampleBuffer *extractedSample = [_priorityQueue extract];
[self analyzeSample:extractedSample];
@@ -60,7 +67,8 @@
}
if (_editOpen == YES) {
[self endEditListAtTime:CMTimeMake(_currentTime, _timescale) empty:NO];
CMTime editEnd = CMTimeMake(_currentTime, _timescale);
[self endEditListAtTime:editEnd empty:NO];
}
}
@@ -69,16 +77,26 @@
}
- (void)analyzeSample:(MP42SampleBuffer *)sample {
#ifdef AVF_DEBUG
NSLog(@"T: %llu, P: %lld, PO: %lld O: %lld", _currentTime, sample->presentationTimestamp, sample->presentationOutputTimestamp, sample->offset);
#endif
if (_timescale == 0) {
_timescale = sample->timescale;
// Re-align things if the first sample pts is not 0
if (sample->presentationTimestamp != 0) {
_currentTime += sample->presentationTimestamp;
}
}
CFDictionaryRef trimStart = NULL, trimEnd = NULL;
if (sample->attachments) {
trimStart = CFDictionaryGetValue(sample->attachments, kCMSampleBufferAttachmentKey_TrimDurationAtStart);
trimEnd = CFDictionaryGetValue(sample->attachments, kCMSampleBufferAttachmentKey_TrimDurationAtEnd);
}
#ifdef AVF_DEBUG
NSLog(@"T: %llu, P: %llu, PO: %llu", _currentTime, sample->presentationTimestamp, sample->presentationOutputTimestamp);
#endif
// Check if we need to add an empty edit list.
if (sample->presentationOutputTimestamp > sample->presentationTimestamp + _delta) {
_delta = sample->presentationOutputTimestamp - sample->presentationTimestamp;
@@ -106,10 +124,15 @@
if (trimStart) {
CMTime trimStartTime = CMTimeMakeFromDictionary(trimStart);
trimStartTime = CMTimeConvertScale(trimStartTime, _timescale, kCMTimeRoundingMethod_Default);
trimStartTime = CMTimeConvertScale(trimStartTime, _timescale, kCMTimeRoundingMethod_QuickTime);
editStart.value += trimStartTime.value;
}
if (_priming && _primingUsed == NO) {
editStart.value -= _priming;
_primingUsed = YES;
}
[self startEditListAtTime:editStart];
}
@@ -122,7 +145,7 @@
if (trimEnd) {
CMTime trimEndTime = CMTimeMakeFromDictionary(trimEnd);
trimEndTime = CMTimeConvertScale(trimEndTime, _timescale, kCMTimeRoundingMethod_Default);
trimEndTime = CMTimeConvertScale(trimEndTime, _timescale, kCMTimeRoundingMethod_QuickTime);
editEnd.value -= trimEndTime.value;
}