Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: media/base/android/access_unit_queue.cc

Issue 1128383003: Implementation of MediaCodecPlayer stage 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improved state machine diagrams Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #endif
28
29 // Determine whether the chunk contains EOS.
30 bool has_eos = false;
31 for (const AccessUnit& unit : data.access_units) {
32 #if DCHECK_IS_ON()
33 if (unit.status == DemuxerStream::kConfigChanged)
34 ++num_config_placeholders;
35 #endif
36 if (unit.is_end_of_stream) {
37 DVLOG(1) << "AccessUnitQueue::" << __FUNCTION__ << ": EOS detected";
38 has_eos = true;
39 }
40 }
41
42 DCHECK(data.demuxer_configs.size() == num_config_placeholders);
43
44 // Also verify that there is no more than one |kConfigChanged| per chunk.
45 DCHECK(num_config_placeholders <= 1);
46
47 // Create the next chunk and copy data to it.
48 scoped_ptr<DemuxerData> chunk(new DemuxerData(data));
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 --current_chunk_;
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.
103
104 if (current_chunk_ == chunks_.end())
105 return false;
106
107 for (int i = index_in_chunk_; i >= 0; --i) {
108 if ((*current_chunk_)->access_units[i].is_key_frame)
109 return true;
110 }
111
112 return false;
113 }
114
115 void AccessUnitQueue::GetInfo(Info* info) const {
116 // Media thread, Decoder thread
117 base::AutoLock lock(lock_);
118
119 info->length = GetLength();
120 info->has_eos = has_eos_;
121 info->front_unit = nullptr;
122 info->configs = nullptr;
123
124 if (info->length > 0) {
125 DCHECK(current_chunk_ != chunks_.end());
126 DCHECK(index_in_chunk_ < (*current_chunk_)->access_units.size());
127 info->front_unit = &(*current_chunk_)->access_units[index_in_chunk_];
128
129 if (info->front_unit->status == DemuxerStream::kConfigChanged) {
130 DCHECK(!(*current_chunk_)->demuxer_configs.empty());
qinmin 2015/05/31 20:19:12 This DCHECK is useless, the next DCHECK covers thi
Tima Vaisburd 2015/06/01 18:56:52 Done.
131 DCHECK((*current_chunk_)->demuxer_configs.size() == 1);
132 info->configs = &(*current_chunk_)->demuxer_configs[0];
133 }
134 }
135 }
136
137 int AccessUnitQueue::GetLength() const {
138 int result = 0;
139 DataChunkQueue::const_iterator chunk;
140 for (chunk = current_chunk_; chunk != chunks_.end(); ++chunk) {
141 result += (*chunk)->access_units.size();
142 if (chunk == current_chunk_)
143 result -= index_in_chunk_;
144 }
145 return result;
146 }
147
148 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698