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

Unified Diff: content/common/gpu/media/h264_dpb.cc

Issue 9814001: Add VAVDA, the VAAPI Video Decode Accelerator for Intel CPUs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for occasional decode freeze on output falling behind for more demanding streams. Created 8 years, 8 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: content/common/gpu/media/h264_dpb.cc
diff --git a/content/common/gpu/media/h264_dpb.cc b/content/common/gpu/media/h264_dpb.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1ed5010937494862241a4bc74f16f0f5b6d55647
--- /dev/null
+++ b/content/common/gpu/media/h264_dpb.cc
@@ -0,0 +1,142 @@
+// Copyright (c) 2012 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 "h264_dpb.h"
+
+#include <algorithm>
+
+#include "base/logging.h"
+#include "base/stl_util.h"
+
+namespace content {
+
+H264DPB::H264DPB() {}
+
+H264DPB::~H264DPB() {
+ Clear();
+}
+
+void H264DPB::Clear() {
+ STLDeleteElements(&pics_);
+}
+
+void H264DPB::RemovePic(const H264Picture::PtrVector::iterator iter) {
+ DVLOG(3) << "Removing pic_num: " << (*iter)->pic_num << " from DPB";
+ delete *iter;
+ pics_.erase(iter);
+}
+
+void H264DPB::RemoveByPOC(int poc) {
+ for (H264Picture::PtrVector::iterator it = pics_.begin(); it != pics_.end();
+ ++it) {
+ if ((*it)->pic_order_cnt == poc) {
+ RemovePic(it);
+ return;
+ }
+ }
+ DVLOG(1) << "Missing POC: " << poc;
Ami GONE FROM CHROMIUM 2012/04/09 02:41:47 Is this not a DCHECK-able offense?
Pawel Osciak 2012/05/03 16:22:07 Yeah, I'm reconsidering error resilience especiall
+}
+
+void H264DPB::RemoveUnused() {
+ for (H264Picture::PtrVector::iterator it = pics_.begin(); it != pics_.end();
+ ++it) {
+ if ((*it)->outputted && !(*it)->ref)
+ RemovePic(it);
Ami GONE FROM CHROMIUM 2012/04/09 02:41:47 Isn't this a bug (erase inside RemovePic invalidat
Pawel Osciak 2012/05/03 16:22:07 Of course. I always forget.
+ }
+}
+
+void H264DPB::StorePic(H264Picture* pic) {
+ DCHECK_LT(pics_.size(), kDPBMaxSize);
+ DVLOG(3) << "Adding PicNum: " << pic->pic_num << " ref: " << (int)pic->ref
+ << " longterm: " << (int)pic->long_term << " to DPB";
+ pics_.push_back(pic);
+}
+
+int H264DPB::CountRefPics() {
+ int ret = 0;
+ for (size_t i = 0; i < pics_.size(); ++i) {
+ if (pics_[i]->ref)
+ ++ret;
+ }
+ return ret;
+}
+
+void H264DPB::MarkAllUnusedForRef() {
+ for (size_t i = 0; i < pics_.size(); ++i)
+ pics_[i]->ref = false;
+}
+
+H264Picture* H264DPB::GetShortRefPicByPicNum(int pic_num) {
+ for (size_t i = 0; i < pics_.size(); ++i) {
+ H264Picture* pic = pics_[i];
+ if (pic->ref && !pic->long_term && pic->pic_num == pic_num)
+ return pic;
+ }
+
+ DVLOG(1) << "Missing short ref pic num: " << pic_num;
Ami GONE FROM CHROMIUM 2012/04/09 02:41:47 Here and elsewhere aren't these properties of a ma
Pawel Osciak 2012/05/03 16:22:07 My intention was to die gracefully with a stream e
+ return NULL;
+}
+
+H264Picture* H264DPB::GetLongRefPicByLongTermPicNum(int pic_num) {
+ for (size_t i = 0; i < pics_.size(); ++i) {
+ H264Picture* pic = pics_[i];
+ if (pic->ref && pic->long_term && pic->long_term_pic_num == pic_num)
+ return pic;
+ }
+
+ DVLOG(1) << "Missing long term pic num: " << pic_num;
+ return NULL;
+}
+
+H264Picture* H264DPB::GetLowestFrameNumWrapShortRefPic() {
+ H264Picture* ret = NULL;
Ami GONE FROM CHROMIUM 2012/04/09 02:41:47 A trick to avoid the need for the !ret (and an ext
Pawel Osciak 2012/05/03 16:22:07 Yeah, that's basically the case, but feel more com
+ for (size_t i = 0; i < pics_.size(); ++i) {
+ H264Picture* pic = pics_[i];
+ if (pic->ref && !pic->long_term &&
+ (!ret || pic->frame_num_wrap < ret->frame_num_wrap))
+ ret = pic;
+ }
+ return ret;
+}
+
+struct IsH264PictureOutputted {
+ bool operator()(H264Picture*& pic) {
+ return pic->outputted;
+ }
+};
+
+void H264DPB::GetNotOutputtedPicsAppending(H264Picture::PtrVector& out) {
+ // Append to ret all not outputted pictures.
+ std::remove_copy_if(pics_.begin(), pics_.end(), std::back_inserter(out),
+ IsH264PictureOutputted());
Ami GONE FROM CHROMIUM 2012/04/09 02:41:47 Why algorithms instead of a loop? (here and below)
Pawel Osciak 2012/05/03 16:22:07 You really hate stl, don't you? ;) Done, even with
Ami GONE FROM CHROMIUM 2012/05/03 23:22:53 Hey, it's not just me - your editor (and future re
+}
+
+struct IsH264PictureShortTermRef
+ : public std::unary_function<H264Picture*, bool> {
+ bool operator()(const H264Picture* pic) const {
+ return (pic->ref && !pic->long_term);
+ }
+};
+
+void H264DPB::GetShortTermRefPicsAppending(H264Picture::PtrVector& out) {
+ // copy_if in terms of remove_copy_if.
+ std::remove_copy_if(pics_.begin(), pics_.end(), std::back_inserter(out),
+ std::not1(IsH264PictureShortTermRef()));
+}
+
+struct IsH264PictureLongTermRef
+ : public std::unary_function<H264Picture*, bool> {
+ bool operator()(const H264Picture* pic) const {
+ return (pic->ref && pic->long_term);
+ }
+};
+
+void H264DPB::GetLongTermRefPicsAppending(H264Picture::PtrVector& out) {
+ // copy_if in terms of remove_copy_if.
+ std::remove_copy_if(pics_.begin(), pics_.end(), std::back_inserter(out),
+ std::not1(IsH264PictureLongTermRef()));
+}
+
+} // namespace content
+

Powered by Google App Engine
This is Rietveld 408576698