| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "content/common/gpu/media/h264_dpb.h" | 9 #include "content/common/gpu/media/h264_dpb.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 H264PictureBase::H264PictureBase() { |
| 14 memset(this, 0, sizeof(*this)); |
| 15 } |
| 16 |
| 13 H264DPB::H264DPB() : max_num_pics_(0) {} | 17 H264DPB::H264DPB() : max_num_pics_(0) {} |
| 14 H264DPB::~H264DPB() {} | 18 H264DPB::~H264DPB() {} |
| 15 | 19 |
| 16 void H264DPB::Clear() { | 20 void H264DPB::Clear() { |
| 17 pics_.clear(); | 21 pics_.clear(); |
| 18 } | 22 } |
| 19 | 23 |
| 20 void H264DPB::set_max_num_pics(size_t max_num_pics) { | 24 void H264DPB::set_max_num_pics(size_t max_num_pics) { |
| 21 DCHECK_LE(max_num_pics, kDPBMaxSize); | 25 DCHECK_LE(max_num_pics, kDPBMaxSize); |
| 22 max_num_pics_ = max_num_pics; | 26 max_num_pics_ = max_num_pics; |
| 23 if (pics_.size() > max_num_pics_) | 27 if (pics_.size() > max_num_pics_) |
| 24 pics_.resize(max_num_pics_); | 28 pics_.resize(max_num_pics_); |
| 25 } | 29 } |
| 26 | 30 |
| 31 void H264DPB::UpdatePicPositions() { |
| 32 size_t i = 0; |
| 33 for (auto& pic : pics_) { |
| 34 pic->dpb_position = i; |
| 35 ++i; |
| 36 } |
| 37 } |
| 38 |
| 27 void H264DPB::DeleteByPOC(int poc) { | 39 void H264DPB::DeleteByPOC(int poc) { |
| 28 for (Pictures::iterator it = pics_.begin(); it != pics_.end(); ++it) { | 40 for (H264Picture::Vector::iterator it = pics_.begin(); |
| 41 it != pics_.end(); ++it) { |
| 29 if ((*it)->pic_order_cnt == poc) { | 42 if ((*it)->pic_order_cnt == poc) { |
| 30 pics_.erase(it); | 43 pics_.erase(it); |
| 44 UpdatePicPositions(); |
| 31 return; | 45 return; |
| 32 } | 46 } |
| 33 } | 47 } |
| 34 NOTREACHED() << "Missing POC: " << poc; | 48 NOTREACHED() << "Missing POC: " << poc; |
| 35 } | 49 } |
| 36 | 50 |
| 37 void H264DPB::DeleteUnused() { | 51 void H264DPB::DeleteUnused() { |
| 38 for (Pictures::iterator it = pics_.begin(); it != pics_.end(); ) { | 52 for (H264Picture::Vector::iterator it = pics_.begin(); it != pics_.end(); ) { |
| 39 if ((*it)->outputted && !(*it)->ref) | 53 if ((*it)->outputted && !(*it)->ref) |
| 40 it = pics_.erase(it); | 54 it = pics_.erase(it); |
| 41 else | 55 else |
| 42 ++it; | 56 ++it; |
| 43 } | 57 } |
| 58 UpdatePicPositions(); |
| 44 } | 59 } |
| 45 | 60 |
| 46 void H264DPB::StorePic(H264Picture* pic) { | 61 void H264DPB::StorePic(const scoped_refptr<H264Picture>& pic) { |
| 47 DCHECK_LT(pics_.size(), max_num_pics_); | 62 DCHECK_LT(pics_.size(), max_num_pics_); |
| 48 DVLOG(3) << "Adding PicNum: " << pic->pic_num << " ref: " << (int)pic->ref | 63 DVLOG(3) << "Adding PicNum: " << pic->pic_num << " ref: " << (int)pic->ref |
| 49 << " longterm: " << (int)pic->long_term << " to DPB"; | 64 << " longterm: " << (int)pic->long_term << " to DPB"; |
| 65 pic->dpb_position = pics_.size(); |
| 50 pics_.push_back(pic); | 66 pics_.push_back(pic); |
| 51 } | 67 } |
| 52 | 68 |
| 53 int H264DPB::CountRefPics() { | 69 int H264DPB::CountRefPics() { |
| 54 int ret = 0; | 70 int ret = 0; |
| 55 for (size_t i = 0; i < pics_.size(); ++i) { | 71 for (size_t i = 0; i < pics_.size(); ++i) { |
| 56 if (pics_[i]->ref) | 72 if (pics_[i]->ref) |
| 57 ++ret; | 73 ++ret; |
| 58 } | 74 } |
| 59 return ret; | 75 return ret; |
| 60 } | 76 } |
| 61 | 77 |
| 62 void H264DPB::MarkAllUnusedForRef() { | 78 void H264DPB::MarkAllUnusedForRef() { |
| 63 for (size_t i = 0; i < pics_.size(); ++i) | 79 for (size_t i = 0; i < pics_.size(); ++i) |
| 64 pics_[i]->ref = false; | 80 pics_[i]->ref = false; |
| 65 } | 81 } |
| 66 | 82 |
| 67 H264Picture* H264DPB::GetShortRefPicByPicNum(int pic_num) { | 83 scoped_refptr<H264Picture> H264DPB::GetShortRefPicByPicNum(int pic_num) { |
| 68 for (size_t i = 0; i < pics_.size(); ++i) { | 84 for (const auto& pic : pics_) { |
| 69 H264Picture* pic = pics_[i]; | |
| 70 if (pic->ref && !pic->long_term && pic->pic_num == pic_num) | 85 if (pic->ref && !pic->long_term && pic->pic_num == pic_num) |
| 71 return pic; | 86 return pic; |
| 72 } | 87 } |
| 73 | 88 |
| 74 DVLOG(1) << "Missing short ref pic num: " << pic_num; | 89 DVLOG(1) << "Missing short ref pic num: " << pic_num; |
| 75 return NULL; | 90 return nullptr; |
| 76 } | 91 } |
| 77 | 92 |
| 78 H264Picture* H264DPB::GetLongRefPicByLongTermPicNum(int pic_num) { | 93 scoped_refptr<H264Picture> H264DPB::GetLongRefPicByLongTermPicNum(int pic_num) { |
| 79 for (size_t i = 0; i < pics_.size(); ++i) { | 94 for (const auto& pic : pics_) { |
| 80 H264Picture* pic = pics_[i]; | |
| 81 if (pic->ref && pic->long_term && pic->long_term_pic_num == pic_num) | 95 if (pic->ref && pic->long_term && pic->long_term_pic_num == pic_num) |
| 82 return pic; | 96 return pic; |
| 83 } | 97 } |
| 84 | 98 |
| 85 DVLOG(1) << "Missing long term pic num: " << pic_num; | 99 DVLOG(1) << "Missing long term pic num: " << pic_num; |
| 86 return NULL; | 100 return nullptr; |
| 87 } | 101 } |
| 88 | 102 |
| 89 H264Picture* H264DPB::GetLowestFrameNumWrapShortRefPic() { | 103 scoped_refptr<H264Picture> H264DPB::GetLowestFrameNumWrapShortRefPic() { |
| 90 H264Picture* ret = NULL; | 104 scoped_refptr<H264Picture> ret; |
| 91 for (size_t i = 0; i < pics_.size(); ++i) { | 105 for (const auto& pic : pics_) { |
| 92 H264Picture* pic = pics_[i]; | |
| 93 if (pic->ref && !pic->long_term && | 106 if (pic->ref && !pic->long_term && |
| 94 (!ret || pic->frame_num_wrap < ret->frame_num_wrap)) | 107 (!ret || pic->frame_num_wrap < ret->frame_num_wrap)) |
| 95 ret = pic; | 108 ret = pic; |
| 96 } | 109 } |
| 97 return ret; | 110 return ret; |
| 98 } | 111 } |
| 99 | 112 |
| 100 void H264DPB::GetNotOutputtedPicsAppending(H264Picture::PtrVector& out) { | 113 void H264DPB::GetNotOutputtedPicsAppending(H264Picture::Vector* out) { |
| 101 for (size_t i = 0; i < pics_.size(); ++i) { | 114 for (const auto& pic : pics_) { |
| 102 H264Picture* pic = pics_[i]; | |
| 103 if (!pic->outputted) | 115 if (!pic->outputted) |
| 104 out.push_back(pic); | 116 out->push_back(pic); |
| 105 } | 117 } |
| 106 } | 118 } |
| 107 | 119 |
| 108 void H264DPB::GetShortTermRefPicsAppending(H264Picture::PtrVector& out) { | 120 void H264DPB::GetShortTermRefPicsAppending(H264Picture::Vector* out) { |
| 109 for (size_t i = 0; i < pics_.size(); ++i) { | 121 for (const auto& pic : pics_) { |
| 110 H264Picture* pic = pics_[i]; | |
| 111 if (pic->ref && !pic->long_term) | 122 if (pic->ref && !pic->long_term) |
| 112 out.push_back(pic); | 123 out->push_back(pic); |
| 113 } | 124 } |
| 114 } | 125 } |
| 115 | 126 |
| 116 void H264DPB::GetLongTermRefPicsAppending(H264Picture::PtrVector& out) { | 127 void H264DPB::GetLongTermRefPicsAppending(H264Picture::Vector* out) { |
| 117 for (size_t i = 0; i < pics_.size(); ++i) { | 128 for (const auto& pic : pics_) { |
| 118 H264Picture* pic = pics_[i]; | |
| 119 if (pic->ref && pic->long_term) | 129 if (pic->ref && pic->long_term) |
| 120 out.push_back(pic); | 130 out->push_back(pic); |
| 121 } | 131 } |
| 122 } | 132 } |
| 123 | 133 |
| 124 } // namespace content | 134 } // namespace content |
| OLD | NEW |