| 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" |
| 11 #include "media/base/data_buffer.h" | 11 #include "media/base/data_buffer.h" |
| 12 #include "media/base/video_decoder_config.h" | 12 #include "media/base/video_decoder_config.h" |
| 13 #include "media/filters/chunk_demuxer_client.h" | 13 #include "media/filters/chunk_demuxer_client.h" |
| 14 #include "media/webm/webm_stream_parser.h" | 14 #include "media/webm/webm_stream_parser.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 | 17 |
| 18 // TODO(acolwell): Remove this when fixing http://crbug.com/122909 . | |
| 19 const char* kDefaultSourceType = "video/webm; codecs=\"vp8, vorbis\""; | |
| 20 | |
| 21 // Create an "end of stream" buffer. | 18 // Create an "end of stream" buffer. |
| 22 static Buffer* CreateEOSBuffer() { | 19 static Buffer* CreateEOSBuffer() { |
| 23 return new DataBuffer(0); | 20 return new DataBuffer(0); |
| 24 } | 21 } |
| 25 | 22 |
| 26 class ChunkDemuxerStream : public DemuxerStream { | 23 class ChunkDemuxerStream : public DemuxerStream { |
| 27 public: | 24 public: |
| 28 typedef std::deque<scoped_refptr<Buffer> > BufferQueue; | 25 typedef std::deque<scoped_refptr<Buffer> > BufferQueue; |
| 29 typedef std::deque<ReadCB> ReadCBQueue; | 26 typedef std::deque<ReadCB> ReadCBQueue; |
| 30 typedef std::deque<base::Closure> ClosureQueue; | 27 typedef std::deque<base::Closure> ClosureQueue; |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 if (video_.get()) | 448 if (video_.get()) |
| 452 video_->Flush(); | 449 video_->Flush(); |
| 453 | 450 |
| 454 byte_queue_.Reset(); | 451 byte_queue_.Reset(); |
| 455 stream_parser_->Flush(); | 452 stream_parser_->Flush(); |
| 456 | 453 |
| 457 seek_waits_for_data_ = true; | 454 seek_waits_for_data_ = true; |
| 458 ChangeState_Locked(INITIALIZED); | 455 ChangeState_Locked(INITIALIZED); |
| 459 } | 456 } |
| 460 | 457 |
| 461 ChunkDemuxer::Status ChunkDemuxer::AddId(const std::string& id, | 458 bool ChunkDemuxer::AppendData(const uint8* data, size_t length) { |
| 462 const std::string& type) { | 459 DVLOG(1) << "AppendData(" << length << ")"; |
| 463 // TODO(acolwell): Proper mimetype decoding and support for more than one ID | |
| 464 // will be added as part of http://crbug.com/122909 | |
| 465 if (type != kDefaultSourceType) | |
| 466 return kNotSupported; | |
| 467 | 460 |
| 468 if (!source_id_.empty()) | 461 if (!data || length == 0u) |
| 469 return kReachedIdLimit; | |
| 470 | |
| 471 source_id_ = id; | |
| 472 return kOk; | |
| 473 } | |
| 474 | |
| 475 bool ChunkDemuxer::RemoveId(const std::string& id) { | |
| 476 DCHECK(!source_id_.empty()); | |
| 477 DCHECK_EQ(source_id_, id); | |
| 478 source_id_ = ""; | |
| 479 return true; | |
| 480 } | |
| 481 | |
| 482 bool ChunkDemuxer::AppendData(const std::string& id, | |
| 483 const uint8* data, | |
| 484 size_t length) { | |
| 485 DVLOG(1) << "AppendData(" << id << ", " << length << ")"; | |
| 486 | |
| 487 // TODO(acolwell): Remove when http://webk.it/83788 fix lands. | |
| 488 if (source_id_.empty()) | |
| 489 AddId(id, kDefaultSourceType); | |
| 490 | |
| 491 DCHECK(!source_id_.empty()); | |
| 492 DCHECK_EQ(source_id_, id); | |
| 493 | |
| 494 if (id.empty() || !data || length == 0u) | |
| 495 return false; | 462 return false; |
| 496 | 463 |
| 497 int64 buffered_bytes = 0; | 464 int64 buffered_bytes = 0; |
| 498 base::TimeDelta buffered_ts = base::TimeDelta::FromSeconds(-1); | 465 base::TimeDelta buffered_ts = base::TimeDelta::FromSeconds(-1); |
| 499 | 466 |
| 500 PipelineStatusCB cb; | 467 PipelineStatusCB cb; |
| 501 { | 468 { |
| 502 base::AutoLock auto_lock(lock_); | 469 base::AutoLock auto_lock(lock_); |
| 503 | 470 |
| 504 byte_queue_.Push(data, length); | 471 byte_queue_.Push(data, length); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 if (!video_->CanAddBuffers(buffers)) | 714 if (!video_->CanAddBuffers(buffers)) |
| 748 return false; | 715 return false; |
| 749 | 716 |
| 750 video_->AddBuffers(buffers); | 717 video_->AddBuffers(buffers); |
| 751 seek_waits_for_data_ = false; | 718 seek_waits_for_data_ = false; |
| 752 | 719 |
| 753 return true; | 720 return true; |
| 754 } | 721 } |
| 755 | 722 |
| 756 } // namespace media | 723 } // namespace media |
| OLD | NEW |