Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/media/media_devices_util.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/bind.h" | |
| 11 #include "base/command_line.h" | |
| 12 #include "base/strings/string_split.h" | |
| 13 #include "base/strings/string_tokenizer.h" | |
| 14 #include "content/browser/frame_host/render_frame_host_delegate.h" | |
| 15 #include "content/browser/frame_host/render_frame_host_impl.h" | |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 #include "content/public/common/media_stream_request.h" | |
| 18 #include "media/base/media_switches.h" | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 std::string GetDefaultMediaDeviceIDOnUIThread(MediaDeviceType device_type, | |
| 25 int render_process_id, | |
| 26 int render_frame_id) { | |
| 27 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 28 RenderFrameHostImpl* frame_host = | |
| 29 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | |
| 30 if (!frame_host) | |
| 31 return std::string(); | |
| 32 | |
| 33 RenderFrameHostDelegate* delegate = frame_host->delegate(); | |
| 34 if (!delegate) | |
| 35 return std::string(); | |
| 36 | |
| 37 MediaStreamType media_stream_type; | |
| 38 switch (device_type) { | |
| 39 case MEDIA_DEVICE_TYPE_AUDIO_INPUT: | |
| 40 media_stream_type = MEDIA_DEVICE_AUDIO_CAPTURE; | |
| 41 break; | |
| 42 case MEDIA_DEVICE_TYPE_VIDEO_INPUT: | |
| 43 media_stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; | |
| 44 break; | |
| 45 default: | |
| 46 return std::string(); | |
| 47 } | |
| 48 | |
| 49 return delegate->GetDefaultMediaDeviceID(media_stream_type); | |
| 50 } | |
| 51 | |
| 52 std::string GetDefaultMediaDeviceIDFromCommandLine( | |
|
clamy
2017/01/27 16:44:34
When is this supposed to be used?
Guido Urdaneta
2017/01/27 17:02:14
It is used when the kUseFakeDeviceForMediaStream c
clamy
2017/01/27 17:05:47
If this is meant to be used in test, then I'd sugg
Guido Urdaneta
2017/01/27 17:14:44
If I use a "ForTesting" suffix, I get the followin
clamy
2017/01/27 17:16:14
Acknowledged.
Guido Urdaneta
2017/01/27 17:17:51
So, should I proceed with the rename?
clamy
2017/01/27 17:19:15
No it's ok without. You could add a comment that e
| |
| 53 MediaDeviceType device_type) { | |
| 54 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 55 switches::kUseFakeDeviceForMediaStream)); | |
| 56 const std::string option = | |
| 57 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 58 switches::kUseFakeDeviceForMediaStream); | |
| 59 // Optional comma delimited parameters to the command line can specify values | |
| 60 // for the default device IDs. | |
| 61 // Examples: "video-input-default-id=mycam, audio-input-default-id=mymic" | |
| 62 base::StringTokenizer option_tokenizer(option, ", "); | |
| 63 option_tokenizer.set_quote_chars("\""); | |
| 64 | |
| 65 while (option_tokenizer.GetNext()) { | |
| 66 std::vector<std::string> param = | |
| 67 base::SplitString(option_tokenizer.token(), "=", base::TRIM_WHITESPACE, | |
| 68 base::SPLIT_WANT_NONEMPTY); | |
| 69 if (param.size() != 2u) { | |
| 70 DLOG(WARNING) << "Forgot a value '" << option << "'? Use name=value for " | |
| 71 << switches::kUseFakeDeviceForMediaStream << "."; | |
| 72 return std::string(); | |
| 73 } | |
| 74 | |
| 75 if (device_type == MEDIA_DEVICE_TYPE_AUDIO_INPUT && | |
| 76 param.front() == "audio-input-default-id") { | |
| 77 return param.back(); | |
| 78 } else if (device_type == MEDIA_DEVICE_TYPE_VIDEO_INPUT && | |
| 79 param.front() == "video-input-default-id") { | |
| 80 return param.back(); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 return std::string(); | |
| 85 } | |
| 86 | |
| 87 } // namespace | |
| 88 | |
| 89 void GetDefaultMediaDeviceID( | |
| 90 MediaDeviceType device_type, | |
| 91 int render_process_id, | |
| 92 int render_frame_id, | |
| 93 const base::Callback<void(const std::string&)>& callback) { | |
| 94 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 95 switches::kUseFakeDeviceForMediaStream)) { | |
| 96 callback.Run(GetDefaultMediaDeviceIDFromCommandLine(device_type)); | |
| 97 return; | |
| 98 } | |
| 99 | |
| 100 BrowserThread::PostTaskAndReplyWithResult( | |
| 101 BrowserThread::UI, FROM_HERE, | |
| 102 base::Bind(&GetDefaultMediaDeviceIDOnUIThread, device_type, | |
| 103 render_process_id, render_frame_id), | |
| 104 callback); | |
| 105 } | |
| 106 | |
| 107 } // namespace content | |
| OLD | NEW |