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

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: Comments, better Listener callbacks, removed unused includes Created 5 years, 7 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() : has_eos_(false) {}
13
14 AccessUnitQueue::~AccessUnitQueue() {}
15
16 void AccessUnitQueue::PushBack(const DemuxerData& data) {
17 // TODO(timav): The lock is expensive here because it lasts
18 // for the whole duration of data copying. We need to figure out
19 // whet to do with this.
20
21 // Media thread
22 base::AutoLock lock(lock_);
23
24 for (const AccessUnit& unit : data.access_units) {
25 access_units_.push_back(unit);
26 if (unit.is_end_of_stream) {
27 DVLOG(1) << "AccessUnitQueue::" << __FUNCTION__ << ": EOS detected";
28 has_eos_ = true;
29 }
30 }
31
32 // We assume that the rule "one DemuxerConfigs for one AU
33 // with |kConfigChanged|" holds and do not check anything.
34 for (const DemuxerConfigs& conf : data.demuxer_configs)
35 demuxer_configs_.push_back(conf);
36 }
37
38 void AccessUnitQueue::PopFront() {
39 // Decoder thread
40 base::AutoLock lock(lock_);
41
42 if (access_units_.front().status == DemuxerStream::kConfigChanged)
43 demuxer_configs_.pop_front();
44
45 if (access_units_.front().is_end_of_stream)
46 has_eos_ = false; // assume there os only one AU with EOS
47
48 access_units_.pop_front();
49 }
50
51 void AccessUnitQueue::Flush() {
52 // Media thread
53 base::AutoLock lock(lock_);
54
55 access_units_.clear();
56 demuxer_configs_.clear();
57 has_eos_ = false;
58 }
59
60 bool AccessUnitQueue::SkipToKeyFrame() {
61 // Media thread
62 base::AutoLock lock(lock_);
63 // We assume there cannot be |demuxer_configs_| elements for non-key frames.
64
65 std::deque<AccessUnit>::iterator it;
66 for (it = access_units_.begin(); it!= access_units_.end(); ++it) {
67 if (it->is_key_frame) {
68 access_units_.erase(access_units_.begin(), it);
69 return true;
70 }
71 }
72
73 return false;
74 }
75
76 void AccessUnitQueue::GetInfo(Info* info) const {
77 // Media thread, Decoder thread
78 base::AutoLock lock(lock_);
79
80 info->length = access_units_.size();
81 info->has_eos = has_eos_;
82 info->front_unit = nullptr;
83 info->configs = nullptr;
84
85 if (info->length > 0) {
86 if (access_units_.front().status == DemuxerStream::kConfigChanged)
87 info->configs = &demuxer_configs_.front();
88 else
89 info->front_unit = &access_units_.front();
90 }
91
92 DCHECK(!info->front_unit || !info->configs);
93 }
94
95 } // namespace media
96
97 std::ostream& operator<<(std::ostream& os, const media::AccessUnit& au) {
98 os << "status:" << au.status
99 << (au.is_end_of_stream ? " EOS" : "")
100 << (au.is_key_frame ? " KEY_FRAME" : "")
101 << " pts:" << au.timestamp
102 << " size:" << au.data.size();
103 return os;
104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698