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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 { | 209 { |
210 base::AutoLock auto_lock(lock_); | 210 base::AutoLock auto_lock(lock_); |
211 buffers_.clear(); | 211 buffers_.clear(); |
212 ChangeState_Locked(WAITING_FOR_SEEK); | 212 ChangeState_Locked(WAITING_FOR_SEEK); |
213 last_buffer_timestamp_ = kNoTimestamp(); | 213 last_buffer_timestamp_ = kNoTimestamp(); |
214 | 214 |
215 std::swap(read_cbs_, read_cbs); | 215 std::swap(read_cbs_, read_cbs); |
216 } | 216 } |
217 | 217 |
218 for (ReadCBQueue::iterator it = read_cbs.begin(); it != read_cbs.end(); ++it) | 218 for (ReadCBQueue::iterator it = read_cbs.begin(); it != read_cbs.end(); ++it) |
219 it->Run(scoped_refptr<Buffer>()); | 219 it->Run(scoped_refptr<DecoderBuffer>()); |
220 } | 220 } |
221 | 221 |
222 void ChunkDemuxerStream::Seek(base::TimeDelta time) { | 222 void ChunkDemuxerStream::Seek(base::TimeDelta time) { |
223 base::AutoLock auto_lock(lock_); | 223 base::AutoLock auto_lock(lock_); |
224 | 224 |
225 DCHECK(read_cbs_.empty()); | 225 DCHECK(read_cbs_.empty()); |
226 | 226 |
227 if (state_ == WAITING_FOR_SEEK) { | 227 if (state_ == WAITING_FOR_SEEK) { |
228 ChangeState_Locked(RETURNING_DATA_FOR_READS); | 228 ChangeState_Locked(RETURNING_DATA_FOR_READS); |
229 return; | 229 return; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 base::TimeDelta end_duration = buffers_.back()->GetDuration(); | 318 base::TimeDelta end_duration = buffers_.back()->GetDuration(); |
319 if (end_duration != kNoTimestamp()) | 319 if (end_duration != kNoTimestamp()) |
320 *end_out += end_duration; | 320 *end_out += end_duration; |
321 | 321 |
322 return true; | 322 return true; |
323 } | 323 } |
324 | 324 |
325 // Helper function that makes sure |read_cb| runs on |message_loop|. | 325 // Helper function that makes sure |read_cb| runs on |message_loop|. |
326 static void RunOnMessageLoop(const DemuxerStream::ReadCB& read_cb, | 326 static void RunOnMessageLoop(const DemuxerStream::ReadCB& read_cb, |
327 MessageLoop* message_loop, | 327 MessageLoop* message_loop, |
328 const scoped_refptr<Buffer>& buffer) { | 328 const scoped_refptr<DecoderBuffer>& buffer) { |
329 if (MessageLoop::current() != message_loop) { | 329 if (MessageLoop::current() != message_loop) { |
330 message_loop->PostTask(FROM_HERE, base::Bind( | 330 message_loop->PostTask(FROM_HERE, base::Bind( |
331 &RunOnMessageLoop, read_cb, message_loop, buffer)); | 331 &RunOnMessageLoop, read_cb, message_loop, buffer)); |
332 return; | 332 return; |
333 } | 333 } |
334 | 334 |
335 read_cb.Run(buffer); | 335 read_cb.Run(buffer); |
336 } | 336 } |
337 | 337 |
338 // DemuxerStream methods. | 338 // DemuxerStream methods. |
339 void ChunkDemuxerStream::Read(const ReadCB& read_cb) { | 339 void ChunkDemuxerStream::Read(const ReadCB& read_cb) { |
340 scoped_refptr<Buffer> buffer; | 340 scoped_refptr<DecoderBuffer> buffer; |
341 | 341 |
342 { | 342 { |
343 base::AutoLock auto_lock(lock_); | 343 base::AutoLock auto_lock(lock_); |
344 | 344 |
345 switch (state_) { | 345 switch (state_) { |
346 case RETURNING_DATA_FOR_READS: | 346 case RETURNING_DATA_FOR_READS: |
347 // If we don't have any buffers ready or already have | 347 // If we don't have any buffers ready or already have |
348 // pending reads, then defer this read. | 348 // pending reads, then defer this read. |
349 if (buffers_.empty() || !read_cbs_.empty()) { | 349 if (buffers_.empty() || !read_cbs_.empty()) { |
350 DeferRead_Locked(read_cb); | 350 DeferRead_Locked(read_cb); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 while (!buffers_.empty() && !read_cbs_.empty()) { | 423 while (!buffers_.empty() && !read_cbs_.empty()) { |
424 closures->push_back(base::Bind(read_cbs_.front(), buffers_.front())); | 424 closures->push_back(base::Bind(read_cbs_.front(), buffers_.front())); |
425 buffers_.pop_front(); | 425 buffers_.pop_front(); |
426 read_cbs_.pop_front(); | 426 read_cbs_.pop_front(); |
427 } | 427 } |
428 | 428 |
429 if (state_ != RECEIVED_EOS || !buffers_.empty() || read_cbs_.empty()) | 429 if (state_ != RECEIVED_EOS || !buffers_.empty() || read_cbs_.empty()) |
430 return; | 430 return; |
431 | 431 |
432 // Push enough EOS buffers to satisfy outstanding Read() requests. | 432 // Push enough EOS buffers to satisfy outstanding Read() requests. |
433 scoped_refptr<Buffer> end_of_stream_buffer = | 433 scoped_refptr<DecoderBuffer> end_of_stream_buffer = |
434 StreamParserBuffer::CreateEOSBuffer(); | 434 StreamParserBuffer::CreateEOSBuffer(); |
435 while (!read_cbs_.empty()) { | 435 while (!read_cbs_.empty()) { |
436 closures->push_back(base::Bind(read_cbs_.front(), end_of_stream_buffer)); | 436 closures->push_back(base::Bind(read_cbs_.front(), end_of_stream_buffer)); |
437 read_cbs_.pop_front(); | 437 read_cbs_.pop_front(); |
438 } | 438 } |
439 | 439 |
440 ChangeState_Locked(RETURNING_EOS_FOR_READS); | 440 ChangeState_Locked(RETURNING_EOS_FOR_READS); |
441 } | 441 } |
442 | 442 |
443 ChunkDemuxer::ChunkDemuxer(ChunkDemuxerClient* client) | 443 ChunkDemuxer::ChunkDemuxer(ChunkDemuxerClient* client) |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 return true; | 891 return true; |
892 } | 892 } |
893 | 893 |
894 bool ChunkDemuxer::OnKeyNeeded(scoped_array<uint8> init_data, | 894 bool ChunkDemuxer::OnKeyNeeded(scoped_array<uint8> init_data, |
895 int init_data_size) { | 895 int init_data_size) { |
896 client_->KeyNeeded(init_data.Pass(), init_data_size); | 896 client_->KeyNeeded(init_data.Pass(), init_data_size); |
897 return true; | 897 return true; |
898 } | 898 } |
899 | 899 |
900 } // namespace media | 900 } // namespace media |
OLD | NEW |