| 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> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <list> | 9 #include <list> |
| 10 | 10 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // Helper methods that call methods with similar names on all the | 156 // Helper methods that call methods with similar names on all the |
| 157 // ChunkDemuxerStreams managed by this object. | 157 // ChunkDemuxerStreams managed by this object. |
| 158 void StartReturningData(); | 158 void StartReturningData(); |
| 159 void AbortReads(); | 159 void AbortReads(); |
| 160 void Seek(TimeDelta seek_time); | 160 void Seek(TimeDelta seek_time); |
| 161 void CompletePendingReadIfPossible(); | 161 void CompletePendingReadIfPossible(); |
| 162 void OnSetDuration(TimeDelta duration); | 162 void OnSetDuration(TimeDelta duration); |
| 163 void MarkEndOfStream(); | 163 void MarkEndOfStream(); |
| 164 void UnmarkEndOfStream(); | 164 void UnmarkEndOfStream(); |
| 165 void Shutdown(); | 165 void Shutdown(); |
| 166 // Sets the memory limit on each stream of a specific type. | |
| 167 // |memory_limit| is the maximum number of bytes each stream of type |type| | |
| 168 // is allowed to hold in its buffer. | |
| 169 void SetMemoryLimits(DemuxerStream::Type type, int memory_limit); | |
| 170 bool IsSeekWaitingForData() const; | 166 bool IsSeekWaitingForData() const; |
| 171 | 167 |
| 172 private: | 168 private: |
| 173 // Called by the |stream_parser_| when a new initialization segment is | 169 // Called by the |stream_parser_| when a new initialization segment is |
| 174 // encountered. | 170 // encountered. |
| 175 // Returns true on a successful call. Returns false if an error occurred while | 171 // Returns true on a successful call. Returns false if an error occurred while |
| 176 // processing decoder configurations. | 172 // processing decoder configurations. |
| 177 bool OnNewConfigs(bool allow_audio, bool allow_video, | 173 bool OnNewConfigs(bool allow_audio, bool allow_video, |
| 178 const AudioDecoderConfig& audio_config, | 174 const AudioDecoderConfig& audio_config, |
| 179 const VideoDecoderConfig& video_config, | 175 const VideoDecoderConfig& video_config, |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 | 503 |
| 508 if (video_) | 504 if (video_) |
| 509 video_->Shutdown(); | 505 video_->Shutdown(); |
| 510 | 506 |
| 511 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | 507 for (TextStreamMap::iterator itr = text_stream_map_.begin(); |
| 512 itr != text_stream_map_.end(); ++itr) { | 508 itr != text_stream_map_.end(); ++itr) { |
| 513 itr->second->Shutdown(); | 509 itr->second->Shutdown(); |
| 514 } | 510 } |
| 515 } | 511 } |
| 516 | 512 |
| 517 void SourceState::SetMemoryLimits(DemuxerStream::Type type, int memory_limit) { | |
| 518 switch (type) { | |
| 519 case DemuxerStream::AUDIO: | |
| 520 if (audio_) | |
| 521 audio_->set_memory_limit(memory_limit); | |
| 522 break; | |
| 523 case DemuxerStream::VIDEO: | |
| 524 if (video_) | |
| 525 video_->set_memory_limit(memory_limit); | |
| 526 break; | |
| 527 case DemuxerStream::TEXT: | |
| 528 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | |
| 529 itr != text_stream_map_.end(); ++itr) { | |
| 530 itr->second->set_memory_limit(memory_limit); | |
| 531 } | |
| 532 break; | |
| 533 case DemuxerStream::UNKNOWN: | |
| 534 case DemuxerStream::NUM_TYPES: | |
| 535 NOTREACHED(); | |
| 536 break; | |
| 537 } | |
| 538 } | |
| 539 | |
| 540 bool SourceState::IsSeekWaitingForData() const { | 513 bool SourceState::IsSeekWaitingForData() const { |
| 541 if (audio_ && audio_->IsSeekWaitingForData()) | 514 if (audio_ && audio_->IsSeekWaitingForData()) |
| 542 return true; | 515 return true; |
| 543 | 516 |
| 544 if (video_ && video_->IsSeekWaitingForData()) | 517 if (video_ && video_->IsSeekWaitingForData()) |
| 545 return true; | 518 return true; |
| 546 | 519 |
| 547 // NOTE: We are intentionally not checking the text tracks | 520 // NOTE: We are intentionally not checking the text tracks |
| 548 // because text tracks are discontinuous and may not have data | 521 // because text tracks are discontinuous and may not have data |
| 549 // for the seek position. This is ok and playback should not be | 522 // for the seek position. This is ok and playback should not be |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 base::AutoLock auto_lock(lock_); | 986 base::AutoLock auto_lock(lock_); |
| 1014 return stream_->GetCurrentVideoDecoderConfig(); | 987 return stream_->GetCurrentVideoDecoderConfig(); |
| 1015 } | 988 } |
| 1016 | 989 |
| 1017 bool ChunkDemuxerStream::SupportsConfigChanges() { return true; } | 990 bool ChunkDemuxerStream::SupportsConfigChanges() { return true; } |
| 1018 | 991 |
| 1019 VideoRotation ChunkDemuxerStream::video_rotation() { | 992 VideoRotation ChunkDemuxerStream::video_rotation() { |
| 1020 return VIDEO_ROTATION_0; | 993 return VIDEO_ROTATION_0; |
| 1021 } | 994 } |
| 1022 | 995 |
| 996 size_t ChunkDemuxerStream::GetMemoryLimit() const { |
| 997 return stream_->GetMemoryLimit(); |
| 998 } |
| 999 |
| 1000 void ChunkDemuxerStream::SetMemoryLimit(size_t memory_limit) { |
| 1001 stream_->SetMemoryLimit(memory_limit); |
| 1002 } |
| 1003 |
| 1023 TextTrackConfig ChunkDemuxerStream::text_track_config() { | 1004 TextTrackConfig ChunkDemuxerStream::text_track_config() { |
| 1024 CHECK_EQ(type_, TEXT); | 1005 CHECK_EQ(type_, TEXT); |
| 1025 base::AutoLock auto_lock(lock_); | 1006 base::AutoLock auto_lock(lock_); |
| 1026 return stream_->GetCurrentTextTrackConfig(); | 1007 return stream_->GetCurrentTextTrackConfig(); |
| 1027 } | 1008 } |
| 1028 | 1009 |
| 1029 void ChunkDemuxerStream::SetLiveness(Liveness liveness) { | 1010 void ChunkDemuxerStream::SetLiveness(Liveness liveness) { |
| 1030 base::AutoLock auto_lock(lock_); | 1011 base::AutoLock auto_lock(lock_); |
| 1031 liveness_ = liveness; | 1012 liveness_ = liveness; |
| 1032 } | 1013 } |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 return; | 1562 return; |
| 1582 | 1563 |
| 1583 ShutdownAllStreams(); | 1564 ShutdownAllStreams(); |
| 1584 | 1565 |
| 1585 ChangeState_Locked(SHUTDOWN); | 1566 ChangeState_Locked(SHUTDOWN); |
| 1586 | 1567 |
| 1587 if(!seek_cb_.is_null()) | 1568 if(!seek_cb_.is_null()) |
| 1588 base::ResetAndReturn(&seek_cb_).Run(PIPELINE_ERROR_ABORT); | 1569 base::ResetAndReturn(&seek_cb_).Run(PIPELINE_ERROR_ABORT); |
| 1589 } | 1570 } |
| 1590 | 1571 |
| 1591 void ChunkDemuxer::SetMemoryLimits(DemuxerStream::Type type, int memory_limit) { | |
| 1592 for (SourceStateMap::iterator itr = source_state_map_.begin(); | |
| 1593 itr != source_state_map_.end(); ++itr) { | |
| 1594 itr->second->SetMemoryLimits(type, memory_limit); | |
| 1595 } | |
| 1596 } | |
| 1597 | |
| 1598 void ChunkDemuxer::ChangeState_Locked(State new_state) { | 1572 void ChunkDemuxer::ChangeState_Locked(State new_state) { |
| 1599 lock_.AssertAcquired(); | 1573 lock_.AssertAcquired(); |
| 1600 DVLOG(1) << "ChunkDemuxer::ChangeState_Locked() : " | 1574 DVLOG(1) << "ChunkDemuxer::ChangeState_Locked() : " |
| 1601 << state_ << " -> " << new_state; | 1575 << state_ << " -> " << new_state; |
| 1602 state_ = new_state; | 1576 state_ = new_state; |
| 1603 } | 1577 } |
| 1604 | 1578 |
| 1605 ChunkDemuxer::~ChunkDemuxer() { | 1579 ChunkDemuxer::~ChunkDemuxer() { |
| 1606 DCHECK_NE(state_, INITIALIZED); | 1580 DCHECK_NE(state_, INITIALIZED); |
| 1607 | 1581 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1832 } | 1806 } |
| 1833 | 1807 |
| 1834 void ChunkDemuxer::ShutdownAllStreams() { | 1808 void ChunkDemuxer::ShutdownAllStreams() { |
| 1835 for (SourceStateMap::iterator itr = source_state_map_.begin(); | 1809 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
| 1836 itr != source_state_map_.end(); ++itr) { | 1810 itr != source_state_map_.end(); ++itr) { |
| 1837 itr->second->Shutdown(); | 1811 itr->second->Shutdown(); |
| 1838 } | 1812 } |
| 1839 } | 1813 } |
| 1840 | 1814 |
| 1841 } // namespace media | 1815 } // namespace media |
| OLD | NEW |