Chromium Code Reviews| 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() | |
| 13 : index_in_chunk_(0), | |
| 14 has_eos_(false) { | |
| 15 current_chunk_ = chunks_.end(); | |
| 16 } | |
| 17 | |
| 18 AccessUnitQueue::~AccessUnitQueue() {} | |
| 19 | |
| 20 void AccessUnitQueue::PushBack(const DemuxerData& data) { | |
| 21 // Media thread | |
| 22 DCHECK(!data.access_units.empty()); | |
| 23 | |
| 24 #if DCHECK_IS_ON() | |
| 25 // Verify the rule "one DemuxerConfigs for one AU with |kConfigChanged|". | |
| 26 size_t num_config_placeholders = 0; | |
| 27 | |
| 28 for (size_t i = 0; i < data.access_units.size(); ++i) { | |
| 29 const AccessUnit& unit = data.access_units[i]; | |
| 30 if (unit.status == DemuxerStream::kConfigChanged) | |
| 31 ++num_config_placeholders; | |
| 32 | |
| 33 // EOS must be the last unit in the chunk | |
| 34 if (unit.is_end_of_stream) { | |
| 35 DCHECK(i == data.access_units.size() - 1); | |
| 36 } | |
| 37 } | |
| 38 #endif | |
| 39 | |
| 40 DCHECK(data.demuxer_configs.size() == num_config_placeholders); | |
| 41 | |
| 42 // Also verify that there is no more than one |kConfigChanged| per chunk. | |
| 43 DCHECK(num_config_placeholders <= 1); | |
| 44 | |
| 45 // Create the next chunk and copy data to it. | |
| 46 scoped_ptr<DemuxerData> chunk(new DemuxerData(data)); | |
| 47 | |
| 48 // EOS flag can only be in the last access unit. | |
| 49 bool has_eos = chunk->access_units.back().is_end_of_stream; | |
| 50 | |
| 51 // Append this chunk to the queue. | |
| 52 base::AutoLock lock(lock_); | |
| 53 | |
| 54 bool was_empty = (current_chunk_ == chunks_.end()); | |
| 55 | |
| 56 chunks_.push_back(chunk.Pass()); | |
| 57 | |
| 58 // Position the current chunk. | |
| 59 if (was_empty) { | |
| 60 current_chunk_ = chunks_.end(); | |
| 61 --current_chunk_; | |
|
watk
2015/06/04 20:56:43
It seems more obvious to use chunks_.begin()?
Tima Vaisburd
2015/06/05 04:17:46
I need an iterator that points to the last (newly
watk
2015/06/05 20:13:22
Oh, I thought was_empty meant chunks_ was empty
Tima Vaisburd
2015/06/05 22:09:46
I did not explain it well. I agree with you that r
| |
| 62 index_in_chunk_ = 0; | |
| 63 } | |
| 64 | |
| 65 // We expect that the chunk containing EOS is the last chunk. | |
| 66 DCHECK(!has_eos_); | |
| 67 has_eos_ = has_eos; | |
| 68 } | |
| 69 | |
| 70 void AccessUnitQueue::Advance() { | |
| 71 // Decoder thread | |
| 72 base::AutoLock lock(lock_); | |
| 73 | |
| 74 if (current_chunk_ == chunks_.end()) | |
| 75 return; | |
| 76 | |
| 77 ++index_in_chunk_; | |
| 78 if ((*current_chunk_)->access_units.size() <= index_in_chunk_) { | |
| 79 index_in_chunk_ = 0; | |
| 80 ++current_chunk_; | |
| 81 } | |
| 82 | |
| 83 // Remove all chunks before the current | |
| 84 DataChunkQueue::iterator first_to_keep = current_chunk_; | |
| 85 chunks_.erase(chunks_.begin(), first_to_keep); | |
| 86 } | |
| 87 | |
| 88 void AccessUnitQueue::Flush() { | |
| 89 // Media thread | |
| 90 base::AutoLock lock(lock_); | |
| 91 | |
| 92 chunks_.clear(); | |
| 93 | |
| 94 current_chunk_ = chunks_.end(); | |
| 95 index_in_chunk_ = 0; | |
| 96 has_eos_ = false; | |
| 97 } | |
| 98 | |
| 99 bool AccessUnitQueue::SkipToKeyFrame() { | |
| 100 // Media thread | |
| 101 base::AutoLock lock(lock_); | |
| 102 | |
| 103 // Search backwards in the current chunk only. | |
| 104 | |
| 105 if (current_chunk_ == chunks_.end()) | |
| 106 return false; | |
| 107 | |
| 108 for (int i = index_in_chunk_; i >= 0; --i) { | |
| 109 if ((*current_chunk_)->access_units[i].is_key_frame) { | |
| 110 index_in_chunk_ = i; | |
| 111 return true; | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 return false; | |
| 116 } | |
| 117 | |
| 118 void AccessUnitQueue::GetInfo(Info* info) const { | |
|
watk
2015/06/04 20:56:43
Any reason to not return the Info by value here? I
Tima Vaisburd
2015/06/05 04:17:46
Still it would be perhaps 16 bytes instead of 4, w
watk
2015/06/05 20:13:22
With RVO I doubt this will be a copy. In any case,
Tima Vaisburd
2015/06/05 22:09:45
Done.
| |
| 119 // Media thread, Decoder thread | |
| 120 base::AutoLock lock(lock_); | |
| 121 | |
| 122 info->length = GetUndecodedAccessUnitLength(); | |
| 123 info->has_eos = has_eos_; | |
| 124 info->front_unit = nullptr; | |
| 125 info->configs = nullptr; | |
| 126 | |
| 127 if (info->length > 0) { | |
| 128 DCHECK(current_chunk_ != chunks_.end()); | |
| 129 DCHECK(index_in_chunk_ < (*current_chunk_)->access_units.size()); | |
| 130 info->front_unit = &(*current_chunk_)->access_units[index_in_chunk_]; | |
| 131 | |
| 132 if (info->front_unit->status == DemuxerStream::kConfigChanged) { | |
| 133 DCHECK((*current_chunk_)->demuxer_configs.size() == 1); | |
| 134 info->configs = &(*current_chunk_)->demuxer_configs[0]; | |
| 135 } | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 int AccessUnitQueue::GetUndecodedAccessUnitLength() const { | |
| 140 int result = 0; | |
| 141 DataChunkQueue::const_iterator chunk; | |
| 142 for (chunk = current_chunk_; chunk != chunks_.end(); ++chunk) { | |
| 143 result += (*chunk)->access_units.size(); | |
| 144 if (chunk == current_chunk_) | |
| 145 result -= index_in_chunk_; | |
|
watk
2015/06/04 20:56:43
Can you move this outside of the for loop and remo
Tima Vaisburd
2015/06/05 04:17:46
I redid the method but not sure I like it better t
watk
2015/06/05 20:13:22
I agree your previous version was better than the
Tima Vaisburd
2015/06/05 22:09:46
Shame on me! Done.
| |
| 146 } | |
| 147 return result; | |
| 148 } | |
| 149 | |
| 150 } // namespace media | |
| OLD | NEW |