| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/base/filter_host.h" | 5 #include "media/base/filter_host.h" |
| 6 #include "media/filters/audio_renderer_base.h" | 6 #include "media/filters/audio_renderer_base.h" |
| 7 | 7 |
| 8 namespace media { | 8 namespace media { |
| 9 | 9 |
| 10 // The maximum size of the queue, which also acts as the number of initial reads | 10 // The maximum size of the queue, which also acts as the number of initial reads |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 | 32 |
| 33 void AudioRendererBase::Stop() { | 33 void AudioRendererBase::Stop() { |
| 34 OnStop(); | 34 OnStop(); |
| 35 | 35 |
| 36 AutoLock auto_lock(lock_); | 36 AutoLock auto_lock(lock_); |
| 37 queue_.clear(); | 37 queue_.clear(); |
| 38 stopped_ = true; | 38 stopped_ = true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void AudioRendererBase::Seek(base::TimeDelta time) { | 41 void AudioRendererBase::Seek(base::TimeDelta time, FilterCallback* callback) { |
| 42 AutoLock auto_lock(lock_); | 42 AutoLock auto_lock(lock_); |
| 43 last_fill_buffer_time_ = base::TimeDelta(); | 43 last_fill_buffer_time_ = base::TimeDelta(); |
| 44 | 44 |
| 45 // Clear the queue of decoded packets and release the buffers. Fire as many | 45 // Clear the queue of decoded packets and release the buffers. Fire as many |
| 46 // reads as buffers released. It is safe to schedule reads here because | 46 // reads as buffers released. It is safe to schedule reads here because |
| 47 // demuxer and decoders should have received the seek signal. | 47 // demuxer and decoders should have received the seek signal. |
| 48 // TODO(hclam): we should preform prerolling again after each seek to avoid | 48 // TODO(hclam): we should preform prerolling again after each seek to avoid |
| 49 // glitch or clicking of audio. | 49 // glitch or clicking of audio. |
| 50 while (!queue_.empty()) { | 50 while (!queue_.empty()) { |
| 51 queue_.pop_front(); | 51 queue_.pop_front(); |
| 52 ScheduleRead(); | 52 ScheduleRead(); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool AudioRendererBase::Initialize(AudioDecoder* decoder) { | 56 void AudioRendererBase::Initialize(AudioDecoder* decoder, |
| 57 FilterCallback* callback) { |
| 57 DCHECK(decoder); | 58 DCHECK(decoder); |
| 59 DCHECK(callback); |
| 58 decoder_ = decoder; | 60 decoder_ = decoder; |
| 61 initialize_callback_.reset(callback); |
| 59 | 62 |
| 60 // Schedule our initial reads. | 63 // Schedule our initial reads. |
| 61 for (size_t i = 0; i < max_queue_size_; ++i) { | 64 for (size_t i = 0; i < max_queue_size_; ++i) { |
| 62 ScheduleRead(); | 65 ScheduleRead(); |
| 63 } | 66 } |
| 64 | 67 |
| 65 // Defer initialization until all scheduled reads have completed. | 68 // Defer initialization until all scheduled reads have completed. |
| 66 return OnInitialize(decoder_->media_format()); | 69 if (!OnInitialize(decoder_->media_format())) { |
| 70 host()->Error(PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 71 initialize_callback_->Run(); |
| 72 initialize_callback_.reset(); |
| 73 } |
| 67 } | 74 } |
| 68 | 75 |
| 69 void AudioRendererBase::OnReadComplete(Buffer* buffer_in) { | 76 void AudioRendererBase::OnReadComplete(Buffer* buffer_in) { |
| 70 bool initialization_complete = false; | 77 bool initialization_complete = false; |
| 71 { | 78 { |
| 72 AutoLock auto_lock(lock_); | 79 AutoLock auto_lock(lock_); |
| 73 // If we have stopped don't enqueue, same for end of stream buffer since | 80 // If we have stopped don't enqueue, same for end of stream buffer since |
| 74 // it has no data. | 81 // it has no data. |
| 75 if (!stopped_ && !buffer_in->IsEndOfStream()) { | 82 if (!stopped_ && !buffer_in->IsEndOfStream()) { |
| 76 queue_.push_back(buffer_in); | 83 queue_.push_back(buffer_in); |
| 77 DCHECK(queue_.size() <= max_queue_size_); | 84 DCHECK(queue_.size() <= max_queue_size_); |
| 78 } | 85 } |
| 79 | 86 |
| 80 if (!initialized_) { | 87 if (!initialized_) { |
| 81 // We have completed the initialization when we preroll enough and hit | 88 // We have completed the initialization when we preroll enough and hit |
| 82 // the target queue size or the stream has ended. | 89 // the target queue size or the stream has ended. |
| 83 if (queue_.size() == max_queue_size_ || buffer_in->IsEndOfStream()) | 90 if (queue_.size() == max_queue_size_ || buffer_in->IsEndOfStream()) |
| 84 initialization_complete = true; | 91 initialization_complete = true; |
| 85 } | 92 } |
| 86 } | 93 } |
| 87 | 94 |
| 88 if (initialization_complete) { | 95 if (initialization_complete) { |
| 89 if (queue_.empty()) { | 96 if (queue_.empty()) { |
| 90 // If we say we have initialized but buffer queue is empty, raise an | 97 // If we say we have initialized but buffer queue is empty, raise an |
| 91 // error. | 98 // error. |
| 92 host()->Error(PIPELINE_ERROR_NO_DATA); | 99 host()->Error(PIPELINE_ERROR_NO_DATA); |
| 93 } else { | 100 } else { |
| 94 initialized_ = true; | 101 initialized_ = true; |
| 95 host()->InitializationComplete(); | |
| 96 } | 102 } |
| 103 initialize_callback_->Run(); |
| 104 initialize_callback_.reset(); |
| 97 } | 105 } |
| 98 } | 106 } |
| 99 | 107 |
| 100 // TODO(scherkus): clean up FillBuffer().. it's overly complex!! | 108 // TODO(scherkus): clean up FillBuffer().. it's overly complex!! |
| 101 size_t AudioRendererBase::FillBuffer(uint8* dest, | 109 size_t AudioRendererBase::FillBuffer(uint8* dest, |
| 102 size_t dest_len, | 110 size_t dest_len, |
| 103 float rate, | 111 float rate, |
| 104 const base::TimeDelta& playback_delay) { | 112 const base::TimeDelta& playback_delay) { |
| 105 size_t buffers_released = 0; | 113 size_t buffers_released = 0; |
| 106 size_t dest_written = 0; | 114 size_t dest_written = 0; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // TODO(scherkus): might be handy to support NULL parameters. | 236 // TODO(scherkus): might be handy to support NULL parameters. |
| 229 std::string mime_type; | 237 std::string mime_type; |
| 230 return media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && | 238 return media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && |
| 231 media_format.GetAsInteger(MediaFormat::kChannels, channels_out) && | 239 media_format.GetAsInteger(MediaFormat::kChannels, channels_out) && |
| 232 media_format.GetAsInteger(MediaFormat::kSampleRate, sample_rate_out) && | 240 media_format.GetAsInteger(MediaFormat::kSampleRate, sample_rate_out) && |
| 233 media_format.GetAsInteger(MediaFormat::kSampleBits, sample_bits_out) && | 241 media_format.GetAsInteger(MediaFormat::kSampleBits, sample_bits_out) && |
| 234 mime_type.compare(mime_type::kUncompressedAudio) == 0; | 242 mime_type.compare(mime_type::kUncompressedAudio) == 0; |
| 235 } | 243 } |
| 236 | 244 |
| 237 } // namespace media | 245 } // namespace media |
| OLD | NEW |