Index: media/video/capture/mac/video_capture_device_mac.mm |
diff --git a/media/video/capture/mac/video_capture_device_mac.mm b/media/video/capture/mac/video_capture_device_mac.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2978d60fda73a897ef55684cbe921262474b2cf1 |
--- /dev/null |
+++ b/media/video/capture/mac/video_capture_device_mac.mm |
@@ -0,0 +1,148 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "media/video/capture/mac/video_capture_device_mac.h" |
+ |
+#include "base/logging.h" |
+#include "base/time.h" |
+#include "media/video/capture/mac/video_capture_device_mac_qtkit.h" |
+ |
+namespace media { |
+ |
+void VideoCaptureDevice::GetDeviceNames(Names* device_names) { |
+ // Empty the name list. |
+ device_names->clear(); |
+ |
+ // Get an array of devices. |
+ NSArray* device_list = [[NSArray alloc] |
dmac
2011/10/06 23:36:22
couple of things here:
a) no space between : and
mflodman_chromium_OOO
2011/10/07 13:03:51
Removed.
|
+ initWithArray: [QTCaptureDevice |
+ inputDevicesWithMediaType:QTMediaTypeVideo]]; |
+ |
+ for (unsigned int i = 0; i < device_list.count; ++i) { |
dmac
2011/10/06 23:36:22
for (QTCaptureDevice *device in [QTCaptureDevice i
mflodman_chromium_OOO
2011/10/07 13:03:51
Done.
|
+ QTCaptureDevice* capture_device = |
+ static_cast<QTCaptureDevice*>([device_list objectAtIndex:i]); |
+ if (capture_device) { |
dmac
2011/10/06 23:36:22
capture_device won't be null.
mflodman_chromium_OOO
2011/10/07 13:03:51
Removed.
|
+ Name name; |
+ NSString* qt_device_name = [capture_device localizedDisplayName]; |
+ name.device_name = [qt_device_name UTF8String]; |
+ NSString* qt_unique_id = [capture_device uniqueID]; |
+ name.unique_id = [qt_unique_id UTF8String]; |
+ device_names->push_back(name); |
+ } |
+ } |
+} |
+ |
+VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { |
+ VideoCaptureDeviceMac* capture_device = |
+ new VideoCaptureDeviceMac(device_name); |
+ if (!capture_device) { |
+ return NULL; |
dmac
2011/10/06 23:36:22
do you not want to at least LOG in either of these
mflodman_chromium_OOO
2011/10/07 13:03:51
Done, added LOG(ERROR) calls.
|
+ } |
+ if (!capture_device->Init()) { |
+ delete capture_device; |
+ return NULL; |
+ } |
+ return capture_device; |
+} |
+ |
+VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name) |
+ : device_name_(device_name), |
+ observer_(NULL), |
+ state_(kIdle), |
+ capture_device_(NULL) { |
+} |
+ |
+VideoCaptureDeviceMac::~VideoCaptureDeviceMac() { |
+ if (capture_device_) { |
+ [capture_device_ release]; |
dmac
2011/10/06 23:36:22
no need to check capture_device_.
Just call [captu
mflodman_chromium_OOO
2011/10/07 13:03:51
Done.
|
+ } |
+} |
+ |
+void VideoCaptureDeviceMac::Allocate(int width, int height, int frame_rate, |
+ EventHandler* observer) { |
+ if (state_ != kIdle) { |
+ return; |
+ } |
+ if (![capture_device_ setCaptureDevice:device_name_.device_name.c_str()]) { |
+ SetErrorState("Could not open capture device."); |
+ return; |
+ } |
+ if ([capture_device_ setCaptureHeight:height |
+ AndWidth:width |
+ AndFrameRate:frame_rate] == NO) { |
+ SetErrorState("Could not configure capture device."); |
+ return; |
+ } |
+ |
+ observer_ = observer; |
+ state_ = kAllocated; |
+ Capability current_settings; |
+ current_settings.color = kARGB; |
+ current_settings.width = width; |
+ current_settings.height = height; |
+ current_settings.frame_rate = frame_rate; |
+ |
+ observer_->OnFrameInfo(current_settings); |
+ return; |
dmac
2011/10/06 23:36:22
no need for return at end
mflodman_chromium_OOO
2011/10/07 13:03:51
Done.
|
+} |
+ |
+void VideoCaptureDeviceMac::Start() { |
+ if (state_ != kAllocated) { |
+ return; |
+ } |
+ if (![capture_device_ startCapture]) { |
+ SetErrorState("Could not start capture device."); |
+ return; |
+ } |
+ state_ = kCapturing; |
+} |
+ |
+void VideoCaptureDeviceMac::Stop() { |
+ if (state_ != kCapturing) { |
+ return; |
+ } |
+ [capture_device_ stopCapture]; |
+ state_ = kAllocated; |
+} |
+ |
+void VideoCaptureDeviceMac::DeAllocate() { |
+ if (state_ != kAllocated && state_ != kCapturing) { |
+ return; |
+ } |
+ if (state_ == kCapturing) { |
+ [capture_device_ stopCapture]; |
+ } |
+ [capture_device_ removeCaptureDevice]; |
+ state_ = kIdle; |
+} |
+ |
+const VideoCaptureDevice::Name& VideoCaptureDeviceMac::device_name() { |
+ return device_name_; |
+} |
+ |
+bool VideoCaptureDeviceMac::Init() { |
+ capture_device_ = [[VideoCaptureDeviceMacQTKit alloc] init]; |
dmac
2011/10/06 23:36:22
if folks call init twice we are going to leak a ca
mflodman_chromium_OOO
2011/10/07 13:03:51
Done, added new state + DCHECK.
|
+ if (capture_device_ == NULL) { |
+ return false; |
+ } |
+ [capture_device_ registerReceiver:this]; |
+ return true; |
+} |
+ |
+int VideoCaptureDeviceMac::IncomingFrame(void* video_frame, |
+ int video_frame_length, |
+ const Capability& frame_info) { |
+ observer_->OnIncomingCapturedFrame(static_cast<uint8*>(video_frame), |
+ video_frame_length, |
+ base::Time::Now()); |
+ return 0; |
+} |
+ |
+void VideoCaptureDeviceMac::SetErrorState(const std::string& reason) { |
+ DLOG(ERROR) << reason; |
+ state_ = kError; |
+ observer_->OnError(); |
+} |
+ |
+} // namespace media |