1 /*
2 * HEVC video decoder
3 *
4 * Copyright (C) 2012 - 2013 Guillaume Martres
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #ifndef AVCODEC_HEVC_HEVCDEC_H
24 #define AVCODEC_HEVC_HEVCDEC_H
25
26 #include <stdatomic.h>
27
30
38
44
45 #define SHIFT_CTB_WPP 2
46
47 #define MAX_TB_SIZE 32
49 #define DEFAULT_INTRA_TC_OFFSET 2
50
51 #define HEVC_CONTEXTS 199
52 #define HEVC_STAT_COEFFS 4
53
54 #define MRG_MAX_NUM_CANDS 5
55
58
59 #define EPEL_EXTRA_BEFORE 1
60 #define EPEL_EXTRA_AFTER 2
62 #define QPEL_EXTRA_BEFORE 3
63 #define QPEL_EXTRA_AFTER 4
65
66 #define EDGE_EMU_BUFFER_STRIDE 80
67
68 /**
69 * Value of the luma sample at position (x, y) in the 2D array tab.
70 */
71 #define SAMPLE(tab, x, y) ((tab)[(y) * s->sps->width + (x)])
72 #define SAMPLE_CTB(tab, x, y) ((tab)[(y) * min_cb_width + (x)])
73
74 #define IS_IDR(s) ((s)->nal_unit_type == HEVC_NAL_IDR_W_RADL || (s)->nal_unit_type == HEVC_NAL_IDR_N_LP)
75 #define IS_BLA(s) ((s)->nal_unit_type == HEVC_NAL_BLA_W_RADL || (s)->nal_unit_type == HEVC_NAL_BLA_W_LP || \
76 (s)->nal_unit_type == HEVC_NAL_BLA_N_LP)
77 #define IS_IRAP(s) ((s)->nal_unit_type >= HEVC_NAL_BLA_W_LP && (s)->nal_unit_type <= HEVC_NAL_RSV_IRAP_VCL23)
78
79 #define HEVC_RECOVERY_UNSPECIFIED INT_MAX
80 #define HEVC_RECOVERY_END INT_MIN
81 #define HEVC_IS_RECOVERING(s) ((s)->recovery_poc != HEVC_RECOVERY_UNSPECIFIED && (s)->recovery_poc != HEVC_RECOVERY_END)
82
92 };
93
103 };
104
109 };
110
115 };
116
122 };
123
160 };
161
167 };
168
174 };
175
180 };
181
186
193
200
204
207
208 /// address (in raster order) of the first block in the current slice segment
210 /// address (in raster order) of the first block in the current slice
212
214
217
223
224 /// RPS coded in the slice header itself is stored here
232
236
238
241
246
248
252
256
258
261
264
269
271
274
279
282
285
289
293
296
297 // Inferred parameters
302
304 int16_t
x;
///< horizontal component of motion vector
305 int16_t
y;
///< vertical component of motion vector
307
313
322
332
335
337
338 // Inferred parameters;
348
353
354 #define HEVC_FRAME_FLAG_OUTPUT (1 << 0)
355 #define HEVC_FRAME_FLAG_SHORT_REF (1 << 1)
356 #define HEVC_FRAME_FLAG_LONG_REF (1 << 2)
357 #define HEVC_FRAME_FLAG_UNAVAILABLE (1 << 3)
358 #define HEVC_FRAME_FLAG_CORRUPT (1 << 4)
359
361 union {
362 struct {
364 };
366 };
368 int needs_fg;
/* 1 if grain needs to be applied by the decoder */
374
378
380
381 // for secondary-layer frames, this is the DPB index of the base-layer frame
382 // from the same AU, if it exists, otherwise -1
384
385 /**
386 * A combination of HEVC_FRAME_FLAG_*
387 */
390
393
395
397
400
402
403 /**
404 * This is a pointer to the common CABAC state.
405 * In case entropy_coding_sync_enabled_flag is set,
406 * the CABAC state after decoding the second CTU in a row is
407 * stored here and used to initialize the CABAC state before
408 * decoding the first CTU in the next row.
409 * This is the basis for WPP and in case slice-threading is used,
410 * the next row is decoded by another thread making this state
411 * shared between threads.
412 */
414
417
419
421
428 /* +7 is for subpixel interpolation, *2 for high bit depths */
430 /* The extended size between the new edge emu buffer is abused by SAO */
433
438
439 #define BOUNDARY_LEFT_SLICE (1 << 0)
440 #define BOUNDARY_LEFT_TILE (1 << 1)
441 #define BOUNDARY_UPPER_SLICE (1 << 2)
442 #define BOUNDARY_UPPER_TILE (1 << 3)
443 /* properties of the boundary of the current CTB for the purposes
444 * of the deblocking filter */
446
447 // an array of these structs is used for per-thread state - pad its size
448 // to avoid false sharing
451
455
457
460
463
464 // CU
467
468 // PU
472
473 // CTB-level flags affecting loop filter operation
475
477
479
482
485
489
493
496
497 // per-layer decoding state, addressed by VPS layer indices
499 // VPS index of the layer currently being decoded
501 // bitmask of layer indices that are active for decoding/output
504
505 /** 1 if the independent slice segment header was successfully parsed */
507
509
513
514 /// candidate references for the current frame
516
526 int slice_idx;
///< number of the slice being currently decoded
527 int eos;
///< current packet contains an EOS/EOB NAL
528 int last_eos;
///< last packet contains an EOS/EOB NAL
530
531 // NoRaslOutputFlag associated with the last IRAP frame
533
538
539 /** used on BE to byteswap the lines for checksumming */
542
543 /** The target for the common_cabac_state of the local contexts. */
545
548
550
552
554 // type of the first VCL NAL of the current frame
556 // index in pkt.nals of the NAL unit after which we can call
557 // ff_thread_finish_setup()
559
560 int is_nalff;
///< this flag is != 0 if bitstream is encapsulated
561 ///< as a format defined in 14496-15
563
564 // multi-layer AVOptions
567
570
573
576
578
579 // dts of the packet currently being decoded
581
585
586 /**
587 * Mark all frames in DPB as unused for reference.
588 */
590
591 /**
592 * Drop all frames currently in DPB.
593 */
595
597
598 /**
599 * Construct the reference picture sets for the current frame.
600 */
602
603 /**
604 * Construct the reference picture list(s) for the current slice.
605 */
607
609 int ctb_addr_ts);
611 int ctb_addr_ts,
const uint8_t *
data,
size_t size,
612 int is_wpp);
622 int x0, int y0, int x_cb, int y_cb, int min_cb_width);
626 int ct_depth, int x0, int y0);
644
645 /**
646 * Get the number of candidate references for the current frame.
647 */
649 unsigned layer_idx);
650
652
654 {
664 return 1;
665 default: break;
666 }
667 return 0;
668 }
669
670 /**
671 * Find frames in the DPB that are ready for output and either write them to the
672 * output FIFO or drop their output flag, depending on the value of discard.
673 *
674 * @param max_output maximum number of AUs with an output-pending frame in at
675 * least one layer that can be present in the DPB before output
676 * is triggered
677 * @param max_dpb maximum number of any frames that can be present in the DPB
678 * for any layer before output is triggered
679 */
681 unsigned layers_active_decode, unsigned layers_active_output,
682 unsigned max_output, unsigned max_dpb, int discard);
683
685
687 int nPbW, int nPbH, int log2_ctb_size);
689 int x0, int y0,
690 int nPbW, int nPbH, int log2_cb_size,
691 int part_idx,
int merge_idx,
MvField *
mv);
693 int x0, int y0,
694 int nPbW, int nPbH, int log2_cb_size,
695 int part_idx, int merge_idx,
699 int x, int y, int ctb_size);
702 int x_ctb, int y_ctb, int ctb_size);
705 int xBase, int yBase, int log2_cb_size);
708 int x0, int y0, int log2_trafo_size);
714 int x0, int y0,
715 int log2_trafo_size,
enum ScanType scan_idx,
716 int c_idx);
717
719
721
725
726 #endif /* AVCODEC_HEVC_HEVCDEC_H */