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

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

Issue 2609863004: Pass camera facing to WebKit (Closed)
Patch Set: modify settings names 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "content/public/browser/web_contents_media_capture_id.h" 42 #include "content/public/browser/web_contents_media_capture_id.h"
43 #include "content/public/common/content_client.h" 43 #include "content/public/common/content_client.h"
44 #include "content/public/common/content_switches.h" 44 #include "content/public/common/content_switches.h"
45 #include "content/public/common/media_stream_request.h" 45 #include "content/public/common/media_stream_request.h"
46 #include "crypto/hmac.h" 46 #include "crypto/hmac.h"
47 #include "media/audio/audio_device_description.h" 47 #include "media/audio/audio_device_description.h"
48 #include "media/audio/audio_manager.h" 48 #include "media/audio/audio_manager.h"
49 #include "media/base/audio_parameters.h" 49 #include "media/base/audio_parameters.h"
50 #include "media/base/channel_layout.h" 50 #include "media/base/channel_layout.h"
51 #include "media/base/media_switches.h" 51 #include "media/base/media_switches.h"
52 #include "media/capture/video/linux/camera_facing_chromeos.h"
jochen (gone - plz use gerrit) 2017/01/05 12:17:59 we shouldn't unconditionally include platform spec
shenghao 2017/01/06 09:43:01 Done.
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"
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 base::LazyInstance<media::CameraFacingChromeOS>::Leaky g_camera_facing_ =
jochen (gone - plz use gerrit) 2017/01/05 12:17:59 why is that a singleton can't we create a new inst
shenghao 2017/01/06 09:43:01 It's a lazy instance so it only be constructed whe
73 LAZY_INSTANCE_INITIALIZER;
74
70 // Creates a random label used to identify requests. 75 // Creates a random label used to identify requests.
71 std::string RandomLabel() { 76 std::string RandomLabel() {
72 // An earlier PeerConnection spec [1] defined MediaStream::label alphabet as 77 // 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 78 // 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 79 // 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 80 // U+007E. That causes problems with searching for labels in bots, so we use a
76 // safe alphanumeric subset |kAlphabet|. 81 // safe alphanumeric subset |kAlphabet|.
77 // [1] http://dev.w3.org/2011/webrtc/editor/webrtc.html 82 // [1] http://dev.w3.org/2011/webrtc/editor/webrtc.html
78 static const char kAlphabet[] = "0123456789" 83 static const char kAlphabet[] = "0123456789"
79 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 84 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 return MEDIA_DEVICE_TYPE_AUDIO_INPUT; 205 return MEDIA_DEVICE_TYPE_AUDIO_INPUT;
201 case MEDIA_DEVICE_VIDEO_CAPTURE: 206 case MEDIA_DEVICE_VIDEO_CAPTURE:
202 return MEDIA_DEVICE_TYPE_VIDEO_INPUT; 207 return MEDIA_DEVICE_TYPE_VIDEO_INPUT;
203 default: 208 default:
204 NOTREACHED(); 209 NOTREACHED();
205 } 210 }
206 211
207 return NUM_MEDIA_DEVICE_TYPES; 212 return NUM_MEDIA_DEVICE_TYPES;
208 } 213 }
209 214
215 VideoFacingMode GetVideoFacing(std::string device_id, std::string model_id) {
216 media::CameraFacingChromeOS::LensFacing facing =
217 g_camera_facing_.Get().GetCameraFacing(device_id, model_id);
218 switch (facing) {
219 case media::CameraFacingChromeOS::LensFacing::FRONT:
220 return VideoFacingMode::MEDIA_VIDEO_FACING_USER;
221 case media::CameraFacingChromeOS::LensFacing::BACK:
222 return VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT;
223 }
224 return VideoFacingMode::MEDIA_VIDEO_FACING_NONE;
225 }
226
210 MediaStreamDevices ConvertToMediaStreamDevices( 227 MediaStreamDevices ConvertToMediaStreamDevices(
211 MediaStreamType stream_type, 228 MediaStreamType stream_type,
212 const MediaDeviceInfoArray& device_infos) { 229 const MediaDeviceInfoArray& device_infos) {
213 MediaStreamDevices devices; 230 MediaStreamDevices devices;
214 for (const auto& info : device_infos) { 231 for (const auto& info : device_infos) {
215 devices.emplace_back(stream_type, info.device_id, info.label); 232 devices.emplace_back(stream_type, info.device_id, info.label,
233 GetVideoFacing(info.device_id, info.model_id));
216 } 234 }
217 235
218 return devices; 236 return devices;
219 } 237 }
220 238
221 } // namespace 239 } // namespace
222 240
223 241
224 // MediaStreamManager::DeviceRequest represents a request to either enumerate 242 // MediaStreamManager::DeviceRequest represents a request to either enumerate
225 // available devices or open one or more devices. 243 // 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; 1761 generate_stream_test_callback_ = test_callback;
1744 } 1762 }
1745 1763
1746 #if defined(OS_WIN) 1764 #if defined(OS_WIN)
1747 void MediaStreamManager::FlushVideoCaptureThreadForTesting() { 1765 void MediaStreamManager::FlushVideoCaptureThreadForTesting() {
1748 video_capture_thread_.FlushForTesting(); 1766 video_capture_thread_.FlushForTesting();
1749 } 1767 }
1750 #endif 1768 #endif
1751 1769
1752 } // namespace content 1770 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698