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

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

Issue 2609863004: Pass camera facing to WebKit (Closed)
Patch Set: address review comment 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>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "media/capture/video/video_capture_device_factory.h" 52 #include "media/capture/video/video_capture_device_factory.h"
53 #include "url/gurl.h" 53 #include "url/gurl.h"
54 #include "url/origin.h" 54 #include "url/origin.h"
55 55
56 #if defined(OS_WIN) 56 #if defined(OS_WIN)
57 #include "base/win/scoped_com_initializer.h" 57 #include "base/win/scoped_com_initializer.h"
58 #endif 58 #endif
59 59
60 #if defined(OS_CHROMEOS) 60 #if defined(OS_CHROMEOS)
61 #include "chromeos/audio/cras_audio_handler.h" 61 #include "chromeos/audio/cras_audio_handler.h"
62 #include "media/capture/video/linux/camera_facing_chromeos.h"
62 #endif 63 #endif
63 64
64 namespace content { 65 namespace content {
65 66
66 base::LazyInstance<base::ThreadLocalPointer<MediaStreamManager>>::Leaky 67 base::LazyInstance<base::ThreadLocalPointer<MediaStreamManager>>::Leaky
67 g_media_stream_manager_tls_ptr = LAZY_INSTANCE_INITIALIZER; 68 g_media_stream_manager_tls_ptr = LAZY_INSTANCE_INITIALIZER;
68 69
69 namespace { 70 namespace {
71
72 #if defined(OS_CHROMEOS)
73 base::LazyInstance<media::CameraFacingChromeOS>::Leaky g_camera_facing_ =
mcasas 2017/01/11 22:24:58 s/g_camera_facing_/g_camera_facing/ (no trailing u
shenghao 2017/01/12 08:10:48 Done.
74 LAZY_INSTANCE_INITIALIZER;
75 #endif
76
70 // Creates a random label used to identify requests. 77 // Creates a random label used to identify requests.
71 std::string RandomLabel() { 78 std::string RandomLabel() {
72 // An earlier PeerConnection spec [1] defined MediaStream::label alphabet as 79 // 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 80 // 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 81 // 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 82 // U+007E. That causes problems with searching for labels in bots, so we use a
76 // safe alphanumeric subset |kAlphabet|. 83 // safe alphanumeric subset |kAlphabet|.
77 // [1] http://dev.w3.org/2011/webrtc/editor/webrtc.html 84 // [1] http://dev.w3.org/2011/webrtc/editor/webrtc.html
78 static const char kAlphabet[] = "0123456789" 85 static const char kAlphabet[] = "0123456789"
79 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 86 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 return MEDIA_DEVICE_TYPE_AUDIO_INPUT; 207 return MEDIA_DEVICE_TYPE_AUDIO_INPUT;
201 case MEDIA_DEVICE_VIDEO_CAPTURE: 208 case MEDIA_DEVICE_VIDEO_CAPTURE:
202 return MEDIA_DEVICE_TYPE_VIDEO_INPUT; 209 return MEDIA_DEVICE_TYPE_VIDEO_INPUT;
203 default: 210 default:
204 NOTREACHED(); 211 NOTREACHED();
205 } 212 }
206 213
207 return NUM_MEDIA_DEVICE_TYPES; 214 return NUM_MEDIA_DEVICE_TYPES;
208 } 215 }
209 216
217 VideoFacingMode GetVideoFacing(std::string device_id,
218 std::string model_id,
219 MediaStreamType stream_type) {
220 #if defined(OS_CHROMEOS)
221 media::CameraFacingChromeOS::LensFacing facing =
222 g_camera_facing_.Get().GetCameraFacing(device_id, model_id);
223 switch (facing) {
224 case media::CameraFacingChromeOS::LensFacing::FRONT:
225 return VideoFacingMode::MEDIA_VIDEO_FACING_USER;
226 case media::CameraFacingChromeOS::LensFacing::BACK:
227 return VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT;
228 }
229 #endif
230 if (IsScreenCaptureMediaType(stream_type)) {
231 return VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT;
232 }
233 return VideoFacingMode::MEDIA_VIDEO_FACING_NONE;
234 }
235
210 MediaStreamDevices ConvertToMediaStreamDevices( 236 MediaStreamDevices ConvertToMediaStreamDevices(
211 MediaStreamType stream_type, 237 MediaStreamType stream_type,
212 const MediaDeviceInfoArray& device_infos) { 238 const MediaDeviceInfoArray& device_infos) {
213 MediaStreamDevices devices; 239 MediaStreamDevices devices;
214 for (const auto& info : device_infos) { 240 for (const auto& info : device_infos) {
215 devices.emplace_back(stream_type, info.device_id, info.label); 241 devices.emplace_back(
242 stream_type, info.device_id, info.label,
243 GetVideoFacing(info.device_id, info.model_id, stream_type));
216 } 244 }
217 245
218 return devices; 246 return devices;
219 } 247 }
220 248
221 } // namespace 249 } // namespace
222 250
223 251
224 // MediaStreamManager::DeviceRequest represents a request to either enumerate 252 // MediaStreamManager::DeviceRequest represents a request to either enumerate
225 // available devices or open one or more devices. 253 // 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; 1771 generate_stream_test_callback_ = test_callback;
1744 } 1772 }
1745 1773
1746 #if defined(OS_WIN) 1774 #if defined(OS_WIN)
1747 void MediaStreamManager::FlushVideoCaptureThreadForTesting() { 1775 void MediaStreamManager::FlushVideoCaptureThreadForTesting() {
1748 video_capture_thread_.FlushForTesting(); 1776 video_capture_thread_.FlushForTesting();
1749 } 1777 }
1750 #endif 1778 #endif
1751 1779
1752 } // namespace content 1780 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698