OLD | NEW |
---|---|
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/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 if (effects == media::AudioParameters::NO_EFFECTS) | 35 if (effects == media::AudioParameters::NO_EFFECTS) |
36 return "NO_EFFECTS"; | 36 return "NO_EFFECTS"; |
37 | 37 |
38 struct { | 38 struct { |
39 int flag; | 39 int flag; |
40 const char* name; | 40 const char* name; |
41 } flags[] = { | 41 } flags[] = { |
42 { media::AudioParameters::ECHO_CANCELLER, "ECHO_CANCELLER" }, | 42 { media::AudioParameters::ECHO_CANCELLER, "ECHO_CANCELLER" }, |
43 { media::AudioParameters::DUCKING, "DUCKING" }, | 43 { media::AudioParameters::DUCKING, "DUCKING" }, |
44 { media::AudioParameters::KEYBOARD_MIC, "KEYBOARD_MIC" }, | 44 { media::AudioParameters::KEYBOARD_MIC, "KEYBOARD_MIC" }, |
45 { media::AudioParameters::HOTWORD, "HOTWORD" }, | |
45 }; | 46 }; |
46 | 47 |
47 std::string ret; | 48 std::string ret; |
48 for (size_t i = 0; i < arraysize(flags); ++i) { | 49 for (size_t i = 0; i < arraysize(flags); ++i) { |
49 if (effects & flags[i].flag) { | 50 if (effects & flags[i].flag) { |
50 if (!ret.empty()) | 51 if (!ret.empty()) |
51 ret += " | "; | 52 ret += " | "; |
52 ret += flags[i].name; | 53 ret += flags[i].name; |
53 effects &= ~flags[i].flag; | 54 effects &= ~flags[i].flag; |
54 } | 55 } |
55 } | 56 } |
56 | 57 |
57 if (effects) { | 58 if (effects) { |
58 if (!ret.empty()) | 59 if (!ret.empty()) |
59 ret += " | "; | 60 ret += " | "; |
60 ret += base::IntToString(effects); | 61 ret += base::IntToString(effects); |
61 } | 62 } |
62 | 63 |
63 return ret; | 64 return ret; |
64 } | 65 } |
65 | 66 |
67 std::string FormatToString(media::AudioParameters::Format format) { | |
68 switch (format) { | |
69 case media::AudioParameters::AUDIO_PCM_LINEAR: | |
70 return "pcm_linear"; | |
71 case media::AudioParameters::AUDIO_PCM_LOW_LATENCY: | |
72 return "pcm_low_latency"; | |
73 case media::AudioParameters::AUDIO_FAKE: | |
74 return "fake"; | |
75 default: | |
76 break; | |
watk
2015/02/05 20:48:44
Maybe you could remove the default case so we get
DaleCurtis
2015/02/05 21:14:54
Good idea. Added a NOTREACHED() too.
| |
77 } | |
78 | |
79 return "unknown"; | |
80 } | |
81 | |
66 const char kAudioLogStatusKey[] = "status"; | 82 const char kAudioLogStatusKey[] = "status"; |
67 const char kAudioLogUpdateFunction[] = "media.updateAudioComponent"; | 83 const char kAudioLogUpdateFunction[] = "media.updateAudioComponent"; |
68 | 84 |
69 } // namespace | 85 } // namespace |
70 | 86 |
71 namespace content { | 87 namespace content { |
72 | 88 |
73 class AudioLogImpl : public media::AudioLog { | 89 class AudioLogImpl : public media::AudioLog { |
74 public: | 90 public: |
75 AudioLogImpl(int owner_id, | 91 AudioLogImpl(int owner_id, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 AudioLogImpl::~AudioLogImpl() {} | 126 AudioLogImpl::~AudioLogImpl() {} |
111 | 127 |
112 void AudioLogImpl::OnCreated(int component_id, | 128 void AudioLogImpl::OnCreated(int component_id, |
113 const media::AudioParameters& params, | 129 const media::AudioParameters& params, |
114 const std::string& device_id) { | 130 const std::string& device_id) { |
115 base::DictionaryValue dict; | 131 base::DictionaryValue dict; |
116 StoreComponentMetadata(component_id, &dict); | 132 StoreComponentMetadata(component_id, &dict); |
117 | 133 |
118 dict.SetString(kAudioLogStatusKey, "created"); | 134 dict.SetString(kAudioLogStatusKey, "created"); |
119 dict.SetString("device_id", device_id); | 135 dict.SetString("device_id", device_id); |
136 dict.SetString("device_type", FormatToString(params.format())); | |
120 dict.SetInteger("frames_per_buffer", params.frames_per_buffer()); | 137 dict.SetInteger("frames_per_buffer", params.frames_per_buffer()); |
121 dict.SetInteger("sample_rate", params.sample_rate()); | 138 dict.SetInteger("sample_rate", params.sample_rate()); |
122 dict.SetInteger("channels", params.channels()); | 139 dict.SetInteger("channels", params.channels()); |
123 dict.SetString("channel_layout", | 140 dict.SetString("channel_layout", |
124 ChannelLayoutToString(params.channel_layout())); | 141 ChannelLayoutToString(params.channel_layout())); |
125 dict.SetString("effects", EffectsToString(params.effects())); | 142 dict.SetString("effects", EffectsToString(params.effects())); |
126 | 143 |
127 media_internals_->SendUpdateAndCacheAudioStreamKey( | 144 media_internals_->SendUpdateAndCacheAudioStreamKey( |
128 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict); | 145 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict); |
129 } | 146 } |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 const std::string& function, | 541 const std::string& function, |
525 const base::DictionaryValue* value) { | 542 const base::DictionaryValue* value) { |
526 SendUpdate(SerializeUpdate(function, value)); | 543 SendUpdate(SerializeUpdate(function, value)); |
527 | 544 |
528 base::AutoLock auto_lock(lock_); | 545 base::AutoLock auto_lock(lock_); |
529 scoped_ptr<base::Value> out_value; | 546 scoped_ptr<base::Value> out_value; |
530 CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value)); | 547 CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value)); |
531 } | 548 } |
532 | 549 |
533 } // namespace content | 550 } // namespace content |
OLD | NEW |