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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 245 |
246 void VideoCaptureManager::Register( | 246 void VideoCaptureManager::Register( |
247 MediaStreamProviderListener* listener, | 247 MediaStreamProviderListener* listener, |
248 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { | 248 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { |
249 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 249 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
250 DCHECK(!listener_); | 250 DCHECK(!listener_); |
251 DCHECK(!device_task_runner_.get()); | 251 DCHECK(!device_task_runner_.get()); |
252 listener_ = listener; | 252 listener_ = listener; |
253 device_task_runner_ = device_task_runner; | 253 device_task_runner_ = device_task_runner; |
254 #if defined(OS_ANDROID) | 254 #if defined(OS_ANDROID) |
| 255 application_state_has_running_activities_ = true; |
255 app_status_listener_.reset(new base::android::ApplicationStatusListener( | 256 app_status_listener_.reset(new base::android::ApplicationStatusListener( |
256 base::Bind(&VideoCaptureManager::OnApplicationStateChange, | 257 base::Bind(&VideoCaptureManager::OnApplicationStateChange, |
257 base::Unretained(this)))); | 258 base::Unretained(this)))); |
258 #endif | 259 #endif |
259 } | 260 } |
260 | 261 |
261 void VideoCaptureManager::Unregister() { | 262 void VideoCaptureManager::Unregister() { |
262 DCHECK(listener_); | 263 DCHECK(listener_); |
263 listener_ = nullptr; | 264 listener_ = nullptr; |
264 } | 265 } |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 base::Bind(&VideoCaptureManager::OnDeviceLayerInitialized, this, | 1075 base::Bind(&VideoCaptureManager::OnDeviceLayerInitialized, this, |
1075 and_then)); | 1076 and_then)); |
1076 } | 1077 } |
1077 #endif | 1078 #endif |
1078 | 1079 |
1079 #if defined(OS_ANDROID) | 1080 #if defined(OS_ANDROID) |
1080 void VideoCaptureManager::OnApplicationStateChange( | 1081 void VideoCaptureManager::OnApplicationStateChange( |
1081 base::android::ApplicationState state) { | 1082 base::android::ApplicationState state) { |
1082 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1083 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1083 | 1084 |
1084 if (state == base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { | 1085 // Only release/resume devices when the Application state changes from |
| 1086 // RUNNING->STOPPED->RUNNING. |
| 1087 if (state == base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES && |
| 1088 !application_state_has_running_activities_) { |
1085 ResumeDevices(); | 1089 ResumeDevices(); |
| 1090 application_state_has_running_activities_ = true; |
1086 } else if (state == base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES) { | 1091 } else if (state == base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES) { |
1087 ReleaseDevices(); | 1092 ReleaseDevices(); |
| 1093 application_state_has_running_activities_ = false; |
1088 } | 1094 } |
1089 } | 1095 } |
1090 | 1096 |
1091 void VideoCaptureManager::ReleaseDevices() { | 1097 void VideoCaptureManager::ReleaseDevices() { |
1092 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1098 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1093 | 1099 |
1094 for (auto& entry : devices_) { | 1100 for (auto& entry : devices_) { |
1095 // Do not stop Content Video Capture devices, e.g. Tab or Screen capture. | 1101 // Do not stop Content Video Capture devices, e.g. Tab or Screen capture. |
1096 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE) | 1102 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE) |
1097 continue; | 1103 continue; |
1098 | 1104 |
1099 DoStopDevice(entry); | 1105 DoStopDevice(entry); |
1100 } | 1106 } |
1101 } | 1107 } |
1102 | 1108 |
1103 void VideoCaptureManager::ResumeDevices() { | 1109 void VideoCaptureManager::ResumeDevices() { |
1104 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1110 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1105 | 1111 |
1106 for (auto& entry : devices_) { | 1112 for (auto& entry : devices_) { |
1107 // Do not resume Content Video Capture devices, e.g. Tab or Screen capture. | 1113 // Do not resume Content Video Capture devices, e.g. Tab or Screen capture. |
1108 // Do not try to restart already running devices. A device will be running | 1114 // Do not try to restart already running devices. |
1109 // if the Application state changes from | |
1110 // APPLICATION_STATE_HAS_RUNNING_ACTIVITIES | |
1111 // ->APPLICATION_STATE_HAS_PAUSED_ACTIVITIES | |
1112 // ->APPLICATION_STATE_HAS_RUNNING_ACTIVITIES | |
1113 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE || | 1115 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE || |
1114 entry->video_capture_device()) | 1116 entry->video_capture_device()) |
1115 continue; | 1117 continue; |
1116 | 1118 |
1117 // Check if the device is already in the start queue. | 1119 // Check if the device is already in the start queue. |
1118 bool device_in_queue = false; | 1120 bool device_in_queue = false; |
1119 for (auto& request : device_start_queue_) { | 1121 for (auto& request : device_start_queue_) { |
1120 if (request.serial_id() == entry->serial_id) { | 1122 if (request.serial_id() == entry->serial_id) { |
1121 device_in_queue = true; | 1123 device_in_queue = true; |
1122 break; | 1124 break; |
1123 } | 1125 } |
1124 } | 1126 } |
1125 | 1127 |
1126 if (!device_in_queue) { | 1128 if (!device_in_queue) { |
1127 // Session ID is only valid for Screen capture. So we can fake it to | 1129 // Session ID is only valid for Screen capture. So we can fake it to |
1128 // resume video capture devices here. | 1130 // resume video capture devices here. |
1129 QueueStartDevice(kFakeSessionId, entry, entry->parameters); | 1131 QueueStartDevice(kFakeSessionId, entry, entry->parameters); |
1130 } | 1132 } |
1131 } | 1133 } |
1132 } | 1134 } |
1133 #endif // defined(OS_ANDROID) | 1135 #endif // defined(OS_ANDROID) |
1134 | 1136 |
1135 } // namespace content | 1137 } // namespace content |
OLD | NEW |