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

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

Issue 187593004: Hook up AudioDeviceListenerWin to monitor all default device changes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 6 years, 9 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/stringprintf.h" 9 #include "base/strings/stringprintf.h"
9 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/web_ui.h" 11 #include "content/public/browser/web_ui.h"
11 #include "media/audio/audio_parameters.h" 12 #include "media/audio/audio_parameters.h"
12 #include "media/base/media_log.h" 13 #include "media/base/media_log.h"
13 #include "media/base/media_log_event.h" 14 #include "media/base/media_log_event.h"
14 15
15 namespace { 16 namespace {
16 17
17 static base::LazyInstance<content::MediaInternals>::Leaky g_media_internals = 18 static base::LazyInstance<content::MediaInternals>::Leaky g_media_internals =
18 LAZY_INSTANCE_INITIALIZER; 19 LAZY_INSTANCE_INITIALIZER;
19 20
20 base::string16 SerializeUpdate(const std::string& function, 21 base::string16 SerializeUpdate(const std::string& function,
21 const base::Value* value) { 22 const base::Value* value) {
22 return content::WebUI::GetJavascriptCall( 23 return content::WebUI::GetJavascriptCall(
23 function, std::vector<const base::Value*>(1, value)); 24 function, std::vector<const base::Value*>(1, value));
24 } 25 }
25 26
27 std::string EffectsToString(int effects) {
28 if (effects == media::AudioParameters::NO_EFFECTS)
29 return "NO_EFFECTS";
30
31 struct {
32 int flag;
33 const char* name;
34 } flags[] = {
35 { media::AudioParameters::ECHO_CANCELLER, "ECHO_CANCELLER" },
36 { media::AudioParameters::DUCKING, "DUCKING" },
37 };
38
39 std::string ret;
40 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(flags); ++i) {
41 if (effects & flags[i].flag) {
42 if (!ret.empty())
43 ret += " | ";
44 ret += flags[i].name;
45 effects &= ~flags[i].flag;
46 }
47 }
48
49 if (effects) {
50 if (!ret.empty())
51 ret += " | ";
52 ret += base::IntToString(effects);
53 }
54
55 return ret;
56 }
57
26 const char kAudioLogStatusKey[] = "status"; 58 const char kAudioLogStatusKey[] = "status";
27 const char kAudioLogUpdateFunction[] = "media.updateAudioComponent"; 59 const char kAudioLogUpdateFunction[] = "media.updateAudioComponent";
28 60
29 } // namespace 61 } // namespace
30 62
31 namespace content { 63 namespace content {
32 64
33 class AudioLogImpl : public media::AudioLog { 65 class AudioLogImpl : public media::AudioLog {
34 public: 66 public:
35 AudioLogImpl(int owner_id, 67 AudioLogImpl(int owner_id,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 StoreComponentMetadata(component_id, &dict); 108 StoreComponentMetadata(component_id, &dict);
77 109
78 dict.SetString(kAudioLogStatusKey, "created"); 110 dict.SetString(kAudioLogStatusKey, "created");
79 dict.SetString("device_id", device_id); 111 dict.SetString("device_id", device_id);
80 dict.SetInteger("input_channels", params.input_channels()); 112 dict.SetInteger("input_channels", params.input_channels());
81 dict.SetInteger("frames_per_buffer", params.frames_per_buffer()); 113 dict.SetInteger("frames_per_buffer", params.frames_per_buffer());
82 dict.SetInteger("sample_rate", params.sample_rate()); 114 dict.SetInteger("sample_rate", params.sample_rate());
83 dict.SetInteger("channels", params.channels()); 115 dict.SetInteger("channels", params.channels());
84 dict.SetString("channel_layout", 116 dict.SetString("channel_layout",
85 ChannelLayoutToString(params.channel_layout())); 117 ChannelLayoutToString(params.channel_layout()));
118 dict.SetString("effects", EffectsToString(params.effects()));
86 119
87 media_internals_->SendUpdateAndCache( 120 media_internals_->SendUpdateAndCache(
88 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict); 121 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict);
89 } 122 }
90 123
91 void AudioLogImpl::OnStarted(int component_id) { 124 void AudioLogImpl::OnStarted(int component_id) {
92 SendSingleStringUpdate(component_id, kAudioLogStatusKey, "started"); 125 SendSingleStringUpdate(component_id, kAudioLogStatusKey, "started");
93 } 126 }
94 127
95 void AudioLogImpl::OnStopped(int component_id) { 128 void AudioLogImpl::OnStopped(int component_id) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 const std::string& function, 266 const std::string& function,
234 const base::DictionaryValue* value) { 267 const base::DictionaryValue* value) {
235 SendUpdate(SerializeUpdate(function, value)); 268 SendUpdate(SerializeUpdate(function, value));
236 269
237 base::AutoLock auto_lock(lock_); 270 base::AutoLock auto_lock(lock_);
238 scoped_ptr<base::Value> out_value; 271 scoped_ptr<base::Value> out_value;
239 CHECK(cached_data_.Remove(cache_key, &out_value)); 272 CHECK(cached_data_.Remove(cache_key, &out_value));
240 } 273 }
241 274
242 } // namespace content 275 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/media/media_internals_unittest.cc » ('j') | media/audio/win/audio_device_listener_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698