-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestAsyncParser.m
74 lines (58 loc) · 1.95 KB
/
TestAsyncParser.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
//
// TestAsyncParser.m
// OHMTagLib
//
// Created by Tobias Hieta on 2011-02-06.
// Copyright 2011 OHM Interactive. All rights reserved.
//
#import "TestAsyncParser.h"
#import "GTMLogger.h"
@implementation TestAsyncParser
-(void)setUp
{
tagLib = [OHMTagLib new];
testData = [NSData dataWithContentsOfFile:@"testdata/testm4a2.m4a"];
}
-(void)metadataRequest:(OHMTagLibMetadataRequest *)request jumpBytes:(int)bytes
{
request.position += bytes;
}
-(void)addDataToRequest:(NSTimer*)timer
{
GTMLoggerDebug(@"In addDataToRequest");
OHMTagLibMetadataRequest *req = [timer.userInfo objectForKey:@"request"];
int bytes = MAX([[timer.userInfo objectForKey:@"bytes"] intValue], 1024);
GTMLoggerDebug(@"adding %d bytes to the request", bytes);
[req.buffer addData:[testData subdataWithRange:NSMakeRange(req.position, bytes)]];
req.position += bytes;
}
-(void)metadataRequest:(OHMTagLibMetadataRequest *)request needMoreData:(int)bytes
{
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:request, @"request", [NSNumber numberWithInt:bytes], @"bytes", nil];
NSTimer *time = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(addDataToRequest:) userInfo:dict repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:time forMode:NSDefaultRunLoopMode];
}
-(void)metadataRequest:(OHMTagLibMetadataRequest *)request readError:(NSError *)error
{
}
-(void)metadataRequest:(OHMTagLibMetadataRequest *)request gotMetadata:(OHMTagLibMetadata *)metadata
{
done = YES;
}
-(void)testAsyncParser
{
OHMTagLibMetadataRequest *request = [OHMTagLibMetadataRequest new];
request.delegate = self;
[request.buffer addData:[testData subdataWithRange:NSMakeRange(0, 4096)]];
request.position = 4096;
[tagLib readMetadata:request];
done = NO;
while (!done) {
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
}
}
-(void)tearDown
{
[tagLib release];
}
@end