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(), | 361 output_bus_.get(), total_delay_bytes); |
362 AudioBuffersState(0, total_delay_bytes)); | |
363 | 362 |
364 output_bus_->ToInterleaved(frames_filled, bytes_per_sample, output_samples); | 363 output_bus_->ToInterleaved(frames_filled, bytes_per_sample, output_samples); |
365 | 364 |
366 return frames_filled; | 365 return frames_filled; |
367 } | 366 } |
368 | 367 |
369 uint32 CrasUnifiedStream::WriteAudio(size_t frames, | 368 uint32 CrasUnifiedStream::WriteAudio(size_t frames, |
370 uint8* buffer, | 369 uint8* buffer, |
371 const timespec* sample_ts) { | 370 const timespec* sample_ts) { |
372 DCHECK_EQ(frames, static_cast<size_t>(output_bus_->frames())); | 371 DCHECK_EQ(frames, static_cast<size_t>(output_bus_->frames())); |
373 | 372 |
374 // Determine latency and pass that on to the source. | 373 // Determine latency and pass that on to the source. |
375 timespec latency_ts = {0, 0}; | 374 timespec latency_ts = {0, 0}; |
376 cras_client_calc_playback_latency(sample_ts, &latency_ts); | 375 cras_client_calc_playback_latency(sample_ts, &latency_ts); |
377 | 376 |
378 int frames_filled = source_callback_->OnMoreData( | 377 int frames_filled = source_callback_->OnMoreData( |
379 output_bus_.get(), AudioBuffersState(0, GetBytesLatency(latency_ts))); | 378 output_bus_.get(), GetBytesLatency(latency_ts)); |
380 | 379 |
381 // Note: If this ever changes to output raw float the data must be clipped and | 380 // Note: If this ever changes to output raw float the data must be clipped and |
382 // sanitized since it may come from an untrusted source such as NaCl. | 381 // sanitized since it may come from an untrusted source such as NaCl. |
383 output_bus_->ToInterleaved( | 382 output_bus_->ToInterleaved( |
384 frames_filled, bytes_per_frame_ / params_.channels(), buffer); | 383 frames_filled, bytes_per_frame_ / params_.channels(), buffer); |
385 | 384 |
386 return frames_filled; | 385 return frames_filled; |
387 } | 386 } |
388 | 387 |
389 void CrasUnifiedStream::NotifyStreamError(int err) { | 388 void CrasUnifiedStream::NotifyStreamError(int err) { |
390 // This will remove the stream from the client. | 389 // This will remove the stream from the client. |
391 if (source_callback_) | 390 if (source_callback_) |
392 source_callback_->OnError(this); | 391 source_callback_->OnError(this); |
393 } | 392 } |
394 | 393 |
395 } // namespace media | 394 } // namespace media |
OLD | NEW |