Libav
hevc.c
Go to the documentation of this file.
1 /*
2  * HEVC video decoder
3  *
4  * Copyright (C) 2012 - 2013 Guillaume Martres
5  * Copyright (C) 2012 - 2013 Mickael Raulet
6  * Copyright (C) 2012 - 2013 Gildas Cocherel
7  * Copyright (C) 2012 - 2013 Wassim Hamidouche
8  *
9  * This file is part of Libav.
10  *
11  * Libav is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * Libav is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with Libav; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24  */
25 
26 #include "libavutil/attributes.h"
27 #include "libavutil/common.h"
28 #include "libavutil/display.h"
29 #include "libavutil/internal.h"
30 #include "libavutil/md5.h"
31 #include "libavutil/opt.h"
32 #include "libavutil/pixdesc.h"
33 #include "libavutil/stereo3d.h"
34 
35 #include "bswapdsp.h"
36 #include "bytestream.h"
37 #include "cabac_functions.h"
38 #include "golomb.h"
39 #include "hevc.h"
40 
41 const uint8_t ff_hevc_qpel_extra_before[4] = { 0, 3, 3, 2 };
42 const uint8_t ff_hevc_qpel_extra_after[4] = { 0, 3, 4, 4 };
43 const uint8_t ff_hevc_qpel_extra[4] = { 0, 6, 7, 6 };
44 
45 static const uint8_t scan_1x1[1] = { 0 };
46 
47 static const uint8_t horiz_scan2x2_x[4] = { 0, 1, 0, 1 };
48 
49 static const uint8_t horiz_scan2x2_y[4] = { 0, 0, 1, 1 };
50 
51 static const uint8_t horiz_scan4x4_x[16] = {
52  0, 1, 2, 3,
53  0, 1, 2, 3,
54  0, 1, 2, 3,
55  0, 1, 2, 3,
56 };
57 
58 static const uint8_t horiz_scan4x4_y[16] = {
59  0, 0, 0, 0,
60  1, 1, 1, 1,
61  2, 2, 2, 2,
62  3, 3, 3, 3,
63 };
64 
65 static const uint8_t horiz_scan8x8_inv[8][8] = {
66  { 0, 1, 2, 3, 16, 17, 18, 19, },
67  { 4, 5, 6, 7, 20, 21, 22, 23, },
68  { 8, 9, 10, 11, 24, 25, 26, 27, },
69  { 12, 13, 14, 15, 28, 29, 30, 31, },
70  { 32, 33, 34, 35, 48, 49, 50, 51, },
71  { 36, 37, 38, 39, 52, 53, 54, 55, },
72  { 40, 41, 42, 43, 56, 57, 58, 59, },
73  { 44, 45, 46, 47, 60, 61, 62, 63, },
74 };
75 
76 static const uint8_t diag_scan2x2_x[4] = { 0, 0, 1, 1 };
77 
78 static const uint8_t diag_scan2x2_y[4] = { 0, 1, 0, 1 };
79 
80 static const uint8_t diag_scan2x2_inv[2][2] = {
81  { 0, 2, },
82  { 1, 3, },
83 };
84 
86  0, 0, 1, 0,
87  1, 2, 0, 1,
88  2, 3, 1, 2,
89  3, 2, 3, 3,
90 };
91 
93  0, 1, 0, 2,
94  1, 0, 3, 2,
95  1, 0, 3, 2,
96  1, 3, 2, 3,
97 };
98 
99 static const uint8_t diag_scan4x4_inv[4][4] = {
100  { 0, 2, 5, 9, },
101  { 1, 4, 8, 12, },
102  { 3, 7, 11, 14, },
103  { 6, 10, 13, 15, },
104 };
105 
107  0, 0, 1, 0,
108  1, 2, 0, 1,
109  2, 3, 0, 1,
110  2, 3, 4, 0,
111  1, 2, 3, 4,
112  5, 0, 1, 2,
113  3, 4, 5, 6,
114  0, 1, 2, 3,
115  4, 5, 6, 7,
116  1, 2, 3, 4,
117  5, 6, 7, 2,
118  3, 4, 5, 6,
119  7, 3, 4, 5,
120  6, 7, 4, 5,
121  6, 7, 5, 6,
122  7, 6, 7, 7,
123 };
124 
126  0, 1, 0, 2,
127  1, 0, 3, 2,
128  1, 0, 4, 3,
129  2, 1, 0, 5,
130  4, 3, 2, 1,
131  0, 6, 5, 4,
132  3, 2, 1, 0,
133  7, 6, 5, 4,
134  3, 2, 1, 0,
135  7, 6, 5, 4,
136  3, 2, 1, 7,
137  6, 5, 4, 3,
138  2, 7, 6, 5,
139  4, 3, 7, 6,
140  5, 4, 7, 6,
141  5, 7, 6, 7,
142 };
143 
144 static const uint8_t diag_scan8x8_inv[8][8] = {
145  { 0, 2, 5, 9, 14, 20, 27, 35, },
146  { 1, 4, 8, 13, 19, 26, 34, 42, },
147  { 3, 7, 12, 18, 25, 33, 41, 48, },
148  { 6, 11, 17, 24, 32, 40, 47, 53, },
149  { 10, 16, 23, 31, 39, 46, 52, 57, },
150  { 15, 22, 30, 38, 45, 51, 56, 60, },
151  { 21, 29, 37, 44, 50, 55, 59, 62, },
152  { 28, 36, 43, 49, 54, 58, 61, 63, },
153 };
154 
164 /* free everything allocated by pic_arrays_init() */
166 {
167  av_freep(&s->sao);
168  av_freep(&s->deblock);
169 
170  av_freep(&s->skip_flag);
171  av_freep(&s->tab_ct_depth);
172 
173  av_freep(&s->tab_ipm);
174  av_freep(&s->cbf_luma);
175  av_freep(&s->is_pcm);
176 
177  av_freep(&s->qp_y_tab);
180 
181  av_freep(&s->horizontal_bs);
182  av_freep(&s->vertical_bs);
183 
186 }
187 
188 /* allocate arrays that depend on frame dimensions */
189 static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)
190 {
191  int log2_min_cb_size = sps->log2_min_cb_size;
192  int width = sps->width;
193  int height = sps->height;
194  int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
195  ((height >> log2_min_cb_size) + 1);
196  int ctb_count = sps->ctb_width * sps->ctb_height;
197  int min_pu_size = sps->min_pu_width * sps->min_pu_height;
198 
199  s->bs_width = width >> 3;
200  s->bs_height = height >> 3;
201 
202  s->sao = av_mallocz_array(ctb_count, sizeof(*s->sao));
203  s->deblock = av_mallocz_array(ctb_count, sizeof(*s->deblock));
204  if (!s->sao || !s->deblock)
205  goto fail;
206 
207  s->skip_flag = av_malloc(pic_size_in_ctb);
209  if (!s->skip_flag || !s->tab_ct_depth)
210  goto fail;
211 
212  s->cbf_luma = av_malloc(sps->min_tb_width * sps->min_tb_height);
213  s->tab_ipm = av_mallocz(min_pu_size);
214  s->is_pcm = av_malloc(min_pu_size);
215  if (!s->tab_ipm || !s->cbf_luma || !s->is_pcm)
216  goto fail;
217 
218  s->filter_slice_edges = av_malloc(ctb_count);
219  s->tab_slice_address = av_malloc(pic_size_in_ctb *
220  sizeof(*s->tab_slice_address));
221  s->qp_y_tab = av_malloc(pic_size_in_ctb *
222  sizeof(*s->qp_y_tab));
223  if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address)
224  goto fail;
225 
226  s->horizontal_bs = av_mallocz(2 * s->bs_width * (s->bs_height + 1));
227  s->vertical_bs = av_mallocz(2 * s->bs_width * (s->bs_height + 1));
228  if (!s->horizontal_bs || !s->vertical_bs)
229  goto fail;
230 
231  s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField),
233  s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab),
235  if (!s->tab_mvf_pool || !s->rpl_tab_pool)
236  goto fail;
237 
238  return 0;
239 
240 fail:
241  pic_arrays_free(s);
242  return AVERROR(ENOMEM);
243 }
244 
246 {
247  int i = 0;
248  int j = 0;
249  uint8_t luma_weight_l0_flag[16];
250  uint8_t chroma_weight_l0_flag[16];
251  uint8_t luma_weight_l1_flag[16];
252  uint8_t chroma_weight_l1_flag[16];
253 
255  if (s->sps->chroma_format_idc != 0) {
256  int delta = get_se_golomb(gb);
258  }
259 
260  for (i = 0; i < s->sh.nb_refs[L0]; i++) {
261  luma_weight_l0_flag[i] = get_bits1(gb);
262  if (!luma_weight_l0_flag[i]) {
263  s->sh.luma_weight_l0[i] = 1 << s->sh.luma_log2_weight_denom;
264  s->sh.luma_offset_l0[i] = 0;
265  }
266  }
267  if (s->sps->chroma_format_idc != 0) { // FIXME: invert "if" and "for"
268  for (i = 0; i < s->sh.nb_refs[L0]; i++)
269  chroma_weight_l0_flag[i] = get_bits1(gb);
270  } else {
271  for (i = 0; i < s->sh.nb_refs[L0]; i++)
272  chroma_weight_l0_flag[i] = 0;
273  }
274  for (i = 0; i < s->sh.nb_refs[L0]; i++) {
275  if (luma_weight_l0_flag[i]) {
276  int delta_luma_weight_l0 = get_se_golomb(gb);
277  s->sh.luma_weight_l0[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l0;
278  s->sh.luma_offset_l0[i] = get_se_golomb(gb);
279  }
280  if (chroma_weight_l0_flag[i]) {
281  for (j = 0; j < 2; j++) {
282  int delta_chroma_weight_l0 = get_se_golomb(gb);
283  int delta_chroma_offset_l0 = get_se_golomb(gb);
284  s->sh.chroma_weight_l0[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0;
285  s->sh.chroma_offset_l0[i][j] = av_clip_c((delta_chroma_offset_l0 - ((128 * s->sh.chroma_weight_l0[i][j])
286  >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
287  }
288  } else {
289  s->sh.chroma_weight_l0[i][0] = 1 << s->sh.chroma_log2_weight_denom;
290  s->sh.chroma_offset_l0[i][0] = 0;
291  s->sh.chroma_weight_l0[i][1] = 1 << s->sh.chroma_log2_weight_denom;
292  s->sh.chroma_offset_l0[i][1] = 0;
293  }
294  }
295  if (s->sh.slice_type == B_SLICE) {
296  for (i = 0; i < s->sh.nb_refs[L1]; i++) {
297  luma_weight_l1_flag[i] = get_bits1(gb);
298  if (!luma_weight_l1_flag[i]) {
299  s->sh.luma_weight_l1[i] = 1 << s->sh.luma_log2_weight_denom;
300  s->sh.luma_offset_l1[i] = 0;
301  }
302  }
303  if (s->sps->chroma_format_idc != 0) {
304  for (i = 0; i < s->sh.nb_refs[L1]; i++)
305  chroma_weight_l1_flag[i] = get_bits1(gb);
306  } else {
307  for (i = 0; i < s->sh.nb_refs[L1]; i++)
308  chroma_weight_l1_flag[i] = 0;
309  }
310  for (i = 0; i < s->sh.nb_refs[L1]; i++) {
311  if (luma_weight_l1_flag[i]) {
312  int delta_luma_weight_l1 = get_se_golomb(gb);
313  s->sh.luma_weight_l1[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l1;
314  s->sh.luma_offset_l1[i] = get_se_golomb(gb);
315  }
316  if (chroma_weight_l1_flag[i]) {
317  for (j = 0; j < 2; j++) {
318  int delta_chroma_weight_l1 = get_se_golomb(gb);
319  int delta_chroma_offset_l1 = get_se_golomb(gb);
320  s->sh.chroma_weight_l1[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l1;
321  s->sh.chroma_offset_l1[i][j] = av_clip_c((delta_chroma_offset_l1 - ((128 * s->sh.chroma_weight_l1[i][j])
322  >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
323  }
324  } else {
325  s->sh.chroma_weight_l1[i][0] = 1 << s->sh.chroma_log2_weight_denom;
326  s->sh.chroma_offset_l1[i][0] = 0;
327  s->sh.chroma_weight_l1[i][1] = 1 << s->sh.chroma_log2_weight_denom;
328  s->sh.chroma_offset_l1[i][1] = 0;
329  }
330  }
331  }
332 }
333 
335 {
336  const HEVCSPS *sps = s->sps;
337  int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
338  int prev_delta_msb = 0;
339  unsigned int nb_sps = 0, nb_sh;
340  int i;
341 
342  rps->nb_refs = 0;
344  return 0;
345 
346  if (sps->num_long_term_ref_pics_sps > 0)
347  nb_sps = get_ue_golomb_long(gb);
348  nb_sh = get_ue_golomb_long(gb);
349 
350  if (nb_sh + nb_sps > FF_ARRAY_ELEMS(rps->poc))
351  return AVERROR_INVALIDDATA;
352 
353  rps->nb_refs = nb_sh + nb_sps;
354 
355  for (i = 0; i < rps->nb_refs; i++) {
356  uint8_t delta_poc_msb_present;
357 
358  if (i < nb_sps) {
359  uint8_t lt_idx_sps = 0;
360 
361  if (sps->num_long_term_ref_pics_sps > 1)
362  lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps));
363 
364  rps->poc[i] = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
365  rps->used[i] = sps->used_by_curr_pic_lt_sps_flag[lt_idx_sps];
366  } else {
367  rps->poc[i] = get_bits(gb, sps->log2_max_poc_lsb);
368  rps->used[i] = get_bits1(gb);
369  }
370 
371  delta_poc_msb_present = get_bits1(gb);
372  if (delta_poc_msb_present) {
373  int delta = get_ue_golomb_long(gb);
374 
375  if (i && i != nb_sps)
376  delta += prev_delta_msb;
377 
378  rps->poc[i] += s->poc - delta * max_poc_lsb - s->sh.pic_order_cnt_lsb;
379  prev_delta_msb = delta;
380  }
381  }
382 
383  return 0;
384 }
385 
386 static int set_sps(HEVCContext *s, const HEVCSPS *sps)
387 {
388  int ret;
389  unsigned int num = 0, den = 0;
390 
391  pic_arrays_free(s);
392  ret = pic_arrays_init(s, sps);
393  if (ret < 0)
394  goto fail;
395 
396  s->avctx->coded_width = sps->width;
397  s->avctx->coded_height = sps->height;
398  s->avctx->width = sps->output_width;
399  s->avctx->height = sps->output_height;
400  s->avctx->pix_fmt = sps->pix_fmt;
402 
403  ff_set_sar(s->avctx, sps->vui.sar);
404 
408  else
410 
414  s->avctx->colorspace = sps->vui.matrix_coeffs;
415  } else {
419  }
420 
421  ff_hevc_pred_init(&s->hpc, sps->bit_depth);
422  ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
423  ff_videodsp_init (&s->vdsp, sps->bit_depth);
424 
425  if (sps->sao_enabled) {
428  if (ret < 0)
429  goto fail;
430  s->frame = s->tmp_frame;
431  }
432 
433  s->sps = sps;
434  s->vps = (HEVCVPS*) s->vps_list[s->sps->vps_id]->data;
435 
437  num = s->vps->vps_num_units_in_tick;
438  den = s->vps->vps_time_scale;
439  } else if (sps->vui.vui_timing_info_present_flag) {
440  num = sps->vui.vui_num_units_in_tick;
441  den = sps->vui.vui_time_scale;
442  }
443 
444  if (num != 0 && den != 0)
446  num, den, 1 << 30);
447 
448  return 0;
449 
450 fail:
451  pic_arrays_free(s);
452  s->sps = NULL;
453  return ret;
454 }
455 
457 {
458  GetBitContext *gb = &s->HEVClc.gb;
459  SliceHeader *sh = &s->sh;
460  int i, ret;
461 
462  // Coded parameters
464  if (s->ref && sh->first_slice_in_pic_flag) {
465  av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
466  return 1; // This slice will be skiped later, do not corrupt state
467  }
468 
469  if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) {
470  s->seq_decode = (s->seq_decode + 1) & 0xff;
471  s->max_ra = INT_MAX;
472  if (IS_IDR(s))
474  }
475  if (IS_IRAP(s))
477 
478  sh->pps_id = get_ue_golomb_long(gb);
479  if (sh->pps_id >= MAX_PPS_COUNT || !s->pps_list[sh->pps_id]) {
480  av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", sh->pps_id);
481  return AVERROR_INVALIDDATA;
482  }
483  if (!sh->first_slice_in_pic_flag &&
484  s->pps != (HEVCPPS*)s->pps_list[sh->pps_id]->data) {
485  av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
486  return AVERROR_INVALIDDATA;
487  }
488  s->pps = (HEVCPPS*)s->pps_list[sh->pps_id]->data;
489 
490  if (s->sps != (HEVCSPS*)s->sps_list[s->pps->sps_id]->data) {
491  s->sps = (HEVCSPS*)s->sps_list[s->pps->sps_id]->data;
492 
494  ret = set_sps(s, s->sps);
495  if (ret < 0)
496  return ret;
497 
498  s->seq_decode = (s->seq_decode + 1) & 0xff;
499  s->max_ra = INT_MAX;
500  }
501 
504 
506  if (!sh->first_slice_in_pic_flag) {
507  int slice_address_length;
508 
511 
512  slice_address_length = av_ceil_log2(s->sps->ctb_width *
513  s->sps->ctb_height);
514  sh->slice_segment_addr = get_bits(gb, slice_address_length);
515  if (sh->slice_segment_addr >= s->sps->ctb_width * s->sps->ctb_height) {
517  "Invalid slice segment address: %u.\n",
518  sh->slice_segment_addr);
519  return AVERROR_INVALIDDATA;
520  }
521 
522  if (!sh->dependent_slice_segment_flag) {
523  sh->slice_addr = sh->slice_segment_addr;
524  s->slice_idx++;
525  }
526  } else {
527  sh->slice_segment_addr = sh->slice_addr = 0;
528  s->slice_idx = 0;
529  s->slice_initialized = 0;
530  }
531 
532  if (!sh->dependent_slice_segment_flag) {
533  s->slice_initialized = 0;
534 
535  for (i = 0; i < s->pps->num_extra_slice_header_bits; i++)
536  skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
537 
538  sh->slice_type = get_ue_golomb_long(gb);
539  if (!(sh->slice_type == I_SLICE ||
540  sh->slice_type == P_SLICE ||
541  sh->slice_type == B_SLICE)) {
542  av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n",
543  sh->slice_type);
544  return AVERROR_INVALIDDATA;
545  }
546  if (IS_IRAP(s) && sh->slice_type != I_SLICE) {
547  av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
548  return AVERROR_INVALIDDATA;
549  }
550 
551  // when flag is not present, picture is inferred to be output
552  sh->pic_output_flag = 1;
554  sh->pic_output_flag = get_bits1(gb);
555 
557  sh->colour_plane_id = get_bits(gb, 2);
558 
559  if (!IS_IDR(s)) {
560  int short_term_ref_pic_set_sps_flag, poc;
561 
564  if (!sh->first_slice_in_pic_flag && poc != s->poc) {
566  "Ignoring POC change between slices: %d -> %d\n", s->poc, poc);
568  return AVERROR_INVALIDDATA;
569  poc = s->poc;
570  }
571  s->poc = poc;
572 
573  short_term_ref_pic_set_sps_flag = get_bits1(gb);
574  if (!short_term_ref_pic_set_sps_flag) {
575  ret = ff_hevc_decode_short_term_rps(s, &sh->slice_rps, s->sps, 1);
576  if (ret < 0)
577  return ret;
578 
579  sh->short_term_rps = &sh->slice_rps;
580  } else {
581  int numbits, rps_idx;
582 
583  if (!s->sps->nb_st_rps) {
584  av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n");
585  return AVERROR_INVALIDDATA;
586  }
587 
588  numbits = av_ceil_log2(s->sps->nb_st_rps);
589  rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0;
590  sh->short_term_rps = &s->sps->st_rps[rps_idx];
591  }
592 
593  ret = decode_lt_rps(s, &sh->long_term_rps, gb);
594  if (ret < 0) {
595  av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
597  return AVERROR_INVALIDDATA;
598  }
599 
602  else
604  } else {
605  s->sh.short_term_rps = NULL;
606  s->poc = 0;
607  }
608 
609  /* 8.3.1 */
610  if (s->temporal_id == 0 &&
611  s->nal_unit_type != NAL_TRAIL_N &&
612  s->nal_unit_type != NAL_TSA_N &&
613  s->nal_unit_type != NAL_STSA_N &&
614  s->nal_unit_type != NAL_RADL_N &&
615  s->nal_unit_type != NAL_RADL_R &&
616  s->nal_unit_type != NAL_RASL_N &&
618  s->pocTid0 = s->poc;
619 
620  if (s->sps->sao_enabled) {
624  } else {
628  }
629 
630  sh->nb_refs[L0] = sh->nb_refs[L1] = 0;
631  if (sh->slice_type == P_SLICE || sh->slice_type == B_SLICE) {
632  int nb_refs;
633 
635  if (sh->slice_type == B_SLICE)
637 
638  if (get_bits1(gb)) { // num_ref_idx_active_override_flag
639  sh->nb_refs[L0] = get_ue_golomb_long(gb) + 1;
640  if (sh->slice_type == B_SLICE)
641  sh->nb_refs[L1] = get_ue_golomb_long(gb) + 1;
642  }
643  if (sh->nb_refs[L0] > MAX_REFS || sh->nb_refs[L1] > MAX_REFS) {
644  av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n",
645  sh->nb_refs[L0], sh->nb_refs[L1]);
646  return AVERROR_INVALIDDATA;
647  }
648 
649  sh->rpl_modification_flag[0] = 0;
650  sh->rpl_modification_flag[1] = 0;
651  nb_refs = ff_hevc_frame_nb_refs(s);
652  if (!nb_refs) {
653  av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n");
654  return AVERROR_INVALIDDATA;
655  }
656 
657  if (s->pps->lists_modification_present_flag && nb_refs > 1) {
658  sh->rpl_modification_flag[0] = get_bits1(gb);
659  if (sh->rpl_modification_flag[0]) {
660  for (i = 0; i < sh->nb_refs[L0]; i++)
661  sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs));
662  }
663 
664  if (sh->slice_type == B_SLICE) {
665  sh->rpl_modification_flag[1] = get_bits1(gb);
666  if (sh->rpl_modification_flag[1] == 1)
667  for (i = 0; i < sh->nb_refs[L1]; i++)
668  sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs));
669  }
670  }
671 
672  if (sh->slice_type == B_SLICE)
673  sh->mvd_l1_zero_flag = get_bits1(gb);
674 
676  sh->cabac_init_flag = get_bits1(gb);
677  else
678  sh->cabac_init_flag = 0;
679 
680  sh->collocated_ref_idx = 0;
682  sh->collocated_list = L0;
683  if (sh->slice_type == B_SLICE)
684  sh->collocated_list = !get_bits1(gb);
685 
686  if (sh->nb_refs[sh->collocated_list] > 1) {
688  if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) {
690  "Invalid collocated_ref_idx: %d.\n",
691  sh->collocated_ref_idx);
692  return AVERROR_INVALIDDATA;
693  }
694  }
695  }
696 
697  if ((s->pps->weighted_pred_flag && sh->slice_type == P_SLICE) ||
698  (s->pps->weighted_bipred_flag && sh->slice_type == B_SLICE)) {
699  pred_weight_table(s, gb);
700  }
701 
703  if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) {
705  "Invalid number of merging MVP candidates: %d.\n",
706  sh->max_num_merge_cand);
707  return AVERROR_INVALIDDATA;
708  }
709  }
710 
711  sh->slice_qp_delta = get_se_golomb(gb);
712 
716  } else {
717  sh->slice_cb_qp_offset = 0;
718  sh->slice_cr_qp_offset = 0;
719  }
720 
722  int deblocking_filter_override_flag = 0;
723 
725  deblocking_filter_override_flag = get_bits1(gb);
726 
727  if (deblocking_filter_override_flag) {
730  sh->beta_offset = get_se_golomb(gb) * 2;
731  sh->tc_offset = get_se_golomb(gb) * 2;
732  }
733  } else {
735  sh->beta_offset = s->pps->beta_offset;
736  sh->tc_offset = s->pps->tc_offset;
737  }
738  } else {
740  sh->beta_offset = 0;
741  sh->tc_offset = 0;
742  }
743 
749  } else {
751  }
752  } else if (!s->slice_initialized) {
753  av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n");
754  return AVERROR_INVALIDDATA;
755  }
756 
757  sh->num_entry_point_offsets = 0;
760  if (sh->num_entry_point_offsets > 0) {
761  int offset_len = get_ue_golomb_long(gb) + 1;
762 
763  for (i = 0; i < sh->num_entry_point_offsets; i++)
764  skip_bits(gb, offset_len);
765  }
766  }
767 
769  unsigned int length = get_ue_golomb_long(gb);
770  for (i = 0; i < length; i++)
771  skip_bits(gb, 8); // slice_header_extension_data_byte
772  }
773 
774  // Inferred parameters
775  sh->slice_qp = 26 + s->pps->pic_init_qp_minus26 + sh->slice_qp_delta;
776  if (sh->slice_qp > 51 ||
777  sh->slice_qp < -s->sps->qp_bd_offset) {
779  "The slice_qp %d is outside the valid range "
780  "[%d, 51].\n",
781  sh->slice_qp,
782  -s->sps->qp_bd_offset);
783  return AVERROR_INVALIDDATA;
784  }
785 
787 
789  av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n");
790  return AVERROR_INVALIDDATA;
791  }
792 
794 
795  if (!s->pps->cu_qp_delta_enabled_flag)
796  s->HEVClc.qp_y = FFUMOD(s->sh.slice_qp + 52 + 2 * s->sps->qp_bd_offset,
797  52 + s->sps->qp_bd_offset) - s->sps->qp_bd_offset;
798 
799  s->slice_initialized = 1;
800 
801  return 0;
802 }
803 
804 #define CTB(tab, x, y) ((tab)[(y) * s->sps->ctb_width + (x)])
805 
806 #define SET_SAO(elem, value) \
807 do { \
808  if (!sao_merge_up_flag && !sao_merge_left_flag) \
809  sao->elem = value; \
810  else if (sao_merge_left_flag) \
811  sao->elem = CTB(s->sao, rx-1, ry).elem; \
812  else if (sao_merge_up_flag) \
813  sao->elem = CTB(s->sao, rx, ry-1).elem; \
814  else \
815  sao->elem = 0; \
816 } while (0)
817 
818 static void hls_sao_param(HEVCContext *s, int rx, int ry)
819 {
820  HEVCLocalContext *lc = &s->HEVClc;
821  int sao_merge_left_flag = 0;
822  int sao_merge_up_flag = 0;
823  int shift = s->sps->bit_depth - FFMIN(s->sps->bit_depth, 10);
824  SAOParams *sao = &CTB(s->sao, rx, ry);
825  int c_idx, i;
826 
829  if (rx > 0) {
830  if (lc->ctb_left_flag)
831  sao_merge_left_flag = ff_hevc_sao_merge_flag_decode(s);
832  }
833  if (ry > 0 && !sao_merge_left_flag) {
834  if (lc->ctb_up_flag)
835  sao_merge_up_flag = ff_hevc_sao_merge_flag_decode(s);
836  }
837  }
838 
839  for (c_idx = 0; c_idx < 3; c_idx++) {
840  if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
841  sao->type_idx[c_idx] = SAO_NOT_APPLIED;
842  continue;
843  }
844 
845  if (c_idx == 2) {
846  sao->type_idx[2] = sao->type_idx[1];
847  sao->eo_class[2] = sao->eo_class[1];
848  } else {
849  SET_SAO(type_idx[c_idx], ff_hevc_sao_type_idx_decode(s));
850  }
851 
852  if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
853  continue;
854 
855  for (i = 0; i < 4; i++)
856  SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(s));
857 
858  if (sao->type_idx[c_idx] == SAO_BAND) {
859  for (i = 0; i < 4; i++) {
860  if (sao->offset_abs[c_idx][i]) {
861  SET_SAO(offset_sign[c_idx][i],
863  } else {
864  sao->offset_sign[c_idx][i] = 0;
865  }
866  }
867  SET_SAO(band_position[c_idx], ff_hevc_sao_band_position_decode(s));
868  } else if (c_idx != 2) {
869  SET_SAO(eo_class[c_idx], ff_hevc_sao_eo_class_decode(s));
870  }
871 
872  // Inferred parameters
873  sao->offset_val[c_idx][0] = 0;
874  for (i = 0; i < 4; i++) {
875  sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i] << shift;
876  if (sao->type_idx[c_idx] == SAO_EDGE) {
877  if (i > 1)
878  sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
879  } else if (sao->offset_sign[c_idx][i]) {
880  sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
881  }
882  }
883  }
884 }
885 
886 #undef SET_SAO
887 #undef CTB
888 
889 static void hls_residual_coding(HEVCContext *s, int x0, int y0,
890  int log2_trafo_size, enum ScanType scan_idx,
891  int c_idx)
892 {
893 #define GET_COORD(offset, n) \
894  do { \
895  x_c = (scan_x_cg[offset >> 4] << 2) + scan_x_off[n]; \
896  y_c = (scan_y_cg[offset >> 4] << 2) + scan_y_off[n]; \
897  } while (0)
898  HEVCLocalContext *lc = &s->HEVClc;
899  int transform_skip_flag = 0;
900 
901  int last_significant_coeff_x, last_significant_coeff_y;
902  int last_scan_pos;
903  int n_end;
904  int num_coeff = 0;
905  int greater1_ctx = 1;
906 
907  int num_last_subset;
908  int x_cg_last_sig, y_cg_last_sig;
909 
910  const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off;
911 
912  ptrdiff_t stride = s->frame->linesize[c_idx];
913  int hshift = s->sps->hshift[c_idx];
914  int vshift = s->sps->vshift[c_idx];
915  uint8_t *dst = &s->frame->data[c_idx][(y0 >> vshift) * stride +
916  ((x0 >> hshift) << s->sps->pixel_shift)];
917  DECLARE_ALIGNED(16, int16_t, coeffs[MAX_TB_SIZE * MAX_TB_SIZE]) = { 0 };
918  DECLARE_ALIGNED(8, uint8_t, significant_coeff_group_flag[8][8]) = { { 0 } };
919 
920  int trafo_size = 1 << log2_trafo_size;
921  int i, qp, shift, add, scale, scale_m;
922  const uint8_t level_scale[] = { 40, 45, 51, 57, 64, 72 };
923  const uint8_t *scale_matrix;
924  uint8_t dc_scale;
925 
926  // Derive QP for dequant
927  if (!lc->cu.cu_transquant_bypass_flag) {
928  static const int qp_c[] = {
929  29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37
930  };
931 
932  static const uint8_t rem6[51 + 2 * 6 + 1] = {
933  0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
934  3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
935  0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
936  };
937 
938  static const uint8_t div6[51 + 2 * 6 + 1] = {
939  0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
940  3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
941  7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
942  };
943  int qp_y = lc->qp_y;
944 
945  if (c_idx == 0) {
946  qp = qp_y + s->sps->qp_bd_offset;
947  } else {
948  int qp_i, offset;
949 
950  if (c_idx == 1)
951  offset = s->pps->cb_qp_offset + s->sh.slice_cb_qp_offset;
952  else
953  offset = s->pps->cr_qp_offset + s->sh.slice_cr_qp_offset;
954 
955  qp_i = av_clip_c(qp_y + offset, -s->sps->qp_bd_offset, 57);
956  if (qp_i < 30)
957  qp = qp_i;
958  else if (qp_i > 43)
959  qp = qp_i - 6;
960  else
961  qp = qp_c[qp_i - 30];
962 
963  qp += s->sps->qp_bd_offset;
964  }
965 
966  shift = s->sps->bit_depth + log2_trafo_size - 5;
967  add = 1 << (shift - 1);
968  scale = level_scale[rem6[qp]] << (div6[qp]);
969  scale_m = 16; // default when no custom scaling lists.
970  dc_scale = 16;
971 
972  if (s->sps->scaling_list_enable_flag) {
974  &s->pps->scaling_list : &s->sps->scaling_list;
975  int matrix_id = lc->cu.pred_mode != MODE_INTRA;
976 
977  if (log2_trafo_size != 5)
978  matrix_id = 3 * matrix_id + c_idx;
979 
980  scale_matrix = sl->sl[log2_trafo_size - 2][matrix_id];
981  if (log2_trafo_size >= 4)
982  dc_scale = sl->sl_dc[log2_trafo_size - 4][matrix_id];
983  }
984  }
985 
988  log2_trafo_size == 2) {
989  transform_skip_flag = ff_hevc_transform_skip_flag_decode(s, c_idx);
990  }
991 
992  last_significant_coeff_x =
993  ff_hevc_last_significant_coeff_x_prefix_decode(s, c_idx, log2_trafo_size);
994  last_significant_coeff_y =
995  ff_hevc_last_significant_coeff_y_prefix_decode(s, c_idx, log2_trafo_size);
996 
997  if (last_significant_coeff_x > 3) {
998  int suffix = ff_hevc_last_significant_coeff_suffix_decode(s, last_significant_coeff_x);
999  last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
1000  (2 + (last_significant_coeff_x & 1)) +
1001  suffix;
1002  }
1003 
1004  if (last_significant_coeff_y > 3) {
1005  int suffix = ff_hevc_last_significant_coeff_suffix_decode(s, last_significant_coeff_y);
1006  last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
1007  (2 + (last_significant_coeff_y & 1)) +
1008  suffix;
1009  }
1010 
1011  if (scan_idx == SCAN_VERT)
1012  FFSWAP(int, last_significant_coeff_x, last_significant_coeff_y);
1013 
1014  x_cg_last_sig = last_significant_coeff_x >> 2;
1015  y_cg_last_sig = last_significant_coeff_y >> 2;
1016 
1017  switch (scan_idx) {
1018  case SCAN_DIAG: {
1019  int last_x_c = last_significant_coeff_x & 3;
1020  int last_y_c = last_significant_coeff_y & 3;
1021 
1022  scan_x_off = ff_hevc_diag_scan4x4_x;
1023  scan_y_off = ff_hevc_diag_scan4x4_y;
1024  num_coeff = diag_scan4x4_inv[last_y_c][last_x_c];
1025  if (trafo_size == 4) {
1026  scan_x_cg = scan_1x1;
1027  scan_y_cg = scan_1x1;
1028  } else if (trafo_size == 8) {
1029  num_coeff += diag_scan2x2_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1030  scan_x_cg = diag_scan2x2_x;
1031  scan_y_cg = diag_scan2x2_y;
1032  } else if (trafo_size == 16) {
1033  num_coeff += diag_scan4x4_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1034  scan_x_cg = ff_hevc_diag_scan4x4_x;
1035  scan_y_cg = ff_hevc_diag_scan4x4_y;
1036  } else { // trafo_size == 32
1037  num_coeff += diag_scan8x8_inv[y_cg_last_sig][x_cg_last_sig] << 4;
1038  scan_x_cg = ff_hevc_diag_scan8x8_x;
1039  scan_y_cg = ff_hevc_diag_scan8x8_y;
1040  }
1041  break;
1042  }
1043  case SCAN_HORIZ:
1044  scan_x_cg = horiz_scan2x2_x;
1045  scan_y_cg = horiz_scan2x2_y;
1046  scan_x_off = horiz_scan4x4_x;
1047  scan_y_off = horiz_scan4x4_y;
1048  num_coeff = horiz_scan8x8_inv[last_significant_coeff_y][last_significant_coeff_x];
1049  break;
1050  default: //SCAN_VERT
1051  scan_x_cg = horiz_scan2x2_y;
1052  scan_y_cg = horiz_scan2x2_x;
1053  scan_x_off = horiz_scan4x4_y;
1054  scan_y_off = horiz_scan4x4_x;
1055  num_coeff = horiz_scan8x8_inv[last_significant_coeff_x][last_significant_coeff_y];
1056  break;
1057  }
1058  num_coeff++;
1059  num_last_subset = (num_coeff - 1) >> 4;
1060 
1061  for (i = num_last_subset; i >= 0; i--) {
1062  int n, m;
1063  int x_cg, y_cg, x_c, y_c;
1064  int implicit_non_zero_coeff = 0;
1065  int64_t trans_coeff_level;
1066  int prev_sig = 0;
1067  int offset = i << 4;
1068 
1069  uint8_t significant_coeff_flag_idx[16];
1070  uint8_t nb_significant_coeff_flag = 0;
1071 
1072  x_cg = scan_x_cg[i];
1073  y_cg = scan_y_cg[i];
1074 
1075  if (i < num_last_subset && i > 0) {
1076  int ctx_cg = 0;
1077  if (x_cg < (1 << (log2_trafo_size - 2)) - 1)
1078  ctx_cg += significant_coeff_group_flag[x_cg + 1][y_cg];
1079  if (y_cg < (1 << (log2_trafo_size - 2)) - 1)
1080  ctx_cg += significant_coeff_group_flag[x_cg][y_cg + 1];
1081 
1082  significant_coeff_group_flag[x_cg][y_cg] =
1084  implicit_non_zero_coeff = 1;
1085  } else {
1086  significant_coeff_group_flag[x_cg][y_cg] =
1087  ((x_cg == x_cg_last_sig && y_cg == y_cg_last_sig) ||
1088  (x_cg == 0 && y_cg == 0));
1089  }
1090 
1091  last_scan_pos = num_coeff - offset - 1;
1092 
1093  if (i == num_last_subset) {
1094  n_end = last_scan_pos - 1;
1095  significant_coeff_flag_idx[0] = last_scan_pos;
1096  nb_significant_coeff_flag = 1;
1097  } else {
1098  n_end = 15;
1099  }
1100 
1101  if (x_cg < ((1 << log2_trafo_size) - 1) >> 2)
1102  prev_sig = significant_coeff_group_flag[x_cg + 1][y_cg];
1103  if (y_cg < ((1 << log2_trafo_size) - 1) >> 2)
1104  prev_sig += significant_coeff_group_flag[x_cg][y_cg + 1] << 1;
1105 
1106  for (n = n_end; n >= 0; n--) {
1107  GET_COORD(offset, n);
1108 
1109  if (significant_coeff_group_flag[x_cg][y_cg] &&
1110  (n > 0 || implicit_non_zero_coeff == 0)) {
1111  if (ff_hevc_significant_coeff_flag_decode(s, c_idx, x_c, y_c,
1112  log2_trafo_size,
1113  scan_idx,
1114  prev_sig) == 1) {
1115  significant_coeff_flag_idx[nb_significant_coeff_flag] = n;
1116  nb_significant_coeff_flag++;
1117  implicit_non_zero_coeff = 0;
1118  }
1119  } else {
1120  int last_cg = (x_c == (x_cg << 2) && y_c == (y_cg << 2));
1121  if (last_cg && implicit_non_zero_coeff && significant_coeff_group_flag[x_cg][y_cg]) {
1122  significant_coeff_flag_idx[nb_significant_coeff_flag] = n;
1123  nb_significant_coeff_flag++;
1124  }
1125  }
1126  }
1127 
1128  n_end = nb_significant_coeff_flag;
1129 
1130  if (n_end) {
1131  int first_nz_pos_in_cg = 16;
1132  int last_nz_pos_in_cg = -1;
1133  int c_rice_param = 0;
1134  int first_greater1_coeff_idx = -1;
1135  uint8_t coeff_abs_level_greater1_flag[16] = { 0 };
1136  uint16_t coeff_sign_flag;
1137  int sum_abs = 0;
1138  int sign_hidden = 0;
1139 
1140  // initialize first elem of coeff_bas_level_greater1_flag
1141  int ctx_set = (i > 0 && c_idx == 0) ? 2 : 0;
1142 
1143  if (!(i == num_last_subset) && greater1_ctx == 0)
1144  ctx_set++;
1145  greater1_ctx = 1;
1146  last_nz_pos_in_cg = significant_coeff_flag_idx[0];
1147 
1148  for (m = 0; m < (n_end > 8 ? 8 : n_end); m++) {
1149  int n_idx = significant_coeff_flag_idx[m];
1150  int inc = (ctx_set << 2) + greater1_ctx;
1151  coeff_abs_level_greater1_flag[n_idx] =
1153  if (coeff_abs_level_greater1_flag[n_idx]) {
1154  greater1_ctx = 0;
1155  } else if (greater1_ctx > 0 && greater1_ctx < 3) {
1156  greater1_ctx++;
1157  }
1158 
1159  if (coeff_abs_level_greater1_flag[n_idx] &&
1160  first_greater1_coeff_idx == -1)
1161  first_greater1_coeff_idx = n_idx;
1162  }
1163  first_nz_pos_in_cg = significant_coeff_flag_idx[n_end - 1];
1164  sign_hidden = last_nz_pos_in_cg - first_nz_pos_in_cg >= 4 &&
1166 
1167  if (first_greater1_coeff_idx != -1) {
1168  coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += ff_hevc_coeff_abs_level_greater2_flag_decode(s, c_idx, ctx_set);
1169  }
1170  if (!s->pps->sign_data_hiding_flag || !sign_hidden) {
1171  coeff_sign_flag = ff_hevc_coeff_sign_flag(s, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag);
1172  } else {
1173  coeff_sign_flag = ff_hevc_coeff_sign_flag(s, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1));
1174  }
1175 
1176  for (m = 0; m < n_end; m++) {
1177  n = significant_coeff_flag_idx[m];
1178  GET_COORD(offset, n);
1179  trans_coeff_level = 1 + coeff_abs_level_greater1_flag[n];
1180  if (trans_coeff_level == ((m < 8) ?
1181  ((n == first_greater1_coeff_idx) ? 3 : 2) : 1)) {
1182  int last_coeff_abs_level_remaining = ff_hevc_coeff_abs_level_remaining(s, trans_coeff_level, c_rice_param);
1183 
1184  trans_coeff_level += last_coeff_abs_level_remaining;
1185  if ((trans_coeff_level) > (3 * (1 << c_rice_param)))
1186  c_rice_param = FFMIN(c_rice_param + 1, 4);
1187  }
1188  if (s->pps->sign_data_hiding_flag && sign_hidden) {
1189  sum_abs += trans_coeff_level;
1190  if (n == first_nz_pos_in_cg && ((sum_abs & 1) == 1))
1191  trans_coeff_level = -trans_coeff_level;
1192  }
1193  if (coeff_sign_flag >> 15)
1194  trans_coeff_level = -trans_coeff_level;
1195  coeff_sign_flag <<= 1;
1196  if (!lc->cu.cu_transquant_bypass_flag) {
1197  if (s->sps->scaling_list_enable_flag) {
1198  if (y_c || x_c || log2_trafo_size < 4) {
1199  int pos;
1200  switch (log2_trafo_size) {
1201  case 3: pos = (y_c << 3) + x_c; break;
1202  case 4: pos = ((y_c >> 1) << 3) + (x_c >> 1); break;
1203  case 5: pos = ((y_c >> 2) << 3) + (x_c >> 2); break;
1204  default: pos = (y_c << 2) + x_c;
1205  }
1206  scale_m = scale_matrix[pos];
1207  } else {
1208  scale_m = dc_scale;
1209  }
1210  }
1211  trans_coeff_level = (trans_coeff_level * (int64_t)scale * (int64_t)scale_m + add) >> shift;
1212  if(trans_coeff_level < 0) {
1213  if((~trans_coeff_level) & 0xFffffffffff8000)
1214  trans_coeff_level = -32768;
1215  } else {
1216  if (trans_coeff_level & 0xffffffffffff8000)
1217  trans_coeff_level = 32767;
1218  }
1219  }
1220  coeffs[y_c * trafo_size + x_c] = trans_coeff_level;
1221  }
1222  }
1223  }
1224 
1225  if (lc->cu.cu_transquant_bypass_flag) {
1226  s->hevcdsp.transquant_bypass[log2_trafo_size - 2](dst, coeffs, stride);
1227  } else {
1228  if (transform_skip_flag)
1229  s->hevcdsp.transform_skip(dst, coeffs, stride);
1230  else if (lc->cu.pred_mode == MODE_INTRA && c_idx == 0 &&
1231  log2_trafo_size == 2)
1232  s->hevcdsp.transform_4x4_luma_add(dst, coeffs, stride);
1233  else
1234  s->hevcdsp.transform_add[log2_trafo_size - 2](dst, coeffs, stride);
1235  }
1236 }
1237 
1238 static int hls_transform_unit(HEVCContext *s, int x0, int y0,
1239  int xBase, int yBase, int cb_xBase, int cb_yBase,
1240  int log2_cb_size, int log2_trafo_size,
1241  int trafo_depth, int blk_idx,
1242  int cbf_luma, int cbf_cb, int cbf_cr)
1243 {
1244  HEVCLocalContext *lc = &s->HEVClc;
1245 
1246  if (lc->cu.pred_mode == MODE_INTRA) {
1247  int trafo_size = 1 << log2_trafo_size;
1248  ff_hevc_set_neighbour_available(s, x0, y0, trafo_size, trafo_size);
1249 
1250  s->hpc.intra_pred[log2_trafo_size - 2](s, x0, y0, 0);
1251  if (log2_trafo_size > 2) {
1252  trafo_size = trafo_size << (s->sps->hshift[1] - 1);
1253  ff_hevc_set_neighbour_available(s, x0, y0, trafo_size, trafo_size);
1254  s->hpc.intra_pred[log2_trafo_size - 3](s, x0, y0, 1);
1255  s->hpc.intra_pred[log2_trafo_size - 3](s, x0, y0, 2);
1256  } else if (blk_idx == 3) {
1257  trafo_size = trafo_size << s->sps->hshift[1];
1258  ff_hevc_set_neighbour_available(s, xBase, yBase,
1259  trafo_size, trafo_size);
1260  s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase, 1);
1261  s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase, 2);
1262  }
1263  }
1264 
1265  if (cbf_luma || cbf_cb || cbf_cr) {
1266  int scan_idx = SCAN_DIAG;
1267  int scan_idx_c = SCAN_DIAG;
1268 
1271  if (lc->tu.cu_qp_delta != 0)
1272  if (ff_hevc_cu_qp_delta_sign_flag(s) == 1)
1273  lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta;
1274  lc->tu.is_cu_qp_delta_coded = 1;
1275 
1276  if (lc->tu.cu_qp_delta < -(26 + s->sps->qp_bd_offset / 2) ||
1277  lc->tu.cu_qp_delta > (25 + s->sps->qp_bd_offset / 2)) {
1279  "The cu_qp_delta %d is outside the valid range "
1280  "[%d, %d].\n",
1281  lc->tu.cu_qp_delta,
1282  -(26 + s->sps->qp_bd_offset / 2),
1283  (25 + s->sps->qp_bd_offset / 2));
1284  return AVERROR_INVALIDDATA;
1285  }
1286 
1287  ff_hevc_set_qPy(s, x0, y0, cb_xBase, cb_yBase, log2_cb_size);
1288  }
1289 
1290  if (lc->cu.pred_mode == MODE_INTRA && log2_trafo_size < 4) {
1291  if (lc->tu.cur_intra_pred_mode >= 6 &&
1292  lc->tu.cur_intra_pred_mode <= 14) {
1293  scan_idx = SCAN_VERT;
1294  } else if (lc->tu.cur_intra_pred_mode >= 22 &&
1295  lc->tu.cur_intra_pred_mode <= 30) {
1296  scan_idx = SCAN_HORIZ;
1297  }
1298 
1299  if (lc->pu.intra_pred_mode_c >= 6 &&
1300  lc->pu.intra_pred_mode_c <= 14) {
1301  scan_idx_c = SCAN_VERT;
1302  } else if (lc->pu.intra_pred_mode_c >= 22 &&
1303  lc->pu.intra_pred_mode_c <= 30) {
1304  scan_idx_c = SCAN_HORIZ;
1305  }
1306  }
1307 
1308  if (cbf_luma)
1309  hls_residual_coding(s, x0, y0, log2_trafo_size, scan_idx, 0);
1310  if (log2_trafo_size > 2) {
1311  if (cbf_cb)
1312  hls_residual_coding(s, x0, y0, log2_trafo_size - 1, scan_idx_c, 1);
1313  if (cbf_cr)
1314  hls_residual_coding(s, x0, y0, log2_trafo_size - 1, scan_idx_c, 2);
1315  } else if (blk_idx == 3) {
1316  if (cbf_cb)
1317  hls_residual_coding(s, xBase, yBase, log2_trafo_size, scan_idx_c, 1);
1318  if (cbf_cr)
1319  hls_residual_coding(s, xBase, yBase, log2_trafo_size, scan_idx_c, 2);
1320  }
1321  }
1322  return 0;
1323 }
1324 
1325 static void set_deblocking_bypass(HEVCContext *s, int x0, int y0, int log2_cb_size)
1326 {
1327  int cb_size = 1 << log2_cb_size;
1328  int log2_min_pu_size = s->sps->log2_min_pu_size;
1329 
1330  int min_pu_width = s->sps->min_pu_width;
1331  int x_end = FFMIN(x0 + cb_size, s->sps->width);
1332  int y_end = FFMIN(y0 + cb_size, s->sps->height);
1333  int i, j;
1334 
1335  for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1336  for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++)
1337  s->is_pcm[i + j * min_pu_width] = 2;
1338 }
1339 
1340 static int hls_transform_tree(HEVCContext *s, int x0, int y0,
1341  int xBase, int yBase, int cb_xBase, int cb_yBase,
1342  int log2_cb_size, int log2_trafo_size,
1343  int trafo_depth, int blk_idx,
1344  int cbf_cb, int cbf_cr)
1345 {
1346  HEVCLocalContext *lc = &s->HEVClc;
1347  uint8_t split_transform_flag;
1348  int ret;
1349 
1350  if (lc->cu.intra_split_flag) {
1351  if (trafo_depth == 1)
1352  lc->tu.cur_intra_pred_mode = lc->pu.intra_pred_mode[blk_idx];
1353  } else {
1355  }
1356 
1357  if (log2_trafo_size <= s->sps->log2_max_trafo_size &&
1358  log2_trafo_size > s->sps->log2_min_tb_size &&
1359  trafo_depth < lc->cu.max_trafo_depth &&
1360  !(lc->cu.intra_split_flag && trafo_depth == 0)) {
1361  split_transform_flag = ff_hevc_split_transform_flag_decode(s, log2_trafo_size);
1362  } else {
1363  int inter_split = s->sps->max_transform_hierarchy_depth_inter == 0 &&
1364  lc->cu.pred_mode == MODE_INTER &&
1365  lc->cu.part_mode != PART_2Nx2N &&
1366  trafo_depth == 0;
1367 
1368  split_transform_flag = log2_trafo_size > s->sps->log2_max_trafo_size ||
1369  (lc->cu.intra_split_flag && trafo_depth == 0) ||
1370  inter_split;
1371  }
1372 
1373  if (log2_trafo_size > 2 && (trafo_depth == 0 || cbf_cb))
1374  cbf_cb = ff_hevc_cbf_cb_cr_decode(s, trafo_depth);
1375  else if (log2_trafo_size > 2 || trafo_depth == 0)
1376  cbf_cb = 0;
1377  if (log2_trafo_size > 2 && (trafo_depth == 0 || cbf_cr))
1378  cbf_cr = ff_hevc_cbf_cb_cr_decode(s, trafo_depth);
1379  else if (log2_trafo_size > 2 || trafo_depth == 0)
1380  cbf_cr = 0;
1381 
1382  if (split_transform_flag) {
1383  const int trafo_size_split = 1 << (log2_trafo_size - 1);
1384  const int x1 = x0 + trafo_size_split;
1385  const int y1 = y0 + trafo_size_split;
1386 
1387 #define SUBDIVIDE(x, y, idx) \
1388 do { \
1389  ret = hls_transform_tree(s, x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1390  log2_trafo_size - 1, trafo_depth + 1, idx, \
1391  cbf_cb, cbf_cr); \
1392  if (ret < 0) \
1393  return ret; \
1394 } while (0)
1395 
1396  SUBDIVIDE(x0, y0, 0);
1397  SUBDIVIDE(x1, y0, 1);
1398  SUBDIVIDE(x0, y1, 2);
1399  SUBDIVIDE(x1, y1, 3);
1400 
1401 #undef SUBDIVIDE
1402  } else {
1403  int min_tu_size = 1 << s->sps->log2_min_tb_size;
1404  int log2_min_tu_size = s->sps->log2_min_tb_size;
1405  int min_tu_width = s->sps->min_tb_width;
1406  int cbf_luma = 1;
1407 
1408  if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 ||
1409  cbf_cb || cbf_cr)
1410  cbf_luma = ff_hevc_cbf_luma_decode(s, trafo_depth);
1411 
1412  ret = hls_transform_unit(s, x0, y0, xBase, yBase, cb_xBase, cb_yBase,
1413  log2_cb_size, log2_trafo_size, trafo_depth,
1414  blk_idx, cbf_luma, cbf_cb, cbf_cr);
1415  if (ret < 0)
1416  return ret;
1417  // TODO: store cbf_luma somewhere else
1418  if (cbf_luma) {
1419  int i, j;
1420  for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size)
1421  for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1422  int x_tu = (x0 + j) >> log2_min_tu_size;
1423  int y_tu = (y0 + i) >> log2_min_tu_size;
1424  s->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1425  }
1426  }
1428  ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_trafo_size);
1431  set_deblocking_bypass(s, x0, y0, log2_trafo_size);
1432  }
1433  }
1434  return 0;
1435 }
1436 
1437 static int hls_pcm_sample(HEVCContext *s, int x0, int y0, int log2_cb_size)
1438 {
1439  //TODO: non-4:2:0 support
1440  HEVCLocalContext *lc = &s->HEVClc;
1441  GetBitContext gb;
1442  int cb_size = 1 << log2_cb_size;
1443  int stride0 = s->frame->linesize[0];
1444  uint8_t *dst0 = &s->frame->data[0][y0 * stride0 + (x0 << s->sps->pixel_shift)];
1445  int stride1 = s->frame->linesize[1];
1446  uint8_t *dst1 = &s->frame->data[1][(y0 >> s->sps->vshift[1]) * stride1 + ((x0 >> s->sps->hshift[1]) << s->sps->pixel_shift)];
1447  int stride2 = s->frame->linesize[2];
1448  uint8_t *dst2 = &s->frame->data[2][(y0 >> s->sps->vshift[2]) * stride2 + ((x0 >> s->sps->hshift[2]) << s->sps->pixel_shift)];
1449 
1450  int length = cb_size * cb_size * s->sps->pcm.bit_depth + ((cb_size * cb_size) >> 1) * s->sps->pcm.bit_depth_chroma;
1451  const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3);
1452  int ret;
1453 
1455  ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size);
1456 
1457  ret = init_get_bits(&gb, pcm, length);
1458  if (ret < 0)
1459  return ret;
1460 
1461  s->hevcdsp.put_pcm(dst0, stride0, cb_size, &gb, s->sps->pcm.bit_depth);
1462  s->hevcdsp.put_pcm(dst1, stride1, cb_size / 2, &gb, s->sps->pcm.bit_depth_chroma);
1463  s->hevcdsp.put_pcm(dst2, stride2, cb_size / 2, &gb, s->sps->pcm.bit_depth_chroma);
1464  return 0;
1465 }
1466 
1467 static void hls_mvd_coding(HEVCContext *s, int x0, int y0, int log2_cb_size)
1468 {
1469  HEVCLocalContext *lc = &s->HEVClc;
1472 
1473  if (x)
1475  if (y)
1477 
1478  switch (x) {
1479  case 2: lc->pu.mvd.x = ff_hevc_mvd_decode(s); break;
1480  case 1: lc->pu.mvd.x = ff_hevc_mvd_sign_flag_decode(s); break;
1481  case 0: lc->pu.mvd.x = 0; break;
1482  }
1483 
1484  switch (y) {
1485  case 2: lc->pu.mvd.y = ff_hevc_mvd_decode(s); break;
1486  case 1: lc->pu.mvd.y = ff_hevc_mvd_sign_flag_decode(s); break;
1487  case 0: lc->pu.mvd.y = 0; break;
1488  }
1489 }
1490 
1504 static void luma_mc(HEVCContext *s, int16_t *dst, ptrdiff_t dststride,
1505  AVFrame *ref, const Mv *mv, int x_off, int y_off,
1506  int block_w, int block_h)
1507 {
1508  HEVCLocalContext *lc = &s->HEVClc;
1509  uint8_t *src = ref->data[0];
1510  ptrdiff_t srcstride = ref->linesize[0];
1511  int pic_width = s->sps->width;
1512  int pic_height = s->sps->height;
1513 
1514  int mx = mv->x & 3;
1515  int my = mv->y & 3;
1516  int extra_left = ff_hevc_qpel_extra_before[mx];
1517  int extra_top = ff_hevc_qpel_extra_before[my];
1518 
1519  x_off += mv->x >> 2;
1520  y_off += mv->y >> 2;
1521  src += y_off * srcstride + (x_off << s->sps->pixel_shift);
1522 
1523  if (x_off < extra_left || y_off < extra_top ||
1524  x_off >= pic_width - block_w - ff_hevc_qpel_extra_after[mx] ||
1525  y_off >= pic_height - block_h - ff_hevc_qpel_extra_after[my]) {
1526  const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->sps->pixel_shift;
1527  int offset = extra_top * srcstride + (extra_left << s->sps->pixel_shift);
1528  int buf_offset = extra_top *
1529  edge_emu_stride + (extra_left << s->sps->pixel_shift);
1530 
1531  s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset,
1532  edge_emu_stride, srcstride,
1533  block_w + ff_hevc_qpel_extra[mx],
1534  block_h + ff_hevc_qpel_extra[my],
1535  x_off - extra_left, y_off - extra_top,
1536  pic_width, pic_height);
1537  src = lc->edge_emu_buffer + buf_offset;
1538  srcstride = edge_emu_stride;
1539  }
1540  s->hevcdsp.put_hevc_qpel[my][mx](dst, dststride, src, srcstride, block_w,
1541  block_h, lc->mc_buffer);
1542 }
1543 
1558 static void chroma_mc(HEVCContext *s, int16_t *dst1, int16_t *dst2,
1559  ptrdiff_t dststride, AVFrame *ref, const Mv *mv,
1560  int x_off, int y_off, int block_w, int block_h)
1561 {
1562  HEVCLocalContext *lc = &s->HEVClc;
1563  uint8_t *src1 = ref->data[1];
1564  uint8_t *src2 = ref->data[2];
1565  ptrdiff_t src1stride = ref->linesize[1];
1566  ptrdiff_t src2stride = ref->linesize[2];
1567  int pic_width = s->sps->width >> 1;
1568  int pic_height = s->sps->height >> 1;
1569 
1570  int mx = mv->x & 7;
1571  int my = mv->y & 7;
1572 
1573  x_off += mv->x >> 3;
1574  y_off += mv->y >> 3;
1575  src1 += y_off * src1stride + (x_off << s->sps->pixel_shift);
1576  src2 += y_off * src2stride + (x_off << s->sps->pixel_shift);
1577 
1578  if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER ||
1579  x_off >= pic_width - block_w - EPEL_EXTRA_AFTER ||
1580  y_off >= pic_height - block_h - EPEL_EXTRA_AFTER) {
1581  const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->sps->pixel_shift;
1582  int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << s->sps->pixel_shift));
1583  int buf_offset1 = EPEL_EXTRA_BEFORE *
1584  (edge_emu_stride + (1 << s->sps->pixel_shift));
1585  int offset2 = EPEL_EXTRA_BEFORE * (src2stride + (1 << s->sps->pixel_shift));
1586  int buf_offset2 = EPEL_EXTRA_BEFORE *
1587  (edge_emu_stride + (1 << s->sps->pixel_shift));
1588 
1589  s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1,
1590  edge_emu_stride, src1stride,
1591  block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1592  x_off - EPEL_EXTRA_BEFORE,
1593  y_off - EPEL_EXTRA_BEFORE,
1594  pic_width, pic_height);
1595 
1596  src1 = lc->edge_emu_buffer + buf_offset1;
1597  src1stride = edge_emu_stride;
1598  s->hevcdsp.put_hevc_epel[!!my][!!mx](dst1, dststride, src1, src1stride,
1599  block_w, block_h, mx, my, lc->mc_buffer);
1600 
1601  s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src2 - offset2,
1602  edge_emu_stride, src2stride,
1603  block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
1604  x_off - EPEL_EXTRA_BEFORE,
1605  y_off - EPEL_EXTRA_BEFORE,
1606  pic_width, pic_height);
1607  src2 = lc->edge_emu_buffer + buf_offset2;
1608  src2stride = edge_emu_stride;
1609 
1610  s->hevcdsp.put_hevc_epel[!!my][!!mx](dst2, dststride, src2, src2stride,
1611  block_w, block_h, mx, my,
1612  lc->mc_buffer);
1613  } else {
1614  s->hevcdsp.put_hevc_epel[!!my][!!mx](dst1, dststride, src1, src1stride,
1615  block_w, block_h, mx, my,
1616  lc->mc_buffer);
1617  s->hevcdsp.put_hevc_epel[!!my][!!mx](dst2, dststride, src2, src2stride,
1618  block_w, block_h, mx, my,
1619  lc->mc_buffer);
1620  }
1621 }
1622 
1624  const Mv *mv, int y0, int height)
1625 {
1626  int y = (mv->y >> 2) + y0 + height + 9;
1627  ff_thread_await_progress(&ref->tf, y, 0);
1628 }
1629 
1630 static void hls_prediction_unit(HEVCContext *s, int x0, int y0,
1631  int nPbW, int nPbH,
1632  int log2_cb_size, int partIdx)
1633 {
1634 #define POS(c_idx, x, y) \
1635  &s->frame->data[c_idx][((y) >> s->sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \
1636  (((x) >> s->sps->hshift[c_idx]) << s->sps->pixel_shift)]
1637  HEVCLocalContext *lc = &s->HEVClc;
1638  int merge_idx = 0;
1639  struct MvField current_mv = {{{ 0 }}};
1640 
1641  int min_pu_width = s->sps->min_pu_width;
1642 
1643  MvField *tab_mvf = s->ref->tab_mvf;
1644  RefPicList *refPicList = s->ref->refPicList;
1645  HEVCFrame *ref0, *ref1;
1646 
1647  int tmpstride = MAX_PB_SIZE;
1648 
1649  uint8_t *dst0 = POS(0, x0, y0);
1650  uint8_t *dst1 = POS(1, x0, y0);
1651  uint8_t *dst2 = POS(2, x0, y0);
1652  int log2_min_cb_size = s->sps->log2_min_cb_size;
1653  int min_cb_width = s->sps->min_cb_width;
1654  int x_cb = x0 >> log2_min_cb_size;
1655  int y_cb = y0 >> log2_min_cb_size;
1656  int ref_idx[2];
1657  int mvp_flag[2];
1658  int x_pu, y_pu;
1659  int i, j;
1660 
1661  if (SAMPLE_CTB(s->skip_flag, x_cb, y_cb)) {
1662  if (s->sh.max_num_merge_cand > 1)
1663  merge_idx = ff_hevc_merge_idx_decode(s);
1664  else
1665  merge_idx = 0;
1666 
1667  ff_hevc_luma_mv_merge_mode(s, x0, y0,
1668  1 << log2_cb_size,
1669  1 << log2_cb_size,
1670  log2_cb_size, partIdx,
1671  merge_idx, &current_mv);
1672  x_pu = x0 >> s->sps->log2_min_pu_size;
1673  y_pu = y0 >> s->sps->log2_min_pu_size;
1674 
1675  for (j = 0; j < nPbH >> s->sps->log2_min_pu_size; j++)
1676  for (i = 0; i < nPbW >> s->sps->log2_min_pu_size; i++)
1677  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
1678  } else { /* MODE_INTER */
1680  if (lc->pu.merge_flag) {
1681  if (s->sh.max_num_merge_cand > 1)
1682  merge_idx = ff_hevc_merge_idx_decode(s);
1683  else
1684  merge_idx = 0;
1685 
1686  ff_hevc_luma_mv_merge_mode(s, x0, y0, nPbW, nPbH, log2_cb_size,
1687  partIdx, merge_idx, &current_mv);
1688  x_pu = x0 >> s->sps->log2_min_pu_size;
1689  y_pu = y0 >> s->sps->log2_min_pu_size;
1690 
1691  for (j = 0; j < nPbH >> s->sps->log2_min_pu_size; j++)
1692  for (i = 0; i < nPbW >> s->sps->log2_min_pu_size; i++)
1693  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
1694  } else {
1695  enum InterPredIdc inter_pred_idc = PRED_L0;
1696  ff_hevc_set_neighbour_available(s, x0, y0, nPbW, nPbH);
1697  if (s->sh.slice_type == B_SLICE)
1698  inter_pred_idc = ff_hevc_inter_pred_idc_decode(s, nPbW, nPbH);
1699 
1700  if (inter_pred_idc != PRED_L1) {
1701  if (s->sh.nb_refs[L0]) {
1702  ref_idx[0] = ff_hevc_ref_idx_lx_decode(s, s->sh.nb_refs[L0]);
1703  current_mv.ref_idx[0] = ref_idx[0];
1704  }
1705  current_mv.pred_flag[0] = 1;
1706  hls_mvd_coding(s, x0, y0, 0);
1707  mvp_flag[0] = ff_hevc_mvp_lx_flag_decode(s);
1708  ff_hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size,
1709  partIdx, merge_idx, &current_mv,
1710  mvp_flag[0], 0);
1711  current_mv.mv[0].x += lc->pu.mvd.x;
1712  current_mv.mv[0].y += lc->pu.mvd.y;
1713  }
1714 
1715  if (inter_pred_idc != PRED_L0) {
1716  if (s->sh.nb_refs[L1]) {
1717  ref_idx[1] = ff_hevc_ref_idx_lx_decode(s, s->sh.nb_refs[L1]);
1718  current_mv.ref_idx[1] = ref_idx[1];
1719  }
1720 
1721  if (s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc == PRED_BI) {
1722  AV_ZERO32(&lc->pu.mvd);
1723  } else {
1724  hls_mvd_coding(s, x0, y0, 1);
1725  }
1726 
1727  current_mv.pred_flag[1] = 1;
1728  mvp_flag[1] = ff_hevc_mvp_lx_flag_decode(s);
1729  ff_hevc_luma_mv_mvp_mode(s, x0, y0, nPbW, nPbH, log2_cb_size,
1730  partIdx, merge_idx, &current_mv,
1731  mvp_flag[1], 1);
1732  current_mv.mv[1].x += lc->pu.mvd.x;
1733  current_mv.mv[1].y += lc->pu.mvd.y;
1734  }
1735 
1736  x_pu = x0 >> s->sps->log2_min_pu_size;
1737  y_pu = y0 >> s->sps->log2_min_pu_size;
1738 
1739  for(j = 0; j < nPbH >> s->sps->log2_min_pu_size; j++)
1740  for (i = 0; i < nPbW >> s->sps->log2_min_pu_size; i++)
1741  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
1742  }
1743  }
1744 
1745  if (current_mv.pred_flag[0]) {
1746  ref0 = refPicList[0].ref[current_mv.ref_idx[0]];
1747  if (!ref0)
1748  return;
1749  hevc_await_progress(s, ref0, &current_mv.mv[0], y0, nPbH);
1750  }
1751  if (current_mv.pred_flag[1]) {
1752  ref1 = refPicList[1].ref[current_mv.ref_idx[1]];
1753  if (!ref1)
1754  return;
1755  hevc_await_progress(s, ref1, &current_mv.mv[1], y0, nPbH);
1756  }
1757 
1758  if (current_mv.pred_flag[0] && !current_mv.pred_flag[1]) {
1759  DECLARE_ALIGNED(16, int16_t, tmp[MAX_PB_SIZE * MAX_PB_SIZE]);
1760  DECLARE_ALIGNED(16, int16_t, tmp2[MAX_PB_SIZE * MAX_PB_SIZE]);
1761 
1762  luma_mc(s, tmp, tmpstride, ref0->frame,
1763  &current_mv.mv[0], x0, y0, nPbW, nPbH);
1764 
1765  if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) ||
1766  (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) {
1768  s->sh.luma_weight_l0[current_mv.ref_idx[0]],
1769  s->sh.luma_offset_l0[current_mv.ref_idx[0]],
1770  dst0, s->frame->linesize[0], tmp,
1771  tmpstride, nPbW, nPbH);
1772  } else {
1773  s->hevcdsp.put_unweighted_pred(dst0, s->frame->linesize[0], tmp, tmpstride, nPbW, nPbH);
1774  }
1775  chroma_mc(s, tmp, tmp2, tmpstride, ref0->frame,
1776  &current_mv.mv[0], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2);
1777 
1778  if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) ||
1779  (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) {
1781  s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0],
1782  s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0],
1783  dst1, s->frame->linesize[1], tmp, tmpstride,
1784  nPbW / 2, nPbH / 2);
1786  s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1],
1787  s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1],
1788  dst2, s->frame->linesize[2], tmp2, tmpstride,
1789  nPbW / 2, nPbH / 2);
1790  } else {
1791  s->hevcdsp.put_unweighted_pred(dst1, s->frame->linesize[1], tmp, tmpstride, nPbW/2, nPbH/2);
1792  s->hevcdsp.put_unweighted_pred(dst2, s->frame->linesize[2], tmp2, tmpstride, nPbW/2, nPbH/2);
1793  }
1794  } else if (!current_mv.pred_flag[0] && current_mv.pred_flag[1]) {
1795  DECLARE_ALIGNED(16, int16_t, tmp [MAX_PB_SIZE * MAX_PB_SIZE]);
1796  DECLARE_ALIGNED(16, int16_t, tmp2[MAX_PB_SIZE * MAX_PB_SIZE]);
1797 
1798  if (!ref1)
1799  return;
1800 
1801  luma_mc(s, tmp, tmpstride, ref1->frame,
1802  &current_mv.mv[1], x0, y0, nPbW, nPbH);
1803 
1804  if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) ||
1805  (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) {
1807  s->sh.luma_weight_l1[current_mv.ref_idx[1]],
1808  s->sh.luma_offset_l1[current_mv.ref_idx[1]],
1809  dst0, s->frame->linesize[0], tmp, tmpstride,
1810  nPbW, nPbH);
1811  } else {
1812  s->hevcdsp.put_unweighted_pred(dst0, s->frame->linesize[0], tmp, tmpstride, nPbW, nPbH);
1813  }
1814 
1815  chroma_mc(s, tmp, tmp2, tmpstride, ref1->frame,
1816  &current_mv.mv[1], x0/2, y0/2, nPbW/2, nPbH/2);
1817 
1818  if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) ||
1819  (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) {
1821  s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0],
1822  s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0],
1823  dst1, s->frame->linesize[1], tmp, tmpstride, nPbW/2, nPbH/2);
1825  s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1],
1826  s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1],
1827  dst2, s->frame->linesize[2], tmp2, tmpstride, nPbW/2, nPbH/2);
1828  } else {
1829  s->hevcdsp.put_unweighted_pred(dst1, s->frame->linesize[1], tmp, tmpstride, nPbW/2, nPbH/2);
1830  s->hevcdsp.put_unweighted_pred(dst2, s->frame->linesize[2], tmp2, tmpstride, nPbW/2, nPbH/2);
1831  }
1832  } else if (current_mv.pred_flag[0] && current_mv.pred_flag[1]) {
1833  DECLARE_ALIGNED(16, int16_t, tmp [MAX_PB_SIZE * MAX_PB_SIZE]);
1834  DECLARE_ALIGNED(16, int16_t, tmp2[MAX_PB_SIZE * MAX_PB_SIZE]);
1835  DECLARE_ALIGNED(16, int16_t, tmp3[MAX_PB_SIZE * MAX_PB_SIZE]);
1836  DECLARE_ALIGNED(16, int16_t, tmp4[MAX_PB_SIZE * MAX_PB_SIZE]);
1837  HEVCFrame *ref0 = refPicList[0].ref[current_mv.ref_idx[0]];
1838  HEVCFrame *ref1 = refPicList[1].ref[current_mv.ref_idx[1]];
1839 
1840  if (!ref0 || !ref1)
1841  return;
1842 
1843  luma_mc(s, tmp, tmpstride, ref0->frame,
1844  &current_mv.mv[0], x0, y0, nPbW, nPbH);
1845  luma_mc(s, tmp2, tmpstride, ref1->frame,
1846  &current_mv.mv[1], x0, y0, nPbW, nPbH);
1847 
1848  if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) ||
1849  (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) {
1851  s->sh.luma_weight_l0[current_mv.ref_idx[0]],
1852  s->sh.luma_weight_l1[current_mv.ref_idx[1]],
1853  s->sh.luma_offset_l0[current_mv.ref_idx[0]],
1854  s->sh.luma_offset_l1[current_mv.ref_idx[1]],
1855  dst0, s->frame->linesize[0],
1856  tmp, tmp2, tmpstride, nPbW, nPbH);
1857  } else {
1858  s->hevcdsp.put_weighted_pred_avg(dst0, s->frame->linesize[0],
1859  tmp, tmp2, tmpstride, nPbW, nPbH);
1860  }
1861 
1862  chroma_mc(s, tmp, tmp2, tmpstride, ref0->frame,
1863  &current_mv.mv[0], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2);
1864  chroma_mc(s, tmp3, tmp4, tmpstride, ref1->frame,
1865  &current_mv.mv[1], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2);
1866 
1867  if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) ||
1868  (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) {
1870  s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0],
1871  s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0],
1872  s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0],
1873  s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0],
1874  dst1, s->frame->linesize[1], tmp, tmp3,
1875  tmpstride, nPbW / 2, nPbH / 2);
1877  s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1],
1878  s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1],
1879  s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1],
1880  s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1],
1881  dst2, s->frame->linesize[2], tmp2, tmp4,
1882  tmpstride, nPbW / 2, nPbH / 2);
1883  } else {
1884  s->hevcdsp.put_weighted_pred_avg(dst1, s->frame->linesize[1], tmp, tmp3, tmpstride, nPbW/2, nPbH/2);
1885  s->hevcdsp.put_weighted_pred_avg(dst2, s->frame->linesize[2], tmp2, tmp4, tmpstride, nPbW/2, nPbH/2);
1886  }
1887  }
1888 }
1889 
1893 static int luma_intra_pred_mode(HEVCContext *s, int x0, int y0, int pu_size,
1894  int prev_intra_luma_pred_flag)
1895 {
1896  HEVCLocalContext *lc = &s->HEVClc;
1897  int x_pu = x0 >> s->sps->log2_min_pu_size;
1898  int y_pu = y0 >> s->sps->log2_min_pu_size;
1899  int min_pu_width = s->sps->min_pu_width;
1900  int size_in_pus = pu_size >> s->sps->log2_min_pu_size;
1901  int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1);
1902  int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1);
1903 
1904  int cand_up = (lc->ctb_up_flag || y0b) ?
1905  s->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC;
1906  int cand_left = (lc->ctb_left_flag || x0b) ?
1907  s->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC;
1908 
1909  int y_ctb = (y0 >> (s->sps->log2_ctb_size)) << (s->sps->log2_ctb_size);
1910 
1911  MvField *tab_mvf = s->ref->tab_mvf;
1912  int intra_pred_mode;
1913  int candidate[3];
1914  int i, j;
1915 
1916  // intra_pred_mode prediction does not cross vertical CTB boundaries
1917  if ((y0 - 1) < y_ctb)
1918  cand_up = INTRA_DC;
1919 
1920  if (cand_left == cand_up) {
1921  if (cand_left < 2) {
1922  candidate[0] = INTRA_PLANAR;
1923  candidate[1] = INTRA_DC;
1924  candidate[2] = INTRA_ANGULAR_26;
1925  } else {
1926  candidate[0] = cand_left;
1927  candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
1928  candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
1929  }
1930  } else {
1931  candidate[0] = cand_left;
1932  candidate[1] = cand_up;
1933  if (candidate[0] != INTRA_PLANAR && candidate[1] != INTRA_PLANAR) {
1934  candidate[2] = INTRA_PLANAR;
1935  } else if (candidate[0] != INTRA_DC && candidate[1] != INTRA_DC) {
1936  candidate[2] = INTRA_DC;
1937  } else {
1938  candidate[2] = INTRA_ANGULAR_26;
1939  }
1940  }
1941 
1942  if (prev_intra_luma_pred_flag) {
1943  intra_pred_mode = candidate[lc->pu.mpm_idx];
1944  } else {
1945  if (candidate[0] > candidate[1])
1946  FFSWAP(uint8_t, candidate[0], candidate[1]);
1947  if (candidate[0] > candidate[2])
1948  FFSWAP(uint8_t, candidate[0], candidate[2]);
1949  if (candidate[1] > candidate[2])
1950  FFSWAP(uint8_t, candidate[1], candidate[2]);
1951 
1952  intra_pred_mode = lc->pu.rem_intra_luma_pred_mode;
1953  for (i = 0; i < 3; i++)
1954  if (intra_pred_mode >= candidate[i])
1955  intra_pred_mode++;
1956  }
1957 
1958  /* write the intra prediction units into the mv array */
1959  if (!size_in_pus)
1960  size_in_pus = 1;
1961  for (i = 0; i < size_in_pus; i++) {
1962  memset(&s->tab_ipm[(y_pu + i) * min_pu_width + x_pu],
1963  intra_pred_mode, size_in_pus);
1964 
1965  for (j = 0; j < size_in_pus; j++) {
1966  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].is_intra = 1;
1967  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag[0] = 0;
1968  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag[1] = 0;
1969  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].ref_idx[0] = 0;
1970  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].ref_idx[1] = 0;
1971  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].mv[0].x = 0;
1972  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].mv[0].y = 0;
1973  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].mv[1].x = 0;
1974  tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].mv[1].y = 0;
1975  }
1976  }
1977 
1978  return intra_pred_mode;
1979 }
1980 
1981 static av_always_inline void set_ct_depth(HEVCContext *s, int x0, int y0,
1982  int log2_cb_size, int ct_depth)
1983 {
1984  int length = (1 << log2_cb_size) >> s->sps->log2_min_cb_size;
1985  int x_cb = x0 >> s->sps->log2_min_cb_size;
1986  int y_cb = y0 >> s->sps->log2_min_cb_size;
1987  int y;
1988 
1989  for (y = 0; y < length; y++)
1990  memset(&s->tab_ct_depth[(y_cb + y) * s->sps->min_cb_width + x_cb],
1991  ct_depth, length);
1992 }
1993 
1994 static void intra_prediction_unit(HEVCContext *s, int x0, int y0,
1995  int log2_cb_size)
1996 {
1997  HEVCLocalContext *lc = &s->HEVClc;
1998  static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
1999  uint8_t prev_intra_luma_pred_flag[4];
2000  int split = lc->cu.part_mode == PART_NxN;
2001  int pb_size = (1 << log2_cb_size) >> split;
2002  int side = split + 1;
2003  int chroma_mode;
2004  int i, j;
2005 
2006  for (i = 0; i < side; i++)
2007  for (j = 0; j < side; j++)
2008  prev_intra_luma_pred_flag[2 * i + j] = ff_hevc_prev_intra_luma_pred_flag_decode(s);
2009 
2010  for (i = 0; i < side; i++) {
2011  for (j = 0; j < side; j++) {
2012  if (prev_intra_luma_pred_flag[2 * i + j])
2014  else
2016 
2017  lc->pu.intra_pred_mode[2 * i + j] =
2018  luma_intra_pred_mode(s, x0 + pb_size * j, y0 + pb_size * i, pb_size,
2019  prev_intra_luma_pred_flag[2 * i + j]);
2020  }
2021  }
2022 
2023  chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(s);
2024  if (chroma_mode != 4) {
2025  if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
2026  lc->pu.intra_pred_mode_c = 34;
2027  else
2028  lc->pu.intra_pred_mode_c = intra_chroma_table[chroma_mode];
2029  } else {
2030  lc->pu.intra_pred_mode_c = lc->pu.intra_pred_mode[0];
2031  }
2032 }
2033 
2035  int x0, int y0,
2036  int log2_cb_size)
2037 {
2038  HEVCLocalContext *lc = &s->HEVClc;
2039  int pb_size = 1 << log2_cb_size;
2040  int size_in_pus = pb_size >> s->sps->log2_min_pu_size;
2041  int min_pu_width = s->sps->min_pu_width;
2042  MvField *tab_mvf = s->ref->tab_mvf;
2043  int x_pu = x0 >> s->sps->log2_min_pu_size;
2044  int y_pu = y0 >> s->sps->log2_min_pu_size;
2045  int j, k;
2046 
2047  if (size_in_pus == 0)
2048  size_in_pus = 1;
2049  for (j = 0; j < size_in_pus; j++) {
2050  memset(&s->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus);
2051  for (k = 0; k < size_in_pus; k++)
2052  tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].is_intra = lc->cu.pred_mode == MODE_INTRA;
2053  }
2054 }
2055 
2056 static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
2057 {
2058  int cb_size = 1 << log2_cb_size;
2059  HEVCLocalContext *lc = &s->HEVClc;
2060  int log2_min_cb_size = s->sps->log2_min_cb_size;
2061  int length = cb_size >> log2_min_cb_size;
2062  int min_cb_width = s->sps->min_cb_width;
2063  int x_cb = x0 >> log2_min_cb_size;
2064  int y_cb = y0 >> log2_min_cb_size;
2065  int x, y, ret;
2066 
2067  lc->cu.x = x0;
2068  lc->cu.y = y0;
2069  lc->cu.rqt_root_cbf = 1;
2070  lc->cu.pred_mode = MODE_INTRA;
2071  lc->cu.part_mode = PART_2Nx2N;
2072  lc->cu.intra_split_flag = 0;
2073  lc->cu.pcm_flag = 0;
2074 
2075  SAMPLE_CTB(s->skip_flag, x_cb, y_cb) = 0;
2076  for (x = 0; x < 4; x++)
2077  lc->pu.intra_pred_mode[x] = 1;
2080  if (lc->cu.cu_transquant_bypass_flag)
2081  set_deblocking_bypass(s, x0, y0, log2_cb_size);
2082  } else
2083  lc->cu.cu_transquant_bypass_flag = 0;
2084 
2085  if (s->sh.slice_type != I_SLICE) {
2086  uint8_t skip_flag = ff_hevc_skip_flag_decode(s, x0, y0, x_cb, y_cb);
2087 
2088  lc->cu.pred_mode = MODE_SKIP;
2089  x = y_cb * min_cb_width + x_cb;
2090  for (y = 0; y < length; y++) {
2091  memset(&s->skip_flag[x], skip_flag, length);
2092  x += min_cb_width;
2093  }
2094  lc->cu.pred_mode = skip_flag ? MODE_SKIP : MODE_INTER;
2095  }
2096 
2097  if (SAMPLE_CTB(s->skip_flag, x_cb, y_cb)) {
2098  hls_prediction_unit(s, x0, y0, cb_size, cb_size, log2_cb_size, 0);
2099  intra_prediction_unit_default_value(s, x0, y0, log2_cb_size);
2100 
2102  ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size);
2103  } else {
2104  if (s->sh.slice_type != I_SLICE)
2106  if (lc->cu.pred_mode != MODE_INTRA ||
2107  log2_cb_size == s->sps->log2_min_cb_size) {
2108  lc->cu.part_mode = ff_hevc_part_mode_decode(s, log2_cb_size);
2109  lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN &&
2110  lc->cu.pred_mode == MODE_INTRA;
2111  }
2112 
2113  if (lc->cu.pred_mode == MODE_INTRA) {
2114  if (lc->cu.part_mode == PART_2Nx2N && s->sps->pcm_enabled_flag &&
2115  log2_cb_size >= s->sps->pcm.log2_min_pcm_cb_size &&
2116  log2_cb_size <= s->sps->pcm.log2_max_pcm_cb_size) {
2118  }
2119  if (lc->cu.pcm_flag) {
2120  intra_prediction_unit_default_value(s, x0, y0, log2_cb_size);
2121  ret = hls_pcm_sample(s, x0, y0, log2_cb_size);
2123  set_deblocking_bypass(s, x0, y0, log2_cb_size);
2124 
2125  if (ret < 0)
2126  return ret;
2127  } else {
2128  intra_prediction_unit(s, x0, y0, log2_cb_size);
2129  }
2130  } else {
2131  intra_prediction_unit_default_value(s, x0, y0, log2_cb_size);
2132  switch (lc->cu.part_mode) {
2133  case PART_2Nx2N:
2134  hls_prediction_unit(s, x0, y0, cb_size, cb_size, log2_cb_size, 0);
2135  break;
2136  case PART_2NxN:
2137  hls_prediction_unit(s, x0, y0, cb_size, cb_size / 2, log2_cb_size, 0);
2138  hls_prediction_unit(s, x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1);
2139  break;
2140  case PART_Nx2N:
2141  hls_prediction_unit(s, x0, y0, cb_size / 2, cb_size, log2_cb_size, 0);
2142  hls_prediction_unit(s, x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1);
2143  break;
2144  case PART_2NxnU:
2145  hls_prediction_unit(s, x0, y0, cb_size, cb_size / 4, log2_cb_size, 0);
2146  hls_prediction_unit(s, x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1);
2147  break;
2148  case PART_2NxnD:
2149  hls_prediction_unit(s, x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0);
2150  hls_prediction_unit(s, x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1);
2151  break;
2152  case PART_nLx2N:
2153  hls_prediction_unit(s, x0, y0, cb_size / 4, cb_size, log2_cb_size, 0);
2154  hls_prediction_unit(s, x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1);
2155  break;
2156  case PART_nRx2N:
2157  hls_prediction_unit(s, x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0);
2158  hls_prediction_unit(s, x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1);
2159  break;
2160  case PART_NxN:
2161  hls_prediction_unit(s, x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0);
2162  hls_prediction_unit(s, x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1);
2163  hls_prediction_unit(s, x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2);
2164  hls_prediction_unit(s, x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3);
2165  break;
2166  }
2167  }
2168 
2169  if (!lc->cu.pcm_flag) {
2170  if (lc->cu.pred_mode != MODE_INTRA &&
2171  !(lc->cu.part_mode == PART_2Nx2N && lc->pu.merge_flag)) {
2173  }
2174  if (lc->cu.rqt_root_cbf) {
2175  lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ?
2178  ret = hls_transform_tree(s, x0, y0, x0, y0, x0, y0,
2179  log2_cb_size,
2180  log2_cb_size, 0, 0, 0, 0);
2181  if (ret < 0)
2182  return ret;
2183  } else {
2185  ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size);
2186  }
2187  }
2188  }
2189 
2191  ff_hevc_set_qPy(s, x0, y0, x0, y0, log2_cb_size);
2192 
2193  x = y_cb * min_cb_width + x_cb;
2194  for (y = 0; y < length; y++) {
2195  memset(&s->qp_y_tab[x], lc->qp_y, length);
2196  x += min_cb_width;
2197  }
2198 
2199  set_ct_depth(s, x0, y0, log2_cb_size, lc->ct.depth);
2200 
2201  return 0;
2202 }
2203 
2204 static int hls_coding_quadtree(HEVCContext *s, int x0, int y0,
2205  int log2_cb_size, int cb_depth)
2206 {
2207  HEVCLocalContext *lc = &s->HEVClc;
2208  const int cb_size = 1 << log2_cb_size;
2209  int split_cu;
2210 
2211  lc->ct.depth = cb_depth;
2212  if (x0 + cb_size <= s->sps->width &&
2213  y0 + cb_size <= s->sps->height &&
2214  log2_cb_size > s->sps->log2_min_cb_size) {
2215  split_cu = ff_hevc_split_coding_unit_flag_decode(s, cb_depth, x0, y0);
2216  } else {
2217  split_cu = (log2_cb_size > s->sps->log2_min_cb_size);
2218  }
2219  if (s->pps->cu_qp_delta_enabled_flag &&
2220  log2_cb_size >= s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth) {
2221  lc->tu.is_cu_qp_delta_coded = 0;
2222  lc->tu.cu_qp_delta = 0;
2223  }
2224 
2225  if (split_cu) {
2226  const int cb_size_split = cb_size >> 1;
2227  const int x1 = x0 + cb_size_split;
2228  const int y1 = y0 + cb_size_split;
2229 
2230  log2_cb_size--;
2231  cb_depth++;
2232 
2233 #define SUBDIVIDE(x, y) \
2234 do { \
2235  if (x < s->sps->width && y < s->sps->height) { \
2236  int ret = hls_coding_quadtree(s, x, y, log2_cb_size, cb_depth);\
2237  if (ret < 0) \
2238  return ret; \
2239  } \
2240 } while (0)
2241 
2242  SUBDIVIDE(x0, y0);
2243  SUBDIVIDE(x1, y0);
2244  SUBDIVIDE(x0, y1);
2245  SUBDIVIDE(x1, y1);
2246  } else {
2247  int ret = hls_coding_unit(s, x0, y0, log2_cb_size);
2248  if (ret < 0)
2249  return ret;
2250  }
2251 
2252  return 0;
2253 }
2254 
2255 static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb,
2256  int ctb_addr_ts)
2257 {
2258  HEVCLocalContext *lc = &s->HEVClc;
2259  int ctb_size = 1 << s->sps->log2_ctb_size;
2260  int ctb_addr_rs = s->pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2261  int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr;
2262 
2263  s->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr;
2264 
2266  if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2267  lc->first_qp_group = 1;
2268  lc->end_of_tiles_x = s->sps->width;
2269  } else if (s->pps->tiles_enabled_flag) {
2270  if (ctb_addr_ts && s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[ctb_addr_ts - 1]) {
2271  int idxX = s->pps->col_idxX[x_ctb >> s->sps->log2_ctb_size];
2272  lc->start_of_tiles_x = x_ctb;
2273  lc->end_of_tiles_x = x_ctb + (s->pps->column_width[idxX] << s->sps->log2_ctb_size);
2274  lc->first_qp_group = 1;
2275  }
2276  } else {
2277  lc->end_of_tiles_x = s->sps->width;
2278  }
2279 
2280  lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->sps->height);
2281 
2282  lc->boundary_flags = 0;
2283  if (s->pps->tiles_enabled_flag) {
2284  if (x_ctb > 0 && s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
2286  if (x_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - 1])
2288  if (y_ctb > 0 && s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->sps->ctb_width]])
2290  if (y_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - s->sps->ctb_width])
2292  } else {
2293  if (!ctb_addr_in_slice > 0)
2295  if (ctb_addr_in_slice < s->sps->ctb_width)
2297  }
2298 
2299  lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE));
2300  lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= s->sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE));
2301  lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= s->sps->ctb_width) && (s->pps->tile_id[ctb_addr_ts] == s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - s->sps->ctb_width]]));
2302  lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= s->sps->ctb_width) && (s->pps->tile_id[ctb_addr_ts] == s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - s->sps->ctb_width]]));
2303 }
2304 
2306 {
2307  int ctb_size = 1 << s->sps->log2_ctb_size;
2308  int more_data = 1;
2309  int x_ctb = 0;
2310  int y_ctb = 0;
2311  int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
2312  int ret;
2313 
2314  while (more_data && ctb_addr_ts < s->sps->ctb_size) {
2315  int ctb_addr_rs = s->pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2316 
2317  x_ctb = (ctb_addr_rs % ((s->sps->width + ctb_size - 1) >> s->sps->log2_ctb_size)) << s->sps->log2_ctb_size;
2318  y_ctb = (ctb_addr_rs / ((s->sps->width + ctb_size - 1) >> s->sps->log2_ctb_size)) << s->sps->log2_ctb_size;
2319  hls_decode_neighbour(s, x_ctb, y_ctb, ctb_addr_ts);
2320 
2321  ff_hevc_cabac_init(s, ctb_addr_ts);
2322 
2323  hls_sao_param(s, x_ctb >> s->sps->log2_ctb_size, y_ctb >> s->sps->log2_ctb_size);
2324 
2325  s->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
2326  s->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
2328 
2329  ret = hls_coding_quadtree(s, x_ctb, y_ctb, s->sps->log2_ctb_size, 0);
2330  if (ret < 0)
2331  return ret;
2332  more_data = !ff_hevc_end_of_slice_flag_decode(s);
2333 
2334  ctb_addr_ts++;
2335  ff_hevc_save_states(s, ctb_addr_ts);
2336  ff_hevc_hls_filters(s, x_ctb, y_ctb, ctb_size);
2337  }
2338 
2339  if (x_ctb + ctb_size >= s->sps->width &&
2340  y_ctb + ctb_size >= s->sps->height)
2341  ff_hevc_hls_filter(s, x_ctb, y_ctb);
2342 
2343  return ctb_addr_ts;
2344 }
2345 
2351 {
2352  GetBitContext *gb = &s->HEVClc.gb;
2353  int nuh_layer_id;
2354 
2355  if (get_bits1(gb) != 0)
2356  return AVERROR_INVALIDDATA;
2357 
2358  s->nal_unit_type = get_bits(gb, 6);
2359 
2360  nuh_layer_id = get_bits(gb, 6);
2361  s->temporal_id = get_bits(gb, 3) - 1;
2362  if (s->temporal_id < 0)
2363  return AVERROR_INVALIDDATA;
2364 
2366  "nal_unit_type: %d, nuh_layer_id: %dtemporal_id: %d\n",
2367  s->nal_unit_type, nuh_layer_id, s->temporal_id);
2368 
2369  return nuh_layer_id == 0;
2370 }
2371 
2373 {
2374  int min_pu_size = 1 << s->sps->log2_min_pu_size;
2375  int x, y, c_idx;
2376 
2377  for (c_idx = 0; c_idx < 3; c_idx++) {
2378  ptrdiff_t stride = s->frame->linesize[c_idx];
2379  int hshift = s->sps->hshift[c_idx];
2380  int vshift = s->sps->vshift[c_idx];
2381  for (y = 0; y < s->sps->min_pu_height; y++) {
2382  for (x = 0; x < s->sps->min_pu_width; x++) {
2383  if (s->is_pcm[y * s->sps->min_pu_width + x]) {
2384  int n;
2385  int len = min_pu_size >> hshift;
2386  uint8_t *src = &s->frame->data[c_idx][((y << s->sps->log2_min_pu_size) >> vshift) * stride + (((x << s->sps->log2_min_pu_size) >> hshift) << s->sps->pixel_shift)];
2387  uint8_t *dst = &s->sao_frame->data[c_idx][((y << s->sps->log2_min_pu_size) >> vshift) * stride + (((x << s->sps->log2_min_pu_size) >> hshift) << s->sps->pixel_shift)];
2388  for (n = 0; n < (min_pu_size >> vshift); n++) {
2389  memcpy(dst, src, len);
2390  src += stride;
2391  dst += stride;
2392  }
2393  }
2394  }
2395  }
2396  }
2397 }
2398 
2400 {
2401  AVFrame *out = s->ref->frame;
2402 
2403  if (s->sei_frame_packing_present &&
2406  s->content_interpretation_type > 0 &&
2407  s->content_interpretation_type < 3) {
2409  if (!stereo)
2410  return AVERROR(ENOMEM);
2411 
2412  switch (s->frame_packing_arrangement_type) {
2413  case 3:
2414  if (s->quincunx_subsampling)
2416  else
2417  stereo->type = AV_STEREO3D_SIDEBYSIDE;
2418  break;
2419  case 4:
2420  stereo->type = AV_STEREO3D_TOPBOTTOM;
2421  break;
2422  case 5:
2423  stereo->type = AV_STEREO3D_FRAMESEQUENCE;
2424  break;
2425  }
2426 
2427  if (s->content_interpretation_type == 2)
2428  stereo->flags = AV_STEREO3D_FLAG_INVERT;
2429  }
2430 
2432  (s->sei_anticlockwise_rotation || s->sei_hflip || s->sei_vflip)) {
2433  double angle = s->sei_anticlockwise_rotation * 360 / (double) (1 << 16);
2434  AVFrameSideData *rotation = av_frame_new_side_data(out,
2436  sizeof(int32_t) * 9);
2437  if (!rotation)
2438  return AVERROR(ENOMEM);
2439 
2440  av_display_rotation_set((int32_t *)rotation->data, angle);
2441  av_display_matrix_flip((int32_t *)rotation->data,
2442  s->sei_hflip, s->sei_vflip);
2443  }
2444 
2445  return 0;
2446 }
2447 
2449 {
2450  HEVCLocalContext *lc = &s->HEVClc;
2451  int ret;
2452 
2453  memset(s->horizontal_bs, 0, 2 * s->bs_width * (s->bs_height + 1));
2454  memset(s->vertical_bs, 0, 2 * s->bs_width * (s->bs_height + 1));
2455  memset(s->cbf_luma, 0, s->sps->min_tb_width * s->sps->min_tb_height);
2456  memset(s->is_pcm, 0, s->sps->min_pu_width * s->sps->min_pu_height);
2457 
2458  lc->start_of_tiles_x = 0;
2459  s->is_decoded = 0;
2460  s->first_nal_type = s->nal_unit_type;
2461 
2462  if (s->pps->tiles_enabled_flag)
2463  lc->end_of_tiles_x = s->pps->column_width[0] << s->sps->log2_ctb_size;
2464 
2465  ret = ff_hevc_set_new_ref(s, s->sps->sao_enabled ? &s->sao_frame : &s->frame,
2466  s->poc);
2467  if (ret < 0)
2468  goto fail;
2469 
2470  ret = ff_hevc_frame_rps(s);
2471  if (ret < 0) {
2472  av_log(s->avctx, AV_LOG_ERROR, "Error constructing the frame RPS.\n");
2473  goto fail;
2474  }
2475 
2476  s->ref->frame->key_frame = IS_IRAP(s);
2477 
2478  ret = set_side_data(s);
2479  if (ret < 0)
2480  goto fail;
2481 
2483  ret = ff_hevc_output_frame(s, s->output_frame, 0);
2484  if (ret < 0)
2485  goto fail;
2486 
2488 
2489  return 0;
2490 
2491 fail:
2492  if (s->ref)
2493  ff_thread_report_progress(&s->ref->tf, INT_MAX, 0);
2494  s->ref = NULL;
2495  return ret;
2496 }
2497 
2498 static int decode_nal_unit(HEVCContext *s, const uint8_t *nal, int length)
2499 {
2500  HEVCLocalContext *lc = &s->HEVClc;
2501  GetBitContext *gb = &lc->gb;
2502  int ctb_addr_ts, ret;
2503 
2504  ret = init_get_bits8(gb, nal, length);
2505  if (ret < 0)
2506  return ret;
2507 
2508  ret = hls_nal_unit(s);
2509  if (ret < 0) {
2510  av_log(s->avctx, AV_LOG_ERROR, "Invalid NAL unit %d, skipping.\n",
2511  s->nal_unit_type);
2512  goto fail;
2513  } else if (!ret)
2514  return 0;
2515 
2516  switch (s->nal_unit_type) {
2517  case NAL_VPS:
2518  ret = ff_hevc_decode_nal_vps(s);
2519  if (ret < 0)
2520  goto fail;
2521  break;
2522  case NAL_SPS:
2523  ret = ff_hevc_decode_nal_sps(s);
2524  if (ret < 0)
2525  goto fail;
2526  break;
2527  case NAL_PPS:
2528  ret = ff_hevc_decode_nal_pps(s);
2529  if (ret < 0)
2530  goto fail;
2531  break;
2532  case NAL_SEI_PREFIX:
2533  case NAL_SEI_SUFFIX:
2534  ret = ff_hevc_decode_nal_sei(s);
2535  if (ret < 0)
2536  goto fail;
2537  break;
2538  case NAL_TRAIL_R:
2539  case NAL_TRAIL_N:
2540  case NAL_TSA_N:
2541  case NAL_TSA_R:
2542  case NAL_STSA_N:
2543  case NAL_STSA_R:
2544  case NAL_BLA_W_LP:
2545  case NAL_BLA_W_RADL:
2546  case NAL_BLA_N_LP:
2547  case NAL_IDR_W_RADL:
2548  case NAL_IDR_N_LP:
2549  case NAL_CRA_NUT:
2550  case NAL_RADL_N:
2551  case NAL_RADL_R:
2552  case NAL_RASL_N:
2553  case NAL_RASL_R:
2554  ret = hls_slice_header(s);
2555  if (ret < 0)
2556  return ret;
2557 
2558  if (s->max_ra == INT_MAX) {
2559  if (s->nal_unit_type == NAL_CRA_NUT || IS_BLA(s)) {
2560  s->max_ra = s->poc;
2561  } else {
2562  if (IS_IDR(s))
2563  s->max_ra = INT_MIN;
2564  }
2565  }
2566 
2567  if ((s->nal_unit_type == NAL_RASL_R || s->nal_unit_type == NAL_RASL_N) &&
2568  s->poc <= s->max_ra) {
2569  s->is_decoded = 0;
2570  break;
2571  } else {
2572  if (s->nal_unit_type == NAL_RASL_R && s->poc > s->max_ra)
2573  s->max_ra = INT_MIN;
2574  }
2575 
2576  if (s->sh.first_slice_in_pic_flag) {
2577  ret = hevc_frame_start(s);
2578  if (ret < 0)
2579  return ret;
2580  } else if (!s->ref) {
2581  av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");
2582  goto fail;
2583  }
2584 
2585  if (s->nal_unit_type != s->first_nal_type) {
2587  "Non-matching NAL types of the VCL NALUs: %d %d\n",
2588  s->first_nal_type, s->nal_unit_type);
2589  return AVERROR_INVALIDDATA;
2590  }
2591 
2592  if (!s->sh.dependent_slice_segment_flag &&
2593  s->sh.slice_type != I_SLICE) {
2594  ret = ff_hevc_slice_rpl(s);
2595  if (ret < 0) {
2597  "Error constructing the reference lists for the current slice.\n");
2598  goto fail;
2599  }
2600  }
2601 
2602  ctb_addr_ts = hls_slice_data(s);
2603  if (ctb_addr_ts >= (s->sps->ctb_width * s->sps->ctb_height)) {
2604  s->is_decoded = 1;
2607  s->sps->sao_enabled)
2608  restore_tqb_pixels(s);
2609  }
2610 
2611  if (ctb_addr_ts < 0) {
2612  ret = ctb_addr_ts;
2613  goto fail;
2614  }
2615  break;
2616  case NAL_EOS_NUT:
2617  case NAL_EOB_NUT:
2618  s->seq_decode = (s->seq_decode + 1) & 0xff;
2619  s->max_ra = INT_MAX;
2620  break;
2621  case NAL_AUD:
2622  case NAL_FD_NUT:
2623  break;
2624  default:
2625  av_log(s->avctx, AV_LOG_INFO,
2626  "Skipping NAL unit %d\n", s->nal_unit_type);
2627  }
2628 
2629  return 0;
2630 fail:
2632  return ret;
2633  return 0;
2634 }
2635 
2636 /* FIXME: This is adapted from ff_h264_decode_nal, avoiding duplication
2637  * between these functions would be nice. */
2638 static int extract_rbsp(const uint8_t *src, int length,
2639  HEVCNAL *nal)
2640 {
2641  int i, si, di;
2642  uint8_t *dst;
2643 
2644 #define STARTCODE_TEST \
2645  if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
2646  if (src[i + 2] != 3) { \
2647  /* startcode, so we must be past the end */ \
2648  length = i; \
2649  } \
2650  break; \
2651  }
2652 #if HAVE_FAST_UNALIGNED
2653 #define FIND_FIRST_ZERO \
2654  if (i > 0 && !src[i]) \
2655  i--; \
2656  while (src[i]) \
2657  i++
2658 #if HAVE_FAST_64BIT
2659  for (i = 0; i + 1 < length; i += 9) {
2660  if (!((~AV_RN64A(src + i) &
2661  (AV_RN64A(src + i) - 0x0100010001000101ULL)) &
2662  0x8000800080008080ULL))
2663  continue;
2664  FIND_FIRST_ZERO;
2666  i -= 7;
2667  }
2668 #else
2669  for (i = 0; i + 1 < length; i += 5) {
2670  if (!((~AV_RN32A(src + i) &
2671  (AV_RN32A(src + i) - 0x01000101U)) &
2672  0x80008080U))
2673  continue;
2674  FIND_FIRST_ZERO;
2676  i -= 3;
2677  }
2678 #endif /* HAVE_FAST_64BIT */
2679 #else
2680  for (i = 0; i + 1 < length; i += 2) {
2681  if (src[i])
2682  continue;
2683  if (i > 0 && src[i - 1] == 0)
2684  i--;
2686  }
2687 #endif /* HAVE_FAST_UNALIGNED */
2688 
2689  if (i >= length - 1) { // no escaped 0
2690  nal->data = src;
2691  nal->size = length;
2692  return length;
2693  }
2694 
2696  length + FF_INPUT_BUFFER_PADDING_SIZE);
2697  if (!nal->rbsp_buffer)
2698  return AVERROR(ENOMEM);
2699 
2700  dst = nal->rbsp_buffer;
2701 
2702  memcpy(dst, src, i);
2703  si = di = i;
2704  while (si + 2 < length) {
2705  // remove escapes (very rare 1:2^22)
2706  if (src[si + 2] > 3) {
2707  dst[di++] = src[si++];
2708  dst[di++] = src[si++];
2709  } else if (src[si] == 0 && src[si + 1] == 0) {
2710  if (src[si + 2] == 3) { // escape
2711  dst[di++] = 0;
2712  dst[di++] = 0;
2713  si += 3;
2714 
2715  continue;
2716  } else // next start code
2717  goto nsc;
2718  }
2719 
2720  dst[di++] = src[si++];
2721  }
2722  while (si < length)
2723  dst[di++] = src[si++];
2724 
2725 nsc:
2726  memset(dst + di, 0, FF_INPUT_BUFFER_PADDING_SIZE);
2727 
2728  nal->data = dst;
2729  nal->size = di;
2730  return si;
2731 }
2732 
2733 static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
2734 {
2735  int i, consumed, ret = 0;
2736 
2737  s->ref = NULL;
2738  s->eos = 0;
2739 
2740  /* split the input packet into NAL units, so we know the upper bound on the
2741  * number of slices in the frame */
2742  s->nb_nals = 0;
2743  while (length >= 4) {
2744  HEVCNAL *nal;
2745  int extract_length = 0;
2746 
2747  if (s->is_nalff) {
2748  int i;
2749  for (i = 0; i < s->nal_length_size; i++)
2750  extract_length = (extract_length << 8) | buf[i];
2751  buf += s->nal_length_size;
2752  length -= s->nal_length_size;
2753 
2754  if (extract_length > length) {
2755  av_log(s->avctx, AV_LOG_ERROR, "Invalid NAL unit size.\n");
2756  ret = AVERROR_INVALIDDATA;
2757  goto fail;
2758  }
2759  } else {
2760  if (buf[2] == 0) {
2761  length--;
2762  buf++;
2763  continue;
2764  }
2765  if (buf[0] != 0 || buf[1] != 0 || buf[2] != 1) {
2766  ret = AVERROR_INVALIDDATA;
2767  goto fail;
2768  }
2769 
2770  buf += 3;
2771  length -= 3;
2772  extract_length = length;
2773  }
2774 
2775  if (s->nals_allocated < s->nb_nals + 1) {
2776  int new_size = s->nals_allocated + 1;
2777  HEVCNAL *tmp = av_realloc_array(s->nals, new_size, sizeof(*tmp));
2778  if (!tmp) {
2779  ret = AVERROR(ENOMEM);
2780  goto fail;
2781  }
2782  s->nals = tmp;
2783  memset(s->nals + s->nals_allocated, 0,
2784  (new_size - s->nals_allocated) * sizeof(*tmp));
2785  s->nals_allocated = new_size;
2786  }
2787  nal = &s->nals[s->nb_nals++];
2788 
2789  consumed = extract_rbsp(buf, extract_length, nal);
2790  if (consumed < 0) {
2791  ret = consumed;
2792  goto fail;
2793  }
2794 
2795  ret = init_get_bits8(&s->HEVClc.gb, nal->data, nal->size);
2796  if (ret < 0)
2797  goto fail;
2798  hls_nal_unit(s);
2799 
2800  if (s->nal_unit_type == NAL_EOB_NUT ||
2801  s->nal_unit_type == NAL_EOS_NUT)
2802  s->eos = 1;
2803 
2804  buf += consumed;
2805  length -= consumed;
2806  }
2807 
2808  /* parse the NAL units */
2809  for (i = 0; i < s->nb_nals; i++) {
2810  int ret = decode_nal_unit(s, s->nals[i].data, s->nals[i].size);
2811  if (ret < 0) {
2813  "Error parsing NAL unit #%d.\n", i);
2814  goto fail;
2815  }
2816  }
2817 
2818 fail:
2819  if (s->ref)
2820  ff_thread_report_progress(&s->ref->tf, INT_MAX, 0);
2821 
2822  return ret;
2823 }
2824 
2825 static void print_md5(void *log_ctx, int level, uint8_t md5[16])
2826 {
2827  int i;
2828  for (i = 0; i < 16; i++)
2829  av_log(log_ctx, level, "%02"PRIx8, md5[i]);
2830 }
2831 
2832 static int verify_md5(HEVCContext *s, AVFrame *frame)
2833 {
2834  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
2835  int pixel_shift;
2836  int i, j;
2837 
2838  if (!desc)
2839  return AVERROR(EINVAL);
2840 
2841  pixel_shift = desc->comp[0].depth_minus1 > 7;
2842 
2843  av_log(s->avctx, AV_LOG_DEBUG, "Verifying checksum for frame with POC %d: ",
2844  s->poc);
2845 
2846  /* the checksums are LE, so we have to byteswap for >8bpp formats
2847  * on BE arches */
2848 #if HAVE_BIGENDIAN
2849  if (pixel_shift && !s->checksum_buf) {
2851  FFMAX3(frame->linesize[0], frame->linesize[1],
2852  frame->linesize[2]));
2853  if (!s->checksum_buf)
2854  return AVERROR(ENOMEM);
2855  }
2856 #endif
2857 
2858  for (i = 0; frame->data[i]; i++) {
2859  int width = s->avctx->coded_width;
2860  int height = s->avctx->coded_height;
2861  int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width;
2862  int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height;
2863  uint8_t md5[16];
2864 
2865  av_md5_init(s->md5_ctx);
2866  for (j = 0; j < h; j++) {
2867  const uint8_t *src = frame->data[i] + j * frame->linesize[i];
2868 #if HAVE_BIGENDIAN
2869  if (pixel_shift) {
2870  s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf,
2871  (const uint16_t *) src, w);
2872  src = s->checksum_buf;
2873  }
2874 #endif
2875  av_md5_update(s->md5_ctx, src, w << pixel_shift);
2876  }
2877  av_md5_final(s->md5_ctx, md5);
2878 
2879  if (!memcmp(md5, s->md5[i], 16)) {
2880  av_log (s->avctx, AV_LOG_DEBUG, "plane %d - correct ", i);
2881  print_md5(s->avctx, AV_LOG_DEBUG, md5);
2882  av_log (s->avctx, AV_LOG_DEBUG, "; ");
2883  } else {
2884  av_log (s->avctx, AV_LOG_ERROR, "mismatching checksum of plane %d - ", i);
2885  print_md5(s->avctx, AV_LOG_ERROR, md5);
2886  av_log (s->avctx, AV_LOG_ERROR, " != ");
2887  print_md5(s->avctx, AV_LOG_ERROR, s->md5[i]);
2888  av_log (s->avctx, AV_LOG_ERROR, "\n");
2889  return AVERROR_INVALIDDATA;
2890  }
2891  }
2892 
2893  av_log(s->avctx, AV_LOG_DEBUG, "\n");
2894 
2895  return 0;
2896 }
2897 
2898 static int hevc_decode_frame(AVCodecContext *avctx, void *data, int *got_output,
2899  AVPacket *avpkt)
2900 {
2901  int ret;
2902  HEVCContext *s = avctx->priv_data;
2903 
2904  if (!avpkt->size) {
2905  ret = ff_hevc_output_frame(s, data, 1);
2906  if (ret < 0)
2907  return ret;
2908  if (ret == 1)
2909  return AVERROR_INVALIDDATA;
2910 
2911  *got_output = ret;
2912  return 0;
2913  }
2914 
2915  s->ref = NULL;
2916  ret = decode_nal_units(s, avpkt->data, avpkt->size);
2917  if (ret < 0)
2918  return ret;
2919 
2920  /* verify the SEI checksum */
2921  if (avctx->err_recognition & AV_EF_CRCCHECK && s->is_decoded &&
2922  s->is_md5) {
2923  ret = verify_md5(s, s->ref->frame);
2924  if (ret < 0 && avctx->err_recognition & AV_EF_EXPLODE) {
2925  ff_hevc_unref_frame(s, s->ref, ~0);
2926  return ret;
2927  }
2928  }
2929  s->is_md5 = 0;
2930 
2931  if (s->is_decoded) {
2932  av_log(avctx, AV_LOG_DEBUG, "Decoded frame with POC %d.\n", s->poc);
2933  s->is_decoded = 0;
2934  }
2935 
2936  if (s->output_frame->buf[0]) {
2937  av_frame_move_ref(data, s->output_frame);
2938  *got_output = 1;
2939  }
2940 
2941  return avpkt->size;
2942 }
2943 
2944 static int hevc_ref_frame(HEVCContext *s, HEVCFrame *dst, HEVCFrame *src)
2945 {
2946  int ret = ff_thread_ref_frame(&dst->tf, &src->tf);
2947  if (ret < 0)
2948  return ret;
2949 
2950  dst->tab_mvf_buf = av_buffer_ref(src->tab_mvf_buf);
2951  if (!dst->tab_mvf_buf)
2952  goto fail;
2953  dst->tab_mvf = src->tab_mvf;
2954 
2955  dst->rpl_tab_buf = av_buffer_ref(src->rpl_tab_buf);
2956  if (!dst->rpl_tab_buf)
2957  goto fail;
2958  dst->rpl_tab = src->rpl_tab;
2959 
2960  dst->rpl_buf = av_buffer_ref(src->rpl_buf);
2961  if (!dst->rpl_buf)
2962  goto fail;
2963 
2964  dst->poc = src->poc;
2965  dst->ctb_count = src->ctb_count;
2966  dst->window = src->window;
2967  dst->flags = src->flags;
2968  dst->sequence = src->sequence;
2969 
2970  return 0;
2971 fail:
2972  ff_hevc_unref_frame(s, dst, ~0);
2973  return AVERROR(ENOMEM);
2974 }
2975 
2977 {
2978  HEVCContext *s = avctx->priv_data;
2979  int i;
2980 
2981  pic_arrays_free(s);
2982 
2983  av_freep(&s->md5_ctx);
2984 
2985  av_frame_free(&s->tmp_frame);
2987 
2988  for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
2989  ff_hevc_unref_frame(s, &s->DPB[i], ~0);
2990  av_frame_free(&s->DPB[i].frame);
2991  }
2992 
2993  for (i = 0; i < FF_ARRAY_ELEMS(s->vps_list); i++)
2994  av_buffer_unref(&s->vps_list[i]);
2995  for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++)
2996  av_buffer_unref(&s->sps_list[i]);
2997  for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++)
2998  av_buffer_unref(&s->pps_list[i]);
2999 
3000  for (i = 0; i < s->nals_allocated; i++)
3001  av_freep(&s->nals[i].rbsp_buffer);
3002  av_freep(&s->nals);
3003  s->nals_allocated = 0;
3004 
3005  return 0;
3006 }
3007 
3009 {
3010  HEVCContext *s = avctx->priv_data;
3011  int i;
3012 
3013  s->avctx = avctx;
3014 
3015  s->tmp_frame = av_frame_alloc();
3016  if (!s->tmp_frame)
3017  goto fail;
3018 
3020  if (!s->output_frame)
3021  goto fail;
3022 
3023  for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
3024  s->DPB[i].frame = av_frame_alloc();
3025  if (!s->DPB[i].frame)
3026  goto fail;
3027  s->DPB[i].tf.f = s->DPB[i].frame;
3028  }
3029 
3030  s->max_ra = INT_MAX;
3031 
3032  s->md5_ctx = av_md5_alloc();
3033  if (!s->md5_ctx)
3034  goto fail;
3035 
3036  ff_bswapdsp_init(&s->bdsp);
3037 
3038  s->context_initialized = 1;
3039 
3040  return 0;
3041 
3042 fail:
3043  hevc_decode_free(avctx);
3044  return AVERROR(ENOMEM);
3045 }
3046 
3048  const AVCodecContext *src)
3049 {
3050  HEVCContext *s = dst->priv_data;
3051  HEVCContext *s0 = src->priv_data;
3052  int i, ret;
3053 
3054  if (!s->context_initialized) {
3055  ret = hevc_init_context(dst);
3056  if (ret < 0)
3057  return ret;
3058  }
3059 
3060  for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
3061  ff_hevc_unref_frame(s, &s->DPB[i], ~0);
3062  if (s0->DPB[i].frame->buf[0]) {
3063  ret = hevc_ref_frame(s, &s->DPB[i], &s0->DPB[i]);
3064  if (ret < 0)
3065  return ret;
3066  }
3067  }
3068 
3069  for (i = 0; i < FF_ARRAY_ELEMS(s->vps_list); i++) {
3070  av_buffer_unref(&s->vps_list[i]);
3071  if (s0->vps_list[i]) {
3072  s->vps_list[i] = av_buffer_ref(s0->vps_list[i]);
3073  if (!s->vps_list[i])
3074  return AVERROR(ENOMEM);
3075  }
3076  }
3077 
3078  for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++) {
3079  av_buffer_unref(&s->sps_list[i]);
3080  if (s0->sps_list[i]) {
3081  s->sps_list[i] = av_buffer_ref(s0->sps_list[i]);
3082  if (!s->sps_list[i])
3083  return AVERROR(ENOMEM);
3084  }
3085  }
3086 
3087  for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) {
3088  av_buffer_unref(&s->pps_list[i]);
3089  if (s0->pps_list[i]) {
3090  s->pps_list[i] = av_buffer_ref(s0->pps_list[i]);
3091  if (!s->pps_list[i])
3092  return AVERROR(ENOMEM);
3093  }
3094  }
3095 
3096  if (s->sps != s0->sps)
3097  ret = set_sps(s, s0->sps);
3098 
3099  s->seq_decode = s0->seq_decode;
3100  s->seq_output = s0->seq_output;
3101  s->pocTid0 = s0->pocTid0;
3102  s->max_ra = s0->max_ra;
3103 
3104  s->is_nalff = s0->is_nalff;
3106 
3107  if (s0->eos) {
3108  s->seq_decode = (s->seq_decode + 1) & 0xff;
3109  s->max_ra = INT_MAX;
3110  }
3111 
3112  return 0;
3113 }
3114 
3116 {
3117  AVCodecContext *avctx = s->avctx;
3118  GetByteContext gb;
3119  int ret;
3120 
3121  bytestream2_init(&gb, avctx->extradata, avctx->extradata_size);
3122 
3123  if (avctx->extradata_size > 3 &&
3124  (avctx->extradata[0] || avctx->extradata[1] ||
3125  avctx->extradata[2] > 1)) {
3126  /* It seems the extradata is encoded as hvcC format.
3127  * Temporarily, we support configurationVersion==0 until 14496-15 3rd
3128  * is finalized. When finalized, configurationVersion will be 1 and we
3129  * can recognize hvcC by checking if avctx->extradata[0]==1 or not. */
3130  int i, j, num_arrays, nal_len_size;
3131 
3132  s->is_nalff = 1;
3133 
3134  bytestream2_skip(&gb, 21);
3135  nal_len_size = (bytestream2_get_byte(&gb) & 3) + 1;
3136  num_arrays = bytestream2_get_byte(&gb);
3137 
3138  /* nal units in the hvcC always have length coded with 2 bytes,
3139  * so put a fake nal_length_size = 2 while parsing them */
3140  s->nal_length_size = 2;
3141 
3142  /* Decode nal units from hvcC. */
3143  for (i = 0; i < num_arrays; i++) {
3144  int type = bytestream2_get_byte(&gb) & 0x3f;
3145  int cnt = bytestream2_get_be16(&gb);
3146 
3147  for (j = 0; j < cnt; j++) {
3148  // +2 for the nal size field
3149  int nalsize = bytestream2_peek_be16(&gb) + 2;
3150  if (bytestream2_get_bytes_left(&gb) < nalsize) {
3152  "Invalid NAL unit size in extradata.\n");
3153  return AVERROR_INVALIDDATA;
3154  }
3155 
3156  ret = decode_nal_units(s, gb.buffer, nalsize);
3157  if (ret < 0) {
3158  av_log(avctx, AV_LOG_ERROR,
3159  "Decoding nal unit %d %d from hvcC failed\n",
3160  type, i);
3161  return ret;
3162  }
3163  bytestream2_skip(&gb, nalsize);
3164  }
3165  }
3166 
3167  /* Now store right nal length size, that will be used to parse
3168  * all other nals */
3169  s->nal_length_size = nal_len_size;
3170  } else {
3171  s->is_nalff = 0;
3172  ret = decode_nal_units(s, avctx->extradata, avctx->extradata_size);
3173  if (ret < 0)
3174  return ret;
3175  }
3176  return 0;
3177 }
3178 
3180 {
3181  HEVCContext *s = avctx->priv_data;
3182  int ret;
3183 
3185 
3186  avctx->internal->allocate_progress = 1;
3187 
3188  ret = hevc_init_context(avctx);
3189  if (ret < 0)
3190  return ret;
3191 
3192  if (avctx->extradata_size > 0 && avctx->extradata) {
3193  ret = hevc_decode_extradata(s);
3194  if (ret < 0) {
3195  hevc_decode_free(avctx);
3196  return ret;
3197  }
3198  }
3199 
3200  return 0;
3201 }
3202 
3204 {
3205  HEVCContext *s = avctx->priv_data;
3206  int ret;
3207 
3208  memset(s, 0, sizeof(*s));
3209 
3210  ret = hevc_init_context(avctx);
3211  if (ret < 0)
3212  return ret;
3213 
3214  return 0;
3215 }
3216 
3218 {
3219  HEVCContext *s = avctx->priv_data;
3220  ff_hevc_flush_dpb(s);
3221  s->max_ra = INT_MAX;
3222 }
3223 
3224 #define OFFSET(x) offsetof(HEVCContext, x)
3225 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
3226 
3227 static const AVProfile profiles[] = {
3228  { FF_PROFILE_HEVC_MAIN, "Main" },
3229  { FF_PROFILE_HEVC_MAIN_10, "Main 10" },
3230  { FF_PROFILE_HEVC_MAIN_STILL_PICTURE, "Main Still Picture" },
3231  { FF_PROFILE_UNKNOWN },
3232 };
3233 
3234 static const AVOption options[] = {
3235  { "apply_defdispwin", "Apply default display window from VUI", OFFSET(apply_defdispwin),
3236  AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, PAR },
3237  { NULL },
3238 };
3239 
3240 static const AVClass hevc_decoder_class = {
3241  .class_name = "HEVC decoder",
3242  .item_name = av_default_item_name,
3243  .option = options,
3244  .version = LIBAVUTIL_VERSION_INT,
3245 };
3246 
3248  .name = "hevc",
3249  .long_name = NULL_IF_CONFIG_SMALL("HEVC (High Efficiency Video Coding)"),
3250  .type = AVMEDIA_TYPE_VIDEO,
3251  .id = AV_CODEC_ID_HEVC,
3252  .priv_data_size = sizeof(HEVCContext),
3253  .priv_class = &hevc_decoder_class,
3258  .update_thread_context = hevc_update_thread_context,
3259  .init_thread_copy = hevc_init_thread_copy,
3260  .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY |
3262  .profiles = NULL_IF_CONFIG_SMALL(profiles),
3263 };
int nals_allocated
Definition: hevc.h:833
#define EDGE_EMU_BUFFER_STRIDE
Definition: hevc.h:74
static const uint8_t horiz_scan2x2_x[4]
Definition: hevc.c:47
int frame_packing_arrangement_type
Definition: hevc.h:852
uint8_t ctb_up_flag
Definition: hevc.h:730
AVFrame * frame
Definition: hevc.h:666
unsigned int log2_min_cb_size
Definition: hevc.h:435
int sei_frame_packing_present
frame packing arrangement variables
Definition: hevc.h:851
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
int ff_hevc_merge_idx_decode(HEVCContext *s)
Definition: hevc_cabac.c:619
HEVCPredContext hpc
Definition: hevc.h:798
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
int pic_order_cnt_lsb
Definition: hevc.h:538
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:106
int ff_hevc_frame_nb_refs(HEVCContext *s)
Get the number of candidate references for the current frame.
Definition: hevc_refs.c:470
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1599
int quincunx_subsampling
Definition: hevc.h:854
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
HEVCFrame * ref
Definition: hevc.h:786
static void restore_tqb_pixels(HEVCContext *s)
Definition: hevc.c:2372
#define EPEL_EXTRA_AFTER
Definition: hevc.h:71
Definition: hevc.h:623
void(* put_hevc_epel[2][2])(int16_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride, int width, int height, int mx, int my, int16_t *mcbuffer)
Definition: hevcdsp.h:64
int ctb_height
Definition: hevc.h:449
void(* put_pcm)(uint8_t *dst, ptrdiff_t stride, int size, GetBitContext *gb, int pcm_bit_depth)
Definition: hevcdsp.h:42
uint8_t is_cu_qp_delta_coded
Definition: hevc.h:653
static void hls_mvd_coding(HEVCContext *s, int x0, int y0, int log2_cb_size)
Definition: hevc.c:1467
AVOption.
Definition: opt.h:234
Views are alternated temporally.
Definition: stereo3d.h:66
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
Definition: golomb.h:179
int ff_hevc_merge_flag_decode(HEVCContext *s)
Definition: hevc_cabac.c:630
Definition: hevc.h:96
int ff_hevc_sao_band_position_decode(HEVCContext *s)
Definition: hevc_cabac.c:432
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1244
VideoDSPContext vdsp
Definition: hevc.h:800
uint8_t edge_emu_buffer[(MAX_PB_SIZE+7)*EDGE_EMU_BUFFER_STRIDE *2]
Definition: hevc.h:737
static void hevc_await_progress(HEVCContext *s, HEVCFrame *ref, const Mv *mv, int y0, int height)
Definition: hevc.c:1623
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
int ff_hevc_decode_nal_sps(HEVCContext *s)
Definition: hevc_ps.c:609
Views are next to each other, but when upscaling apply a checkerboard pattern.
Definition: stereo3d.h:87
Definition: hevc.h:200
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:129
int content_interpretation_type
Definition: hevc.h:853
AVFrame * f
Definition: thread.h:36
int ff_hevc_cbf_luma_decode(HEVCContext *s, int trafo_depth)
Definition: hevc_cabac.c:712
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:393
int vps_id
Definition: hevc.h:384
int16_t x
horizontal component of motion vector
Definition: hevc.h:619
void(* bswap16_buf)(uint16_t *dst, const uint16_t *src, int len)
Definition: bswapdsp.h:26
Definition: h264.h:115
static int hevc_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Definition: hevc.c:3047
#define MAX_REFS
Definition: hevc.h:42
int sei_hflip
Definition: hevc.h:859
uint8_t nb_refs
Definition: hevc.h:272
MvField * tab_mvf
Definition: hevc.h:668
int pic_init_qp_minus26
Definition: hevc.h:473
static int set_sps(HEVCContext *s, const HEVCSPS *sps)
Definition: hevc.c:386
int bs_width
Definition: hevc.h:793
int ff_hevc_end_of_slice_flag_decode(HEVCContext *s)
Definition: hevc_cabac.c:464
uint8_t intra_split_flag
IntraSplitFlag.
Definition: hevc.h:613
#define MAX_PPS_COUNT
Definition: h264.h:50
VUI vui
Definition: hevc.h:408
AVFrame * sao_frame
Definition: hevc.h:764
int rem_intra_luma_pred_mode
Definition: hevc.h:641
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1782
int vshift[3]
Definition: hevc.h:459
void(* put_hevc_qpel[4][4])(int16_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride, int width, int height, int16_t *mcbuffer)
Definition: hevcdsp.h:61
int num
numerator
Definition: rational.h:44
void ff_hevc_luma_mv_merge_mode(HEVCContext *s, int x0, int y0, int nPbW, int nPbH, int log2_cb_size, int part_idx, int merge_idx, MvField *mv)
Definition: hevc_mvs.c:546
int size
Definition: avcodec.h:974
int ff_hevc_significant_coeff_group_flag_decode(HEVCContext *s, int c_idx, int ctx_cg)
Definition: hevc_cabac.c:763
unsigned int slice_addr
Definition: hevc.h:534
uint32_t vui_time_scale
Definition: hevc.h:320
int nb_nals
Definition: hevc.h:832
uint8_t weighted_bipred_flag
Definition: hevc.h:485
void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags)
Definition: hevc_refs.c:30
int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header)
Definition: hevc_ps.c:73
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:58
#define MAX_PB_SIZE
Definition: hevc.h:58
int tc_offset
Definition: hevc.h:658
int ff_hevc_rem_intra_luma_pred_mode_decode(HEVCContext *s)
Definition: hevc_cabac.c:598
void(* put_unweighted_pred)(uint8_t *dst, ptrdiff_t dststride, int16_t *src, ptrdiff_t srcstride, int width, int height)
Definition: hevcdsp.h:68
PredictionUnit pu
Definition: hevc.h:740
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1270
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:132
static void intra_prediction_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
Definition: hevc.c:1994
uint8_t seq_loop_filter_across_slices_enabled_flag
Definition: hevc.h:498
uint8_t cabac_init_present_flag
Definition: hevc.h:469
int16_t chroma_offset_l1[16][2]
Definition: hevc.h:592
void ff_hevc_hls_filter(HEVCContext *s, int x, int y)
Definition: hevc_filter.c:729
Definition: hevc.h:246
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everythnig contained in src to dst and reset src.
Definition: frame.c:300
int ff_hevc_frame_rps(HEVCContext *s)
Construct the reference picture sets for the current frame.
Definition: hevc_refs.c:388
#define FF_ARRAY_ELEMS(a)
int x
Definition: hevc.h:602
int ff_hevc_coeff_abs_level_greater2_flag_decode(HEVCContext *s, int c_idx, int inc)
Definition: hevc_cabac.c:831
int min_cb_height
Definition: hevc.h:452
int * ctb_addr_ts_to_rs
CtbAddrTSToRS.
Definition: hevc.h:522
int num_ref_idx_l0_default_active
num_ref_idx_l0_default_active_minus1 + 1
Definition: hevc.h:471
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
struct HEVCFrame * ref[MAX_REFS]
Definition: hevc.h:276
uint8_t dependent_slice_segment_flag
Definition: hevc.h:541
CABACContext cc
Definition: hevc.h:722
ShortTermRPS slice_rps
Definition: hevc.h:546
int profile
profile
Definition: avcodec.h:2638
ShortTermRPS st_rps[MAX_SHORT_TERM_RPS_COUNT]
Definition: hevc.h:415
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:2812
int width
Definition: hevc.h:446
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
int ff_hevc_sao_type_idx_decode(HEVCContext *s)
Definition: hevc_cabac.c:422
uint16_t seq_decode
Sequence counters for decoded and output frames, so that old frames are output first after a POC rese...
Definition: hevc.h:828
enum NALUnitType first_nal_type
Definition: hevc.h:835
Macro definitions for various function/variable attributes.
int qp_bd_offset
Definition: hevc.h:461
int pixel_shift
Definition: hevc.h:395
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1175
uint8_t entropy_coding_sync_enabled_flag
Definition: hevc.h:491
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
int max_ra
Definition: hevc.h:792
int ff_hevc_cu_transquant_bypass_flag_decode(HEVCContext *s)
Definition: hevc_cabac.c:469
static int hls_slice_data(HEVCContext *s)
Definition: hevc.c:2305
int output_width
Definition: hevc.h:389
const uint8_t ff_hevc_qpel_extra_before[4]
Definition: hevc.c:41
static void hls_sao_param(HEVCContext *s, int rx, int ry)
Definition: hevc.c:818
#define AV_RN32A(p)
Definition: intreadwrite.h:446
AVBufferPool * rpl_tab_pool
candidate references for the current frame
Definition: hevc.h:776
CodingTree ct
Definition: hevc.h:738
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:38
#define PAR
Definition: hevc.c:3225
int ff_hevc_last_significant_coeff_y_prefix_decode(HEVCContext *s, int c_idx, int log2_size)
Definition: hevc_cabac.c:745
int chroma_format_idc
Definition: hevc.h:385
uint8_t disable_dbf
Definition: hevc.h:502
unsigned int log2_max_trafo_size
Definition: hevc.h:438
unsigned int slice_segment_addr
address (in raster order) of the first block in the current slice
Definition: hevc.h:532
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:275
struct AVMD5 * av_md5_alloc(void)
Definition: md5.c:49
int ff_hevc_mpm_idx_decode(HEVCContext *s)
Definition: hevc_cabac.c:590
int ff_hevc_coeff_abs_level_greater1_flag_decode(HEVCContext *s, int c_idx, int ctx_set)
Definition: hevc_cabac.c:822
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:97
int end_of_tiles_x
Definition: hevc.h:734
uint8_t
#define av_cold
Definition: attributes.h:66
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:57
int ff_hevc_skip_flag_decode(HEVCContext *s, int x0, int y0, int x_cb, int y_cb)
Definition: hevc_cabac.c:474
InterPredIdc
Definition: hevc.h:199
struct HEVCSPS::@23 pcm
float delta
AVOptions.
Stereo 3D type: this structure describes how two videos are packed within a single video surface...
Definition: stereo3d.h:123
static int set_side_data(HEVCContext *s)
Definition: hevc.c:2399
uint8_t ctb_up_right_flag
Definition: hevc.h:731
LongTermRPS long_term_rps
Definition: hevc.h:548
const uint8_t * data
Definition: hevc.h:698
int poc[32]
Definition: hevc.h:270
uint8_t vps_timing_info_present_flag
Definition: hevc.h:368
int ff_hevc_abs_mvd_greater0_flag_decode(HEVCContext *s)
Definition: hevc_cabac.c:671
uint8_t matrix_coeffs
Definition: hevc.h:305
static int hls_slice_header(HEVCContext *s)
Definition: hevc.c:456
int min_tb_width
Definition: hevc.h:453
int depth
ctDepth
Definition: hevc.h:598
uint8_t * rbsp_buffer
Definition: hevc.h:694
int num_entry_point_offsets
Definition: hevc.h:576
#define FF_PROFILE_HEVC_MAIN
Definition: avcodec.h:2712
AVFrame * output_frame
Definition: hevc.h:766
SAOParams * sao
Definition: hevc.h:782
int num_ref_idx_l1_default_active
num_ref_idx_l1_default_active_minus1 + 1
Definition: hevc.h:472
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1164
unsigned int log2_min_pcm_cb_size
Definition: hevc.h:428
AVCodecContext * avctx
Definition: hevc.h:754
int min_cb_width
Definition: hevc.h:451
static void luma_mc(HEVCContext *s, int16_t *dst, ptrdiff_t dststride, AVFrame *ref, const Mv *mv, int x_off, int y_off, int block_w, int block_h)
8.5.3.2.2.1 Luma sample interpolation process
Definition: hevc.c:1504
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:684
static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
Definition: hevc.c:2056
const char data[16]
Definition: mxf.c:70
uint8_t scaling_list_data_present_flag
Definition: hevc.h:506
HEVCNAL * nals
Definition: hevc.h:831
BswapDSPContext bdsp
Definition: hevc.h:801
ThreadFrame tf
Definition: hevc.h:667
uint8_t first_slice_in_pic_flag
Definition: hevc.h:540
uint8_t * data
Definition: avcodec.h:973
uint8_t bit_depth_chroma
Definition: hevc.h:427
const uint8_t * buffer
Definition: bytestream.h:33
uint8_t ctb_up_left_flag
Definition: hevc.h:732
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:2349
#define STARTCODE_TEST
#define MAX_TB_SIZE
Definition: hevc.h:57
int ff_hevc_decode_nal_sei(HEVCContext *s)
Definition: hevc_sei.c:134
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition: utils.c:145
void(* put_weighted_pred_avg)(uint8_t *dst, ptrdiff_t dststride, int16_t *src1, int16_t *src2, ptrdiff_t srcstride, int width, int height)
Definition: hevcdsp.h:70
Definition: hevc.h:201
#define EPEL_EXTRA_BEFORE
Definition: hevc.h:70
int8_t * qp_y_tab
Definition: hevc.h:802
uint8_t loop_filter_disable_flag
Definition: hevc.h:430
int ff_hevc_mvd_decode(HEVCContext *s)
Definition: hevc_cabac.c:681
static void print_md5(void *log_ctx, int level, uint8_t md5[16])
Definition: hevc.c:2825
int sei_anticlockwise_rotation
Definition: hevc.h:858
uint8_t pic_output_flag
Definition: hevc.h:542
uint8_t * tab_ct_depth
Definition: hevc.h:810
void ff_hevc_flush_dpb(HEVCContext *s)
Drop all frames currently in DPB.
Definition: hevc_refs.c:71
static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb)
Definition: hevc.c:334
uint8_t cu_transquant_bypass_flag
Definition: hevc.h:615
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
#define FF_PROFILE_HEVC_MAIN_10
Definition: avcodec.h:2713
static av_unused const uint8_t * skip_bytes(CABACContext *c, int n)
Skip n bytes and reset the decoder.
uint8_t transquant_bypass_enable_flag
Definition: hevc.h:487
#define FFUMOD(a, b)
Definition: hevc.h:88
uint8_t used[32]
Definition: hevc.h:271
int ff_hevc_sao_offset_sign_decode(HEVCContext *s)
Definition: hevc_cabac.c:452
int temporal_id
temporal_id_plus1 - 1
Definition: hevc.h:785
#define SET_SAO(elem, value)
Definition: hevc.c:806
uint8_t first_qp_group
Definition: hevc.h:719
HEVCDSPContext hevcdsp
Definition: hevc.h:799
int ctb_count
Definition: hevc.h:671
uint8_t no_output_of_prior_pics_flag
Definition: hevc.h:552
struct HEVCSPS::@22 temporal_layer[MAX_SUB_LAYERS]
static void hevc_decode_flush(AVCodecContext *avctx)
Definition: hevc.c:3217
int slice_idx
number of the slice being currently decoded
Definition: hevc.h:790
#define BOUNDARY_UPPER_SLICE
Definition: hevc.h:745
uint8_t intra_pred_mode[4]
Definition: hevc.h:642
const HEVCSPS * sps
Definition: hevc.h:769
uint8_t colour_plane_id
RPS coded in the slice header itself is stored here.
Definition: hevc.h:543
uint16_t depth_minus1
Number of bits in the component minus 1.
Definition: pixdesc.h:57
void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len)
Definition: md5.c:144
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:1355
int flags
Additional information about the frame packing.
Definition: stereo3d.h:132
static av_cold int hevc_init_thread_copy(AVCodecContext *avctx)
Definition: hevc.c:3203
void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, int log2_trafo_size)
Definition: hevc_filter.c:586
uint8_t slice_initialized
1 if the independent slice segment header was successfully parsed
Definition: hevc.h:761
static int extract_rbsp(const uint8_t *src, int length, HEVCNAL *nal)
Definition: hevc.c:2638
unsigned int log2_max_poc_lsb
Definition: hevc.h:398
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
void(* transform_add[4])(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
Definition: hevcdsp.h:51
int min_pu_height
Definition: hevc.h:456
AVBufferRef * vps_list[MAX_VPS_COUNT]
Definition: hevc.h:771
static void chroma_mc(HEVCContext *s, int16_t *dst1, int16_t *dst2, ptrdiff_t dststride, AVFrame *ref, const Mv *mv, int x_off, int y_off, int block_w, int block_h)
8.5.3.2.2.2 Chroma sample interpolation process
Definition: hevc.c:1558
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:713
AVBufferRef * rpl_tab_buf
Definition: hevc.h:678
#define AVERROR(e)
Definition: error.h:43
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:161
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:69
uint8_t rpl_modification_flag[2]
Definition: hevc.h:551
int vui_timing_info_present_flag
Definition: hevc.h:318
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:145
Definition: hevc.h:186
RefPicList * refPicList
Definition: hevc.h:669
int16_t luma_offset_l0[16]
Definition: hevc.h:588
HEVCLocalContext HEVClc
Definition: hevc.h:756
static av_always_inline av_const int av_clip_c(int a, int amin, int amax)
Clip a signed integer value into the amin-amax range.
Definition: common.h:93
int bs_height
Definition: hevc.h:794
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
void(* intra_pred[4])(struct HEVCContext *s, int x0, int y0, int c_idx)
Definition: hevc.h:704
int ff_hevc_compute_poc(HEVCContext *s, int poc_lsb)
Compute POC of the current frame and return it.
Definition: hevc_refs.c:447
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:151
unsigned int log2_ctb_size
Definition: hevc.h:439
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
int tc_offset
tc_offset_div2 * 2
Definition: hevc.h:572
const char * name
Name of the codec implementation.
Definition: avcodec.h:2819
const ShortTermRPS * short_term_rps
Definition: hevc.h:547
uint8_t merge_flag
Definition: hevc.h:644
void(* weighted_pred)(uint8_t denom, int16_t wlxFlag, int16_t olxFlag, uint8_t *dst, ptrdiff_t dststride, int16_t *src, ptrdiff_t srcstride, int width, int height)
Definition: hevcdsp.h:73
void ff_init_cabac_states(void)
Definition: cabac.c:124
void(* transquant_bypass[4])(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
Definition: hevcdsp.h:45
struct AVMD5 * md5_ctx
Definition: hevc.h:838
void ff_hevc_save_states(HEVCContext *s, int ctb_addr_ts)
Definition: hevc_cabac.c:326
int8_t slice_qp
Definition: hevc.h:578
static int verify_md5(HEVCContext *s, AVFrame *frame)
Definition: hevc.c:2832
static const AVClass hevc_decoder_class
Definition: hevc.c:3240
uint8_t max_trafo_depth
MaxTrafoDepth.
Definition: hevc.h:614
uint16_t sequence
A sequence counter, so that old frames are output first after a POC reset.
Definition: hevc.h:685
uint8_t colour_primaries
Definition: hevc.h:303
uint8_t slice_temporal_mvp_enabled_flag
Definition: hevc.h:553
uint8_t * vertical_bs
Definition: hevc.h:804
static char * split(char *message, char delim)
Definition: af_channelmap.c:85
uint8_t tiles_enabled_flag
Definition: hevc.h:490
int ff_hevc_decode_nal_vps(HEVCContext *s)
Definition: hevc_ps.c:322
int eo_class[3]
sao_eo_class
Definition: hevcdsp.h:34
uint32_t vps_num_units_in_tick
Definition: hevc.h:369
static av_cold int hevc_init_context(AVCodecContext *avctx)
Definition: hevc.c:3008
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
int16_t luma_weight_l0[16]
Definition: hevc.h:583
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
const HEVCPPS * pps
Definition: hevc.h:770
int * col_idxX
Definition: hevc.h:519
int ff_hevc_mvd_sign_flag_decode(HEVCContext *s)
Definition: hevc_cabac.c:697
int slice_qp_delta
Definition: hevc.h:567
common internal API header
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:531
int ff_hevc_mvp_lx_flag_decode(HEVCContext *s)
Definition: hevc_cabac.c:661
uint8_t is_intra
Definition: hevc.h:627
uint8_t lists_modification_present_flag
Definition: hevc.h:509
uint8_t profile_idc
Definition: hevc.h:339
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
Definition: videodsp.c:37
AVBufferRef * tab_mvf_buf
Definition: hevc.h:677
int ff_hevc_coeff_abs_level_remaining(HEVCContext *s, int base_level, int rc_rice_param)
Definition: hevc_cabac.c:839
uint8_t type_idx[3]
sao_type_idx
Definition: hevcdsp.h:38
int beta_offset
beta_offset_div2 * 2
Definition: hevc.h:571
const uint8_t ff_hevc_qpel_extra[4]
Definition: hevc.c:43
int ff_hevc_transform_skip_flag_decode(HEVCContext *s, int c_idx)
Definition: hevc_cabac.c:717
const uint8_t ff_hevc_qpel_extra_after[4]
Definition: hevc.c:42
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2422
int max_transform_hierarchy_depth_inter
Definition: hevc.h:442
#define IS_IDR(s)
Definition: hevc.h:82
#define FFMIN(a, b)
Definition: common.h:57
void(* weighted_pred_avg)(uint8_t denom, int16_t wl0Flag, int16_t wl1Flag, int16_t ol0Flag, int16_t ol1Flag, uint8_t *dst, ptrdiff_t dststride, int16_t *src1, int16_t *src2, ptrdiff_t srcstride, int width, int height)
Definition: hevcdsp.h:76
int16_t mc_buffer[(64+7)*64]
Definition: hevc.h:716
static const AVOption options[]
Definition: hevc.c:3234
int rbsp_buffer_size
Definition: hevc.h:695
int slice_cr_qp_offset
Definition: hevc.h:569
int offset_abs[3][4]
sao_offset_abs
Definition: hevcdsp.h:29
int output_height
Definition: hevc.h:389
int width
picture width / height.
Definition: avcodec.h:1229
int ff_hevc_output_frame(HEVCContext *s, AVFrame *frame, int flush)
Find next frame in output order and put a reference to it in frame.
Definition: hevc_refs.c:154
uint8_t * tab_ipm
Definition: hevc.h:812
int size
Definition: hevc.h:697
static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
Definition: hevc.c:2733
void ff_hevc_hls_filters(HEVCContext *s, int x_ctb, int y_ctb, int ctb_size)
Definition: hevc_filter.c:736
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:2639
static int luma_intra_pred_mode(HEVCContext *s, int x0, int y0, int pu_size, int prev_intra_luma_pred_flag)
8.4.1
Definition: hevc.c:1893
int hshift[3]
Definition: hevc.h:458
int ff_hevc_part_mode_decode(HEVCContext *s, int log2_cb_size)
Definition: hevc_cabac.c:543
#define FF_PROFILE_HEVC_MAIN_STILL_PICTURE
Definition: avcodec.h:2714
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
#define OFFSET(x)
Definition: hevc.c:3224
AVBufferRef * sps_list[MAX_SPS_COUNT]
Definition: hevc.h:772
int32_t
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:114
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1761
uint8_t cu_qp_delta_enabled_flag
Definition: hevc.h:478
uint8_t used_by_curr_pic_lt_sps_flag[32]
Definition: hevc.h:422
int8_t qp_y
Definition: hevc.h:724
static int hls_pcm_sample(HEVCContext *s, int x0, int y0, int log2_cb_size)
Definition: hevc.c:1437
Definition: hevc.h:133
Context Adaptive Binary Arithmetic Coder inline functions.
int level
level
Definition: avcodec.h:2721
Definition: hevc.h:202
int ctb_width
Definition: hevc.h:448
int16_t chroma_weight_l0[16][2]
Definition: hevc.h:584
void ff_hevc_set_neighbour_available(HEVCContext *s, int x0, int y0, int nPbW, int nPbH)
Definition: hevc_mvs.c:41
uint8_t sl_dc[2][6]
Definition: hevc.h:380
uint8_t sign_data_hiding_flag
Definition: hevc.h:467
int height
Definition: hevc.h:447
#define AV_EF_EXPLODE
Definition: avcodec.h:2433
uint8_t output_flag_present_flag
Definition: hevc.h:486
uint16_t seq_output
Definition: hevc.h:829
Definition: h264.h:116
int mpm_idx
Definition: hevc.h:640
const uint8_t ff_hevc_diag_scan4x4_y[16]
Definition: hevc.c:92
PTLCommon general_ptl
Definition: hevc.h:349
int16_t luma_offset_l1[16]
Definition: hevc.h:591
int offset_val[3][5]
SaoOffsetVal.
Definition: hevcdsp.h:36
int16_t chroma_offset_l0[16][2]
Definition: hevc.h:589
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
void av_display_rotation_set(int32_t matrix[9], double angle)
Initialize a transformation matrix describing a pure rotation by the specified angle (in degrees)...
Definition: display.c:52
static int hevc_frame_start(HEVCContext *s)
Definition: hevc.c:2448
AVBufferRef * pps_list[MAX_PPS_COUNT]
Definition: hevc.h:773
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:365
unsigned int pps_id
address (in raster order) of the first block in the current slice segment
Definition: hevc.h:529
#define IS_BLA(s)
Definition: hevc.h:83
if(ac->has_optimized_func)
uint8_t sl[4][6][64]
Definition: hevc.h:379
uint8_t pic_slice_level_chroma_qp_offsets_present_flag
Definition: hevc.h:483
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
Definition: golomb.h:81
int ff_hevc_split_coding_unit_flag_decode(HEVCContext *s, int ct_depth, int x0, int y0)
Definition: hevc_cabac.c:524
uint32_t vps_time_scale
Definition: hevc.h:370
Definition: hevc.h:132
int colour_description_present_flag
Definition: hevc.h:302
static const int8_t mv[256][2]
Definition: 4xm.c:75
HEVCFrame DPB[32]
Definition: hevc.h:787
Definition: hevc.h:383
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:186
static void hls_prediction_unit(HEVCContext *s, int x0, int y0, int nPbW, int nPbH, int log2_cb_size, int partIdx)
Definition: hevc.c:1630
enum AVPixelFormat pix_fmt
Definition: hevc.h:396
Definition: hevc.h:356
static int hls_transform_unit(HEVCContext *s, int x0, int y0, int xBase, int yBase, int cb_xBase, int cb_yBase, int log2_cb_size, int log2_trafo_size, int trafo_depth, int blk_idx, int cbf_luma, int cbf_cb, int cbf_cr)
Definition: hevc.c:1238
RefPicListTab ** rpl_tab
Definition: hevc.h:670
int sei_display_orientation_present
display orientation
Definition: hevc.h:857
NULL
Definition: eval.c:55
int slice_cb_qp_offset
Definition: hevc.h:568
void ff_hevc_dsp_init(HEVCDSPContext *hevcdsp, int bit_depth)
Definition: hevcdsp.c:114
static int width
Definition: utils.c:156
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:127
#define AV_LOG_INFO
Standard information.
Definition: log.h:134
#define CTB(tab, x, y)
Definition: hevc.c:804
static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)
Definition: hevc.c:189
static void pic_arrays_free(HEVCContext *s)
NOTE: Each function hls_foo correspond to the function foo in the specification (HLS stands for High ...
Definition: hevc.c:165
Definition: hevc.h:464
uint8_t transform_skip_enabled_flag
Definition: hevc.h:476
static av_cold int hevc_decode_init(AVCodecContext *avctx)
Definition: hevc.c:3179
#define IS_IRAP(s)
Definition: hevc.h:85
Definition: hevc.h:693
int ff_hevc_significant_coeff_flag_decode(HEVCContext *s, int c_idx, int x_c, int y_c, int log2_trafo_size, int scan_idx, int prev_sig)
Definition: hevc_cabac.c:772
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: frame.h:84
uint8_t is_nalff
this flag is != 0 if bitstream is encapsulated as a format defined in 14496-15
Definition: hevc.h:843
int * ctb_addr_rs_to_ts
CtbAddrRSToTS.
Definition: hevc.h:521
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:66
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
PTL ptl
Definition: hevc.h:409
int max_sub_layers
Definition: hevc.h:401
unsigned int log2_min_pu_size
Definition: hevc.h:440
int ff_hevc_decode_nal_pps(HEVCContext *s)
Definition: hevc_ps.c:988
int ff_hevc_abs_mvd_greater1_flag_decode(HEVCContext *s)
Definition: hevc_cabac.c:676
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:408
av_default_item_name
Definition: dnxhdenc.c:52
int8_t pred_flag[2]
Definition: hevc.h:626
uint8_t md5[3][16]
Definition: hevc.h:839
unsigned int sps_id
seq_parameter_set_id
Definition: hevc.h:465
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
ScalingList scaling_list
Definition: hevc.h:507
main external API structure.
Definition: avcodec.h:1050
uint8_t is_md5
Definition: hevc.h:840
uint8_t sao_enabled
Definition: hevc.h:418
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
Definition: display.c:67
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
static int hevc_decode_extradata(HEVCContext *s)
Definition: hevc.c:3115
enum PredMode pred_mode
PredMode.
Definition: hevc.h:605
void(* transform_skip)(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
Definition: hevcdsp.h:48
int num_extra_slice_header_bits
Definition: hevc.h:511
uint8_t * data
The data buffer.
Definition: buffer.h:89
int16_t y
vertical component of motion vector
Definition: hevc.h:620
Definition: hevc.h:110
void ff_hevc_clear_refs(HEVCContext *s)
Mark all frames in DPB as unused for reference.
Definition: hevc_refs.c:62
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:621
uint8_t num_long_term_ref_pics_sps
Definition: hevc.h:423
uint8_t * data
Definition: frame.h:104
const HEVCVPS * vps
Definition: hevc.h:768
void av_md5_init(AVMD5 *ctx)
Definition: md5.c:134
TransformUnit tu
Definition: hevc.h:727
static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, int ctb_addr_ts)
Definition: hevc.c:2255
void(* transform_4x4_luma_add)(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
Definition: hevcdsp.h:49
uint32_t vui_num_units_in_tick
Definition: hevc.h:319
int extradata_size
Definition: avcodec.h:1165
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:82
uint8_t ctb_left_flag
Definition: hevc.h:729
int y
Definition: hevc.h:603
AVCodec ff_hevc_decoder
Definition: hevc.c:3247
uint8_t deblocking_filter_control_present_flag
Definition: hevc.h:500
int cu_qp_delta
Definition: hevc.h:649
uint8_t * is_pcm
Definition: hevc.h:815
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:271
void ff_hevc_pred_init(HEVCPredContext *hpc, int bit_depth)
Definition: hevcpred.c:37
uint8_t * checksum_buf
used on BE to byteswap the lines for checksumming
Definition: hevc.h:821
uint8_t sps_temporal_mvp_enabled_flag
Definition: hevc.h:432
unsigned int nb_st_rps
Definition: hevc.h:414
int coded_height
Definition: avcodec.h:1244
AVFrame * tmp_frame
Definition: hevc.h:765
uint8_t cabac_init_flag
Definition: hevc.h:560
Describe the class of an AVClass context structure.
Definition: log.h:33
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:263
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:444
#define POS(c_idx, x, y)
int poc
Definition: hevc.h:672
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:230
static av_always_inline void set_ct_depth(HEVCContext *s, int x0, int y0, int log2_cb_size, int ct_depth)
Definition: hevc.c:1981
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1775
static void pred_weight_table(HEVCContext *s, GetBitContext *gb)
Definition: hevc.c:245
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1768
#define EPEL_EXTRA
Definition: hevc.h:72
AVFrame * frame
Definition: hevc.h:763
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:375
int ff_hevc_sao_eo_class_decode(HEVCContext *s)
Definition: hevc_cabac.c:457
static const uint8_t rem6[QP_MAX_NUM+1]
Definition: h264_slice.c:47
unsigned int max_num_merge_cand
5 - 5_minus_max_num_merge_cand
Definition: hevc.h:574
static const uint8_t diag_scan2x2_inv[2][2]
Definition: hevc.c:80
int checksum_buf_size
Definition: hevc.h:822
DBParams * deblock
Definition: hevc.h:783
GetBitContext gb
Definition: hevc.h:721
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data...
Definition: avcodec.h:2430
unsigned int log2_min_tb_size
Definition: hevc.h:437
int poc
Definition: hevc.h:788
#define L0
Definition: hevc.h:67
enum PartMode part_mode
PartMode.
Definition: hevc.h:606
uint16_t lt_ref_pic_poc_lsb_sps[32]
Definition: hevc.h:421
int ff_hevc_slice_rpl(HEVCContext *s)
Construct the reference picture list(s) for the current slice.
Definition: hevc_refs.c:232
static int hls_nal_unit(HEVCContext *s)
Definition: hevc.c:2350
static const uint8_t horiz_scan4x4_x[16]
Definition: hevc.c:51
enum NALUnitType nal_unit_type
Definition: hevc.h:784
int start_of_tiles_x
Definition: hevc.h:733
Definition: hevc.h:618
void av_md5_final(AVMD5 *ctx, uint8_t *dst)
Definition: md5.c:160
int allocate_progress
Whether to allocate progress for frame threading.
Definition: internal.h:81
HEVCWindow window
Definition: hevc.h:675
uint8_t scaling_list_enable_flag
Definition: hevc.h:411
int * tile_id
TileId.
Definition: hevc.h:523
static void set_deblocking_bypass(HEVCContext *s, int x0, int y0, int log2_cb_size)
Definition: hevc.c:1325
static const uint8_t horiz_scan4x4_y[16]
Definition: hevc.c:58
int16_t luma_weight_l1[16]
Definition: hevc.h:586
int16_t chroma_log2_weight_denom
Definition: hevc.h:581
int tc_offset
tc_offset_div2 * 2
Definition: hevc.h:504
uint8_t transfer_characteristic
Definition: hevc.h:304
int pocTid0
Definition: hevc.h:789
uint8_t flags
A combination of HEVC_FRAME_FLAG_*.
Definition: hevc.h:690
Views are on top of each other.
Definition: stereo3d.h:55
Definition: hevc.h:207
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:283
int cr_qp_offset
Definition: hevc.h:482
ScalingList scaling_list
Definition: hevc.h:412
int ff_hevc_inter_pred_idc_decode(HEVCContext *s, int nPbW, int nPbH)
Definition: hevc_cabac.c:635
int ff_hevc_cbf_cb_cr_decode(HEVCContext *s, int trafo_depth)
Definition: hevc_cabac.c:707
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
Definition: stereo3d.c:32
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
Definition: h264.h:117
int ff_hevc_ref_idx_lx_decode(HEVCContext *s, int num_ref_idx_lx)
Definition: hevc_cabac.c:645
uint8_t level
Definition: svq3.c:147
uint8_t intra_pred_mode_c
Definition: hevc.h:645
static int hls_coding_quadtree(HEVCContext *s, int x0, int y0, int log2_cb_size, int cb_depth)
Definition: hevc.c:2204
uint8_t level_idc
Definition: hevc.h:341
the normal 219*2^(n-8) "MPEG" YUV ranges
Definition: pixfmt.h:364
int eos
current packet contains an EOS/EOB NAL
Definition: hevc.h:791
int height
Definition: gxfenc.c:72
Views are next to each other.
Definition: stereo3d.h:45
int sei_vflip
Definition: hevc.h:859
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
const uint8_t ff_hevc_diag_scan8x8_x[64]
Definition: hevc.c:106
int ff_hevc_intra_chroma_pred_mode_decode(HEVCContext *s)
Definition: hevc_cabac.c:608
int max_transform_hierarchy_depth_intra
coded frame dimension in various units
Definition: hevc.h:443
Mv mv[2]
Definition: hevc.h:624
int ff_hevc_no_residual_syntax_flag_decode(HEVCContext *s)
Definition: hevc_cabac.c:666
uint8_t * skip_flag
Definition: hevc.h:809
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:388
int8_t ref_idx[2]
Definition: hevc.h:625
static void hls_residual_coding(HEVCContext *s, int x0, int y0, int log2_trafo_size, enum ScanType scan_idx, int c_idx)
Definition: hevc.c:889
common internal and external API header
AVBufferPool * av_buffer_pool_init(int size, AVBufferRef *(*alloc)(int size))
Allocate and initialize a buffer pool.
Definition: buffer.c:197
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:755
uint8_t weighted_pred_flag
Definition: hevc.h:484
uint8_t * horizontal_bs
Definition: hevc.h:803
Definition: hevc.h:245
#define BOUNDARY_LEFT_SLICE
Definition: hevc.h:743
static av_cold void flush(AVCodecContext *avctx)
Flush (reset) the frame ID after seeking.
Definition: alsdec.c:1797
unsigned int nb_refs[2]
Definition: hevc.h:555
int32_t * tab_slice_address
Definition: hevc.h:806
uint8_t disable_deblocking_filter_flag
slice_header_disable_deblocking_filter_flag
Definition: hevc.h:561
static int hevc_decode_frame(AVCodecContext *avctx, void *data, int *got_output, AVPacket *avpkt)
Definition: hevc.c:2898
unsigned int * column_width
ColumnWidth.
Definition: hevc.h:515
static const uint8_t diag_scan2x2_x[4]
Definition: hevc.c:76
Definition: hevc.h:97
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:92
AVProfile.
Definition: avcodec.h:2800
uint8_t * filter_slice_edges
Definition: hevc.h:818
uint8_t slice_header_extension_present_flag
Definition: hevc.h:512
uint8_t collocated_list
Definition: hevc.h:563
static int decode_nal_unit(HEVCContext *s, const uint8_t *nal, int length)
Definition: hevc.c:2498
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:160
int ff_hevc_coeff_sign_flag(HEVCContext *s, uint8_t nb)
Definition: hevc_cabac.c:864
int nal_length_size
Number of bytes used for nal length (1, 2 or 4)
Definition: hevc.h:847
int den
denominator
Definition: rational.h:45
int slice_ctb_addr_rs
Definition: hevc.h:594
void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, int nPbH, int log2_cb_size, int part_idx, int merge_idx, MvField *mv, int mvp_lx_flag, int LX)
Definition: hevc_mvs.c:645
AVBufferPool * tab_mvf_pool
Definition: hevc.h:775
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
static int hls_transform_tree(HEVCContext *s, int x0, int y0, int xBase, int yBase, int cb_xBase, int cb_yBase, int log2_cb_size, int log2_trafo_size, int trafo_depth, int blk_idx, int cbf_cb, int cbf_cr)
Definition: hevc.c:1340
int video_full_range_flag
Definition: hevc.h:301
int ff_hevc_cu_qp_delta_abs(HEVCContext *s)
Definition: hevc_cabac.c:489
AVRational sar
Definition: hevc.h:294
uint8_t slice_loop_filter_across_slices_enabled_flag
Definition: hevc.h:562
static const uint8_t div6[QP_MAX_NUM+1]
Definition: h264_slice.c:53
void ff_hevc_cabac_init(HEVCContext *s, int ctb_addr_ts)
Definition: hevc_cabac.c:377
void * priv_data
Definition: avcodec.h:1092
#define SUBDIVIDE(x, y, idx)
int ff_hevc_split_transform_flag_decode(HEVCContext *s, int log2_trafo_size)
Definition: hevc_cabac.c:702
unsigned int collocated_ref_idx
Definition: hevc.h:565
#define GET_COORD(offset, n)
uint8_t pcm_flag
Definition: hevc.h:610
CodingUnit cu
Definition: hevc.h:739
int len
int min_pu_width
Definition: hevc.h:455
static const uint8_t horiz_scan8x8_inv[8][8]
Definition: hevc.c:65
int ff_hevc_pred_mode_decode(HEVCContext *s)
Definition: hevc_cabac.c:519
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1100
int beta_offset
Definition: hevc.h:657
int ff_hevc_cu_qp_delta_sign_flag(HEVCContext *s)
Definition: hevc_cabac.c:514
const uint8_t ff_hevc_diag_scan4x4_x[16]
Definition: hevc.c:85
int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCContext *s)
Definition: hevc_cabac.c:585
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:191
#define AV_ZERO32(d)
Definition: intreadwrite.h:534
void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC, int xBase, int yBase, int log2_cb_size)
Definition: hevc_filter.c:154
unsigned int list_entry_lx[2][32]
Definition: hevc.h:549
uint8_t luma_log2_weight_denom
Definition: hevc.h:580
static const uint8_t diag_scan4x4_inv[4][4]
Definition: hevc.c:99
int16_t chroma_weight_l1[16][2]
Definition: hevc.h:585
int ff_hevc_last_significant_coeff_suffix_decode(HEVCContext *s, int last_significant_coeff_prefix)
Definition: hevc_cabac.c:751
uint8_t long_term_ref_pics_present_flag
Definition: hevc.h:420
Definition: hevc.h:131
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:205
int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, int poc)
Definition: hevc_refs.c:118
static const uint8_t scan_1x1[1]
Definition: hevc.c:45
int ff_hevc_last_significant_coeff_x_prefix_decode(HEVCContext *s, int c_idx, int log2_size)
Definition: hevc_cabac.c:739
int boundary_flags
Definition: hevc.h:749
int diff_cu_qp_delta_depth
Definition: hevc.h:479
int ff_hevc_sao_offset_abs_decode(HEVCContext *s)
Definition: hevc_cabac.c:442
int cur_intra_pred_mode
Definition: hevc.h:652
int ff_hevc_pcm_flag_decode(HEVCContext *s)
Definition: hevc_cabac.c:580
int num_reorder_pics
Definition: hevc.h:404
const uint8_t ff_hevc_diag_scan8x8_y[64]
Definition: hevc.c:125
#define av_always_inline
Definition: attributes.h:40
int cb_qp_offset
Definition: hevc.h:481
uint8_t context_initialized
Definition: hevc.h:842
AVBufferRef * rpl_buf
Definition: hevc.h:679
int is_decoded
Definition: hevc.h:796
int video_signal_type_present_flag
Definition: hevc.h:299
#define FFSWAP(type, a, b)
Definition: common.h:60
uint8_t deblocking_filter_override_enabled_flag
Definition: hevc.h:501
int bit_depth
Definition: hevc.h:394
enum SliceType slice_type
Definition: hevc.h:536
int beta_offset
beta_offset_div2 * 2
Definition: hevc.h:503
int min_tb_height
Definition: hevc.h:454
static const uint8_t horiz_scan2x2_y[4]
Definition: hevc.c:49
#define BOUNDARY_LEFT_TILE
Definition: hevc.h:744
static const uint8_t diag_scan2x2_y[4]
Definition: hevc.c:78
#define L1
Definition: hevc.h:68
uint8_t * cbf_luma
Definition: hevc.h:814
int ff_hevc_sao_merge_flag_decode(HEVCContext *s)
Definition: hevc_cabac.c:417
#define AV_RN64A(p)
Definition: intreadwrite.h:450
SliceHeader sh
Definition: hevc.h:781
ScanType
Definition: hevc.h:256
exp golomb vlc stuff
int pcm_enabled_flag
Definition: hevc.h:399
static av_cold int hevc_decode_free(AVCodecContext *avctx)
Definition: hevc.c:2976
This structure stores compressed data.
Definition: avcodec.h:950
uint8_t mvd_l1_zero_flag
Definition: hevc.h:558
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:850
void(* emulated_edge_mc)(uint8_t *buf, const uint8_t *src, ptrdiff_t buf_linesize, ptrdiff_t src_linesize, int block_w, int block_h, int src_x, int src_y, int w, int h)
Copy a rectangular area of samples to a temporary buffer and replicate the border samples...
Definition: videodsp.h:52
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
static int hevc_ref_frame(HEVCContext *s, HEVCFrame *dst, HEVCFrame *src)
Definition: hevc.c:2944
static const uint8_t diag_scan8x8_inv[8][8]
Definition: hevc.c:144
for(j=16;j >0;--j)
uint8_t separate_colour_plane_flag
output (i.e. cropped) values
Definition: hevc.h:386
static const AVProfile profiles[]
Definition: hevc.c:3227
#define FFMAX3(a, b, c)
Definition: common.h:56
int end_of_tiles_y
Definition: hevc.h:735
uint8_t rqt_root_cbf
Definition: hevc.h:608
static void intra_prediction_unit_default_value(HEVCContext *s, int x0, int y0, int log2_cb_size)
Definition: hevc.c:2034
uint8_t slice_sample_adaptive_offset_flag[3]
Definition: hevc.h:557
#define SAMPLE_CTB(tab, x, y)
Definition: hevc.h:80
uint8_t dependent_slice_segments_enabled_flag
Definition: hevc.h:489
int offset_sign[3][4]
sao_offset_sign
Definition: hevcdsp.h:30
#define BOUNDARY_UPPER_TILE
Definition: hevc.h:746