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

Unified 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: Addressed some comments 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 side-by-side diff with in-line comments
Download patch
Index: media/base/android/access_unit_queue.cc
diff --git a/media/base/android/access_unit_queue.cc b/media/base/android/access_unit_queue.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cdb1e29fbe1601936d77f88a28d144089d711aa8
--- /dev/null
+++ b/media/base/android/access_unit_queue.cc
@@ -0,0 +1,108 @@
+// 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 "media/base/android/access_unit_queue.h"
+
+#include "base/logging.h"
+#include "media/base/demuxer_stream.h"
+
+namespace media {
+
+AccessUnitQueue::AccessUnitQueue() : has_eos_(false) {}
+
+AccessUnitQueue::~AccessUnitQueue() {}
+
+void AccessUnitQueue::PushBack(const DemuxerData& data) {
+ // TODO(timav): The lock is expensive here because it lasts
+ // for the whole duration of data copying. We need to figure out
+ // what to do with this.
+
+ // Media thread
+ base::AutoLock lock(lock_);
+
+ // We expect that the chunk containing EOS is the last chunk
+ DCHECK(!has_eos_);
+
+ DCHECK(!data.access_units.empty());
+
+#if DCHECK_IS_ON()
+ // Verify the rule "one DemuxerConfigs for one AU with |kConfigChanged|".
+ size_t num_config_placeholders = 0;
+#endif
+
+ for (const AccessUnit& unit : data.access_units) {
+#if DCHECK_IS_ON()
+ if (unit.status == DemuxerStream::kConfigChanged)
+ ++num_config_placeholders;
+#endif
+ access_units_.push_back(unit);
+ if (unit.is_end_of_stream) {
+ DVLOG(1) << "AccessUnitQueue::" << __FUNCTION__ << ": EOS detected";
+ has_eos_ = true;
+ }
+ }
+
+ DCHECK(data.demuxer_configs.size() == num_config_placeholders);
+
+ for (const DemuxerConfigs& conf : data.demuxer_configs)
+ demuxer_configs_.push_back(conf);
+}
+
+void AccessUnitQueue::PopFront() {
+ // Decoder thread
+ base::AutoLock lock(lock_);
+
+ if (access_units_.front().status == DemuxerStream::kConfigChanged)
+ demuxer_configs_.pop_front();
+
+ access_units_.pop_front();
+
+ if (access_units_.empty())
+ has_eos_ = false;
+}
+
+void AccessUnitQueue::Flush() {
+ // Media thread
+ base::AutoLock lock(lock_);
+
+ access_units_.clear();
+ demuxer_configs_.clear();
+ has_eos_ = false;
+}
+
+bool AccessUnitQueue::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) {
+ if (it->is_key_frame) {
+ access_units_.erase(access_units_.begin(), it);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void AccessUnitQueue::GetInfo(Info* info) const {
+ // Media thread, Decoder thread
+ base::AutoLock lock(lock_);
+
+ info->length = access_units_.size();
+ info->has_eos = has_eos_;
+ info->front_unit = nullptr;
+ info->configs = nullptr;
+
+ if (info->length > 0) {
+ info->front_unit = &access_units_.front();
+ if (access_units_.front().status == DemuxerStream::kConfigChanged) {
+ DCHECK(!demuxer_configs_.empty());
+ info->configs = &demuxer_configs_.front();
+ }
+ }
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698