Chromium Code Reviews| 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/media_stream_manager.h" | 5 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 MediaStreamType stream_type, | 211 MediaStreamType stream_type, |
| 212 const MediaDeviceInfoArray& device_infos) { | 212 const MediaDeviceInfoArray& device_infos) { |
| 213 MediaStreamDevices devices; | 213 MediaStreamDevices devices; |
| 214 for (const auto& info : device_infos) { | 214 for (const auto& info : device_infos) { |
| 215 devices.emplace_back(stream_type, info.device_id, info.label); | 215 devices.emplace_back(stream_type, info.device_id, info.label); |
| 216 } | 216 } |
| 217 | 217 |
| 218 return devices; | 218 return devices; |
| 219 } | 219 } |
| 220 | 220 |
| 221 bool FindFirstDeviceIdForVideoKind(const MediaDeviceInfoArray& devices, | |
| 222 VideoKind video_kind, | |
| 223 VideoCaptureManager* video_capture_manager, | |
| 224 std::string* device_id) { | |
| 225 for (const auto& device : devices) { | |
| 226 media::VideoCaptureFormats formats; | |
| 227 video_capture_manager->GetDeviceSupportedFormats(device.device_id, | |
| 228 &formats); | |
| 229 for (const auto& format : formats) { | |
| 230 if ((video_kind == VIDEO_KIND_DEPTH && | |
| 231 format.pixel_format == media::PIXEL_FORMAT_Y16) || | |
| 232 (video_kind == VIDEO_KIND_COLOR && | |
| 233 format.pixel_format != media::PIXEL_FORMAT_Y16)) { | |
| 234 *device_id = device.device_id; | |
| 235 return true; | |
| 236 } | |
| 237 } | |
| 238 } | |
| 239 return false; | |
| 240 } | |
| 241 | |
| 221 } // namespace | 242 } // namespace |
| 222 | 243 |
| 223 | 244 |
| 224 // MediaStreamManager::DeviceRequest represents a request to either enumerate | 245 // MediaStreamManager::DeviceRequest represents a request to either enumerate |
| 225 // available devices or open one or more devices. | 246 // available devices or open one or more devices. |
| 226 // TODO(perkj): MediaStreamManager still needs refactoring. I propose we create | 247 // TODO(perkj): MediaStreamManager still needs refactoring. I propose we create |
| 227 // several subclasses of DeviceRequest and move some of the responsibility of | 248 // several subclasses of DeviceRequest and move some of the responsibility of |
| 228 // the MediaStreamManager to the subclasses to get rid of the way too many if | 249 // the MediaStreamManager to the subclasses to get rid of the way too many if |
| 229 // statements in MediaStreamManager. | 250 // statements in MediaStreamManager. |
| 230 class MediaStreamManager::DeviceRequest { | 251 class MediaStreamManager::DeviceRequest { |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 LOG(WARNING) << "Invalid device ID = " << controls.device_id; | 822 LOG(WARNING) << "Invalid device ID = " << controls.device_id; |
| 802 return false; | 823 return false; |
| 803 } | 824 } |
| 804 return true; | 825 return true; |
| 805 } | 826 } |
| 806 | 827 |
| 807 bool MediaStreamManager::GetRequestedDeviceCaptureId( | 828 bool MediaStreamManager::GetRequestedDeviceCaptureId( |
| 808 const DeviceRequest* request, | 829 const DeviceRequest* request, |
| 809 MediaStreamType type, | 830 MediaStreamType type, |
| 810 const MediaDeviceInfoArray& devices, | 831 const MediaDeviceInfoArray& devices, |
| 811 std::string* device_id) const { | 832 std::string* device_id) { |
| 812 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { | 833 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { |
| 813 return PickDeviceId(request->salt, request->security_origin, | 834 return PickDeviceId(request->salt, request->security_origin, |
| 814 request->controls.audio, devices, device_id); | 835 request->controls.audio, devices, device_id); |
| 815 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { | 836 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
| 837 if (request->controls.video.device_id.empty() && | |
|
Guido Urdaneta
2017/02/07 10:26:03
There is a CL (http://crrev.com/2669243004/) close
aleksandar.stojiljkovic
2017/02/07 11:33:49
Thanks. Looks good.
| |
| 838 request->controls.video_kind != VIDEO_KIND_NO_CONSTRAINT) { | |
| 839 return FindFirstDeviceIdForVideoKind(devices, | |
| 840 request->controls.video_kind, | |
| 841 video_capture_manager(), device_id); | |
| 842 } | |
| 816 return PickDeviceId(request->salt, request->security_origin, | 843 return PickDeviceId(request->salt, request->security_origin, |
| 817 request->controls.video, devices, device_id); | 844 request->controls.video, devices, device_id); |
| 818 } else { | 845 } else { |
| 819 NOTREACHED(); | 846 NOTREACHED(); |
| 820 } | 847 } |
| 821 return false; | 848 return false; |
| 822 } | 849 } |
| 823 | 850 |
| 824 void MediaStreamManager::TranslateDeviceIdToSourceId( | 851 void MediaStreamManager::TranslateDeviceIdToSourceId( |
| 825 DeviceRequest* request, | 852 DeviceRequest* request, |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1743 generate_stream_test_callback_ = test_callback; | 1770 generate_stream_test_callback_ = test_callback; |
| 1744 } | 1771 } |
| 1745 | 1772 |
| 1746 #if defined(OS_WIN) | 1773 #if defined(OS_WIN) |
| 1747 void MediaStreamManager::FlushVideoCaptureThreadForTesting() { | 1774 void MediaStreamManager::FlushVideoCaptureThreadForTesting() { |
| 1748 video_capture_thread_.FlushForTesting(); | 1775 video_capture_thread_.FlushForTesting(); |
| 1749 } | 1776 } |
| 1750 #endif | 1777 #endif |
| 1751 | 1778 |
| 1752 } // namespace content | 1779 } // namespace content |
| OLD | NEW |