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/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/message_loop.h" | 11 #include "base/message_loop_proxy.h" |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
12 #include "media/base/audio_decoder_config.h" | 13 #include "media/base/audio_decoder_config.h" |
13 #include "media/base/stream_parser_buffer.h" | 14 #include "media/base/stream_parser_buffer.h" |
14 #include "media/base/video_decoder_config.h" | 15 #include "media/base/video_decoder_config.h" |
15 #include "media/filters/chunk_demuxer_client.h" | 16 #include "media/filters/chunk_demuxer_client.h" |
16 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 17 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
17 #include "media/mp4/mp4_stream_parser.h" | 18 #include "media/mp4/mp4_stream_parser.h" |
18 #endif | 19 #endif |
19 #include "media/webm/webm_stream_parser.h" | 20 #include "media/webm/webm_stream_parser.h" |
20 | 21 |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 ChangeState_Locked(SHUTDOWN); | 395 ChangeState_Locked(SHUTDOWN); |
395 std::swap(read_cbs_, read_cbs); | 396 std::swap(read_cbs_, read_cbs); |
396 } | 397 } |
397 | 398 |
398 // Pass end of stream buffers to all callbacks to signal that no more data | 399 // Pass end of stream buffers to all callbacks to signal that no more data |
399 // will be sent. | 400 // will be sent. |
400 for (ReadCBQueue::iterator it = read_cbs.begin(); it != read_cbs.end(); ++it) | 401 for (ReadCBQueue::iterator it = read_cbs.begin(); it != read_cbs.end(); ++it) |
401 it->Run(DemuxerStream::kOk, StreamParserBuffer::CreateEOSBuffer()); | 402 it->Run(DemuxerStream::kOk, StreamParserBuffer::CreateEOSBuffer()); |
402 } | 403 } |
403 | 404 |
404 // Helper function that makes sure |read_cb| runs on |message_loop|. | 405 // Helper function that makes sure |read_cb| runs on |message_loop_proxy|. |
405 static void RunOnMessageLoop(const DemuxerStream::ReadCB& read_cb, | 406 static void RunOnMessageLoop( |
406 MessageLoop* message_loop, | 407 const DemuxerStream::ReadCB& read_cb, |
407 DemuxerStream::Status status, | 408 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy, |
408 const scoped_refptr<DecoderBuffer>& buffer) { | 409 DemuxerStream::Status status, |
409 if (MessageLoop::current() != message_loop) { | 410 const scoped_refptr<DecoderBuffer>& buffer) { |
410 message_loop->PostTask(FROM_HERE, base::Bind( | 411 if (!message_loop_proxy->BelongsToCurrentThread()) { |
411 &RunOnMessageLoop, read_cb, message_loop, status, buffer)); | 412 message_loop_proxy->PostTask(FROM_HERE, base::Bind( |
| 413 &RunOnMessageLoop, read_cb, message_loop_proxy, status, buffer)); |
412 return; | 414 return; |
413 } | 415 } |
414 | 416 |
415 read_cb.Run(status, buffer); | 417 read_cb.Run(status, buffer); |
416 } | 418 } |
417 | 419 |
418 // DemuxerStream methods. | 420 // DemuxerStream methods. |
419 void ChunkDemuxerStream::Read(const ReadCB& read_cb) { | 421 void ChunkDemuxerStream::Read(const ReadCB& read_cb) { |
420 DemuxerStream::Status status = kOk; | 422 DemuxerStream::Status status = kOk; |
421 scoped_refptr<StreamParserBuffer> buffer; | 423 scoped_refptr<StreamParserBuffer> buffer; |
(...skipping 29 matching lines...) Expand all Loading... |
451 state_ = state; | 453 state_ = state; |
452 } | 454 } |
453 | 455 |
454 ChunkDemuxerStream::~ChunkDemuxerStream() {} | 456 ChunkDemuxerStream::~ChunkDemuxerStream() {} |
455 | 457 |
456 void ChunkDemuxerStream::DeferRead_Locked(const ReadCB& read_cb) { | 458 void ChunkDemuxerStream::DeferRead_Locked(const ReadCB& read_cb) { |
457 lock_.AssertAcquired(); | 459 lock_.AssertAcquired(); |
458 // Wrap & store |read_cb| so that it will | 460 // Wrap & store |read_cb| so that it will |
459 // get called on the current MessageLoop. | 461 // get called on the current MessageLoop. |
460 read_cbs_.push_back(base::Bind(&RunOnMessageLoop, read_cb, | 462 read_cbs_.push_back(base::Bind(&RunOnMessageLoop, read_cb, |
461 MessageLoop::current())); | 463 base::MessageLoopProxy::current())); |
462 } | 464 } |
463 | 465 |
464 void ChunkDemuxerStream::CreateReadDoneClosures_Locked(ClosureQueue* closures) { | 466 void ChunkDemuxerStream::CreateReadDoneClosures_Locked(ClosureQueue* closures) { |
465 lock_.AssertAcquired(); | 467 lock_.AssertAcquired(); |
466 | 468 |
467 if (state_ != RETURNING_DATA_FOR_READS) | 469 if (state_ != RETURNING_DATA_FOR_READS) |
468 return; | 470 return; |
469 | 471 |
470 DemuxerStream::Status status; | 472 DemuxerStream::Status status; |
471 scoped_refptr<StreamParserBuffer> buffer; | 473 scoped_refptr<StreamParserBuffer> buffer; |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 video_->SetStartTime(start_time_); | 1063 video_->SetStartTime(start_time_); |
1062 video_->Seek(start_time_); | 1064 video_->Seek(start_time_); |
1063 } | 1065 } |
1064 | 1066 |
1065 // The demuxer is now initialized after the |start_timestamp_| was set. | 1067 // The demuxer is now initialized after the |start_timestamp_| was set. |
1066 ChangeState_Locked(INITIALIZED); | 1068 ChangeState_Locked(INITIALIZED); |
1067 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); | 1069 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
1068 } | 1070 } |
1069 | 1071 |
1070 } // namespace media | 1072 } // namespace media |
OLD | NEW |