| 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/renderer_host/media/audio_sync_reader.h" | 5 #include "content/browser/renderer_host/media/audio_sync_reader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/strings/stringprintf.h" | |
| 13 #include "content/browser/renderer_host/media/media_stream_manager.h" | |
| 14 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
| 15 #include "media/audio/audio_buffers_state.h" | 13 #include "media/audio/audio_buffers_state.h" |
| 16 #include "media/audio/audio_parameters.h" | 14 #include "media/audio/audio_parameters.h" |
| 17 | 15 |
| 18 using media::AudioBus; | 16 using media::AudioBus; |
| 19 | 17 |
| 20 namespace { | |
| 21 | |
| 22 // Used to log if any audio glitches have been detected during an audio session. | |
| 23 // Elements in this enum should not be added, deleted or rearranged. | |
| 24 enum AudioGlitchResult { | |
| 25 AUDIO_RENDERER_NO_AUDIO_GLITCHES = 0, | |
| 26 AUDIO_RENDERER_AUDIO_GLITCHES = 1, | |
| 27 AUDIO_RENDERER_AUDIO_GLITCHES_MAX = AUDIO_RENDERER_AUDIO_GLITCHES | |
| 28 }; | |
| 29 | |
| 30 void LogAudioGlitchResult(AudioGlitchResult result) { | |
| 31 UMA_HISTOGRAM_ENUMERATION("Media.AudioRendererAudioGlitches", | |
| 32 result, | |
| 33 AUDIO_RENDERER_AUDIO_GLITCHES_MAX + 1); | |
| 34 } | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 namespace content { | 18 namespace content { |
| 39 | 19 |
| 40 AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory, | 20 AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory, |
| 41 const media::AudioParameters& params) | 21 const media::AudioParameters& params) |
| 42 : shared_memory_(shared_memory), | 22 : shared_memory_(shared_memory), |
| 43 mute_audio_(CommandLine::ForCurrentProcess()->HasSwitch( | 23 mute_audio_(CommandLine::ForCurrentProcess()->HasSwitch( |
| 44 switches::kMuteAudio)), | 24 switches::kMuteAudio)), |
| 45 packet_size_(shared_memory_->requested_size()), | 25 packet_size_(shared_memory_->requested_size()), |
| 46 renderer_callback_count_(0), | 26 renderer_callback_count_(0), |
| 47 renderer_missed_callback_count_(0), | 27 renderer_missed_callback_count_(0), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 60 AudioSyncReader::~AudioSyncReader() { | 40 AudioSyncReader::~AudioSyncReader() { |
| 61 if (!renderer_callback_count_) | 41 if (!renderer_callback_count_) |
| 62 return; | 42 return; |
| 63 | 43 |
| 64 // Recording the percentage of deadline misses gives us a rough overview of | 44 // Recording the percentage of deadline misses gives us a rough overview of |
| 65 // how many users might be running into audio glitches. | 45 // how many users might be running into audio glitches. |
| 66 int percentage_missed = | 46 int percentage_missed = |
| 67 100.0 * renderer_missed_callback_count_ / renderer_callback_count_; | 47 100.0 * renderer_missed_callback_count_ / renderer_callback_count_; |
| 68 UMA_HISTOGRAM_PERCENTAGE( | 48 UMA_HISTOGRAM_PERCENTAGE( |
| 69 "Media.AudioRendererMissedDeadline", percentage_missed); | 49 "Media.AudioRendererMissedDeadline", percentage_missed); |
| 70 | |
| 71 // Add more detailed information regarding detected audio glitches where | |
| 72 // a non-zero value of |renderer_missed_callback_count_| is added to the | |
| 73 // AUDIO_RENDERER_AUDIO_GLITCHES bin. | |
| 74 renderer_missed_callback_count_ > 0 ? | |
| 75 LogAudioGlitchResult(AUDIO_RENDERER_AUDIO_GLITCHES) : | |
| 76 LogAudioGlitchResult(AUDIO_RENDERER_NO_AUDIO_GLITCHES); | |
| 77 std::string log_string = base::StringPrintf( | |
| 78 "ASR: number of detected audio glitches=%ld", | |
| 79 renderer_missed_callback_count_); | |
| 80 MediaStreamManager::SendMessageToNativeLog(log_string); | |
| 81 DVLOG(1) << log_string; | |
| 82 } | 50 } |
| 83 | 51 |
| 84 // media::AudioOutputController::SyncReader implementations. | 52 // media::AudioOutputController::SyncReader implementations. |
| 85 void AudioSyncReader::UpdatePendingBytes(uint32 bytes) { | 53 void AudioSyncReader::UpdatePendingBytes(uint32 bytes) { |
| 86 // Zero out the entire output buffer to avoid stuttering/repeating-buffers | 54 // Zero out the entire output buffer to avoid stuttering/repeating-buffers |
| 87 // in the anomalous case if the renderer is unable to keep up with real-time. | 55 // in the anomalous case if the renderer is unable to keep up with real-time. |
| 88 output_bus_->Zero(); | 56 output_bus_->Zero(); |
| 89 socket_->Send(&bytes, sizeof(bytes)); | 57 socket_->Send(&bytes, sizeof(bytes)); |
| 90 ++buffer_index_; | 58 ++buffer_index_; |
| 91 } | 59 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 base::TimeDelta::FromMilliseconds(1), | 147 base::TimeDelta::FromMilliseconds(1), |
| 180 base::TimeDelta::FromMilliseconds(1000), | 148 base::TimeDelta::FromMilliseconds(1000), |
| 181 50); | 149 50); |
| 182 return false; | 150 return false; |
| 183 } | 151 } |
| 184 | 152 |
| 185 return true; | 153 return true; |
| 186 } | 154 } |
| 187 | 155 |
| 188 } // namespace content | 156 } // namespace content |
| OLD | NEW |