| 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/chunk_demuxer.h" | 5 #include "media/filters/chunk_demuxer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "media/base/audio_decoder_config.h" | 10 #include "media/base/audio_decoder_config.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // monotonically increasing timestamps. | 62 // monotonically increasing timestamps. |
| 63 base::TimeDelta last_buffer_timestamp_; | 63 base::TimeDelta last_buffer_timestamp_; |
| 64 | 64 |
| 65 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); | 65 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 ChunkDemuxerStream::ChunkDemuxerStream(const AudioDecoderConfig& audio_config) | 68 ChunkDemuxerStream::ChunkDemuxerStream(const AudioDecoderConfig& audio_config) |
| 69 : type_(AUDIO), | 69 : type_(AUDIO), |
| 70 shutdown_called_(false), | 70 shutdown_called_(false), |
| 71 received_end_of_stream_(false), | 71 received_end_of_stream_(false), |
| 72 last_buffer_timestamp_(kNoTimestamp) { | 72 last_buffer_timestamp_(kNoTimestamp()) { |
| 73 audio_config_.CopyFrom(audio_config); | 73 audio_config_.CopyFrom(audio_config); |
| 74 } | 74 } |
| 75 | 75 |
| 76 | 76 |
| 77 ChunkDemuxerStream::ChunkDemuxerStream(const VideoDecoderConfig& video_config) | 77 ChunkDemuxerStream::ChunkDemuxerStream(const VideoDecoderConfig& video_config) |
| 78 : type_(VIDEO), | 78 : type_(VIDEO), |
| 79 shutdown_called_(false), | 79 shutdown_called_(false), |
| 80 received_end_of_stream_(false), | 80 received_end_of_stream_(false), |
| 81 last_buffer_timestamp_(kNoTimestamp) { | 81 last_buffer_timestamp_(kNoTimestamp()) { |
| 82 video_config_.CopyFrom(video_config); | 82 video_config_.CopyFrom(video_config); |
| 83 } | 83 } |
| 84 | 84 |
| 85 ChunkDemuxerStream::~ChunkDemuxerStream() {} | 85 ChunkDemuxerStream::~ChunkDemuxerStream() {} |
| 86 | 86 |
| 87 void ChunkDemuxerStream::Flush() { | 87 void ChunkDemuxerStream::Flush() { |
| 88 DVLOG(1) << "Flush()"; | 88 DVLOG(1) << "Flush()"; |
| 89 base::AutoLock auto_lock(lock_); | 89 base::AutoLock auto_lock(lock_); |
| 90 buffers_.clear(); | 90 buffers_.clear(); |
| 91 received_end_of_stream_ = false; | 91 received_end_of_stream_ = false; |
| 92 last_buffer_timestamp_ = kNoTimestamp; | 92 last_buffer_timestamp_ = kNoTimestamp(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool ChunkDemuxerStream::CanAddBuffers(const BufferQueue& buffers) const { | 95 bool ChunkDemuxerStream::CanAddBuffers(const BufferQueue& buffers) const { |
| 96 base::AutoLock auto_lock(lock_); | 96 base::AutoLock auto_lock(lock_); |
| 97 | 97 |
| 98 // If we haven't seen any buffers yet, then anything can be added. | 98 // If we haven't seen any buffers yet, then anything can be added. |
| 99 if (last_buffer_timestamp_ == kNoTimestamp) | 99 if (last_buffer_timestamp_ == kNoTimestamp()) |
| 100 return true; | 100 return true; |
| 101 | 101 |
| 102 if (buffers.empty()) | 102 if (buffers.empty()) |
| 103 return true; | 103 return true; |
| 104 | 104 |
| 105 return (buffers.front()->GetTimestamp() > last_buffer_timestamp_); | 105 return (buffers.front()->GetTimestamp() > last_buffer_timestamp_); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void ChunkDemuxerStream::AddBuffers(const BufferQueue& buffers) { | 108 void ChunkDemuxerStream::AddBuffers(const BufferQueue& buffers) { |
| 109 if (buffers.empty()) | 109 if (buffers.empty()) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 124 | 124 |
| 125 // Push enough EOS buffers to satisfy outstanding Read() requests. | 125 // Push enough EOS buffers to satisfy outstanding Read() requests. |
| 126 if (read_cbs_.size() > buffers_.size()) { | 126 if (read_cbs_.size() > buffers_.size()) { |
| 127 size_t pending_read_without_data = read_cbs_.size() - buffers_.size(); | 127 size_t pending_read_without_data = read_cbs_.size() - buffers_.size(); |
| 128 for (size_t i = 0; i <= pending_read_without_data; ++i) { | 128 for (size_t i = 0; i <= pending_read_without_data; ++i) { |
| 129 buffers_.push_back(*itr); | 129 buffers_.push_back(*itr); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 } else { | 132 } else { |
| 133 base::TimeDelta current_ts = (*itr)->GetTimestamp(); | 133 base::TimeDelta current_ts = (*itr)->GetTimestamp(); |
| 134 if (last_buffer_timestamp_ != kNoTimestamp) { | 134 if (last_buffer_timestamp_ != kNoTimestamp()) { |
| 135 DCHECK_GT(current_ts.ToInternalValue(), | 135 DCHECK_GT(current_ts.ToInternalValue(), |
| 136 last_buffer_timestamp_.ToInternalValue()); | 136 last_buffer_timestamp_.ToInternalValue()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 last_buffer_timestamp_ = current_ts; | 139 last_buffer_timestamp_ = current_ts; |
| 140 buffers_.push_back(*itr); | 140 buffers_.push_back(*itr); |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 while (!buffers_.empty() && !read_cbs_.empty()) { | 144 while (!buffers_.empty() && !read_cbs_.empty()) { |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 if (!video_->CanAddBuffers(buffers)) | 634 if (!video_->CanAddBuffers(buffers)) |
| 635 return false; | 635 return false; |
| 636 | 636 |
| 637 video_->AddBuffers(buffers); | 637 video_->AddBuffers(buffers); |
| 638 seek_waits_for_data_ = false; | 638 seek_waits_for_data_ = false; |
| 639 | 639 |
| 640 return true; | 640 return true; |
| 641 } | 641 } |
| 642 | 642 |
| 643 } // namespace media | 643 } // namespace media |
| OLD | NEW |