OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/logging.h" |
| 6 |
| 7 #include "media/base/android/au_queue.h" |
| 8 #include "media/base/demuxer_stream.h" |
| 9 |
| 10 //#include "base/tvlog.h" |
| 11 |
| 12 namespace media { |
| 13 |
| 14 AUQueue::AUQueue() |
| 15 : has_eos_(false) |
| 16 {} |
| 17 |
| 18 AUQueue::~AUQueue() |
| 19 {} |
| 20 |
| 21 void AUQueue::PushBack(const DemuxerData& data) { |
| 22 base::AutoLock lock(lock_); |
| 23 |
| 24 for (const AccessUnit& unit : data.access_units) { |
| 25 access_units_.push_back(unit); |
| 26 if (unit.is_end_of_stream || unit.data.empty()) { |
| 27 DVLOG(1) << "AUQueue::" << __FUNCTION__ << ": EOS detected"; |
| 28 has_eos_ = true; |
| 29 } |
| 30 } |
| 31 |
| 32 // We assume that the rule "one DemuxerConfigs for one AU |
| 33 // with |kConfigChanged|" holds and do not check anything. |
| 34 for (const DemuxerConfigs& conf : data.demuxer_configs) |
| 35 demuxer_configs_.push_back(conf); |
| 36 } |
| 37 |
| 38 void AUQueue::PopFront() { |
| 39 base::AutoLock lock(lock_); |
| 40 |
| 41 if (access_units_.front().status == DemuxerStream::kConfigChanged) |
| 42 demuxer_configs_.pop_front(); |
| 43 |
| 44 if (access_units_.front().is_end_of_stream) |
| 45 has_eos_ = false; // assume there os only one AU with EOS |
| 46 |
| 47 access_units_.pop_front(); |
| 48 } |
| 49 |
| 50 void AUQueue::Flush() { |
| 51 base::AutoLock lock(lock_); |
| 52 |
| 53 access_units_.clear(); |
| 54 demuxer_configs_.clear(); |
| 55 has_eos_ = false; |
| 56 } |
| 57 |
| 58 bool AUQueue::SkipToKeyFrame() { |
| 59 // Media thread |
| 60 base::AutoLock lock(lock_); |
| 61 // We assume there cannot be |demuxer_configs_| elements for non-key frames. |
| 62 |
| 63 std::deque<AccessUnit>::iterator it; |
| 64 for (it = access_units_.begin(); it!= access_units_.end(); ++it) { |
| 65 if (it->is_key_frame) { |
| 66 access_units_.erase(access_units_.begin(), it); |
| 67 return true; |
| 68 } |
| 69 } |
| 70 |
| 71 return false; |
| 72 } |
| 73 |
| 74 void AUQueue::GetInfo(Info* info) const { |
| 75 base::AutoLock lock(lock_); |
| 76 |
| 77 info->length = access_units_.size(); |
| 78 info->has_eos = has_eos_; |
| 79 if (info->length > 0) { |
| 80 info->front_unit = &access_units_.front(); |
| 81 info->configs = |
| 82 (info->front_unit->status == DemuxerStream::kConfigChanged) ? |
| 83 &demuxer_configs_.front() : nullptr; |
| 84 } else { |
| 85 info->front_unit = nullptr; |
| 86 info->configs = nullptr; |
| 87 } |
| 88 } |
| 89 |
| 90 bool AUQueue::HasEOS() const { |
| 91 base::AutoLock lock(lock_); |
| 92 |
| 93 return has_eos_; |
| 94 } |
| 95 |
| 96 int AUQueue::Length() const { |
| 97 base::AutoLock lock(lock_); |
| 98 |
| 99 return access_units_.size(); |
| 100 } |
| 101 |
| 102 } // namespace media |
| 103 |
| 104 std::ostream& operator<<(std::ostream& os, const media::AccessUnit& au) { |
| 105 os << "status:" << au.status |
| 106 << (au.is_end_of_stream ? " EOS" : "") |
| 107 << (au.is_key_frame ? " KEY_FRAME" : "") |
| 108 << " pts:" << au.timestamp |
| 109 << " size:" << au.data.size(); |
| 110 return os; |
| 111 } |
OLD | NEW |