Index: media/base/android/au_queue.cc |
diff --git a/media/base/android/au_queue.cc b/media/base/android/au_queue.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6be3d522dbc273522457cdaa7d7dcbd715a9152d |
--- /dev/null |
+++ b/media/base/android/au_queue.cc |
@@ -0,0 +1,111 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/logging.h" |
+ |
+#include "media/base/android/au_queue.h" |
+#include "media/base/demuxer_stream.h" |
+ |
+//#include "base/tvlog.h" |
qinmin
2015/05/12 23:58:22
remove unused includes
timav
2015/05/13 01:05:17
I need them for testing. I will remove them last t
|
+ |
+namespace media { |
+ |
+AUQueue::AUQueue() |
+ : has_eos_(false) |
qinmin
2015/05/12 23:58:22
the ctor can squeeze a single line
Tima Vaisburd
2015/05/13 22:51:46
Done.
wolenetz
2015/05/19 21:58:36
In general, "git cl format" is your friend :)
|
+{} |
+ |
+AUQueue::~AUQueue() |
+{} |
qinmin
2015/05/12 23:58:22
move {} to the previous line
Tima Vaisburd
2015/05/13 22:51:46
Done.
|
+ |
+void AUQueue::PushBack(const DemuxerData& data) { |
+ base::AutoLock lock(lock_); |
qinmin
2015/05/12 23:58:22
the lock is pretty expensive here as data will be
timav
2015/05/13 01:05:17
I used std::deque for simplicity as a temporary so
Tima Vaisburd
2015/05/13 22:51:47
Added TODO item
|
+ |
+ for (const AccessUnit& unit : data.access_units) { |
+ access_units_.push_back(unit); |
+ if (unit.is_end_of_stream || unit.data.empty()) { |
+ DVLOG(1) << "AUQueue::" << __FUNCTION__ << ": EOS detected"; |
+ has_eos_ = true; |
+ } |
+ } |
+ |
+ // We assume that the rule "one DemuxerConfigs for one AU |
+ // with |kConfigChanged|" holds and do not check anything. |
+ for (const DemuxerConfigs& conf : data.demuxer_configs) |
+ demuxer_configs_.push_back(conf); |
+} |
+ |
+void AUQueue::PopFront() { |
+ base::AutoLock lock(lock_); |
+ |
+ if (access_units_.front().status == DemuxerStream::kConfigChanged) |
+ demuxer_configs_.pop_front(); |
+ |
+ if (access_units_.front().is_end_of_stream) |
+ has_eos_ = false; // assume there os only one AU with EOS |
+ |
+ access_units_.pop_front(); |
+} |
+ |
+void AUQueue::Flush() { |
+ base::AutoLock lock(lock_); |
+ |
+ access_units_.clear(); |
+ demuxer_configs_.clear(); |
+ has_eos_ = false; |
+} |
+ |
+bool AUQueue::SkipToKeyFrame() { |
+ // Media thread |
+ base::AutoLock lock(lock_); |
+ // We assume there cannot be |demuxer_configs_| elements for non-key frames. |
+ |
+ std::deque<AccessUnit>::iterator it; |
+ for (it = access_units_.begin(); it!= access_units_.end(); ++it) { |
qinmin
2015/05/12 23:58:22
doesn't this skip all the access units that haven'
timav
2015/05/13 01:05:17
I think I misunderstood what SetCurrentFrameToPrev
|
+ if (it->is_key_frame) { |
+ access_units_.erase(access_units_.begin(), it); |
+ return true; |
+ } |
+ } |
+ |
+ return false; |
+} |
+ |
+void AUQueue::GetInfo(Info* info) const { |
+ base::AutoLock lock(lock_); |
+ |
+ info->length = access_units_.size(); |
+ info->has_eos = has_eos_; |
+ if (info->length > 0) { |
+ info->front_unit = &access_units_.front(); |
+ info->configs = |
+ (info->front_unit->status == DemuxerStream::kConfigChanged) ? |
+ &demuxer_configs_.front() : nullptr; |
+ } else { |
+ info->front_unit = nullptr; |
+ info->configs = nullptr; |
+ } |
+} |
+ |
+bool AUQueue::HasEOS() const { |
+ base::AutoLock lock(lock_); |
+ |
+ return has_eos_; |
+} |
+ |
+int AUQueue::Length() const { |
+ base::AutoLock lock(lock_); |
+ |
+ return access_units_.size(); |
+} |
+ |
+} // namespace media |
+ |
+std::ostream& operator<<(std::ostream& os, const media::AccessUnit& au) { |
+ os << "status:" << au.status |
+ << (au.is_end_of_stream ? " EOS" : "") |
+ << (au.is_key_frame ? " KEY_FRAME" : "") |
+ << " pts:" << au.timestamp |
+ << " size:" << au.data.size(); |
+ return os; |
+} |