Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager.cc

Issue 2609863004: Pass camera facing to WebKit (Closed)
Patch Set: fix trybot errors Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 #include <cctype> 11 #include <cctype>
12 #include <list> 12 #include <list>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/power_monitor/power_monitor.h" 19 #include "base/power_monitor/power_monitor.h"
20 #include "base/profiler/scoped_tracker.h" 20 #include "base/profiler/scoped_tracker.h"
21 #include "base/rand_util.h" 21 #include "base/rand_util.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "base/task_runner_util.h" 25 #include "base/task_runner_util.h"
26 #include "base/threading/thread.h" 26 #include "base/threading/thread.h"
27 #include "base/threading/thread_local.h" 27 #include "base/threading/thread_local.h"
28 #include "base/threading/thread_restrictions.h"
28 #include "build/build_config.h" 29 #include "build/build_config.h"
29 #include "content/browser/child_process_security_policy_impl.h" 30 #include "content/browser/child_process_security_policy_impl.h"
30 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 31 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
31 #include "content/browser/renderer_host/media/media_capture_devices_impl.h" 32 #include "content/browser/renderer_host/media/media_capture_devices_impl.h"
32 #include "content/browser/renderer_host/media/media_devices_manager.h" 33 #include "content/browser/renderer_host/media/media_devices_manager.h"
33 #include "content/browser/renderer_host/media/media_stream_requester.h" 34 #include "content/browser/renderer_host/media/media_stream_requester.h"
34 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 35 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
35 #include "content/browser/renderer_host/media/video_capture_manager.h" 36 #include "content/browser/renderer_host/media/video_capture_manager.h"
36 #include "content/browser/renderer_host/render_process_host_impl.h" 37 #include "content/browser/renderer_host/render_process_host_impl.h"
37 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
(...skipping 14 matching lines...) Expand all
52 #include "media/capture/video/video_capture_device_factory.h" 53 #include "media/capture/video/video_capture_device_factory.h"
53 #include "url/gurl.h" 54 #include "url/gurl.h"
54 #include "url/origin.h" 55 #include "url/origin.h"
55 56
56 #if defined(OS_WIN) 57 #if defined(OS_WIN)
57 #include "base/win/scoped_com_initializer.h" 58 #include "base/win/scoped_com_initializer.h"
58 #endif 59 #endif
59 60
60 #if defined(OS_CHROMEOS) 61 #if defined(OS_CHROMEOS)
61 #include "chromeos/audio/cras_audio_handler.h" 62 #include "chromeos/audio/cras_audio_handler.h"
63 #include "media/capture/video/linux/camera_facing_chromeos.h"
62 #endif 64 #endif
63 65
64 namespace content { 66 namespace content {
65 67
66 base::LazyInstance<base::ThreadLocalPointer<MediaStreamManager>>::Leaky 68 base::LazyInstance<base::ThreadLocalPointer<MediaStreamManager>>::Leaky
67 g_media_stream_manager_tls_ptr = LAZY_INSTANCE_INITIALIZER; 69 g_media_stream_manager_tls_ptr = LAZY_INSTANCE_INITIALIZER;
68 70
69 namespace { 71 namespace {
72
73 #if defined(OS_CHROMEOS)
74 base::LazyInstance<media::CameraFacingChromeOS>::Leaky g_camera_facing =
75 LAZY_INSTANCE_INITIALIZER;
hta - Chromium 2017/01/12 19:36:41 If this is a singleton, does it make the assumptio
shenghao 2017/01/13 11:09:34 No.
76 #endif
77
70 // Creates a random label used to identify requests. 78 // Creates a random label used to identify requests.
71 std::string RandomLabel() { 79 std::string RandomLabel() {
72 // An earlier PeerConnection spec [1] defined MediaStream::label alphabet as 80 // An earlier PeerConnection spec [1] defined MediaStream::label alphabet as
73 // an uuid with characters from range: U+0021, U+0023 to U+0027, U+002A to 81 // an uuid with characters from range: U+0021, U+0023 to U+0027, U+002A to
74 // U+002B, U+002D to U+002E, U+0030 to U+0039, U+0041 to U+005A, U+005E to 82 // U+002B, U+002D to U+002E, U+0030 to U+0039, U+0041 to U+005A, U+005E to
75 // U+007E. That causes problems with searching for labels in bots, so we use a 83 // U+007E. That causes problems with searching for labels in bots, so we use a
76 // safe alphanumeric subset |kAlphabet|. 84 // safe alphanumeric subset |kAlphabet|.
77 // [1] http://dev.w3.org/2011/webrtc/editor/webrtc.html 85 // [1] http://dev.w3.org/2011/webrtc/editor/webrtc.html
78 static const char kAlphabet[] = "0123456789" 86 static const char kAlphabet[] = "0123456789"
79 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 87 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 return MEDIA_DEVICE_TYPE_AUDIO_INPUT; 208 return MEDIA_DEVICE_TYPE_AUDIO_INPUT;
201 case MEDIA_DEVICE_VIDEO_CAPTURE: 209 case MEDIA_DEVICE_VIDEO_CAPTURE:
202 return MEDIA_DEVICE_TYPE_VIDEO_INPUT; 210 return MEDIA_DEVICE_TYPE_VIDEO_INPUT;
203 default: 211 default:
204 NOTREACHED(); 212 NOTREACHED();
205 } 213 }
206 214
207 return NUM_MEDIA_DEVICE_TYPES; 215 return NUM_MEDIA_DEVICE_TYPES;
208 } 216 }
209 217
218 VideoFacingMode GetVideoFacing(std::string device_id,
219 std::string model_id,
220 MediaStreamType stream_type) {
221 #if defined(OS_CHROMEOS)
222 media::CameraFacingChromeOS::LensFacing facing =
223 g_camera_facing.Get().GetCameraFacing(device_id, model_id);
224 switch (facing) {
225 case media::CameraFacingChromeOS::LensFacing::FRONT:
226 return VideoFacingMode::MEDIA_VIDEO_FACING_USER;
227 case media::CameraFacingChromeOS::LensFacing::BACK:
228 return VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT;
229 }
230 #endif
231 if (IsScreenCaptureMediaType(stream_type)) {
232 return VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT;
hta - Chromium 2017/01/12 19:36:41 How does this choice make sense? I'd have thought
shenghao 2017/01/13 11:09:34 done
233 }
234 return VideoFacingMode::MEDIA_VIDEO_FACING_NONE;
235 }
236
210 MediaStreamDevices ConvertToMediaStreamDevices( 237 MediaStreamDevices ConvertToMediaStreamDevices(
211 MediaStreamType stream_type, 238 MediaStreamType stream_type,
212 const MediaDeviceInfoArray& device_infos) { 239 const MediaDeviceInfoArray& device_infos) {
240 base::ThreadRestrictions::SetIOAllowed(true);
jochen (gone - plz use gerrit) 2017/01/12 11:54:41 why is this required? how long will the operation
shenghao 2017/01/13 11:09:34 Because we need to access camera config file when
213 MediaStreamDevices devices; 241 MediaStreamDevices devices;
214 for (const auto& info : device_infos) { 242 for (const auto& info : device_infos) {
215 devices.emplace_back(stream_type, info.device_id, info.label); 243 devices.emplace_back(
244 stream_type, info.device_id, info.label,
245 GetVideoFacing(info.device_id, info.model_id, stream_type));
216 } 246 }
217 247
218 return devices; 248 return devices;
219 } 249 }
220 250
221 } // namespace 251 } // namespace
222 252
223 253
224 // MediaStreamManager::DeviceRequest represents a request to either enumerate 254 // MediaStreamManager::DeviceRequest represents a request to either enumerate
225 // available devices or open one or more devices. 255 // available devices or open one or more devices.
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 generate_stream_test_callback_ = test_callback; 1773 generate_stream_test_callback_ = test_callback;
1744 } 1774 }
1745 1775
1746 #if defined(OS_WIN) 1776 #if defined(OS_WIN)
1747 void MediaStreamManager::FlushVideoCaptureThreadForTesting() { 1777 void MediaStreamManager::FlushVideoCaptureThreadForTesting() {
1748 video_capture_thread_.FlushForTesting(); 1778 video_capture_thread_.FlushForTesting();
1749 } 1779 }
1750 #endif 1780 #endif
1751 1781
1752 } // namespace content 1782 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698