| 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 audio_bus_->ToInterleaved( |
| 319 frames_filled, bytes_per_frame_ / channel_count_, |
| 320 packet->GetWritableData()); |
| 317 | 321 |
| 318 if (packet_size == 0) | 322 if (packet_size == 0) |
| 319 return false; | 323 return false; |
| 320 | 324 |
| 321 media::AdjustVolume(packet->GetWritableData(), | 325 media::AdjustVolume(packet->GetWritableData(), |
| 322 packet_size, | 326 packet_size, |
| 323 channel_count_, | 327 channel_count_, |
| 324 bytes_per_frame_ / channel_count_, | 328 bytes_per_frame_ / channel_count_, |
| 325 volume_); | 329 volume_); |
| 326 packet->SetDataSize(packet_size); | 330 packet->SetDataSize(packet_size); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 418 |
| 415 volume_ = static_cast<float>(volume); | 419 volume_ = static_cast<float>(volume); |
| 416 } | 420 } |
| 417 | 421 |
| 418 void PulseAudioOutputStream::GetVolume(double* volume) { | 422 void PulseAudioOutputStream::GetVolume(double* volume) { |
| 419 DCHECK(manager_->GetMessageLoop()->BelongsToCurrentThread()); | 423 DCHECK(manager_->GetMessageLoop()->BelongsToCurrentThread()); |
| 420 | 424 |
| 421 *volume = volume_; | 425 *volume = volume_; |
| 422 } | 426 } |
| 423 | 427 |
| 424 uint32 PulseAudioOutputStream::RunDataCallback( | 428 int PulseAudioOutputStream::RunDataCallback( |
| 425 uint8* dest, uint32 max_size, AudioBuffersState buffers_state) { | 429 AudioBus* audio_bus, AudioBuffersState buffers_state) { |
| 426 if (source_callback_) | 430 if (source_callback_) |
| 427 return source_callback_->OnMoreData(dest, max_size, buffers_state); | 431 return source_callback_->OnMoreData(audio_bus, buffers_state); |
| 428 | 432 |
| 429 return 0; | 433 return 0; |
| 430 } | 434 } |
| 431 | 435 |
| 432 } // namespace media | 436 } // namespace media |
| OLD | NEW |