Line data Source code
1 : /* 2 : * Copyright(c) 2019 Intel Corporation 3 : * SPDX - License - Identifier: BSD - 2 - Clause - Patent 4 : */ 5 : 6 : /* 7 : * Copyright (c) 2016, Alliance for Open Media. All rights reserved 8 : * 9 : * This source code is subject to the terms of the BSD 2 Clause License and 10 : * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 11 : * was not distributed with this source code in the LICENSE file, you can 12 : * obtain it at www.aomedia.org/license/software. If the Alliance for Open 13 : * Media Patent License 1.0 was not distributed with this source code in the 14 : * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 15 : */ 16 : 17 : #include <stdlib.h> 18 : #include "EbDefinitions.h" 19 : #include "EbDlfProcess.h" 20 : #include "EbEncDecResults.h" 21 : #include "EbThreads.h" 22 : #include "EbReferenceObject.h" 23 : 24 : #include "EbDeblockingFilter.h" 25 : 26 : void eb_av1_loop_restoration_save_boundary_lines(const Yv12BufferConfig *frame, Av1Common *cm, int32_t after_cdef); 27 : 28 16 : static void dlf_context_dctor(EbPtr p) 29 : { 30 16 : DlfContext *obj = (DlfContext*)p; 31 16 : EB_DELETE(obj->temp_lf_recon_picture_ptr); 32 16 : EB_DELETE(obj->temp_lf_recon_picture16bit_ptr); 33 16 : } 34 : /****************************************************** 35 : * Dlf Context Constructor 36 : ******************************************************/ 37 16 : EbErrorType dlf_context_ctor( 38 : DlfContext *context_ptr, 39 : EbFifo *dlf_input_fifo_ptr, 40 : EbFifo *dlf_output_fifo_ptr , 41 : EbBool is16bit, 42 : EbColorFormat color_format, 43 : uint32_t max_input_luma_width, 44 : uint32_t max_input_luma_height 45 : ) 46 : { 47 16 : EbErrorType return_error = EB_ErrorNone; 48 16 : context_ptr->dctor = dlf_context_dctor; 49 : 50 : // Input/Output System Resource Manager FIFOs 51 16 : context_ptr->dlf_input_fifo_ptr = dlf_input_fifo_ptr; 52 16 : context_ptr->dlf_output_fifo_ptr = dlf_output_fifo_ptr; 53 : 54 16 : context_ptr->temp_lf_recon_picture16bit_ptr = (EbPictureBufferDesc *)EB_NULL; 55 16 : context_ptr->temp_lf_recon_picture_ptr = (EbPictureBufferDesc *)EB_NULL; 56 : EbPictureBufferDescInitData temp_lf_recon_desc_init_data; 57 16 : temp_lf_recon_desc_init_data.max_width = (uint16_t)max_input_luma_width; 58 16 : temp_lf_recon_desc_init_data.max_height = (uint16_t)max_input_luma_height; 59 16 : temp_lf_recon_desc_init_data.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK; 60 : 61 16 : temp_lf_recon_desc_init_data.left_padding = PAD_VALUE; 62 16 : temp_lf_recon_desc_init_data.right_padding = PAD_VALUE; 63 16 : temp_lf_recon_desc_init_data.top_padding = PAD_VALUE; 64 16 : temp_lf_recon_desc_init_data.bot_padding = PAD_VALUE; 65 : 66 16 : temp_lf_recon_desc_init_data.split_mode = EB_FALSE; 67 16 : temp_lf_recon_desc_init_data.color_format = color_format; 68 : 69 16 : if (is16bit) { 70 0 : temp_lf_recon_desc_init_data.bit_depth = EB_16BIT; 71 0 : EB_NEW( 72 : context_ptr->temp_lf_recon_picture16bit_ptr, 73 : eb_recon_picture_buffer_desc_ctor, 74 : (EbPtr)&temp_lf_recon_desc_init_data); 75 : } 76 : else { 77 16 : temp_lf_recon_desc_init_data.bit_depth = EB_8BIT; 78 16 : EB_NEW( 79 : context_ptr->temp_lf_recon_picture_ptr, 80 : eb_recon_picture_buffer_desc_ctor, 81 : (EbPtr)&temp_lf_recon_desc_init_data); 82 : } 83 : 84 16 : return return_error; 85 : } 86 : 87 : /****************************************************** 88 : * Dlf Kernel 89 : ******************************************************/ 90 16 : void* dlf_kernel(void *input_ptr) 91 : { 92 : // Context & SCS & PCS 93 16 : DlfContext *context_ptr = (DlfContext*)input_ptr; 94 : PictureControlSet *picture_control_set_ptr; 95 : SequenceControlSet *sequence_control_set_ptr; 96 : 97 : //// Input 98 : EbObjectWrapper *enc_dec_results_wrapper_ptr; 99 : EncDecResults *enc_dec_results_ptr; 100 : 101 : //// Output 102 : EbObjectWrapper *dlf_results_wrapper_ptr; 103 : struct DlfResults* dlf_results_ptr; 104 : 105 : // SB Loop variables 106 120 : for (;;) { 107 : // Get EncDec Results 108 136 : eb_get_full_object( 109 : context_ptr->dlf_input_fifo_ptr, 110 : &enc_dec_results_wrapper_ptr); 111 : 112 120 : enc_dec_results_ptr = (EncDecResults*)enc_dec_results_wrapper_ptr->object_ptr; 113 120 : picture_control_set_ptr = (PictureControlSet*)enc_dec_results_ptr->picture_control_set_wrapper_ptr->object_ptr; 114 120 : sequence_control_set_ptr = (SequenceControlSet*)picture_control_set_ptr->sequence_control_set_wrapper_ptr->object_ptr; 115 : 116 120 : EbBool is16bit = (EbBool)(sequence_control_set_ptr->static_config.encoder_bit_depth > EB_8BIT); 117 : 118 120 : EbBool dlfEnableFlag = (EbBool) picture_control_set_ptr->parent_pcs_ptr->loop_filter_mode; 119 120 : if (dlfEnableFlag && picture_control_set_ptr->parent_pcs_ptr->loop_filter_mode >= 2) { 120 60 : EbPictureBufferDesc *recon_buffer = is16bit ? picture_control_set_ptr->recon_picture16bit_ptr : picture_control_set_ptr->recon_picture_ptr; 121 : 122 60 : if (picture_control_set_ptr->parent_pcs_ptr->is_used_as_reference_flag == EB_TRUE) 123 : //get the 16bit form of the input LCU 124 38 : if (is16bit) 125 0 : recon_buffer = ((EbReferenceObject*)picture_control_set_ptr->parent_pcs_ptr->reference_picture_wrapper_ptr->object_ptr)->reference_picture16bit; 126 : else 127 38 : recon_buffer = ((EbReferenceObject*)picture_control_set_ptr->parent_pcs_ptr->reference_picture_wrapper_ptr->object_ptr)->reference_picture; 128 : else // non ref pictures 129 22 : recon_buffer = is16bit ? picture_control_set_ptr->recon_picture16bit_ptr : picture_control_set_ptr->recon_picture_ptr; 130 : 131 60 : eb_av1_loop_filter_init(picture_control_set_ptr); 132 : 133 60 : if (picture_control_set_ptr->parent_pcs_ptr->loop_filter_mode == 2) { 134 0 : eb_av1_pick_filter_level( 135 : context_ptr, 136 0 : (EbPictureBufferDesc*)picture_control_set_ptr->parent_pcs_ptr->enhanced_picture_ptr, 137 : picture_control_set_ptr, 138 : LPF_PICK_FROM_Q); 139 : } 140 : 141 60 : eb_av1_pick_filter_level( 142 : context_ptr, 143 60 : (EbPictureBufferDesc*)picture_control_set_ptr->parent_pcs_ptr->enhanced_picture_ptr, 144 : picture_control_set_ptr, 145 : LPF_PICK_FROM_FULL_IMAGE); 146 : 147 : #if NO_ENCDEC 148 : //NO DLF 149 : picture_control_set_ptr->parent_pcs_ptr->lf.filter_level[0] = 0; 150 : picture_control_set_ptr->parent_pcs_ptr->lf.filter_level[1] = 0; 151 : picture_control_set_ptr->parent_pcs_ptr->lf.filter_level_u = 0; 152 : picture_control_set_ptr->parent_pcs_ptr->lf.filter_level_v = 0; 153 : #endif 154 60 : eb_av1_loop_filter_frame( 155 : recon_buffer, 156 : picture_control_set_ptr, 157 : 0, 158 : 3); 159 : } 160 : 161 : //pre-cdef prep 162 : { 163 120 : Av1Common* cm = picture_control_set_ptr->parent_pcs_ptr->av1_cm; 164 : EbPictureBufferDesc * recon_picture_ptr; 165 120 : if (is16bit) { 166 0 : if (picture_control_set_ptr->parent_pcs_ptr->is_used_as_reference_flag == EB_TRUE) 167 0 : recon_picture_ptr = ((EbReferenceObject*)picture_control_set_ptr->parent_pcs_ptr->reference_picture_wrapper_ptr->object_ptr)->reference_picture16bit; 168 : else 169 0 : recon_picture_ptr = picture_control_set_ptr->recon_picture16bit_ptr; 170 : } 171 : else { 172 120 : if (picture_control_set_ptr->parent_pcs_ptr->is_used_as_reference_flag == EB_TRUE) 173 68 : recon_picture_ptr = ((EbReferenceObject*)picture_control_set_ptr->parent_pcs_ptr->reference_picture_wrapper_ptr->object_ptr)->reference_picture; 174 : else 175 52 : recon_picture_ptr = picture_control_set_ptr->recon_picture_ptr; 176 : } 177 : 178 120 : link_eb_to_aom_buffer_desc( 179 : recon_picture_ptr, 180 : cm->frame_to_show); 181 : 182 120 : if (sequence_control_set_ptr->seq_header.enable_restoration) 183 60 : eb_av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 0); 184 120 : if (sequence_control_set_ptr->seq_header.enable_cdef && picture_control_set_ptr->parent_pcs_ptr->cdef_filter_mode) 185 : { 186 120 : if (is16bit) 187 : { 188 0 : picture_control_set_ptr->src[0] = (uint16_t*)recon_picture_ptr->buffer_y + (recon_picture_ptr->origin_x + recon_picture_ptr->origin_y * recon_picture_ptr->stride_y); 189 0 : picture_control_set_ptr->src[1] = (uint16_t*)recon_picture_ptr->buffer_cb + (recon_picture_ptr->origin_x / 2 + recon_picture_ptr->origin_y / 2 * recon_picture_ptr->stride_cb); 190 0 : picture_control_set_ptr->src[2] = (uint16_t*)recon_picture_ptr->buffer_cr + (recon_picture_ptr->origin_x / 2 + recon_picture_ptr->origin_y / 2 * recon_picture_ptr->stride_cr); 191 : 192 0 : EbPictureBufferDesc *input_picture_ptr = picture_control_set_ptr->input_frame16bit; 193 0 : picture_control_set_ptr->ref_coeff[0] = (uint16_t*)input_picture_ptr->buffer_y + (input_picture_ptr->origin_x + input_picture_ptr->origin_y * input_picture_ptr->stride_y); 194 0 : picture_control_set_ptr->ref_coeff[1] = (uint16_t*)input_picture_ptr->buffer_cb + (input_picture_ptr->origin_x / 2 + input_picture_ptr->origin_y / 2 * input_picture_ptr->stride_cb); 195 0 : picture_control_set_ptr->ref_coeff[2] = (uint16_t*)input_picture_ptr->buffer_cr + (input_picture_ptr->origin_x / 2 + input_picture_ptr->origin_y / 2 * input_picture_ptr->stride_cr); 196 : } 197 : else 198 : { 199 120 : EbByte rec_ptr = &((recon_picture_ptr->buffer_y)[recon_picture_ptr->origin_x + recon_picture_ptr->origin_y * recon_picture_ptr->stride_y]); 200 120 : EbByte rec_ptr_cb = &((recon_picture_ptr->buffer_cb)[recon_picture_ptr->origin_x / 2 + recon_picture_ptr->origin_y / 2 * recon_picture_ptr->stride_cb]); 201 120 : EbByte rec_ptr_cr = &((recon_picture_ptr->buffer_cr)[recon_picture_ptr->origin_x / 2 + recon_picture_ptr->origin_y / 2 * recon_picture_ptr->stride_cr]); 202 : 203 120 : EbPictureBufferDesc *input_picture_ptr = (EbPictureBufferDesc*)picture_control_set_ptr->parent_pcs_ptr->enhanced_picture_ptr; 204 120 : EbByte enh_ptr = &((input_picture_ptr->buffer_y)[input_picture_ptr->origin_x + input_picture_ptr->origin_y * input_picture_ptr->stride_y]); 205 120 : EbByte enh_ptr_cb = &((input_picture_ptr->buffer_cb)[input_picture_ptr->origin_x / 2 + input_picture_ptr->origin_y / 2 * input_picture_ptr->stride_cb]); 206 120 : EbByte enh_ptr_cr = &((input_picture_ptr->buffer_cr)[input_picture_ptr->origin_x / 2 + input_picture_ptr->origin_y / 2 * input_picture_ptr->stride_cr]); 207 : 208 120 : picture_control_set_ptr->src[0] = (uint16_t*)rec_ptr; 209 120 : picture_control_set_ptr->src[1] = (uint16_t*)rec_ptr_cb; 210 120 : picture_control_set_ptr->src[2] = (uint16_t*)rec_ptr_cr; 211 : 212 120 : picture_control_set_ptr->ref_coeff[0] = (uint16_t*)enh_ptr; 213 120 : picture_control_set_ptr->ref_coeff[1] = (uint16_t*)enh_ptr_cb; 214 120 : picture_control_set_ptr->ref_coeff[2] = (uint16_t*)enh_ptr_cr; 215 : 216 : } 217 : } 218 : } 219 : 220 120 : picture_control_set_ptr->cdef_segments_column_count = sequence_control_set_ptr->cdef_segment_column_count; 221 120 : picture_control_set_ptr->cdef_segments_row_count = sequence_control_set_ptr->cdef_segment_row_count; 222 120 : picture_control_set_ptr->cdef_segments_total_count = (uint16_t)(picture_control_set_ptr->cdef_segments_column_count * picture_control_set_ptr->cdef_segments_row_count); 223 120 : picture_control_set_ptr->tot_seg_searched_cdef = 0; 224 : uint32_t segment_index; 225 : 226 7320 : for (segment_index = 0; segment_index < picture_control_set_ptr->cdef_segments_total_count; ++segment_index) 227 : { 228 : // Get Empty DLF Results to Cdef 229 7200 : eb_get_empty_object( 230 : context_ptr->dlf_output_fifo_ptr, 231 : &dlf_results_wrapper_ptr); 232 7200 : dlf_results_ptr = (struct DlfResults*)dlf_results_wrapper_ptr->object_ptr; 233 7200 : dlf_results_ptr->picture_control_set_wrapper_ptr = enc_dec_results_ptr->picture_control_set_wrapper_ptr; 234 7200 : dlf_results_ptr->segment_index = segment_index; 235 : // Post DLF Results 236 7200 : eb_post_full_object(dlf_results_wrapper_ptr); 237 : } 238 : 239 : // Release EncDec Results 240 120 : eb_release_object(enc_dec_results_wrapper_ptr); 241 : } 242 : 243 : return EB_NULL; 244 : }