diff --git a/MP42/MP42File.h b/MP42/MP42File.h index 35d4234..298ed43 100644 --- a/MP42/MP42File.h +++ b/MP42/MP42File.h @@ -61,7 +61,6 @@ typedef void (^MP42FileProgressHandler)(double progress); NSMutableDictionary *_importers; BOOL _hasFileRepresentation; - } + (void)setGlobalLogger:(id )logger; @@ -201,22 +200,22 @@ typedef void (^MP42FileProgressHandler)(double progress); * Exports a MP42File object. * * @param url An NSURL object that specifies a url to a file. - * @param attributes An NSDictionary object that specifies the desired operation and its options, + * @param options An NSDictionary object that specifies the desired operation and its options, * @param outError A pointer to an NSError object; if the operation fails, an NSError object is returned in this location. * * @return YES if the movie file was successfully created, NO otherwise. */ -- (BOOL)writeToUrl:(NSURL *)url withAttributes:(NSDictionary *)attributes error:(NSError **)outError; +- (BOOL)writeToUrl:(NSURL *)url options:(nullable NSDictionary *)options error:(NSError **)outError; /** * Updates a MP42File object. * - * @param attributes An NSDictionary object that specifies the desired operation and its options. + * @param options An NSDictionary object that specifies the desired operation and its options. * @param outError A pointer to an NSError object; if the operation fails, an NSError object is returned in this location. * * @return YES if the movie file was successfully created, NO otherwise. */ -- (BOOL)updateMP4FileWithAttributes:(NSDictionary *)attributes error:(NSError **)outError; +- (BOOL)updateMP4FileWithOptions:(nullable NSDictionary *)options error:(NSError **)outError; /** * Cancels a write/update operation. diff --git a/MP42/MP42File.m b/MP42/MP42File.m index 3cd68b1..e28c7e3 100644 --- a/MP42/MP42File.m +++ b/MP42/MP42File.m @@ -457,8 +457,9 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { id track = [[self.itracks objectAtIndex:index] retain]; [self.itracks removeObjectAtIndex:index]; - if (newIndex > [self.itracks count] || newIndex > index) + if (newIndex > [self.itracks count] || newIndex > index) { newIndex--; + } [self.itracks insertObject:track atIndex:newIndex]; [track release]; } @@ -605,7 +606,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { } } -- (BOOL)writeToUrl:(NSURL *)url withAttributes:(NSDictionary *)attributes error:(NSError **)outError { +- (BOOL)writeToUrl:(NSURL *)url options:(nullable NSDictionary *)options error:(NSError **)outError { BOOL success = YES; if (!url) { @@ -616,7 +617,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { return NO; } - if ([self hasFileRepresentation]) { + if (self.hasFileRepresentation) { __block BOOL noErr = YES; if (![self.URL isEqualTo:url]) { @@ -642,7 +643,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { if (noErr) { self.URL = url; - success = [self updateMP4FileWithAttributes:attributes error:outError]; + success = [self updateMP4FileWithOptions:options error:outError]; } else { success = NO; [*outError autorelease]; @@ -650,16 +651,16 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { } else { self.URL = url; - NSString *fileExtension = [self.URL pathExtension]; + NSString *fileExtension = self.URL.pathExtension; char *majorBrand = "mp42"; char *supportedBrands[4]; uint32_t supportedBrandsCount = 0; uint32_t flags = 0; - if ([[attributes valueForKey:MP4264BitData] boolValue]) + if ([options[MP4264BitData] boolValue]) flags += 0x01; - if ([[attributes valueForKey:MP4264BitTime] boolValue]) + if ([options[MP4264BitTime] boolValue]) flags += 0x02; if ([fileExtension isEqualToString:MP42FileTypeM4V]) { @@ -683,7 +684,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { supportedBrandsCount = 2; } - self.fileHandle = MP4CreateEx([[self.URL path] fileSystemRepresentation], + self.fileHandle = MP4CreateEx(self.URL.path.fileSystemRepresentation, flags, 1, 1, majorBrand, 0, supportedBrands, supportedBrandsCount); @@ -691,7 +692,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { MP4SetTimeScale(self.fileHandle, 600); [self stopWriting]; - success = [self updateMP4FileWithAttributes:attributes error:outError]; + success = [self updateMP4FileWithOptions:options error:outError]; } else { success = NO; if (outError) { @@ -704,9 +705,9 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { return success; } -- (BOOL)updateMP4FileWithAttributes:(NSDictionary *)attributes error:(NSError **)outError { +- (BOOL)updateMP4FileWithOptions:(nullable NSDictionary *)options error:(NSError **)outError { // Organize the alternate groups - if ([[attributes valueForKey:MP42OrganizeAlternateGroups] boolValue]) { + if ([options[MP42OrganizeAlternateGroups] boolValue]) { [self organizeAlternateGroups]; } @@ -820,9 +821,9 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { } // Generate previews images for chapters - if ([attributes[MP42GenerateChaptersPreviewTrack] boolValue] && [self.itracks count]) { + if ([options[MP42GenerateChaptersPreviewTrack] boolValue] && self.itracks.count) { [self createChaptersPreview]; - } else if ([attributes[MP42CustomChaptersPreviewTrack] boolValue] && [self.itracks count]) { + } else if ([options[MP42CustomChaptersPreviewTrack] boolValue] && self.itracks.count) { [self customChaptersPreview]; } diff --git a/MP42/MP42FileImporter.m b/MP42/MP42FileImporter.m index a4be694..8345b4a 100644 --- a/MP42/MP42FileImporter.m +++ b/MP42/MP42FileImporter.m @@ -70,9 +70,9 @@ self = [MP42VobSubImporter alloc]; } #if !__LP64__ - else if ([pathExtension caseInsensitiveCompare: @"mov"] == NSOrderedSame) { + /*else if ([pathExtension caseInsensitiveCompare: @"mov"] == NSOrderedSame) { self = [MP42QTImporter alloc]; - } + }*/ #endif else if ([pathExtension caseInsensitiveCompare: @"m2ts"] == NSOrderedSame || [pathExtension caseInsensitiveCompare: @"ts"] == NSOrderedSame || diff --git a/MP42/MP42Track.m b/MP42/MP42Track.m index 50fab3c..f323698 100644 --- a/MP42/MP42Track.m +++ b/MP42/MP42Track.m @@ -152,6 +152,7 @@ - (BOOL)writeToFile:(MP4FileHandle)fileHandle error:(NSError **)outError { BOOL success = YES; + if (!fileHandle || !_Id) { if ( outError != NULL) { *outError = MP42Error(@"Failed to modify track", @@ -162,7 +163,7 @@ } } - if ([_updatedProperty valueForKey:@"name"] || !_muxed) { + if (_updatedProperty[@"name"] || !_muxed) { if (![_name isEqualToString:@"Video Track"] && ![_name isEqualToString:@"Sound Track"] && ![_name isEqualToString:@"Subtitle Track"] && @@ -172,7 +173,7 @@ ![_name isEqualToString:@"Unknown Track"] && _name != nil) { - const char *cString = [_name cStringUsingEncoding: NSMacOSRomanStringEncoding]; + const char *cString = [_name cStringUsingEncoding:NSMacOSRomanStringEncoding]; if (cString) { MP4SetTrackName(fileHandle, _Id, cString); @@ -183,20 +184,29 @@ MP4SetTrackName(fileHandle, _Id, "\0"); } } - if ([_updatedProperty valueForKey:@"alternate_group"] || !_muxed) + + if (_updatedProperty[@"alternate_group"] || !_muxed) { MP4SetTrackIntegerProperty(fileHandle, _Id, "tkhd.alternate_group", _alternate_group); - if ([_updatedProperty valueForKey:@"start_offset"]) - setTrackStartOffset(fileHandle, _Id, _startOffset); - if ([_updatedProperty valueForKey:@"language"] || !_muxed) - MP4SetTrackLanguage(fileHandle, _Id, lang_for_english([_language UTF8String])->iso639_2); - if ([_updatedProperty valueForKey:@"extendedLanguageTag"] || !_muxed) - MP4SetTrackStringProperty(fileHandle, _Id, "mdia.elng", [_extendedLanguageTag cStringUsingEncoding:NSASCIIStringEncoding]); - if ([_updatedProperty valueForKey:@"enabled"] || !_muxed) { - if (_enabled) MP4SetTrackEnabled(fileHandle, _Id); - else MP4SetTrackDisabled(fileHandle, _Id); } - if (_updatedProperty[@"mediaCharacteristicTags"]) { + if (_updatedProperty[@"start_offset"]) { + setTrackStartOffset(fileHandle, _Id, _startOffset); + } + + if (_updatedProperty[@"language"] || !_muxed) { + MP4SetTrackLanguage(fileHandle, _Id, lang_for_english([_language UTF8String])->iso639_2); + } + + if (_updatedProperty[@"extendedLanguageTag"] || !_muxed) { + MP4SetTrackStringProperty(fileHandle, _Id, "mdia.elng", [_extendedLanguageTag cStringUsingEncoding:NSASCIIStringEncoding]); + } + + if (_updatedProperty[@"enabled"] || !_muxed) { + if (_enabled) { MP4SetTrackEnabled(fileHandle, _Id); } + else { MP4SetTrackDisabled(fileHandle, _Id); } + } + + if (_updatedProperty[@"mediaCharacteristicTags"] || !_muxed) { MP4RemoveAllMediaCharacteristicTags(fileHandle, _Id); for (NSString *tag in _mediaCharacteristicTags) {