00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #pragma once
00024
00025 #include "cinder/Cinder.h"
00026 #include "cinder/Surface.h"
00027 #include "cinder/Exception.h"
00028
00029 #if defined( CINDER_MAC )
00030 # if defined( __OBJC__ )
00031 @class CaptureCocoa;
00032 @class QTCaptureDevice;
00033 # else
00034 class CaptureCocoa;
00035 class QTCaptureDevice;
00036 # endif
00037 #elif defined( CINDER_MSW )
00038 # include "msw/videoInput/videoInput.h"
00039 #endif
00040
00041 #include <map>
00042
00043 namespace cinder {
00044
00045 class Capture {
00046 public:
00047 class Device;
00048
00049 Capture() {}
00050 Capture( int32_t width, int32_t height, const Device &device = Device() );
00051 ~Capture() {}
00052
00054 void start();
00056 void stop();
00058 bool isCapturing();
00059
00061 bool checkNewFrame() const;
00062
00064 int32_t getWidth() const { return mObj->mWidth; }
00066 int32_t getHeight() const { return mObj->mHeight; }
00068 Vec2i getSize() const { return Vec2i( getWidth(), getHeight() ); }
00070 float getAspectRatio() const { return getWidth() / (float)getHeight(); }
00072 Area getBounds() const { return Area( 0, 0, getWidth(), getHeight() ); }
00073
00075 Surface8u getSurface() const;
00077 Device getDevice() const { return mObj->mDevice; }
00078
00080 static const std::vector<Device>& getDevices( bool forceRefresh = false );
00082 static Device findDeviceByName( const std::string &name );
00083
00085 class Device {
00086 public:
00088 const std::string& getName() const { return mName; }
00090 bool checkAvailable() const;
00092 bool isConnected() const;
00093
00095 #if defined( CINDER_MAC )
00096 const std::string& getUniqueId() const { return mUniqueId; }
00097 #else
00098 int getUniqueId() const { return mUniqueId; }
00099 #endif
00100
00101 #if defined( CINDER_MAC )
00102 Device() {}
00103 #else
00104 Device() : mUniqueId( 0 ) {}
00105 #endif
00106 protected:
00107 #if defined( CINDER_MAC )
00108 Device( QTCaptureDevice* device );
00109 #else
00110 Device( const std::string &name, int uniqueId ) : mName( name ), mUniqueId( uniqueId ) {}
00111 #endif
00112
00113 std::string mName;
00114 #if defined( CINDER_MAC )
00115 std::string mUniqueId;
00116 #else
00117 int mUniqueId;
00118 #endif
00119
00120 friend class Capture;
00121 };
00122
00123 protected:
00124 struct Obj {
00125 Obj( int32_t width, int32_t height, const Capture::Device &device );
00126 virtual ~Obj();
00127
00128 #if defined( CINDER_MAC )
00129 CaptureCocoa *mImpl;
00130 #elif defined( CINDER_MSW )
00131 int mDeviceID;
00132
00133
00134 shared_ptr<class CaptureMgr> mMgrPtr;
00135 bool mIsCapturing;
00136 shared_ptr<class SurfaceCache> mSurfaceCache;
00137 #endif
00138 int32_t mWidth, mHeight;
00139 mutable Surface8u mCurrentFrame;
00140 Capture::Device mDevice;
00141 };
00142
00143 shared_ptr<Obj> mObj;
00144 static bool sDevicesEnumerated;
00145 static std::vector<Capture::Device> sDevices;
00146
00147 public:
00149
00150 typedef shared_ptr<Obj> Capture::*unspecified_bool_type;
00151 operator unspecified_bool_type() { return ( mObj.get() == 0 ) ? 0 : &Capture::mObj; }
00152 void reset() { mObj.reset(); }
00154 };
00155
00156 class CaptureExc : public Exception {
00157 };
00158
00159 class CaptureExcInitFail : public CaptureExc {
00160 };
00161
00162 class CaptureExcInvalidChannelOrder : public CaptureExc {
00163 };
00164
00165 }