Various fixes.

This commit is contained in:
Damiano Galassi committed 2014-03-27 09:58:34 +01:00
1 parent 6bc342118d
commit 618b52140c
2 files changed
+55 -28

No files matched your search

+54 -27
View File
@@ -27,7 +27,6 @@
uint64_t editsSize; uint64_t editsSize;
BOOL editOpen; BOOL editOpen;
int64_t currentTime; int64_t currentTime;
int64_t currentEditTime;
AVAssetReaderOutput *assetReaderOutput; AVAssetReaderOutput *assetReaderOutput;
} }
@end @end
@@ -217,6 +216,7 @@
[(MP42VideoTrack*)newTrack setWidth: dimensions.width]; [(MP42VideoTrack*)newTrack setWidth: dimensions.width];
[(MP42VideoTrack*)newTrack setHeight: dimensions.height]; [(MP42VideoTrack*)newTrack setHeight: dimensions.height];
// Reads the pixel aspect ratio information
CFDictionaryRef pixelAspectRatioFromCMFormatDescription = CMFormatDescriptionGetExtension(formatDescription, kCMFormatDescriptionExtension_PixelAspectRatio); CFDictionaryRef pixelAspectRatioFromCMFormatDescription = CMFormatDescriptionGetExtension(formatDescription, kCMFormatDescriptionExtension_PixelAspectRatio);
if (pixelAspectRatioFromCMFormatDescription) { if (pixelAspectRatioFromCMFormatDescription) {
NSInteger hSpacing, vSpacing; NSInteger hSpacing, vSpacing;
@@ -225,9 +225,31 @@
[(MP42VideoTrack*)newTrack setHSpacing:hSpacing]; [(MP42VideoTrack*)newTrack setHSpacing:hSpacing];
[(MP42VideoTrack*)newTrack setVSpacing:vSpacing]; [(MP42VideoTrack*)newTrack setVSpacing:vSpacing];
} }
// Reads the clean aperture information
CFDictionaryRef cleanApertureFromCMFormatDescription = CMFormatDescriptionGetExtension(formatDescription, kCMFormatDescriptionExtension_CleanAperture);
if (cleanApertureFromCMFormatDescription) {
double cleanApertureWidth, cleanApertureHeight;
double cleanApertureHorizontalOffset, cleanApertureVerticalOffset;
CFNumberGetValue(CFDictionaryGetValue(cleanApertureFromCMFormatDescription, kCMFormatDescriptionKey_CleanApertureWidth),
kCFNumberDoubleType, &cleanApertureWidth);
CFNumberGetValue(CFDictionaryGetValue(cleanApertureFromCMFormatDescription, kCMFormatDescriptionKey_CleanApertureHeight),
kCFNumberDoubleType, &cleanApertureHeight);
CFNumberGetValue(CFDictionaryGetValue(cleanApertureFromCMFormatDescription, kCMFormatDescriptionKey_CleanApertureHorizontalOffset),
kCFNumberDoubleType, &cleanApertureHorizontalOffset);
CFNumberGetValue(CFDictionaryGetValue(cleanApertureFromCMFormatDescription, kCMFormatDescriptionKey_CleanApertureVerticalOffset),
kCFNumberDoubleType, &cleanApertureVerticalOffset);
[(MP42VideoTrack*)newTrack setCleanApertureWidthN:cleanApertureWidth];
[(MP42VideoTrack*)newTrack setCleanApertureWidthD:1];
[(MP42VideoTrack*)newTrack setCleanApertureHeightN:cleanApertureHeight];
[(MP42VideoTrack*)newTrack setCleanApertureHeightD:1];
[(MP42VideoTrack*)newTrack setHorizOffN:cleanApertureHorizontalOffset];
[(MP42VideoTrack*)newTrack setHorizOffD:1];
[(MP42VideoTrack*)newTrack setVertOffN:cleanApertureVerticalOffset];
[(MP42VideoTrack*)newTrack setVertOffD:1];
} }
} }
else if ([[track mediaType] isEqualToString:AVMediaTypeAudio]) { } else if ([[track mediaType] isEqualToString:AVMediaTypeAudio]) {
newTrack = [[MP42AudioTrack alloc] init]; newTrack = [[MP42AudioTrack alloc] init];
if (formatDescription) { if (formatDescription) {
@@ -237,22 +259,19 @@
if (layoutSize) { if (layoutSize) {
[(MP42AudioTrack*)newTrack setChannels:AudioChannelLayoutTag_GetNumberOfChannels(layout->mChannelLayoutTag)]; [(MP42AudioTrack*)newTrack setChannels:AudioChannelLayoutTag_GetNumberOfChannels(layout->mChannelLayoutTag)];
[(MP42AudioTrack*)newTrack setChannelLayoutTag:layout->mChannelLayoutTag]; [(MP42AudioTrack*)newTrack setChannelLayoutTag:layout->mChannelLayoutTag];
} } else {
else
[(MP42AudioTrack*)newTrack setChannels:1]; [(MP42AudioTrack*)newTrack setChannels:1];
} }
} }
else if ([[track mediaType] isEqualToString:AVMediaTypeSubtitle]) { } else if ([[track mediaType] isEqualToString:AVMediaTypeSubtitle]) {
newTrack = [[MP42SubtitleTrack alloc] init]; newTrack = [[MP42SubtitleTrack alloc] init];
} } else if ([[track mediaType] isEqualToString:AVMediaTypeText]) {
else if ([[track mediaType] isEqualToString:AVMediaTypeText]) {
// It looks like there is no way to know what text track is used for chapters in the original file. // It looks like there is no way to know what text track is used for chapters in the original file.
if (chapters) if (chapters)
newTrack = chapters; newTrack = chapters;
else else
newTrack = [[MP42ChapterTrack alloc] init]; newTrack = [[MP42ChapterTrack alloc] init];
} } else {
else {
newTrack = [[MP42Track alloc] init]; newTrack = [[MP42Track alloc] init];
} }
@@ -264,12 +283,13 @@
// "name" is undefined in AVMetadataFormat.h, so read the official track name "tnam", and then "name". On 10.7, "name" is returned as an NSData // "name" is undefined in AVMetadataFormat.h, so read the official track name "tnam", and then "name". On 10.7, "name" is returned as an NSData
id trackName = [[[AVMetadataItem metadataItemsFromArray:trackMetadata withKey:AVMetadataQuickTimeUserDataKeyTrackName keySpace:nil] lastObject] value]; id trackName = [[[AVMetadataItem metadataItemsFromArray:trackMetadata withKey:AVMetadataQuickTimeUserDataKeyTrackName keySpace:nil] lastObject] value];
id trackName_oldFormat = [[[AVMetadataItem metadataItemsFromArray:trackMetadata withKey:@"name" keySpace:nil] lastObject] value]; id trackName_oldFormat = [[[AVMetadataItem metadataItemsFromArray:trackMetadata withKey:@"name" keySpace:nil] lastObject] value];
if (trackName && [trackName isKindOfClass:[NSString class]]) if (trackName && [trackName isKindOfClass:[NSString class]]) {
newTrack.name = trackName; newTrack.name = trackName;
else if (trackName_oldFormat && [trackName_oldFormat isKindOfClass:[NSString class]]) } else if (trackName_oldFormat && [trackName_oldFormat isKindOfClass:[NSString class]]) {
newTrack.name = trackName_oldFormat; newTrack.name = trackName_oldFormat;
else if (trackName_oldFormat && [trackName_oldFormat isKindOfClass:[NSData class]]) } else if (trackName_oldFormat && [trackName_oldFormat isKindOfClass:[NSData class]]) {
newTrack.name = [NSString stringWithCString:[trackName_oldFormat bytes] encoding:NSMacOSRomanStringEncoding]; newTrack.name = [NSString stringWithCString:[trackName_oldFormat bytes] encoding:NSMacOSRomanStringEncoding];
}
newTrack.language = [self langForTrack:track]; newTrack.language = [self langForTrack:track];
@@ -417,7 +437,7 @@
} }
} }
items = [AVMetadataItem metadataItemsFromArray:itunesMetadata withKey:AVMetadataiTunesMetadataKeyCoverArt keySpace:AVMetadataKeySpaceiTunes]; /*items = [AVMetadataItem metadataItemsFromArray:itunesMetadata withKey:AVMetadataiTunesMetadataKeyCoverArt keySpace:AVMetadataKeySpaceiTunes];
if ([items count]) { if ([items count]) {
id artworkData = [[items lastObject] value]; id artworkData = [[items lastObject] value];
if ([artworkData isKindOfClass:[NSData class]]) { if ([artworkData isKindOfClass:[NSData class]]) {
@@ -425,7 +445,7 @@
[_metadata.artworks addObject:[[[MP42Image alloc] initWithImage:image] autorelease]]; [_metadata.artworks addObject:[[[MP42Image alloc] initWithImage:image] autorelease]];
[image release]; [image release];
} }
} }*/
} }
if ([availableMetadataFormats containsObject:AVMetadataFormatQuickTimeMetadata]) { if ([availableMetadataFormats containsObject:AVMetadataFormatQuickTimeMetadata]) {
NSArray* quicktimeMetadata = [_localAsset metadataForFormat:AVMetadataFormatQuickTimeMetadata]; NSArray* quicktimeMetadata = [_localAsset metadataForFormat:AVMetadataFormatQuickTimeMetadata];
@@ -636,6 +656,9 @@
return nil; return nil;
} }
/**
* Starts a new edit
*/
- (void)startEditListAtTime:(CMTime)time helper:(AVFDemuxHelper *)helper { - (void)startEditListAtTime:(CMTime)time helper:(AVFDemuxHelper *)helper {
if (helper->editsSize <= helper->editsCount) { if (helper->editsSize <= helper->editsCount) {
helper->editsSize += 20; helper->editsSize += 20;
@@ -645,6 +668,9 @@
helper->editOpen = YES; helper->editOpen = YES;
} }
/**
* Closes a opened edit
*/
- (void)endEditListAtTime:(CMTime)time empty:(BOOL)type helper:(AVFDemuxHelper *)helper { - (void)endEditListAtTime:(CMTime)time empty:(BOOL)type helper:(AVFDemuxHelper *)helper {
if (!helper->editOpen) if (!helper->editOpen)
return; return;
@@ -657,7 +683,6 @@
} }
helper->editsCount++; helper->editsCount++;
helper->currentEditTime = 0;
helper->editOpen = NO; helper->editOpen = NO;
} }
@@ -740,12 +765,15 @@
CMTime time = CMTimeConvertScale(presentationOutputTimeStamp, duration.timescale, kCMTimeRoundingMethod_Default); CMTime time = CMTimeConvertScale(presentationOutputTimeStamp, duration.timescale, kCMTimeRoundingMethod_Default);
[self endEditListAtTime:time empty:YES helper:demuxHelper]; [self endEditListAtTime:time empty:YES helper:demuxHelper];
[self startEditListAtTime:time helper:demuxHelper]; [self startEditListAtTime:time helper:demuxHelper];
demuxHelper->currentTime += time.value;
} }
#ifdef SB_AVF_DEBUG #ifdef SB_AVF_DEBUG
NSLog(@"Dur: %lld, D: %lld, P: %lld, PO: %lld", duration.value, decodeTimeStamp.value, presentationTimeStamp.value, presentationOutputTimeStamp.value); NSLog(@"Dur: %lld, D: %lld, P: %lld, PO: %lld", duration.value, decodeTimeStamp.value, presentationTimeStamp.value, presentationOutputTimeStamp.value);
#endif #endif
// Check if we have to trim the start or end of a sample
// If so it means we need to start/end an edit
CFTypeRef trimStart = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_TrimDurationAtStart, kCMAttachmentMode_ShouldNotPropagate); CFTypeRef trimStart = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_TrimDurationAtStart, kCMAttachmentMode_ShouldNotPropagate);
if (trimStart) { if (trimStart) {
CMTime trimStartTime = CMTimeMakeFromDictionary(trimStart); CMTime trimStartTime = CMTimeMakeFromDictionary(trimStart);
@@ -767,6 +795,7 @@
[self endEditListAtTime:editEnd empty:NO helper:demuxHelper]; [self endEditListAtTime:editEnd empty:NO helper:demuxHelper];
} }
// Enqueues the new sample
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init]; MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
sample->data = sampleData; sample->data = sampleData;
sample->size = sampleSize; sample->size = sampleSize;
@@ -780,9 +809,9 @@
[sample release]; [sample release];
demuxHelper->currentTime += duration.value; demuxHelper->currentTime += duration.value;
demuxHelper->currentEditTime += duration.value;
currentDataLength += sampleSize; currentDataLength += sampleSize;
} else { } else {
// The CMSampleBufferRef contains more than one sample
if (!CMSampleBufferDataIsReady(sampleBuffer)) if (!CMSampleBufferDataIsReady(sampleBuffer))
CMSampleBufferMakeDataReady(sampleBuffer); CMSampleBufferMakeDataReady(sampleBuffer);
@@ -820,6 +849,8 @@
#ifdef SB_AVF_DEBUG #ifdef SB_AVF_DEBUG
#endif #endif
// Check if we have to trim the start or end of a sample
// If so it means we need to start/end an edit
CFTypeRef trimStart = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_TrimDurationAtStart, kCMAttachmentMode_ShouldNotPropagate); CFTypeRef trimStart = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_TrimDurationAtStart, kCMAttachmentMode_ShouldNotPropagate);
if (trimStart) { if (trimStart) {
CMTime trimStartTime = CMTimeMakeFromDictionary(trimStart); CMTime trimStartTime = CMTimeMakeFromDictionary(trimStart);
@@ -849,8 +880,8 @@
int pos = 0; int pos = 0;
for (int i = 0; i < samplesNum; i++) { for (int i = 0; i < samplesNum; i++) {
CMSampleTimingInfo sampleTimingInfo; CMSampleTimingInfo sampleTimingInfo;
CMTime decodeTimeStamp = {0,0,0,0}; CMTime decodeTimeStamp;
CMTime presentationTimeStamp = {0,0,0,0}; CMTime presentationTimeStamp;
CMTime presentationOutputTimeStamp = CMSampleBufferGetOutputPresentationTimeStamp(sampleBuffer); CMTime presentationOutputTimeStamp = CMSampleBufferGetOutputPresentationTimeStamp(sampleBuffer);
size_t sampleSize; size_t sampleSize;
@@ -889,6 +920,7 @@
pos += sampleSize; pos += sampleSize;
} }
// Read sample attachment, sync to mark the frame as sync
BOOL sync = 1; BOOL sync = 1;
CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, NO); CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, NO);
if (attachmentsArray) { if (attachmentsArray) {
@@ -902,11 +934,12 @@
NSLog(@"D: %lld, P: %lld, PO: %lld", decodeTimeStamp.value, presentationTimeStamp.value, presentationOutputTimeStamp.value); NSLog(@"D: %lld, P: %lld, PO: %lld", decodeTimeStamp.value, presentationTimeStamp.value, presentationOutputTimeStamp.value);
#endif #endif
// Enqueues the new sample
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init]; MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
sample->data = sampleData; sample->data = sampleData;
sample->size = sampleSize; sample->size = sampleSize;
sample->duration = sampleTimingInfo.duration.value; sample->duration = sampleTimingInfo.duration.value;
sample->offset = 0; //-sampleTimingInfo.decodeTimeStamp.value + sampleTimingInfo.presentationTimeStamp.value; sample->offset = -decodeTimeStamp.value + presentationTimeStamp.value;
sample->timestamp = sampleTimingInfo.presentationTimeStamp.value; sample->timestamp = sampleTimingInfo.presentationTimeStamp.value;
sample->isSync = sync; sample->isSync = sync;
sample->trackId = track.sourceId; sample->trackId = track.sourceId;
@@ -915,7 +948,6 @@
[sample release]; [sample release];
demuxHelper->currentTime += sampleTimingInfo.duration.value; demuxHelper->currentTime += sampleTimingInfo.duration.value;
demuxHelper->currentEditTime += sampleTimingInfo.duration.value;
currentDataLength += sampleSize; currentDataLength += sampleSize;
} }
@@ -929,16 +961,11 @@
_progress = (((CGFloat) currentDataLength / totalDataLength ) * 100); _progress = (((CGFloat) currentDataLength / totalDataLength ) * 100);
} else { } else {
AVAssetReaderStatus status = assetReader.status;
if (status == AVAssetReaderStatusCompleted) {
NSLog(@"AVAssetReader: done");
}
break; break;
} }
} }
[self endEditListAtTime:CMTimeMake(demuxHelper->currentEditTime, timescale) empty:NO helper:demuxHelper]; // Closes the last edit
[self endEditListAtTime:CMTimeMake(demuxHelper->currentTime, timescale) empty:NO helper:demuxHelper];
} }
[assetReader release]; [assetReader release];
+1 -1
View File
@@ -225,7 +225,7 @@ static void logCallback(MP4LogLevel loglevel, const char* fmt, va_list ap)
if ([track.format isEqualToString:MP42VideoFormatJPEG]) if ([track.format isEqualToString:MP42VideoFormatJPEG])
previewsId = track.Id; previewsId = track.Id;
//[self loadPreviewsFromTrackID:previewsId]; [self loadPreviewsFromTrackID:previewsId];
_tracksToBeDeleted = [[NSMutableArray alloc] init]; _tracksToBeDeleted = [[NSMutableArray alloc] init];
_metadata = [[MP42Metadata alloc] initWithSourceURL:_fileURL fileHandle:_fileHandle]; _metadata = [[MP42Metadata alloc] initWithSourceURL:_fileURL fileHandle:_fileHandle];