39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
40 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
41 5, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 24
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8,
46 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36,
47 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64
52 static const int qp_c[] = {
53 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37
55 int qp, qp_i,
offset, idxt;
63 qp_i = av_clip(qp_y + offset, 0, 57);
72 qp = av_clip(qp_i, 0, 51);
85 int xQgBase = xBase - (xBase & MinCuQpDeltaSizeMask);
86 int yQgBase = yBase - (yBase & MinCuQpDeltaSizeMask);
90 int availableA = (xBase & ctb_size_mask) &&
91 (xQgBase & ctb_size_mask);
92 int availableB = (yBase & ctb_size_mask) &&
93 (yQgBase & ctb_size_mask);
94 int qPy_pred, qPy_a, qPy_b;
108 qPy_a = s->
qp_y_tab[(x_cb - 1) + y_cb * min_cb_width];
114 qPy_b = s->
qp_y_tab[x_cb + (y_cb - 1) * min_cb_width];
119 return (qPy_a + qPy_b + 1) >> 1;
137 int x = xC >> log2_min_cb_size;
138 int y = yC >> log2_min_cb_size;
143 intptr_t stride_dst, intptr_t stride_src)
147 if (((intptr_t)dst | (intptr_t)src | stride_dst | stride_src) & 15) {
148 for (i = 0; i <
height; i++) {
149 for (j = 0; j <
width; j+=8)
155 for (i = 0; i <
height; i++) {
156 for (j = 0; j <
width; j+=16)
167 *(uint16_t *)dst = *(uint16_t *)
src;
173 int pixel_shift,
int height,
174 int stride_dst,
int stride_src)
177 if (pixel_shift == 0) {
178 for (i = 0; i <
height; i++) {
184 for (i = 0; i <
height; i++) {
185 *(uint16_t *)dst = *(uint16_t *)
src;
193 int stride_src,
int x,
int y,
int width,
int height,
194 int c_idx,
int x_ctb,
int y_ctb)
204 src + stride_src * (height - 1), width << sh);
209 copy_vert(s->
sao_pixel_buffer_v[c_idx] + (((2 * x_ctb + 1) * h + y) << sh), src + ((width - 1) << sh), sh, height, 1 << sh, stride_src);
214 ptrdiff_t stride_src, ptrdiff_t stride_dst,
228 for (y = y_min; y < y_max; y++) {
229 for (x = x_min; x < x_max; x++) {
234 for (n = 0; n < (min_pu_size >> vshift); n++) {
235 memcpy(src, dst, len);
245 #define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)])
249 static const uint8_t sao_tab[8] = { 0, 1, 2, 2, 3, 3, 4, 4 };
259 uint8_t vert_edge[] = { 0, 0 };
260 uint8_t horiz_edge[] = { 0, 0 };
261 uint8_t diag_edge[] = { 0, 0, 0, 0 };
265 uint8_t restore = no_tile_filter || !lfase;
271 edges[0] = x_ctb == 0;
272 edges[1] = y_ctb == 0;
293 if (!edges[0] && !edges[1]) {
296 if (!edges[1] && !edges[2]) {
299 if (!edges[2] && !edges[3]) {
302 if (!edges[0] && !edges[3]) {
315 int tab = sao_tab[(
FFALIGN(width, 8) >> 3) - 1];
333 x, y, width, height, c_idx);
345 int left_edge = edges[0];
346 int top_edge = edges[1];
347 int right_edge = edges[2];
348 int bottom_edge = edges[3];
350 int left_pixels, right_pixels;
356 int left = 1 - left_edge;
357 int right = 1 - right_edge;
362 dst1 = dst - stride_dst - (left << sh);
363 src1[0] = src - stride_src - (left << sh);
367 src_idx = (
CTB(s->
sao, x_ctb-1, y_ctb-1).type_idx[c_idx] ==
372 src_idx = (
CTB(s->
sao, x_ctb, y_ctb-1).type_idx[c_idx] ==
374 memcpy(dst1 + pos, src1[src_idx] + pos, width << sh);
377 src_idx = (
CTB(s->
sao, x_ctb+1, y_ctb-1).type_idx[c_idx] ==
379 copy_pixel(dst1 + pos, src1[src_idx] + pos, sh);
383 int left = 1 - left_edge;
384 int right = 1 - right_edge;
389 dst1 = dst + height * stride_dst - (left << sh);
390 src1[0] = src + height * stride_src - (left << sh);
394 src_idx = (
CTB(s->
sao, x_ctb-1, y_ctb+1).type_idx[c_idx] ==
399 src_idx = (
CTB(s->
sao, x_ctb, y_ctb+1).type_idx[c_idx] ==
401 memcpy(dst1 + pos, src1[src_idx] + pos, width << sh);
404 src_idx = (
CTB(s->
sao, x_ctb+1, y_ctb+1).type_idx[c_idx] ==
406 copy_pixel(dst1 + pos, src1[src_idx] + pos, sh);
414 sh, height, stride_dst, 1 << sh);
424 sh, height, stride_dst, 1 << sh);
431 src - (left_pixels << sh),
432 (width + left_pixels + right_pixels) << sh,
433 height, stride_dst, stride_src);
440 stride_src, stride_dst,
448 x, y, width, height, c_idx);
464 x_pu = x >> log2_min_pu_size;
465 y_pu = y >> log2_min_pu_size;
472 #define TC_CALC(qp, bs) \
473 tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) + \
474 (tc_offset >> 1 << 1), \
475 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)]
487 int x_end, x_end2, y_end;
488 int ctb_size = 1 << log2_ctb_size;
489 int ctb = (x0 >> log2_ctb_size) +
493 int left_tc_offset, left_beta_offset;
494 int tc_offset, beta_offset;
504 left_beta_offset = 0;
507 x_end = x0 + ctb_size;
510 y_end = y0 + ctb_size;
514 tc_offset = cur_tc_offset;
515 beta_offset = cur_beta_offset;
520 for (y = y0; y < y_end; y += 8) {
522 for (x = x0 ? x0 : 8; x < x_end; x += 8) {
526 const int qp = (
get_qPy(s, x - 1, y) +
get_qPy(s, x, y) + 1) >> 1;
530 tc[0] = bs0 ?
TC_CALC(qp, bs0) : 0;
531 tc[1] = bs1 ?
TC_CALC(qp, bs1) : 0;
534 no_p[0] =
get_pcm(s, x - 1, y);
535 no_p[1] =
get_pcm(s, x - 1, y + 4);
537 no_q[1] =
get_pcm(s, x, y + 4);
540 beta, tc, no_p, no_q);
544 beta, tc, no_p, no_q);
552 for (x = x0 ? x0 - 8 : 0; x < x_end2; x += 8) {
556 const int qp = (
get_qPy(s, x, y - 1) +
get_qPy(s, x, y) + 1) >> 1;
558 tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset;
559 beta_offset = x >= x0 ? cur_beta_offset : left_beta_offset;
562 tc[0] = bs0 ?
TC_CALC(qp, bs0) : 0;
563 tc[1] = bs1 ?
TC_CALC(qp, bs1) : 0;
566 no_p[0] =
get_pcm(s, x, y - 1);
567 no_p[1] =
get_pcm(s, x + 4, y - 1);
569 no_q[1] =
get_pcm(s, x + 4, y);
572 beta, tc, no_p, no_q);
576 beta, tc, no_p, no_q);
582 for (chroma = 1; chroma <= 2; chroma++) {
587 for (y = y0; y < y_end; y += (8 * v)) {
588 for (x = x0 ? x0 : 8 * h; x < x_end; x += (8 *
h)) {
592 if ((bs0 == 2) || (bs1 == 2)) {
593 const int qp0 = (
get_qPy(s, x - 1, y) +
get_qPy(s, x, y) + 1) >> 1;
594 const int qp1 = (
get_qPy(s, x - 1, y + (4 * v)) +
get_qPy(s, x, y + (4 * v)) + 1) >> 1;
596 c_tc[0] = (bs0 == 2) ?
chroma_tc(s, qp0, chroma, tc_offset) : 0;
597 c_tc[1] = (bs1 == 2) ?
chroma_tc(s, qp1, chroma, tc_offset) : 0;
600 no_p[0] =
get_pcm(s, x - 1, y);
601 no_p[1] =
get_pcm(s, x - 1, y + (4 * v));
603 no_q[1] =
get_pcm(s, x, y + (4 * v));
618 tc_offset = x0 ? left_tc_offset : cur_tc_offset;
621 x_end2 = x_end - 8 *
h;
622 for (x = x0 ? x0 - 8 * h : 0; x < x_end2; x += (8 *
h)) {
625 if ((bs0 == 2) || (bs1 == 2)) {
626 const int qp0 = bs0 == 2 ? (
get_qPy(s, x, y - 1) +
get_qPy(s, x, y) + 1) >> 1 : 0;
627 const int qp1 = bs1 == 2 ? (
get_qPy(s, x + (4 * h), y - 1) +
get_qPy(s, x + (4 * h), y) + 1) >> 1 : 0;
629 c_tc[0] = bs0 == 2 ?
chroma_tc(s, qp0, chroma, tc_offset) : 0;
630 c_tc[1] = bs1 == 2 ?
chroma_tc(s, qp1, chroma, cur_tc_offset) : 0;
633 no_p[0] =
get_pcm(s, x, y - 1);
634 no_p[1] =
get_pcm(s, x + (4 * h), y - 1);
636 no_q[1] =
get_pcm(s, x + (4 * h), y);
697 ref_B = neigh_refPicList[0].
list[neigh->
ref_idx[0]];
700 ref_B = neigh_refPicList[1].
list[neigh->
ref_idx[1]];
703 if (ref_A == ref_B) {
724 int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width +
726 int boundary_upper, boundary_left;
729 boundary_upper = y0 > 0 && !(y0 & 7);
730 if (boundary_upper &&
739 if (boundary_upper) {
743 int yp_pu = (y0 - 1) >> log2_min_pu_size;
744 int yq_pu = y0 >> log2_min_pu_size;
745 int yp_tu = (y0 - 1) >> log2_min_tu_size;
746 int yq_tu = y0 >> log2_min_tu_size;
748 for (i = 0; i < (1 << log2_trafo_size); i += 4) {
749 int x_pu = (x0 + i) >> log2_min_pu_size;
750 int x_tu = (x0 + i) >> log2_min_tu_size;
751 MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
752 MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
758 else if (curr_cbf_luma || top_cbf_luma)
767 boundary_left = x0 > 0 && !(x0 & 7);
781 int xp_pu = (x0 - 1) >> log2_min_pu_size;
782 int xq_pu = x0 >> log2_min_pu_size;
783 int xp_tu = (x0 - 1) >> log2_min_tu_size;
784 int xq_tu = x0 >> log2_min_tu_size;
786 for (i = 0; i < (1 << log2_trafo_size); i += 4) {
787 int y_pu = (y0 + i) >> log2_min_pu_size;
788 int y_tu = (y0 + i) >> log2_min_tu_size;
789 MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
790 MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
796 else if (curr_cbf_luma || left_cbf_luma)
804 if (log2_trafo_size > log2_min_pu_size && !is_intra) {
808 for (j = 8; j < (1 << log2_trafo_size); j += 8) {
809 int yp_pu = (y0 + j - 1) >> log2_min_pu_size;
810 int yq_pu = (y0 + j) >> log2_min_pu_size;
812 for (i = 0; i < (1 << log2_trafo_size); i += 4) {
813 int x_pu = (x0 + i) >> log2_min_pu_size;
814 MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
815 MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
823 for (j = 0; j < (1 << log2_trafo_size); j += 4) {
824 int y_pu = (y0 + j) >> log2_min_pu_size;
826 for (i = 8; i < (1 << log2_trafo_size); i += 8) {
827 int xp_pu = (x0 + i - 1) >> log2_min_pu_size;
828 int xq_pu = (x0 + i) >> log2_min_pu_size;
829 MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
830 MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
859 if (x_end && y_end) {
870 int x_end = x_ctb >= s->
ps.
sps->
width - ctb_size;
unsigned int log2_min_cb_size
uint8_t edge_emu_buffer[(MAX_PB_SIZE+7)*EDGE_EMU_BUFFER_STRIDE *2]
void(* sao_edge_restore[2])(uint8_t *_dst, uint8_t *_src, ptrdiff_t _stride_dst, ptrdiff_t _stride_src, struct SAOParams *sao, int *borders, int _width, int _height, int c_idx, uint8_t *vert_edge, uint8_t *horiz_edge, uint8_t *diag_edge)
int16_t x
horizontal component of motion vector
static void restore_tqb_pixels(HEVCContext *s, uint8_t *src1, const uint8_t *dst1, ptrdiff_t stride_src, ptrdiff_t stride_dst, int x0, int y0, int width, int height, int c_idx)
void(* hevc_h_loop_filter_chroma_c)(uint8_t *pix, ptrdiff_t stride, int32_t *tc, uint8_t *no_p, uint8_t *no_q)
static void sao_filter_CTB(HEVCContext *s, int x, int y)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, int log2_trafo_size)
void(* hevc_h_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride, int beta, int32_t *tc, uint8_t *no_p, uint8_t *no_q)
static const uint8_t tctable[54]
uint8_t loop_filter_disable_flag
void ff_hevc_hls_filter(HEVCContext *s, int x, int y, int ctb_size)
static void copy_CTB(uint8_t *dst, const uint8_t *src, int width, int height, intptr_t stride_dst, intptr_t stride_src)
static const uint8_t betatable[52]
uint8_t transquant_bypass_enable_flag
#define BOUNDARY_UPPER_SLICE
void(* hevc_v_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride, int beta, int32_t *tc, uint8_t *no_p, uint8_t *no_q)
void ff_hevc_hls_filters(HEVCContext *s, int x_ctb, int y_ctb, int ctb_size)
unsigned int log2_ctb_size
static void copy_CTB_to_hv(HEVCContext *s, const uint8_t *src, int stride_src, int x, int y, int width, int height, int c_idx, int x_ctb, int y_ctb)
uint8_t * sao_pixel_buffer_h[3]
void(* sao_edge_filter[5])(uint8_t *_dst, uint8_t *_src, ptrdiff_t stride_dst, int16_t *sao_offset_val, int sao_eo_class, int width, int height)
static const uint8_t offset[127][2]
uint8_t tiles_enabled_flag
static void copy_pixel(uint8_t *dst, const uint8_t *src, int pixel_shift)
int eo_class[3]
sao_eo_class
common internal API header
void(* hevc_v_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride, int32_t *tc, uint8_t *no_p, uint8_t *no_q)
uint8_t type_idx[3]
sao_type_idx
#define FF_THREAD_FRAME
Decode more than one frame at once.
uint8_t * sao_pixel_buffer_v[3]
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
void(* hevc_h_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride, int32_t *tc, uint8_t *no_p, uint8_t *no_q)
Context Adaptive Binary Arithmetic Coder inline functions.
void(* sao_band_filter[5])(uint8_t *_dst, uint8_t *_src, ptrdiff_t _stride_dst, ptrdiff_t _stride_src, int16_t *sao_offset_val, int sao_left_class, int width, int height)
int * ctb_addr_rs_to_ts
CtbAddrRSToTS.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
unsigned int log2_min_pu_size
int16_t y
vertical component of motion vector
uint8_t loop_filter_across_tiles_enabled_flag
unsigned int log2_min_tb_size
static int get_qPy(HEVCContext *s, int xC, int yC)
HEVCLocalContext * HEVClc
static int get_pcm(HEVCContext *s, int x, int y)
void(* hevc_h_loop_filter_luma_c)(uint8_t *pix, ptrdiff_t stride, int beta, int32_t *tc, uint8_t *no_p, uint8_t *no_q)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define DEFAULT_INTRA_TC_OFFSET
RefPicList * ff_hevc_get_ref_list(HEVCContext *s, HEVCFrame *frame, int x0, int y0)
static int chroma_tc(HEVCContext *s, int qp_y, int c_idx, int tc_offset)
common internal and external API header
#define BOUNDARY_LEFT_SLICE
int32_t * tab_slice_address
int16_t offset_val[3][5]
SaoOffsetVal.
uint8_t * filter_slice_edges
enum AVDiscard skip_loop_filter
Skip loop filtering for selected frames.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
uint8_t band_position[3]
sao_band_position
void(* hevc_v_loop_filter_luma_c)(uint8_t *pix, ptrdiff_t stride, int beta, int32_t *tc, uint8_t *no_p, uint8_t *no_q)
static const struct twinvq_data tab
static void copy_vert(uint8_t *dst, const uint8_t *src, int pixel_shift, int height, int stride_dst, int stride_src)
int diff_cu_qp_delta_depth
void ff_hevc_set_qPy(HEVCContext *s, int xBase, int yBase, int log2_cb_size)
void(* hevc_v_loop_filter_chroma_c)(uint8_t *pix, ptrdiff_t stride, int32_t *tc, uint8_t *no_p, uint8_t *no_q)
#define BOUNDARY_LEFT_TILE
static int boundary_strength(HEVCContext *s, MvField *curr, MvField *neigh, RefPicList *neigh_refPicList)
static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0)
#define BOUNDARY_UPPER_TILE
static int get_qPy_pred(HEVCContext *s, int xBase, int yBase, int log2_cb_size)