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 "media/audio/audio_output_device.h" | 5 #include "media/audio/audio_output_device.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 SetActualDataSizeInBytes(&shared_memory_, memory_length_, 0); | 259 SetActualDataSizeInBytes(&shared_memory_, memory_length_, 0); |
260 return; | 260 return; |
261 } | 261 } |
262 | 262 |
263 // Convert the number of pending bytes in the render buffer | 263 // Convert the number of pending bytes in the render buffer |
264 // into milliseconds. | 264 // into milliseconds. |
265 int audio_delay_milliseconds = pending_data / bytes_per_ms_; | 265 int audio_delay_milliseconds = pending_data / bytes_per_ms_; |
266 | 266 |
267 TRACE_EVENT0("audio", "AudioOutputDevice::FireRenderCallback"); | 267 TRACE_EVENT0("audio", "AudioOutputDevice::FireRenderCallback"); |
268 | 268 |
269 // Update the audio-delay measurement then ask client to render audio. | 269 // Update the audio-delay measurement then ask client to render audio. Since |
| 270 // |audio_bus_| is wrapping the shared memory the Render() call is writing |
| 271 // directly into the shared memory. |
270 size_t num_frames = render_callback_->Render( | 272 size_t num_frames = render_callback_->Render( |
271 audio_bus_.get(), audio_delay_milliseconds); | 273 audio_bus_.get(), audio_delay_milliseconds); |
272 | 274 |
273 // Interleave, scale, and clip to int. | |
274 // TODO(dalecurtis): Remove this when we have float everywhere: | |
275 // http://crbug.com/114700 | |
276 audio_bus_->ToInterleaved(num_frames, audio_parameters_.bits_per_sample() / 8, | |
277 shared_memory_.memory()); | |
278 | |
279 // Let the host know we are done. | 275 // Let the host know we are done. |
| 276 // TODO(dalecurtis): Technically this is not always correct. Due to channel |
| 277 // padding for alignment, there may be more data available than this. We're |
| 278 // relying on AudioSyncReader::Read() to parse this with that in mind. Rename |
| 279 // these methods to Set/GetActualFrameCount(). |
280 SetActualDataSizeInBytes( | 280 SetActualDataSizeInBytes( |
281 &shared_memory_, memory_length_, | 281 &shared_memory_, memory_length_, |
282 num_frames * audio_parameters_.GetBytesPerFrame()); | 282 num_frames * sizeof(*audio_bus_->channel(0)) * audio_bus_->channels()); |
283 } | 283 } |
284 | 284 |
285 } // namespace media. | 285 } // namespace media. |
OLD | NEW |