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|". | |
|
wolenetz
2015/06/08 21:37:08
Like EOS (and more simple vs the current verificat
Tima Vaisburd
2015/06/09 21:29:21
Changed the comment and simplified the check.
| |
| 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); | |
|
wolenetz
2015/06/08 21:37:09
num_config_placeholders is undefined here in non-D
Tima Vaisburd
2015/06/09 21:29:20
Removed since the checking code is simplified.
| |
| 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 index_in_chunk_ = 0; | |
| 62 } | |
| 63 | |
| 64 // We expect that the chunk containing EOS is the last chunk. | |
| 65 DCHECK(!has_eos_); | |
| 66 has_eos_ = has_eos; | |
| 67 } | |
| 68 | |
| 69 void AccessUnitQueue::Advance() { | |
| 70 // Decoder thread | |
| 71 base::AutoLock lock(lock_); | |
| 72 | |
| 73 if (current_chunk_ == chunks_.end()) | |
| 74 return; | |
| 75 | |
| 76 ++index_in_chunk_; | |
| 77 if ((*current_chunk_)->access_units.size() <= index_in_chunk_) { | |
| 78 index_in_chunk_ = 0; | |
| 79 ++current_chunk_; | |
| 80 } | |
| 81 | |
| 82 // Remove all chunks before the current | |
| 83 DataChunkQueue::iterator first_to_keep = current_chunk_; | |
| 84 chunks_.erase(chunks_.begin(), first_to_keep); | |
| 85 } | |
| 86 | |
| 87 void AccessUnitQueue::Flush() { | |
| 88 // Media thread | |
| 89 base::AutoLock lock(lock_); | |
| 90 | |
| 91 chunks_.clear(); | |
| 92 | |
| 93 current_chunk_ = chunks_.end(); | |
| 94 index_in_chunk_ = 0; | |
| 95 has_eos_ = false; | |
| 96 } | |
| 97 | |
| 98 bool AccessUnitQueue::SkipToKeyFrame() { | |
| 99 // Media thread | |
| 100 base::AutoLock lock(lock_); | |
| 101 | |
| 102 // Search backwards in the current chunk only. | |
|
wolenetz
2015/06/08 21:37:08
This isn't clear from the .h comment. Also, why is
Tima Vaisburd
2015/06/09 21:29:21
Updated the comment in .h.
I searched in the curr
wolenetz
2015/06/11 19:21:20
I tend to agree that increased complexity might no
Tima Vaisburd
2015/06/11 20:54:08
That's no problem in general, and I went forward w
| |
| 103 | |
| 104 if (current_chunk_ == chunks_.end()) | |
| 105 return false; | |
| 106 | |
| 107 for (int i = index_in_chunk_; i >= 0; --i) { | |
|
wolenetz
2015/06/08 21:37:09
minor minor nit: On some platforms (like Windows),
Tima Vaisburd
2015/06/09 21:29:21
I did not find an elegant solution, just put a cas
| |
| 108 if ((*current_chunk_)->access_units[i].is_key_frame) { | |
| 109 index_in_chunk_ = i; | |
| 110 return true; | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 return false; | |
| 115 } | |
| 116 | |
| 117 AccessUnitQueue::Info AccessUnitQueue::GetInfo() const { | |
| 118 // Media thread, Decoder thread | |
| 119 | |
| 120 Info info; | |
| 121 base::AutoLock lock(lock_); | |
| 122 | |
| 123 info.length = GetUndecodedAccessUnitLength(); | |
| 124 info.has_eos = has_eos_; | |
| 125 info.front_unit = nullptr; | |
| 126 info.configs = nullptr; | |
| 127 | |
| 128 if (info.length > 0) { | |
| 129 DCHECK(current_chunk_ != chunks_.end()); | |
| 130 DCHECK(index_in_chunk_ < (*current_chunk_)->access_units.size()); | |
| 131 info.front_unit = &(*current_chunk_)->access_units[index_in_chunk_]; | |
|
wolenetz
2015/06/08 21:37:08
Who owns the DemuxerData scoped pointer at this po
Tima Vaisburd
2015/06/09 21:29:21
The container remains to be the owner. I wanted to
wolenetz
2015/06/11 19:21:20
See my other comments.
| |
| 132 | |
| 133 if (info.front_unit->status == DemuxerStream::kConfigChanged) { | |
| 134 DCHECK((*current_chunk_)->demuxer_configs.size() == 1); | |
| 135 info.configs = &(*current_chunk_)->demuxer_configs[0]; | |
|
wolenetz
2015/06/08 21:37:09
Likewise: ownership?
Tima Vaisburd
2015/06/09 21:29:20
Same as above
| |
| 136 } | |
| 137 } | |
| 138 return info; | |
| 139 } | |
| 140 | |
| 141 int AccessUnitQueue::GetUndecodedAccessUnitLength() const { | |
| 142 int result = 0; | |
| 143 DataChunkQueue::const_iterator chunk; | |
| 144 for (chunk = current_chunk_; chunk != chunks_.end(); ++chunk) | |
| 145 result += (*chunk)->access_units.size(); | |
| 146 | |
| 147 result -= index_in_chunk_; | |
| 148 return result; | |
| 149 } | |
| 150 | |
| 151 } // namespace media | |
| OLD | NEW |