videoeditorengine/avcedit/inc/parameterset.h
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 * Ixonos Plc
       
    14 *
       
    15 * Description:
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef _PARAMETERSET_H_
       
    21 #define _PARAMETERSET_H_
       
    22 
       
    23 #include "nrctyp32.h"
       
    24 #include "bitbuffer.h"
       
    25 #include <e32def.h>
       
    26 #include <e32base.h>
       
    27 
       
    28 
       
    29 /* Parameter set error codes */
       
    30 #define PS_ERR_MEM_ALLOC            -5
       
    31 #define PS_ERR_UNSUPPORTED_FEATURE  -4
       
    32 #define PS_ERR_UNSUPPORTED_PROFILE  -3
       
    33 #define PS_ERR_ILLEGAL_VALUE        -2
       
    34 #define PS_ERROR                    -1
       
    35 #define PS_OK                        0
       
    36 
       
    37 
       
    38 /* Boolean Type */
       
    39 typedef unsigned int Boolean;
       
    40 
       
    41 /* According to the Awaji meeting decision: */
       
    42 #define PS_MAX_NUM_OF_SPS         32
       
    43 #define PS_MAX_NUM_OF_PPS         256
       
    44 
       
    45 /* Profile IDC's */
       
    46 #define PS_BASELINE_PROFILE_IDC   66
       
    47 #define PS_MAIN_PROFILE_IDC       77
       
    48 #define PS_EXTENDED_PROFILE_IDC   88
       
    49 
       
    50 #define PS_MAX_CPB_CNT            32
       
    51 
       
    52 #define PS_EXTENDED_SAR           255
       
    53 
       
    54 /* Slice groups supported by baseline profile and extended profile */
       
    55 #define PS_MAX_NUM_SLICE_GROUPS              8
       
    56 #define PS_SLICE_GROUP_MAP_TYPE_INTERLEAVED  0
       
    57 #define PS_SLICE_GROUP_MAP_TYPE_DISPERSED    1
       
    58 #define PS_SLICE_GROUP_MAP_TYPE_FOREGROUND   2
       
    59 #define PS_SLICE_GROUP_MAP_TYPE_CHANGING_3   3
       
    60 #define PS_SLICE_GROUP_MAP_TYPE_CHANGING_4   4
       
    61 #define PS_SLICE_GROUP_MAP_TYPE_CHANGING_5   5
       
    62 #define PS_SLICE_GROUP_MAP_TYPE_EXPLICIT     6
       
    63 #define PS_BASELINE_MAX_SLICE_GROUPS 		7
       
    64 
       
    65 
       
    66 #define PS_MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE  256
       
    67 
       
    68 // NOTE: Levels up to 2 are eanbled for testing purposes
       
    69 //       1.2 is the max level we should support
       
    70 //#define PS_MAX_SUPPORTED_LEVEL 20		// Maximum level that we support
       
    71 
       
    72 //WVGA task
       
    73 #define PS_MAX_SUPPORTED_LEVEL 31
       
    74 
       
    75 
       
    76 /*
       
    77  * Hypothetical reference decoder parameters
       
    78  */
       
    79 
       
    80 typedef struct _hrd_parameters_s
       
    81 {
       
    82   unsigned    cpb_cnt_minus1;                                   // ue(v)
       
    83   unsigned    bit_rate_scale;                                   // u(4)
       
    84   unsigned    cpb_size_scale;                                   // u(4)
       
    85     u_int32   bit_rate_value_minus1[PS_MAX_CPB_CNT];            // ue(v)
       
    86     u_int32   cpb_size_value_minus1[PS_MAX_CPB_CNT];            // ue(v)
       
    87     unsigned  cbr_flag[PS_MAX_CPB_CNT];                         // u(1)
       
    88   unsigned    initial_cpb_removal_delay_length_minus1;          // u(5)
       
    89   unsigned    cpb_removal_delay_length_minus1;                  // u(5)
       
    90   unsigned    dpb_output_delay_length_minus1;                   // u(5)
       
    91   unsigned    time_offset_length;                               // u(5)
       
    92 } hrd_parameters_s;
       
    93 
       
    94 
       
    95 /*
       
    96  * Video usability information
       
    97  */
       
    98 
       
    99 typedef struct _vui_parameters_s
       
   100 {
       
   101   Boolean             aspect_ratio_info_present_flag;                   // u(1)
       
   102     unsigned          aspect_ratio_idc;                                 // u(8)
       
   103       unsigned        sar_width;                                        // u(16)
       
   104       unsigned        sar_height;                                       // u(16)
       
   105   Boolean             overscan_info_present_flag;                       // u(1)
       
   106     Boolean           overscan_appropriate_flag;                        // u(1)
       
   107   Boolean             video_signal_type_present_flag;                   // u(1)
       
   108     unsigned          video_format;                                     // u(3)
       
   109     Boolean           video_full_range_flag;                            // u(1)
       
   110     Boolean           colour_description_present_flag;                  // u(1)
       
   111       unsigned        colour_primaries;                                 // u(8)
       
   112       unsigned        transfer_characteristics;                         // u(8)
       
   113       unsigned        matrix_coefficients;                              // u(8)
       
   114   Boolean             chroma_loc_info_present_flag;                     // u(1)
       
   115     unsigned          chroma_sample_loc_type_top_field;                 // ue(v)
       
   116     unsigned          chroma_sample_loc_type_bottom_field;              // ue(v)
       
   117   Boolean             timing_info_present_flag;                         // u(1)
       
   118     u_int32           num_units_in_tick;                                // u(32)
       
   119     u_int32           time_scale;                                       // u(32)
       
   120     Boolean           fixed_frame_rate_flag;                            // u(1)
       
   121   Boolean             nal_hrd_parameters_present_flag;                  // u(1)
       
   122     hrd_parameters_s  nal_hrd_parameters;                               // hrd_paramters_s
       
   123   Boolean             vcl_hrd_parameters_present_flag;                  // u(1)
       
   124     hrd_parameters_s  vcl_hrd_parameters;                               // hrd_paramters_s
       
   125   // if ((nal_hrd_parameters_present_flag || (vcl_hrd_parameters_present_flag))
       
   126     Boolean           low_delay_hrd_flag;                               // u(1)
       
   127   Boolean             pic_struct_present_flag;                          // u(1)
       
   128   Boolean             bitstream_restriction_flag;                       // u(1)
       
   129     Boolean           motion_vectors_over_pic_boundaries_flag;          // u(1)
       
   130     unsigned          max_bytes_per_pic_denom;                          // ue(v)
       
   131     unsigned          max_bits_per_mb_denom;                            // ue(v)
       
   132     unsigned          log2_max_mv_length_horizontal;                    // ue(v)
       
   133     unsigned          log2_max_mv_length_vertical;                      // ue(v)
       
   134     unsigned          num_reorder_frames;                               // ue(v)
       
   135     unsigned          max_dec_frame_buffering;                          // ue(v)
       
   136 } vui_parameters_s;
       
   137 
       
   138 
       
   139 /*
       
   140  * Picture parameter set
       
   141  */
       
   142 
       
   143 typedef struct _pic_parameter_set_s
       
   144 {
       
   145   unsigned      pic_parameter_set_id;                          // ue(v)
       
   146   unsigned      seq_parameter_set_id;                          // ue(v)
       
   147   Boolean       entropy_coding_mode_flag;                      // u(1)
       
   148   Boolean       pic_order_present_flag;                        // u(1)
       
   149   unsigned      num_slice_groups_minus1;                       // ue(v)
       
   150     unsigned    slice_group_map_type;                          // ue(v)
       
   151       // if( slice_group_map_type = = 0 )
       
   152       unsigned  run_length_minus1[PS_MAX_NUM_SLICE_GROUPS];    // ue(v)
       
   153       // else if( slice_group_map_type = = 2 )
       
   154       unsigned  top_left[PS_MAX_NUM_SLICE_GROUPS];             // ue(v)
       
   155       unsigned  bottom_right[PS_MAX_NUM_SLICE_GROUPS];         // ue(v)
       
   156       // else if( slice_group_map_type = = 3 || 4 || 5
       
   157       Boolean   slice_group_change_direction_flag;             // u(1)
       
   158       unsigned  slice_group_change_rate_minus1;                // ue(v)
       
   159       // else if( slice_group_map_type = = 6 )
       
   160       unsigned  pic_size_in_map_units_minus1;                  // ue(v)
       
   161       unsigned  *slice_group_id;                               // complete MBAmap u(v)
       
   162   unsigned      num_ref_idx_l0_active_minus1;                  // ue(v)
       
   163   unsigned      num_ref_idx_l1_active_minus1;                  // ue(v)
       
   164   Boolean       weighted_pred_flag;                            // u(1)
       
   165   Boolean       weighted_bipred_idc;                           // u(2)
       
   166   int           pic_init_qp_minus26;                           // se(v)
       
   167   int           pic_init_qs_minus26;                           // se(v)
       
   168   int           chroma_qp_index_offset;                        // se(v)
       
   169   Boolean       deblocking_filter_parameters_present_flag;     // u(1)
       
   170   Boolean       constrained_intra_pred_flag;                   // u(1)
       
   171   Boolean       redundant_pic_cnt_present_flag;                // u(1)
       
   172   
       
   173 	TUint8 indexChanged;	// Flag for changed PPS Id (because of Id conflict in clip (can happen in e.g. merge, cut operations)
       
   174   	TUint newPPSId;
       
   175   	TUint PPSlength;
       
   176   	TUint8* codedPPSBuffer;
       
   177     TUint encPPSId;
       
   178     TUint origPPSId;
       
   179 } pic_parameter_set_s;
       
   180 
       
   181 
       
   182 /*
       
   183  * Sequence parameter set
       
   184  */
       
   185 
       
   186 typedef struct _seq_parameter_set_s
       
   187 {
       
   188   unsigned  profile_idc;                                      // u(8)
       
   189   Boolean   constraint_set0_flag;                             // u(1)
       
   190   Boolean   constraint_set1_flag;                             // u(1)
       
   191   Boolean   constraint_set2_flag;                             // u(1)
       
   192   Boolean   constraint_set3_flag;                             // u(1)
       
   193   Boolean   reserved_zero_4bits;                              // u(4)
       
   194   unsigned  level_idc;                                        // u(8)
       
   195   unsigned  seq_parameter_set_id;                             // ue(v)
       
   196   unsigned  log2_max_frame_num_minus4;                        // ue(v)
       
   197   unsigned  pic_order_cnt_type;
       
   198     // if( pic_order_cnt_type == 0 ) 
       
   199     unsigned log2_max_pic_order_cnt_lsb_minus4;               // ue(v)
       
   200     // else if( pic_order_cnt_type == 1 )
       
   201     Boolean delta_pic_order_always_zero_flag;                 // u(1)
       
   202     int32   offset_for_non_ref_pic;                           // se(v)
       
   203     int32   offset_for_top_to_bottom_field;                   // se(v)
       
   204     unsigned  num_ref_frames_in_pic_order_cnt_cycle;          // ue(v)
       
   205       // for( i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++ )
       
   206       int32 offset_for_ref_frame[PS_MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE];   // se(v)
       
   207   unsigned  num_ref_frames;                                   // ue(v)
       
   208   Boolean   gaps_in_frame_num_value_allowed_flag;             // u(1)
       
   209   unsigned  pic_width_in_mbs_minus1;                          // ue(v)
       
   210   unsigned  pic_height_in_map_units_minus1;                   // ue(v)
       
   211   Boolean   frame_mbs_only_flag;                              // u(1)
       
   212     // if( !frame_mbs_only_flag ) 
       
   213     Boolean mb_adaptive_frame_field_flag;                     // u(1)
       
   214   Boolean   direct_8x8_inference_flag;                        // u(1)
       
   215   Boolean       frame_cropping_flag;                           // u(1)
       
   216     unsigned    frame_crop_left_offset;                        // ue(v)
       
   217     unsigned    frame_crop_right_offset;                       // ue(v)
       
   218     unsigned    frame_crop_top_offset;                         // ue(v)
       
   219     unsigned    frame_crop_bottom_offset;                      // ue(v)
       
   220   Boolean   vui_parameters_present_flag;                      // u(1)
       
   221     vui_parameters_s vui_parameters;                          // vui_seq_parameters_s
       
   222     
       
   223   	TUint8 indexChanged;	// Flag for changed PPS Id (because of Id conflict in clip (can happen in e.g. merge, cut operations)
       
   224   	TUint newSPSId;
       
   225   	TUint SPSlength;
       
   226     TUint8* codedSPSBuffer;
       
   227     TUint encSPSId;
       
   228     TUint origSPSId;
       
   229     TUint8	maxFrameNumChanged;
       
   230     TUint origMaxFrameNum;
       
   231     TUint encMaxFrameNum;
       
   232     TUint8	maxPOCNumChanged;
       
   233     TUint origMaxPOCNum;
       
   234     TUint encMaxPOCNum;
       
   235 } seq_parameter_set_s;
       
   236 
       
   237 
       
   238 
       
   239 /*
       
   240  * Function prototypes
       
   241  */
       
   242 
       
   243 
       
   244 
       
   245 TInt psParseLevelFromSPS( bitbuffer_s *bitbuf, TInt& aLevel );
       
   246 
       
   247 TInt AddBytesToBuffer(bitbuffer_s *aBitBuffer, TUint aNumBytes);
       
   248 
       
   249 int psDecodeSPS( bitbuffer_s *bitbuf, seq_parameter_set_s **spsList, 
       
   250                  TInt& aWidth, TInt& aHeight );
       
   251 
       
   252 void psCloseParametersSets(seq_parameter_set_s **spsList,
       
   253                            pic_parameter_set_s **ppsList);
       
   254                            
       
   255 void psClosePPS( pic_parameter_set_s *pps );
       
   256 
       
   257 void psCloseSPS( seq_parameter_set_s *sps );
       
   258 
       
   259 
       
   260 #ifdef VIDEOEDITORENGINE_AVC_EDITING
       
   261 
       
   262 TInt psParseSPS( bitbuffer_s *bitbuf, seq_parameter_set_s **spsList, TUint aFrameFromEncoder, TBool *aEncodeUntilIDR, TUint *aNumSPS );
       
   263 
       
   264 TInt psParsePPS( bitbuffer_s *bitbuf, pic_parameter_set_s **ppsList, seq_parameter_set_s **spsList, 
       
   265 				 TUint aFrameFromEncoder, TUint *aNumPPS );
       
   266 
       
   267 void psGetAspectRatio(seq_parameter_set_s *sps, int *width, int *height);
       
   268 
       
   269 TInt GetNumTrailingBits(bitbuffer_s *aBitBuffer);
       
   270 
       
   271 TInt ReturnUnsignedExpGolombCodeLength(TUint aValue);
       
   272 
       
   273 void EncodeUnsignedExpGolombCode(bitbuffer_s *aBitBuffer, TUint aValue);
       
   274 
       
   275 void ShiftBitBufferBitsRight(bitbuffer_s *aBitBuffer, TInt aDiff);
       
   276 
       
   277 void ShiftBitBufferBitsLeft(bitbuffer_s *aBitBuffer, TInt aDiff);
       
   278 
       
   279 void ShiftBufferLeftByOneByte(bitbuffer_s *aBitBuffer);
       
   280 
       
   281 void ShiftBufferRightByOneByte(bitbuffer_s *aBitBuffer);
       
   282 
       
   283 void ShiftBufferRight(bitbuffer_s *aBitBuffer, TInt aDiff, TUint aTrailingBits, TUint aOldIdLength);
       
   284 
       
   285 void ShiftBufferLeft(bitbuffer_s *aBitBuffer, TInt aDiff, TUint aOldIdLength);
       
   286 
       
   287 
       
   288 #endif  // VIDEOEDITORENGINE_AVC_EDITING
       
   289 
       
   290 #endif