1 /*
2 * HEVC video decoder
3 *
4 * Copyright (C) 2012 - 2013 Guillaume Martres
5 * Copyright (C) 2012 - 2013 Gildas Cocherel
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
26
30
32 {
33 /* frame->frame can be NULL if context init failed */
35 return;
36
37 frame->
flags &= ~flags;
40
43
48
50
53 }
54 }
55
57 {
63 }
64
66 {
67 int i;
72 }
73
75 {
76 int i;
79 }
80
82 {
87 continue;
88
91 if (ret < 0)
93
96 goto fail;
97
100 goto fail;
102
105 goto fail;
110
113
120 goto fail;
122 }
123 }
124
126 fail:
129 }
132 }
133
135 {
137 int i;
138
139 /* check that this POC doesn't already exist */
142
146 poc);
148 }
149 }
150
152 if (!ref)
154
157
160 else
162
166
167 return 0;
168 }
169
171 {
172 do {
173 int nb_output = 0;
174 int min_poc = INT_MAX;
176
183 }
184 }
185 }
186
191 nb_output++;
192 if (frame->
poc < min_poc || nb_output == 1) {
193 min_poc = frame->
poc;
194 min_idx = i;
195 }
196 }
197 }
198
199 /* wait for more frames before output */
202 return 0;
203
204 if (nb_output) {
210
214 else
216 if (ret < 0)
218
219 for (i = 0; i < 3; i++) {
225 }
227 "Output frame with POC %d.\n", frame->
poc);
228 return 1;
229 }
230
233 else
234 break;
235 } while (1);
236
237 return 0;
238 }
239
241 {
242 int dpb = 0;
243 int min_poc = INT_MAX;
244 int i;
245
248 if ((frame->
flags) &&
251 dpb++;
252 }
253 }
254
258 if ((frame->
flags) &&
262 min_poc = frame->
poc;
263 }
264 }
265 }
266
271 frame->
poc <= min_poc) {
273 }
274 }
275
276 dpb--;
277 }
278 }
279
281 {
285 int i;
286
289
290 for (i = ctb_addr_ts; i < ctb_count; i++)
292
294
295 return 0;
296 }
297
299 {
301
305
307 if (ret < 0)
309
314 }
315
316 for (list_idx = 0; list_idx < nb_list; list_idx++) {
319
320 /* The order of the elements is
321 * ST_CURR_BEF - ST_CURR_AFT - LT_CURR for the L0 and
322 * ST_CURR_AFT - ST_CURR_BEF - LT_CURR for the L1 */
326
327 /* concatenate the candidate lists for the current frame */
336 }
337 }
338 }
339
340 /* reorder the references if necessary */
342 for (i = 0; i < sh->
nb_refs[list_idx]; i++) {
344
348 }
349
351 rpl->
ref[i] = rpl_tmp.
ref[idx];
354 }
355 } else {
356 memcpy(rpl, &rpl_tmp, sizeof(*rpl));
358 }
359
363 }
364
365 return 0;
366 }
367
369 {
370 int i;
372
376 if ((ref->
poc & LtMask) == poc)
377 return ref;
378 }
379 }
380
384 if (ref->
poc == poc || (ref->
poc & LtMask) == poc)
385 return ref;
386 }
387 }
388
390 "Could not find ref with POC %d\n", poc);
392 }
393
395 {
397 frame->
flags |= flag;
398 }
399
401 {
404
406 if (!frame)
408
411 for (i = 0; frame->
frame->
buf[i]; i++)
414 } else {
420 }
421 }
422 }
423
427
430
432 }
433
434 /* add a reference with the given poc to the list and mark it as used in DPB */
436 int poc, int ref_flag)
437 {
439
442
443 if (!ref) {
445 if (!ref)
447 }
448
452
454 return 0;
455 }
456
458 {
463
464 if (!short_rps) {
466 return 0;
467 }
468
469 /* clear the reference flags on all frames except the current one */
472
474 continue;
475
477 }
478
480 rps[i].nb_refs = 0;
481
482 /* add the short refs */
485 int list;
486
487 if (!short_rps->
used[i])
489 else if (i < short_rps->num_negative_pics)
491 else
493
495 if (ret < 0)
496 goto fail;
497 }
498
499 /* add the long refs */
500 for (i = 0; i < long_rps->
nb_refs; i++) {
501 int poc = long_rps->
poc[i];
503
505 if (ret < 0)
506 goto fail;
507 }
508
509 fail:
510 /* release any frames that are now unused */
513
515 }
516
518 {
520 int prev_poc_lsb = s->
pocTid0 % max_poc_lsb;
521 int prev_poc_msb = s->
pocTid0 - prev_poc_lsb;
522 int poc_msb;
523
524 if (poc_lsb < prev_poc_lsb && prev_poc_lsb - poc_lsb >= max_poc_lsb / 2)
525 poc_msb = prev_poc_msb + max_poc_lsb;
526 else if (poc_lsb > prev_poc_lsb && poc_lsb - prev_poc_lsb > max_poc_lsb / 2)
527 poc_msb = prev_poc_msb - max_poc_lsb;
528 else
529 poc_msb = prev_poc_msb;
530
531 // For BLA picture types, POCmsb is set to 0.
535 poc_msb = 0;
536
537 return poc_msb + poc_lsb;
538 }
539
541 {
543 int i;
546
547 if (rps) {
549 ret += !!rps->
used[i];
551 ret += !!rps->
used[i];
552 }
553
554 if (long_rps) {
555 for (i = 0; i < long_rps->
nb_refs; i++)
556 ret += !!long_rps->
used[i];
557 }
559 }