| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 DCHECK(read_queue_.empty()) << "Read requests should be empty"; | 135 DCHECK(read_queue_.empty()) << "Read requests should be empty"; |
| 136 buffer_queue_.clear(); | 136 buffer_queue_.clear(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void FFmpegDemuxerStream::Stop() { | 139 void FFmpegDemuxerStream::Stop() { |
| 140 DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); | 140 DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); |
| 141 base::AutoLock auto_lock(lock_); | 141 base::AutoLock auto_lock(lock_); |
| 142 buffer_queue_.clear(); | 142 buffer_queue_.clear(); |
| 143 for (ReadQueue::iterator it = read_queue_.begin(); | 143 for (ReadQueue::iterator it = read_queue_.begin(); |
| 144 it != read_queue_.end(); ++it) { | 144 it != read_queue_.end(); ++it) { |
| 145 it->Run(new DataBuffer(0)); | 145 it->Run(scoped_refptr<Buffer>(new DataBuffer(0))); |
| 146 } | 146 } |
| 147 read_queue_.clear(); | 147 read_queue_.clear(); |
| 148 stopped_ = true; | 148 stopped_ = true; |
| 149 } | 149 } |
| 150 | 150 |
| 151 base::TimeDelta FFmpegDemuxerStream::duration() { | 151 base::TimeDelta FFmpegDemuxerStream::duration() { |
| 152 return duration_; | 152 return duration_; |
| 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. | 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. | 164 // The demuxer_ may have been destroyed in the pipleine thread. |
| 165 // | 165 // |
| 166 // TODO(scherkus): it would be cleaner if we replied with an error message. | 166 // TODO(scherkus): it would be cleaner if we replied with an error message. |
| 167 if (stopped_) { | 167 if (stopped_) { |
| 168 read_callback.Run(new DataBuffer(0)); | 168 read_callback.Run(scoped_refptr<Buffer>(new DataBuffer(0))); |
| 169 return; | 169 return; |
| 170 } | 170 } |
| 171 | 171 |
| 172 if (!buffer_queue_.empty()) { | 172 if (!buffer_queue_.empty()) { |
| 173 // Dequeue a buffer send back. | 173 // Dequeue a buffer send back. |
| 174 scoped_refptr<Buffer> buffer = buffer_queue_.front(); | 174 scoped_refptr<Buffer> buffer = buffer_queue_.front(); |
| 175 buffer_queue_.pop_front(); | 175 buffer_queue_.pop_front(); |
| 176 | 176 |
| 177 // Execute the callback. | 177 // Execute the callback. |
| 178 read_callback.Run(buffer); | 178 read_callback.Run(buffer); |
| 179 | 179 |
| 180 if (!read_queue_.empty()) | 180 if (!read_queue_.empty()) |
| 181 demuxer_->PostDemuxTask(); | 181 demuxer_->PostDemuxTask(); |
| 182 | 182 |
| 183 } else { | 183 } else { |
| 184 demuxer_->message_loop()->PostTask(FROM_HERE, base::Bind( | 184 demuxer_->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 185 &FFmpegDemuxerStream::ReadTask, this, read_callback)); | 185 &FFmpegDemuxerStream::ReadTask, this, read_callback)); |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 | 188 |
| 189 void FFmpegDemuxerStream::ReadTask(const ReadCallback& read_callback) { | 189 void FFmpegDemuxerStream::ReadTask(const ReadCallback& read_callback) { |
| 190 DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); | 190 DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); |
| 191 | 191 |
| 192 base::AutoLock auto_lock(lock_); | 192 base::AutoLock auto_lock(lock_); |
| 193 // 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. |
| 194 // | 194 // |
| 195 // 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. |
| 196 if (stopped_) { | 196 if (stopped_) { |
| 197 read_callback.Run(new DataBuffer(0)); | 197 read_callback.Run(scoped_refptr<Buffer>(new DataBuffer(0))); |
| 198 return; | 198 return; |
| 199 } | 199 } |
| 200 | 200 |
| 201 // Enqueue the callback and attempt to satisfy it immediately. | 201 // Enqueue the callback and attempt to satisfy it immediately. |
| 202 read_queue_.push_back(read_callback); | 202 read_queue_.push_back(read_callback); |
| 203 FulfillPendingRead(); | 203 FulfillPendingRead(); |
| 204 | 204 |
| 205 // Check if there are still pending reads, demux some more. | 205 // Check if there are still pending reads, demux some more. |
| 206 if (!read_queue_.empty()) { | 206 if (!read_queue_.empty()) { |
| 207 demuxer_->PostDemuxTask(); | 207 demuxer_->PostDemuxTask(); |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 read_event_.Wait(); | 730 read_event_.Wait(); |
| 731 return last_read_bytes_; | 731 return last_read_bytes_; |
| 732 } | 732 } |
| 733 | 733 |
| 734 void FFmpegDemuxer::SignalReadCompleted(size_t size) { | 734 void FFmpegDemuxer::SignalReadCompleted(size_t size) { |
| 735 last_read_bytes_ = size; | 735 last_read_bytes_ = size; |
| 736 read_event_.Signal(); | 736 read_event_.Signal(); |
| 737 } | 737 } |
| 738 | 738 |
| 739 } // namespace media | 739 } // namespace media |
| OLD | NEW |