LCOV - code coverage report
Current view: top level - Codec - EbSequenceControlSet.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 268 283 94.7 %
Date: 2019-11-25 17:38:06 Functions: 9 9 100.0 %

          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 "EbDefinitions.h"
       9             : #include "EbSequenceControlSet.h"
      10             : 
      11           8 : static void eb_sequence_control_set_dctor(EbPtr p)
      12             : {
      13           8 :     SequenceControlSet *obj = (SequenceControlSet*)p;
      14           8 :     EB_FREE_ARRAY(obj->sb_params_array);
      15           8 :     EB_FREE_ARRAY(obj->sb_geom);
      16           8 : }
      17             : 
      18             : /**************************************************************************************************
      19             :     General notes on how Sequence Control Sets (SCS) are used.
      20             : 
      21             :     SequenceControlSetInstance
      22             :         is the master copy that interacts with the API in real-time.  When a
      23             :         change happens, the changeFlag is signaled so that appropriate action can
      24             :         be taken.  There is one scsInstance per stream/encode instance.  The scsInstance
      25             :         owns the encodeContext
      26             : 
      27             :     encodeContext
      28             :         has context type variables (i.e. non-config) that keep track of global parameters.
      29             : 
      30             :     SequenceControlSets
      31             :         general SCSs are controled by a system resource manager.  They are kept completely
      32             :         separate from the instances.  In general there is one active SCS at a time.  When the
      33             :         changeFlag is signaled, the old active SCS is no longer used for new input pictures.
      34             :         A fresh copy of the scsInstance is made to a new SCS, which becomes the active SCS.  The
      35             :         old SCS will eventually be released back into the SCS pool when its current pictures are
      36             :         finished encoding.
      37             : 
      38             :     Motivations
      39             :         The whole reason for this structure is due to the nature of the pipeline.  We have to
      40             :         take great care not to have pipeline mismanagement.  Once an object enters use in the
      41             :         pipeline, it cannot be changed on the fly or you will have pipeline coherency problems.
      42             :  ***************************************************************************************************/
      43           8 : EbErrorType eb_sequence_control_set_ctor(
      44             :     SequenceControlSet *sequence_control_set_ptr,
      45             :     EbPtr object_init_data_ptr)
      46             : {
      47           8 :     EbSequenceControlSetInitData *scsInitData = (EbSequenceControlSetInitData*)object_init_data_ptr;
      48             :     uint32_t segment_index;
      49             : 
      50           8 :     sequence_control_set_ptr->dctor = eb_sequence_control_set_dctor;
      51             : 
      52           8 :     sequence_control_set_ptr->static_config.sb_sz = 64;
      53           8 :     sequence_control_set_ptr->static_config.partition_depth = 4;
      54           8 :     sequence_control_set_ptr->static_config.qp = 32;
      55             : 
      56             :     // Segments
      57          56 :     for (segment_index = 0; segment_index < MAX_TEMPORAL_LAYERS; ++segment_index) {
      58          48 :         sequence_control_set_ptr->me_segment_column_count_array[segment_index] = 1;
      59          48 :         sequence_control_set_ptr->me_segment_row_count_array[segment_index] = 1;
      60          48 :         sequence_control_set_ptr->enc_dec_segment_col_count_array[segment_index] = 1;
      61          48 :         sequence_control_set_ptr->enc_dec_segment_row_count_array[segment_index] = 1;
      62             :     }
      63             : 
      64             :     // Encode Context
      65           8 :     if (scsInitData != EB_NULL)
      66           8 :         sequence_control_set_ptr->encode_context_ptr = scsInitData->encode_context_ptr;
      67             : 
      68             :     // Profile & ID
      69           8 :     sequence_control_set_ptr->chroma_format_idc = EB_YUV420;
      70           8 :     sequence_control_set_ptr->max_temporal_layers = 1;
      71             : 
      72           8 :     sequence_control_set_ptr->bits_for_picture_order_count = 16;
      73           8 :     sequence_control_set_ptr->subsampling_y = 1;
      74           8 :     sequence_control_set_ptr->subsampling_x = 1;
      75             : 
      76           8 :     sequence_control_set_ptr->encoder_bit_depth = 8;
      77             : 
      78             :     // Bitdepth
      79             :     //sequence_control_set_ptr->input_bitdepth = EB_8BIT;
      80             :     //sequence_control_set_ptr->output_bitdepth = EB_8BIT;
      81             : 
      82             :     // GOP Structure
      83           8 :     sequence_control_set_ptr->max_ref_count = 1;
      84             : 
      85             :     // LCU
      86           8 :     sequence_control_set_ptr->sb_sz = 64;
      87           8 :     sequence_control_set_ptr->max_sb_depth = 3;
      88             : 
      89             :     // CU
      90           8 :     sequence_control_set_ptr->max_cu_size = 64;
      91           8 :     sequence_control_set_ptr->min_cu_size = 8;
      92           8 :     sequence_control_set_ptr->max_intra_size = 32;
      93           8 :     sequence_control_set_ptr->min_intra_size = 8;
      94           8 :     sequence_control_set_ptr->intra4x4_flag = EB_TRUE;
      95             : 
      96           8 :     sequence_control_set_ptr->general_progressive_source_flag = 1;
      97           8 :     sequence_control_set_ptr->general_interlaced_source_flag = 0;
      98           8 :     sequence_control_set_ptr->general_frame_only_constraint_flag = 0;
      99             :     // Rate Control
     100           8 :     sequence_control_set_ptr->rate_control_mode = 0;
     101           8 :     sequence_control_set_ptr->target_bitrate = 0x1000;
     102           8 :     sequence_control_set_ptr->available_bandwidth = 0x1000;
     103             : 
     104             :     // Quantization
     105           8 :     sequence_control_set_ptr->qp = 20;
     106             :     // Initialize SB params
     107           8 :     EB_MALLOC_ARRAY(sequence_control_set_ptr->sb_params_array,
     108             :         ((MAX_PICTURE_WIDTH_SIZE + sequence_control_set_ptr->sb_sz - 1) / sequence_control_set_ptr->sb_sz) *
     109             :         ((MAX_PICTURE_HEIGHT_SIZE + sequence_control_set_ptr->sb_sz - 1) / sequence_control_set_ptr->sb_sz));
     110             : 
     111           8 :     sequence_control_set_ptr->seq_header.frame_width_bits = 16;
     112           8 :     sequence_control_set_ptr->seq_header.frame_height_bits = 16;
     113           8 :     sequence_control_set_ptr->seq_header.frame_id_numbers_present_flag = 0;
     114             :     //    cm->large_scale_tile ? 0 : cm->error_resilient_mode;
     115           8 :     sequence_control_set_ptr->seq_header.frame_id_length = FRAME_ID_LENGTH;
     116           8 :     sequence_control_set_ptr->seq_header.delta_frame_id_length = DELTA_FRAME_ID_LENGTH;
     117             : 
     118           8 :     if (scsInitData && scsInitData->sb_size == 128)
     119             :     {
     120           0 :         sequence_control_set_ptr->seq_header.sb_size = BLOCK_128X128;
     121           0 :         sequence_control_set_ptr->sb_size_pix = 128;
     122           0 :         sequence_control_set_ptr->max_block_cnt = 4421;
     123             : 
     124           0 :         sequence_control_set_ptr->seq_header.sb_mi_size = 32;        // Size of the superblock in units of MI blocks
     125           0 :         sequence_control_set_ptr->seq_header.sb_size_log2 = 5;
     126             :     }
     127             :     else
     128             :     {
     129           8 :         sequence_control_set_ptr->seq_header.sb_size = BLOCK_64X64;
     130           8 :         sequence_control_set_ptr->sb_size_pix = 64;
     131           8 :         sequence_control_set_ptr->max_block_cnt = 1101;
     132             : 
     133           8 :         sequence_control_set_ptr->seq_header.sb_mi_size = 16;        // Size of the superblock in units of MI blocks
     134           8 :         sequence_control_set_ptr->seq_header.sb_size_log2 = 4;
     135             :     }
     136             :     // 0 - disable dual interpolation filter
     137             :     // 1 - enable vertical and horiz filter selection
     138           8 :     sequence_control_set_ptr->seq_header.enable_dual_filter = 0;
     139           8 :     sequence_control_set_ptr->seq_header.order_hint_info.enable_order_hint = 1;
     140             :     // 0 - disable order hint, and related tools:
     141             :     // jnt_comp, ref_frame_mvs, frame_sign_bias
     142             :     // if 0, enable_jnt_comp must be set zs 0.
     143           8 :     sequence_control_set_ptr->seq_header.order_hint_info.enable_jnt_comp = 0;
     144             : 
     145           8 :     sequence_control_set_ptr->seq_header.order_hint_info.order_hint_bits = sequence_control_set_ptr->seq_header.order_hint_info.enable_order_hint ? (6+1) : (-1+1);
     146             : 
     147           8 :     sequence_control_set_ptr->seq_header.seq_force_screen_content_tools = 2;
     148             :     // 0 - force off
     149             :     // 1 - force on
     150             :     // 2 - adaptive
     151           8 :     sequence_control_set_ptr->seq_header.seq_force_integer_mv = 2;  // 0 - Not to force. MV can be in 1/4 or 1/8
     152             :     // 1 - force to integer
     153             :     // 2 - adaptive
     154             : 
     155           8 :     sequence_control_set_ptr->seq_header.order_hint_info.enable_ref_frame_mvs = 1;
     156             : #if NO_ENCDEC || SHUT_FILTERING
     157             :     sequence_control_set_ptr->enable_cdef = 0;
     158             : 
     159             :     sequence_control_set_ptr->enable_restoration = 0;
     160             : #else
     161           8 :     sequence_control_set_ptr->seq_header.enable_cdef = 1;
     162           8 :     sequence_control_set_ptr->seq_header.enable_restoration = 1;
     163             : #endif
     164             : 
     165           8 :     sequence_control_set_ptr->film_grain_random_seed = 7391;
     166           8 :     sequence_control_set_ptr->reference_count = 4;
     167             : 
     168           8 :     return EB_ErrorNone;
     169             : }
     170             : 
     171           6 : EbErrorType eb_sequence_control_set_creator(
     172             :     EbPtr *object_dbl_ptr,
     173             :     EbPtr object_init_data_ptr)
     174             : {
     175             :     SequenceControlSet* obj;
     176             : 
     177           6 :     *object_dbl_ptr = NULL;
     178           6 :     EB_NEW(obj, eb_sequence_control_set_ctor, object_init_data_ptr);
     179           6 :     *object_dbl_ptr = obj;
     180           6 :     return EB_ErrorNone;
     181             : }
     182             : 
     183             : /************************************************
     184             :  * Sequence Control Set Copy
     185             :  ************************************************/
     186           2 : EbErrorType copy_sequence_control_set(
     187             :     SequenceControlSet *dst,
     188             :     SequenceControlSet *src)
     189             : {
     190           2 :     uint32_t  writeCount = 0;
     191             : 
     192           2 :     dst->static_config = src->static_config;                            writeCount += sizeof(EbSvtAv1EncConfiguration);
     193           2 :     dst->encode_context_ptr = src->encode_context_ptr;                        writeCount += sizeof(EncodeContext*);
     194           2 :     dst->sps_id = src->sps_id;                                   writeCount += sizeof(uint32_t);
     195           2 :     dst->vps_id = src->vps_id;                                   writeCount += sizeof(uint32_t);
     196           2 :     dst->profile_space = src->profile_space;                            writeCount += sizeof(uint32_t);
     197           2 :     dst->profile_idc = src->profile_idc;                              writeCount += sizeof(uint32_t);
     198           2 :     dst->level_idc = src->level_idc;                                writeCount += sizeof(uint32_t);
     199           2 :     dst->tier_idc = src->tier_idc;                                 writeCount += sizeof(uint32_t);
     200           2 :     dst->chroma_format_idc = src->chroma_format_idc;                         writeCount += sizeof(uint32_t);
     201           2 :     dst->max_temporal_layers = src->max_temporal_layers;                       writeCount += sizeof(uint32_t);
     202           2 :     dst->bits_for_picture_order_count = src->bits_for_picture_order_count;                writeCount += sizeof(uint32_t);
     203           2 :     dst->max_input_luma_width = src->max_input_luma_width;                       writeCount += sizeof(uint32_t);
     204           2 :     dst->max_input_luma_height = src->max_input_luma_height;                      writeCount += sizeof(uint32_t);
     205           2 :     dst->max_input_chroma_height = src->max_input_chroma_height;                    writeCount += sizeof(uint32_t);
     206           2 :     dst->max_input_chroma_width = src->max_input_chroma_width;                     writeCount += sizeof(uint32_t);
     207           2 :     dst->max_input_pad_right = src->max_input_pad_right;                        writeCount += sizeof(uint32_t);
     208           2 :     dst->max_input_pad_bottom = src->max_input_pad_bottom;                       writeCount += sizeof(uint32_t);
     209           2 :     dst->seq_header.max_frame_width = src->seq_header.max_frame_width;                               writeCount += sizeof(uint32_t);
     210           2 :     dst->seq_header.max_frame_height = src->seq_header.max_frame_height;                              writeCount += sizeof(uint32_t);
     211           2 :     dst->chroma_width = src->chroma_width;                             writeCount += sizeof(uint32_t);
     212           2 :     dst->chroma_height = src->chroma_height;                            writeCount += sizeof(uint32_t);
     213           2 :     dst->pad_right = src->pad_right;                                writeCount += sizeof(uint32_t);
     214           2 :     dst->pad_bottom = src->pad_bottom;                               writeCount += sizeof(uint32_t);
     215           2 :     dst->cropping_left_offset = src->cropping_left_offset;                      writeCount += sizeof(int32_t);
     216           2 :     dst->cropping_right_offset = src->cropping_right_offset;                     writeCount += sizeof(int32_t);
     217           2 :     dst->cropping_top_offset = src->cropping_top_offset;                       writeCount += sizeof(int32_t);
     218           2 :     dst->cropping_bottom_offset = src->cropping_bottom_offset;                    writeCount += sizeof(int32_t);
     219           2 :     dst->conformance_window_flag = src->conformance_window_flag;                   writeCount += sizeof(uint32_t);
     220           2 :     dst->frame_rate = src->frame_rate;                               writeCount += sizeof(uint32_t);
     221             :     //dst->input_bitdepth = src->input_bitdepth;                           writeCount += sizeof(EB_BITDEPTH);
     222             :     //dst->output_bitdepth = src->output_bitdepth;                          writeCount += sizeof(EB_BITDEPTH);
     223           2 :     dst->encoder_bit_depth = src->encoder_bit_depth;                      writeCount += sizeof(uint32_t);
     224           2 :     dst->subsampling_x = src->subsampling_x;                writeCount += sizeof(uint16_t);
     225           2 :     dst->subsampling_y = src->subsampling_y;                writeCount += sizeof(uint16_t);
     226           2 :     dst->pred_struct_ptr = src->pred_struct_ptr;                           writeCount += sizeof(PredictionStructure*);
     227           2 :     dst->intra_period_length = src->intra_period_length;                       writeCount += sizeof(int32_t);
     228           2 :     dst->intra_refresh_type = src->intra_refresh_type;                        writeCount += sizeof(uint32_t);
     229           2 :     dst->max_ref_count = src->max_ref_count;                             writeCount += sizeof(uint32_t);
     230           2 :     dst->sb_sz = src->sb_sz;                                 writeCount += sizeof(uint32_t);
     231           2 :     dst->max_sb_depth = src->max_sb_depth;                             writeCount += sizeof(uint32_t);
     232           2 :     dst->max_cu_size = src->max_cu_size;                               writeCount += sizeof(uint32_t);
     233           2 :     dst->min_cu_size = src->min_cu_size;                               writeCount += sizeof(uint32_t);
     234           2 :     dst->max_intra_size = src->max_intra_size;                            writeCount += sizeof(uint32_t);
     235           2 :     dst->min_intra_size = src->min_intra_size;                            writeCount += sizeof(uint32_t);
     236           2 :     dst->intra4x4_flag = src->intra4x4_flag;                            writeCount += sizeof(EbBool);
     237           2 :     dst->general_progressive_source_flag = src->general_progressive_source_flag;        writeCount += sizeof(uint32_t);
     238           2 :     dst->general_interlaced_source_flag = src->general_interlaced_source_flag;         writeCount += sizeof(uint32_t);
     239           2 :     dst->general_frame_only_constraint_flag = src->general_frame_only_constraint_flag;      writeCount += sizeof(uint32_t);
     240           2 :     dst->target_bitrate = src->target_bitrate;                           writeCount += sizeof(uint32_t);
     241           2 :     dst->available_bandwidth = src->available_bandwidth;                      writeCount += sizeof(uint32_t);
     242           2 :     dst->qp = src->qp;                                      writeCount += sizeof(uint32_t);
     243           2 :     dst->film_grain_denoise_strength = src->film_grain_denoise_strength;          writeCount += sizeof(int32_t);
     244           2 :     dst->seq_header.film_grain_params_present = src->seq_header.film_grain_params_present;              writeCount += sizeof(int32_t);
     245           2 :     dst->seq_header.film_grain_params_present = src->seq_header.film_grain_params_present;              writeCount += sizeof(int32_t);
     246           2 :     dst->picture_control_set_pool_init_count = src->picture_control_set_pool_init_count;            writeCount += sizeof(int32_t);
     247           2 :     dst->picture_control_set_pool_init_count_child = src->picture_control_set_pool_init_count_child; writeCount += sizeof(int32_t);
     248           2 :     dst->pa_reference_picture_buffer_init_count = src->pa_reference_picture_buffer_init_count; writeCount += sizeof(int32_t);
     249           2 :     dst->reference_picture_buffer_init_count = src->reference_picture_buffer_init_count; writeCount += sizeof(int32_t);
     250           2 :     dst->input_buffer_fifo_init_count = src->input_buffer_fifo_init_count; writeCount += sizeof(int32_t);
     251           2 :     dst->overlay_input_picture_buffer_init_count = src->overlay_input_picture_buffer_init_count; writeCount += sizeof(int32_t);
     252             : 
     253           2 :     dst->output_stream_buffer_fifo_init_count = src->output_stream_buffer_fifo_init_count; writeCount += sizeof(int32_t);
     254           2 :     dst->output_recon_buffer_fifo_init_count = src->output_recon_buffer_fifo_init_count; writeCount += sizeof(int32_t);
     255           2 :     dst->resource_coordination_fifo_init_count = src->resource_coordination_fifo_init_count; writeCount += sizeof(int32_t);
     256           2 :     dst->picture_analysis_fifo_init_count = src->picture_analysis_fifo_init_count; writeCount += sizeof(int32_t);
     257           2 :     dst->picture_decision_fifo_init_count = src->picture_decision_fifo_init_count; writeCount += sizeof(int32_t);
     258           2 :     dst->motion_estimation_fifo_init_count = src->motion_estimation_fifo_init_count; writeCount += sizeof(int32_t);
     259           2 :     dst->initial_rate_control_fifo_init_count = src->initial_rate_control_fifo_init_count; writeCount += sizeof(int32_t);
     260           2 :     dst->picture_demux_fifo_init_count = src->picture_demux_fifo_init_count; writeCount += sizeof(int32_t);
     261           2 :     dst->rate_control_tasks_fifo_init_count = src->rate_control_tasks_fifo_init_count; writeCount += sizeof(int32_t);
     262           2 :     dst->rate_control_fifo_init_count = src->rate_control_fifo_init_count; writeCount += sizeof(int32_t);
     263           2 :     dst->mode_decision_configuration_fifo_init_count = src->mode_decision_configuration_fifo_init_count; writeCount += sizeof(int32_t);
     264           2 :     dst->enc_dec_fifo_init_count = src->enc_dec_fifo_init_count; writeCount += sizeof(int32_t);
     265           2 :     dst->entropy_coding_fifo_init_count = src->entropy_coding_fifo_init_count; writeCount += sizeof(int32_t);
     266           2 :     dst->picture_analysis_process_init_count = src->picture_analysis_process_init_count; writeCount += sizeof(int32_t);
     267           2 :     dst->motion_estimation_process_init_count = src->motion_estimation_process_init_count; writeCount += sizeof(int32_t);
     268           2 :     dst->source_based_operations_process_init_count = src->source_based_operations_process_init_count; writeCount += sizeof(int32_t);
     269           2 :     dst->mode_decision_configuration_process_init_count = src->mode_decision_configuration_process_init_count; writeCount += sizeof(int32_t);
     270           2 :     dst->enc_dec_process_init_count = src->enc_dec_process_init_count; writeCount += sizeof(int32_t);
     271           2 :     dst->entropy_coding_process_init_count = src->entropy_coding_process_init_count; writeCount += sizeof(int32_t);
     272           2 :     dst->total_process_init_count = src->total_process_init_count; writeCount += sizeof(int32_t);
     273           2 :     dst->left_padding = src->left_padding; writeCount += sizeof(int16_t);
     274           2 :     dst->right_padding = src->right_padding; writeCount += sizeof(int16_t);
     275           2 :     dst->top_padding = src->top_padding; writeCount += sizeof(int16_t);
     276           2 :     dst->bot_padding = src->bot_padding; writeCount += sizeof(int16_t);
     277           2 :     dst->reference_count = src->reference_count; writeCount += sizeof(uint32_t);
     278          14 :     for (uint8_t i = 0; i< MAX_HIERARCHICAL_LEVEL; i++) {
     279          12 :         dst->me_segment_column_count_array[i] = src->me_segment_column_count_array[i];
     280          12 :         dst->me_segment_row_count_array[i] = src->me_segment_row_count_array[i];
     281          12 :         dst->enc_dec_segment_col_count_array[i] = src->enc_dec_segment_col_count_array[i];
     282          12 :         dst->enc_dec_segment_row_count_array[i] = src->enc_dec_segment_row_count_array[i];
     283             :     }
     284             : 
     285           2 :     dst->cdef_segment_column_count = src->cdef_segment_column_count;
     286           2 :     dst->cdef_segment_row_count = src->cdef_segment_row_count;
     287             : 
     288           2 :     dst->rest_segment_column_count = src->rest_segment_column_count;
     289           2 :     dst->rest_segment_row_count = src->rest_segment_row_count;
     290           2 :     dst->mrp_mode       = src->mrp_mode;
     291           2 :     dst->nsq_present    = src->nsq_present;
     292           2 :     dst->cdf_mode       = src->cdf_mode;
     293           2 :     dst->down_sampling_method_me_search = src->down_sampling_method_me_search;
     294           2 :     dst->tf_segment_column_count = src->tf_segment_column_count;
     295           2 :     dst->tf_segment_row_count = src->tf_segment_row_count;
     296           2 :     dst->over_boundary_block_mode = src->over_boundary_block_mode;
     297           2 :     dst->mfmv_enabled = src->mfmv_enabled;
     298             : #if TWO_PASS
     299           2 :     dst->use_input_stat_file = src->use_input_stat_file;
     300           2 :     dst->use_output_stat_file = src->use_output_stat_file;
     301             : #endif
     302           2 :     return EB_ErrorNone;
     303             : }
     304             : 
     305           4 : extern EbErrorType derive_input_resolution(
     306             :     SequenceControlSet *sequenceControlSetPtr,
     307             :     uint32_t                  inputSize) {
     308           4 :     EbErrorType return_error = EB_ErrorNone;
     309             : 
     310           4 :     sequenceControlSetPtr->input_resolution = (inputSize < INPUT_SIZE_1080i_TH) ?
     311             :         INPUT_SIZE_576p_RANGE_OR_LOWER :
     312             :         (inputSize < INPUT_SIZE_1080p_TH) ?
     313             :         INPUT_SIZE_1080i_RANGE :
     314             :         (inputSize < INPUT_SIZE_4K_TH) ?
     315             :         INPUT_SIZE_1080p_RANGE :
     316             :         INPUT_SIZE_4K_RANGE;
     317             : 
     318           4 :     return return_error;
     319             : }
     320             : 
     321           2 : static void eb_sequence_control_set_instance_dctor(EbPtr p)
     322             : {
     323           2 :    EbSequenceControlSetInstance* obj = (EbSequenceControlSetInstance*)p;
     324           2 :    EB_DELETE(obj->encode_context_ptr);
     325           2 :    EB_DELETE(obj->sequence_control_set_ptr);
     326           2 :    EB_DESTROY_MUTEX(obj->config_mutex);
     327           2 : }
     328             : 
     329           2 : EbErrorType eb_sequence_control_set_instance_ctor(
     330             :     EbSequenceControlSetInstance *object_dbl_ptr)
     331             : {
     332             :     EbSequenceControlSetInitData scsInitData;
     333             : 
     334           2 :     object_dbl_ptr->dctor = eb_sequence_control_set_instance_dctor;
     335             : 
     336           2 :     EB_NEW(object_dbl_ptr->encode_context_ptr, encode_context_ctor, EB_NULL);
     337           2 :     scsInitData.encode_context_ptr = object_dbl_ptr->encode_context_ptr;
     338             : 
     339           2 :     scsInitData.sb_size = 64;
     340             : 
     341           2 :     EB_NEW(object_dbl_ptr->sequence_control_set_ptr, eb_sequence_control_set_ctor, (void *)&scsInitData);
     342           2 :     EB_CREATE_MUTEX(object_dbl_ptr->config_mutex);
     343             : 
     344           2 :     return EB_ErrorNone;
     345             : }
     346             : 
     347           2 : extern EbErrorType sb_params_init(
     348             :     SequenceControlSet *sequence_control_set_ptr) {
     349           2 :     EbErrorType return_error = EB_ErrorNone;
     350             :     uint16_t    sb_index;
     351             :     uint16_t    rasterScanCuIndex;
     352           2 :     uint8_t   pictureLcuWidth = (uint8_t)((sequence_control_set_ptr->seq_header.max_frame_width + sequence_control_set_ptr->sb_sz - 1) / sequence_control_set_ptr->sb_sz);
     353           2 :     uint8_t    pictureLcuHeight = (uint8_t)((sequence_control_set_ptr->seq_header.max_frame_height + sequence_control_set_ptr->sb_sz - 1) / sequence_control_set_ptr->sb_sz);
     354             :     //free old one;
     355           2 :     EB_FREE_ARRAY(sequence_control_set_ptr->sb_params_array);
     356             : 
     357           2 :     EB_MALLOC_ARRAY(sequence_control_set_ptr->sb_params_array, pictureLcuWidth * pictureLcuHeight);
     358             : 
     359         122 :     for (sb_index = 0; sb_index < pictureLcuWidth * pictureLcuHeight; ++sb_index) {
     360         120 :         sequence_control_set_ptr->sb_params_array[sb_index].horizontal_index = (uint8_t)(sb_index % pictureLcuWidth);
     361         120 :         sequence_control_set_ptr->sb_params_array[sb_index].vertical_index = (uint8_t)(sb_index / pictureLcuWidth);
     362         120 :         sequence_control_set_ptr->sb_params_array[sb_index].origin_x = sequence_control_set_ptr->sb_params_array[sb_index].horizontal_index * sequence_control_set_ptr->sb_sz;
     363         120 :         sequence_control_set_ptr->sb_params_array[sb_index].origin_y = sequence_control_set_ptr->sb_params_array[sb_index].vertical_index * sequence_control_set_ptr->sb_sz;
     364             : 
     365         120 :         sequence_control_set_ptr->sb_params_array[sb_index].width = (uint8_t)(((sequence_control_set_ptr->seq_header.max_frame_width - sequence_control_set_ptr->sb_params_array[sb_index].origin_x) < sequence_control_set_ptr->sb_sz) ?
     366           0 :             sequence_control_set_ptr->seq_header.max_frame_width - sequence_control_set_ptr->sb_params_array[sb_index].origin_x :
     367             :             sequence_control_set_ptr->sb_sz);
     368             : 
     369         120 :         sequence_control_set_ptr->sb_params_array[sb_index].height = (uint8_t)(((sequence_control_set_ptr->seq_header.max_frame_height - sequence_control_set_ptr->sb_params_array[sb_index].origin_y) < sequence_control_set_ptr->sb_sz) ?
     370          20 :             sequence_control_set_ptr->seq_header.max_frame_height - sequence_control_set_ptr->sb_params_array[sb_index].origin_y :
     371             :             sequence_control_set_ptr->sb_sz);
     372             : 
     373         120 :         sequence_control_set_ptr->sb_params_array[sb_index].is_complete_sb = (uint8_t)(((sequence_control_set_ptr->sb_params_array[sb_index].width == sequence_control_set_ptr->sb_sz) && (sequence_control_set_ptr->sb_params_array[sb_index].height == sequence_control_set_ptr->sb_sz)) ?
     374             :             1 :
     375             :             0);
     376             : 
     377         348 :         sequence_control_set_ptr->sb_params_array[sb_index].is_edge_sb = (sequence_control_set_ptr->sb_params_array[sb_index].origin_x < sequence_control_set_ptr->sb_sz) ||
     378         108 :             (sequence_control_set_ptr->sb_params_array[sb_index].origin_y < sequence_control_set_ptr->sb_sz) ||
     379          90 :             (sequence_control_set_ptr->sb_params_array[sb_index].origin_x > sequence_control_set_ptr->seq_header.max_frame_width - sequence_control_set_ptr->sb_sz) ||
     380         228 :             (sequence_control_set_ptr->sb_params_array[sb_index].origin_y > sequence_control_set_ptr->seq_header.max_frame_height - sequence_control_set_ptr->sb_sz) ? 1 : 0;
     381             : 
     382         120 :         uint8_t potential_logo_sb = 0;
     383             : 
     384             :         // 4K
     385             :         /*__ 14 __         __ 14__*/
     386             :         ///////////////////////////
     387             :         //         |          |         //
     388             :         //         8          8         //
     389             :         //___14_ |          |_14___//
     390             :         //                         //
     391             :         //                         //
     392             :         //-----------------------// |
     393             :         //                         // 8
     394             :         ///////////////////////////    |
     395             : 
     396             :         // 1080p/720P
     397             :         /*__ 7 __          __ 7__*/
     398             :         ///////////////////////////
     399             :         //         |          |         //
     400             :         //         4          4         //
     401             :         //___7__ |          |__7___//
     402             :         //                         //
     403             :         //                         //
     404             :         //-----------------------// |
     405             :         //                         // 4
     406             :         ///////////////////////////    |
     407             : 
     408             :         // 480P
     409             :         /*__ 3 __          __ 3__*/
     410             :         ///////////////////////////
     411             :         //         |          |         //
     412             :         //         2          2         //
     413             :         //___3__ |          |__3___//
     414             :         //                         //
     415             :         //                         //
     416             :         //-----------------------// |
     417             :         //                         // 2
     418             :         ///////////////////////////    |
     419         120 :         if (sequence_control_set_ptr->input_resolution <= INPUT_SIZE_576p_RANGE_OR_LOWER) {
     420         120 :             potential_logo_sb = (sequence_control_set_ptr->sb_params_array[sb_index].origin_x >= (sequence_control_set_ptr->seq_header.max_frame_width - (3 * sequence_control_set_ptr->sb_sz))) && (sequence_control_set_ptr->sb_params_array[sb_index].origin_y < 2 * sequence_control_set_ptr->sb_sz) ? 1 : potential_logo_sb;
     421         120 :             potential_logo_sb = (sequence_control_set_ptr->sb_params_array[sb_index].origin_x < ((3 * sequence_control_set_ptr->sb_sz))) && (sequence_control_set_ptr->sb_params_array[sb_index].origin_y < 2 * sequence_control_set_ptr->sb_sz) ? 1 : potential_logo_sb;
     422         120 :             potential_logo_sb = (sequence_control_set_ptr->sb_params_array[sb_index].origin_y >= (sequence_control_set_ptr->seq_header.max_frame_height - (2 * sequence_control_set_ptr->sb_sz))) ? 1 : potential_logo_sb;
     423             :         }
     424             :         else
     425           0 :             if (sequence_control_set_ptr->input_resolution < INPUT_SIZE_4K_RANGE) {
     426           0 :                 potential_logo_sb = (sequence_control_set_ptr->sb_params_array[sb_index].origin_x >= (sequence_control_set_ptr->seq_header.max_frame_width - (7 * sequence_control_set_ptr->sb_sz))) && (sequence_control_set_ptr->sb_params_array[sb_index].origin_y < 4 * sequence_control_set_ptr->sb_sz) ? 1 : potential_logo_sb;
     427           0 :                 potential_logo_sb = (sequence_control_set_ptr->sb_params_array[sb_index].origin_x < ((7 * sequence_control_set_ptr->sb_sz))) && (sequence_control_set_ptr->sb_params_array[sb_index].origin_y < 4 * sequence_control_set_ptr->sb_sz) ? 1 : potential_logo_sb;
     428           0 :                 potential_logo_sb = (sequence_control_set_ptr->sb_params_array[sb_index].origin_y >= (sequence_control_set_ptr->seq_header.max_frame_height - (4 * sequence_control_set_ptr->sb_sz))) ? 1 : potential_logo_sb;
     429             :             }
     430             :             else {
     431           0 :                 potential_logo_sb = (sequence_control_set_ptr->sb_params_array[sb_index].origin_x >= (sequence_control_set_ptr->seq_header.max_frame_width - (14 * sequence_control_set_ptr->sb_sz))) && (sequence_control_set_ptr->sb_params_array[sb_index].origin_y < 8 * sequence_control_set_ptr->sb_sz) ? 1 : potential_logo_sb;
     432           0 :                 potential_logo_sb = (sequence_control_set_ptr->sb_params_array[sb_index].origin_x < ((14 * sequence_control_set_ptr->sb_sz))) && (sequence_control_set_ptr->sb_params_array[sb_index].origin_y < 8 * sequence_control_set_ptr->sb_sz) ? 1 : potential_logo_sb;
     433           0 :                 potential_logo_sb = (sequence_control_set_ptr->sb_params_array[sb_index].origin_y >= (sequence_control_set_ptr->seq_header.max_frame_height - (8 * sequence_control_set_ptr->sb_sz))) ? 1 : potential_logo_sb;
     434             :             }
     435         120 :         sequence_control_set_ptr->sb_params_array[sb_index].potential_logo_sb = potential_logo_sb;
     436             : 
     437       10320 :         for (rasterScanCuIndex = RASTER_SCAN_CU_INDEX_64x64; rasterScanCuIndex <= RASTER_SCAN_CU_INDEX_8x8_63; rasterScanCuIndex++) {
     438       10200 :             sequence_control_set_ptr->sb_params_array[sb_index].raster_scan_cu_validity[rasterScanCuIndex] = ((sequence_control_set_ptr->sb_params_array[sb_index].origin_x + raster_scan_cu_x[rasterScanCuIndex] + raster_scan_cu_size[rasterScanCuIndex] > sequence_control_set_ptr->seq_header.max_frame_width) || (sequence_control_set_ptr->sb_params_array[sb_index].origin_y + raster_scan_cu_y[rasterScanCuIndex] + raster_scan_cu_size[rasterScanCuIndex] > sequence_control_set_ptr->seq_header.max_frame_height)) ?
     439       10200 :                 EB_FALSE :
     440             :                 EB_TRUE;
     441             :         }
     442             :     }
     443             : 
     444           2 :     sequence_control_set_ptr->picture_width_in_sb = pictureLcuWidth;
     445           2 :     sequence_control_set_ptr->picture_height_in_sb = pictureLcuHeight;
     446           2 :     sequence_control_set_ptr->sb_total_count = pictureLcuWidth * pictureLcuHeight;
     447             : 
     448           2 :     return return_error;
     449             : }
     450             : 
     451           2 : EbErrorType sb_geom_init(SequenceControlSet * sequence_control_set_ptr)
     452             : {
     453             :     uint16_t    sb_index;
     454             :     uint16_t    md_scan_block_index;
     455           2 :     uint16_t   pictureLcuWidth = (sequence_control_set_ptr->seq_header.max_frame_width + sequence_control_set_ptr->sb_size_pix - 1) / sequence_control_set_ptr->sb_size_pix;
     456           2 :     uint16_t    pictureLcuHeight = (sequence_control_set_ptr->seq_header.max_frame_height + sequence_control_set_ptr->sb_size_pix - 1) / sequence_control_set_ptr->sb_size_pix;
     457             : 
     458             : 
     459           2 :     EB_FREE_ARRAY(sequence_control_set_ptr->sb_geom);
     460           2 :     EB_MALLOC_ARRAY(sequence_control_set_ptr->sb_geom, pictureLcuWidth * pictureLcuHeight);
     461             : 
     462         122 :     for (sb_index = 0; sb_index < pictureLcuWidth * pictureLcuHeight; ++sb_index) {
     463         120 :         sequence_control_set_ptr->sb_geom[sb_index].horizontal_index = sb_index % pictureLcuWidth;
     464         120 :         sequence_control_set_ptr->sb_geom[sb_index].vertical_index = sb_index / pictureLcuWidth;
     465         120 :         sequence_control_set_ptr->sb_geom[sb_index].origin_x = sequence_control_set_ptr->sb_geom[sb_index].horizontal_index * sequence_control_set_ptr->sb_size_pix;
     466         120 :         sequence_control_set_ptr->sb_geom[sb_index].origin_y = sequence_control_set_ptr->sb_geom[sb_index].vertical_index * sequence_control_set_ptr->sb_size_pix;
     467             : 
     468         120 :         sequence_control_set_ptr->sb_geom[sb_index].width = (uint8_t)(((sequence_control_set_ptr->seq_header.max_frame_width - sequence_control_set_ptr->sb_geom[sb_index].origin_x) < sequence_control_set_ptr->sb_size_pix) ?
     469           0 :             sequence_control_set_ptr->seq_header.max_frame_width - sequence_control_set_ptr->sb_geom[sb_index].origin_x :
     470         120 :             sequence_control_set_ptr->sb_size_pix);
     471             : 
     472         120 :         sequence_control_set_ptr->sb_geom[sb_index].height = (uint8_t)(((sequence_control_set_ptr->seq_header.max_frame_height - sequence_control_set_ptr->sb_geom[sb_index].origin_y) < sequence_control_set_ptr->sb_size_pix) ?
     473          20 :             sequence_control_set_ptr->seq_header.max_frame_height - sequence_control_set_ptr->sb_geom[sb_index].origin_y :
     474         100 :             sequence_control_set_ptr->sb_size_pix);
     475             : 
     476         120 :         sequence_control_set_ptr->sb_geom[sb_index].is_complete_sb =
     477         120 :             (uint8_t)(((sequence_control_set_ptr->sb_geom[sb_index].width == sequence_control_set_ptr->sb_size_pix) && (sequence_control_set_ptr->sb_geom[sb_index].height == sequence_control_set_ptr->sb_size_pix)) ?
     478             :                 1 :
     479             :                 0);
     480             : 
     481         120 :         uint16_t max_block_count = sequence_control_set_ptr->max_block_cnt;
     482             : 
     483      132240 :         for (md_scan_block_index = 0; md_scan_block_index < max_block_count ; md_scan_block_index++) {
     484      132120 :             const BlockGeom * blk_geom = get_blk_geom_mds(md_scan_block_index);
     485      132120 :             if (sequence_control_set_ptr->over_boundary_block_mode == 1) {
     486       66060 :                 sequence_control_set_ptr->sb_geom[sb_index].block_is_allowed[md_scan_block_index] =
     487       66060 :                     ((sequence_control_set_ptr->sb_geom[sb_index].origin_x + blk_geom->origin_x + blk_geom->bwidth / 2 < sequence_control_set_ptr->seq_header.max_frame_width) &&
     488       66060 :                     (sequence_control_set_ptr->sb_geom[sb_index].origin_y + blk_geom->origin_y + blk_geom->bheight / 2 < sequence_control_set_ptr->seq_header.max_frame_height)) ?
     489       66060 :                     EB_TRUE :
     490             :                     EB_FALSE;
     491             : 
     492             :                 // Temporary if the cropped width is not 4, 8, 16, 32, 64 and 128, the block is not allowed. To be removed after intrinsic functions for NxM spatial_full_distortion_kernel_func_ptr_array are added
     493       66060 :                 int32_t cropped_width = MIN(blk_geom->bwidth, sequence_control_set_ptr->seq_header.max_frame_width - (sequence_control_set_ptr->sb_geom[sb_index].origin_x + blk_geom->origin_x));
     494       66060 :                 if (cropped_width != 4 && cropped_width != 8 && cropped_width != 16 && cropped_width != 32 && cropped_width != 64 && cropped_width != 128)
     495           0 :                     sequence_control_set_ptr->sb_geom[sb_index].block_is_allowed[md_scan_block_index] = EB_FALSE;
     496             : 
     497       66060 :                 if (blk_geom->shape != PART_N)
     498       45600 :                     blk_geom = get_blk_geom_mds(blk_geom->sqi_mds);
     499       66060 :                 sequence_control_set_ptr->sb_geom[sb_index].block_is_inside_md_scan[md_scan_block_index] =
     500       66060 :                     ((sequence_control_set_ptr->sb_geom[sb_index].origin_x >= sequence_control_set_ptr->seq_header.max_frame_width) ||
     501       66060 :                     (sequence_control_set_ptr->sb_geom[sb_index].origin_y >= sequence_control_set_ptr->seq_header.max_frame_height)) ?
     502       66060 :                     EB_FALSE :
     503             :                     EB_TRUE;
     504             :             }
     505             :             else {
     506       66060 :                 if (blk_geom->shape != PART_N)
     507       45600 :                     blk_geom = get_blk_geom_mds(blk_geom->sqi_mds);
     508             : 
     509       66060 :                 sequence_control_set_ptr->sb_geom[sb_index].block_is_allowed[md_scan_block_index] =
     510       66060 :                     ((sequence_control_set_ptr->sb_geom[sb_index].origin_x + blk_geom->origin_x + blk_geom->bwidth > sequence_control_set_ptr->seq_header.max_frame_width) ||
     511       66060 :                     (sequence_control_set_ptr->sb_geom[sb_index].origin_y + blk_geom->origin_y + blk_geom->bheight > sequence_control_set_ptr->seq_header.max_frame_height)) ?
     512       66060 :                     EB_FALSE :
     513             :                     EB_TRUE;
     514             : 
     515       66060 :                 sequence_control_set_ptr->sb_geom[sb_index].block_is_inside_md_scan[md_scan_block_index] =
     516       66060 :                     ((sequence_control_set_ptr->sb_geom[sb_index].origin_x + blk_geom->origin_x + blk_geom->bwidth > sequence_control_set_ptr->seq_header.max_frame_width) ||
     517       66060 :                     (sequence_control_set_ptr->sb_geom[sb_index].origin_y + blk_geom->origin_y + blk_geom->bheight > sequence_control_set_ptr->seq_header.max_frame_height)) ?
     518       66060 :                     EB_FALSE :
     519             :                     EB_TRUE;
     520             : 
     521             :             }
     522             :         }
     523             :     }
     524             : 
     525           2 :     sequence_control_set_ptr->sb_tot_cnt = pictureLcuWidth * pictureLcuHeight;
     526             : 
     527           2 :     return 0;
     528             : }

Generated by: LCOV version 1.14