home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 114 / macaddict114.cdr / Software / Utilities / macam.0.8.4.dmg / macam sources / driver_core / MyDummyCameraDriver.m < prev   
Encoding:
Text File  |  2005-08-16  |  3.2 KB  |  94 lines

  1. /*
  2.     macam - webcam app and QuickTime driver component
  3.     Copyright (C) 2002 Matthias Krauss (macam@matthias-krauss.de)
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  $Id: MyDummyCameraDriver.m,v 1.3 2005/08/16 04:48:07 hxr Exp $
  19. */
  20.  
  21. #import "MyDummyCameraDriver.h"
  22. #import "Resolvers.h"
  23.  
  24. @implementation MyDummyCameraDriver
  25.  
  26. + (unsigned short) cameraUsbProductID { return 0; }
  27. + (unsigned short) cameraUsbVendorID { return 0; }
  28. + (NSString*) cameraName { return [MyCameraCentral localizedStringFor:@"Dummy camera"]; }
  29.  
  30.  
  31. - (id) initWithError:(CameraError)err central:(MyCameraCentral*)c {
  32.     short rate;
  33.     CameraResolution res;
  34.     self=[super initWithCentral:c];    //init superclass
  35.     if (self==NULL) return NULL;
  36.     self->errMsg=err;                //Copy our params
  37.     res=[self defaultResolutionAndRate:&rate];
  38.     [self setResolution:res fps:rate];
  39.     return self;    
  40. }
  41.  
  42. - (id) initWithCentral:(MyCameraCentral*)c {
  43.     return [self initWithError:CameraErrorOK central:c];
  44. }
  45.  
  46. - (CameraError) startupWithUsbLocationId:(UInt32)usbLocationId {
  47.     return [super startupWithUsbLocationId:usbLocationId];
  48. }
  49.  
  50. - (BOOL) realCamera {    //Returns if the camera is a real image grabber or a dummy
  51.     return (errMsg==CameraErrorOK);        //We're a dummy - if error is ok, we display a test image and act like a real one
  52. }
  53.  
  54.  
  55. - (BOOL) supportsResolution:(CameraResolution)r fps:(short)fr {
  56.     if ((fr<20)&&(r>=ResolutionQSIF)) return YES;
  57.     else return NO;
  58. }
  59.  
  60. - (CameraResolution) defaultResolutionAndRate:(short*)dFps {
  61.     if (dFps) *dFps=5;
  62.     return ResolutionSIF;
  63. }
  64.  
  65. //Grabbing
  66.  
  67.  
  68. /*
  69.  
  70. Why CFRunLoops? Somehow, I didn't manage to get the NSRunLoop stopped after invalidating the timer - the most likely reason is the connection to the main thread. This is not beautiful, but it works. It affects only the two lines CFRunLoopRun(); (which could be [[NSRunLoop currentRunLoop] run]) and CFRunLoopStop(CFRunLoopGetCurrent()); (which could be omitted as far as I understand it because [timer invalidate] should remove the timer from the run loop).
  71.  
  72. */
  73.  
  74. - (CameraError) decodingThread {
  75.     [NSTimer scheduledTimerWithTimeInterval:(1.0f)/((float)fps)
  76.                                      target:self
  77.                                    selector:@selector(imageTime:)
  78.                                    userInfo:NULL
  79.                                     repeats:YES];
  80.     CFRunLoopRun();
  81.     return CameraErrorOK;
  82. }
  83.  
  84. - (void) imageTime:(NSTimer*)timer {
  85.     if (shouldBeGrabbing) {
  86.         [self makeErrorImage:errMsg];
  87.     } else {
  88.         [timer invalidate];
  89.         CFRunLoopStop(CFRunLoopGetCurrent());
  90.     }
  91. }
  92.  
  93. @end
  94.