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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 void AddBuffers(const BufferQueue& buffers); | 133 void AddBuffers(const BufferQueue& buffers); |
134 void Shutdown(); | 134 void Shutdown(); |
135 | 135 |
136 // Gets the time range buffered by this object. | 136 // Gets the time range buffered by this object. |
137 // Returns true if there is buffered data. |start_out| & |end_out| are set to | 137 // Returns true if there is buffered data. |start_out| & |end_out| are set to |
138 // the start and end time of the buffered data respectively. | 138 // the start and end time of the buffered data respectively. |
139 // Returns false if no data is buffered. | 139 // Returns false if no data is buffered. |
140 bool GetBufferedRange(base::TimeDelta* start_out, | 140 bool GetBufferedRange(base::TimeDelta* start_out, |
141 base::TimeDelta* end_out) const; | 141 base::TimeDelta* end_out) const; |
142 | 142 |
143 bool GetLastBufferTimestamp(base::TimeDelta* timestamp) const; | |
144 | |
145 // DemuxerStream methods. | 143 // DemuxerStream methods. |
146 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 144 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
147 virtual Type type() OVERRIDE; | 145 virtual Type type() OVERRIDE; |
148 virtual void EnableBitstreamConverter() OVERRIDE; | 146 virtual void EnableBitstreamConverter() OVERRIDE; |
149 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; | 147 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; |
150 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE; | 148 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE; |
151 | 149 |
152 protected: | 150 protected: |
153 virtual ~ChunkDemuxerStream(); | 151 virtual ~ChunkDemuxerStream(); |
154 | 152 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 *start_out = buffers_.front()->GetTimestamp(); | 315 *start_out = buffers_.front()->GetTimestamp(); |
318 *end_out = buffers_.back()->GetTimestamp(); | 316 *end_out = buffers_.back()->GetTimestamp(); |
319 | 317 |
320 base::TimeDelta end_duration = buffers_.back()->GetDuration(); | 318 base::TimeDelta end_duration = buffers_.back()->GetDuration(); |
321 if (end_duration != kNoTimestamp()) | 319 if (end_duration != kNoTimestamp()) |
322 *end_out += end_duration; | 320 *end_out += end_duration; |
323 | 321 |
324 return true; | 322 return true; |
325 } | 323 } |
326 | 324 |
327 bool ChunkDemuxerStream::GetLastBufferTimestamp( | |
328 base::TimeDelta* timestamp) const { | |
329 base::AutoLock auto_lock(lock_); | |
330 | |
331 if (buffers_.empty()) | |
332 return false; | |
333 | |
334 *timestamp = buffers_.back()->GetTimestamp(); | |
335 return true; | |
336 } | |
337 | |
338 // Helper function that makes sure |read_cb| runs on |message_loop|. | 325 // Helper function that makes sure |read_cb| runs on |message_loop|. |
339 static void RunOnMessageLoop(const DemuxerStream::ReadCB& read_cb, | 326 static void RunOnMessageLoop(const DemuxerStream::ReadCB& read_cb, |
340 MessageLoop* message_loop, | 327 MessageLoop* message_loop, |
341 const scoped_refptr<Buffer>& buffer) { | 328 const scoped_refptr<Buffer>& buffer) { |
342 if (MessageLoop::current() != message_loop) { | 329 if (MessageLoop::current() != message_loop) { |
343 message_loop->PostTask(FROM_HERE, base::Bind( | 330 message_loop->PostTask(FROM_HERE, base::Bind( |
344 &RunOnMessageLoop, read_cb, message_loop, buffer)); | 331 &RunOnMessageLoop, read_cb, message_loop, buffer)); |
345 return; | 332 return; |
346 } | 333 } |
347 | 334 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 AddId(id, "video/webm", codecs); | 647 AddId(id, "video/webm", codecs); |
661 } | 648 } |
662 | 649 |
663 DCHECK(!source_id_.empty()); | 650 DCHECK(!source_id_.empty()); |
664 DCHECK_EQ(source_id_, id); | 651 DCHECK_EQ(source_id_, id); |
665 DCHECK(!id.empty()); | 652 DCHECK(!id.empty()); |
666 DCHECK(data); | 653 DCHECK(data); |
667 DCHECK_GT(length, 0u); | 654 DCHECK_GT(length, 0u); |
668 | 655 |
669 int64 buffered_bytes = 0; | 656 int64 buffered_bytes = 0; |
670 base::TimeDelta buffered_ts = base::TimeDelta::FromSeconds(-1); | |
671 | 657 |
672 PipelineStatusCB cb; | 658 PipelineStatusCB cb; |
673 { | 659 { |
674 base::AutoLock auto_lock(lock_); | 660 base::AutoLock auto_lock(lock_); |
675 | 661 |
676 // Capture |seek_waits_for_data_| state before we start parsing. | 662 // Capture |seek_waits_for_data_| state before we start parsing. |
677 // Its state can be changed by OnAudioBuffers() or OnVideoBuffers() | 663 // Its state can be changed by OnAudioBuffers() or OnVideoBuffers() |
678 // calls during the parse. | 664 // calls during the parse. |
679 bool old_seek_waits_for_data = seek_waits_for_data_; | 665 bool old_seek_waits_for_data = seek_waits_for_data_; |
680 | 666 |
(...skipping 21 matching lines...) Expand all Loading... |
702 return false; | 688 return false; |
703 } | 689 } |
704 | 690 |
705 // Check to see if parsing triggered seek_waits_for_data_ to go from true to | 691 // Check to see if parsing triggered seek_waits_for_data_ to go from true to |
706 // false. This indicates we have parsed enough data to complete the seek. | 692 // false. This indicates we have parsed enough data to complete the seek. |
707 if (old_seek_waits_for_data && !seek_waits_for_data_ && | 693 if (old_seek_waits_for_data && !seek_waits_for_data_ && |
708 !seek_cb_.is_null()) { | 694 !seek_cb_.is_null()) { |
709 std::swap(cb, seek_cb_); | 695 std::swap(cb, seek_cb_); |
710 } | 696 } |
711 | 697 |
712 base::TimeDelta tmp; | 698 buffered_bytes_ += length; |
713 if (audio_.get() && audio_->GetLastBufferTimestamp(&tmp) && | |
714 tmp > buffered_ts) { | |
715 buffered_ts = tmp; | |
716 } | |
717 | |
718 if (video_.get() && video_->GetLastBufferTimestamp(&tmp) && | |
719 tmp > buffered_ts) { | |
720 buffered_ts = tmp; | |
721 } | |
722 | |
723 buffered_bytes = buffered_bytes_; | 699 buffered_bytes = buffered_bytes_; |
724 } | 700 } |
725 | 701 |
726 // Notify the host of 'network activity' because we got data. | 702 // Notify the host of 'network activity' because we got data. |
727 host_->SetBufferedBytes(buffered_bytes); | 703 host_->SetBufferedBytes(buffered_bytes); |
728 | 704 |
729 host_->SetNetworkActivity(true); | 705 host_->SetNetworkActivity(true); |
730 | 706 |
731 if (!cb.is_null()) | 707 if (!cb.is_null()) |
732 cb.Run(PIPELINE_OK); | 708 cb.Run(PIPELINE_OK); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 return true; | 891 return true; |
916 } | 892 } |
917 | 893 |
918 bool ChunkDemuxer::OnKeyNeeded(scoped_array<uint8> init_data, | 894 bool ChunkDemuxer::OnKeyNeeded(scoped_array<uint8> init_data, |
919 int init_data_size) { | 895 int init_data_size) { |
920 client_->KeyNeeded(init_data.Pass(), init_data_size); | 896 client_->KeyNeeded(init_data.Pass(), init_data_size); |
921 return true; | 897 return true; |
922 } | 898 } |
923 | 899 |
924 } // namespace media | 900 } // namespace media |
OLD | NEW |