| 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" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "content/browser/renderer_host/media/media_stream_manager.h" | 14 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 16 #include "media/audio/audio_device_thread.h" |
| 16 #include "media/base/audio_parameters.h" | 17 #include "media/base/audio_parameters.h" |
| 17 | 18 |
| 18 using media::AudioBus; | 19 using media::AudioBus; |
| 19 using media::AudioOutputBuffer; | 20 using media::AudioOutputBuffer; |
| 21 using Packet = media::AudioDeviceThread::Packet; |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // Used to log if any audio glitches have been detected during an audio session. | 25 // Used to log if any audio glitches have been detected during an audio session. |
| 24 // Elements in this enum should not be added, deleted or rearranged. | 26 // Elements in this enum should not be added, deleted or rearranged. |
| 25 enum AudioGlitchResult { | 27 enum AudioGlitchResult { |
| 26 AUDIO_RENDERER_NO_AUDIO_GLITCHES = 0, | 28 AUDIO_RENDERER_NO_AUDIO_GLITCHES = 0, |
| 27 AUDIO_RENDERER_AUDIO_GLITCHES = 1, | 29 AUDIO_RENDERER_AUDIO_GLITCHES = 1, |
| 28 AUDIO_RENDERER_AUDIO_GLITCHES_MAX = AUDIO_RENDERER_AUDIO_GLITCHES | 30 AUDIO_RENDERER_AUDIO_GLITCHES_MAX = AUDIO_RENDERER_AUDIO_GLITCHES |
| 29 }; | 31 }; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 LogAudioGlitchResult(AUDIO_RENDERER_AUDIO_GLITCHES) : | 101 LogAudioGlitchResult(AUDIO_RENDERER_AUDIO_GLITCHES) : |
| 100 LogAudioGlitchResult(AUDIO_RENDERER_NO_AUDIO_GLITCHES); | 102 LogAudioGlitchResult(AUDIO_RENDERER_NO_AUDIO_GLITCHES); |
| 101 std::string log_string = | 103 std::string log_string = |
| 102 base::StringPrintf("ASR: number of detected audio glitches=%d", | 104 base::StringPrintf("ASR: number of detected audio glitches=%d", |
| 103 static_cast<int>(renderer_missed_callback_count_)); | 105 static_cast<int>(renderer_missed_callback_count_)); |
| 104 MediaStreamManager::SendMessageToNativeLog(log_string); | 106 MediaStreamManager::SendMessageToNativeLog(log_string); |
| 105 DVLOG(1) << log_string; | 107 DVLOG(1) << log_string; |
| 106 } | 108 } |
| 107 | 109 |
| 108 // media::AudioOutputController::SyncReader implementations. | 110 // media::AudioOutputController::SyncReader implementations. |
| 109 void AudioSyncReader::UpdatePendingBytes(uint32_t bytes, | 111 void AudioSyncReader::UpdatePendingBytes( |
| 110 uint32_t frames_skipped) { | 112 uint32_t bytes, |
| 113 uint32_t frames_skipped, |
| 114 const media::AudioTimestamp& output_timestamp) { |
| 111 // Increase the number of skipped frames stored in shared memory. We don't | 115 // Increase the number of skipped frames stored in shared memory. We don't |
| 112 // send it over the socket since sending more than 4 bytes might lead to being | 116 // send it over the socket since sending more than 4 bytes might lead to being |
| 113 // descheduled. The reading side will zero it when consumed. | 117 // descheduled. The reading side will zero it when consumed. |
| 114 AudioOutputBuffer* buffer = | 118 AudioOutputBuffer* buffer = |
| 115 reinterpret_cast<AudioOutputBuffer*>(shared_memory_->memory()); | 119 reinterpret_cast<AudioOutputBuffer*>(shared_memory_->memory()); |
| 116 buffer->params.frames_skipped += frames_skipped; | 120 buffer->params.frames_skipped += frames_skipped; |
| 117 | 121 |
| 118 // Zero out the entire output buffer to avoid stuttering/repeating-buffers | 122 // Zero out the entire output buffer to avoid stuttering/repeating-buffers |
| 119 // in the anomalous case if the renderer is unable to keep up with real-time. | 123 // in the anomalous case if the renderer is unable to keep up with real-time. |
| 120 output_bus_->Zero(); | 124 output_bus_->Zero(); |
| 121 | 125 |
| 122 socket_->Send(&bytes, sizeof(bytes)); | 126 Packet packet = {bytes, output_timestamp}; |
| 127 socket_->Send(&packet, sizeof(packet)); |
| 123 ++buffer_index_; | 128 ++buffer_index_; |
| 124 } | 129 } |
| 125 | 130 |
| 126 void AudioSyncReader::Read(AudioBus* dest) { | 131 void AudioSyncReader::Read(AudioBus* dest) { |
| 127 ++renderer_callback_count_; | 132 ++renderer_callback_count_; |
| 128 if (!WaitUntilDataIsReady()) { | 133 if (!WaitUntilDataIsReady()) { |
| 129 ++trailing_renderer_missed_callback_count_; | 134 ++trailing_renderer_missed_callback_count_; |
| 130 ++renderer_missed_callback_count_; | 135 ++renderer_missed_callback_count_; |
| 131 if (renderer_missed_callback_count_ <= 100) { | 136 if (renderer_missed_callback_count_ <= 100) { |
| 132 LOG(WARNING) << "AudioSyncReader::Read timed out, audio glitch count=" | 137 LOG(WARNING) << "AudioSyncReader::Read timed out, audio glitch count=" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 base::TimeDelta::FromMilliseconds(1), | 214 base::TimeDelta::FromMilliseconds(1), |
| 210 base::TimeDelta::FromMilliseconds(1000), | 215 base::TimeDelta::FromMilliseconds(1000), |
| 211 50); | 216 50); |
| 212 return false; | 217 return false; |
| 213 } | 218 } |
| 214 | 219 |
| 215 return true; | 220 return true; |
| 216 } | 221 } |
| 217 | 222 |
| 218 } // namespace content | 223 } // namespace content |
| OLD | NEW |