| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Defer initialization until all scheduled reads have completed. | 66 // Defer initialization until all scheduled reads have completed. |
| 67 return OnInitialize(decoder_->media_format()); | 67 return OnInitialize(decoder_->media_format()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void AudioRendererBase::OnReadComplete(Buffer* buffer_in) { | 70 void AudioRendererBase::OnReadComplete(Buffer* buffer_in) { |
| 71 bool initialization_complete = false; | 71 bool initialization_complete = false; |
| 72 { | 72 { |
| 73 AutoLock auto_lock(lock_); | 73 AutoLock auto_lock(lock_); |
| 74 if (!stopped_) { | 74 // If we have stopped don't enqueue, same for end of stream buffer since |
| 75 // it has no data. |
| 76 if (!stopped_ && !buffer_in->IsEndOfStream()) { |
| 75 queue_.push_back(buffer_in); | 77 queue_.push_back(buffer_in); |
| 76 DCHECK(queue_.size() <= max_queue_size_); | 78 DCHECK(queue_.size() <= max_queue_size_); |
| 77 } | 79 } |
| 78 | 80 |
| 79 // See if we're finally initialized. | 81 if (!initialized_) { |
| 80 // TODO(scherkus): handle end of stream cases where we'll never reach max | 82 // We have completed the initialization when we preroll enough and hit |
| 81 // queue size. | 83 // the target queue size or the stream has ended. |
| 82 if (!initialized_ && queue_.size() == max_queue_size_) { | 84 if (queue_.size() == max_queue_size_ || buffer_in->IsEndOfStream()) |
| 83 initialization_complete = true; | 85 initialization_complete = true; |
| 84 } | 86 } |
| 85 } | 87 } |
| 86 | 88 |
| 87 if (initialization_complete) { | 89 if (initialization_complete) { |
| 88 initialized_ = true; | 90 if (queue_.empty()) { |
| 89 host_->InitializationComplete(); | 91 // If we say we have initialized but buffer queue is empty, raise an |
| 92 // error. |
| 93 host_->Error(PIPELINE_ERROR_NO_DATA); |
| 94 } else { |
| 95 initialized_ = true; |
| 96 host_->InitializationComplete(); |
| 97 } |
| 90 } | 98 } |
| 91 } | 99 } |
| 92 | 100 |
| 93 // TODO(scherkus): clean up FillBuffer().. it's overly complex!! | 101 // TODO(scherkus): clean up FillBuffer().. it's overly complex!! |
| 94 size_t AudioRendererBase::FillBuffer(uint8* dest, size_t dest_len, | 102 size_t AudioRendererBase::FillBuffer(uint8* dest, size_t dest_len, |
| 95 float rate) { | 103 float rate) { |
| 96 size_t buffers_released = 0; | 104 size_t buffers_released = 0; |
| 97 size_t dest_written = 0; | 105 size_t dest_written = 0; |
| 98 base::TimeDelta last_fill_buffer_time; | 106 base::TimeDelta last_fill_buffer_time; |
| 99 { | 107 { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // TODO(scherkus): might be handy to support NULL parameters. | 217 // TODO(scherkus): might be handy to support NULL parameters. |
| 210 std::string mime_type; | 218 std::string mime_type; |
| 211 return media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && | 219 return media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && |
| 212 media_format.GetAsInteger(MediaFormat::kChannels, channels_out) && | 220 media_format.GetAsInteger(MediaFormat::kChannels, channels_out) && |
| 213 media_format.GetAsInteger(MediaFormat::kSampleRate, sample_rate_out) && | 221 media_format.GetAsInteger(MediaFormat::kSampleRate, sample_rate_out) && |
| 214 media_format.GetAsInteger(MediaFormat::kSampleBits, sample_bits_out) && | 222 media_format.GetAsInteger(MediaFormat::kSampleBits, sample_bits_out) && |
| 215 mime_type.compare(mime_type::kUncompressedAudio) == 0; | 223 mime_type.compare(mime_type::kUncompressedAudio) == 0; |
| 216 } | 224 } |
| 217 | 225 |
| 218 } // namespace media | 226 } // namespace media |
| OLD | NEW |