OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/video/capture/mac/video_capture_device_mac.h" | 5 #include "media/video/capture/mac/video_capture_device_mac.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; | 79 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; |
80 } | 80 } |
81 for (NSString* key in capture_devices) { | 81 for (NSString* key in capture_devices) { |
82 Name name([[capture_devices valueForKey:key] UTF8String], | 82 Name name([[capture_devices valueForKey:key] UTF8String], |
83 [key UTF8String]); | 83 [key UTF8String]); |
84 device_names->push_back(name); | 84 device_names->push_back(name); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 // static | 88 // static |
89 void VideoCaptureDevice::GetDeviceSupportedFormats(const Name& device, | 89 void VideoCaptureDevice::GetDeviceSupportedFormats( |
90 VideoCaptureCapabilities* formats) { | 90 const Name& device, |
| 91 VideoCaptureFormats* formats) { |
91 NOTIMPLEMENTED(); | 92 NOTIMPLEMENTED(); |
92 } | 93 } |
93 | 94 |
94 const std::string VideoCaptureDevice::Name::GetModel() const { | 95 const std::string VideoCaptureDevice::Name::GetModel() const { |
95 // Both PID and VID are 4 characters. | 96 // Both PID and VID are 4 characters. |
96 if (unique_id_.size() < 2 * kVidPidSize) { | 97 if (unique_id_.size() < 2 * kVidPidSize) { |
97 return ""; | 98 return ""; |
98 } | 99 } |
99 | 100 |
100 // The last characters of device id is a concatenation of VID and then PID. | 101 // The last characters of device id is a concatenation of VID and then PID. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 [capture_device_ setFrameReceiver:nil]; | 201 [capture_device_ setFrameReceiver:nil]; |
201 client_.reset(); | 202 client_.reset(); |
202 state_ = kIdle; | 203 state_ = kIdle; |
203 tried_to_square_pixels_ = false; | 204 tried_to_square_pixels_ = false; |
204 } | 205 } |
205 | 206 |
206 bool VideoCaptureDeviceMac::Init() { | 207 bool VideoCaptureDeviceMac::Init() { |
207 DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current()); | 208 DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current()); |
208 DCHECK_EQ(state_, kNotInitialized); | 209 DCHECK_EQ(state_, kNotInitialized); |
209 | 210 |
| 211 // TODO(mcasas): The following check might not be necessary; if the device has |
| 212 // disappeared after enumeration and before coming here, opening would just |
| 213 // fail but not necessarily produce a crash. |
210 Names device_names; | 214 Names device_names; |
211 GetDeviceNames(&device_names); | 215 GetDeviceNames(&device_names); |
212 Name* found = device_names.FindById(device_name_.id()); | 216 Names::iterator it = device_names.begin(); |
213 if (!found) | 217 for (; it != device_names.end(); ++it) { |
| 218 if (it->id() == device_name_.id()) |
| 219 break; |
| 220 } |
| 221 if (it == device_names.end()) |
214 return false; | 222 return false; |
215 | 223 |
216 capture_device_ = | 224 capture_device_ = |
217 [[VideoCaptureDeviceQTKit alloc] initWithFrameReceiver:this]; | 225 [[VideoCaptureDeviceQTKit alloc] initWithFrameReceiver:this]; |
218 if (!capture_device_) | 226 if (!capture_device_) |
219 return false; | 227 return false; |
220 | 228 |
221 state_ = kIdle; | 229 state_ = kIdle; |
222 return true; | 230 return true; |
223 } | 231 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height() | 329 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height() |
322 width:capture_format_.frame_size.width() | 330 width:capture_format_.frame_size.width() |
323 frameRate:capture_format_.frame_rate]) { | 331 frameRate:capture_format_.frame_rate]) { |
324 ReceiveError("Could not configure capture device."); | 332 ReceiveError("Could not configure capture device."); |
325 return false; | 333 return false; |
326 } | 334 } |
327 return true; | 335 return true; |
328 } | 336 } |
329 | 337 |
330 } // namespace media | 338 } // namespace media |
OLD | NEW |