andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * video_capture_quick_time.h |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QUICKTIME_VIDEO_CAPTURE_QUICK_TIME_H_ |
| 17 | #define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QUICKTIME_VIDEO_CAPTURE_QUICK_TIME_H_ |
| 18 | |
| 19 | #include <QuickTime/QuickTime.h> |
| 20 | |
| 21 | |
| 22 | #include "../../device_info_impl.h" |
| 23 | #include "../../video_capture_impl.h" |
| 24 | #include "list_wrapper.h" |
| 25 | |
| 26 | |
| 27 | #define START_CODEC_WIDTH 352 |
| 28 | #define START_CODEC_HEIGHT 288 |
| 29 | #define SLEEP(x) usleep(x * 1000); |
| 30 | |
| 31 | namespace webrtc |
| 32 | { |
| 33 | class CriticalSectionWrapper; |
| 34 | class EventWrapper; |
| 35 | class ThreadWrapper; |
| 36 | |
| 37 | class VideoCaptureMacQuickTime : public VideoCaptureImpl |
| 38 | { |
| 39 | |
| 40 | public: |
| 41 | VideoCaptureMacQuickTime(const WebRtc_Word32 id); |
| 42 | virtual ~VideoCaptureMacQuickTime(); |
| 43 | |
| 44 | static void Destroy(VideoCaptureModule* module); |
| 45 | |
| 46 | WebRtc_Word32 Init(const WebRtc_Word32 id, |
| 47 | const WebRtc_UWord8* deviceUniqueIdUTF8); |
| 48 | virtual WebRtc_Word32 StartCapture( |
| 49 | const VideoCaptureCapability& capability); |
| 50 | virtual WebRtc_Word32 StopCapture(); |
| 51 | virtual bool CaptureStarted(); |
| 52 | virtual WebRtc_Word32 CaptureSettings(VideoCaptureCapability& settings); |
| 53 | |
| 54 | // TODO: remove? |
| 55 | int VideoCaptureInitThreadContext(); |
| 56 | int VideoCaptureTerminate(); |
| 57 | int VideoCaptureSetCaptureDevice(const char* deviceName, int size); |
| 58 | int UpdateCaptureSettings(int channel, webrtc::VideoCodec& inst, bool def); |
| 59 | int VideoCaptureRun(); |
| 60 | int VideoCaptureStop(); |
| 61 | |
| 62 | protected: |
| 63 | |
| 64 | private: // functions |
| 65 | |
| 66 | struct VideoCaptureMacName |
| 67 | { |
| 68 | VideoCaptureMacName(); |
| 69 | |
| 70 | enum { kVideoCaptureMacNameMaxSize = 64}; |
| 71 | char _name[kVideoCaptureMacNameMaxSize]; |
| 72 | CFIndex _size; |
| 73 | }; |
| 74 | |
| 75 | // Timeout value [ms] if we want to create a new device list or not |
| 76 | enum { kVideoCaptureDeviceListTimeout = 5000}; |
| 77 | // Temporary constant allowing this size from builtin iSight webcams. |
| 78 | enum { kYuy2_1280_1024_length = 2621440}; |
| 79 | |
| 80 | private: |
| 81 | |
| 82 | // Capture device callback |
| 83 | static OSErr SendProcess(SGChannel sgChannel, Ptr p, long len, long *offset, |
| 84 | long chRefCon, TimeValue time, short writeType, |
| 85 | long refCon); |
| 86 | int SendFrame(SGChannel sgChannel, char* data, long length, TimeValue time); |
| 87 | |
| 88 | // Capture device functions |
| 89 | int CreateLocalGWorld(int width, int height); |
| 90 | int RemoveLocalGWorld(); |
| 91 | int ConnectCaptureDevice(); |
| 92 | int DisconnectCaptureDevice(); |
| 93 | virtual bool IsCaptureDeviceSelected(); |
| 94 | |
| 95 | // Process to make sure the capture device won't stop |
| 96 | static bool GrabberUpdateThread(void*); |
| 97 | bool GrabberUpdateProcess(); |
| 98 | |
| 99 | // Starts and stops the capture |
| 100 | int StartQuickTimeCapture(); |
| 101 | int StopQuickTimeCapture(bool* wasCapturing = NULL); |
| 102 | |
| 103 | static CFIndex PascalStringToCString(const unsigned char* pascalString, |
| 104 | char* cString, |
| 105 | CFIndex bufferSize); |
| 106 | |
| 107 | private: // variables |
| 108 | WebRtc_Word32 _id; |
| 109 | bool _isCapturing; |
| 110 | VideoCaptureCapability _captureCapability; |
| 111 | CriticalSectionWrapper* _grabberCritsect; |
| 112 | CriticalSectionWrapper* _videoMacCritsect; |
| 113 | bool _terminated; |
| 114 | webrtc::ThreadWrapper* _grabberUpdateThread; |
| 115 | webrtc::EventWrapper* _grabberUpdateEvent; |
| 116 | SeqGrabComponent _captureGrabber; |
| 117 | Component _captureDevice; |
| 118 | char _captureDeviceDisplayName[64]; |
| 119 | RawVideoType _captureVideoType; |
| 120 | bool _captureIsInitialized; |
| 121 | GWorldPtr _gWorld; |
| 122 | SGChannel _captureChannel; |
| 123 | ImageSequence _captureSequence; |
| 124 | bool _sgPrepared; |
| 125 | bool _sgStarted; |
| 126 | int _trueCaptureWidth; |
| 127 | int _trueCaptureHeight; |
| 128 | ListWrapper _captureDeviceList; |
| 129 | unsigned long _captureDeviceListTime; |
| 130 | ListWrapper _captureCapabilityList; |
| 131 | }; |
| 132 | } // namespace webrtc |
| 133 | #endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QUICKTIME_VIDEO_CAPTURE_QUICK_TIME_H_ |