/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. static int loopCount = 0;
  4. @interface Snapshot : CSGCamera
  5. {
  6. CFMutableDataRef tiff;
  7. }
  8. - (void)setDataRef:(CFMutableDataRef)dataRef;
  9. - (void)camera:(CSGCamera *)aCamera didReceiveFrame:(CSGImage *)aFrame;
  10. @end
  11. @implementation Snapshot
  12. - (void)setDataRef:(CFMutableDataRef)dataRef
  13. {
  14. tiff = dataRef;
  15. }
  16. - (void)camera:(CSGCamera *)aCamera didReceiveFrame:(CSGImage *)aFrame;
  17. {
  18. if (++loopCount == CAMERA_TRIGGER_THRESHOLD) {
  19. CFDataRef image = (CFDataRef)[aFrame TIFFRepresentationUsingCompression:NSTIFFCompressionNone factor:0.0];
  20. CFIndex len = CFDataGetLength(image);
  21. CFDataSetLength(tiff, len);
  22. CFDataReplaceBytes(tiff, CFRangeMake((CFIndex)0, len), CFDataGetBytePtr(image), len);
  23. //CFRelease(image);
  24. [self stop];
  25. }
  26. }
  27. @end
  28. off_t
  29. PROCFS_GetTIFFSizeFromCamera(void)
  30. {
  31. return (off_t)((off_t)(640 * 480 * 4) + (off_t)8192);
  32. }
  33. int
  34. PROCFS_GetTIFFFromCamera(CFMutableDataRef *data)
  35. {
  36. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  37. loopCount = 0;
  38. Snapshot *camera = [[Snapshot alloc] init];
  39. [camera setDataRef:*data];
  40. [camera setDelegate:camera];
  41. [camera startWithSize:NSMakeSize(640, 480)];
  42. [[NSRunLoop currentRunLoop]
  43. runUntilDate:[NSDate dateWithTimeIntervalSinceNow:CAMERA_ACTIVE_DURATION]];
  44. [camera release];
  45. [pool release];
  46. return 0;
  47. }