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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 packet_size_(shared_memory_->requested_size()), | 44 packet_size_(shared_memory_->requested_size()), |
45 renderer_callback_count_(0), | 45 renderer_callback_count_(0), |
46 renderer_missed_callback_count_(0), | 46 renderer_missed_callback_count_(0), |
47 #if defined(OS_MACOSX) | 47 #if defined(OS_MACOSX) |
48 maximum_wait_time_(params.GetBufferDuration() / 2), | 48 maximum_wait_time_(params.GetBufferDuration() / 2), |
49 #else | 49 #else |
50 // TODO(dalecurtis): Investigate if we can reduce this on all platforms. | 50 // TODO(dalecurtis): Investigate if we can reduce this on all platforms. |
51 maximum_wait_time_(base::TimeDelta::FromMilliseconds(20)), | 51 maximum_wait_time_(base::TimeDelta::FromMilliseconds(20)), |
52 #endif | 52 #endif |
53 buffer_index_(0) { | 53 buffer_index_(0) { |
54 DCHECK_EQ(packet_size_, AudioBus::CalculateMemorySize(params)); | 54 DCHECK_EQ(packet_size_, sizeof(AudioOutputBufferParameters) + |
55 output_bus_ = AudioBus::WrapMemory(params, shared_memory->memory()); | 55 AudioBus::CalculateMemorySize(params)); |
56 AudioOutputBuffer* buffer = | |
57 reinterpret_cast<AudioOutputBuffer*>(shared_memory_->memory()); | |
58 output_bus_ = AudioBus::WrapMemory(params, buffer->audio); | |
56 output_bus_->Zero(); | 59 output_bus_->Zero(); |
57 } | 60 } |
58 | 61 |
59 AudioSyncReader::~AudioSyncReader() { | 62 AudioSyncReader::~AudioSyncReader() { |
60 if (!renderer_callback_count_) | 63 if (!renderer_callback_count_) |
61 return; | 64 return; |
62 | 65 |
63 // Recording the percentage of deadline misses gives us a rough overview of | 66 // Recording the percentage of deadline misses gives us a rough overview of |
64 // how many users might be running into audio glitches. | 67 // how many users might be running into audio glitches. |
65 int percentage_missed = | 68 int percentage_missed = |
66 100.0 * renderer_missed_callback_count_ / renderer_callback_count_; | 69 100.0 * renderer_missed_callback_count_ / renderer_callback_count_; |
67 UMA_HISTOGRAM_PERCENTAGE( | 70 UMA_HISTOGRAM_PERCENTAGE( |
68 "Media.AudioRendererMissedDeadline", percentage_missed); | 71 "Media.AudioRendererMissedDeadline", percentage_missed); |
69 | 72 |
70 // Add more detailed information regarding detected audio glitches where | 73 // Add more detailed information regarding detected audio glitches where |
71 // a non-zero value of |renderer_missed_callback_count_| is added to the | 74 // a non-zero value of |renderer_missed_callback_count_| is added to the |
72 // AUDIO_RENDERER_AUDIO_GLITCHES bin. | 75 // AUDIO_RENDERER_AUDIO_GLITCHES bin. |
73 renderer_missed_callback_count_ > 0 ? | 76 renderer_missed_callback_count_ > 0 ? |
74 LogAudioGlitchResult(AUDIO_RENDERER_AUDIO_GLITCHES) : | 77 LogAudioGlitchResult(AUDIO_RENDERER_AUDIO_GLITCHES) : |
75 LogAudioGlitchResult(AUDIO_RENDERER_NO_AUDIO_GLITCHES); | 78 LogAudioGlitchResult(AUDIO_RENDERER_NO_AUDIO_GLITCHES); |
76 std::string log_string = | 79 std::string log_string = |
77 base::StringPrintf("ASR: number of detected audio glitches=%d", | 80 base::StringPrintf("ASR: number of detected audio glitches=%d", |
78 static_cast<int>(renderer_missed_callback_count_)); | 81 static_cast<int>(renderer_missed_callback_count_)); |
79 MediaStreamManager::SendMessageToNativeLog(log_string); | 82 MediaStreamManager::SendMessageToNativeLog(log_string); |
80 DVLOG(1) << log_string; | 83 DVLOG(1) << log_string; |
81 } | 84 } |
82 | 85 |
83 // media::AudioOutputController::SyncReader implementations. | 86 // media::AudioOutputController::SyncReader implementations. |
84 void AudioSyncReader::UpdatePendingBytes(uint32 bytes) { | 87 void AudioSyncReader::UpdatePendingBytes(uint32_t bytes, |
88 uint32_t frames_skipped) { | |
89 // Increase the number of skipped frames stored in shared memory. We don't | |
tommi (sloooow) - chröme
2015/12/08 08:34:51
why do we increase the number of skipped frames?
I
Henrik Grunell
2015/12/08 09:30:34
Afaict, there is a possibility that we write more
tommi (sloooow) - chröme
2015/12/08 10:08:09
Do we still overwrite in that case? I thought we w
Henrik Grunell
2015/12/08 11:12:32
If Wait...() times out, we'll give the OS an empty
tommi (sloooow) - chröme
2015/12/08 11:43:02
I think I'm out of brain power... can you help me
tommi (sloooow) - chröme
2015/12/08 12:27:39
Got some brain power back :) I realize now that I
Henrik Grunell
2015/12/08 12:56:10
:) I'm glad you could.
| |
90 // send it over the socket since sending more than 4 bytes might lead to being | |
91 // descheduled. The reading side will zero it when consumed. | |
92 AudioOutputBuffer* buffer = | |
93 reinterpret_cast<AudioOutputBuffer*>(shared_memory_->memory()); | |
94 buffer->params.frames_skipped += frames_skipped; | |
95 | |
85 // Zero out the entire output buffer to avoid stuttering/repeating-buffers | 96 // Zero out the entire output buffer to avoid stuttering/repeating-buffers |
86 // in the anomalous case if the renderer is unable to keep up with real-time. | 97 // in the anomalous case if the renderer is unable to keep up with real-time. |
87 output_bus_->Zero(); | 98 output_bus_->Zero(); |
99 | |
88 socket_->Send(&bytes, sizeof(bytes)); | 100 socket_->Send(&bytes, sizeof(bytes)); |
89 ++buffer_index_; | 101 ++buffer_index_; |
90 } | 102 } |
91 | 103 |
92 void AudioSyncReader::Read(AudioBus* dest) { | 104 void AudioSyncReader::Read(AudioBus* dest) { |
93 ++renderer_callback_count_; | 105 ++renderer_callback_count_; |
94 if (!WaitUntilDataIsReady()) { | 106 if (!WaitUntilDataIsReady()) { |
95 ++renderer_missed_callback_count_; | 107 ++renderer_missed_callback_count_; |
96 if (renderer_missed_callback_count_ <= 100) { | 108 if (renderer_missed_callback_count_ <= 100) { |
97 LOG(WARNING) << "AudioSyncReader::Read timed out, audio glitch count=" | 109 LOG(WARNING) << "AudioSyncReader::Read timed out, audio glitch count=" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 base::TimeDelta::FromMilliseconds(1), | 184 base::TimeDelta::FromMilliseconds(1), |
173 base::TimeDelta::FromMilliseconds(1000), | 185 base::TimeDelta::FromMilliseconds(1000), |
174 50); | 186 50); |
175 return false; | 187 return false; |
176 } | 188 } |
177 | 189 |
178 return true; | 190 return true; |
179 } | 191 } |
180 | 192 |
181 } // namespace content | 193 } // namespace content |
OLD | NEW |