00001
00002 #ifndef INCLUDED_CameraSourceQTSG_h_
00003 #define INCLUDED_CameraSourceQTSG_h_
00004
00005 #include "local/DataSource.h"
00006 #include "Shared/plistCollections.h"
00007 #include "IPC/CallbackThread.h"
00008 #include <iostream>
00009 #include <stdexcept>
00010 #include <map>
00011 #include <cmath>
00012
00013 #define TARGET_API_MAC_CARBON 1
00014 #include <Carbon/Carbon.h>
00015 #include <QuickTime/QuickTime.h>
00016
00017 extern bool checkQTThreadInit();
00018
00019
00020
00021 class CameraSourceQTSG : public DataSource, public virtual plist::Dictionary {
00022 public:
00023
00024 CameraSourceQTSG(SeqGrabComponent grabber, const std::string& srcName, const std::string& devName, const std::string& inputName, int inputIdx)
00025 throw(std::pair<OSErr,const char*>)
00026 : DataSource(), layer(0), poller(&CameraSourceQTSG::poll,*this,TimeET(0L),TimeET(1.f/(*sensorFramerate)),true,CallbackPollThread::STOP_FALSE),
00027 sg(grabber), sgChan(NULL), gworld(NULL), name(srcName), deviceName(devName), devInputName(inputName), devInputIdx(inputIdx),
00028 frame(0), skipped(0), queuedFrames(0), grabbing(false),
00029 lastTime(0), duration(0), chanTimeScale(), chanTimeBase(), drawSeq(0), callbackerr(noErr),
00030 gworldBuf(NULL), burnIn(false)
00031 {
00032 initCamera();
00033
00034
00035 setLoadSavePolicy(FIXED,SYNC);
00036 addEntry("Layer",layer,"Controls the resolution layer at which the image should be processed.\n"
00037 "0 indicates \"automatic\" mode (picks layer closest to image's resolution), positive numbers indicate the resolution layer directly.\n"
00038 "Negative values are relative to the number of layers marked available by the vision setup, so that typically -1 would correspond to the \"double\" layer, and -2 would correspond to the \"full\" layer.");
00039 }
00040
00041
00042 ~CameraSourceQTSG();
00043
00044
00045 virtual const std::string& getName() const { return name; }
00046
00047 virtual const std::string& getDeviceName() const { return deviceName; }
00048
00049 virtual const std::string& getInputName() const { return devInputName; }
00050
00051 virtual unsigned int nextTimestamp() { return static_cast<unsigned int>(std::ceil(lastTime+duration*1000)); }
00052 virtual const std::string& nextName() { return name; }
00053
00054 virtual void registerSource();
00055 virtual void deregisterSource();
00056 virtual bool advance();
00057
00058 plist::Primitive<int> layer;
00059
00060 protected:
00061 void initCamera();
00062
00063 void doFreeze();
00064 void doUnfreeze();
00065
00066
00067
00068 static std::string p2c(unsigned char pascalStr[]) {
00069 unsigned char len = *pascalStr++;
00070 return std::string(reinterpret_cast<char*>(pascalStr),len);
00071 }
00072
00073 static void dumpLiteral(OSType t);
00074 static ComponentResult setVideoChannelBounds(SGChannel videoChannel, const Rect *scaledVideoBounds);
00075 static pascal ComponentResult compressCompleteBottleProc(SGChannel c, UInt8 *queuedFrameCount, SGCompressInfo *ci, TimeRecord *t, long refCon);
00076 static pascal OSErr grabDataProc(SGChannel c, Ptr p, long len, long *offset, long chRefCon, TimeValue time, short writeType, long refCon);
00077
00078
00079 RCRegion * imgFrom2vuy(const unsigned char * s, short srcWidth, short srcHeight, short depth, long dataSize);
00080
00081 RCRegion * imgFromyuv2(const unsigned char * s, short srcWidth, short srcHeight, short depth, long dataSize);
00082
00083 bool poll() { Thread::NoCancelScope nc; advance(); return grabbing; }
00084 CallbackPollThread poller;
00085
00086 SeqGrabComponent sg;
00087 SGChannel sgChan;
00088 GWorldPtr gworld;
00089 std::string name;
00090 const std::string deviceName;
00091 const std::string devInputName;
00092 int devInputIdx;
00093
00094 unsigned int frame;
00095 unsigned int skipped;
00096 unsigned int queuedFrames;
00097 bool grabbing;
00098 TimeValue lastTime;
00099 float duration;
00100 TimeScale chanTimeScale;
00101 TimeBase chanTimeBase;
00102 ImageSequence drawSeq;
00103 OSErr callbackerr;
00104
00105 char * gworldBuf;
00106 bool burnIn;
00107
00108 private:
00109 CameraSourceQTSG(const CameraSourceQTSG&);
00110 CameraSourceQTSG& operator=(const CameraSourceQTSG&);
00111 };
00112
00113
00114
00115
00116
00117
00118 #endif