| 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_base.h" | 5 #include "media/filters/audio_renderer_base.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // Throw away everything and schedule our reads. | 76 // Throw away everything and schedule our reads. |
| 77 last_fill_buffer_time_ = base::TimeDelta(); | 77 last_fill_buffer_time_ = base::TimeDelta(); |
| 78 recieved_end_of_stream_ = false; | 78 recieved_end_of_stream_ = false; |
| 79 rendered_end_of_stream_ = false; | 79 rendered_end_of_stream_ = false; |
| 80 | 80 |
| 81 // |algorithm_| will request more reads. | 81 // |algorithm_| will request more reads. |
| 82 algorithm_->FlushBuffers(); | 82 algorithm_->FlushBuffers(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void AudioRendererBase::Initialize(AudioDecoder* decoder, | 85 void AudioRendererBase::Initialize(AudioDecoder* decoder, |
| 86 const base::Closure& init_callback, | 86 const PipelineStatusCB& init_callback, |
| 87 const base::Closure& underflow_callback) { | 87 const base::Closure& underflow_callback) { |
| 88 DCHECK(decoder); | 88 DCHECK(decoder); |
| 89 DCHECK(!init_callback.is_null()); | 89 DCHECK(!init_callback.is_null()); |
| 90 DCHECK(!underflow_callback.is_null()); | 90 DCHECK(!underflow_callback.is_null()); |
| 91 DCHECK_EQ(kUninitialized, state_); | 91 DCHECK_EQ(kUninitialized, state_); |
| 92 decoder_ = decoder; | 92 decoder_ = decoder; |
| 93 underflow_callback_ = underflow_callback; | 93 underflow_callback_ = underflow_callback; |
| 94 | 94 |
| 95 // Create a callback so our algorithm can request more reads. | 95 // Create a callback so our algorithm can request more reads. |
| 96 base::Closure cb = base::Bind(&AudioRendererBase::ScheduleRead_Locked, this); | 96 base::Closure cb = base::Bind(&AudioRendererBase::ScheduleRead_Locked, this); |
| 97 | 97 |
| 98 // Construct the algorithm. | 98 // Construct the algorithm. |
| 99 algorithm_.reset(new AudioRendererAlgorithmBase()); | 99 algorithm_.reset(new AudioRendererAlgorithmBase()); |
| 100 | 100 |
| 101 // Initialize our algorithm with media properties, initial playback rate, | 101 // Initialize our algorithm with media properties, initial playback rate, |
| 102 // and a callback to request more reads from the data source. | 102 // and a callback to request more reads from the data source. |
| 103 ChannelLayout channel_layout = decoder_->channel_layout(); | 103 ChannelLayout channel_layout = decoder_->channel_layout(); |
| 104 int channels = ChannelLayoutToChannelCount(channel_layout); | 104 int channels = ChannelLayoutToChannelCount(channel_layout); |
| 105 int bits_per_channel = decoder_->bits_per_channel(); | 105 int bits_per_channel = decoder_->bits_per_channel(); |
| 106 int sample_rate = decoder_->samples_per_second(); | 106 int sample_rate = decoder_->samples_per_second(); |
| 107 algorithm_->Initialize(channels, sample_rate, bits_per_channel, 0.0f, cb); | 107 algorithm_->Initialize(channels, sample_rate, bits_per_channel, 0.0f, cb); |
| 108 | 108 |
| 109 // Give the subclass an opportunity to initialize itself. | 109 // Give the subclass an opportunity to initialize itself. |
| 110 if (!OnInitialize(bits_per_channel, channel_layout, sample_rate)) { | 110 if (!OnInitialize(bits_per_channel, channel_layout, sample_rate)) { |
| 111 host()->SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); | 111 init_callback.Run(PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 112 init_callback.Run(); | |
| 113 return; | 112 return; |
| 114 } | 113 } |
| 115 | 114 |
| 116 // Finally, execute the start callback. | 115 // Finally, execute the start callback. |
| 117 state_ = kPaused; | 116 state_ = kPaused; |
| 118 init_callback.Run(); | 117 init_callback.Run(PIPELINE_OK); |
| 119 } | 118 } |
| 120 | 119 |
| 121 bool AudioRendererBase::HasEnded() { | 120 bool AudioRendererBase::HasEnded() { |
| 122 base::AutoLock auto_lock(lock_); | 121 base::AutoLock auto_lock(lock_); |
| 123 if (rendered_end_of_stream_) { | 122 if (rendered_end_of_stream_) { |
| 124 DCHECK(algorithm_->IsQueueEmpty()) | 123 DCHECK(algorithm_->IsQueueEmpty()) |
| 125 << "Audio queue should be empty if we have rendered end of stream"; | 124 << "Audio queue should be empty if we have rendered end of stream"; |
| 126 } | 125 } |
| 127 return recieved_end_of_stream_ && rendered_end_of_stream_; | 126 return recieved_end_of_stream_ && rendered_end_of_stream_; |
| 128 } | 127 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 base::AutoLock auto_lock(lock_); | 293 base::AutoLock auto_lock(lock_); |
| 295 return algorithm_->playback_rate(); | 294 return algorithm_->playback_rate(); |
| 296 } | 295 } |
| 297 | 296 |
| 298 bool AudioRendererBase::IsBeforeSeekTime(const scoped_refptr<Buffer>& buffer) { | 297 bool AudioRendererBase::IsBeforeSeekTime(const scoped_refptr<Buffer>& buffer) { |
| 299 return (state_ == kSeeking) && buffer && !buffer->IsEndOfStream() && | 298 return (state_ == kSeeking) && buffer && !buffer->IsEndOfStream() && |
| 300 (buffer->GetTimestamp() + buffer->GetDuration()) < seek_timestamp_; | 299 (buffer->GetTimestamp() + buffer->GetDuration()) < seek_timestamp_; |
| 301 } | 300 } |
| 302 | 301 |
| 303 } // namespace media | 302 } // namespace media |
| OLD | NEW |