Chromium Code Reviews| 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 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/shared_memory.h" | 14 #include "base/memory/shared_memory.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "content/browser/renderer_host/media/media_stream_manager.h" | 19 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 20 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| 21 #include "media/audio/audio_device_thread.h" | |
| 21 #include "media/base/audio_parameters.h" | 22 #include "media/base/audio_parameters.h" |
| 22 | 23 |
| 23 using media::AudioBus; | 24 using media::AudioBus; |
| 24 using media::AudioOutputBuffer; | 25 using media::AudioOutputBuffer; |
| 26 using Packet = media::AudioDeviceThread::Packet; | |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 // Used to log if any audio glitches have been detected during an audio session. | 30 // Used to log if any audio glitches have been detected during an audio session. |
| 29 // Elements in this enum should not be added, deleted or rearranged. | 31 // Elements in this enum should not be added, deleted or rearranged. |
| 30 enum AudioGlitchResult { | 32 enum AudioGlitchResult { |
| 31 AUDIO_RENDERER_NO_AUDIO_GLITCHES = 0, | 33 AUDIO_RENDERER_NO_AUDIO_GLITCHES = 0, |
| 32 AUDIO_RENDERER_AUDIO_GLITCHES = 1, | 34 AUDIO_RENDERER_AUDIO_GLITCHES = 1, |
| 33 AUDIO_RENDERER_AUDIO_GLITCHES_MAX = AUDIO_RENDERER_AUDIO_GLITCHES | 35 AUDIO_RENDERER_AUDIO_GLITCHES_MAX = AUDIO_RENDERER_AUDIO_GLITCHES |
| 34 }; | 36 }; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 !base::CancelableSyncSocket::CreatePair(socket.get(), | 135 !base::CancelableSyncSocket::CreatePair(socket.get(), |
| 134 foreign_socket.get())) { | 136 foreign_socket.get())) { |
| 135 return nullptr; | 137 return nullptr; |
| 136 } | 138 } |
| 137 return base::WrapUnique(new AudioSyncReader(params, std::move(shared_memory), | 139 return base::WrapUnique(new AudioSyncReader(params, std::move(shared_memory), |
| 138 std::move(socket), | 140 std::move(socket), |
| 139 std::move(foreign_socket))); | 141 std::move(foreign_socket))); |
| 140 } | 142 } |
| 141 | 143 |
| 142 // media::AudioOutputController::SyncReader implementations. | 144 // media::AudioOutputController::SyncReader implementations. |
| 143 void AudioSyncReader::UpdatePendingBytes(uint32_t bytes, | 145 void AudioSyncReader::PrepareNextData(base::TimeDelta delay, |
| 144 uint32_t frames_skipped) { | 146 base::TimeTicks delay_timestamp, |
| 147 uint32_t frames_skipped) { | |
| 145 // Increase the number of skipped frames stored in shared memory. We don't | 148 // Increase the number of skipped frames stored in shared memory. We don't |
| 146 // send it over the socket since sending more than 4 bytes might lead to being | 149 // send it over the socket since sending more than 4 bytes might lead to being |
| 147 // descheduled. The reading side will zero it when consumed. | 150 // descheduled. The reading side will zero it when consumed. |
| 148 AudioOutputBuffer* buffer = | 151 AudioOutputBuffer* buffer = |
| 149 reinterpret_cast<AudioOutputBuffer*>(shared_memory_->memory()); | 152 reinterpret_cast<AudioOutputBuffer*>(shared_memory_->memory()); |
| 150 buffer->params.frames_skipped += frames_skipped; | 153 buffer->params.frames_skipped += frames_skipped; |
| 151 | 154 |
| 152 // Zero out the entire output buffer to avoid stuttering/repeating-buffers | 155 // Zero out the entire output buffer to avoid stuttering/repeating-buffers |
| 153 // in the anomalous case if the renderer is unable to keep up with real-time. | 156 // in the anomalous case if the renderer is unable to keep up with real-time. |
| 154 output_bus_->Zero(); | 157 output_bus_->Zero(); |
| 155 | 158 |
| 156 socket_->Send(&bytes, sizeof(bytes)); | 159 Packet packet = {delay.ToInternalValue(), delay_timestamp.ToInternalValue()}; |
|
DaleCurtis
2016/10/20 18:35:29
In the past, there were concerns that sending more
miu
2016/10/23 01:19:15
ditto here: Please use InMicroseconds() instead of
Mikhail
2016/10/24 19:50:23
Done.
| |
| 160 socket_->Send(&packet, sizeof(packet)); | |
| 157 ++buffer_index_; | 161 ++buffer_index_; |
| 158 } | 162 } |
| 159 | 163 |
| 160 void AudioSyncReader::Read(AudioBus* dest) { | 164 void AudioSyncReader::Read(AudioBus* dest) { |
| 161 ++renderer_callback_count_; | 165 ++renderer_callback_count_; |
| 162 if (!WaitUntilDataIsReady()) { | 166 if (!WaitUntilDataIsReady()) { |
| 163 ++trailing_renderer_missed_callback_count_; | 167 ++trailing_renderer_missed_callback_count_; |
| 164 ++renderer_missed_callback_count_; | 168 ++renderer_missed_callback_count_; |
| 165 if (renderer_missed_callback_count_ <= 100) { | 169 if (renderer_missed_callback_count_ <= 100) { |
| 166 LOG(WARNING) << "AudioSyncReader::Read timed out, audio glitch count=" | 170 LOG(WARNING) << "AudioSyncReader::Read timed out, audio glitch count=" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 base::TimeDelta::FromMilliseconds(1), | 236 base::TimeDelta::FromMilliseconds(1), |
| 233 base::TimeDelta::FromMilliseconds(1000), | 237 base::TimeDelta::FromMilliseconds(1000), |
| 234 50); | 238 50); |
| 235 return false; | 239 return false; |
| 236 } | 240 } |
| 237 | 241 |
| 238 return true; | 242 return true; |
| 239 } | 243 } |
| 240 | 244 |
| 241 } // namespace content | 245 } // namespace content |
| OLD | NEW |