OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/android/access_unit_queue.h" | 5 #include "media/base/android/access_unit_queue.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "media/base/demuxer_stream.h" | 9 #include "media/base/demuxer_stream.h" |
10 | 10 |
11 namespace media { | 11 namespace media { |
12 | 12 |
13 namespace { | 13 namespace { |
14 // Amount of history chunks we keep by default. The zero size means we do not | 14 // Amount of history chunks we keep by default. The zero size means we do not |
15 // keep chunks before the current one and the history is limited by the size | 15 // keep chunks before the current one and the history is limited by the size |
16 // of one chunk. | 16 // of one chunk. |
17 const int kDefaultHistoryChunksAmount = 0; | 17 const int kDefaultHistoryChunksAmount = 0; |
18 } | 18 } |
19 | 19 |
20 AccessUnitQueue::AccessUnitQueue() | 20 AccessUnitQueue::AccessUnitQueue() |
21 : index_in_chunk_(0), | 21 : index_in_chunk_(0), |
22 history_chunks_amount_(kDefaultHistoryChunksAmount), | 22 history_chunks_amount_(kDefaultHistoryChunksAmount), |
23 has_eos_(false) { | 23 has_eos_(false) { |
24 current_chunk_ = chunks_.end(); | 24 current_chunk_ = chunks_.end(); |
25 } | 25 } |
26 | 26 |
27 AccessUnitQueue::~AccessUnitQueue() { | 27 AccessUnitQueue::~AccessUnitQueue() { |
28 STLDeleteContainerPointers(chunks_.begin(), chunks_.end()); | 28 base::STLDeleteContainerPointers(chunks_.begin(), chunks_.end()); |
29 } | 29 } |
30 | 30 |
31 void AccessUnitQueue::PushBack(const DemuxerData& data) { | 31 void AccessUnitQueue::PushBack(const DemuxerData& data) { |
32 // Media thread | 32 // Media thread |
33 DCHECK(!data.access_units.empty()); | 33 DCHECK(!data.access_units.empty()); |
34 | 34 |
35 #if DCHECK_IS_ON() | 35 #if DCHECK_IS_ON() |
36 // If there is an AU with |kConfigChanged| status, it must be the last | 36 // If there is an AU with |kConfigChanged| status, it must be the last |
37 // AU in the chunk and the data should have exactly one corresponding | 37 // AU in the chunk and the data should have exactly one corresponding |
38 // DemuxerConfigs. | 38 // DemuxerConfigs. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 index_in_chunk_ = 0; | 101 index_in_chunk_ = 0; |
102 ++current_chunk_; | 102 ++current_chunk_; |
103 | 103 |
104 // Keep only |history_chunks_amount_| before the current one. | 104 // Keep only |history_chunks_amount_| before the current one. |
105 // std::distance() and std::advance() do not work efficiently with std::list, | 105 // std::distance() and std::advance() do not work efficiently with std::list, |
106 // but the history_size should be small (default is 0). | 106 // but the history_size should be small (default is 0). |
107 size_t num_consumed_chunks = std::distance(chunks_.begin(), current_chunk_); | 107 size_t num_consumed_chunks = std::distance(chunks_.begin(), current_chunk_); |
108 if (num_consumed_chunks > history_chunks_amount_) { | 108 if (num_consumed_chunks > history_chunks_amount_) { |
109 DataChunkQueue::iterator first_to_keep = chunks_.begin(); | 109 DataChunkQueue::iterator first_to_keep = chunks_.begin(); |
110 std::advance(first_to_keep, num_consumed_chunks - history_chunks_amount_); | 110 std::advance(first_to_keep, num_consumed_chunks - history_chunks_amount_); |
111 STLDeleteContainerPointers(chunks_.begin(), first_to_keep); | 111 base::STLDeleteContainerPointers(chunks_.begin(), first_to_keep); |
112 chunks_.erase(chunks_.begin(), first_to_keep); | 112 chunks_.erase(chunks_.begin(), first_to_keep); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 void AccessUnitQueue::Flush() { | 116 void AccessUnitQueue::Flush() { |
117 // Media thread | 117 // Media thread |
118 base::AutoLock lock(lock_); | 118 base::AutoLock lock(lock_); |
119 | 119 |
120 STLDeleteContainerPointers(chunks_.begin(), chunks_.end()); | 120 base::STLDeleteContainerPointers(chunks_.begin(), chunks_.end()); |
121 chunks_.clear(); | 121 chunks_.clear(); |
122 | 122 |
123 current_chunk_ = chunks_.end(); | 123 current_chunk_ = chunks_.end(); |
124 index_in_chunk_ = 0; | 124 index_in_chunk_ = 0; |
125 has_eos_ = false; | 125 has_eos_ = false; |
126 } | 126 } |
127 | 127 |
128 bool AccessUnitQueue::RewindToLastKeyFrame() { | 128 bool AccessUnitQueue::RewindToLastKeyFrame() { |
129 // Media thread | 129 // Media thread |
130 base::AutoLock lock(lock_); | 130 base::AutoLock lock(lock_); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 DCHECK((*chunk)->demuxer_configs.size() == 1); | 202 DCHECK((*chunk)->demuxer_configs.size() == 1); |
203 --(*data_length); | 203 --(*data_length); |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 *total_length -= index_in_chunk_; | 207 *total_length -= index_in_chunk_; |
208 *data_length -= index_in_chunk_; | 208 *data_length -= index_in_chunk_; |
209 } | 209 } |
210 | 210 |
211 } // namespace media | 211 } // namespace media |
OLD | NEW |