TUT HEVC Encoder
strategies-ipol.h
Go to the documentation of this file.
1#ifndef STRATEGIES_IPOL_H_
2#define STRATEGIES_IPOL_H_
3/*****************************************************************************
4 * This file is part of Kvazaar HEVC encoder.
5 *
6 * Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
11 *
12 * * Redistributions of source code must retain the above copyright notice, this
13 * list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above copyright notice, this
16 * list of conditions and the following disclaimer in the documentation and/or
17 * other materials provided with the distribution.
18 *
19 * * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
30 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
33 ****************************************************************************/
34
41#include "encoder.h"
42#include "global.h" // IWYU pragma: keep
43#include "kvazaar.h"
44#include "search_inter.h"
45
46 // AVX2 implementation of horizontal filter reads and
47 // writes two rows for luma and four for chroma at a time.
48 // Extra vertical padding is added to prevent segfaults.
49 // Needs one extra byte for input buffer to prevent ASAN
50 // error because AVX2 reads one extra byte in the end.
51#define KVZ_IPOL_MAX_INPUT_SIZE_LUMA_SIMD ((KVZ_EXT_BLOCK_W_LUMA + 1) * KVZ_EXT_BLOCK_W_LUMA + 1)
52#define KVZ_IPOL_MAX_INPUT_SIZE_CHROMA_SIMD ((KVZ_EXT_BLOCK_W_CHROMA + 3) * KVZ_EXT_BLOCK_W_CHROMA + 1)
53#define KVZ_IPOL_MAX_IM_SIZE_LUMA_SIMD ((KVZ_EXT_BLOCK_W_LUMA + 1) * LCU_WIDTH)
54#define KVZ_IPOL_MAX_IM_SIZE_CHROMA_SIMD ((KVZ_EXT_BLOCK_W_CHROMA + 3) * LCU_WIDTH_C)
55
56// On top of basic interpolation, FME needs one extra
57// column and row for ME (left and up). Adding the
58// extra row happens to satisfy AVX2 requirements for
59// row count. No other extra rows are needed.
60#define KVZ_FME_MAX_INPUT_SIZE_SIMD ((KVZ_EXT_BLOCK_W_LUMA + 1) * (KVZ_EXT_BLOCK_W_LUMA + 1))
61
62typedef struct { kvz_pixel *buffer; kvz_pixel *orig_topleft; unsigned stride; unsigned malloc_used; } kvz_extended_block;
63
64typedef void(ipol_blocks_func)(const encoder_control_t * encoder, kvz_pixel *src, int16_t src_stride, int width, int height,
65 kvz_pixel filtered[4][LCU_LUMA_SIZE], int16_t hor_intermediate[5][KVZ_IPOL_MAX_IM_SIZE_LUMA_SIMD], int8_t fme_level, int16_t hor_first_cols[5][KVZ_EXT_BLOCK_W_LUMA + 1],
66 int8_t sample_off_x, int8_t sample_off_y);
67
68typedef struct {
69 // Source samples
70 kvz_pixel *src; // Top-left sample
71 int src_w; // Width
72 int src_h; // Height
73 int src_s; // Stride
74
75 // Requested sampling position, base dimensions, and padding
76 int blk_x;
77 int blk_y;
78 int blk_w; // Width
79 int blk_h; // Height
80 int pad_l; // Left
81 int pad_r; // Right
82 int pad_t; // Top
83 int pad_b; // Bottom
84 int pad_b_simd; // "Don't care" rows in the end. Zeroed out.
85
86 // Buffer for possible extrapolation. Free memory provided by the caller.
88
89 // Extended block data. These are set by the function.
90 kvz_pixel **ext; // Top-left sample with padding
91 kvz_pixel **ext_origin; // Top-left sample without padding
92 int *ext_s; // Stride
94
95typedef void(epol_func)(kvz_epol_args *args);
96
97
98typedef void(kvz_sample_quarterpel_luma_func)(const encoder_control_t * const encoder, kvz_pixel *src, int16_t src_stride, int width, int height, kvz_pixel *dst, int16_t dst_stride, int8_t hor_flag, int8_t ver_flag, const int16_t mv[2]);
99typedef void(kvz_sample_octpel_chroma_func)(const encoder_control_t * const encoder, kvz_pixel *src, int16_t src_stride, int width, int height, kvz_pixel *dst, int16_t dst_stride, int8_t hor_flag, int8_t ver_flag, const int16_t mv[2]);
100
101typedef void(kvz_sample_quarterpel_luma_hi_func)(const encoder_control_t * const encoder, kvz_pixel *src, int16_t src_stride, int width, int height, int16_t *dst, int16_t dst_stride, int8_t hor_flag, int8_t ver_flag, const int16_t mv[2]);
102typedef void(kvz_sample_octpel_chroma_hi_func)(const encoder_control_t * const encoder, kvz_pixel *src, int16_t src_stride, int width, int height, int16_t *dst, int16_t dst_stride, int8_t hor_flag, int8_t ver_flag, const int16_t mv[2]);
103
105 kvz_pixel *src,
106 int16_t src_stride,
107 int width,
108 int height,
109 int16_t *dst,
110 int16_t dst_stride,
111 int8_t hor_flag,
112 int8_t ver_flag,
113 const int16_t mv[2]);
114
116 kvz_pixel *src,
117 int16_t src_stride,
118 int width,
119 int height,
120 int16_t *dst,
121 int16_t dst_stride,
122 int8_t hor_flag,
123 int8_t ver_flag,
124 const int16_t mv[2]);
125
126// Declare function pointers.
136
137
138int kvz_strategy_register_ipol(void* opaque, uint8_t bitdepth);
139
140
141#define STRATEGIES_IPOL_EXPORTS \
142 {"filter_hpel_blocks_hor_ver_luma", (void**) &kvz_filter_hpel_blocks_hor_ver_luma}, \
143 {"filter_hpel_blocks_diag_luma", (void**) &kvz_filter_hpel_blocks_diag_luma}, \
144 {"filter_qpel_blocks_hor_ver_luma", (void**) &kvz_filter_qpel_blocks_hor_ver_luma}, \
145 {"filter_qpel_blocks_diag_luma", (void**) &kvz_filter_qpel_blocks_diag_luma}, \
146 {"sample_quarterpel_luma", (void**) &kvz_sample_quarterpel_luma}, \
147 {"sample_octpel_chroma", (void**) &kvz_sample_octpel_chroma}, \
148 {"sample_quarterpel_luma_hi", (void**) &kvz_sample_quarterpel_luma_hi}, \
149 {"sample_octpel_chroma_hi", (void**) &kvz_sample_octpel_chroma_hi}, \
150 {"get_extended_block", (void**) &kvz_get_extended_block}, \
151
152
153
154#endif //STRATEGIES_IPOL_H_
Initialization of encoder_control_t.
Header that is included in every other header.
#define LCU_LUMA_SIZE
Definition: global.h:168
This file defines the public API of Kvazaar when used as a library.
uint8_t kvz_pixel
Definition: kvazaar.h:95
Inter prediction parameter search.
#define KVZ_EXT_BLOCK_W_LUMA
Definition: search_inter.h:58
void() kvz_sample_octpel_chroma_func(const encoder_control_t *const encoder, kvz_pixel *src, int16_t src_stride, int width, int height, kvz_pixel *dst, int16_t dst_stride, int8_t hor_flag, int8_t ver_flag, const int16_t mv[2])
Definition: strategies-ipol.h:99
ipol_blocks_func * kvz_filter_qpel_blocks_diag_luma
Definition: strategies-ipol.c:44
ipol_blocks_func * kvz_filter_hpel_blocks_hor_ver_luma
Definition: strategies-ipol.c:41
void() kvz_sample_14bit_octpel_chroma_func(const encoder_control_t *const encoder, kvz_pixel *src, int16_t src_stride, int width, int height, int16_t *dst, int16_t dst_stride, int8_t hor_flag, int8_t ver_flag, const int16_t mv[2])
Definition: strategies-ipol.h:115
kvz_sample_quarterpel_luma_func * kvz_sample_quarterpel_luma
Definition: strategies-ipol.c:46
ipol_blocks_func * kvz_filter_qpel_blocks_hor_ver_luma
Definition: strategies-ipol.c:43
epol_func * kvz_get_extended_block
Definition: strategies-ipol.c:45
void() kvz_sample_quarterpel_luma_hi_func(const encoder_control_t *const encoder, kvz_pixel *src, int16_t src_stride, int width, int height, int16_t *dst, int16_t dst_stride, int8_t hor_flag, int8_t ver_flag, const int16_t mv[2])
Definition: strategies-ipol.h:101
void() ipol_blocks_func(const encoder_control_t *encoder, kvz_pixel *src, int16_t src_stride, int width, int height, kvz_pixel filtered[4][LCU_LUMA_SIZE], int16_t hor_intermediate[5][((KVZ_EXT_BLOCK_W_LUMA+1) *LCU_WIDTH)], int8_t fme_level, int16_t hor_first_cols[5][KVZ_EXT_BLOCK_W_LUMA+1], int8_t sample_off_x, int8_t sample_off_y)
Definition: strategies-ipol.h:64
kvz_sample_quarterpel_luma_hi_func * kvz_sample_quarterpel_luma_hi
Definition: strategies-ipol.c:48
kvz_sample_octpel_chroma_hi_func * kvz_sample_octpel_chroma_hi
Definition: strategies-ipol.c:49
ipol_blocks_func * kvz_filter_hpel_blocks_diag_luma
Definition: strategies-ipol.c:42
void() kvz_sample_14bit_quarterpel_luma_func(const encoder_control_t *const encoder, kvz_pixel *src, int16_t src_stride, int width, int height, int16_t *dst, int16_t dst_stride, int8_t hor_flag, int8_t ver_flag, const int16_t mv[2])
Definition: strategies-ipol.h:104
void() epol_func(kvz_epol_args *args)
Definition: strategies-ipol.h:95
#define KVZ_IPOL_MAX_IM_SIZE_LUMA_SIMD
Definition: strategies-ipol.h:53
int kvz_strategy_register_ipol(void *opaque, uint8_t bitdepth)
Definition: strategies-ipol.c:52
kvz_sample_octpel_chroma_func * kvz_sample_octpel_chroma
Definition: strategies-ipol.c:47
void() kvz_sample_quarterpel_luma_func(const encoder_control_t *const encoder, kvz_pixel *src, int16_t src_stride, int width, int height, kvz_pixel *dst, int16_t dst_stride, int8_t hor_flag, int8_t ver_flag, const int16_t mv[2])
Definition: strategies-ipol.h:98
void() kvz_sample_octpel_chroma_hi_func(const encoder_control_t *const encoder, kvz_pixel *src, int16_t src_stride, int width, int height, int16_t *dst, int16_t dst_stride, int8_t hor_flag, int8_t ver_flag, const int16_t mv[2])
Definition: strategies-ipol.h:102
Definition: encoder.h:49
Definition: strategies-ipol.h:68
kvz_pixel * buf
Definition: strategies-ipol.h:87
int src_s
Definition: strategies-ipol.h:73
kvz_pixel ** ext
Definition: strategies-ipol.h:90
int * ext_s
Definition: strategies-ipol.h:92
int blk_y
Definition: strategies-ipol.h:77
int pad_r
Definition: strategies-ipol.h:81
kvz_pixel * src
Definition: strategies-ipol.h:70
int pad_t
Definition: strategies-ipol.h:82
int blk_x
Definition: strategies-ipol.h:76
int pad_l
Definition: strategies-ipol.h:80
kvz_pixel ** ext_origin
Definition: strategies-ipol.h:91
int pad_b
Definition: strategies-ipol.h:83
int blk_w
Definition: strategies-ipol.h:78
int src_w
Definition: strategies-ipol.h:71
int blk_h
Definition: strategies-ipol.h:79
int src_h
Definition: strategies-ipol.h:72
int pad_b_simd
Definition: strategies-ipol.h:84
Definition: strategies-ipol.h:62
kvz_pixel * buffer
Definition: strategies-ipol.h:62