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 <algorithm> |
| 8 #include <deque> |
| 9 |
7 #include "base/bind.h" | 10 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/location.h" |
9 #include "base/logging.h" | 13 #include "base/logging.h" |
10 #include "base/message_loop.h" | 14 #include "base/message_loop_proxy.h" |
11 #include "base/string_util.h" | 15 #include "base/string_util.h" |
12 #include "media/base/audio_decoder_config.h" | 16 #include "media/base/audio_decoder_config.h" |
13 #include "media/base/stream_parser_buffer.h" | 17 #include "media/base/stream_parser_buffer.h" |
14 #include "media/base/video_decoder_config.h" | 18 #include "media/base/video_decoder_config.h" |
15 #include "media/filters/chunk_demuxer_client.h" | 19 #include "media/filters/chunk_demuxer_client.h" |
16 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 20 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
17 #include "media/mp4/mp4_stream_parser.h" | 21 #include "media/mp4/mp4_stream_parser.h" |
18 #endif | 22 #endif |
19 #include "media/webm/webm_stream_parser.h" | 23 #include "media/webm/webm_stream_parser.h" |
20 | 24 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 ChangeState_Locked(SHUTDOWN); | 365 ChangeState_Locked(SHUTDOWN); |
362 std::swap(read_cbs_, read_cbs); | 366 std::swap(read_cbs_, read_cbs); |
363 } | 367 } |
364 | 368 |
365 // Pass end of stream buffers to all callbacks to signal that no more data | 369 // Pass end of stream buffers to all callbacks to signal that no more data |
366 // will be sent. | 370 // will be sent. |
367 for (ReadCBQueue::iterator it = read_cbs.begin(); it != read_cbs.end(); ++it) | 371 for (ReadCBQueue::iterator it = read_cbs.begin(); it != read_cbs.end(); ++it) |
368 it->Run(DemuxerStream::kOk, StreamParserBuffer::CreateEOSBuffer()); | 372 it->Run(DemuxerStream::kOk, StreamParserBuffer::CreateEOSBuffer()); |
369 } | 373 } |
370 | 374 |
371 // Helper function that makes sure |read_cb| runs on |message_loop|. | 375 // Helper function that makes sure |read_cb| runs on |message_loop_proxy|. |
372 static void RunOnMessageLoop(const DemuxerStream::ReadCB& read_cb, | 376 static void RunOnMessageLoop( |
373 MessageLoop* message_loop, | 377 const DemuxerStream::ReadCB& read_cb, |
374 DemuxerStream::Status status, | 378 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy, |
375 const scoped_refptr<DecoderBuffer>& buffer) { | 379 DemuxerStream::Status status, |
376 if (MessageLoop::current() != message_loop) { | 380 const scoped_refptr<DecoderBuffer>& buffer) { |
377 message_loop->PostTask(FROM_HERE, base::Bind( | 381 if (!message_loop_proxy->BelongsToCurrentThread()) { |
378 &RunOnMessageLoop, read_cb, message_loop, status, buffer)); | 382 message_loop_proxy->PostTask(FROM_HERE, base::Bind( |
| 383 &RunOnMessageLoop, read_cb, message_loop_proxy, status, buffer)); |
379 return; | 384 return; |
380 } | 385 } |
381 | 386 |
382 read_cb.Run(status, buffer); | 387 read_cb.Run(status, buffer); |
383 } | 388 } |
384 | 389 |
385 // DemuxerStream methods. | 390 // DemuxerStream methods. |
386 void ChunkDemuxerStream::Read(const ReadCB& read_cb) { | 391 void ChunkDemuxerStream::Read(const ReadCB& read_cb) { |
387 DemuxerStream::Status status = kOk; | 392 DemuxerStream::Status status = kOk; |
388 scoped_refptr<StreamParserBuffer> buffer; | 393 scoped_refptr<StreamParserBuffer> buffer; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 state_ = state; | 426 state_ = state; |
422 } | 427 } |
423 | 428 |
424 ChunkDemuxerStream::~ChunkDemuxerStream() {} | 429 ChunkDemuxerStream::~ChunkDemuxerStream() {} |
425 | 430 |
426 void ChunkDemuxerStream::DeferRead_Locked(const ReadCB& read_cb) { | 431 void ChunkDemuxerStream::DeferRead_Locked(const ReadCB& read_cb) { |
427 lock_.AssertAcquired(); | 432 lock_.AssertAcquired(); |
428 // Wrap & store |read_cb| so that it will | 433 // Wrap & store |read_cb| so that it will |
429 // get called on the current MessageLoop. | 434 // get called on the current MessageLoop. |
430 read_cbs_.push_back(base::Bind(&RunOnMessageLoop, read_cb, | 435 read_cbs_.push_back(base::Bind(&RunOnMessageLoop, read_cb, |
431 MessageLoop::current())); | 436 base::MessageLoopProxy::current())); |
432 } | 437 } |
433 | 438 |
434 void ChunkDemuxerStream::CreateReadDoneClosures_Locked(ClosureQueue* closures) { | 439 void ChunkDemuxerStream::CreateReadDoneClosures_Locked(ClosureQueue* closures) { |
435 lock_.AssertAcquired(); | 440 lock_.AssertAcquired(); |
436 | 441 |
437 if (state_ != RETURNING_DATA_FOR_READS) | 442 if (state_ != RETURNING_DATA_FOR_READS) |
438 return; | 443 return; |
439 | 444 |
440 DemuxerStream::Status status; | 445 DemuxerStream::Status status; |
441 scoped_refptr<StreamParserBuffer> buffer; | 446 scoped_refptr<StreamParserBuffer> buffer; |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 (*itr)->SetTimestamp((*itr)->GetTimestamp() + timestamp_offset); | 1092 (*itr)->SetTimestamp((*itr)->GetTimestamp() + timestamp_offset); |
1088 } | 1093 } |
1089 } | 1094 } |
1090 | 1095 |
1091 bool ChunkDemuxer::IsValidId(const std::string& source_id) const { | 1096 bool ChunkDemuxer::IsValidId(const std::string& source_id) const { |
1092 return source_info_map_.count(source_id) > 0u && | 1097 return source_info_map_.count(source_id) > 0u && |
1093 stream_parser_map_.count(source_id) > 0u; | 1098 stream_parser_map_.count(source_id) > 0u; |
1094 } | 1099 } |
1095 | 1100 |
1096 } // namespace media | 1101 } // namespace media |
OLD | NEW |