video_capture_device_mac.h revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// OS X implementation of VideoCaptureDevice, using QTKit as native capture API. 6 7#ifndef MEDIA_VIDEO_CAPTURE_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_ 8#define MEDIA_VIDEO_CAPTURE_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_ 9 10#include <string> 11 12#include "base/compiler_specific.h" 13#include "base/memory/ref_counted.h" 14#include "base/memory/weak_ptr.h" 15#include "base/message_loop/message_loop_proxy.h" 16#include "media/video/capture/video_capture_device.h" 17#include "media/video/capture/video_capture_types.h" 18 19@class VideoCaptureDeviceQTKit; 20 21namespace media { 22 23// Called by VideoCaptureManager to open, close and start, stop video capture 24// devices. 25class VideoCaptureDeviceMac : public VideoCaptureDevice1 { 26 public: 27 explicit VideoCaptureDeviceMac(const Name& device_name); 28 virtual ~VideoCaptureDeviceMac(); 29 30 // VideoCaptureDevice implementation. 31 virtual void Allocate(const VideoCaptureCapability& capture_format, 32 VideoCaptureDevice::EventHandler* observer) OVERRIDE; 33 virtual void Start() OVERRIDE; 34 virtual void Stop() OVERRIDE; 35 virtual void DeAllocate() OVERRIDE; 36 virtual const Name& device_name() OVERRIDE; 37 38 bool Init(); 39 40 // Called to deliver captured video frames. 41 void ReceiveFrame(const uint8* video_frame, int video_frame_length, 42 const VideoCaptureCapability& frame_info); 43 44 void ReceiveError(const std::string& reason); 45 46 private: 47 void SetErrorState(const std::string& reason); 48 49 // Flag indicating the internal state. 50 enum InternalState { 51 kNotInitialized, 52 kIdle, 53 kAllocated, 54 kCapturing, 55 kError 56 }; 57 58 Name device_name_; 59 VideoCaptureDevice::EventHandler* observer_; 60 61 // Only read and write state_ from inside this loop. 62 const scoped_refptr<base::MessageLoopProxy> loop_proxy_; 63 InternalState state_; 64 65 // Used with Bind and PostTask to ensure that methods aren't called 66 // after the VideoCaptureDeviceMac is destroyed. 67 base::WeakPtrFactory<VideoCaptureDeviceMac> weak_factory_; 68 base::WeakPtr<VideoCaptureDeviceMac> weak_this_; 69 70 VideoCaptureDeviceQTKit* capture_device_; 71 72 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceMac); 73}; 74 75} // namespace media 76 77#endif // MEDIA_VIDEO_CAPTURE_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_ 78