Move the offset calculation to MP42EditListsReconstructor
This commit is contained in:
3 files changed
+15
-10
No files matched your search
+7
-10
@@ -26,8 +26,6 @@
|
|||||||
|
|
||||||
@interface AVFDemuxHelper : NSObject {
|
@interface AVFDemuxHelper : NSObject {
|
||||||
@public
|
@public
|
||||||
int64_t minDisplayOffset;
|
|
||||||
|
|
||||||
AVAssetReaderOutput *assetReaderOutput;
|
AVAssetReaderOutput *assetReaderOutput;
|
||||||
MP42EditListsReconstructor *editsConstructor;
|
MP42EditListsReconstructor *editsConstructor;
|
||||||
}
|
}
|
||||||
@@ -1006,10 +1004,6 @@
|
|||||||
sample->trackId = track.sourceId;
|
sample->trackId = track.sourceId;
|
||||||
sample->attachments = (void *)attachments;
|
sample->attachments = (void *)attachments;
|
||||||
|
|
||||||
if (sample->offset < demuxHelper->minDisplayOffset) {
|
|
||||||
demuxHelper->minDisplayOffset = sample->offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
[demuxHelper->editsConstructor addSample:sample];
|
[demuxHelper->editsConstructor addSample:sample];
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
[sample release];
|
[sample release];
|
||||||
@@ -1191,23 +1185,26 @@
|
|||||||
MP42Track *inputTrack = [self inputTrackWithTrackID:track.sourceId];
|
MP42Track *inputTrack = [self inputTrackWithTrackID:track.sourceId];
|
||||||
|
|
||||||
AVFDemuxHelper *helper = inputTrack.muxer_helper->demuxer_context;
|
AVFDemuxHelper *helper = inputTrack.muxer_helper->demuxer_context;
|
||||||
|
MP42EditListsReconstructor *editsConstructor = helper->editsConstructor;
|
||||||
|
|
||||||
// Make sure the sample offsets are all positive.
|
// Make sure the sample offsets are all positive.
|
||||||
if (helper->minDisplayOffset != 0) {
|
if (editsConstructor.minOffset < 0) {
|
||||||
MP4SampleId samplesCount = MP4GetTrackNumberOfSamples(fileHandle, trackId);
|
MP4SampleId samplesCount = MP4GetTrackNumberOfSamples(fileHandle, trackId);
|
||||||
for (unsigned int i = 0; i < samplesCount; i++) {
|
for (unsigned int i = 0; i < samplesCount; i++) {
|
||||||
MP4SetSampleRenderingOffset(fileHandle,
|
MP4SetSampleRenderingOffset(fileHandle,
|
||||||
trackId,
|
trackId,
|
||||||
1 + i,
|
1 + i,
|
||||||
MP4GetSampleRenderingOffset(fileHandle, trackId, 1 + i) - helper->minDisplayOffset);
|
MP4GetSampleRenderingOffset(fileHandle, trackId, 1 + i) - editsConstructor.minOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add back the new constructed edit lists.
|
// Add back the new constructed edit lists.
|
||||||
for (uint64_t i = 0; i < helper->editsConstructor.editsCount; i++) {
|
for (uint64_t i = 0; i < helper->editsConstructor.editsCount; i++) {
|
||||||
CMTimeRange timeRange = helper->editsConstructor.edits[i];
|
CMTimeRange timeRange = editsConstructor.edits[i];
|
||||||
CMTime duration = CMTimeConvertScale(timeRange.duration, timescale, kCMTimeRoundingMethod_Default);
|
CMTime duration = CMTimeConvertScale(timeRange.duration, timescale, kCMTimeRoundingMethod_Default);
|
||||||
MP4Timestamp startTime = timeRange.start.value == -1 ? -1 : timeRange.start.value - helper->minDisplayOffset;
|
int64_t offset = editsConstructor.minOffset < 0 ? editsConstructor.minOffset : 0;
|
||||||
|
int64_t offset2 = editsConstructor.minOffset > 0 && timeRange.start.value == 0 ? editsConstructor.minOffset : 0;
|
||||||
|
MP4Timestamp startTime = timeRange.start.value == -1 ? -1 : timeRange.start.value - offset + offset2;
|
||||||
|
|
||||||
MP4AddTrackEdit(fileHandle, trackId, MP4_INVALID_EDIT_ID,
|
MP4AddTrackEdit(fileHandle, trackId, MP4_INVALID_EDIT_ID,
|
||||||
startTime,
|
startTime,
|
||||||
|
|||||||
@@ -24,4 +24,6 @@
|
|||||||
@property (readonly, nonatomic) CMTimeRange *edits;
|
@property (readonly, nonatomic) CMTimeRange *edits;
|
||||||
@property (readonly, nonatomic) uint64_t editsCount;
|
@property (readonly, nonatomic) uint64_t editsCount;
|
||||||
|
|
||||||
|
@property (readonly, nonatomic) int64_t minOffset;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -34,6 +34,8 @@
|
|||||||
_priorityQueue = [[MP42Heap alloc] initWithCapacity:32 comparator:^NSComparisonResult(MP42SampleBuffer * obj1, MP42SampleBuffer * obj2) {
|
_priorityQueue = [[MP42Heap alloc] initWithCapacity:32 comparator:^NSComparisonResult(MP42SampleBuffer * obj1, MP42SampleBuffer * obj2) {
|
||||||
return obj2->presentationTimestamp - obj1->presentationTimestamp;
|
return obj2->presentationTimestamp - obj1->presentationTimestamp;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
_minOffset = INT64_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@@ -106,6 +108,10 @@
|
|||||||
_currentMediaTime = sample->presentationTimestamp;
|
_currentMediaTime = sample->presentationTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sample->offset < _minOffset) {
|
||||||
|
_minOffset = sample->offset;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef AVF_DEBUG
|
#ifdef AVF_DEBUG
|
||||||
NSLog(@"T: %llu, D: %lld, P: %lld, PO: %lld O: %lld", _currentMediaTime, sample->decodeTimestamp, sample->presentationTimestamp, sample->presentationOutputTimestamp, sample->offset);
|
NSLog(@"T: %llu, D: %lld, P: %lld, PO: %lld O: %lld", _currentMediaTime, sample->decodeTimestamp, sample->presentationTimestamp, sample->presentationOutputTimestamp, sample->offset);
|
||||||
NSLog(@"%d", sample->flags);
|
NSLog(@"%d", sample->flags);
|
||||||
|
|||||||
Reference in new issue
Block a user