| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "media/base/filter_host.h" | 10 #include "media/base/filter_host.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 | 73 |
| 74 void AudioRendererBase::Initialize(AudioDecoder* decoder, | 74 void AudioRendererBase::Initialize(AudioDecoder* decoder, |
| 75 FilterCallback* callback) { | 75 FilterCallback* callback) { |
| 76 DCHECK(decoder); | 76 DCHECK(decoder); |
| 77 DCHECK(callback); | 77 DCHECK(callback); |
| 78 DCHECK_EQ(kUninitialized, state_); | 78 DCHECK_EQ(kUninitialized, state_); |
| 79 scoped_ptr<FilterCallback> c(callback); | 79 scoped_ptr<FilterCallback> c(callback); |
| 80 decoder_ = decoder; | 80 decoder_ = decoder; |
| 81 | 81 |
| 82 decoder_->set_fill_buffer_done_callback( |
| 83 NewCallback(this, &AudioRendererBase::OnFillBufferDone)); |
| 82 // Get the media properties to initialize our algorithms. | 84 // Get the media properties to initialize our algorithms. |
| 83 int channels = 0; | 85 int channels = 0; |
| 84 int sample_rate = 0; | 86 int sample_rate = 0; |
| 85 int sample_bits = 0; | 87 int sample_bits = 0; |
| 86 if (!ParseMediaFormat(decoder_->media_format(), &channels, &sample_rate, | 88 if (!ParseMediaFormat(decoder_->media_format(), &channels, &sample_rate, |
| 87 &sample_bits)) { | 89 &sample_bits)) { |
| 88 host()->SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); | 90 host()->SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 89 callback->Run(); | 91 callback->Run(); |
| 90 return; | 92 return; |
| 91 } | 93 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 119 | 121 |
| 120 bool AudioRendererBase::HasEnded() { | 122 bool AudioRendererBase::HasEnded() { |
| 121 AutoLock auto_lock(lock_); | 123 AutoLock auto_lock(lock_); |
| 122 if (rendered_end_of_stream_) { | 124 if (rendered_end_of_stream_) { |
| 123 DCHECK(algorithm_->IsQueueEmpty()) | 125 DCHECK(algorithm_->IsQueueEmpty()) |
| 124 << "Audio queue should be empty if we have rendered end of stream"; | 126 << "Audio queue should be empty if we have rendered end of stream"; |
| 125 } | 127 } |
| 126 return recieved_end_of_stream_ && rendered_end_of_stream_; | 128 return recieved_end_of_stream_ && rendered_end_of_stream_; |
| 127 } | 129 } |
| 128 | 130 |
| 129 void AudioRendererBase::OnReadComplete(Buffer* buffer_in) { | 131 void AudioRendererBase::OnFillBufferDone(scoped_refptr<Buffer> buffer_in) { |
| 130 AutoLock auto_lock(lock_); | 132 AutoLock auto_lock(lock_); |
| 131 DCHECK(state_ == kPaused || state_ == kSeeking || state_ == kPlaying); | 133 DCHECK(state_ == kPaused || state_ == kSeeking || state_ == kPlaying); |
| 132 DCHECK_GT(pending_reads_, 0u); | 134 DCHECK_GT(pending_reads_, 0u); |
| 133 --pending_reads_; | 135 --pending_reads_; |
| 134 | 136 |
| 135 // TODO(scherkus): this happens due to a race, primarily because Stop() is a | 137 // TODO(scherkus): this happens due to a race, primarily because Stop() is a |
| 136 // synchronous call when it should be asynchronous and accept a callback. | 138 // synchronous call when it should be asynchronous and accept a callback. |
| 137 // Refer to http://crbug.com/16059 | 139 // Refer to http://crbug.com/16059 |
| 138 if (state_ == kStopped) { | 140 if (state_ == kStopped) { |
| 139 return; | 141 return; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 last_fill_buffer_time -= playback_delay; | 224 last_fill_buffer_time -= playback_delay; |
| 223 host()->SetTime(last_fill_buffer_time); | 225 host()->SetTime(last_fill_buffer_time); |
| 224 } | 226 } |
| 225 | 227 |
| 226 return dest_written; | 228 return dest_written; |
| 227 } | 229 } |
| 228 | 230 |
| 229 void AudioRendererBase::ScheduleRead_Locked() { | 231 void AudioRendererBase::ScheduleRead_Locked() { |
| 230 lock_.AssertAcquired(); | 232 lock_.AssertAcquired(); |
| 231 ++pending_reads_; | 233 ++pending_reads_; |
| 232 decoder_->Read(NewCallback(this, &AudioRendererBase::OnReadComplete)); | 234 // TODO(jiesun): We use dummy buffer to feed decoder to let decoder to |
| 235 // provide buffer pools. In the future, we may want to implement real |
| 236 // buffer pool to recycle buffers. |
| 237 scoped_refptr<Buffer> buffer; |
| 238 decoder_->FillThisBuffer(buffer); |
| 233 } | 239 } |
| 234 | 240 |
| 235 // static | 241 // static |
| 236 bool AudioRendererBase::ParseMediaFormat(const MediaFormat& media_format, | 242 bool AudioRendererBase::ParseMediaFormat(const MediaFormat& media_format, |
| 237 int* channels_out, | 243 int* channels_out, |
| 238 int* sample_rate_out, | 244 int* sample_rate_out, |
| 239 int* sample_bits_out) { | 245 int* sample_bits_out) { |
| 240 // TODO(scherkus): might be handy to support NULL parameters. | 246 // TODO(scherkus): might be handy to support NULL parameters. |
| 241 std::string mime_type; | 247 std::string mime_type; |
| 242 return media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && | 248 return media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && |
| 243 media_format.GetAsInteger(MediaFormat::kChannels, channels_out) && | 249 media_format.GetAsInteger(MediaFormat::kChannels, channels_out) && |
| 244 media_format.GetAsInteger(MediaFormat::kSampleRate, sample_rate_out) && | 250 media_format.GetAsInteger(MediaFormat::kSampleRate, sample_rate_out) && |
| 245 media_format.GetAsInteger(MediaFormat::kSampleBits, sample_bits_out) && | 251 media_format.GetAsInteger(MediaFormat::kSampleBits, sample_bits_out) && |
| 246 mime_type.compare(mime_type::kUncompressedAudio) == 0; | 252 mime_type.compare(mime_type::kUncompressedAudio) == 0; |
| 247 } | 253 } |
| 248 | 254 |
| 249 void AudioRendererBase::SetPlaybackRate(float playback_rate) { | 255 void AudioRendererBase::SetPlaybackRate(float playback_rate) { |
| 250 algorithm_->set_playback_rate(playback_rate); | 256 algorithm_->set_playback_rate(playback_rate); |
| 251 } | 257 } |
| 252 | 258 |
| 253 float AudioRendererBase::GetPlaybackRate() { | 259 float AudioRendererBase::GetPlaybackRate() { |
| 254 return algorithm_->playback_rate(); | 260 return algorithm_->playback_rate(); |
| 255 } | 261 } |
| 256 | 262 |
| 257 } // namespace media | 263 } // namespace media |
| OLD | NEW |