| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/cras/cras_unified.h" | 5 #include "media/audio/cras/cras_unified.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "media/audio/cras/audio_manager_cras.h" | 8 #include "media/audio/cras/audio_manager_cras.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 // of the first input sample and the playback time of the next audio sample | 351 // of the first input sample and the playback time of the next audio sample |
| 352 // passed from the audio server, add them together for total latency. | 352 // passed from the audio server, add them together for total latency. |
| 353 uint32 total_delay_bytes; | 353 uint32 total_delay_bytes; |
| 354 timespec latency_ts = {0, 0}; | 354 timespec latency_ts = {0, 0}; |
| 355 cras_client_calc_capture_latency(input_ts, &latency_ts); | 355 cras_client_calc_capture_latency(input_ts, &latency_ts); |
| 356 total_delay_bytes = GetBytesLatency(latency_ts); | 356 total_delay_bytes = GetBytesLatency(latency_ts); |
| 357 cras_client_calc_playback_latency(output_ts, &latency_ts); | 357 cras_client_calc_playback_latency(output_ts, &latency_ts); |
| 358 total_delay_bytes += GetBytesLatency(latency_ts); | 358 total_delay_bytes += GetBytesLatency(latency_ts); |
| 359 | 359 |
| 360 int frames_filled = source_callback_->OnMoreData( | 360 int frames_filled = source_callback_->OnMoreData( |
| 361 output_bus_.get(), total_delay_bytes); | 361 output_bus_.get(), |
| 362 AudioBuffersState(0, total_delay_bytes)); |
| 362 | 363 |
| 363 output_bus_->ToInterleaved(frames_filled, bytes_per_sample, output_samples); | 364 output_bus_->ToInterleaved(frames_filled, bytes_per_sample, output_samples); |
| 364 | 365 |
| 365 return frames_filled; | 366 return frames_filled; |
| 366 } | 367 } |
| 367 | 368 |
| 368 uint32 CrasUnifiedStream::WriteAudio(size_t frames, | 369 uint32 CrasUnifiedStream::WriteAudio(size_t frames, |
| 369 uint8* buffer, | 370 uint8* buffer, |
| 370 const timespec* sample_ts) { | 371 const timespec* sample_ts) { |
| 371 DCHECK_EQ(frames, static_cast<size_t>(output_bus_->frames())); | 372 DCHECK_EQ(frames, static_cast<size_t>(output_bus_->frames())); |
| 372 | 373 |
| 373 // Determine latency and pass that on to the source. | 374 // Determine latency and pass that on to the source. |
| 374 timespec latency_ts = {0, 0}; | 375 timespec latency_ts = {0, 0}; |
| 375 cras_client_calc_playback_latency(sample_ts, &latency_ts); | 376 cras_client_calc_playback_latency(sample_ts, &latency_ts); |
| 376 | 377 |
| 377 int frames_filled = source_callback_->OnMoreData( | 378 int frames_filled = source_callback_->OnMoreData( |
| 378 output_bus_.get(), GetBytesLatency(latency_ts)); | 379 output_bus_.get(), AudioBuffersState(0, GetBytesLatency(latency_ts))); |
| 379 | 380 |
| 380 // Note: If this ever changes to output raw float the data must be clipped and | 381 // Note: If this ever changes to output raw float the data must be clipped and |
| 381 // sanitized since it may come from an untrusted source such as NaCl. | 382 // sanitized since it may come from an untrusted source such as NaCl. |
| 382 output_bus_->ToInterleaved( | 383 output_bus_->ToInterleaved( |
| 383 frames_filled, bytes_per_frame_ / params_.channels(), buffer); | 384 frames_filled, bytes_per_frame_ / params_.channels(), buffer); |
| 384 | 385 |
| 385 return frames_filled; | 386 return frames_filled; |
| 386 } | 387 } |
| 387 | 388 |
| 388 void CrasUnifiedStream::NotifyStreamError(int err) { | 389 void CrasUnifiedStream::NotifyStreamError(int err) { |
| 389 // This will remove the stream from the client. | 390 // This will remove the stream from the client. |
| 390 if (source_callback_) | 391 if (source_callback_) |
| 391 source_callback_->OnError(this); | 392 source_callback_->OnError(this); |
| 392 } | 393 } |
| 393 | 394 |
| 394 } // namespace media | 395 } // namespace media |
| OLD | NEW |