| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 decoder_ = decoder; | 60 decoder_ = decoder; |
| 61 initialize_callback_.reset(callback); | 61 initialize_callback_.reset(callback); |
| 62 | 62 |
| 63 // Schedule our initial reads. | 63 // Schedule our initial reads. |
| 64 for (size_t i = 0; i < max_queue_size_; ++i) { | 64 for (size_t i = 0; i < max_queue_size_; ++i) { |
| 65 ScheduleRead(); | 65 ScheduleRead(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Defer initialization until all scheduled reads have completed. | 68 // Defer initialization until all scheduled reads have completed. |
| 69 if (!OnInitialize(decoder_->media_format())) { | 69 if (!OnInitialize(decoder_->media_format())) { |
| 70 host()->Error(PIPELINE_ERROR_INITIALIZATION_FAILED); | 70 host()->SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 71 initialize_callback_->Run(); | 71 initialize_callback_->Run(); |
| 72 initialize_callback_.reset(); | 72 initialize_callback_.reset(); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 void AudioRendererBase::OnReadComplete(Buffer* buffer_in) { | 76 void AudioRendererBase::OnReadComplete(Buffer* buffer_in) { |
| 77 bool initialization_complete = false; | 77 bool initialization_complete = false; |
| 78 { | 78 { |
| 79 AutoLock auto_lock(lock_); | 79 AutoLock auto_lock(lock_); |
| 80 // 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 |
| 81 // it has no data. | 81 // it has no data. |
| 82 if (!stopped_ && !buffer_in->IsEndOfStream()) { | 82 if (!stopped_ && !buffer_in->IsEndOfStream()) { |
| 83 queue_.push_back(buffer_in); | 83 queue_.push_back(buffer_in); |
| 84 DCHECK(queue_.size() <= max_queue_size_); | 84 DCHECK(queue_.size() <= max_queue_size_); |
| 85 } | 85 } |
| 86 | 86 |
| 87 if (!initialized_) { | 87 if (!initialized_) { |
| 88 // We have completed the initialization when we preroll enough and hit | 88 // We have completed the initialization when we preroll enough and hit |
| 89 // the target queue size or the stream has ended. | 89 // the target queue size or the stream has ended. |
| 90 if (queue_.size() == max_queue_size_ || buffer_in->IsEndOfStream()) | 90 if (queue_.size() == max_queue_size_ || buffer_in->IsEndOfStream()) |
| 91 initialization_complete = true; | 91 initialization_complete = true; |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 if (initialization_complete) { | 95 if (initialization_complete) { |
| 96 if (queue_.empty()) { | 96 if (queue_.empty()) { |
| 97 // 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 |
| 98 // error. | 98 // error. |
| 99 host()->Error(PIPELINE_ERROR_NO_DATA); | 99 host()->SetError(PIPELINE_ERROR_NO_DATA); |
| 100 } else { | 100 } else { |
| 101 initialized_ = true; | 101 initialized_ = true; |
| 102 } | 102 } |
| 103 initialize_callback_->Run(); | 103 initialize_callback_->Run(); |
| 104 initialize_callback_.reset(); | 104 initialize_callback_.reset(); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 // TODO(scherkus): clean up FillBuffer().. it's overly complex!! | 108 // TODO(scherkus): clean up FillBuffer().. it's overly complex!! |
| 109 size_t AudioRendererBase::FillBuffer(uint8* dest, | 109 size_t AudioRendererBase::FillBuffer(uint8* dest, |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 // TODO(scherkus): might be handy to support NULL parameters. | 236 // TODO(scherkus): might be handy to support NULL parameters. |
| 237 std::string mime_type; | 237 std::string mime_type; |
| 238 return media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && | 238 return media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && |
| 239 media_format.GetAsInteger(MediaFormat::kChannels, channels_out) && | 239 media_format.GetAsInteger(MediaFormat::kChannels, channels_out) && |
| 240 media_format.GetAsInteger(MediaFormat::kSampleRate, sample_rate_out) && | 240 media_format.GetAsInteger(MediaFormat::kSampleRate, sample_rate_out) && |
| 241 media_format.GetAsInteger(MediaFormat::kSampleBits, sample_bits_out) && | 241 media_format.GetAsInteger(MediaFormat::kSampleBits, sample_bits_out) && |
| 242 mime_type.compare(mime_type::kUncompressedAudio) == 0; | 242 mime_type.compare(mime_type::kUncompressedAudio) == 0; |
| 243 } | 243 } |
| 244 | 244 |
| 245 } // namespace media | 245 } // namespace media |
| OLD | NEW |