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
25
30
32 {
33 /* frame->frame can be NULL if context init failed */
35 return;
36
42
45
50
52
55 }
56 }
57
60 {
61 int x_cb = x0 >>
s->ps.sps->log2_ctb_size;
62 int y_cb = y0 >>
s->ps.sps->log2_ctb_size;
63 int pic_width_cb =
s->ps.sps->ctb_width;
64 int ctb_addr_ts =
s->ps.pps->ctb_addr_rs_to_ts[y_cb * pic_width_cb + x_cb];
65 return &
ref->rpl_tab[ctb_addr_ts]->refPicList[0];
66 }
67
69 {
75 }
76
78 {
82 }
83
85 {
89 if (
frame->frame->buf[0])
90 continue;
91
96
100
102 if (!
frame->tab_mvf_buf)
105
107 if (!
frame->rpl_tab_buf)
110 frame->ctb_count =
s->ps.sps->ctb_width *
s->ps.sps->ctb_height;
111 for (j = 0; j <
frame->ctb_count; j++)
113
116
117 if (
s->avctx->hwaccel) {
122 if (!
frame->hwaccel_priv_buf)
124 frame->hwaccel_picture_private =
frame->hwaccel_priv_buf->data;
125 }
126 }
127
132 }
135 }
136
138 {
141
142 /* check that this POC doesn't already exist */
145
146 if (
frame->frame->buf[0] &&
frame->sequence ==
s->seq_decode &&
149 poc);
151 }
152 }
153
157
160
161 if (
s->sh.pic_output_flag)
163 else
165
167 ref->sequence =
s->seq_decode;
168 ref->frame->crop_left =
s->ps.sps->output_window.left_offset;
169 ref->frame->crop_right =
s->ps.sps->output_window.right_offset;
170 ref->frame->crop_top =
s->ps.sps->output_window.top_offset;
171 ref->frame->crop_bottom =
s->ps.sps->output_window.bottom_offset;
172
173 return 0;
174 }
175
177 {
182 }
183 }
184 }
185
187 {
188 if (
IS_IRAP(
s) &&
s->no_rasl_output_flag == 1) {
193 frame->sequence !=
s->seq_decode) {
194 if (
s->sh.no_output_of_prior_pics_flag == 1)
196 else
198 }
199 }
200 }
201 do {
202 int nb_output = 0;
203 int min_poc = INT_MAX;
205
209 frame->sequence ==
s->seq_output) {
210 nb_output++;
211 if (
frame->poc < min_poc || nb_output == 1) {
212 min_poc =
frame->poc;
214 }
215 }
216 }
217
218 /* wait for more frames before output */
219 if (!
flush &&
s->seq_output ==
s->seq_decode &&
s->ps.sps &&
220 nb_output <= s->ps.sps->temporal_layer[
s->ps.sps->max_sub_layers - 1].num_reorder_pics)
221 return 0;
222
223 if (nb_output) {
225
229 else
233
236
239
241 "Output frame with POC %d.\n",
frame->poc);
242 return 1;
243 }
244
245 if (
s->seq_output !=
s->seq_decode)
247 else
248 break;
249 } while (1);
250
251 return 0;
252 }
253
255 {
256 int dpb = 0;
257 int min_poc = INT_MAX;
259
262 if ((
frame->flags) &&
263 frame->sequence ==
s->seq_output &&
265 dpb++;
266 }
267 }
268
269 if (
s->ps.sps && dpb >=
s->ps.sps->temporal_layer[
s->ps.sps->max_sub_layers - 1].max_dec_pic_buffering) {
272 if ((
frame->flags) &&
273 frame->sequence ==
s->seq_output &&
276 min_poc =
frame->poc;
277 }
278 }
279 }
280
284 frame->sequence ==
s->seq_output &&
285 frame->poc <= min_poc) {
287 }
288 }
289
290 dpb--;
291 }
292 }
293
295 {
297 int ctb_count =
frame->ctb_count;
298 int ctb_addr_ts =
s->ps.pps->ctb_addr_rs_to_ts[
s->sh.slice_segment_addr];
300
303
304 for (
i = ctb_addr_ts;
i < ctb_count;
i++)
306
308
309 return 0;
310 }
311
313 {
315
317 uint8_t list_idx;
319
323
328 }
329
330 for (list_idx = 0; list_idx < nb_list; list_idx++) {
333
334 /* The order of the elements is
335 * ST_CURR_BEF - ST_CURR_AFT - LT_CURR for the L0 and
336 * ST_CURR_AFT - ST_CURR_BEF - LT_CURR for the L1 */
340
341 /* concatenate the candidate lists for the current frame */
350 }
351 }
352 }
353
354 /* reorder the references if necessary */
358
362 }
363
365 rpl->
ref[
i] = rpl_tmp.
ref[idx];
368 }
369 } else {
370 memcpy(rpl, &rpl_tmp, sizeof(*rpl));
372 }
373
377 }
378
379 return 0;
380 }
381
383 {
384 int mask = use_msb ? ~0 : (1 <<
s->ps.sps->log2_max_poc_lsb) - 1;
386
389 if (
ref->frame->buf[0] &&
ref->sequence ==
s->seq_decode) {
390 if ((
ref->poc &
mask) == poc && (use_msb ||
ref->poc !=
s->poc))
392 }
393 }
394
397 "Could not find ref with POC %d\n", poc);
399 }
400
402 {
405 }
406
408 {
411
415
416 if (!
s->avctx->hwaccel) {
417 if (!
s->ps.sps->pixel_shift) {
418 for (
i = 0;
frame->frame->data[
i];
i++)
419 memset(
frame->frame->data[
i], 1 << (
s->ps.sps->bit_depth - 1),
421 } else {
422 for (
i = 0;
frame->frame->data[
i];
i++)
423 for (y = 0; y < (
s->ps.sps->height >>
s->ps.sps->vshift[
i]); y++) {
424 uint8_t *dst =
frame->frame->data[
i] + y *
frame->frame->linesize[
i];
425 AV_WN16(dst, 1 << (
s->ps.sps->bit_depth - 1));
427 }
428 }
429 }
430
434
437
439 }
440
441 /* add a reference with the given poc to the list and mark it as used in DPB */
443 int poc, int ref_flag, uint8_t use_msb)
444 {
446
449
454 }
455
459
461 return 0;
462 }
463
465 {
470
471 if (!short_rps) {
473 return 0;
474 }
475
477
478 /* clear the reference flags on all frames except the current one */
481
483 continue;
484
486 }
487
490
491 /* add the short refs */
495
496 if (!short_rps->
used[
i])
498 else if (i < short_rps->num_negative_pics)
500 else
502
506 }
507
508 /* add the long refs */
510 int poc = long_rps->
poc[
i];
512
516 }
517
519 /* release any frames that are now unused */
522
524 }
525
527 {
532
533 if (rps) {
538 }
539
540 if (long_rps) {
543 }
545 }