• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright (C) 2022 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19  */
20 
21 /**
22 *******************************************************************************
23 * @file
24 *  isvce_nalu_stat_aggregator.c
25 *
26 * @brief
27 *  Contains objects used for aggregating nalu statistics
28 *
29 *******************************************************************************
30 */
31 #include <stdio.h>
32 #include <string.h>
33 
34 #include "ih264_typedefs.h"
35 #include "iv2.h"
36 #include "isvce_structs.h"
37 #include "isvce_nalu_stat_aggregator.h"
38 
isvce_nalu_info_au_init(nalu_descriptors_t * ps_nalu_descriptor,UWORD8 u1_num_spatial_layers)39 void isvce_nalu_info_au_init(nalu_descriptors_t *ps_nalu_descriptor, UWORD8 u1_num_spatial_layers)
40 {
41     WORD32 i;
42 
43     for(i = 0; i < u1_num_spatial_layers; i++)
44     {
45         ps_nalu_descriptor[i].u1_num_nalus = 0;
46     }
47 }
48 
isvce_nalu_info_csv_translator(nalu_descriptors_t * ps_nalu_descriptor,isvce_nalu_info_buf_t * ps_csv_buf)49 void isvce_nalu_info_csv_translator(nalu_descriptors_t *ps_nalu_descriptor,
50                                     isvce_nalu_info_buf_t *ps_csv_buf)
51 {
52     char ac_csv_string[MAX_BYTES_PER_NALU_INFO];
53     WORD32 i;
54 
55     WORD64 i8_num_bytes_available = ps_csv_buf->u4_buf_size - ps_csv_buf->u4_num_bytes;
56 
57     for(i = 0; i < ps_nalu_descriptor->u1_num_nalus; i++)
58     {
59         if(ps_nalu_descriptor->as_nalu_info[i].b_is_vcl_nal)
60         {
61             snprintf(ac_csv_string, MAX_BYTES_PER_NALU_INFO, "%d,%u,%d,%d,%d,%d,%d\n",
62                      ps_nalu_descriptor->as_nalu_info[i].e_nalu_type,
63                      (UWORD32) (ps_nalu_descriptor->as_nalu_info[i].i8_num_bits / 8),
64                      ps_nalu_descriptor->as_nalu_info[i].u1_spatial_layer_id,
65                      ps_nalu_descriptor->as_nalu_info[i].u1_temporal_layer_id,
66                      ps_nalu_descriptor->as_nalu_info[i].b_is_idr, 1, 1);
67         }
68         else
69         {
70             snprintf(ac_csv_string, MAX_BYTES_PER_NALU_INFO, "%d,%u,%d,%d,%d,%d,%d\n",
71                      ps_nalu_descriptor->as_nalu_info[i].e_nalu_type,
72                      (UWORD32) (ps_nalu_descriptor->as_nalu_info[i].i8_num_bits / 8), -1, -1, -1,
73                      -1, -1);
74         }
75 
76         snprintf((char *) (ps_csv_buf->pu1_buf + ps_csv_buf->u4_num_bytes), i8_num_bytes_available,
77                  "%s", ac_csv_string);
78 
79         ps_csv_buf->u4_num_bytes = (UWORD32) strlen((char *) ps_csv_buf->pu1_buf);
80         i8_num_bytes_available = ps_csv_buf->u4_buf_size - ps_csv_buf->u4_num_bytes;
81 
82         ASSERT(i8_num_bytes_available >= 0);
83     }
84 }
85 
isvce_get_next_nalu_info_buf(nalu_descriptors_t * ps_nalu_descriptor)86 nalu_info_t *isvce_get_next_nalu_info_buf(nalu_descriptors_t *ps_nalu_descriptor)
87 {
88     return &ps_nalu_descriptor->as_nalu_info[ps_nalu_descriptor->u1_num_nalus];
89 }
90 
isvce_nalu_info_buf_init(nalu_info_t * ps_nalu_info,WORD64 i8_init_bits,NAL_UNIT_TYPE_T e_nalu_type,UWORD8 u1_spatial_layer_id,UWORD8 u1_temporal_layer_id,UWORD8 u1_num_slices,bool b_is_idr)91 void isvce_nalu_info_buf_init(nalu_info_t *ps_nalu_info, WORD64 i8_init_bits,
92                               NAL_UNIT_TYPE_T e_nalu_type, UWORD8 u1_spatial_layer_id,
93                               UWORD8 u1_temporal_layer_id, UWORD8 u1_num_slices, bool b_is_idr)
94 {
95     ps_nalu_info->e_nalu_type = e_nalu_type;
96     ps_nalu_info->i8_num_bits = i8_init_bits;
97     ps_nalu_info->b_is_idr = b_is_idr;
98 
99     switch(e_nalu_type)
100     {
101         case NAL_SLICE_NON_IDR:
102         case NAL_SLICE_IDR:
103         case NAL_CODED_SLICE_EXTENSION:
104         {
105             ps_nalu_info->b_is_vcl_nal = true;
106             ps_nalu_info->u1_spatial_layer_id = u1_spatial_layer_id;
107             ps_nalu_info->u1_temporal_layer_id = u1_temporal_layer_id;
108             ps_nalu_info->u1_num_slices = u1_num_slices;
109 
110             break;
111         }
112         default:
113         {
114             ps_nalu_info->b_is_vcl_nal = false;
115 
116             break;
117         }
118     }
119 }
120 
isvce_update_nalu_count(nalu_descriptors_t * ps_nalu_descriptor)121 void isvce_update_nalu_count(nalu_descriptors_t *ps_nalu_descriptor)
122 {
123     ps_nalu_descriptor->u1_num_nalus++;
124 }
125