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 "ppapi/shared_impl/ppb_audio_shared.h" | 5 #include "ppapi/shared_impl/ppb_audio_shared.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 g_thread_functions = *functions; | 210 g_thread_functions = *functions; |
211 } | 211 } |
212 | 212 |
213 // static | 213 // static |
214 void PPB_Audio_Shared::CallRun(void* self) { | 214 void PPB_Audio_Shared::CallRun(void* self) { |
215 PPB_Audio_Shared* audio = static_cast<PPB_Audio_Shared*>(self); | 215 PPB_Audio_Shared* audio = static_cast<PPB_Audio_Shared*>(self); |
216 audio->Run(); | 216 audio->Run(); |
217 } | 217 } |
218 | 218 |
219 void PPB_Audio_Shared::Run() { | 219 void PPB_Audio_Shared::Run() { |
220 int pending_data = 0; | 220 int control_signal = 0; |
221 while (sizeof(pending_data) == | 221 while (sizeof(control_signal) == |
222 socket_->Receive(&pending_data, sizeof(pending_data))) { | 222 socket_->Receive(&control_signal, sizeof(control_signal))) { |
223 // |buffer_index_| must track the number of Receive() calls. See the Send() | 223 // |buffer_index_| must track the number of Receive() calls. See the Send() |
224 // call below for why this is important. | 224 // call below for why this is important. |
225 ++buffer_index_; | 225 ++buffer_index_; |
226 if (pending_data < 0) | 226 if (control_signal < 0) |
227 break; | 227 break; |
228 | 228 |
229 { | 229 { |
230 TRACE_EVENT0("audio", "PPB_Audio_Shared::FireRenderCallback"); | 230 TRACE_EVENT0("audio", "PPB_Audio_Shared::FireRenderCallback"); |
231 PP_TimeDelta latency = | 231 media::AudioOutputBuffer* buffer = |
232 static_cast<double>(pending_data) / bytes_per_second_; | 232 reinterpret_cast<media::AudioOutputBuffer*>(shared_memory_->memory()); |
233 callback_.Run( | 233 base::TimeDelta delay = |
234 client_buffer_.get(), client_buffer_size_bytes_, latency, user_data_); | 234 base::TimeDelta::FromMicroseconds(buffer->params.delay); |
| 235 |
| 236 callback_.Run(client_buffer_.get(), client_buffer_size_bytes_, |
| 237 delay.InSecondsF(), user_data_); |
235 } | 238 } |
236 | 239 |
237 // Deinterleave the audio data into the shared memory as floats. | 240 // Deinterleave the audio data into the shared memory as floats. |
238 audio_bus_->FromInterleaved(client_buffer_.get(), | 241 audio_bus_->FromInterleaved(client_buffer_.get(), |
239 audio_bus_->frames(), | 242 audio_bus_->frames(), |
240 kBitsPerAudioOutputSample / 8); | 243 kBitsPerAudioOutputSample / 8); |
241 | 244 |
242 // Let the other end know which buffer we just filled. The buffer index is | 245 // Let the other end know which buffer we just filled. The buffer index is |
243 // used to ensure the other end is getting the buffer it expects. For more | 246 // used to ensure the other end is getting the buffer it expects. For more |
244 // details on how this works see AudioSyncReader::WaitUntilDataIsReady(). | 247 // details on how this works see AudioSyncReader::WaitUntilDataIsReady(). |
245 size_t bytes_sent = socket_->Send(&buffer_index_, sizeof(buffer_index_)); | 248 size_t bytes_sent = socket_->Send(&buffer_index_, sizeof(buffer_index_)); |
246 if (bytes_sent != sizeof(buffer_index_)) | 249 if (bytes_sent != sizeof(buffer_index_)) |
247 break; | 250 break; |
248 } | 251 } |
249 } | 252 } |
250 | 253 |
251 } // namespace ppapi | 254 } // namespace ppapi |
OLD | NEW |