Home | History | Annotate | Download | only in decoder
      1 /******************************************************************************
      2  *
      3  * Copyright (C) 2015 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 Name         : ih264d_vui.c                                                */
     24 /*                                                                           */
     25 /*  Description       : This file contains routines to parse VUI NAL's       */
     26 /*                                                                           */
     27 /*  List of Functions : <List the functions defined in this file>            */
     28 /*                                                                           */
     29 /*  Issues / Problems : None                                                 */
     30 /*                                                                           */
     31 /*  Revision History  :                                                      */
     32 /*                                                                           */
     33 /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
     34 /*         25 05 2005   NS              Draft                                */
     35 /*                                                                           */
     36 /*****************************************************************************/
     37 
     38 #include "ih264_typedefs.h"
     39 #include "ih264_macros.h"
     40 #include "ih264_platform_macros.h"
     41 #include "ih264d_vui.h"
     42 #include "ih264d_bitstrm.h"
     43 #include "ih264d_parse_cavlc.h"
     44 #include "ih264d_structs.h"
     45 #include "ih264d_error_handler.h"
     46 
     47 /*****************************************************************************/
     48 /*                                                                           */
     49 /*  Function Name : ih264d_parse_hrd_parametres                                     */
     50 /*                                                                           */
     51 /*  Description   : This function parses hrd_t parametres                      */
     52 /*  Inputs        : ps_hrd          pointer to HRD params                    */
     53 /*                  ps_bitstrm   Bitstream                                */
     54 /*  Globals       : None                                                     */
     55 /*  Processing    : Parses HRD params                                        */
     56 /*  Outputs       : None                                                     */
     57 /*  Returns       : None                                                     */
     58 /*                                                                           */
     59 /*  Issues        : None                                                     */
     60 /*                                                                           */
     61 /*  Revision History:                                                        */
     62 /*                                                                           */
     63 /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
     64 /*         06 05 2002   NS              Draft                                */
     65 /*                                                                           */
     66 /*****************************************************************************/
     67 
     68 WORD32 ih264d_parse_hrd_parametres(hrd_t *ps_hrd,
     69                                    dec_bit_stream_t *ps_bitstrm)
     70 {
     71     UWORD8 u1_index;
     72     UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
     73     UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
     74 
     75     ps_hrd->u4_cpb_cnt = 1
     76                     + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
     77     if(ps_hrd->u4_cpb_cnt > 31)
     78         return ERROR_INV_SPS_PPS_T;
     79     ps_hrd->u1_bit_rate_scale = ih264d_get_bits_h264(ps_bitstrm, 4);
     80     ps_hrd->u1_cpb_size_scale = ih264d_get_bits_h264(ps_bitstrm, 4);
     81 
     82     for(u1_index = 0; u1_index < (UWORD8)ps_hrd->u4_cpb_cnt; u1_index++)
     83     {
     84         ps_hrd->u4_bit_rate[u1_index] = 1
     85                         + ih264d_uev(pu4_bitstrm_ofst,
     86                                      pu4_bitstrm_buf);
     87         ps_hrd->u4_cpb_size[u1_index] = 1
     88                         + ih264d_uev(pu4_bitstrm_ofst,
     89                                      pu4_bitstrm_buf);
     90         ps_hrd->u1_cbr_flag[u1_index] = ih264d_get_bits_h264(ps_bitstrm, 1);
     91     }
     92 
     93     ps_hrd->u1_initial_cpb_removal_delay = 1
     94                     + ih264d_get_bits_h264(ps_bitstrm, 5);
     95     ps_hrd->u1_cpb_removal_delay_length = 1
     96                     + ih264d_get_bits_h264(ps_bitstrm, 5);
     97     ps_hrd->u1_dpb_output_delay_length = 1
     98                     + ih264d_get_bits_h264(ps_bitstrm, 5);
     99     ps_hrd->u1_time_offset_length = ih264d_get_bits_h264(ps_bitstrm, 5);
    100 
    101     return OK;
    102 }
    103 
    104 /*****************************************************************************/
    105 /*                                                                           */
    106 /*  Function Name : ih264d_parse_vui_parametres                                     */
    107 /*                                                                           */
    108 /*  Description   : This function parses VUI NALs.                           */
    109 /*  Inputs        : ps_vu4          pointer to VUI params                    */
    110 /*                  ps_bitstrm   Bitstream                                */
    111 /*  Globals       : None                                                     */
    112 /*  Processing    : Parses VUI NAL's units and stores the info               */
    113 /*  Outputs       : None                                                     */
    114 /*  Returns       : None                                                     */
    115 /*                                                                           */
    116 /*  Issues        : None                                                     */
    117 /*                                                                           */
    118 /*  Revision History:                                                        */
    119 /*                                                                           */
    120 /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
    121 /*         06 05 2002   NS              Draft                                */
    122 /*                                                                           */
    123 /*****************************************************************************/
    124 
    125 WORD32 ih264d_parse_vui_parametres(vui_t *ps_vu4,
    126                                    dec_bit_stream_t *ps_bitstrm)
    127 {
    128     UWORD8 u4_bits;
    129     UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
    130     UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
    131     WORD32 ret;
    132 
    133     u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
    134     if(u4_bits)
    135     {
    136         u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8);
    137         ps_vu4->u1_aspect_ratio_idc = (UWORD8)u4_bits;
    138         if(VUI_EXTENDED_SAR == u4_bits)
    139         {
    140             ps_vu4->u2_sar_width = ih264d_get_bits_h264(ps_bitstrm, 16);
    141             ps_vu4->u2_sar_height = ih264d_get_bits_h264(ps_bitstrm, 16);
    142         }
    143     }
    144 
    145     u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
    146     if(u4_bits)
    147     {
    148         ps_vu4->u1_overscan_appropriate_flag = ih264d_get_bits_h264(
    149                         ps_bitstrm, 1);
    150     }
    151     u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
    152     if(u4_bits)
    153     {
    154         ps_vu4->u1_video_format = ih264d_get_bits_h264(ps_bitstrm, 3);
    155         ps_vu4->u1_video_full_range_flag = ih264d_get_bits_h264(ps_bitstrm,
    156                                                                 1);
    157         u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
    158         if(u4_bits)
    159         {
    160             ps_vu4->u1_colour_primaries = ih264d_get_bits_h264(ps_bitstrm,
    161                                                                8);
    162             ps_vu4->u1_tfr_chars = ih264d_get_bits_h264(ps_bitstrm, 8);
    163             ps_vu4->u1_matrix_coeffs = ih264d_get_bits_h264(ps_bitstrm, 8);
    164         }
    165     }
    166 
    167     u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
    168     if(u4_bits)
    169     {
    170         ps_vu4->u1_cr_top_field = ih264d_uev(pu4_bitstrm_ofst,
    171                                              pu4_bitstrm_buf);
    172         ps_vu4->u1_cr_bottom_field = ih264d_uev(pu4_bitstrm_ofst,
    173                                                 pu4_bitstrm_buf);
    174     }
    175 
    176     u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
    177     if(u4_bits)
    178     {
    179         ps_vu4->u4_num_units_in_tick = ih264d_get_bits_h264(ps_bitstrm, 32);
    180         ps_vu4->u4_time_scale = ih264d_get_bits_h264(ps_bitstrm, 32);
    181         ps_vu4->u1_fixed_frame_rate_flag = ih264d_get_bits_h264(ps_bitstrm,
    182                                                                 1);
    183     }
    184 
    185     u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
    186     ps_vu4->u1_nal_hrd_params_present = u4_bits;
    187     if(u4_bits)
    188     {
    189         ret = ih264d_parse_hrd_parametres(&ps_vu4->s_nal_hrd, ps_bitstrm);
    190         if(ret != OK)
    191             return ret;
    192     }
    193     u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
    194     ps_vu4->u1_vcl_hrd_params_present = u4_bits;
    195     if(u4_bits)
    196     {
    197         ret = ih264d_parse_hrd_parametres(&ps_vu4->s_vcl_hrd, ps_bitstrm);
    198         if(ret != OK)
    199             return ret;
    200     }
    201 
    202     if(ps_vu4->u1_nal_hrd_params_present || u4_bits)
    203     {
    204         ps_vu4->u1_low_delay_hrd_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
    205     }
    206     ps_vu4->u1_pic_struct_present_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
    207 
    208     ps_vu4->u1_bitstream_restriction_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
    209 
    210     if(ps_vu4->u1_bitstream_restriction_flag)
    211     {
    212         ps_vu4->u1_mv_over_pic_boundaries_flag = ih264d_get_bits_h264(
    213                         ps_bitstrm, 1);
    214         ps_vu4->u4_max_bytes_per_pic_denom = ih264d_uev(pu4_bitstrm_ofst,
    215                                                         pu4_bitstrm_buf);
    216         ps_vu4->u4_max_bits_per_mb_denom = ih264d_uev(pu4_bitstrm_ofst,
    217                                                       pu4_bitstrm_buf);
    218         ps_vu4->u4_log2_max_mv_length_horz = ih264d_uev(pu4_bitstrm_ofst,
    219                                                         pu4_bitstrm_buf);
    220         ps_vu4->u4_log2_max_mv_length_vert = ih264d_uev(pu4_bitstrm_ofst,
    221                                                         pu4_bitstrm_buf);
    222         ps_vu4->u4_num_reorder_frames = ih264d_uev(pu4_bitstrm_ofst,
    223                                                    pu4_bitstrm_buf);
    224         ps_vu4->u4_max_dec_frame_buffering = ih264d_uev(pu4_bitstrm_ofst,
    225                                                         pu4_bitstrm_buf);
    226     }
    227     else
    228     {
    229         /* Setting this to a large value if not present */
    230         ps_vu4->u4_num_reorder_frames = 64;
    231         ps_vu4->u4_max_dec_frame_buffering = 64;
    232     }
    233 
    234     return OK;
    235 }
    236