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
33
35 {
41
44
46 frame->nb_rpl_elems = 0;
49
51 }
52 }
53
55 {
57 int x_cb = x0 >>
sps->log2_ctb_size;
58 int y_cb = y0 >>
sps->log2_ctb_size;
59 int pic_width_cb =
sps->ctb_width;
60 int ctb_addr_ts =
ref->pps->ctb_addr_rs_to_ts[y_cb * pic_width_cb + x_cb];
61 return &
ref->rpl_tab[ctb_addr_ts]->refPicList[0];
62 }
63
65 {
71 }
72
74 {
79 }
80 }
81
83 {
85 const int view_id =
vps->view_id[
s->cur_layer];
90 continue;
91
95
96 // Add LCEVC SEI metadata here, as it's needed in get_buffer()
97 if (
s->sei.common.lcevc.info) {
103 }
104
105 // add view ID side data if it's nontrivial
106 if (
vps->nb_layers > 1 || view_id) {
109 &
frame->f->nb_side_data,
111 sizeof(int), 0);
112 if (!sd)
114 *(
int*)sd->
data = view_id;
115
118
120 if (!stereo_3d)
122
128 else
130 }
131 }
132
137
141 frame->nb_rpl_elems =
s->pkt.nb_nals;
142
146
151 for (j = 0; j <
frame->ctb_count; j++)
153
159
163
165
170 }
173 }
174
176 {
179
180 /* check that this POC doesn't already exist */
183
186 poc);
188 }
189 }
190
194
197 s->collocated_ref =
NULL;
198
199 ref->base_layer_frame = (l != &
s->layers[0] &&
s->layers[0].cur_frame) ?
200 s->layers[0].cur_frame -
s->layers[0].DPB : -1;
201
202 if (
s->sh.pic_output_flag)
204 else
206
212
213 return 0;
214 }
215
217 {
222 }
223 }
224 }
225
227 unsigned layers_active_decode, unsigned layers_active_output,
228 unsigned max_output, unsigned max_dpb, int discard)
229 {
230 while (1) {
232 int nb_output = 0;
233 int min_poc = INT_MAX;
234 int min_layer = -1;
235 int min_idx,
ret = 0;
236
239
240 if (!(layers_active_decode & (1 << layer)))
241 continue;
242
246 // nb_output counts AUs with an output-pending frame
247 // in at least one layer
248 if (!(
frame->base_layer_frame >= 0 &&
250 nb_output++;
251 if (min_layer < 0 || frame->poc < min_poc) {
252 min_poc =
frame->poc;
254 min_layer = layer;
255 }
256 }
257 nb_dpb[layer] += !!
frame->flags;
258 }
259 }
260
261 if (nb_output > max_output ||
262 (nb_output &&
263 (nb_dpb[0] > max_dpb || nb_dpb[1] > max_dpb))) {
266 int output = !discard && (layers_active_output & (1 << min_layer));
267
269 f->pkt_dts =
s->pkt_dts;
271 }
275
277 output ?
"Output" :
"Discarded", min_layer,
frame->poc);
278 continue;
279 }
280 return 0;
281 }
282 }
283
285 {
287 int ctb_count =
frame->ctb_count;
288 int ctb_addr_ts =
s->pps->ctb_addr_rs_to_ts[
s->sh.slice_segment_addr];
290
291 if (
s->slice_idx >=
frame->nb_rpl_elems)
293
294 for (
i = ctb_addr_ts;
i < ctb_count;
i++)
296
298
299 return 0;
300 }
301
303 {
305
307 uint8_t list_idx;
309
313
317 !
s->pps->pps_curr_pic_ref_enabled_flag) {
320 }
321
322 for (list_idx = 0; list_idx < nb_list; list_idx++) {
324 RefPicList *rpl = &
s->cur_frame->refPicList[list_idx];
325
326 /* The order of the elements is
327 * ST_CURR_BEF - INTER_LAYER0 - ST_CURR_AFT - LT_CURR - INTER_LAYER1 for the L0 and
328 * ST_CURR_AFT - INTER_LAYER1 - ST_CURR_BEF - LT_CURR - INTER_LAYER0 for the L1 */
334 };
335
336 /* concatenate the candidate lists for the current frame */
343 // multiview inter-layer refs are treated as long-term here,
344 // cf. G.8.1.3
349 }
350 }
351 // Construct RefPicList0, RefPicList1 (8-8, 8-10)
357 }
358 }
359
360 /* reorder the references if necessary */
364
368 }
369
371 rpl->
ref[
i] = rpl_tmp.
ref[idx];
374 }
375 } else {
376 memcpy(rpl, &rpl_tmp, sizeof(*rpl));
378 }
379
380 // 8-9
381 if (
s->pps->pps_curr_pic_ref_enabled_flag &&
386 }
387
391 }
392
393 return 0;
394 }
395
397 int poc, uint8_t use_msb)
398 {
401
405 if ((
ref->poc &
mask) == poc && (use_msb ||
ref->poc !=
s->poc))
407 }
408 }
409
412 "Could not find ref with POC %d\n", poc);
414 }
415
417 {
420 }
421
423 {
426
430
431 if (!
s->avctx->hwaccel) {
436 } else {
442 }
443 }
444 }
445
448
451
453 }
454
455 /* add a reference with the given poc to the list and mark it as used in DPB */
458 int poc, int ref_flag, uint8_t use_msb)
459 {
461
464
469 }
470
474
476 return 0;
477 }
478
480 {
485
487
488 /* clear the reference flags on all frames except the current one */
491
492 if (
frame ==
s->cur_frame)
493 continue;
494
496 }
497
500
501 if (!short_rps)
502 goto inter_layer;
503
504 /* add the short refs */
508
509 if (!(short_rps->
used & (1 <<
i)))
511 else if (i < short_rps->num_negative_pics)
513 else
515
520 }
521
522 /* add the long refs */
524 int poc = long_rps->
poc[
i];
526
531 }
532
533 inter_layer:
534 /* add inter-layer refs */
535 if (
s->sh.inter_layer_pred) {
537
539
540 /* Given the assumption of at most two layers, refPicSet0Flag is
541 * always 1, so only RefPicSetInterLayer0 can ever contain a frame. */
543 // inter-layer refs are treated as short-term here, cf. F.8.1.6
548 }
549 }
550
552 /* release any frames that are now unused */
555
557 }
558
560 unsigned layer_idx)
561 {
566
567 if (rps) {
572 }
573
574 if (long_rps) {
577 }
578
580 av_assert0(
pps->sps->vps->num_direct_ref_layers[layer_idx] < 2);
582 }
583
584 if (
pps->pps_curr_pic_ref_enabled_flag)
586
588 }