/src/x265/source/common/piclist.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * Copyright (C) 2013-2020 MulticoreWare, Inc |
3 | | * |
4 | | * Authors: Gopu Govindaswamy <gopu@multicorewareinc.com> |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 2 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. |
19 | | * |
20 | | * This program is also available under a commercial proprietary license. |
21 | | * For more information, contact us at license @ x265.com. |
22 | | *****************************************************************************/ |
23 | | |
24 | | #include "common.h" |
25 | | #include "piclist.h" |
26 | | #include "frame.h" |
27 | | |
28 | | using namespace X265_NS; |
29 | | |
30 | | void PicList::pushFront(Frame& curFrame) |
31 | 0 | { |
32 | 0 | X265_CHECK(!curFrame.m_next && !curFrame.m_prev, "piclist: picture already in list\n"); // ensure frame is not in a list |
33 | 0 | curFrame.m_next = m_start; |
34 | 0 | curFrame.m_prev = NULL; |
35 | |
|
36 | 0 | if (m_count) |
37 | 0 | { |
38 | 0 | m_start->m_prev = &curFrame; |
39 | 0 | m_start = &curFrame; |
40 | 0 | } |
41 | 0 | else |
42 | 0 | { |
43 | 0 | m_start = m_end = &curFrame; |
44 | 0 | } |
45 | 0 | m_count++; |
46 | 0 | } |
47 | | |
48 | | void PicList::pushFrontMCSTF(Frame& curFrame) |
49 | 0 | { |
50 | 0 | X265_CHECK(!curFrame.m_nextMCSTF && !curFrame.m_nextMCSTF, "piclist: picture already in OPB list\n"); // ensure frame is not in a list |
51 | 0 | curFrame.m_nextMCSTF = m_start; |
52 | 0 | curFrame.m_prevMCSTF = NULL; |
53 | |
|
54 | 0 | if (m_count) |
55 | 0 | { |
56 | 0 | m_start->m_prevMCSTF = &curFrame; |
57 | 0 | m_start = &curFrame; |
58 | 0 | } |
59 | 0 | else |
60 | 0 | { |
61 | 0 | m_start = m_end = &curFrame; |
62 | 0 | } |
63 | 0 | m_count++; |
64 | |
|
65 | 0 | } |
66 | | |
67 | | void PicList::pushBack(Frame& curFrame) |
68 | 0 | { |
69 | 0 | X265_CHECK(!curFrame.m_next && !curFrame.m_prev, "piclist: picture already in list\n"); // ensure frame is not in a list |
70 | 0 | curFrame.m_next = NULL; |
71 | 0 | curFrame.m_prev = m_end; |
72 | |
|
73 | 0 | if (m_count) |
74 | 0 | { |
75 | 0 | m_end->m_next = &curFrame; |
76 | 0 | m_end = &curFrame; |
77 | 0 | } |
78 | 0 | else |
79 | 0 | { |
80 | 0 | m_start = m_end = &curFrame; |
81 | 0 | } |
82 | 0 | m_count++; |
83 | 0 | } |
84 | | |
85 | | #if ENABLE_MULTIVIEW |
86 | | Frame* PicList::popFrontSubDPB() |
87 | | { |
88 | | if (m_start) |
89 | | { |
90 | | Frame* temp = m_start; |
91 | | m_count--; |
92 | | |
93 | | if (m_count) |
94 | | { |
95 | | m_start = m_start->m_nextSubDPB; |
96 | | m_start->m_prevSubDPB = NULL; |
97 | | } |
98 | | else |
99 | | { |
100 | | m_start = m_end = NULL; |
101 | | } |
102 | | temp->m_next = temp->m_prev = NULL; |
103 | | return temp; |
104 | | } |
105 | | else |
106 | | return NULL; |
107 | | } |
108 | | |
109 | | void PicList::pushBackSubDPB(Frame& curFrame) |
110 | | { |
111 | | X265_CHECK(!curFrame.m_nextSubDPB && !curFrame.m_prevSubDPB, "piclist: picture already in Sub DPB list\n"); // ensure frame is not in a list |
112 | | curFrame.m_nextSubDPB = NULL; |
113 | | curFrame.m_prevSubDPB = m_end; |
114 | | |
115 | | if (m_count) |
116 | | { |
117 | | m_end->m_nextSubDPB = &curFrame; |
118 | | m_end = &curFrame; |
119 | | } |
120 | | else |
121 | | { |
122 | | m_start = m_end = &curFrame; |
123 | | } |
124 | | m_count++; |
125 | | } |
126 | | |
127 | | void PicList::removeSubDPB(Frame& curFrame) |
128 | | { |
129 | | #if _DEBUG |
130 | | Frame* tmp = m_start; |
131 | | while (tmp && tmp != &curFrame) |
132 | | { |
133 | | tmp = tmp->m_nextSubDPB; |
134 | | } |
135 | | |
136 | | X265_CHECK(tmp == &curFrame, "piclist: pic being removed was not in list\n"); // verify pic is in this list |
137 | | #endif |
138 | | |
139 | | m_count--; |
140 | | if (m_count) |
141 | | { |
142 | | if (m_start == &curFrame) |
143 | | m_start = curFrame.m_nextSubDPB; |
144 | | if (m_end == &curFrame) |
145 | | m_end = curFrame.m_prevSubDPB; |
146 | | |
147 | | if (curFrame.m_nextSubDPB) |
148 | | curFrame.m_nextSubDPB->m_prevSubDPB = curFrame.m_prevSubDPB; |
149 | | if (curFrame.m_prevSubDPB) |
150 | | curFrame.m_prevSubDPB->m_nextSubDPB = curFrame.m_nextSubDPB; |
151 | | } |
152 | | else |
153 | | { |
154 | | m_start = m_end = NULL; |
155 | | } |
156 | | |
157 | | curFrame.m_nextSubDPB = curFrame.m_prevSubDPB = NULL; |
158 | | } |
159 | | #endif |
160 | | |
161 | | void PicList::pushBackMCSTF(Frame& curFrame) |
162 | 0 | { |
163 | 0 | X265_CHECK(!curFrame.m_nextMCSTF && !curFrame.m_prevMCSTF, "piclist: picture already in OPB list\n"); // ensure frame is not in a list |
164 | 0 | curFrame.m_nextMCSTF = NULL; |
165 | 0 | curFrame.m_prevMCSTF = m_end; |
166 | |
|
167 | 0 | if (m_count) |
168 | 0 | { |
169 | 0 | m_end->m_nextMCSTF = &curFrame; |
170 | 0 | m_end = &curFrame; |
171 | 0 | } |
172 | 0 | else |
173 | 0 | { |
174 | 0 | m_start = m_end = &curFrame; |
175 | 0 | } |
176 | 0 | m_count++; |
177 | 0 | } |
178 | | |
179 | | Frame *PicList::popFront() |
180 | 0 | { |
181 | 0 | if (m_start) |
182 | 0 | { |
183 | 0 | Frame *temp = m_start; |
184 | 0 | m_count--; |
185 | |
|
186 | 0 | if (m_count) |
187 | 0 | { |
188 | 0 | m_start = m_start->m_next; |
189 | 0 | m_start->m_prev = NULL; |
190 | 0 | } |
191 | 0 | else |
192 | 0 | { |
193 | 0 | m_start = m_end = NULL; |
194 | 0 | } |
195 | 0 | temp->m_next = temp->m_prev = NULL; |
196 | 0 | return temp; |
197 | 0 | } |
198 | 0 | else |
199 | 0 | return NULL; |
200 | 0 | } |
201 | | |
202 | | Frame* PicList::getPOC(int poc, int sLayerId) |
203 | 0 | { |
204 | 0 | Frame *curFrame = m_start; |
205 | 0 | int layer = curFrame->m_param->numViews > 1 ? curFrame->m_viewId : (curFrame->m_param->numScalableLayers > 1) ? curFrame->m_sLayerId : 0; |
206 | 0 | while (curFrame && (curFrame->m_poc != poc || layer != sLayerId)) |
207 | 0 | { |
208 | 0 | curFrame = curFrame->m_next; |
209 | 0 | if(curFrame) |
210 | 0 | layer = curFrame->m_param->numViews > 1 ? curFrame->m_viewId : (curFrame->m_param->numScalableLayers > 1) ? curFrame->m_sLayerId : 0; |
211 | 0 | } |
212 | 0 | return curFrame; |
213 | 0 | } |
214 | | |
215 | | Frame* PicList::getPOCMCSTF(int poc) |
216 | 0 | { |
217 | 0 | Frame *curFrame = m_start; |
218 | 0 | while (curFrame && curFrame->m_poc != poc) |
219 | 0 | curFrame = curFrame->m_nextMCSTF; |
220 | 0 | return curFrame; |
221 | 0 | } |
222 | | |
223 | | Frame *PicList::popBack() |
224 | 0 | { |
225 | 0 | if (m_end) |
226 | 0 | { |
227 | 0 | Frame* temp = m_end; |
228 | 0 | m_count--; |
229 | |
|
230 | 0 | if (m_count) |
231 | 0 | { |
232 | 0 | m_end = m_end->m_prev; |
233 | 0 | m_end->m_next = NULL; |
234 | 0 | } |
235 | 0 | else |
236 | 0 | { |
237 | 0 | m_start = m_end = NULL; |
238 | 0 | } |
239 | 0 | temp->m_next = temp->m_prev = NULL; |
240 | 0 | return temp; |
241 | 0 | } |
242 | 0 | else |
243 | 0 | return NULL; |
244 | 0 | } |
245 | | |
246 | | Frame *PicList::popBackMCSTF() |
247 | 0 | { |
248 | 0 | if (m_end) |
249 | 0 | { |
250 | 0 | Frame* temp = m_end; |
251 | 0 | m_count--; |
252 | |
|
253 | 0 | if (m_count) |
254 | 0 | { |
255 | 0 | m_end = m_end->m_prevMCSTF; |
256 | 0 | m_end->m_nextMCSTF = NULL; |
257 | 0 | } |
258 | 0 | else |
259 | 0 | { |
260 | 0 | m_start = m_end = NULL; |
261 | 0 | } |
262 | 0 | temp->m_nextMCSTF = temp->m_prevMCSTF = NULL; |
263 | 0 | return temp; |
264 | 0 | } |
265 | 0 | else |
266 | 0 | return NULL; |
267 | 0 | } |
268 | | |
269 | | Frame* PicList::getCurFrame(int sLayer) |
270 | 0 | { |
271 | 0 | Frame *curFrame = m_start; |
272 | 0 | int layer = curFrame->m_param->numViews > 1 ? curFrame->m_viewId : (curFrame->m_param->numScalableLayers > 1) ? curFrame->m_sLayerId : 0; |
273 | 0 | if (layer == sLayer && curFrame != NULL) |
274 | 0 | return curFrame; |
275 | 0 | else |
276 | 0 | return NULL; |
277 | 0 | } |
278 | | |
279 | | void PicList::remove(Frame& curFrame) |
280 | 0 | { |
281 | | #if _DEBUG |
282 | | Frame *tmp = m_start; |
283 | | while (tmp && tmp != &curFrame) |
284 | | { |
285 | | tmp = tmp->m_next; |
286 | | } |
287 | | |
288 | | X265_CHECK(tmp == &curFrame, "piclist: pic being removed was not in list\n"); // verify pic is in this list |
289 | | #endif |
290 | |
|
291 | 0 | m_count--; |
292 | 0 | if (m_count) |
293 | 0 | { |
294 | 0 | if (m_start == &curFrame) |
295 | 0 | m_start = curFrame.m_next; |
296 | 0 | if (m_end == &curFrame) |
297 | 0 | m_end = curFrame.m_prev; |
298 | |
|
299 | 0 | if (curFrame.m_next) |
300 | 0 | curFrame.m_next->m_prev = curFrame.m_prev; |
301 | 0 | if (curFrame.m_prev) |
302 | 0 | curFrame.m_prev->m_next = curFrame.m_next; |
303 | 0 | } |
304 | 0 | else |
305 | 0 | { |
306 | 0 | m_start = m_end = NULL; |
307 | 0 | } |
308 | |
|
309 | 0 | curFrame.m_next = curFrame.m_prev = NULL; |
310 | 0 | } |
311 | | |
312 | | |
313 | | Frame* PicList::removeFrame(Frame& curFrame) |
314 | 0 | { |
315 | 0 | Frame* tmp = &curFrame; |
316 | | #if _DEBUG |
317 | | tmp = m_start; |
318 | | while (tmp && tmp != &curFrame) |
319 | | { |
320 | | tmp = tmp->m_next; |
321 | | } |
322 | | |
323 | | X265_CHECK(tmp == &curFrame, "piclist: pic being removed was not in list\n"); // verify pic is in this list |
324 | | #endif |
325 | |
|
326 | 0 | m_count--; |
327 | 0 | if (m_count) |
328 | 0 | { |
329 | 0 | if (m_start == &curFrame) |
330 | 0 | m_start = curFrame.m_next; |
331 | 0 | if (m_end == &curFrame) |
332 | 0 | m_end = curFrame.m_prev; |
333 | |
|
334 | 0 | if (curFrame.m_next) |
335 | 0 | curFrame.m_next->m_prev = curFrame.m_prev; |
336 | 0 | if (curFrame.m_prev) |
337 | 0 | curFrame.m_prev->m_next = curFrame.m_next; |
338 | 0 | } |
339 | 0 | else |
340 | 0 | { |
341 | 0 | m_start = m_end = NULL; |
342 | 0 | } |
343 | |
|
344 | 0 | curFrame.m_next = curFrame.m_prev = NULL; |
345 | 0 | return tmp; |
346 | 0 | } |
347 | | |
348 | | void PicList::removeMCSTF(Frame& curFrame) |
349 | 0 | { |
350 | | #if _DEBUG |
351 | | Frame *tmp = m_start; |
352 | | while (tmp && tmp != &curFrame) |
353 | | { |
354 | | tmp = tmp->m_nextMCSTF; |
355 | | } |
356 | | |
357 | | X265_CHECK(tmp == &curFrame, "framelist: pic being removed was not in list\n"); // verify pic is in this list |
358 | | #endif |
359 | |
|
360 | 0 | m_count--; |
361 | 0 | if (m_count) |
362 | 0 | { |
363 | 0 | if (m_start == &curFrame) |
364 | 0 | m_start = curFrame.m_nextMCSTF; |
365 | 0 | if (m_end == &curFrame) |
366 | 0 | m_end = curFrame.m_prevMCSTF; |
367 | |
|
368 | 0 | if (curFrame.m_nextMCSTF) |
369 | 0 | curFrame.m_nextMCSTF->m_prevMCSTF = curFrame.m_prevMCSTF; |
370 | 0 | if (curFrame.m_prevMCSTF) |
371 | 0 | curFrame.m_prevMCSTF->m_nextMCSTF = curFrame.m_nextMCSTF; |
372 | 0 | } |
373 | 0 | else |
374 | 0 | { |
375 | 0 | m_start = m_end = NULL; |
376 | 0 | } |
377 | |
|
378 | 0 | curFrame.m_nextMCSTF = curFrame.m_prevMCSTF = NULL; |
379 | 0 | } |