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

Side by Side Diff: content/browser/media/media_devices_util.cc

Issue 2646833002: Add IPC to query capabilities of video input devices. (Closed)
Patch Set: 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
(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(
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 LOG(WARNING) << "Forget a value '" << option << "'? Use name=value for "
71 << switches::kUseFakeDeviceForMediaStream << ".";
dcheng 2017/01/20 07:56:50 DLOG. This doesn't seem like a switch real users a
Guido Urdaneta 2017/01/20 12:40:58 Done.
72 return std::string();
73 }
74
75 if (device_type == MEDIA_DEVICE_TYPE_AUDIO_INPUT &&
76 base::EqualsCaseInsensitiveASCII(param.front(),
dcheng 2017/01/20 07:56:50 Similarly, since this isn't really exposed to real
Guido Urdaneta 2017/01/20 12:40:58 Done.
77 "audio-input-default-id")) {
78 return param.back();
79 } else if (device_type == MEDIA_DEVICE_TYPE_VIDEO_INPUT &&
80 base::EqualsCaseInsensitiveASCII(param.front(),
81 "video-input-default-id")) {
82 return param.back();
83 }
84 }
85
86 return std::string();
87 }
88
89 } // namespace
90
91 void GetDefaultMediaDeviceID(
92 MediaDeviceType device_type,
93 int render_process_id,
94 int render_frame_id,
95 const base::Callback<void(const std::string&)>& callback) {
96 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
97 switches::kUseFakeDeviceForMediaStream)) {
98 callback.Run(GetDefaultMediaDeviceIDFromCommandLine(device_type));
99 return;
100 }
101
102 BrowserThread::PostTaskAndReplyWithResult(
103 BrowserThread::UI, FROM_HERE,
104 base::Bind(&GetDefaultMediaDeviceIDOnUIThread, device_type,
105 render_process_id, render_frame_id),
106 callback);
107 }
108
109 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698