| 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 case media::AudioParameters::AUDIO_LAST_FORMAT: |
| 76 break; |
| 77 } |
| 78 |
| 79 NOTREACHED(); |
| 80 return "unknown"; |
| 81 } |
| 82 |
| 66 const char kAudioLogStatusKey[] = "status"; | 83 const char kAudioLogStatusKey[] = "status"; |
| 67 const char kAudioLogUpdateFunction[] = "media.updateAudioComponent"; | 84 const char kAudioLogUpdateFunction[] = "media.updateAudioComponent"; |
| 68 | 85 |
| 69 } // namespace | 86 } // namespace |
| 70 | 87 |
| 71 namespace content { | 88 namespace content { |
| 72 | 89 |
| 73 class AudioLogImpl : public media::AudioLog { | 90 class AudioLogImpl : public media::AudioLog { |
| 74 public: | 91 public: |
| 75 AudioLogImpl(int owner_id, | 92 AudioLogImpl(int owner_id, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 AudioLogImpl::~AudioLogImpl() {} | 127 AudioLogImpl::~AudioLogImpl() {} |
| 111 | 128 |
| 112 void AudioLogImpl::OnCreated(int component_id, | 129 void AudioLogImpl::OnCreated(int component_id, |
| 113 const media::AudioParameters& params, | 130 const media::AudioParameters& params, |
| 114 const std::string& device_id) { | 131 const std::string& device_id) { |
| 115 base::DictionaryValue dict; | 132 base::DictionaryValue dict; |
| 116 StoreComponentMetadata(component_id, &dict); | 133 StoreComponentMetadata(component_id, &dict); |
| 117 | 134 |
| 118 dict.SetString(kAudioLogStatusKey, "created"); | 135 dict.SetString(kAudioLogStatusKey, "created"); |
| 119 dict.SetString("device_id", device_id); | 136 dict.SetString("device_id", device_id); |
| 137 dict.SetString("device_type", FormatToString(params.format())); |
| 120 dict.SetInteger("frames_per_buffer", params.frames_per_buffer()); | 138 dict.SetInteger("frames_per_buffer", params.frames_per_buffer()); |
| 121 dict.SetInteger("sample_rate", params.sample_rate()); | 139 dict.SetInteger("sample_rate", params.sample_rate()); |
| 122 dict.SetInteger("channels", params.channels()); | 140 dict.SetInteger("channels", params.channels()); |
| 123 dict.SetString("channel_layout", | 141 dict.SetString("channel_layout", |
| 124 ChannelLayoutToString(params.channel_layout())); | 142 ChannelLayoutToString(params.channel_layout())); |
| 125 dict.SetString("effects", EffectsToString(params.effects())); | 143 dict.SetString("effects", EffectsToString(params.effects())); |
| 126 | 144 |
| 127 media_internals_->SendUpdateAndCacheAudioStreamKey( | 145 media_internals_->SendUpdateAndCacheAudioStreamKey( |
| 128 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict); | 146 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict); |
| 129 } | 147 } |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 const std::string& function, | 542 const std::string& function, |
| 525 const base::DictionaryValue* value) { | 543 const base::DictionaryValue* value) { |
| 526 SendUpdate(SerializeUpdate(function, value)); | 544 SendUpdate(SerializeUpdate(function, value)); |
| 527 | 545 |
| 528 base::AutoLock auto_lock(lock_); | 546 base::AutoLock auto_lock(lock_); |
| 529 scoped_ptr<base::Value> out_value; | 547 scoped_ptr<base::Value> out_value; |
| 530 CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value)); | 548 CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value)); |
| 531 } | 549 } |
| 532 | 550 |
| 533 } // namespace content | 551 } // namespace content |
| OLD | NEW |