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

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

Issue 616833004: chrome://media-internals: update MediaInternals when devices capabilities are enumerated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: burnik@ comments. Rebased. Refactored capabilities update. Created 6 years, 2 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/media/media_internals.h" 5 #include "content/browser/media/media_internals.h"
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 dict.SetString(kAudioLogStatusKey, "created"); 111 dict.SetString(kAudioLogStatusKey, "created");
112 dict.SetString("device_id", device_id); 112 dict.SetString("device_id", device_id);
113 dict.SetInteger("frames_per_buffer", params.frames_per_buffer()); 113 dict.SetInteger("frames_per_buffer", params.frames_per_buffer());
114 dict.SetInteger("sample_rate", params.sample_rate()); 114 dict.SetInteger("sample_rate", params.sample_rate());
115 dict.SetInteger("channels", params.channels()); 115 dict.SetInteger("channels", params.channels());
116 dict.SetString("channel_layout", 116 dict.SetString("channel_layout",
117 ChannelLayoutToString(params.channel_layout())); 117 ChannelLayoutToString(params.channel_layout()));
118 dict.SetString("effects", EffectsToString(params.effects())); 118 dict.SetString("effects", EffectsToString(params.effects()));
119 119
120 media_internals_->SendUpdateAndCache( 120 media_internals_->SendUpdateAndCacheAudioStreamKey(
121 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict); 121 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict);
122 } 122 }
123 123
124 void AudioLogImpl::OnStarted(int component_id) { 124 void AudioLogImpl::OnStarted(int component_id) {
125 SendSingleStringUpdate(component_id, kAudioLogStatusKey, "started"); 125 SendSingleStringUpdate(component_id, kAudioLogStatusKey, "started");
126 } 126 }
127 127
128 void AudioLogImpl::OnStopped(int component_id) { 128 void AudioLogImpl::OnStopped(int component_id) {
129 SendSingleStringUpdate(component_id, kAudioLogStatusKey, "stopped"); 129 SendSingleStringUpdate(component_id, kAudioLogStatusKey, "stopped");
130 } 130 }
131 131
132 void AudioLogImpl::OnClosed(int component_id) { 132 void AudioLogImpl::OnClosed(int component_id) {
133 base::DictionaryValue dict; 133 base::DictionaryValue dict;
134 StoreComponentMetadata(component_id, &dict); 134 StoreComponentMetadata(component_id, &dict);
135 dict.SetString(kAudioLogStatusKey, "closed"); 135 dict.SetString(kAudioLogStatusKey, "closed");
136 media_internals_->SendUpdateAndPurgeCache( 136 media_internals_->SendUpdateAndPurgeAudioStreamCache(
137 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict); 137 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict);
138 } 138 }
139 139
140 void AudioLogImpl::OnError(int component_id) { 140 void AudioLogImpl::OnError(int component_id) {
141 SendSingleStringUpdate(component_id, "error_occurred", "true"); 141 SendSingleStringUpdate(component_id, "error_occurred", "true");
142 } 142 }
143 143
144 void AudioLogImpl::OnSetVolume(int component_id, double volume) { 144 void AudioLogImpl::OnSetVolume(int component_id, double volume) {
145 base::DictionaryValue dict; 145 base::DictionaryValue dict;
146 StoreComponentMetadata(component_id, &dict); 146 StoreComponentMetadata(component_id, &dict);
147 dict.SetDouble("volume", volume); 147 dict.SetDouble("volume", volume);
148 media_internals_->SendUpdateAndCache( 148 media_internals_->SendUpdateAndCacheAudioStreamKey(
149 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict); 149 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict);
150 } 150 }
151 151
152 std::string AudioLogImpl::FormatCacheKey(int component_id) { 152 std::string AudioLogImpl::FormatCacheKey(int component_id) {
153 return base::StringPrintf("%d:%d:%d", owner_id_, component_, component_id); 153 return base::StringPrintf("%d:%d:%d", owner_id_, component_, component_id);
154 } 154 }
155 155
156 void AudioLogImpl::SendSingleStringUpdate(int component_id, 156 void AudioLogImpl::SendSingleStringUpdate(int component_id,
157 const std::string& key, 157 const std::string& key,
158 const std::string& value) { 158 const std::string& value) {
159 base::DictionaryValue dict; 159 base::DictionaryValue dict;
160 StoreComponentMetadata(component_id, &dict); 160 StoreComponentMetadata(component_id, &dict);
161 dict.SetString(key, value); 161 dict.SetString(key, value);
162 media_internals_->SendUpdateAndCache( 162 media_internals_->SendUpdateAndCacheAudioStreamKey(
163 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict); 163 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict);
164 } 164 }
165 165
166 void AudioLogImpl::StoreComponentMetadata(int component_id, 166 void AudioLogImpl::StoreComponentMetadata(int component_id,
167 base::DictionaryValue* dict) { 167 base::DictionaryValue* dict) {
168 dict->SetInteger("owner_id", owner_id_); 168 dict->SetInteger("owner_id", owner_id_);
169 dict->SetInteger("component_id", component_id); 169 dict->SetInteger("component_id", component_id);
170 dict->SetInteger("component_type", component_); 170 dict->SetInteger("component_type", component_);
171 } 171 }
172 172
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
208 for (size_t i = 0; i < update_callbacks_.size(); ++i) { 208 for (size_t i = 0; i < update_callbacks_.size(); ++i) {
209 if (update_callbacks_[i].Equals(callback)) { 209 if (update_callbacks_[i].Equals(callback)) {
210 update_callbacks_.erase(update_callbacks_.begin() + i); 210 update_callbacks_.erase(update_callbacks_.begin() + i);
211 return; 211 return;
212 } 212 }
213 } 213 }
214 NOTREACHED(); 214 NOTREACHED();
215 } 215 }
216 216
217 void MediaInternals::SendEverything() { 217 void MediaInternals::SendAudioStreamData() {
218 base::string16 everything_update; 218 base::string16 audio_stream_update;
219 { 219 {
220 base::AutoLock auto_lock(lock_); 220 base::AutoLock auto_lock(lock_);
221 everything_update = SerializeUpdate( 221 audio_stream_update = SerializeUpdate(
222 "media.onReceiveEverything", &cached_data_); 222 "media.onReceiveEverything", &audio_streams_cached_data_);
223 } 223 }
224 SendUpdate(everything_update); 224 SendUpdate(audio_stream_update);
225 }
226
227 void MediaInternals::UpdateVideoCaptureDeviceCapabilities(
228 const std::vector<Tuple2<media::VideoCaptureDevice::Name,
229 media::VideoCaptureFormats> >& name_and_formats) {
230 DCHECK(video_devices_cached_data_.empty());
perkj_chrome 2014/10/07 15:51:23 You dont' need a member variable video_devices_cac
mcasas 2014/10/08 11:31:04 Done.
231
232 for (const auto &name_and_format : name_and_formats) {
233 base::DictionaryValue* formats_dict = new base::DictionaryValue();
234 formats_dict->SetString("Unique ID", name_and_format.a.id());
235 #if defined(OS_WIN) || defined(OS_MACOSX)
236 formats_dict->SetString("Capture API:",
237 name_and_format.a.capture_api_type());
burnik 2014/10/07 14:17:02 Looks like capture_api_type() is not a string. You
mcasas 2014/10/07 14:54:44 Yeah, just saw it :) It's more complex to add the
238 #endif
239 int cont = 0;
240 for (const auto &format : name_and_format.b) {
241 formats_dict->SetString(base::StringPrintf("[%3d]", cont++),
242 format.ToString());
243 }
244 video_devices_cached_data_.Set(name_and_format.a.GetNameAndModel(),
245 formats_dict);
246 }
247 // TODO(mcasas): Send the capabilities to JS in a similar way to what
perkj_chrome 2014/10/07 14:12:51 remove TODO. It does not belong in here.
mcasas 2014/10/07 14:54:44 I think it does, since it's to be removed in the n
perkj_chrome 2014/10/07 15:51:23 I see. I thought this was actually a comment about
248 // MediaInternals::SendAudioStreamData() does.
249 DVLOG(1) << "Received: " << video_devices_cached_data_;
250
251 video_devices_cached_data_.Clear();
perkj_chrome 2014/10/07 14:12:51 ?
mcasas 2014/10/07 14:54:44 This line goes with the previous TODO comment, IOW
perkj_chrome 2014/10/07 15:51:23 TODO remove once....
mcasas 2014/10/08 11:31:04 Gone anyway since I moved |video_devices_cached_da
252 }
253
254 scoped_ptr<media::AudioLog> MediaInternals::CreateAudioLog(
255 AudioComponent component) {
256 base::AutoLock auto_lock(lock_);
257 return scoped_ptr<media::AudioLog>(new AudioLogImpl(
258 owner_ids_[component]++, component, this));
225 } 259 }
226 260
227 void MediaInternals::SendUpdate(const base::string16& update) { 261 void MediaInternals::SendUpdate(const base::string16& update) {
228 // SendUpdate() may be called from any thread, but must run on the IO thread. 262 // SendUpdate() may be called from any thread, but must run on the IO thread.
229 // TODO(dalecurtis): This is pretty silly since the update callbacks simply 263 // TODO(dalecurtis): This is pretty silly since the update callbacks simply
230 // forward the calls to the UI thread. We should avoid the extra hop. 264 // forward the calls to the UI thread. We should avoid the extra hop.
231 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 265 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
232 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( 266 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
233 &MediaInternals::SendUpdate, base::Unretained(this), update)); 267 &MediaInternals::SendUpdate, base::Unretained(this), update));
234 return; 268 return;
235 } 269 }
236 270
237 for (size_t i = 0; i < update_callbacks_.size(); i++) 271 for (size_t i = 0; i < update_callbacks_.size(); i++)
238 update_callbacks_[i].Run(update); 272 update_callbacks_[i].Run(update);
239 } 273 }
240 274
241 scoped_ptr<media::AudioLog> MediaInternals::CreateAudioLog( 275 void MediaInternals::SendUpdateAndCacheAudioStreamKey(
242 AudioComponent component) { 276 const std::string& cache_key,
243 base::AutoLock auto_lock(lock_); 277 const std::string& function,
244 return scoped_ptr<media::AudioLog>(new AudioLogImpl( 278 const base::DictionaryValue* value) {
245 owner_ids_[component]++, component, this));
246 }
247
248 void MediaInternals::SendUpdateAndCache(const std::string& cache_key,
249 const std::string& function,
250 const base::DictionaryValue* value) {
251 SendUpdate(SerializeUpdate(function, value)); 279 SendUpdate(SerializeUpdate(function, value));
252 280
253 base::AutoLock auto_lock(lock_); 281 base::AutoLock auto_lock(lock_);
254 if (!cached_data_.HasKey(cache_key)) { 282 if (!audio_streams_cached_data_.HasKey(cache_key)) {
255 cached_data_.Set(cache_key, value->DeepCopy()); 283 audio_streams_cached_data_.Set(cache_key, value->DeepCopy());
256 return; 284 return;
257 } 285 }
258 286
259 base::DictionaryValue* existing_dict = NULL; 287 base::DictionaryValue* existing_dict = NULL;
260 CHECK(cached_data_.GetDictionary(cache_key, &existing_dict)); 288 CHECK(audio_streams_cached_data_.GetDictionary(cache_key, &existing_dict));
261 existing_dict->MergeDictionary(value); 289 existing_dict->MergeDictionary(value);
262 } 290 }
263 291
264 void MediaInternals::SendUpdateAndPurgeCache( 292 void MediaInternals::SendUpdateAndPurgeAudioStreamCache(
265 const std::string& cache_key, 293 const std::string& cache_key,
266 const std::string& function, 294 const std::string& function,
267 const base::DictionaryValue* value) { 295 const base::DictionaryValue* value) {
268 SendUpdate(SerializeUpdate(function, value)); 296 SendUpdate(SerializeUpdate(function, value));
269 297
270 base::AutoLock auto_lock(lock_); 298 base::AutoLock auto_lock(lock_);
271 scoped_ptr<base::Value> out_value; 299 scoped_ptr<base::Value> out_value;
272 CHECK(cached_data_.Remove(cache_key, &out_value)); 300 CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value));
273 } 301 }
274 302
275 } // namespace content 303 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698