OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 153 } |
154 | 154 |
155 DemuxerStream::Type FFmpegDemuxerStream::type() { | 155 DemuxerStream::Type FFmpegDemuxerStream::type() { |
156 return type_; | 156 return type_; |
157 } | 157 } |
158 | 158 |
159 void FFmpegDemuxerStream::Read(const ReadCallback& read_callback) { | 159 void FFmpegDemuxerStream::Read(const ReadCallback& read_callback) { |
160 DCHECK(!read_callback.is_null()); | 160 DCHECK(!read_callback.is_null()); |
161 | 161 |
162 base::AutoLock auto_lock(lock_); | 162 base::AutoLock auto_lock(lock_); |
| 163 // Don't accept any additional reads if we've been told to stop. |
| 164 // The demuxer_ may have been destroyed in the pipleine thread. |
| 165 // |
| 166 // TODO(scherkus): it would be cleaner if we replied with an error message. |
| 167 if (stopped_) { |
| 168 read_callback.Run(new DataBuffer(0)); |
| 169 return; |
| 170 } |
| 171 |
163 if (!buffer_queue_.empty()) { | 172 if (!buffer_queue_.empty()) { |
164 // Dequeue a buffer send back. | 173 // Dequeue a buffer send back. |
165 scoped_refptr<Buffer> buffer = buffer_queue_.front(); | 174 scoped_refptr<Buffer> buffer = buffer_queue_.front(); |
166 buffer_queue_.pop_front(); | 175 buffer_queue_.pop_front(); |
167 | 176 |
168 // Execute the callback. | 177 // Execute the callback. |
169 read_callback.Run(buffer); | 178 read_callback.Run(buffer); |
170 | 179 |
171 if (!read_queue_.empty()) | 180 if (!read_queue_.empty()) |
172 demuxer_->PostDemuxTask(); | 181 demuxer_->PostDemuxTask(); |
173 | 182 |
174 } else { | 183 } else { |
175 demuxer_->message_loop()->PostTask(FROM_HERE, base::Bind( | 184 demuxer_->message_loop()->PostTask(FROM_HERE, base::Bind( |
176 &FFmpegDemuxerStream::ReadTask, this, read_callback)); | 185 &FFmpegDemuxerStream::ReadTask, this, read_callback)); |
177 } | 186 } |
178 } | 187 } |
179 | 188 |
180 void FFmpegDemuxerStream::ReadTask(const ReadCallback& read_callback) { | 189 void FFmpegDemuxerStream::ReadTask(const ReadCallback& read_callback) { |
181 DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); | 190 DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); |
182 | 191 |
183 base::AutoLock auto_lock(lock_); | 192 base::AutoLock auto_lock(lock_); |
184 // Don't accept any additional reads if we've been told to stop. | 193 // Don't accept any additional reads if we've been told to stop. |
185 // | 194 // |
186 // TODO(scherkus): it would be cleaner if we replied with an error message. | 195 // TODO(scherkus): it would be cleaner if we replied with an error message. |
187 if (stopped_) { | 196 if (stopped_) { |
| 197 read_callback.Run(new DataBuffer(0)); |
188 return; | 198 return; |
189 } | 199 } |
190 | 200 |
191 // Enqueue the callback and attempt to satisfy it immediately. | 201 // Enqueue the callback and attempt to satisfy it immediately. |
192 read_queue_.push_back(read_callback); | 202 read_queue_.push_back(read_callback); |
193 FulfillPendingRead(); | 203 FulfillPendingRead(); |
194 | 204 |
195 // Check if there are still pending reads, demux some more. | 205 // Check if there are still pending reads, demux some more. |
196 if (!read_queue_.empty()) { | 206 if (!read_queue_.empty()) { |
197 demuxer_->PostDemuxTask(); | 207 demuxer_->PostDemuxTask(); |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 read_event_.Wait(); | 730 read_event_.Wait(); |
721 return last_read_bytes_; | 731 return last_read_bytes_; |
722 } | 732 } |
723 | 733 |
724 void FFmpegDemuxer::SignalReadCompleted(size_t size) { | 734 void FFmpegDemuxer::SignalReadCompleted(size_t size) { |
725 last_read_bytes_ = size; | 735 last_read_bytes_ = size; |
726 read_event_.Signal(); | 736 read_event_.Signal(); |
727 } | 737 } |
728 | 738 |
729 } // namespace media | 739 } // namespace media |
OLD | NEW |