LCOV - code coverage report
Current view: top level - Codec - EbEncDecSegments.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 61 63 96.8 %
Date: 2019-11-25 17:38:06 Functions: 3 3 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             : #include <string.h>
       8             : 
       9             : #include "EbEncDecSegments.h"
      10             : #include "EbThreads.h"
      11             : 
      12           6 : static void enc_dec_segments_dctor(EbPtr p)
      13             : {
      14           6 :     EncDecSegments* obj = (EncDecSegments*)p;
      15             :     uint32_t row_index;
      16          42 :     for (row_index = 0; row_index < obj->segment_max_row_count; ++row_index) {
      17          36 :         EB_DESTROY_MUTEX(obj->row_array[row_index].assignment_mutex);
      18             :     }
      19           6 :     EB_DESTROY_MUTEX(obj->dep_map.update_mutex);
      20           6 :     EB_FREE_ARRAY(obj->x_start_array);
      21           6 :     EB_FREE_ARRAY(obj->y_start_array);
      22           6 :     EB_FREE_ARRAY(obj->valid_lcu_count_array);
      23           6 :     EB_FREE_ARRAY(obj->dep_map.dependency_map);
      24           6 :     EB_FREE_ARRAY(obj->row_array);
      25           6 : }
      26             : 
      27           6 : EbErrorType enc_dec_segments_ctor(
      28             :     EncDecSegments      *segments_ptr,
      29             :     uint32_t             segment_col_count,
      30             :     uint32_t             segment_row_count)
      31             : {
      32             :     uint32_t row_index;
      33             : 
      34           6 :     segments_ptr->dctor = enc_dec_segments_dctor;
      35             : 
      36           6 :     segments_ptr->segment_max_row_count = segment_row_count;
      37           6 :     segments_ptr->segment_max_band_count = segment_row_count + segment_col_count;
      38           6 :     segments_ptr->segment_max_total_count = segments_ptr->segment_max_row_count * segments_ptr->segment_max_band_count;
      39             : 
      40             :     // Start Arrays
      41           6 :     EB_MALLOC_ARRAY(segments_ptr->x_start_array, segments_ptr->segment_max_total_count);
      42             : 
      43           6 :     EB_MALLOC_ARRAY(segments_ptr->y_start_array, segments_ptr->segment_max_total_count);
      44             : 
      45           6 :     EB_MALLOC_ARRAY(segments_ptr->valid_lcu_count_array, segments_ptr->segment_max_total_count);
      46             : 
      47             :     // Dependency map
      48           6 :     EB_MALLOC_ARRAY(segments_ptr->dep_map.dependency_map, segments_ptr->segment_max_total_count);
      49             : 
      50           6 :     EB_CREATE_MUTEX(segments_ptr->dep_map.update_mutex);
      51             : 
      52             :     // Segment rows
      53           6 :     EB_MALLOC_ARRAY(segments_ptr->row_array,  segments_ptr->segment_max_row_count);
      54          42 :     for (row_index = 0; row_index < segments_ptr->segment_max_row_count; ++row_index) {
      55          36 :         segments_ptr->row_array[row_index].assignment_mutex = NULL;
      56             :     }
      57             : 
      58          42 :     for (row_index = 0; row_index < segments_ptr->segment_max_row_count; ++row_index) {
      59          36 :         EB_CREATE_MUTEX(segments_ptr->row_array[row_index].assignment_mutex);
      60             :     }
      61             : 
      62           6 :     return EB_ErrorNone;
      63             : }
      64             : 
      65         120 : void enc_dec_segments_init(
      66             :     EncDecSegments *segments_ptr,
      67             :     uint32_t            segColCount,
      68             :     uint32_t            segRowCount,
      69             :     uint32_t            pic_width_lcu,
      70             :     uint32_t            pic_height_lcu)
      71             : {
      72             :     unsigned x, y, yLast;
      73             :     unsigned row_index, band_index, segment_index;
      74             : 
      75         120 :     segments_ptr->lcu_row_count = pic_height_lcu;
      76         120 :     segments_ptr->lcu_band_count = BAND_TOTAL_COUNT(pic_height_lcu, pic_width_lcu);
      77         120 :     segments_ptr->segment_row_count = segRowCount;
      78         120 :     segments_ptr->segment_band_count = BAND_TOTAL_COUNT(segRowCount, segColCount);
      79         120 :     segments_ptr->segmentTotalCount = segments_ptr->segment_row_count * segments_ptr->segment_band_count;
      80             : 
      81             :     //EB_MEMSET(segments_ptr->inputMap.inputDependencyMap, 0, sizeof(uint16_t) * segments_ptr->segmentTotalCount);
      82         120 :     EB_MEMSET(segments_ptr->valid_lcu_count_array, 0, sizeof(uint16_t) * segments_ptr->segmentTotalCount);
      83         120 :     EB_MEMSET(segments_ptr->x_start_array, -1, sizeof(uint16_t) * segments_ptr->segmentTotalCount);
      84         120 :     EB_MEMSET(segments_ptr->y_start_array, -1, sizeof(uint16_t) * segments_ptr->segmentTotalCount);
      85             : 
      86             :     // Initialize the per-LCU input availability map & Start Arrays
      87         840 :     for (y = 0; y < pic_height_lcu; ++y) {
      88        7920 :         for (x = 0; x < pic_width_lcu; ++x) {
      89        7200 :             band_index = BAND_INDEX(x, y, segments_ptr->segment_band_count, segments_ptr->lcu_band_count);
      90        7200 :             row_index = ROW_INDEX(y, segments_ptr->segment_row_count, segments_ptr->lcu_row_count);
      91        7200 :             segment_index = SEGMENT_INDEX(row_index, band_index, segments_ptr->segment_band_count);
      92             : 
      93             :             //++segments_ptr->inputMap.inputDependencyMap[segment_index];
      94        7200 :             ++segments_ptr->valid_lcu_count_array[segment_index];
      95        7200 :             segments_ptr->x_start_array[segment_index] = (segments_ptr->x_start_array[segment_index] == (uint16_t)-1) ?
      96             :                 (uint16_t)x :
      97           0 :                 segments_ptr->x_start_array[segment_index];
      98        7200 :             segments_ptr->y_start_array[segment_index] = (segments_ptr->y_start_array[segment_index] == (uint16_t)-1) ?
      99             :                 (uint16_t)y :
     100           0 :                 segments_ptr->y_start_array[segment_index];
     101             :         }
     102             :     }
     103             : 
     104             :     // Initialize the row-based controls
     105         840 :     for (row_index = 0; row_index < segments_ptr->segment_row_count; ++row_index) {
     106         720 :         y = ((row_index * segments_ptr->lcu_row_count) + (segments_ptr->segment_row_count - 1)) / segments_ptr->segment_row_count;
     107         720 :         yLast = ((((row_index + 1) * segments_ptr->lcu_row_count) + (segments_ptr->segment_row_count - 1)) / segments_ptr->segment_row_count) - 1;
     108         720 :         band_index = BAND_INDEX(0, y, segments_ptr->segment_band_count, segments_ptr->lcu_band_count);
     109             : 
     110         720 :         segments_ptr->row_array[row_index].starting_seg_index = (uint16_t)SEGMENT_INDEX(row_index, band_index, segments_ptr->segment_band_count);
     111         720 :         band_index = BAND_INDEX(pic_width_lcu - 1, yLast, segments_ptr->segment_band_count, segments_ptr->lcu_band_count);
     112         720 :         segments_ptr->row_array[row_index].ending_seg_index = (uint16_t)SEGMENT_INDEX(row_index, band_index, segments_ptr->segment_band_count);
     113         720 :         segments_ptr->row_array[row_index].current_seg_index = segments_ptr->row_array[row_index].starting_seg_index;
     114             :     }
     115             : 
     116             :     // Initialize the per-segment dependency map
     117         120 :     EB_MEMSET(segments_ptr->dep_map.dependency_map, 0, sizeof(uint8_t) * segments_ptr->segmentTotalCount);
     118         840 :     for (row_index = 0; row_index < segments_ptr->segment_row_count; ++row_index) {
     119        7920 :         for (segment_index = segments_ptr->row_array[row_index].starting_seg_index; segment_index <= segments_ptr->row_array[row_index].ending_seg_index; ++segment_index) {
     120             :             // Check that segment is valid
     121        7200 :             if (segments_ptr->valid_lcu_count_array[segment_index]) {
     122             :                 // Right Neighbor
     123        7200 :                 if (segment_index < segments_ptr->row_array[row_index].ending_seg_index)
     124        6480 :                     ++segments_ptr->dep_map.dependency_map[segment_index + 1];
     125             :                 // Bottom Neighbor
     126        7200 :                 if (row_index < segments_ptr->segment_row_count - 1 && segment_index + segments_ptr->segment_band_count >= segments_ptr->row_array[row_index + 1].starting_seg_index)
     127        5400 :                     ++segments_ptr->dep_map.dependency_map[segment_index + segments_ptr->segment_band_count];
     128             :             }
     129             :         }
     130             :     }
     131             : 
     132         120 :     return;
     133             : }

Generated by: LCOV version 1.14