LCOV - code coverage report
Current view: top level - Codec - EbModeDecisionProcess.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 184 251 73.3 %
Date: 2019-11-25 17:38:06 Functions: 6 9 66.7 %

          Line data    Source code
       1             : /*
       2             : * Copyright(c) 2019 Intel Corporation
       3             : * SPDX - License - Identifier: BSD - 2 - Clause - Patent
       4             : */
       5             : 
       6             : #include <stdlib.h>
       7             : 
       8             : #include "EbUtility.h"
       9             : #include "EbModeDecisionProcess.h"
      10             : #include "EbLambdaRateTables.h"
      11             : 
      12          16 : static void mode_decision_context_dctor(EbPtr p)
      13             : {
      14          16 :     ModeDecisionContext* obj = (ModeDecisionContext*)p;
      15             : #if PAL_SUP
      16         240 :     for (int cd = 0; cd < MAX_PAL_CAND; cd++)
      17         224 :         if (obj->palette_cand_array[cd].color_idx_map)
      18         224 :             EB_FREE_ARRAY(obj->palette_cand_array[cd].color_idx_map);
      19       29696 :     for (uint32_t candidateIndex = 0; candidateIndex < MODE_DECISION_CANDIDATE_MAX_COUNT; ++candidateIndex)
      20       29680 :         if (obj->fast_candidate_ptr_array[candidateIndex]->palette_info.color_idx_map)
      21       29680 :             EB_FREE_ARRAY(obj->fast_candidate_ptr_array[candidateIndex]->palette_info.color_idx_map);
      22       70752 :     for (uint32_t codedLeafIndex = 0; codedLeafIndex < BLOCK_MAX_COUNT_SB_128; ++codedLeafIndex)
      23       70736 :         if (obj->md_cu_arr_nsq[codedLeafIndex].palette_info.color_idx_map)
      24       70736 :             EB_FREE_ARRAY(obj->md_cu_arr_nsq[codedLeafIndex].palette_info.color_idx_map);
      25             : #endif
      26          16 :     EB_FREE_ARRAY(obj->ref_best_ref_sq_table);
      27          16 :     EB_FREE_ARRAY(obj->ref_best_cost_sq_table);
      28             : #if ENHANCE_ATB
      29          16 :     EB_FREE_ARRAY(obj->above_txfm_context);
      30          16 :     EB_FREE_ARRAY(obj->left_txfm_context);
      31             : #endif
      32             : #if NO_ENCDEC //SB128_TODO to upgrade
      33             :     int codedLeafIndex;
      34             :     for (codedLeafIndex = 0; codedLeafIndex < BLOCK_MAX_COUNT_SB_128; ++codedLeafIndex) {
      35             :         EB_DELETE(obj->md_cu_arr_nsq[codedLeafIndex].recon_tmp);
      36             :         EB_DELETE(obj->md_cu_arr_nsq[codedLeafIndex].coeff_tmp);
      37             : 
      38             :    }
      39             : #endif
      40        2160 :     EB_DELETE_PTR_ARRAY(obj->candidate_buffer_ptr_array, MAX_NFL_BUFF);
      41             : 
      42             : #if ENHANCE_ATB
      43          16 :     EB_FREE_ARRAY(obj->scratch_candidate_buffer->candidate_ptr);
      44          16 :     EB_DELETE(obj->scratch_candidate_buffer);
      45             : #endif
      46             : 
      47          16 :     EB_DELETE(obj->trans_quant_buffers_ptr);
      48             : #if !HBD_CLEAN_UP // cfl_temp_luma_recon16bit
      49             :     if (obj->hbd_mode_decision)
      50             : #else
      51          16 :     if (obj->hbd_mode_decision > EB_8_BIT_MD)
      52             : #endif
      53           0 :         EB_FREE_ALIGNED_ARRAY(obj->cfl_temp_luma_recon16bit);
      54             : #if !HBD_CLEAN_UP
      55             :     else
      56             : #else
      57          16 :     if (obj->hbd_mode_decision != EB_10_BIT_MD)
      58             : #endif
      59          16 :         EB_FREE_ALIGNED_ARRAY(obj->cfl_temp_luma_recon);
      60          16 :     EB_FREE(obj->transform_inner_array_ptr);
      61          16 :     if (obj->is_md_rate_estimation_ptr_owner)
      62           0 :         EB_FREE_ARRAY(obj->md_rate_estimation_ptr);
      63          16 :     EB_FREE_ARRAY(obj->fast_candidate_array);
      64          16 :     EB_FREE_ARRAY(obj->fast_candidate_ptr_array);
      65          16 :     EB_FREE_ARRAY(obj->fast_cost_array);
      66          16 :     EB_FREE_ARRAY(obj->full_cost_array);
      67          16 :     EB_FREE_ARRAY(obj->full_cost_skip_ptr);
      68          16 :     EB_FREE_ARRAY(obj->full_cost_merge_ptr);
      69          16 :     if (obj->md_cu_arr_nsq) {
      70          16 :         EB_FREE_ARRAY(obj->md_cu_arr_nsq[0].av1xd);
      71             : #if !HBD_CLEAN_UP // neigh_left_recon_16bit neigh_top_recon_16bit
      72             :         if (obj->hbd_mode_decision) {
      73             : #else
      74          16 :         if (obj->hbd_mode_decision > EB_8_BIT_MD) {
      75             : #endif
      76           0 :             EB_FREE_ARRAY(obj->md_cu_arr_nsq[0].neigh_left_recon_16bit[0]);
      77           0 :             EB_FREE_ARRAY(obj->md_cu_arr_nsq[0].neigh_top_recon_16bit[0]);
      78             :         }
      79             : #if HBD_CLEAN_UP
      80          16 :         if (obj->hbd_mode_decision != EB_10_BIT_MD) {
      81             : #else
      82             :         else {
      83             : 
      84             : #endif
      85          16 :             EB_FREE_ARRAY(obj->md_cu_arr_nsq[0].neigh_left_recon[0]);
      86          16 :             EB_FREE_ARRAY(obj->md_cu_arr_nsq[0].neigh_top_recon[0]);
      87             :         }
      88             :     }
      89             : 
      90          16 :     EB_FREE_ARRAY(obj->md_local_cu_unit);
      91          16 :     EB_FREE_ARRAY(obj->md_cu_arr_nsq);
      92          16 :     EB_FREE_ARRAY(obj->md_ep_pipe_sb);
      93          16 : }
      94             : 
      95             : /******************************************************
      96             :  * Mode Decision Context Constructor
      97             :  ******************************************************/
      98          16 : EbErrorType mode_decision_context_ctor(
      99             :     ModeDecisionContext  *context_ptr,
     100             :     EbColorFormat         color_format,
     101             :     EbFifo                *mode_decision_configuration_input_fifo_ptr,
     102             :     EbFifo                *mode_decision_output_fifo_ptr,
     103             :     uint8_t                enable_hbd_mode_decision
     104             : #if PAL_SUP
     105             :     ,uint8_t                 cfg_palette
     106             : #endif
     107             : )
     108             : {
     109             :     uint32_t bufferIndex;
     110             :     uint32_t candidateIndex;
     111             : 
     112             :     (void)color_format;
     113             : 
     114          16 :     context_ptr->dctor = mode_decision_context_dctor;
     115          16 :     context_ptr->hbd_mode_decision = enable_hbd_mode_decision;
     116             : 
     117             :     // Input/Output System Resource Manager FIFOs
     118          16 :     context_ptr->mode_decision_configuration_input_fifo_ptr = mode_decision_configuration_input_fifo_ptr;
     119          16 :     context_ptr->mode_decision_output_fifo_ptr = mode_decision_output_fifo_ptr;
     120             : 
     121             :     // Trasform Scratch Memory
     122          16 :     EB_MALLOC(context_ptr->transform_inner_array_ptr, 3120); //refer to EbInvTransform_SSE2.as. case 32x32
     123             : 
     124             :     // Cfl scratch memory
     125             : #if !HBD_CLEAN_UP // cfl_temp_luma_recon16bit
     126             :     if (context_ptr->hbd_mode_decision) {
     127             : #else
     128          16 :     if (context_ptr->hbd_mode_decision > EB_8_BIT_MD)
     129             : #endif
     130           0 :         EB_MALLOC_ALIGNED(context_ptr->cfl_temp_luma_recon16bit, sizeof(uint16_t) * 128 * 128);
     131             : #if !HBD_CLEAN_UP
     132             :     } else {
     133             : #else
     134          16 :     if (context_ptr->hbd_mode_decision != EB_10_BIT_MD)
     135             : #endif
     136          16 :         EB_MALLOC_ALIGNED(context_ptr->cfl_temp_luma_recon, sizeof(uint8_t) * 128 * 128);
     137             : #if !HBD_CLEAN_UP
     138             :     }
     139             : #endif
     140             :     // MD rate Estimation tables
     141          16 :     EB_MALLOC_ARRAY(context_ptr->md_rate_estimation_ptr, 1);
     142          16 :     context_ptr->is_md_rate_estimation_ptr_owner = EB_TRUE;
     143             : 
     144          16 :     EB_MALLOC_ARRAY(context_ptr->md_local_cu_unit, BLOCK_MAX_COUNT_SB_128);
     145          16 :     EB_MALLOC_ARRAY(context_ptr->md_cu_arr_nsq, BLOCK_MAX_COUNT_SB_128);
     146          16 :     EB_MALLOC_ARRAY(context_ptr->md_ep_pipe_sb, BLOCK_MAX_COUNT_SB_128);
     147             : 
     148             :     // Fast Candidate Array
     149          16 :     EB_MALLOC_ARRAY(context_ptr->fast_candidate_array, MODE_DECISION_CANDIDATE_MAX_COUNT);
     150             : 
     151          16 :     EB_MALLOC_ARRAY(context_ptr->fast_candidate_ptr_array, MODE_DECISION_CANDIDATE_MAX_COUNT);
     152             : 
     153       29696 :     for (candidateIndex = 0; candidateIndex < MODE_DECISION_CANDIDATE_MAX_COUNT; ++candidateIndex) {
     154       29680 :         context_ptr->fast_candidate_ptr_array[candidateIndex] = &context_ptr->fast_candidate_array[candidateIndex];
     155       29680 :         context_ptr->fast_candidate_ptr_array[candidateIndex]->md_rate_estimation_ptr = context_ptr->md_rate_estimation_ptr;
     156             : #if PAL_SUP
     157       29680 :         if (cfg_palette)
     158       29680 :             EB_MALLOC_ARRAY(context_ptr->fast_candidate_ptr_array[candidateIndex]->palette_info.color_idx_map, MAX_PALETTE_SQUARE);
     159             :         else
     160           0 :             context_ptr->fast_candidate_ptr_array[candidateIndex]->palette_info.color_idx_map = NULL;
     161             : #endif
     162             :     }
     163             : 
     164             : #if PAL_SUP
     165         240 :     for (int cd = 0; cd < MAX_PAL_CAND; cd++)
     166         224 :         if (cfg_palette)
     167         224 :             EB_MALLOC_ARRAY(context_ptr->palette_cand_array[cd].color_idx_map, MAX_PALETTE_SQUARE);
     168             :         else
     169           0 :             context_ptr->palette_cand_array[cd].color_idx_map = NULL;
     170             : #endif
     171             :     // Transform and Quantization Buffers
     172          16 :     EB_NEW(
     173             :         context_ptr->trans_quant_buffers_ptr,
     174             :         eb_trans_quant_buffers_ctor);
     175             : 
     176             :     // Cost Arrays
     177          16 :     EB_MALLOC_ARRAY(context_ptr->fast_cost_array, MAX_NFL_BUFF);
     178          16 :     EB_MALLOC_ARRAY(context_ptr->full_cost_array, MAX_NFL_BUFF);
     179          16 :     EB_MALLOC_ARRAY(context_ptr->full_cost_skip_ptr, MAX_NFL_BUFF);
     180          16 :     EB_MALLOC_ARRAY(context_ptr->full_cost_merge_ptr, MAX_NFL_BUFF);
     181             :     // Candidate Buffers
     182          16 :     EB_ALLOC_PTR_ARRAY(context_ptr->candidate_buffer_ptr_array, MAX_NFL_BUFF);
     183        2160 :     for (bufferIndex = 0; bufferIndex < MAX_NFL_BUFF; ++bufferIndex) {
     184             : 
     185        2144 :         EB_NEW(
     186             :             context_ptr->candidate_buffer_ptr_array[bufferIndex],
     187             :             mode_decision_candidate_buffer_ctor,
     188             :             context_ptr->hbd_mode_decision ? EB_10BIT : EB_8BIT,
     189             :             &(context_ptr->fast_cost_array[bufferIndex]),
     190             :             &(context_ptr->full_cost_array[bufferIndex]),
     191             :             &(context_ptr->full_cost_skip_ptr[bufferIndex]),
     192             :             &(context_ptr->full_cost_merge_ptr[bufferIndex])
     193             :         );
     194             :     }
     195             : #if ENHANCE_ATB
     196          16 :     EB_NEW(
     197             :         context_ptr->scratch_candidate_buffer,
     198             :         mode_decision_scratch_candidate_buffer_ctor,
     199             :         context_ptr->hbd_mode_decision ? EB_10BIT : EB_8BIT);
     200             : 
     201          16 :     EB_ALLOC_PTR_ARRAY(context_ptr->scratch_candidate_buffer->candidate_ptr, 1);
     202             : #endif
     203          16 :     context_ptr->md_cu_arr_nsq[0].av1xd = NULL;
     204          16 :     context_ptr->md_cu_arr_nsq[0].neigh_left_recon[0] = NULL;
     205          16 :     context_ptr->md_cu_arr_nsq[0].neigh_top_recon[0] = NULL;
     206          16 :     context_ptr->md_cu_arr_nsq[0].neigh_left_recon_16bit[0] = NULL;
     207          16 :     context_ptr->md_cu_arr_nsq[0].neigh_top_recon_16bit[0] = NULL;
     208          16 :     EB_MALLOC_ARRAY(context_ptr->md_cu_arr_nsq[0].av1xd, BLOCK_MAX_COUNT_SB_128);
     209          16 :     uint16_t sz = sizeof(uint16_t);
     210             : #if !HBD_CLEAN_UP // neigh_left_recon_16bit neigh_top_recon_16bit
     211             :     if (context_ptr->hbd_mode_decision) {
     212             : #else
     213          16 :     if (context_ptr->hbd_mode_decision > EB_8_BIT_MD){
     214             : #endif
     215           0 :         EB_MALLOC_ARRAY(context_ptr->md_cu_arr_nsq[0].neigh_left_recon_16bit[0], BLOCK_MAX_COUNT_SB_128 * 128 * 3 * sz);
     216           0 :         EB_MALLOC_ARRAY(context_ptr->md_cu_arr_nsq[0].neigh_top_recon_16bit[0], BLOCK_MAX_COUNT_SB_128 * 128 * 3 * sz);
     217             :     }
     218             : #if HBD_CLEAN_UP
     219          16 :     if (context_ptr->hbd_mode_decision != EB_10_BIT_MD){
     220             : #else
     221             :     else {
     222             : #endif
     223          16 :         EB_MALLOC_ARRAY(context_ptr->md_cu_arr_nsq[0].neigh_left_recon[0], BLOCK_MAX_COUNT_SB_128 * 128 * 3);
     224          16 :         EB_MALLOC_ARRAY(context_ptr->md_cu_arr_nsq[0].neigh_top_recon[0], BLOCK_MAX_COUNT_SB_128 * 128 * 3);
     225             :     }
     226             :     uint32_t codedLeafIndex, tu_index;
     227       70752 :     for (codedLeafIndex = 0; codedLeafIndex < BLOCK_MAX_COUNT_SB_128; ++codedLeafIndex) {
     228      424416 :         for (tu_index = 0; tu_index < TRANSFORM_UNIT_MAX_COUNT; ++tu_index)
     229      353680 :             context_ptr->md_cu_arr_nsq[codedLeafIndex].transform_unit_array[tu_index].tu_index = tu_index;
     230       70736 :         const BlockGeom * blk_geom = get_blk_geom_mds(codedLeafIndex);
     231             :         UNUSED(blk_geom);
     232       70736 :         context_ptr->md_cu_arr_nsq[codedLeafIndex].av1xd = context_ptr->md_cu_arr_nsq[0].av1xd + codedLeafIndex;
     233             : #if !HBD_CLEAN_UP
     234             :         if (context_ptr->hbd_mode_decision) {
     235             : #endif
     236      282944 :              for (int i = 0; i < 3; i++) {
     237      212208 :                 size_t offset = (codedLeafIndex * 128 * 3 + i * 128) * sz;
     238      212208 :                 context_ptr->md_cu_arr_nsq[codedLeafIndex].neigh_left_recon_16bit[i] = context_ptr->md_cu_arr_nsq[0].neigh_left_recon_16bit[0] + offset;
     239      212208 :                 context_ptr->md_cu_arr_nsq[codedLeafIndex].neigh_top_recon_16bit[i] = context_ptr->md_cu_arr_nsq[0].neigh_top_recon_16bit[0] + offset;
     240             :             }
     241             : #if !HBD_CLEAN_UP
     242             :         } else {
     243             : #endif
     244      282944 :              for (int i = 0; i < 3; i++) {
     245      212208 :                 size_t offset = codedLeafIndex * 128 * 3 + i * 128;
     246      212208 :                 context_ptr->md_cu_arr_nsq[codedLeafIndex].neigh_left_recon[i] = context_ptr->md_cu_arr_nsq[0].neigh_left_recon[0] + offset;
     247      212208 :                 context_ptr->md_cu_arr_nsq[codedLeafIndex].neigh_top_recon[i] = context_ptr->md_cu_arr_nsq[0].neigh_top_recon[0] + offset;
     248             : #if !HBD_CLEAN_UP
     249             :             }
     250             : #endif
     251             :         }
     252             : #if PAL_SUP
     253       70736 :         if (cfg_palette)
     254       70736 :             EB_MALLOC_ARRAY(context_ptr->md_cu_arr_nsq[codedLeafIndex].palette_info.color_idx_map, MAX_PALETTE_SQUARE);
     255             :         else
     256           0 :             context_ptr->md_cu_arr_nsq[codedLeafIndex].palette_info.color_idx_map = NULL;
     257             : #endif
     258             : #if NO_ENCDEC //SB128_TODO to upgrade
     259             :         {
     260             :             EbPictureBufferDescInitData initData;
     261             : 
     262             :             initData.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK;
     263             :             initData.max_width = SB_STRIDE_Y;
     264             :             initData.max_height = SB_STRIDE_Y;
     265             :             initData.bit_depth = EB_32BIT;
     266             :             initData.color_format = EB_YUV420;
     267             :             initData.left_padding = 0;
     268             :             initData.right_padding = 0;
     269             :             initData.top_padding = 0;
     270             :             initData.bot_padding = 0;
     271             :             initData.split_mode = EB_FALSE;
     272             : 
     273             :             EB_NEW(
     274             :                 context_ptr->md_cu_arr_nsq[codedLeafIndex].coeff_tmp,
     275             :                 eb_picture_buffer_desc_ctor,
     276             :                 (EbPtr)&initData);
     277             : 
     278             :             initData.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK;
     279             :             initData.max_width = SB_STRIDE_Y;
     280             :             initData.max_height = SB_STRIDE_Y;
     281             :             initData.bit_depth = EB_8BIT;
     282             :             initData.color_format = EB_YUV420;
     283             :             initData.left_padding = 0;
     284             :             initData.right_padding = 0;
     285             :             initData.top_padding = 0;
     286             :             initData.bot_padding = 0;
     287             :             initData.split_mode = EB_FALSE;
     288             : 
     289             :             EB_NEW(
     290             :                 context_ptr->md_cu_arr_nsq[codedLeafIndex].recon_tmp,
     291             :                 eb_picture_buffer_desc_ctor,
     292             :                 (EbPtr)&initData);
     293             :         }
     294             : #endif
     295             :     }
     296          16 :     EB_MALLOC_ARRAY(context_ptr->ref_best_cost_sq_table, MAX_REF_TYPE_CAND);
     297          16 :     EB_MALLOC_ARRAY(context_ptr->ref_best_ref_sq_table, MAX_REF_TYPE_CAND);
     298             : #if ENHANCE_ATB
     299          16 :     EB_MALLOC_ARRAY(context_ptr->above_txfm_context, (MAX_SB_SIZE >> MI_SIZE_LOG2));
     300          16 :     EB_MALLOC_ARRAY(context_ptr->left_txfm_context, (MAX_SB_SIZE >> MI_SIZE_LOG2));
     301             : #endif
     302          16 :     return EB_ErrorNone;
     303             : }
     304             : 
     305             : /**************************************************
     306             :  * Reset Mode Decision Neighbor Arrays
     307             :  *************************************************/
     308         120 : void reset_mode_decision_neighbor_arrays(PictureControlSet *picture_control_set_ptr)
     309             : {
     310             :     uint8_t depth;
     311         600 :     for (depth = 0; depth < NEIGHBOR_ARRAY_TOTAL_COUNT; depth++) {
     312         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_intra_luma_mode_neighbor_array[depth]);
     313         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_intra_chroma_mode_neighbor_array[depth]);
     314         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_mv_neighbor_array[depth]);
     315         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_skip_flag_neighbor_array[depth]);
     316         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_mode_type_neighbor_array[depth]);
     317         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_leaf_depth_neighbor_array[depth]);
     318         480 :         neighbor_array_unit_reset(picture_control_set_ptr->mdleaf_partition_neighbor_array[depth]);
     319             : 
     320             : #if !HBD_CLEAN_UP // md_luma_recon_neighbor_array md_tx_depth_1_luma_recon_neighbor_array
     321             :         if (!picture_control_set_ptr->hbd_mode_decision) {
     322             : #else
     323         480 :         if (picture_control_set_ptr->hbd_mode_decision != EB_10_BIT_MD) {
     324             : #endif
     325         480 :             neighbor_array_unit_reset(picture_control_set_ptr->md_luma_recon_neighbor_array[depth]);
     326         480 :             neighbor_array_unit_reset(picture_control_set_ptr->md_tx_depth_1_luma_recon_neighbor_array[depth]);
     327         480 :             neighbor_array_unit_reset(picture_control_set_ptr->md_cb_recon_neighbor_array[depth]);
     328         480 :             neighbor_array_unit_reset(picture_control_set_ptr->md_cr_recon_neighbor_array[depth]);
     329             :         }
     330             : #if HBD_CLEAN_UP
     331         480 :         if (picture_control_set_ptr->hbd_mode_decision > EB_8_BIT_MD) {
     332             : #else
     333             :          else {
     334             : #endif
     335             : 
     336           0 :             neighbor_array_unit_reset(picture_control_set_ptr->md_luma_recon_neighbor_array16bit[depth]);
     337           0 :             neighbor_array_unit_reset(picture_control_set_ptr->md_tx_depth_1_luma_recon_neighbor_array16bit[depth]);
     338           0 :             neighbor_array_unit_reset(picture_control_set_ptr->md_cb_recon_neighbor_array16bit[depth]);
     339           0 :             neighbor_array_unit_reset(picture_control_set_ptr->md_cr_recon_neighbor_array16bit[depth]);
     340             :         }
     341             : 
     342         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_skip_coeff_neighbor_array[depth]);
     343         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_luma_dc_sign_level_coeff_neighbor_array[depth]);
     344         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_tx_depth_1_luma_dc_sign_level_coeff_neighbor_array[depth]);
     345         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_cb_dc_sign_level_coeff_neighbor_array[depth]);
     346         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_cr_dc_sign_level_coeff_neighbor_array[depth]);
     347         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_txfm_context_array[depth]);
     348         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_inter_pred_dir_neighbor_array[depth]);
     349         480 :         neighbor_array_unit_reset(picture_control_set_ptr->md_ref_frame_type_neighbor_array[depth]);
     350             : 
     351         480 :         neighbor_array_unit_reset32(picture_control_set_ptr->md_interpolation_type_neighbor_array[depth]);
     352             :     }
     353             : 
     354         120 :     return;
     355             : }
     356             : 
     357           0 : extern void lambda_assign_low_delay(
     358             :     uint32_t                    *fast_lambda,
     359             :     uint32_t                    *full_lambda,
     360             :     uint32_t                    *fast_chroma_lambda,
     361             :     uint32_t                    *full_chroma_lambda,
     362             :     uint32_t                    *full_chroma_lambda_sao,
     363             :     uint8_t                      qp_hierarchical_position,
     364             :     uint8_t                      qp,
     365             :     uint8_t                      chroma_qp)
     366             : 
     367             : {
     368           0 :     if (qp_hierarchical_position == 0) {
     369           0 :         *fast_lambda = lambda_mode_decision_ld_sad[qp];
     370           0 :         *fast_chroma_lambda = lambda_mode_decision_ld_sad[qp];
     371           0 :         *full_lambda = lambda_mode_decision_ld_sse[qp];
     372           0 :         *full_chroma_lambda = lambda_mode_decision_ld_sse[qp];
     373           0 :         *full_chroma_lambda_sao = lambda_mode_decision_ld_sse[chroma_qp];
     374             :     }
     375             :     else { // Hierarchical postions 1, 2, 3, 4, 5
     376           0 :         *fast_lambda = lambda_mode_decision_ld_sad_qp_scaling[qp];
     377           0 :         *fast_chroma_lambda = lambda_mode_decision_ld_sad_qp_scaling[qp];
     378           0 :         *full_lambda = lambda_mode_decision_ld_sse_qp_scaling[qp];
     379           0 :         *full_chroma_lambda = lambda_mode_decision_ld_sse_qp_scaling[qp];
     380           0 :         *full_chroma_lambda_sao = lambda_mode_decision_ld_sse_qp_scaling[chroma_qp];
     381             :     }
     382           0 : }
     383             : 
     384           0 : void lambda_assign_random_access(
     385             :     uint32_t                    *fast_lambda,
     386             :     uint32_t                    *full_lambda,
     387             :     uint32_t                    *fast_chroma_lambda,
     388             :     uint32_t                    *full_chroma_lambda,
     389             :     uint32_t                    *full_chroma_lambda_sao,
     390             :     uint8_t                      qp_hierarchical_position,
     391             :     uint8_t                      qp,
     392             :     uint8_t                      chroma_qp)
     393             : 
     394             : {
     395           0 :     if (qp_hierarchical_position == 0) {
     396           0 :         *fast_lambda = lambda_mode_decision_ra_sad[qp];
     397           0 :         *fast_chroma_lambda = lambda_mode_decision_ra_sad[qp];
     398           0 :         *full_lambda = lambda_mode_decision_ra_sse[qp];
     399           0 :         *full_chroma_lambda = lambda_mode_decision_ra_sse[qp];
     400           0 :         *full_chroma_lambda_sao = lambda_mode_decision_ra_sse[chroma_qp];
     401             :     }
     402           0 :     else if (qp_hierarchical_position < 3) { // Hierarchical postions 1, 2
     403             : 
     404           0 :         *fast_lambda = lambda_mode_decision_ra_sad_qp_scaling_l1[qp];
     405           0 :         *fast_chroma_lambda = lambda_mode_decision_ra_sad_qp_scaling_l1[qp];
     406           0 :         *full_lambda = lambda_mode_decision_ra_sse_qp_scaling_l1[qp];
     407           0 :         *full_chroma_lambda = lambda_mode_decision_ra_sse_qp_scaling_l1[qp];
     408           0 :         *full_chroma_lambda_sao = lambda_mode_decision_ra_sse_qp_scaling_l1[chroma_qp];
     409             :     }
     410             :     else { // Hierarchical postions 3, 4, 5
     411           0 :         *fast_lambda = lambda_mode_decision_ra_sad_qp_scaling_l3[qp];
     412           0 :         *fast_chroma_lambda = lambda_mode_decision_ra_sad_qp_scaling_l3[qp];
     413           0 :         *full_lambda = lambda_mode_decision_ra_sse_qp_scaling_l3[qp];
     414           0 :         *full_chroma_lambda = lambda_mode_decision_ra_sse_qp_scaling_l3[qp];
     415           0 :         *full_chroma_lambda_sao = lambda_mode_decision_ra_sse_qp_scaling_l3[chroma_qp];
     416             :     }
     417           0 : }
     418             : 
     419           0 : void lambdaAssignISlice(
     420             :     uint32_t                    *fast_lambda,
     421             :     uint32_t                    *full_lambda,
     422             :     uint32_t                    *fast_chroma_lambda,
     423             :     uint32_t                    *full_chroma_lambda,
     424             :     uint32_t                    *full_chroma_lambda_sao,
     425             :     uint8_t                      qp_hierarchical_position,
     426             :     uint8_t                      qp,
     427             :     uint8_t                      chroma_qp)
     428             : 
     429             : {
     430           0 :     if (qp_hierarchical_position == 0) {
     431           0 :         *fast_lambda = lambda_mode_decision_i_slice_sad[qp];
     432           0 :         *fast_chroma_lambda = lambda_mode_decision_i_slice_sad[qp];
     433           0 :         *full_lambda = lambda_mode_decision_i_slice_sse[qp];
     434           0 :         *full_chroma_lambda = lambda_mode_decision_i_slice_sse[qp];
     435           0 :         *full_chroma_lambda_sao = lambda_mode_decision_i_slice_sse[chroma_qp];
     436             :     }
     437           0 : }
     438             : const EbLambdaAssignFunc lambda_assignment_function_table[4] = {
     439             :     lambda_assign_low_delay, // low delay P
     440             :     lambda_assign_low_delay, // low delay B
     441             :     lambda_assign_random_access, // Random Access
     442             :     lambdaAssignISlice // I_SLICE
     443             : };
     444             : 
     445       28912 : void Av1lambdaAssign(
     446             :     uint32_t                    *fast_lambda,
     447             :     uint32_t                    *full_lambda,
     448             :     uint32_t                    *fast_chroma_lambda,
     449             :     uint32_t                    *full_chroma_lambda,
     450             :     uint8_t                      bit_depth,
     451             :     uint16_t                     qp_index,
     452             :     EbBool                       hbd_mode_decision)
     453             : {
     454       28912 :     if (bit_depth == 8) {
     455       28912 :         *full_lambda = av1_lambda_mode_decision8_bit_sse[qp_index];
     456       28912 :         *fast_lambda = av1_lambda_mode_decision8_bit_sad[qp_index];
     457             :     }
     458           0 :     else if (bit_depth == 10) {
     459           0 :         *full_lambda = av1lambda_mode_decision10_bit_sse[qp_index];
     460           0 :         *fast_lambda = av1lambda_mode_decision10_bit_sad[qp_index];
     461           0 :         if (hbd_mode_decision) {
     462           0 :             *full_lambda *= 16;
     463           0 :             *fast_lambda *= 4;
     464             :         }
     465             :     }
     466           0 :     else if (bit_depth == 12) {
     467           0 :         *full_lambda = av1lambda_mode_decision12_bit_sse[qp_index];
     468           0 :         *fast_lambda = av1lambda_mode_decision12_bit_sad[qp_index];
     469             :     }
     470             :     else {
     471           0 :         assert(bit_depth >= 8);
     472           0 :         assert(bit_depth <= 12);
     473             :     }
     474             : 
     475             :     //*full_lambda = 0; //-------------Nader
     476             :     //*fast_lambda = 0;
     477       28912 :     *fast_chroma_lambda = *fast_lambda;
     478       28912 :     *full_chroma_lambda = *full_lambda;
     479             : 
     480             :     // NM: To be done: tune lambda based on the picture type and layer.
     481       28912 : }
     482             : const EbAv1LambdaAssignFunc av1_lambda_assignment_function_table[4] = {
     483             :     Av1lambdaAssign,
     484             :     Av1lambdaAssign,
     485             :     Av1lambdaAssign,
     486             :     Av1lambdaAssign,
     487             : };
     488             : 
     489        7200 : void reset_mode_decision(
     490             : #if EIGHT_PEL_PREDICTIVE_ME
     491             :     SequenceControlSet    *sequence_control_set_ptr,
     492             : #endif
     493             :     ModeDecisionContext   *context_ptr,
     494             :     PictureControlSet     *picture_control_set_ptr,
     495             :     uint32_t                   segment_index)
     496             : {
     497        7200 :     FrameHeader *frm_hdr = &picture_control_set_ptr->parent_pcs_ptr->frm_hdr;
     498             : 
     499             :     // QP
     500             : #if ADD_DELTA_QP_SUPPORT
     501        7200 :     uint16_t picture_qp = picture_control_set_ptr->parent_pcs_ptr->frm_hdr.quantization_params.base_q_idx;
     502        7200 :     context_ptr->qp = picture_qp;
     503        7200 :     context_ptr->qp_index = context_ptr->qp;
     504             : #else
     505             :     context_ptr->qp = picture_control_set_ptr->picture_qp;
     506             : #endif
     507             :     // Asuming cb and cr offset to be the same for chroma QP in both slice and pps for lambda computation
     508        7200 :     context_ptr->chroma_qp = (uint8_t)context_ptr->qp;
     509        7200 :     context_ptr->qp_index = (uint8_t)frm_hdr->quantization_params.base_q_idx;
     510        7200 :     (*av1_lambda_assignment_function_table[picture_control_set_ptr->parent_pcs_ptr->pred_structure])(
     511             :         &context_ptr->fast_lambda,
     512             :         &context_ptr->full_lambda,
     513             :         &context_ptr->fast_chroma_lambda,
     514             :         &context_ptr->full_chroma_lambda,
     515        7200 :         (uint8_t)picture_control_set_ptr->parent_pcs_ptr->enhanced_picture_ptr->bit_depth,
     516        7200 :         context_ptr->qp_index,
     517        7200 :         context_ptr->hbd_mode_decision);
     518             :     // Reset MD rate Estimation table to initial values by copying from md_rate_estimation_array
     519        7200 :     if (context_ptr->is_md_rate_estimation_ptr_owner) {
     520          16 :         context_ptr->is_md_rate_estimation_ptr_owner = EB_FALSE;
     521          16 :         EB_FREE_ARRAY(context_ptr->md_rate_estimation_ptr);
     522             :     }
     523        7200 :     context_ptr->md_rate_estimation_ptr = picture_control_set_ptr->md_rate_estimation_array;
     524             :     uint32_t  candidateIndex;
     525    12346300 :     for (candidateIndex = 0; candidateIndex < MODE_DECISION_CANDIDATE_MAX_COUNT; ++candidateIndex)
     526    12339100 :         context_ptr->fast_candidate_ptr_array[candidateIndex]->md_rate_estimation_ptr = context_ptr->md_rate_estimation_ptr;
     527             : 
     528             :     // Reset CABAC Contexts
     529        7200 :     context_ptr->coeff_est_entropy_coder_ptr = picture_control_set_ptr->coeff_est_entropy_coder_ptr;
     530             : 
     531             :     // Reset Neighbor Arrays at start of new Segment / Picture
     532        7200 :     if (segment_index == 0) {
     533         120 :         reset_mode_decision_neighbor_arrays(picture_control_set_ptr);
     534             : #if !FIX_SETTINGS_RESET
     535             :     }
     536             : #endif
     537             : #if EIGHT_PEL_PREDICTIVE_ME
     538         240 :     picture_control_set_ptr->parent_pcs_ptr->frm_hdr.allow_high_precision_mv = picture_control_set_ptr->enc_mode == ENC_M0 &&
     539         120 :         (sequence_control_set_ptr->input_resolution == INPUT_SIZE_576p_RANGE_OR_LOWER) ? 1 : 0;
     540             : #else
     541             : #if EIGTH_PEL_MV
     542             :     picture_control_set_ptr->parent_pcs_ptr->allow_high_precision_mv = picture_control_set_ptr->enc_mode == ENC_M0 &&
     543             :         (picture_control_set_ptr->parent_pcs_ptr->is_pan || picture_control_set_ptr->parent_pcs_ptr->is_tilt) ? 1 : 0;
     544             : #endif
     545             : #endif
     546             :     EbBool enable_wm;
     547         120 :     if (picture_control_set_ptr->parent_pcs_ptr->sc_content_detected)
     548           0 :         enable_wm = EB_FALSE;
     549             :     else
     550             : #if WARP_UPDATE
     551         120 :         enable_wm = (MR_MODE ||
     552          60 :         (picture_control_set_ptr->parent_pcs_ptr->enc_mode == ENC_M0 && picture_control_set_ptr->parent_pcs_ptr->is_used_as_reference_flag) ||
     553         180 :         (picture_control_set_ptr->parent_pcs_ptr->enc_mode <= ENC_M5 && picture_control_set_ptr->parent_pcs_ptr->temporal_layer_index == 0)) ? EB_TRUE : EB_FALSE;
     554             : #else
     555             :         enable_wm = (picture_control_set_ptr->parent_pcs_ptr->enc_mode <= ENC_M5) || MR_MODE ? EB_TRUE : EB_FALSE;
     556             : #endif
     557             : #if !FIX_WM_SETTINGS
     558             :     enable_wm = picture_control_set_ptr->parent_pcs_ptr->temporal_layer_index > 0 ? EB_FALSE : enable_wm;
     559             : #endif
     560         120 :     frm_hdr->allow_warped_motion = enable_wm
     561          38 :         && !(frm_hdr->frame_type == KEY_FRAME || frm_hdr->frame_type == INTRA_ONLY_FRAME)
     562         158 :         && !frm_hdr->error_resilient_mode;
     563         120 :     frm_hdr->is_motion_mode_switchable = frm_hdr->allow_warped_motion;
     564             : #if OBMC_FLAG
     565             :     // OBMC Level                                   Settings
     566             :     // 0                                            OFF
     567             :     // 1                                            OBMC @(MVP, PME and ME) + 16 NICs
     568             :     // 2                                            OBMC @(MVP, PME and ME) + Opt NICs
     569             :     // 3                                            OBMC @(MVP, PME ) + Opt NICs
     570             :     // 4                                            OBMC @(MVP, PME ) + Opt2 NICs
     571         120 :     if (sequence_control_set_ptr->static_config.enable_obmc) {
     572         120 :         if (picture_control_set_ptr->parent_pcs_ptr->enc_mode <= ENC_M0)
     573          60 :             picture_control_set_ptr->parent_pcs_ptr->pic_obmc_mode =
     574          60 :             picture_control_set_ptr->parent_pcs_ptr->sc_content_detected == 0 && picture_control_set_ptr->slice_type != I_SLICE ? 2 : 0;
     575             :         else
     576          60 :             picture_control_set_ptr->parent_pcs_ptr->pic_obmc_mode = 0;
     577             : 
     578             : #if MR_MODE
     579             :         picture_control_set_ptr->parent_pcs_ptr->pic_obmc_mode =
     580             :             picture_control_set_ptr->parent_pcs_ptr->sc_content_detected == 0 && picture_control_set_ptr->slice_type != I_SLICE ? 1 : 0;
     581             : #endif
     582             :     }
     583             :     else
     584           0 :         picture_control_set_ptr->parent_pcs_ptr->pic_obmc_mode = 0;
     585             : 
     586         120 :     frm_hdr->is_motion_mode_switchable =
     587         120 :         frm_hdr->is_motion_mode_switchable || picture_control_set_ptr->parent_pcs_ptr->pic_obmc_mode;
     588             : 
     589             : #endif
     590             : #if FIX_SETTINGS_RESET
     591             :     }
     592             : #endif
     593        7200 :     return;
     594             : }
     595             : 
     596             : /******************************************************
     597             :  * Mode Decision Configure LCU
     598             :  ******************************************************/
     599        7200 : void mode_decision_configure_lcu(
     600             :     ModeDecisionContext   *context_ptr,
     601             :     PictureControlSet     *picture_control_set_ptr,
     602             :     uint8_t                    sb_qp){
     603             :     (void)picture_control_set_ptr;
     604             :     //Disable Lambda update per LCU
     605        7200 :     context_ptr->qp = sb_qp;
     606             :     // Asuming cb and cr offset to be the same for chroma QP in both slice and pps for lambda computation
     607             : 
     608        7200 :     context_ptr->chroma_qp = (uint8_t)context_ptr->qp;
     609             : 
     610             :     /* Note(CHKN) : when Qp modulation varies QP on a sub-LCU(CU) basis,  Lamda has to change based on Cu->QP , and then this code has to move inside the CU loop in MD */
     611             : 
     612             :     // Lambda Assignement
     613        7200 :     context_ptr->qp_index = picture_control_set_ptr->parent_pcs_ptr->frm_hdr.delta_q_params.delta_q_present ? (uint8_t)quantizer_to_qindex[sb_qp] : (uint8_t)picture_control_set_ptr->parent_pcs_ptr->frm_hdr.quantization_params.base_q_idx;
     614             : 
     615        7200 :     (*av1_lambda_assignment_function_table[picture_control_set_ptr->parent_pcs_ptr->pred_structure])(
     616             :         &context_ptr->fast_lambda,
     617             :         &context_ptr->full_lambda,
     618             :         &context_ptr->fast_chroma_lambda,
     619             :         &context_ptr->full_chroma_lambda,
     620        7200 :         (uint8_t)picture_control_set_ptr->parent_pcs_ptr->enhanced_picture_ptr->bit_depth,
     621        7200 :         context_ptr->qp_index,
     622        7200 :         context_ptr->hbd_mode_decision);
     623             : 
     624        7199 :     return;
     625             : }

Generated by: LCOV version 1.14