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/filters/audio_renderer_impl.h" | 5 #include "media/filters/audio_renderer_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 bytes_per_frame_(0), | 26 bytes_per_frame_(0), |
27 bytes_per_second_(0), | 27 bytes_per_second_(0), |
28 stopped_(false), | 28 stopped_(false), |
29 sink_(sink), | 29 sink_(sink), |
30 is_initialized_(false), | 30 is_initialized_(false), |
31 underflow_disabled_(false), | 31 underflow_disabled_(false), |
32 read_cb_(base::Bind(&AudioRendererImpl::DecodedAudioReady, | 32 read_cb_(base::Bind(&AudioRendererImpl::DecodedAudioReady, |
33 base::Unretained(this))) { | 33 base::Unretained(this))) { |
34 } | 34 } |
35 | 35 |
36 void AudioRendererImpl::SetHost(FilterHost* host) { | 36 void AudioRendererImpl::SetHost(AudioRendererHost* host) { |
37 DCHECK(host); | 37 DCHECK(host); |
38 DCHECK(!host_); | 38 DCHECK(!host_); |
39 host_ = host; | 39 host_ = host; |
40 } | 40 } |
41 | 41 |
42 void AudioRendererImpl::Play(const base::Closure& callback) { | 42 void AudioRendererImpl::Play(const base::Closure& callback) { |
43 { | 43 { |
44 base::AutoLock auto_lock(lock_); | 44 base::AutoLock auto_lock(lock_); |
45 DCHECK_EQ(kPaused, state_); | 45 DCHECK_EQ(kPaused, state_); |
46 state_ = kPlaying; | 46 state_ = kPlaying; |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 // | 417 // |
418 // We use the following conditions to determine underflow: | 418 // We use the following conditions to determine underflow: |
419 // 1) Algorithm can not fill the audio callback buffer | 419 // 1) Algorithm can not fill the audio callback buffer |
420 // 2) We have NOT received an end of stream buffer | 420 // 2) We have NOT received an end of stream buffer |
421 // 3) We are in the kPlaying state | 421 // 3) We are in the kPlaying state |
422 // | 422 // |
423 // Otherwise fill the buffer with whatever data we can send to the device. | 423 // Otherwise fill the buffer with whatever data we can send to the device. |
424 if (!algorithm_->CanFillBuffer() && received_end_of_stream_ && | 424 if (!algorithm_->CanFillBuffer() && received_end_of_stream_ && |
425 !rendered_end_of_stream_ && base::Time::Now() >= earliest_end_time_) { | 425 !rendered_end_of_stream_ && base::Time::Now() >= earliest_end_time_) { |
426 rendered_end_of_stream_ = true; | 426 rendered_end_of_stream_ = true; |
427 host_->NotifyEnded(); | 427 host_->AudioRendererEnded(); |
428 } else if (!algorithm_->CanFillBuffer() && !received_end_of_stream_ && | 428 } else if (!algorithm_->CanFillBuffer() && !received_end_of_stream_ && |
429 state_ == kPlaying && !underflow_disabled_) { | 429 state_ == kPlaying && !underflow_disabled_) { |
430 state_ = kUnderflow; | 430 state_ = kUnderflow; |
431 underflow_cb = underflow_cb_; | 431 underflow_cb = underflow_cb_; |
432 } else if (algorithm_->CanFillBuffer()) { | 432 } else if (algorithm_->CanFillBuffer()) { |
433 frames_written = algorithm_->FillBuffer(dest, requested_frames); | 433 frames_written = algorithm_->FillBuffer(dest, requested_frames); |
434 DCHECK_GT(frames_written, 0u); | 434 DCHECK_GT(frames_written, 0u); |
435 } else { | 435 } else { |
436 // We can't write any data this cycle. For example, we may have | 436 // We can't write any data this cycle. For example, we may have |
437 // sent all available data to the audio device while not reaching | 437 // sent all available data to the audio device while not reaching |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 500 |
501 base::TimeDelta AudioRendererImpl::ConvertToDuration(int bytes) { | 501 base::TimeDelta AudioRendererImpl::ConvertToDuration(int bytes) { |
502 if (bytes_per_second_) { | 502 if (bytes_per_second_) { |
503 return base::TimeDelta::FromMicroseconds( | 503 return base::TimeDelta::FromMicroseconds( |
504 base::Time::kMicrosecondsPerSecond * bytes / bytes_per_second_); | 504 base::Time::kMicrosecondsPerSecond * bytes / bytes_per_second_); |
505 } | 505 } |
506 return base::TimeDelta(); | 506 return base::TimeDelta(); |
507 } | 507 } |
508 | 508 |
509 void AudioRendererImpl::OnRenderError() { | 509 void AudioRendererImpl::OnRenderError() { |
510 host_->DisableAudioRenderer(); | 510 host_->AudioRendererDisabled(); |
511 } | 511 } |
512 | 512 |
513 void AudioRendererImpl::DisableUnderflowForTesting() { | 513 void AudioRendererImpl::DisableUnderflowForTesting() { |
514 DCHECK(!is_initialized_); | 514 DCHECK(!is_initialized_); |
515 underflow_disabled_ = true; | 515 underflow_disabled_ = true; |
516 } | 516 } |
517 | 517 |
518 } // namespace media | 518 } // namespace media |
OLD | NEW |