PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/filesystems/procfs/sequencegrab/procfs_sequencegrab.mm

http://macfuse.googlecode.com/
Objective C++ | 61 lines | 46 code | 14 blank | 1 comment | 2 complexity | 22aec25fddd5bf6e76d6ef512b23345e MD5 | raw file
 1#import "procfs_sequencegrab.h"
 2#import "CocoaSequenceGrabber.h"
 3
 4static int loopCount = 0;
 5
 6@interface Snapshot : CSGCamera
 7{
 8    CFMutableDataRef tiff;
 9}
10
11- (void)setDataRef:(CFMutableDataRef)dataRef;
12- (void)camera:(CSGCamera *)aCamera didReceiveFrame:(CSGImage *)aFrame;
13
14@end
15
16@implementation Snapshot
17
18- (void)setDataRef:(CFMutableDataRef)dataRef
19{
20    tiff = dataRef;
21}
22
23- (void)camera:(CSGCamera *)aCamera didReceiveFrame:(CSGImage *)aFrame;
24{
25    if (++loopCount == CAMERA_TRIGGER_THRESHOLD) {
26        CFDataRef image = (CFDataRef)[aFrame TIFFRepresentationUsingCompression:NSTIFFCompressionNone factor:0.0];
27        CFIndex len = CFDataGetLength(image);
28        CFDataSetLength(tiff, len);
29        CFDataReplaceBytes(tiff, CFRangeMake((CFIndex)0, len), CFDataGetBytePtr(image), len);
30        //CFRelease(image);
31        [self stop];
32    }
33}
34
35@end
36
37off_t
38PROCFS_GetTIFFSizeFromCamera(void)
39{
40    return (off_t)((off_t)(640 * 480 * 4) + (off_t)8192);
41}
42
43int
44PROCFS_GetTIFFFromCamera(CFMutableDataRef *data)
45{
46    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
47
48    loopCount = 0;
49
50    Snapshot *camera = [[Snapshot alloc] init];
51    [camera setDataRef:*data];
52    [camera setDelegate:camera];
53    [camera startWithSize:NSMakeSize(640, 480)];
54    [[NSRunLoop currentRunLoop]
55        runUntilDate:[NSDate dateWithTimeIntervalSinceNow:CAMERA_ACTIVE_DURATION]];
56    [camera release];
57
58    [pool release];
59
60    return 0;
61}