Reworked the logger a bit.
This commit is contained in:
1 parent
38ffcce146
commit
224958455a
6 files changed
+37
-10
No files matched your search
+2
-1
@@ -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
@@ -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];
|
||||
|
||||
@@ -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
@@ -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
@@ -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];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user