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