-
Notifications
You must be signed in to change notification settings - Fork 0
/
OHMTagLib.m
78 lines (67 loc) · 1.68 KB
/
OHMTagLib.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// OHMTagLib.m
// OHMTagLib
//
// Created by Tobias Hieta on 2010-12-13.
// Copyright 2010 OHM Interactive. All rights reserved.
//
#import "OHMTagLib.h"
#import "ID3v2.h"
#import "MP4.h"
#import "GTMLogger.h"
@implementation OHMTagLib
@synthesize delegate;
@synthesize useConcurrentSessions;
-(id) init
{
if ((self = [super init])) {
_readers = [[NSArray alloc] initWithObjects:[ID3v2 class], [MP4 class], nil];
_operationQueue = [NSOperationQueue new];
_operationQueue.name = @"readMetadataQueue";
self.useConcurrentSessions = YES;
GTMLoggerDebug(@"OHMTagLib init!");
}
return self;
}
-(Class)getReaderForData:(NSData*)data
{
for (Class reader in _readers) {
GTMLoggerDebug(@"Trying reader %@", [reader name]);
if ([reader isMine:data]) {
return reader;
}
}
return nil;
}
-(BOOL)canHandleData:(NSData*)data
{
Class reader = [self getReaderForData:data];
return reader != nil;
}
-(void)readMetadata:(OHMTagLibMetadataRequest*)request
{
/* "borrow" 10 bytes of data and see if they match any reader plugin */
NSData *data = [request.buffer peekDataFromCurrentPosition:10 error:nil];
if ([data length] != 10) {
GTMLoggerDebug(@"didn't get 10 bytes from peek!");
return;
}
Class reader = [self getReaderForData:data];
if (!reader) {
GTMLoggerDebug(@"No reader, big big problem");
return;
}
request.reader = [reader new];
if (self.useConcurrentSessions) {
[_operationQueue addOperationWithBlock:^{
[request readMetadata];
}];
} else {
[request readMetadata];
}
}
-(void)dealloc
{
[super dealloc];
}
@end