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

Side by Side Diff: content/common/gpu/media/h264_dpb.cc

Issue 1882373004: Migrate content/common/gpu/media code to media/gpu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Squash and rebase Created 4 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 (c) 2012 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 <string.h>
6
7 #include <algorithm>
8
9 #include "base/logging.h"
10 #include "base/stl_util.h"
11 #include "content/common/gpu/media/h264_dpb.h"
12
13 namespace content {
14
15 H264Picture::H264Picture()
16 : pic_order_cnt_type(0),
17 top_field_order_cnt(0),
18 bottom_field_order_cnt(0),
19 pic_order_cnt(0),
20 pic_order_cnt_msb(0),
21 pic_order_cnt_lsb(0),
22 delta_pic_order_cnt_bottom(0),
23 delta_pic_order_cnt0(0),
24 delta_pic_order_cnt1(0),
25 pic_num(0),
26 long_term_pic_num(0),
27 frame_num(0),
28 frame_num_offset(0),
29 frame_num_wrap(0),
30 long_term_frame_idx(0),
31 type(media::H264SliceHeader::kPSlice),
32 nal_ref_idc(0),
33 idr(false),
34 idr_pic_id(0),
35 ref(false),
36 long_term(false),
37 outputted(false),
38 mem_mgmt_5(false),
39 nonexisting(false),
40 field(FIELD_NONE),
41 long_term_reference_flag(false),
42 adaptive_ref_pic_marking_mode_flag(false),
43 dpb_position(0) {
44 memset(&ref_pic_marking, 0, sizeof(ref_pic_marking));
45 }
46
47 H264Picture::~H264Picture() {
48 }
49
50 V4L2H264Picture* H264Picture::AsV4L2H264Picture() {
51 return nullptr;
52 }
53
54 VaapiH264Picture* H264Picture::AsVaapiH264Picture() {
55 return nullptr;
56 }
57
58 H264DPB::H264DPB() : max_num_pics_(0) {}
59 H264DPB::~H264DPB() {}
60
61 void H264DPB::Clear() {
62 pics_.clear();
63 }
64
65 void H264DPB::set_max_num_pics(size_t max_num_pics) {
66 DCHECK_LE(max_num_pics, kDPBMaxSize);
67 max_num_pics_ = max_num_pics;
68 if (pics_.size() > max_num_pics_)
69 pics_.resize(max_num_pics_);
70 }
71
72 void H264DPB::UpdatePicPositions() {
73 size_t i = 0;
74 for (auto& pic : pics_) {
75 pic->dpb_position = i;
76 ++i;
77 }
78 }
79
80 void H264DPB::DeleteByPOC(int poc) {
81 for (H264Picture::Vector::iterator it = pics_.begin();
82 it != pics_.end(); ++it) {
83 if ((*it)->pic_order_cnt == poc) {
84 pics_.erase(it);
85 UpdatePicPositions();
86 return;
87 }
88 }
89 NOTREACHED() << "Missing POC: " << poc;
90 }
91
92 void H264DPB::DeleteUnused() {
93 for (H264Picture::Vector::iterator it = pics_.begin(); it != pics_.end(); ) {
94 if ((*it)->outputted && !(*it)->ref)
95 it = pics_.erase(it);
96 else
97 ++it;
98 }
99 UpdatePicPositions();
100 }
101
102 void H264DPB::StorePic(const scoped_refptr<H264Picture>& pic) {
103 DCHECK_LT(pics_.size(), max_num_pics_);
104 DVLOG(3) << "Adding PicNum: " << pic->pic_num << " ref: " << (int)pic->ref
105 << " longterm: " << (int)pic->long_term << " to DPB";
106 pic->dpb_position = pics_.size();
107 pics_.push_back(pic);
108 }
109
110 int H264DPB::CountRefPics() {
111 int ret = 0;
112 for (size_t i = 0; i < pics_.size(); ++i) {
113 if (pics_[i]->ref)
114 ++ret;
115 }
116 return ret;
117 }
118
119 void H264DPB::MarkAllUnusedForRef() {
120 for (size_t i = 0; i < pics_.size(); ++i)
121 pics_[i]->ref = false;
122 }
123
124 scoped_refptr<H264Picture> H264DPB::GetShortRefPicByPicNum(int pic_num) {
125 for (const auto& pic : pics_) {
126 if (pic->ref && !pic->long_term && pic->pic_num == pic_num)
127 return pic;
128 }
129
130 DVLOG(1) << "Missing short ref pic num: " << pic_num;
131 return nullptr;
132 }
133
134 scoped_refptr<H264Picture> H264DPB::GetLongRefPicByLongTermPicNum(int pic_num) {
135 for (const auto& pic : pics_) {
136 if (pic->ref && pic->long_term && pic->long_term_pic_num == pic_num)
137 return pic;
138 }
139
140 DVLOG(1) << "Missing long term pic num: " << pic_num;
141 return nullptr;
142 }
143
144 scoped_refptr<H264Picture> H264DPB::GetLowestFrameNumWrapShortRefPic() {
145 scoped_refptr<H264Picture> ret;
146 for (const auto& pic : pics_) {
147 if (pic->ref && !pic->long_term &&
148 (!ret || pic->frame_num_wrap < ret->frame_num_wrap))
149 ret = pic;
150 }
151 return ret;
152 }
153
154 void H264DPB::GetNotOutputtedPicsAppending(H264Picture::Vector* out) {
155 for (const auto& pic : pics_) {
156 if (!pic->outputted)
157 out->push_back(pic);
158 }
159 }
160
161 void H264DPB::GetShortTermRefPicsAppending(H264Picture::Vector* out) {
162 for (const auto& pic : pics_) {
163 if (pic->ref && !pic->long_term)
164 out->push_back(pic);
165 }
166 }
167
168 void H264DPB::GetLongTermRefPicsAppending(H264Picture::Vector* out) {
169 for (const auto& pic : pics_) {
170 if (pic->ref && pic->long_term)
171 out->push_back(pic);
172 }
173 }
174
175 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698