| 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/pulse/pulse_output.h" | 5 #include "media/audio/pulse/pulse_output.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
| 10 #include "media/audio/audio_util.h" | 10 #include "media/audio/audio_util.h" |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 pa_usec_t pa_latency_micros; | 303 pa_usec_t pa_latency_micros; |
| 304 int negative; | 304 int negative; |
| 305 pa_stream_get_latency(playback_handle_, &pa_latency_micros, &negative); | 305 pa_stream_get_latency(playback_handle_, &pa_latency_micros, &negative); |
| 306 uint32 hardware_delay = MicrosecondsToBytes(pa_latency_micros, | 306 uint32 hardware_delay = MicrosecondsToBytes(pa_latency_micros, |
| 307 sample_rate_, | 307 sample_rate_, |
| 308 bytes_per_frame_); | 308 bytes_per_frame_); |
| 309 // TODO(slock): Deal with negative latency (negative == 1). This has yet | 309 // TODO(slock): Deal with negative latency (negative == 1). This has yet |
| 310 // to happen in practice though. | 310 // to happen in practice though. |
| 311 scoped_refptr<media::DataBuffer> packet = | 311 scoped_refptr<media::DataBuffer> packet = |
| 312 new media::DataBuffer(packet_size_); | 312 new media::DataBuffer(packet_size_); |
| 313 size_t packet_size = RunDataCallback(packet->GetWritableData(), | 313 int frames_filled = RunDataCallback( |
| 314 packet->GetBufferSize(), | 314 audio_bus_.get(), AudioBuffersState(buffer_delay, hardware_delay)); |
| 315 AudioBuffersState(buffer_delay, | 315 size_t packet_size = frames_filled * bytes_per_frame_; |
| 316 hardware_delay)); | 316 |
| 317 DCHECK_LE(packet_size, packet_size_); |
| 318 // Note: If this ever changes to output raw float the data must be clipped and |
| 319 // sanitized since it may come from an untrusted source such as NaCl. |
| 320 audio_bus_->ToInterleaved( |
| 321 frames_filled, bytes_per_frame_ / channel_count_, |
| 322 packet->GetWritableData()); |
| 317 | 323 |
| 318 if (packet_size == 0) | 324 if (packet_size == 0) |
| 319 return false; | 325 return false; |
| 320 | 326 |
| 321 media::AdjustVolume(packet->GetWritableData(), | 327 media::AdjustVolume(packet->GetWritableData(), |
| 322 packet_size, | 328 packet_size, |
| 323 channel_count_, | 329 channel_count_, |
| 324 bytes_per_frame_ / channel_count_, | 330 bytes_per_frame_ / channel_count_, |
| 325 volume_); | 331 volume_); |
| 326 packet->SetDataSize(packet_size); | 332 packet->SetDataSize(packet_size); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 420 |
| 415 volume_ = static_cast<float>(volume); | 421 volume_ = static_cast<float>(volume); |
| 416 } | 422 } |
| 417 | 423 |
| 418 void PulseAudioOutputStream::GetVolume(double* volume) { | 424 void PulseAudioOutputStream::GetVolume(double* volume) { |
| 419 DCHECK(manager_->GetMessageLoop()->BelongsToCurrentThread()); | 425 DCHECK(manager_->GetMessageLoop()->BelongsToCurrentThread()); |
| 420 | 426 |
| 421 *volume = volume_; | 427 *volume = volume_; |
| 422 } | 428 } |
| 423 | 429 |
| 424 uint32 PulseAudioOutputStream::RunDataCallback( | 430 int PulseAudioOutputStream::RunDataCallback( |
| 425 uint8* dest, uint32 max_size, AudioBuffersState buffers_state) { | 431 AudioBus* audio_bus, AudioBuffersState buffers_state) { |
| 426 if (source_callback_) | 432 if (source_callback_) |
| 427 return source_callback_->OnMoreData(dest, max_size, buffers_state); | 433 return source_callback_->OnMoreData(audio_bus, buffers_state); |
| 428 | 434 |
| 429 return 0; | 435 return 0; |
| 430 } | 436 } |
| 431 | 437 |
| 432 } // namespace media | 438 } // namespace media |
| OLD | NEW |