Go to the documentation of this file.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 CaptureImplQtKit;
00032 @class QTCaptureDevice;
00033 #else
00034 class CaptureImplQtKit;
00035 class QTCaptureDevice;
00036 #endif
00037 #elif defined( CINDER_COCOA_TOUCH_SIMULATOR )
00038 #if defined( __OBJC__ )
00039 @class CaptureImplCocoaDummy;
00040 #else
00041 class CaptureImplCocoaDummy;
00042 #endif
00043 #elif defined( CINDER_COCOA_TOUCH_DEVICE )
00044 #if defined( __OBJC__ )
00045 @class CaptureImplAvFoundation;
00046 #else
00047 class CaptureImplAvFoundation;
00048 #endif
00049 #elif defined( CINDER_MSW )
00050 namespace cinder {
00051 class CaptureImplDirectShow;
00052 }
00053 #endif
00054
00055 #include <map>
00056
00057 namespace cinder {
00058
00059 typedef std::shared_ptr<class Capture> CaptureRef;
00060
00061 class Capture {
00062 public:
00063 class Device;
00064 typedef std::shared_ptr<Device> DeviceRef;
00065
00066 static CaptureRef create( int32_t width, int32_t height, const DeviceRef device = DeviceRef() ) { return CaptureRef( new Capture( width, height, device ) ); }
00067
00068 Capture() {}
00070 Capture( int32_t width, int32_t height, const DeviceRef device = DeviceRef() );
00071 ~Capture() {}
00072
00074 void start();
00076 void stop();
00078 bool isCapturing();
00079
00081 bool checkNewFrame() const;
00082
00084 int32_t getWidth() const;
00086 int32_t getHeight() const;
00088 Vec2i getSize() const { return Vec2i( getWidth(), getHeight() ); }
00090 float getAspectRatio() const { return getWidth() / (float)getHeight(); }
00092 Area getBounds() const { return Area( 0, 0, getWidth(), getHeight() ); }
00093
00095 Surface8u getSurface() const;
00097 const Capture::DeviceRef getDevice() const;
00098
00100 static const std::vector<DeviceRef>& getDevices( bool forceRefresh = false );
00102 static DeviceRef findDeviceByName( const std::string &name );
00104 static DeviceRef findDeviceByNameContains( const std::string &nameFragment );
00105
00106 #if defined( CINDER_COCOA )
00107 typedef std::string DeviceIdentifier;
00108 #else
00109 typedef int DeviceIdentifier;
00110 #endif
00111
00112
00113 class Device {
00114 public:
00115 virtual ~Device() {}
00117 const std::string& getName() const { return mName; }
00119 virtual bool checkAvailable() const = 0;
00121 virtual bool isConnected() const = 0;
00123 virtual Capture::DeviceIdentifier getUniqueId() const = 0;
00125 #if defined( CINDER_COCOA )
00126 virtual void* getNative() const = 0;
00127 #endif
00128 #if defined( CINDER_COCOA_TOUCH )
00129
00130 virtual bool isFrontFacing() const = 0;
00131 #endif
00132 protected:
00133 Device() {}
00134 std::string mName;
00135 };
00136
00137 protected:
00138 struct Obj {
00139 Obj( int32_t width, int32_t height, const Capture::DeviceRef device );
00140 virtual ~Obj();
00141
00142 #if defined( CINDER_MAC )
00143 CaptureImplQtKit *mImpl;
00144 #elif defined( CINDER_COCOA_TOUCH_SIMULATOR )
00145 CaptureImplCocoaDummy *mImpl;
00146 #elif defined( CINDER_COCOA_TOUCH_DEVICE )
00147 CaptureImplAvFoundation *mImpl;
00148 #elif defined( CINDER_MSW )
00149 CaptureImplDirectShow *mImpl;
00150 #endif
00151 };
00152
00153 std::shared_ptr<Obj> mObj;
00154
00155 public:
00157
00158 typedef std::shared_ptr<Obj> Capture::*unspecified_bool_type;
00159 operator unspecified_bool_type() const { return ( mObj.get() == 0 ) ? 0 : &Capture::mObj; }
00160 void reset() { mObj.reset(); }
00162 };
00163
00164 class CaptureExc : public Exception {
00165 };
00166
00167 class CaptureExcInitFail : public CaptureExc {
00168 };
00169
00170 class CaptureExcInvalidChannelOrder : public CaptureExc {
00171 };
00172
00173 }