diff --git a/MP42/MP42File.h b/MP42/MP42File.h index 6b91318..72306d6 100644 --- a/MP42/MP42File.h +++ b/MP42/MP42File.h @@ -17,6 +17,7 @@ #import "MP42Metadata.h" #import "MP42MediaFormat.h" +#import "MP42Logging.h" extern NSString * const MP4264BitData; extern NSString * const MP4264BitTime; @@ -67,7 +68,7 @@ typedef enum MP42Status : NSInteger { } -+ (void)redirectLogUsingBlock:(void (^)(NSString *text))block; ++ (void)setGlobalLogger:(id )logger; @property(nonatomic, readwrite, assign) id delegate; diff --git a/MP42/MP42File.m b/MP42/MP42File.m index 6c89f04..4b2740b 100644 --- a/MP42/MP42File.m +++ b/MP42/MP42File.m @@ -23,7 +23,7 @@ NSString * const MP42GenerateChaptersPreviewTrack = @"MP42ChaptersPreview"; NSString * const MP42CustomChaptersPreviewTrack = @"MP42CustomChaptersPreview"; NSString * const MP42OrganizeAlternateGroups = @"MP42AlternateGroups"; -void (^loggerBlock)(NSString *); +static id _logger = nil; static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { const char *level; @@ -61,7 +61,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { vsnprintf(buffer, 2048, fmt, ap); NSString *output = [NSString stringWithFormat:@"%s: %s\n", level, buffer]; - loggerBlock(output); + [_logger writeToLog:output]; } @interface MP42File () @@ -103,9 +103,9 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { MP4LogSetLevel(MP4_LOG_INFO); } -+ (void)redirectLogUsingBlock:(void (^)(NSString *text))block ++ (void)setGlobalLogger:(id)logger { - loggerBlock = Block_copy(block); + _logger = [logger retain]; } - (BOOL)startReading { @@ -767,7 +767,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { } if ([tracksToMux count]) { - self.muxer = [[[MP42Muxer alloc] initWithDelegate:self] autorelease]; + self.muxer = [[[MP42Muxer alloc] initWithDelegate:self andLogger:_logger] autorelease]; for (MP42Track *track in tracksToMux) { [self.muxer addTrack:track]; diff --git a/MP42/MP42Logging.h b/MP42/MP42Logging.h new file mode 100644 index 0000000..adf4404 --- /dev/null +++ b/MP42/MP42Logging.h @@ -0,0 +1,15 @@ +// +// MP42Logger.h +// MP42Foundation +// +// Created by Damiano Galassi on 26/10/14. +// Copyright (c) 2014 Damiano Galassi. All rights reserved. +// + +#import + +@protocol MP42Logging + +- (void)writeToLog:(NSString *)string; + +@end diff --git a/MP42/MP42Muxer.h b/MP42/MP42Muxer.h index b5a9296..5f894e6 100644 --- a/MP42/MP42Muxer.h +++ b/MP42/MP42Muxer.h @@ -8,6 +8,7 @@ #import #import "mp4v2.h" +#import "MP42Logging.h" @class MP42Track; @@ -17,14 +18,16 @@ @interface MP42Muxer : NSObject { @private - MP4FileHandle _fileHandle; - id _delegate; + MP4FileHandle _fileHandle; + + id _delegate; + id _logger; NSMutableArray *_workingTracks; int32_t _cancelled; } -- (instancetype)initWithDelegate:(id )del; +- (instancetype)initWithDelegate:(id )del andLogger:(id )logger; - (void)addTrack:(MP42Track *)track; diff --git a/MP42/MP42Muxer.m b/MP42/MP42Muxer.m index c6b5132..5ecf089 100644 --- a/MP42/MP42Muxer.m +++ b/MP42/MP42Muxer.m @@ -27,11 +27,12 @@ return self; } -- (instancetype)initWithDelegate:(id )del +- (instancetype)initWithDelegate:(id )del andLogger:(id )logger { if ((self = [super init])) { _workingTracks = [[NSMutableArray alloc] init]; _delegate = del; + _logger = [logger retain]; } return self; @@ -448,6 +449,7 @@ - (void)dealloc { + [_logger release]; [_workingTracks release]; [super dealloc]; } diff --git a/MP42Foundation.xcodeproj/project.pbxproj b/MP42Foundation.xcodeproj/project.pbxproj index ba93a91..d1ccd9a 100644 --- a/MP42Foundation.xcodeproj/project.pbxproj +++ b/MP42Foundation.xcodeproj/project.pbxproj @@ -68,6 +68,8 @@ A91711E6187D547D00459495 /* MP42PreviewGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = A91711E4187D547D00459495 /* MP42PreviewGenerator.h */; }; A91711E8187D547D00459495 /* MP42PreviewGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = A91711E5187D547D00459495 /* MP42PreviewGenerator.m */; }; A91711E9187D547D00459495 /* MP42PreviewGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = A91711E5187D547D00459495 /* MP42PreviewGenerator.m */; }; + A917286619FD2BCE00348DF8 /* MP42Logging.h in Headers */ = {isa = PBXBuildFile; fileRef = A917286519FD2BCE00348DF8 /* MP42Logging.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A917286719FD2BCE00348DF8 /* MP42Logging.h in Headers */ = {isa = PBXBuildFile; fileRef = A917286519FD2BCE00348DF8 /* MP42Logging.h */; }; A925AAAF18379AF800BE84D4 /* MP42Utilities.h in Headers */ = {isa = PBXBuildFile; fileRef = A925AAAD18379AF800BE84D4 /* MP42Utilities.h */; settings = {ATTRIBUTES = (Public, ); }; }; A925AAB018379AF800BE84D4 /* MP42Utilities.m in Sources */ = {isa = PBXBuildFile; fileRef = A925AAAE18379AF800BE84D4 /* MP42Utilities.m */; }; A925AABC1837A16500BE84D4 /* QTKitDecrap.h in Headers */ = {isa = PBXBuildFile; fileRef = A925AABB1837A16500BE84D4 /* QTKitDecrap.h */; }; @@ -265,6 +267,7 @@ A910B5A318394E900064028F /* libmp42.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libmp42.a; sourceTree = BUILT_PRODUCTS_DIR; }; A91711E4187D547D00459495 /* MP42PreviewGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP42PreviewGenerator.h; sourceTree = ""; }; A91711E5187D547D00459495 /* MP42PreviewGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MP42PreviewGenerator.m; sourceTree = ""; }; + A917286519FD2BCE00348DF8 /* MP42Logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP42Logging.h; sourceTree = ""; }; A925AAAD18379AF800BE84D4 /* MP42Utilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP42Utilities.h; sourceTree = ""; }; A925AAAE18379AF800BE84D4 /* MP42Utilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MP42Utilities.m; sourceTree = ""; }; A925AABB1837A16500BE84D4 /* QTKitDecrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QTKitDecrap.h; sourceTree = ""; }; @@ -545,6 +548,7 @@ A9B9C23D1823923100416A4E /* MP42Metadata.m */, A9B9C23A1823923100416A4E /* MP42MediaFormat.h */, A9B9C23B1823923100416A4E /* MP42MediaFormat.m */, + A917286519FD2BCE00348DF8 /* MP42Logging.h */, A9B9C4A418239B7E00416A4E /* Utility */, A9B9C4A218239B6F00416A4E /* Muxer */, A9B9C1F7182391DF00416A4E /* Supporting Files */, @@ -720,6 +724,7 @@ buildActionMask = 2147483647; files = ( A9A0C9B21981593900A72763 /* MP42ComponentLoader.h in Headers */, + A917286719FD2BCE00348DF8 /* MP42Logging.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -727,6 +732,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + A917286619FD2BCE00348DF8 /* MP42Logging.h in Headers */, A9B9C27B1823923200416A4E /* MP42File.h in Headers */, A9DFBDCB1960174500410060 /* MP42EditListsReconstructor.h in Headers */, A9B9C29B1823923200416A4E /* MP42Track.h in Headers */,