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 "content/browser/renderer_host/media/video_capture_manager.h" | 5 #include "content/browser/renderer_host/media/video_capture_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "content/browser/media/capture/desktop_capture_device.h" | 38 #include "content/browser/media/capture/desktop_capture_device.h" |
39 #if defined(USE_AURA) | 39 #if defined(USE_AURA) |
40 #include "content/browser/media/capture/desktop_capture_device_aura.h" | 40 #include "content/browser/media/capture/desktop_capture_device_aura.h" |
41 #endif | 41 #endif |
42 #endif | 42 #endif |
43 | 43 |
44 #if defined(ENABLE_SCREEN_CAPTURE) && defined(OS_ANDROID) | 44 #if defined(ENABLE_SCREEN_CAPTURE) && defined(OS_ANDROID) |
45 #include "content/browser/media/capture/screen_capture_device_android.h" | 45 #include "content/browser/media/capture/screen_capture_device_android.h" |
46 #endif | 46 #endif |
47 | 47 |
48 #if defined(OS_MACOSX) | |
49 #include "media/base/mac/avfoundation_glue.h" | |
50 #endif | |
51 | |
52 namespace { | 48 namespace { |
53 | 49 |
54 // Compares two VideoCaptureFormat by checking smallest frame_size area, then | 50 // Compares two VideoCaptureFormat by checking smallest frame_size area, then |
55 // by _largest_ frame_rate. Used to order a VideoCaptureFormats vector so that | 51 // by _largest_ frame_rate. Used to order a VideoCaptureFormats vector so that |
56 // the first entry for a given resolution has the largest frame rate, as needed | 52 // the first entry for a given resolution has the largest frame rate, as needed |
57 // by the ConsolidateCaptureFormats() method. | 53 // by the ConsolidateCaptureFormats() method. |
58 bool IsCaptureFormatSmaller(const media::VideoCaptureFormat& format1, | 54 bool IsCaptureFormatSmaller(const media::VideoCaptureFormat& format1, |
59 const media::VideoCaptureFormat& format2) { | 55 const media::VideoCaptureFormat& format2) { |
60 DCHECK(format1.frame_size.GetCheckedArea().IsValid()); | 56 DCHECK(format1.frame_size.GetCheckedArea().IsValid()); |
61 DCHECK(format2.frame_size.GetCheckedArea().IsValid()); | 57 DCHECK(format2.frame_size.GetCheckedArea().IsValid()); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 void VideoCaptureManager::Unregister() { | 290 void VideoCaptureManager::Unregister() { |
295 DCHECK(listener_); | 291 DCHECK(listener_); |
296 listener_ = nullptr; | 292 listener_ = nullptr; |
297 } | 293 } |
298 | 294 |
299 void VideoCaptureManager::EnumerateDevices( | 295 void VideoCaptureManager::EnumerateDevices( |
300 const EnumerationCallback& client_callback) { | 296 const EnumerationCallback& client_callback) { |
301 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 297 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
302 DVLOG(1) << "VideoCaptureManager::EnumerateDevices"; | 298 DVLOG(1) << "VideoCaptureManager::EnumerateDevices"; |
303 | 299 |
304 #if defined(OS_MACOSX) | |
305 if (NeedToInitializeCaptureDeviceApi(MEDIA_DEVICE_VIDEO_CAPTURE)) { | |
306 InitializeCaptureDeviceApiOnUIThread(base::Bind( | |
307 &VideoCaptureManager::EnumerateDevices, this, client_callback)); | |
308 return; | |
309 } | |
310 #endif | |
311 | |
312 // Bind a callback to ConsolidateDevicesInfoOnDeviceThread() with an argument | 300 // Bind a callback to ConsolidateDevicesInfoOnDeviceThread() with an argument |
313 // for another callback to OnDevicesInfoEnumerated() to be run in the current | 301 // for another callback to OnDevicesInfoEnumerated() to be run in the current |
314 // loop, i.e. IO loop. Pass a timer for UMA histogram collection. | 302 // loop, i.e. IO loop. Pass a timer for UMA histogram collection. |
315 base::Callback<void(std::unique_ptr<VideoCaptureDeviceDescriptors>)> | 303 base::Callback<void(std::unique_ptr<VideoCaptureDeviceDescriptors>)> |
316 devices_enumerated_callback = base::Bind( | 304 devices_enumerated_callback = base::Bind( |
317 &VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread, this, | 305 &VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread, this, |
318 media::BindToCurrentLoop(base::Bind( | 306 media::BindToCurrentLoop(base::Bind( |
319 &VideoCaptureManager::OnDevicesInfoEnumerated, this, | 307 &VideoCaptureManager::OnDevicesInfoEnumerated, this, |
320 base::Owned(new base::ElapsedTimer()), client_callback)), | 308 base::Owned(new base::ElapsedTimer()), client_callback)), |
321 devices_info_cache_); | 309 devices_info_cache_); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 device_start_queue_.pop_front(); | 424 device_start_queue_.pop_front(); |
437 } | 425 } |
438 DeviceStartQueue::iterator request = device_start_queue_.begin(); | 426 DeviceStartQueue::iterator request = device_start_queue_.begin(); |
439 if (request == device_start_queue_.end()) | 427 if (request == device_start_queue_.end()) |
440 return; | 428 return; |
441 | 429 |
442 const int serial_id = request->serial_id(); | 430 const int serial_id = request->serial_id(); |
443 DeviceEntry* const entry = GetDeviceEntryBySerialId(serial_id); | 431 DeviceEntry* const entry = GetDeviceEntryBySerialId(serial_id); |
444 DCHECK(entry); | 432 DCHECK(entry); |
445 | 433 |
446 #if defined(OS_MACOSX) | |
447 if (NeedToInitializeCaptureDeviceApi(entry->stream_type)) { | |
448 InitializeCaptureDeviceApiOnUIThread( | |
449 base::Bind(&VideoCaptureManager::HandleQueuedStartRequest, this)); | |
450 return; | |
451 } | |
452 #endif | |
453 | |
454 DVLOG(3) << "HandleQueuedStartRequest, Post start to device thread, device = " | 434 DVLOG(3) << "HandleQueuedStartRequest, Post start to device thread, device = " |
455 << entry->id << " start id = " << entry->serial_id; | 435 << entry->id << " start id = " << entry->serial_id; |
456 | 436 |
457 base::Callback<std::unique_ptr<VideoCaptureDevice>(void)> | 437 base::Callback<std::unique_ptr<VideoCaptureDevice>(void)> |
458 start_capture_function; | 438 start_capture_function; |
459 | 439 |
460 switch (entry->stream_type) { | 440 switch (entry->stream_type) { |
461 case MEDIA_DEVICE_VIDEO_CAPTURE: { | 441 case MEDIA_DEVICE_VIDEO_CAPTURE: { |
462 // We look up the device id from the renderer in our local enumeration | 442 // We look up the device id from the renderer in our local enumeration |
463 // since the renderer does not have all the information that might be | 443 // since the renderer does not have all the information that might be |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 VideoCaptureDevice::TakePhotoCallback callback, | 1182 VideoCaptureDevice::TakePhotoCallback callback, |
1203 VideoCaptureDevice* device) { | 1183 VideoCaptureDevice* device) { |
1204 // Unretained() is safe to use here because |device| would be null if it | 1184 // Unretained() is safe to use here because |device| would be null if it |
1205 // was scheduled for shutdown and destruction, and because this task is | 1185 // was scheduled for shutdown and destruction, and because this task is |
1206 // guaranteed to run before the task that destroys the |device|. | 1186 // guaranteed to run before the task that destroys the |device|. |
1207 device_task_runner_->PostTask( | 1187 device_task_runner_->PostTask( |
1208 FROM_HERE, base::Bind(&VideoCaptureDevice::TakePhoto, | 1188 FROM_HERE, base::Bind(&VideoCaptureDevice::TakePhoto, |
1209 base::Unretained(device), base::Passed(&callback))); | 1189 base::Unretained(device), base::Passed(&callback))); |
1210 } | 1190 } |
1211 | 1191 |
1212 #if defined(OS_MACOSX) | |
1213 void VideoCaptureManager::OnDeviceLayerInitialized( | |
1214 const base::Closure& and_then) { | |
1215 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
1216 capture_device_api_initialized_ = true; | |
1217 and_then.Run(); | |
1218 } | |
1219 | |
1220 bool VideoCaptureManager::NeedToInitializeCaptureDeviceApi( | |
1221 MediaStreamType stream_type) { | |
1222 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
1223 return !capture_device_api_initialized_ && | |
1224 stream_type == MEDIA_DEVICE_VIDEO_CAPTURE; | |
1225 } | |
1226 | |
1227 void VideoCaptureManager::InitializeCaptureDeviceApiOnUIThread( | |
1228 const base::Closure& and_then) { | |
1229 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
1230 BrowserThread::PostTaskAndReply( | |
1231 BrowserThread::UI, FROM_HERE, | |
1232 base::Bind(&AVFoundationGlue::InitializeAVFoundation), | |
1233 base::Bind(&VideoCaptureManager::OnDeviceLayerInitialized, this, | |
1234 and_then)); | |
1235 } | |
1236 #endif | |
1237 | |
1238 #if defined(OS_ANDROID) | 1192 #if defined(OS_ANDROID) |
1239 void VideoCaptureManager::OnApplicationStateChange( | 1193 void VideoCaptureManager::OnApplicationStateChange( |
1240 base::android::ApplicationState state) { | 1194 base::android::ApplicationState state) { |
1241 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1195 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1242 | 1196 |
1243 // Only release/resume devices when the Application state changes from | 1197 // Only release/resume devices when the Application state changes from |
1244 // RUNNING->STOPPED->RUNNING. | 1198 // RUNNING->STOPPED->RUNNING. |
1245 if (state == base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES && | 1199 if (state == base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES && |
1246 !application_state_has_running_activities_) { | 1200 !application_state_has_running_activities_) { |
1247 ResumeDevices(); | 1201 ResumeDevices(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 if (!device_in_queue) { | 1240 if (!device_in_queue) { |
1287 // Session ID is only valid for Screen capture. So we can fake it to | 1241 // Session ID is only valid for Screen capture. So we can fake it to |
1288 // resume video capture devices here. | 1242 // resume video capture devices here. |
1289 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); | 1243 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); |
1290 } | 1244 } |
1291 } | 1245 } |
1292 } | 1246 } |
1293 #endif // defined(OS_ANDROID) | 1247 #endif // defined(OS_ANDROID) |
1294 | 1248 |
1295 } // namespace content | 1249 } // namespace content |
OLD | NEW |