Reworked the logger a bit.

This commit is contained in:
Damiano Galassi committed 2014-10-26 14:56:42 +01:00
1 parent 38ffcce146
commit 224958455a
6 files changed
+37 -10

No files matched your search

+2 -1
View File
@@ -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 <MP42Logging>)logger;
@property(nonatomic, readwrite, assign) id <MP42FileDelegate> delegate;
+5 -5
View File
@@ -23,7 +23,7 @@ NSString * const MP42GenerateChaptersPreviewTrack = @"MP42ChaptersPreview";
NSString * const MP42CustomChaptersPreviewTrack = @"MP42CustomChaptersPreview";
NSString * const MP42OrganizeAlternateGroups = @"MP42AlternateGroups";
void (^loggerBlock)(NSString *);
static id <MP42Logging> _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 () <MP42MuxerDelegate>
@@ -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<MP42Logging>)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];
+15
View File
@@ -0,0 +1,15 @@
//
// MP42Logger.h
// MP42Foundation
//
// Created by Damiano Galassi on 26/10/14.
// Copyright (c) 2014 Damiano Galassi. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol MP42Logging <NSObject>
- (void)writeToLog:(NSString *)string;
@end
+6 -3
View File
@@ -8,6 +8,7 @@
#import <Cocoa/Cocoa.h>
#import "mp4v2.h"
#import "MP42Logging.h"
@class MP42Track;
@@ -17,14 +18,16 @@
@interface MP42Muxer : NSObject {
@private
MP4FileHandle _fileHandle;
id _delegate;
MP4FileHandle _fileHandle;
id <MP42MuxerDelegate> _delegate;
id <MP42Logging> _logger;
NSMutableArray *_workingTracks;
int32_t _cancelled;
}
- (instancetype)initWithDelegate:(id <MP42MuxerDelegate>)del;
- (instancetype)initWithDelegate:(id <MP42MuxerDelegate>)del andLogger:(id <MP42Logging>)logger;
- (void)addTrack:(MP42Track *)track;
+3 -1
View File
@@ -27,11 +27,12 @@
return self;
}
- (instancetype)initWithDelegate:(id <MP42FileDelegate>)del
- (instancetype)initWithDelegate:(id <MP42MuxerDelegate>)del andLogger:(id <MP42Logging>)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];
}
+6
View File
@@ -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 = "<group>"; };
A91711E5187D547D00459495 /* MP42PreviewGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MP42PreviewGenerator.m; sourceTree = "<group>"; };
A917286519FD2BCE00348DF8 /* MP42Logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP42Logging.h; sourceTree = "<group>"; };
A925AAAD18379AF800BE84D4 /* MP42Utilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP42Utilities.h; sourceTree = "<group>"; };
A925AAAE18379AF800BE84D4 /* MP42Utilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MP42Utilities.m; sourceTree = "<group>"; };
A925AABB1837A16500BE84D4 /* QTKitDecrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QTKitDecrap.h; sourceTree = "<group>"; };
@@ -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 */,