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 "media/base/android/access_unit_queue.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "media/base/demuxer_stream.h" |
| 9 |
| 10 namespace media { |
| 11 |
| 12 AccessUnitQueue::AccessUnitQueue() : has_eos_(false) {} |
| 13 |
| 14 AccessUnitQueue::~AccessUnitQueue() {} |
| 15 |
| 16 void AccessUnitQueue::PushBack(const DemuxerData& data) { |
| 17 // TODO(timav): The lock is expensive here because it lasts |
| 18 // for the whole duration of data copying. We need to figure out |
| 19 // what to do with this. |
| 20 |
| 21 // Media thread |
| 22 base::AutoLock lock(lock_); |
| 23 |
| 24 // We expect that the chunk containing EOS is the last chunk |
| 25 DCHECK(!has_eos_); |
| 26 |
| 27 DCHECK(!data.access_units.empty()); |
| 28 |
| 29 #if DCHECK_IS_ON() |
| 30 // Verify the rule "one DemuxerConfigs for one AU with |kConfigChanged|". |
| 31 size_t num_config_placeholders = 0; |
| 32 #endif |
| 33 |
| 34 for (const AccessUnit& unit : data.access_units) { |
| 35 #if DCHECK_IS_ON() |
| 36 if (unit.status == DemuxerStream::kConfigChanged) |
| 37 ++num_config_placeholders; |
| 38 #endif |
| 39 access_units_.push_back(unit); |
| 40 if (unit.is_end_of_stream) { |
| 41 DVLOG(1) << "AccessUnitQueue::" << __FUNCTION__ << ": EOS detected"; |
| 42 has_eos_ = true; |
| 43 } |
| 44 } |
| 45 |
| 46 DCHECK(data.demuxer_configs.size() == num_config_placeholders); |
| 47 |
| 48 for (const DemuxerConfigs& conf : data.demuxer_configs) |
| 49 demuxer_configs_.push_back(conf); |
| 50 } |
| 51 |
| 52 void AccessUnitQueue::PopFront() { |
| 53 // Decoder thread |
| 54 base::AutoLock lock(lock_); |
| 55 |
| 56 if (access_units_.front().status == DemuxerStream::kConfigChanged) |
| 57 demuxer_configs_.pop_front(); |
| 58 |
| 59 access_units_.pop_front(); |
| 60 |
| 61 if (access_units_.empty()) |
| 62 has_eos_ = false; |
| 63 } |
| 64 |
| 65 void AccessUnitQueue::Flush() { |
| 66 // Media thread |
| 67 base::AutoLock lock(lock_); |
| 68 |
| 69 access_units_.clear(); |
| 70 demuxer_configs_.clear(); |
| 71 has_eos_ = false; |
| 72 } |
| 73 |
| 74 bool AccessUnitQueue::SkipToKeyFrame() { |
| 75 // Media thread |
| 76 base::AutoLock lock(lock_); |
| 77 // We assume there cannot be |demuxer_configs_| elements for non-key frames. |
| 78 |
| 79 std::deque<AccessUnit>::iterator it; |
| 80 for (it = access_units_.begin(); it!= access_units_.end(); ++it) { |
| 81 if (it->is_key_frame) { |
| 82 access_units_.erase(access_units_.begin(), it); |
| 83 return true; |
| 84 } |
| 85 } |
| 86 |
| 87 return false; |
| 88 } |
| 89 |
| 90 void AccessUnitQueue::GetInfo(Info* info) const { |
| 91 // Media thread, Decoder thread |
| 92 base::AutoLock lock(lock_); |
| 93 |
| 94 info->length = access_units_.size(); |
| 95 info->has_eos = has_eos_; |
| 96 info->front_unit = nullptr; |
| 97 info->configs = nullptr; |
| 98 |
| 99 if (info->length > 0) { |
| 100 info->front_unit = &access_units_.front(); |
| 101 if (access_units_.front().status == DemuxerStream::kConfigChanged) { |
| 102 DCHECK(!demuxer_configs_.empty()); |
| 103 info->configs = &demuxer_configs_.front(); |
| 104 } |
| 105 } |
| 106 } |
| 107 |
| 108 } // namespace media |
OLD | NEW |