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() : index_in_chunk_(0), has_eos_(false) { | |
13 current_chunk_ = chunks_.end(); | |
14 } | |
15 | |
16 AccessUnitQueue::~AccessUnitQueue() { | |
liberato (no reviews please)
2015/06/12 22:24:15
nit: why provide an empty, non-virtual destructor?
Tima Vaisburd
2015/06/12 22:49:01
Having access_unit_queue in this CL is really conf
Tima Vaisburd
2015/06/15 18:57:08
In the latest version of AccessUnitQueue that has
| |
17 } | |
18 | |
19 void AccessUnitQueue::PushBack(const DemuxerData& data) { | |
20 // Media thread | |
21 DCHECK(!data.access_units.empty()); | |
22 | |
23 #if DCHECK_IS_ON() | |
24 // Verify the rule "one DemuxerConfigs for one AU with |kConfigChanged|". | |
25 size_t num_config_placeholders = 0; | |
26 | |
27 for (size_t i = 0; i < data.access_units.size(); ++i) { | |
28 const AccessUnit& unit = data.access_units[i]; | |
29 if (unit.status == DemuxerStream::kConfigChanged) | |
30 ++num_config_placeholders; | |
31 | |
32 // EOS must be the last unit in the chunk | |
33 if (unit.is_end_of_stream) { | |
34 DCHECK(i == data.access_units.size() - 1); | |
35 } | |
36 } | |
37 #endif | |
38 | |
39 DCHECK(data.demuxer_configs.size() == num_config_placeholders); | |
40 | |
41 // Also verify that there is no more than one |kConfigChanged| per chunk. | |
42 DCHECK(num_config_placeholders <= 1); | |
43 | |
44 // Create the next chunk and copy data to it. | |
45 scoped_ptr<DemuxerData> chunk(new DemuxerData(data)); | |
46 | |
47 // EOS flag can only be in the last access unit. | |
48 bool has_eos = chunk->access_units.back().is_end_of_stream; | |
49 | |
50 // Append this chunk to the queue. | |
51 base::AutoLock lock(lock_); | |
52 | |
53 bool was_empty = (current_chunk_ == chunks_.end()); | |
54 | |
55 chunks_.push_back(chunk.Pass()); | |
56 | |
57 // Position the current chunk. | |
58 if (was_empty) { | |
59 current_chunk_ = --chunks_.end(); | |
60 index_in_chunk_ = 0; | |
61 } | |
62 | |
63 // We expect that the chunk containing EOS is the last chunk. | |
64 DCHECK(!has_eos_); | |
65 has_eos_ = has_eos; | |
66 } | |
67 | |
68 void AccessUnitQueue::Advance() { | |
69 // Decoder thread | |
70 base::AutoLock lock(lock_); | |
71 | |
72 if (current_chunk_ == chunks_.end()) | |
73 return; | |
74 | |
75 ++index_in_chunk_; | |
76 if ((*current_chunk_)->access_units.size() <= index_in_chunk_) { | |
77 index_in_chunk_ = 0; | |
78 ++current_chunk_; | |
79 } | |
80 | |
81 // Remove all chunks before the current | |
82 DataChunkQueue::iterator first_to_keep = current_chunk_; | |
83 chunks_.erase(chunks_.begin(), first_to_keep); | |
84 } | |
85 | |
86 void AccessUnitQueue::Flush() { | |
87 // Media thread | |
88 base::AutoLock lock(lock_); | |
89 | |
90 chunks_.clear(); | |
91 | |
92 current_chunk_ = chunks_.end(); | |
93 index_in_chunk_ = 0; | |
94 has_eos_ = false; | |
95 } | |
96 | |
97 bool AccessUnitQueue::SkipToKeyFrame() { | |
98 // Media thread | |
99 base::AutoLock lock(lock_); | |
100 | |
101 // Search backwards in the current chunk only. | |
102 | |
103 if (current_chunk_ == chunks_.end()) | |
104 return false; | |
105 | |
106 for (int i = index_in_chunk_; i >= 0; --i) { | |
107 if ((*current_chunk_)->access_units[i].is_key_frame) { | |
108 index_in_chunk_ = i; | |
109 return true; | |
110 } | |
111 } | |
112 | |
113 return false; | |
114 } | |
115 | |
116 AccessUnitQueue::Info AccessUnitQueue::GetInfo() const { | |
117 // Media thread, Decoder thread | |
118 | |
119 Info info; | |
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 return info; | |
138 } | |
139 | |
140 int AccessUnitQueue::GetUndecodedAccessUnitLength() const { | |
141 int result = 0; | |
142 DataChunkQueue::const_iterator chunk; | |
143 for (chunk = current_chunk_; chunk != chunks_.end(); ++chunk) | |
144 result += (*chunk)->access_units.size(); | |
145 | |
146 result -= index_in_chunk_; | |
147 return result; | |
148 } | |
149 | |
150 } // namespace media | |
OLD | NEW |