Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: content/browser/renderer_host/media/audio_sync_reader.cc

Issue 2517503003: Reland: Make more media APIs aware of |delay| and |delay_timestamp| (Closed)
Patch Set: Comments from chcunningham@ and Dale Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
25 26
26 namespace { 27 namespace {
27 28
28 // Used to log if any audio glitches have been detected during an audio session. 29 // 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. 30 // Elements in this enum should not be added, deleted or rearranged.
30 enum AudioGlitchResult { 31 enum AudioGlitchResult {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 !base::CancelableSyncSocket::CreatePair(socket.get(), 134 !base::CancelableSyncSocket::CreatePair(socket.get(),
134 foreign_socket.get())) { 135 foreign_socket.get())) {
135 return nullptr; 136 return nullptr;
136 } 137 }
137 return base::WrapUnique(new AudioSyncReader(params, std::move(shared_memory), 138 return base::WrapUnique(new AudioSyncReader(params, std::move(shared_memory),
138 std::move(socket), 139 std::move(socket),
139 std::move(foreign_socket))); 140 std::move(foreign_socket)));
140 } 141 }
141 142
142 // media::AudioOutputController::SyncReader implementations. 143 // media::AudioOutputController::SyncReader implementations.
143 void AudioSyncReader::UpdatePendingBytes(uint32_t bytes, 144 void AudioSyncReader::RequestMoreData(base::TimeDelta delay,
144 uint32_t frames_skipped) { 145 base::TimeTicks delay_timestamp,
145 // Increase the number of skipped frames stored in shared memory. We don't 146 int prior_frames_skipped) {
146 // send it over the socket since sending more than 4 bytes might lead to being 147 // We don't send arguments over the socket since sending more than 4
147 // descheduled. The reading side will zero it when consumed. 148 // bytes might lead to being descheduled. The reading side will zero
149 // them when consumed.
148 AudioOutputBuffer* buffer = 150 AudioOutputBuffer* buffer =
149 reinterpret_cast<AudioOutputBuffer*>(shared_memory_->memory()); 151 reinterpret_cast<AudioOutputBuffer*>(shared_memory_->memory());
150 buffer->params.frames_skipped += frames_skipped; 152 // Increase the number of skipped frames stored in shared memory.
153 buffer->params.frames_skipped += prior_frames_skipped;
154 buffer->params.delay = delay.InMicroseconds();
155 buffer->params.delay_timestamp
156 = (delay_timestamp - base::TimeTicks()).InMicroseconds();
151 157
152 // Zero out the entire output buffer to avoid stuttering/repeating-buffers 158 // 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. 159 // in the anomalous case if the renderer is unable to keep up with real-time.
154 output_bus_->Zero(); 160 output_bus_->Zero();
155 161
156 socket_->Send(&bytes, sizeof(bytes)); 162 uint32_t control_signal = 0;
163 if (delay.is_max()) {
164 // std::numeric_limits<uint32_t>::max() is a special signal which is
165 // returned after the browser stops the output device in response to a
166 // renderer side request.
167 control_signal = std::numeric_limits<uint32_t>::max();
168 }
169
170 size_t sent_bytes = socket_->Send(&control_signal, sizeof(control_signal));
171 if (sent_bytes != sizeof(control_signal)) {
172 const std::string error_message = "ASR: No room in socket buffer.";
173 LOG(WARNING) << error_message;
174 MediaStreamManager::SendMessageToNativeLog(error_message);
175 TRACE_EVENT_INSTANT0("audio",
176 "AudioSyncReader: No room in socket buffer",
177 TRACE_EVENT_SCOPE_THREAD);
178 }
157 ++buffer_index_; 179 ++buffer_index_;
158 } 180 }
159 181
160 void AudioSyncReader::Read(AudioBus* dest) { 182 void AudioSyncReader::Read(AudioBus* dest) {
161 ++renderer_callback_count_; 183 ++renderer_callback_count_;
162 if (!WaitUntilDataIsReady()) { 184 if (!WaitUntilDataIsReady()) {
163 ++trailing_renderer_missed_callback_count_; 185 ++trailing_renderer_missed_callback_count_;
164 ++renderer_missed_callback_count_; 186 ++renderer_missed_callback_count_;
165 if (renderer_missed_callback_count_ <= 100) { 187 if (renderer_missed_callback_count_ <= 100) {
166 LOG(WARNING) << "AudioSyncReader::Read timed out, audio glitch count=" 188 LOG(WARNING) << "AudioSyncReader::Read timed out, audio glitch count="
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 base::TimeDelta::FromMilliseconds(1), 254 base::TimeDelta::FromMilliseconds(1),
233 base::TimeDelta::FromMilliseconds(1000), 255 base::TimeDelta::FromMilliseconds(1000),
234 50); 256 50);
235 return false; 257 return false;
236 } 258 }
237 259
238 return true; 260 return true;
239 } 261 }
240 262
241 } // namespace content 263 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_sync_reader.h ('k') | content/renderer/media/renderer_webaudiodevice_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698