00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <time.h>
00017 #include <limits.h>
00018
00019 #include "global.h"
00020
00021 #include "contributors.h"
00022 #include "nal.h"
00023 #include "mbuffer.h"
00024 #include "parset.h"
00025 #include "vlc.h"
00026 #include "q_matrix.h"
00027
00028
00029 static int IdentifyProfile(InputParameters *p_Inp);
00030 static int IdentifyLevel(InputParameters *p_Inp);
00031 static int GenerateVUI_parameters_rbsp(seq_parameter_set_rbsp_t *sps, Bitstream *bitstream);
00032
00033 static const byte ZZ_SCAN[16] =
00034 {
00035 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15
00036 };
00037
00038 static const byte ZZ_SCAN8[64] =
00039 { 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
00040 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
00041 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
00042 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
00043 };
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 void GenerateParameterSets (ImageParameters *p_Img, InputParameters *p_Inp)
00058 {
00059 int i;
00060 seq_parameter_set_rbsp_t *sps = NULL;
00061
00062 sps = AllocSPS();
00063
00064 for (i=0; i<MAXPPS; i++)
00065 {
00066 p_Img->PicParSet[i] = NULL;
00067 }
00068
00069 GenerateSequenceParameterSet(sps, p_Img, p_Inp, 0);
00070
00071 if (p_Inp->GenerateMultiplePPS)
00072 {
00073 p_Img->PicParSet[0] = AllocPPS();
00074 p_Img->PicParSet[1] = AllocPPS();
00075 p_Img->PicParSet[2] = AllocPPS();
00076
00077 if (IS_FREXT_PROFILE(sps->profile_idc))
00078 {
00079 GeneratePictureParameterSet( p_Img->PicParSet[0], sps, p_Img, p_Inp, 0, 0, 0, p_Inp->cb_qp_index_offset, p_Inp->cr_qp_index_offset);
00080 GeneratePictureParameterSet( p_Img->PicParSet[1], sps, p_Img, p_Inp, 1, 1, 1, p_Inp->cb_qp_index_offset, p_Inp->cr_qp_index_offset);
00081 GeneratePictureParameterSet( p_Img->PicParSet[2], sps, p_Img, p_Inp, 2, 1, 2, p_Inp->cb_qp_index_offset, p_Inp->cr_qp_index_offset);
00082
00083 }
00084 else
00085 {
00086 GeneratePictureParameterSet( p_Img->PicParSet[0], sps, p_Img, p_Inp, 0, 0, 0, p_Inp->chroma_qp_index_offset, 0);
00087 GeneratePictureParameterSet( p_Img->PicParSet[1], sps, p_Img, p_Inp, 1, 1, 1, p_Inp->chroma_qp_index_offset, 0);
00088 GeneratePictureParameterSet( p_Img->PicParSet[2], sps, p_Img, p_Inp, 2, 1, 2, p_Inp->chroma_qp_index_offset, 0);
00089 }
00090 }
00091 else
00092 {
00093 p_Img->PicParSet[0] = AllocPPS();
00094 if (IS_FREXT_PROFILE(sps->profile_idc))
00095 GeneratePictureParameterSet( p_Img->PicParSet[0], sps, p_Img, p_Inp, 0, p_Inp->WeightedPrediction, p_Inp->WeightedBiprediction,
00096 p_Inp->cb_qp_index_offset, p_Inp->cr_qp_index_offset);
00097 else
00098 GeneratePictureParameterSet( p_Img->PicParSet[0], sps, p_Img, p_Inp, 0, p_Inp->WeightedPrediction, p_Inp->WeightedBiprediction,
00099 p_Inp->chroma_qp_index_offset, 0);
00100 }
00101
00102 p_Img->active_sps = sps;
00103 p_Img->active_pps = p_Img->PicParSet[0];
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 void FreeParameterSets (ImageParameters *p_Img)
00117 {
00118 int i;
00119 for (i=0; i<MAXPPS; i++)
00120 {
00121 if ( NULL != p_Img->PicParSet[i])
00122 {
00123 FreePPS(p_Img->PicParSet[i]);
00124 p_Img->PicParSet[i] = NULL;
00125 }
00126 }
00127 FreeSPS (p_Img->active_sps);
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 NALU_t *GenerateSeq_parameter_set_NALU (ImageParameters *p_Img)
00147 {
00148 NALU_t *n = AllocNALU(MAXNALUSIZE);
00149 int RBSPlen = 0;
00150 int NALUlen;
00151 byte rbsp[MAXRBSPSIZE];
00152
00153 RBSPlen = GenerateSeq_parameter_set_rbsp (p_Img, p_Img->active_sps, rbsp);
00154 NALUlen = RBSPtoNALU (rbsp, n, RBSPlen, NALU_TYPE_SPS, NALU_PRIORITY_HIGHEST, 1);
00155 n->startcodeprefix_len = 4;
00156
00157 return n;
00158 }
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 NALU_t *GeneratePic_parameter_set_NALU(ImageParameters *p_Img, InputParameters *p_Inp, int PPS_id)
00177 {
00178 NALU_t *n = AllocNALU(MAXNALUSIZE);
00179 int RBSPlen = 0;
00180 int NALUlen;
00181 byte rbsp[MAXRBSPSIZE];
00182
00183 RBSPlen = GeneratePic_parameter_set_rbsp (p_Img, p_Inp, p_Img->PicParSet[PPS_id], rbsp);
00184 NALUlen = RBSPtoNALU (rbsp, n, RBSPlen, NALU_TYPE_PPS, NALU_PRIORITY_HIGHEST, 1);
00185 n->startcodeprefix_len = 4;
00186
00187 return n;
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 void GenerateSequenceParameterSet( seq_parameter_set_rbsp_t *sps,
00214 ImageParameters *p_Img,
00215 InputParameters *p_Inp,
00216 int SPS_id
00217 )
00218 {
00219 unsigned i;
00220 unsigned n_ScalingList;
00221 int SubWidthC [4]= { 1, 2, 2, 1};
00222 int SubHeightC [4]= { 1, 2, 1, 1};
00223
00224 int frext_profile = ((IdentifyProfile(p_Inp)==FREXT_HP) ||
00225 (IdentifyProfile(p_Inp)==FREXT_Hi10P) ||
00226 (IdentifyProfile(p_Inp)==FREXT_Hi422) ||
00227 (IdentifyProfile(p_Inp)==FREXT_Hi444) ||
00228 (IdentifyProfile(p_Inp)==FREXT_CAVLC444));
00229
00230
00231
00232
00233 assert (sps != NULL);
00234
00235
00236 sps->profile_idc = IdentifyProfile(p_Inp);
00237 sps->level_idc = IdentifyLevel(p_Inp);
00238
00239
00240 sps->constrained_set0_flag = FALSE;
00241 sps->constrained_set1_flag = FALSE;
00242 sps->constrained_set2_flag = FALSE;
00243
00244 if ( (sps->level_idc == 9) && !IS_FREXT_PROFILE(sps->profile_idc) )
00245 {
00246 sps->constrained_set3_flag = TRUE;
00247 sps->level_idc = 11;
00248 }
00249 else if (frext_profile && p_Inp->IntraProfile)
00250 {
00251 sps->constrained_set3_flag = TRUE;
00252 }
00253 else
00254 {
00255 sps->constrained_set3_flag = FALSE;
00256 }
00257
00258
00259 sps->seq_parameter_set_id = SPS_id;
00260
00261
00262 sps->bit_depth_luma_minus8 = p_Inp->output.bit_depth[0] - 8;
00263 sps->bit_depth_chroma_minus8 = p_Inp->output.bit_depth[1] - 8;
00264 p_Img->lossless_qpprime_flag = p_Inp->LosslessCoding &
00265 (sps->profile_idc==FREXT_Hi444 || sps->profile_idc==FREXT_CAVLC444);
00266
00267
00268
00269
00270
00271
00272 sps->log2_max_frame_num_minus4 = p_Img->log2_max_frame_num_minus4;
00273 sps->log2_max_pic_order_cnt_lsb_minus4 = p_Img->log2_max_pic_order_cnt_lsb_minus4;
00274
00275 sps->pic_order_cnt_type = p_Inp->pic_order_cnt_type;
00276 sps->num_ref_frames_in_pic_order_cnt_cycle = p_Img->num_ref_frames_in_pic_order_cnt_cycle;
00277 sps->delta_pic_order_always_zero_flag = p_Img->delta_pic_order_always_zero_flag;
00278 sps->offset_for_non_ref_pic = p_Img->offset_for_non_ref_pic;
00279 sps->offset_for_top_to_bottom_field = p_Img->offset_for_top_to_bottom_field;
00280
00281 for (i=0; i<p_Img->num_ref_frames_in_pic_order_cnt_cycle; i++)
00282 {
00283 sps->offset_for_ref_frame[i] = p_Img->offset_for_ref_frame[i];
00284 }
00285
00286
00287
00288 sps->num_ref_frames = (unsigned char) p_Inp->num_ref_frames;
00289
00290
00291 sps->gaps_in_frame_num_value_allowed_flag = FALSE;
00292
00293 sps->frame_mbs_only_flag = (Boolean) !(p_Inp->PicInterlace || p_Inp->MbInterlace);
00294
00295
00296 sps->pic_width_in_mbs_minus1 = (( p_Inp->output.width + p_Img->auto_crop_right) >> 4) -1;
00297 sps->pic_height_in_map_units_minus1 = (((p_Inp->output.height + p_Img->auto_crop_bottom) >> 4)/ (2 - sps->frame_mbs_only_flag)) - 1;
00298
00299
00300 sps->mb_adaptive_frame_field_flag = (Boolean) (FRAME_CODING != p_Inp->MbInterlace);
00301 sps->direct_8x8_inference_flag = (Boolean) p_Inp->directInferenceFlag;
00302
00303
00304 sps->vui_parameters_present_flag = (Boolean) ((p_Inp->output.color_model != CM_YUV && p_Inp->output.yuv_format == YUV444) || p_Inp->EnableVUISupport);
00305 sps->chroma_format_idc = p_Inp->output.yuv_format;
00306 sps->separate_colour_plane_flag = ( sps->chroma_format_idc == YUV444 ) ? p_Inp->separate_colour_plane_flag : 0;
00307
00308 if ( sps->vui_parameters_present_flag )
00309 GenerateVUIParameters(sps, p_Inp);
00310
00311
00312 if(frext_profile)
00313 {
00314 sps->seq_scaling_matrix_present_flag = (Boolean) (p_Inp->ScalingMatrixPresentFlag&1);
00315 n_ScalingList = (sps->chroma_format_idc != YUV444) ? 8 : 12;
00316 for(i=0; i<n_ScalingList; i++)
00317 {
00318 if(i<6)
00319 sps->seq_scaling_list_present_flag[i] = (p_Inp->ScalingListPresentFlag[i]&1);
00320 else
00321 {
00322 if(p_Inp->Transform8x8Mode)
00323 sps->seq_scaling_list_present_flag[i] = (p_Inp->ScalingListPresentFlag[i]&1);
00324 else
00325 sps->seq_scaling_list_present_flag[i] = 0;
00326 }
00327 if( sps->seq_scaling_matrix_present_flag == FALSE )
00328 sps->seq_scaling_list_present_flag[i] = 0;
00329 }
00330 }
00331 else
00332 {
00333 sps->seq_scaling_matrix_present_flag = FALSE;
00334 for(i=0; i<12; i++)
00335 sps->seq_scaling_list_present_flag[i] = 0;
00336
00337 }
00338
00339
00340 if (p_Img->auto_crop_right || p_Img->auto_crop_bottom)
00341 {
00342 sps->frame_cropping_flag = TRUE;
00343 sps->frame_cropping_rect_left_offset=0;
00344 sps->frame_cropping_rect_top_offset=0;
00345 sps->frame_cropping_rect_right_offset= (p_Img->auto_crop_right / SubWidthC[sps->chroma_format_idc]);
00346 sps->frame_cropping_rect_bottom_offset= (p_Img->auto_crop_bottom / (SubHeightC[sps->chroma_format_idc] * (2 - sps->frame_mbs_only_flag)));
00347 if (p_Img->auto_crop_right % SubWidthC[sps->chroma_format_idc])
00348 {
00349 error("automatic frame cropping (width) not possible",500);
00350 }
00351 if (p_Img->auto_crop_bottom % (SubHeightC[sps->chroma_format_idc] * (2 - sps->frame_mbs_only_flag)))
00352 {
00353 error("automatic frame cropping (height) not possible",500);
00354 }
00355 }
00356 else
00357 {
00358 sps->frame_cropping_flag = FALSE;
00359 }
00360
00361 }
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376 void GeneratePictureParameterSet( pic_parameter_set_rbsp_t *pps,
00377 seq_parameter_set_rbsp_t *sps,
00378 ImageParameters *p_Img,
00379 InputParameters *p_Inp,
00380 int PPS_id,
00381 int WeightedPrediction,
00382 int WeightedBiprediction,
00383 int cb_qp_index_offset,
00384 int cr_qp_index_offset
00385 )
00386 {
00387 unsigned i;
00388 unsigned n_ScalingList;
00389
00390 int frext_profile = ((IdentifyProfile(p_Inp)==FREXT_HP) ||
00391 (IdentifyProfile(p_Inp)==FREXT_Hi10P) ||
00392 (IdentifyProfile(p_Inp)==FREXT_Hi422) ||
00393 (IdentifyProfile(p_Inp)==FREXT_Hi444) ||
00394 (IdentifyProfile(p_Inp)==FREXT_CAVLC444));
00395
00396
00397
00398
00399
00400 pps->seq_parameter_set_id = sps->seq_parameter_set_id;
00401 pps->pic_parameter_set_id = PPS_id;
00402 pps->entropy_coding_mode_flag = (p_Inp->symbol_mode == CAVLC ? FALSE : TRUE);
00403
00404 if(frext_profile)
00405 {
00406 pps->transform_8x8_mode_flag = (p_Inp->Transform8x8Mode ? TRUE:FALSE);
00407 pps->pic_scaling_matrix_present_flag = (Boolean) ((p_Inp->ScalingMatrixPresentFlag&2)>>1);
00408 n_ScalingList = (sps->chroma_format_idc != YUV444) ? 8 : 12;
00409 for(i=0; i<n_ScalingList; i++)
00410 {
00411 if(i<6)
00412 pps->pic_scaling_list_present_flag[i] = (p_Inp->ScalingListPresentFlag[i]&2)>>1;
00413 else
00414 {
00415 if(pps->transform_8x8_mode_flag)
00416 pps->pic_scaling_list_present_flag[i] = (p_Inp->ScalingListPresentFlag[i]&2)>>1;
00417 else
00418 pps->pic_scaling_list_present_flag[i] = 0;
00419 }
00420 if( pps->pic_scaling_matrix_present_flag == FALSE )
00421 pps->pic_scaling_list_present_flag[i] = 0;
00422 }
00423 }
00424 else
00425 {
00426 pps->pic_scaling_matrix_present_flag = FALSE;
00427 for(i=0; i<12; i++)
00428 pps->pic_scaling_list_present_flag[i] = 0;
00429
00430 pps->transform_8x8_mode_flag = FALSE;
00431 p_Inp->Transform8x8Mode = 0;
00432 }
00433
00434
00435 pps->bottom_field_pic_order_in_frame_present_flag = p_Img->bottom_field_pic_order_in_frame_present_flag;
00436
00437
00438
00439 pps->num_slice_groups_minus1 = p_Inp->num_slice_groups_minus1;
00440
00441
00442
00443 if (pps->num_slice_groups_minus1 > 0)
00444 {
00445 if ((pps->slice_group_id = calloc ((sps->pic_height_in_map_units_minus1+1)*(sps->pic_width_in_mbs_minus1+1), sizeof(byte))) == NULL)
00446 no_mem_exit ("GeneratePictureParameterSet: slice_group_id");
00447
00448 switch (p_Inp->slice_group_map_type)
00449 {
00450 case 0:
00451 pps->slice_group_map_type = 0;
00452 for(i=0; i<=pps->num_slice_groups_minus1; i++)
00453 {
00454 pps->run_length_minus1[i]=p_Inp->run_length_minus1[i];
00455 }
00456 break;
00457 case 1:
00458 pps->slice_group_map_type = 1;
00459 break;
00460 case 2:
00461
00462 pps->slice_group_map_type = 2;
00463 for(i=0; i<pps->num_slice_groups_minus1; i++)
00464 {
00465 pps->top_left[i] = p_Inp->top_left[i];
00466 pps->bottom_right[i] = p_Inp->bottom_right[i];
00467 }
00468 break;
00469 case 3:
00470 case 4:
00471 case 5:
00472 pps->slice_group_map_type = p_Inp->slice_group_map_type;
00473 pps->slice_group_change_direction_flag = (Boolean) p_Inp->slice_group_change_direction_flag;
00474 pps->slice_group_change_rate_minus1 = p_Inp->slice_group_change_rate_minus1;
00475 break;
00476 case 6:
00477 pps->slice_group_map_type = 6;
00478 pps->pic_size_in_map_units_minus1 =
00479 (((p_Inp->output.height + p_Img->auto_crop_bottom)/MB_BLOCK_SIZE)/(2-sps->frame_mbs_only_flag))
00480 *((p_Inp->output.width + p_Img->auto_crop_right)/MB_BLOCK_SIZE) -1;
00481
00482 for (i=0;i<=pps->pic_size_in_map_units_minus1; i++)
00483 pps->slice_group_id[i] = p_Inp->slice_group_id[i];
00484
00485 break;
00486 default:
00487 printf ("Parset.c: slice_group_map_type invalid, default\n");
00488 assert (0==1);
00489 }
00490 }
00491
00492
00493 pps->num_ref_idx_l0_active_minus1 = sps->frame_mbs_only_flag ? (sps->num_ref_frames-1) : (2 * sps->num_ref_frames - 1) ;
00494 pps->num_ref_idx_l1_active_minus1 = sps->frame_mbs_only_flag ? (sps->num_ref_frames-1) : (2 * sps->num_ref_frames - 1) ;
00495
00496 pps->weighted_pred_flag = (byte) WeightedPrediction;
00497 pps->weighted_bipred_idc = (byte) WeightedBiprediction;
00498
00499 pps->pic_init_qp_minus26 = 0;
00500 pps->pic_init_qs_minus26 = 0;
00501
00502 pps->chroma_qp_index_offset = cb_qp_index_offset;
00503 if (frext_profile)
00504 {
00505 pps->cb_qp_index_offset = cb_qp_index_offset;
00506 pps->cr_qp_index_offset = cr_qp_index_offset;
00507 }
00508 else
00509 pps->cb_qp_index_offset = pps->cr_qp_index_offset = pps->chroma_qp_index_offset;
00510
00511 pps->deblocking_filter_control_present_flag = (Boolean) p_Inp->DFSendParameters;
00512 pps->constrained_intra_pred_flag = (Boolean) p_Inp->UseConstrainedIntraPred;
00513
00514
00515 pps->redundant_pic_cnt_present_flag = (Boolean) p_Inp->redundant_pic_flag;
00516 }
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539 int Scaling_List(short *scalingListinput, short *scalingList, int sizeOfScalingList, short *UseDefaultScalingMatrix, Bitstream *bitstream)
00540 {
00541 int j, scanj;
00542 int len=0;
00543 int delta_scale, lastScale, nextScale;
00544
00545 lastScale = 8;
00546 nextScale = 8;
00547
00548 for(j=0; j<sizeOfScalingList; j++)
00549 {
00550 scanj = (sizeOfScalingList==16) ? ZZ_SCAN[j]:ZZ_SCAN8[j];
00551
00552 if(nextScale!=0)
00553 {
00554 delta_scale = scalingListinput[scanj]-lastScale;
00555 if(delta_scale>127)
00556 delta_scale=delta_scale-256;
00557 else if(delta_scale<-128)
00558 delta_scale=delta_scale+256;
00559
00560 len+=se_v (" : delta_sl ", delta_scale, bitstream);
00561 nextScale = scalingListinput[scanj];
00562 *UseDefaultScalingMatrix|=(scanj==0 && nextScale==0);
00563 }
00564
00565 scalingList[scanj] = (short) ((nextScale==0) ? lastScale:nextScale);
00566 lastScale = scalingList[scanj];
00567 }
00568
00569 return len;
00570 }
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592 int GenerateSeq_parameter_set_rbsp (ImageParameters *p_Img, seq_parameter_set_rbsp_t *sps, byte *rbsp)
00593 {
00594 Bitstream *bitstream;
00595 int len = 0, LenInBytes;
00596 unsigned i;
00597 unsigned n_ScalingList;
00598
00599 assert (rbsp != NULL);
00600
00601 if ((bitstream=calloc(1, sizeof(Bitstream)))==NULL) no_mem_exit("SeqParameterSet:bitstream");
00602
00603
00604 bitstream->streamBuffer = rbsp;
00605 bitstream->bits_to_go = 8;
00606
00607 len+=u_v (8, "SPS: profile_idc", sps->profile_idc, bitstream);
00608
00609 len+=u_1 ("SPS: constrained_set0_flag", sps->constrained_set0_flag, bitstream);
00610 len+=u_1 ("SPS: constrained_set1_flag", sps->constrained_set1_flag, bitstream);
00611 len+=u_1 ("SPS: constrained_set2_flag", sps->constrained_set2_flag, bitstream);
00612 len+=u_1 ("SPS: constrained_set3_flag", sps->constrained_set3_flag, bitstream);
00613 len+=u_v (4, "SPS: reserved_zero_4bits", 0, bitstream);
00614
00615 len+=u_v (8, "SPS: level_idc", sps->level_idc, bitstream);
00616
00617 len+=ue_v ("SPS: seq_parameter_set_id", sps->seq_parameter_set_id, bitstream);
00618
00619
00620 if( IS_FREXT_PROFILE(sps->profile_idc) )
00621 {
00622 len+=ue_v ("SPS: chroma_format_idc", sps->chroma_format_idc, bitstream);
00623 if(p_Img->yuv_format == YUV444)
00624 len+=u_1 ("SPS: separate_colour_plane_flag", sps->separate_colour_plane_flag, bitstream);
00625 len+=ue_v ("SPS: bit_depth_luma_minus8", sps->bit_depth_luma_minus8, bitstream);
00626 len+=ue_v ("SPS: bit_depth_chroma_minus8", sps->bit_depth_chroma_minus8, bitstream);
00627 len+=u_1 ("SPS: lossless_qpprime_y_zero_flag", p_Img->lossless_qpprime_flag, bitstream);
00628
00629
00630 len+=u_1 ("SPS: seq_scaling_matrix_present_flag", sps->seq_scaling_matrix_present_flag, bitstream);
00631
00632 if(sps->seq_scaling_matrix_present_flag)
00633 {
00634 ScaleParameters *p_QScale = p_Img->p_QScale;
00635 n_ScalingList = (sps->chroma_format_idc != YUV444) ? 8 : 12;
00636 for(i=0; i<n_ScalingList; i++)
00637 {
00638 len+=u_1 ("SPS: seq_scaling_list_present_flag", sps->seq_scaling_list_present_flag[i], bitstream);
00639 if(sps->seq_scaling_list_present_flag[i])
00640 {
00641 if(i<6)
00642 len+=Scaling_List(p_QScale->ScalingList4x4input[i], p_QScale->ScalingList4x4[i], 16, &p_QScale->UseDefaultScalingMatrix4x4Flag[i], bitstream);
00643 else
00644 len+=Scaling_List(p_QScale->ScalingList8x8input[i-6], p_QScale->ScalingList8x8[i-6], 64, &p_QScale->UseDefaultScalingMatrix8x8Flag[i-6], bitstream);
00645 }
00646 }
00647 }
00648 }
00649
00650 len+=ue_v ("SPS: log2_max_frame_num_minus4", sps->log2_max_frame_num_minus4, bitstream);
00651 len+=ue_v ("SPS: pic_order_cnt_type", sps->pic_order_cnt_type, bitstream);
00652
00653 if (sps->pic_order_cnt_type == 0)
00654 len+=ue_v ("SPS: log2_max_pic_order_cnt_lsb_minus4", sps->log2_max_pic_order_cnt_lsb_minus4, bitstream);
00655 else if (sps->pic_order_cnt_type == 1)
00656 {
00657 len+=u_1 ("SPS: delta_pic_order_always_zero_flag", sps->delta_pic_order_always_zero_flag, bitstream);
00658 len+=se_v ("SPS: offset_for_non_ref_pic", sps->offset_for_non_ref_pic, bitstream);
00659 len+=se_v ("SPS: offset_for_top_to_bottom_field", sps->offset_for_top_to_bottom_field, bitstream);
00660 len+=ue_v ("SPS: num_ref_frames_in_pic_order_cnt_cycle", sps->num_ref_frames_in_pic_order_cnt_cycle, bitstream);
00661 for (i=0; i<sps->num_ref_frames_in_pic_order_cnt_cycle; i++)
00662 len+=se_v ("SPS: offset_for_ref_frame", sps->offset_for_ref_frame[i], bitstream);
00663 }
00664 len+=ue_v ("SPS: num_ref_frames", sps->num_ref_frames, bitstream);
00665 len+=u_1 ("SPS: gaps_in_frame_num_value_allowed_flag", sps->gaps_in_frame_num_value_allowed_flag, bitstream);
00666 len+=ue_v ("SPS: pic_width_in_mbs_minus1", sps->pic_width_in_mbs_minus1, bitstream);
00667 len+=ue_v ("SPS: pic_height_in_map_units_minus1", sps->pic_height_in_map_units_minus1, bitstream);
00668 len+=u_1 ("SPS: frame_mbs_only_flag", sps->frame_mbs_only_flag, bitstream);
00669 if (!sps->frame_mbs_only_flag)
00670 {
00671 len+=u_1 ("SPS: mb_adaptive_frame_field_flag", sps->mb_adaptive_frame_field_flag, bitstream);
00672 }
00673 len+=u_1 ("SPS: direct_8x8_inference_flag", sps->direct_8x8_inference_flag, bitstream);
00674
00675 len+=u_1 ("SPS: frame_cropping_flag", sps->frame_cropping_flag, bitstream);
00676 if (sps->frame_cropping_flag)
00677 {
00678 len+=ue_v ("SPS: frame_cropping_rect_left_offset", sps->frame_cropping_rect_left_offset, bitstream);
00679 len+=ue_v ("SPS: frame_cropping_rect_right_offset", sps->frame_cropping_rect_right_offset, bitstream);
00680 len+=ue_v ("SPS: frame_cropping_rect_top_offset", sps->frame_cropping_rect_top_offset, bitstream);
00681 len+=ue_v ("SPS: frame_cropping_rect_bottom_offset", sps->frame_cropping_rect_bottom_offset, bitstream);
00682 }
00683
00684 len+=u_1 ("SPS: vui_parameters_present_flag", sps->vui_parameters_present_flag, bitstream);
00685
00686 if (sps->vui_parameters_present_flag)
00687 len+=GenerateVUI_parameters_rbsp(sps, bitstream);
00688
00689 SODBtoRBSP(bitstream);
00690
00691 LenInBytes=bitstream->byte_pos;
00692
00693 free (bitstream);
00694
00695 return LenInBytes;
00696 }
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722 int GeneratePic_parameter_set_rbsp (ImageParameters *p_Img, InputParameters *p_Inp, pic_parameter_set_rbsp_t *pps, byte *rbsp)
00723 {
00724
00725 Bitstream *bitstream;
00726 int len = 0, LenInBytes;
00727 unsigned i;
00728 unsigned n_ScalingList;
00729 unsigned NumberBitsPerSliceGroupId;
00730 int profile_idc;
00731
00732 assert (rbsp != NULL);
00733
00734 if ((bitstream=calloc(1, sizeof(Bitstream)))==NULL) no_mem_exit("PicParameterSet:bitstream");
00735
00736
00737 bitstream->streamBuffer = rbsp;
00738 bitstream->bits_to_go = 8;
00739
00740 pps->bottom_field_pic_order_in_frame_present_flag = p_Img->bottom_field_pic_order_in_frame_present_flag;
00741
00742 len+=ue_v ("PPS: pic_parameter_set_id", pps->pic_parameter_set_id, bitstream);
00743 len+=ue_v ("PPS: seq_parameter_set_id", pps->seq_parameter_set_id, bitstream);
00744 len+=u_1 ("PPS: entropy_coding_mode_flag", pps->entropy_coding_mode_flag, bitstream);
00745 len+=u_1 ("PPS: bottom_field_pic_order_in_frame_present_flag", pps->bottom_field_pic_order_in_frame_present_flag, bitstream);
00746 len+=ue_v ("PPS: num_slice_groups_minus1", pps->num_slice_groups_minus1, bitstream);
00747
00748
00749 if(pps->num_slice_groups_minus1 > 0 )
00750 {
00751 len+=ue_v ("PPS: slice_group_map_type", pps->slice_group_map_type, bitstream);
00752 if (pps->slice_group_map_type == 0)
00753 for (i=0; i<=pps->num_slice_groups_minus1; i++)
00754 len+=ue_v ("PPS: run_length_minus1[i]", pps->run_length_minus1[i], bitstream);
00755 else if (pps->slice_group_map_type==2)
00756 for (i=0; i<pps->num_slice_groups_minus1; i++)
00757 {
00758
00759 len+=ue_v ("PPS: top_left[i]", pps->top_left[i], bitstream);
00760 len+=ue_v ("PPS: bottom_right[i]", pps->bottom_right[i], bitstream);
00761 }
00762 else if (pps->slice_group_map_type == 3 ||
00763 pps->slice_group_map_type == 4 ||
00764 pps->slice_group_map_type == 5)
00765 {
00766 len+=u_1 ("PPS: slice_group_change_direction_flag", pps->slice_group_change_direction_flag, bitstream);
00767 len+=ue_v ("PPS: slice_group_change_rate_minus1", pps->slice_group_change_rate_minus1, bitstream);
00768 }
00769 else if (pps->slice_group_map_type == 6)
00770 {
00771 if (pps->num_slice_groups_minus1>=4)
00772 NumberBitsPerSliceGroupId=3;
00773 else if (pps->num_slice_groups_minus1>=2)
00774 NumberBitsPerSliceGroupId=2;
00775 else if (pps->num_slice_groups_minus1>=1)
00776 NumberBitsPerSliceGroupId=1;
00777 else
00778 NumberBitsPerSliceGroupId=0;
00779
00780 len+=ue_v ("PPS: pic_size_in_map_units_minus1", pps->pic_size_in_map_units_minus1, bitstream);
00781 for(i=0; i<=pps->pic_size_in_map_units_minus1; i++)
00782 len+= u_v (NumberBitsPerSliceGroupId, "PPS: >slice_group_id[i]", pps->slice_group_id[i], bitstream);
00783 }
00784 }
00785
00786
00787 len+=ue_v ("PPS: num_ref_idx_l0_active_minus1", pps->num_ref_idx_l0_active_minus1, bitstream);
00788 len+=ue_v ("PPS: num_ref_idx_l1_active_minus1", pps->num_ref_idx_l1_active_minus1, bitstream);
00789 len+=u_1 ("PPS: weighted_pred_flag", pps->weighted_pred_flag, bitstream);
00790 len+=u_v (2, "PPS: weighted_bipred_idc", pps->weighted_bipred_idc, bitstream);
00791 len+=se_v ("PPS: pic_init_qp_minus26", pps->pic_init_qp_minus26, bitstream);
00792 len+=se_v ("PPS: pic_init_qs_minus26", pps->pic_init_qs_minus26, bitstream);
00793
00794 profile_idc = IdentifyProfile(p_Inp);
00795 if( IS_FREXT_PROFILE(profile_idc) )
00796 len+=se_v ("PPS: chroma_qp_index_offset", pps->cb_qp_index_offset, bitstream);
00797 else
00798 len+=se_v ("PPS: chroma_qp_index_offset", pps->chroma_qp_index_offset, bitstream);
00799
00800 len+=u_1 ("PPS: deblocking_filter_control_present_flag", pps->deblocking_filter_control_present_flag, bitstream);
00801 len+=u_1 ("PPS: constrained_intra_pred_flag", pps->constrained_intra_pred_flag, bitstream);
00802 len+=u_1 ("PPS: redundant_pic_cnt_present_flag", pps->redundant_pic_cnt_present_flag, bitstream);
00803
00804
00805 if( IS_FREXT_PROFILE(profile_idc) )
00806 {
00807 len+=u_1 ("PPS: transform_8x8_mode_flag", pps->transform_8x8_mode_flag, bitstream);
00808
00809 len+=u_1 ("PPS: pic_scaling_matrix_present_flag", pps->pic_scaling_matrix_present_flag, bitstream);
00810
00811 if(pps->pic_scaling_matrix_present_flag)
00812 {
00813 ScaleParameters *p_QScale = p_Img->p_QScale;
00814 n_ScalingList = 6 + ((p_Img->active_sps->chroma_format_idc != 3) ? 2 : 6) * pps->transform_8x8_mode_flag;
00815 for(i=0; i<n_ScalingList; i++)
00816 {
00817 len+=u_1 ("PPS: pic_scaling_list_present_flag", pps->pic_scaling_list_present_flag[i], bitstream);
00818
00819 if(pps->pic_scaling_list_present_flag[i])
00820 {
00821 if(i<6)
00822 len+=Scaling_List(p_QScale->ScalingList4x4input[i], p_QScale->ScalingList4x4[i], 16, &p_QScale->UseDefaultScalingMatrix4x4Flag[i], bitstream);
00823 else
00824 len+=Scaling_List(p_QScale->ScalingList8x8input[i-6], p_QScale->ScalingList8x8[i-6], 64, &p_QScale->UseDefaultScalingMatrix8x8Flag[i-6], bitstream);
00825 }
00826 }
00827 }
00828 len+=se_v ("PPS: second_chroma_qp_index_offset", pps->cr_qp_index_offset, bitstream);
00829 }
00830
00831 SODBtoRBSP(bitstream);
00832
00833 LenInBytes=bitstream->byte_pos;
00834
00835
00836 free (bitstream);
00837
00838 return LenInBytes;
00839 }
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861 int IdentifyProfile(InputParameters *p_Inp)
00862 {
00863 return p_Inp->ProfileIDC;
00864 }
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879 int IdentifyLevel(InputParameters *p_Inp)
00880 {
00881 return p_Inp->LevelIDC;
00882 }
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894 static int GenerateVUI_parameters_rbsp(seq_parameter_set_rbsp_t *sps, Bitstream *bitstream)
00895 {
00896 int len=0;
00897 vui_seq_parameters_t *vui_seq_parameters = &(sps->vui_seq_parameters);
00898
00899 len+=u_1 ("VUI: aspect_ratio_info_present_flag", vui_seq_parameters->aspect_ratio_info_present_flag, bitstream);
00900 if (vui_seq_parameters->aspect_ratio_info_present_flag)
00901 {
00902 len+=u_v (8,"VUI: aspect_ratio_idc", vui_seq_parameters->aspect_ratio_idc, bitstream);
00903 if (vui_seq_parameters->aspect_ratio_idc == 255)
00904 {
00905 len+=u_v (16,"VUI: sar_width", vui_seq_parameters->sar_width, bitstream);
00906 len+=u_v (16,"VUI: sar_height", vui_seq_parameters->sar_height, bitstream);
00907 }
00908 }
00909
00910 len+=u_1 ("VUI: overscan_info_present_flag", vui_seq_parameters->overscan_info_present_flag, bitstream);
00911 if (vui_seq_parameters->overscan_info_present_flag)
00912 {
00913 len+=u_1 ("VUI: overscan_appropriate_flag", vui_seq_parameters->overscan_appropriate_flag, bitstream);
00914 }
00915
00916 len+=u_1 ("VUI: video_signal_type_present_flag", vui_seq_parameters->video_signal_type_present_flag, bitstream);
00917 if (vui_seq_parameters->video_signal_type_present_flag)
00918 {
00919 len+=u_v (3,"VUI: video_format", vui_seq_parameters->video_format, bitstream);
00920 len+=u_1 ("VUI: video_full_range_flag", vui_seq_parameters->video_full_range_flag, bitstream);
00921 len+=u_1 ("VUI: colour_description_present_flag", vui_seq_parameters->colour_description_present_flag, bitstream);
00922 if (vui_seq_parameters->colour_description_present_flag)
00923 {
00924 len+=u_v (8,"VUI: colour_primaries", vui_seq_parameters->colour_primaries, bitstream);
00925 len+=u_v (8,"VUI: transfer_characteristics", vui_seq_parameters->transfer_characteristics, bitstream);
00926 len+=u_v (8,"VUI: matrix_coefficients", vui_seq_parameters->matrix_coefficients, bitstream);
00927 }
00928 }
00929
00930 len+=u_1 ("VUI: chroma_loc_info_present_flag", vui_seq_parameters->chroma_location_info_present_flag, bitstream);
00931 if (vui_seq_parameters->chroma_location_info_present_flag)
00932 {
00933 len+=ue_v ("VUI: chroma_sample_loc_type_top_field", vui_seq_parameters->chroma_sample_loc_type_top_field, bitstream);
00934 len+=ue_v ("VUI: chroma_sample_loc_type_bottom_field", vui_seq_parameters->chroma_sample_loc_type_bottom_field, bitstream);
00935 }
00936
00937 len+=u_1 ("VUI: timing_info_present_flag", vui_seq_parameters->timing_info_present_flag, bitstream);
00938
00939 if (vui_seq_parameters->timing_info_present_flag)
00940 {
00941 len+=u_v (32,"VUI: num_units_in_tick", vui_seq_parameters->num_units_in_tick, bitstream);
00942 len+=u_v (32,"VUI: time_scale", vui_seq_parameters->time_scale, bitstream);
00943 len+=u_1 ("VUI: fixed_frame_rate_flag", vui_seq_parameters->fixed_frame_rate_flag, bitstream);
00944 }
00945
00946
00947 len+=u_1 ("VUI: nal_hrd_parameters_present_flag", vui_seq_parameters->nal_hrd_parameters_present_flag, bitstream);
00948 if ( vui_seq_parameters->nal_hrd_parameters_present_flag )
00949 {
00950 len += WriteHRDParameters(sps, bitstream);
00951 }
00952
00953 len+=u_1 ("VUI: vcl_hrd_parameters_present_flag", vui_seq_parameters->vcl_hrd_parameters_present_flag, bitstream);
00954 if ( vui_seq_parameters->vcl_hrd_parameters_present_flag )
00955 {
00956 len += WriteHRDParameters(sps, bitstream);
00957 }
00958 if ( vui_seq_parameters->nal_hrd_parameters_present_flag || vui_seq_parameters->vcl_hrd_parameters_present_flag )
00959 {
00960 len+=u_1 ("VUI: low_delay_hrd_flag", vui_seq_parameters->low_delay_hrd_flag, bitstream );
00961 }
00962 len+=u_1 ("VUI: pic_struct_present_flag", vui_seq_parameters->pic_struct_present_flag, bitstream);
00963
00964 len+=u_1 ("VUI: bitstream_restriction_flag", vui_seq_parameters->bitstream_restriction_flag, bitstream);
00965 if (vui_seq_parameters->bitstream_restriction_flag)
00966 {
00967 len+=u_1 ("VUI: motion_vectors_over_pic_boundaries_flag", vui_seq_parameters->motion_vectors_over_pic_boundaries_flag, bitstream);
00968 len+=ue_v ("VUI: max_bytes_per_pic_denom", vui_seq_parameters->max_bytes_per_pic_denom, bitstream);
00969 len+=ue_v ("VUI: max_bits_per_mb_denom", vui_seq_parameters->max_bits_per_mb_denom, bitstream);
00970 len+=ue_v ("VUI: log2_max_mv_length_horizontal", vui_seq_parameters->log2_max_mv_length_horizontal, bitstream);
00971 len+=ue_v ("VUI: log2_max_mv_length_vertical", vui_seq_parameters->log2_max_mv_length_vertical, bitstream);
00972 len+=ue_v ("VUI: num_reorder_frames", vui_seq_parameters->num_reorder_frames, bitstream);
00973 len+=ue_v ("VUI: max_dec_frame_buffering", vui_seq_parameters->max_dec_frame_buffering, bitstream);
00974 }
00975
00976 return len;
00977 }
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989 NALU_t *GenerateSEImessage_NALU(InputParameters *p_Inp)
00990 {
00991 NALU_t *n = AllocNALU(MAXNALUSIZE);
00992 int RBSPlen = 0;
00993 int NALUlen;
00994 byte rbsp[MAXRBSPSIZE];
00995
00996 RBSPlen = GenerateSEImessage_rbsp (p_Inp, NORMAL_SEI, rbsp);
00997 NALUlen = RBSPtoNALU (rbsp, n, RBSPlen, NALU_TYPE_SEI, NALU_PRIORITY_DISPOSABLE, 1);
00998 n->startcodeprefix_len = 4;
00999
01000 return n;
01001 }
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016 int GenerateSEImessage_rbsp (InputParameters *p_Inp, int id, byte *rbsp)
01017 {
01018 Bitstream *bitstream;
01019
01020 int len = 0, LenInBytes;
01021 assert (rbsp != NULL);
01022
01023 if ((bitstream=calloc(1, sizeof(Bitstream)))==NULL)
01024 no_mem_exit("SeqParameterSet:bitstream");
01025
01026
01027 bitstream->streamBuffer = rbsp;
01028 bitstream->bits_to_go = 8;
01029
01030 {
01031 char sei_message[500] = "";
01032 char uuid_message[9] = "Random";
01033 unsigned int i, message_size = strlen(p_Inp->SEIMessageText);
01034 TIME_T start_time;
01035 gettime(&start_time);
01036
01037 if (message_size == 0)
01038 {
01039 message_size = 13;
01040 strncpy(sei_message,"Empty Message",message_size);
01041 }
01042 else
01043 strncpy(sei_message,p_Inp->SEIMessageText,message_size);
01044
01045 len+=u_v (8,"SEI: last_payload_type_byte", 5, bitstream);
01046 message_size += 17;
01047 while (message_size > 254)
01048 {
01049 len+=u_v (8,"SEI: ff_byte",255, bitstream);
01050 message_size -= 255;
01051 }
01052 len+=u_v (8,"SEI: last_payload_size_byte",message_size, bitstream);
01053
01054
01055 #ifdef _WIN32
01056 len+=u_v (32,"SEI: uuid_iso_iec_11578",(int) start_time.HighPart, bitstream);
01057 len+=u_v (32,"SEI: uuid_iso_iec_11578",(int) start_time.QuadPart, bitstream);
01058 #else
01059 len+=u_v (32,"SEI: uuid_iso_iec_11578",(int) start_time.tv_sec, bitstream);
01060 len+=u_v (32,"SEI: uuid_iso_iec_11578",(int) start_time.tv_usec, bitstream);
01061 #endif
01062 len+=u_v (32,"SEI: uuid_iso_iec_11578",(int) (uuid_message[0] << 24) + (uuid_message[1] << 16) + (uuid_message[2] << 8) + (uuid_message[3] << 0), bitstream);
01063 len+=u_v (32,"SEI: uuid_iso_iec_11578",(int) (uuid_message[4] << 24) + (uuid_message[5] << 16) + (uuid_message[6] << 8) + (uuid_message[7] << 0), bitstream);
01064 for (i = 0; i < strlen(sei_message); i++)
01065 len+=u_v (8,"SEI: user_data_payload_byte",sei_message[i], bitstream);
01066
01067 len+=u_v (8,"SEI: user_data_payload_byte", 0, bitstream);
01068 }
01069 SODBtoRBSP(bitstream);
01070
01071 LenInBytes=bitstream->byte_pos;
01072
01073 free(bitstream);
01074 return LenInBytes;
01075 }
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090 int WriteHRDParameters(seq_parameter_set_rbsp_t *sps, Bitstream *bitstream)
01091 {
01092
01093 int len = 0;
01094 unsigned int SchedSelIdx = 0;
01095 hrd_parameters_t *hrd = &(sps->vui_seq_parameters.nal_hrd_parameters);
01096
01097 len+=ue_v ("VUI: cpb_cnt_minus1", hrd->cpb_cnt_minus1, bitstream);
01098 len+=u_v (4, "VUI: bit_rate_scale", hrd->bit_rate_scale, bitstream);
01099 len+=u_v (4, "VUI: cpb_size_scale", hrd->cpb_size_scale, bitstream);
01100
01101 for( SchedSelIdx = 0; SchedSelIdx <= (hrd->cpb_cnt_minus1); SchedSelIdx++ )
01102 {
01103 len+=ue_v ("VUI: bit_rate_value_minus1", hrd->bit_rate_value_minus1[SchedSelIdx], bitstream);
01104 len+=ue_v ("VUI: cpb_size_value_minus1", hrd->cpb_size_value_minus1[SchedSelIdx], bitstream);
01105 len+=u_1 ("VUI: cbr_flag", hrd->cbr_flag[SchedSelIdx], bitstream);
01106 }
01107
01108 len+=u_v (5, "VUI: initial_cpb_removal_delay_length_minus1", hrd->initial_cpb_removal_delay_length_minus1, bitstream);
01109 len+=u_v (5, "VUI: cpb_removal_delay_length_minus1", hrd->cpb_removal_delay_length_minus1, bitstream);
01110 len+=u_v (5, "VUI: dpb_output_delay_length_minus1", hrd->dpb_output_delay_length_minus1, bitstream);
01111 len+=u_v (5, "VUI: time_offset_length", hrd->time_offset_length, bitstream);
01112
01113 return len;
01114 }
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129 void GenerateVUIParameters(seq_parameter_set_rbsp_t *sps, InputParameters *p_Inp)
01130 {
01131 unsigned int SchedSelIdx;
01132 hrd_parameters_t *nal_hrd = &(sps->vui_seq_parameters.nal_hrd_parameters);
01133 hrd_parameters_t *vcl_hrd = &(sps->vui_seq_parameters.vcl_hrd_parameters);
01134 vui_seq_parameters_t *vui = &(sps->vui_seq_parameters);
01135 VUIParameters *iVui = &p_Inp->VUI;
01136
01137 vui->aspect_ratio_info_present_flag = (Boolean) iVui->aspect_ratio_info_present_flag;
01138 vui->aspect_ratio_idc = (unsigned int) iVui->aspect_ratio_idc;
01139 vui->sar_width = (unsigned int) iVui->sar_width;
01140 vui->sar_height = (unsigned int) iVui->sar_height;
01141 vui->overscan_info_present_flag = (Boolean) iVui->overscan_info_present_flag;
01142 vui->overscan_appropriate_flag = (Boolean) iVui->overscan_appropriate_flag;
01143 vui->video_signal_type_present_flag = (Boolean) iVui->video_signal_type_present_flag;
01144 vui->video_format = (unsigned int) iVui->video_format;
01145 vui->video_full_range_flag = (Boolean) iVui->video_full_range_flag;
01146 vui->colour_description_present_flag = (Boolean) iVui->colour_description_present_flag;
01147 vui->colour_primaries = (unsigned int) iVui->colour_primaries;
01148 vui->transfer_characteristics = (unsigned int) iVui->transfer_characteristics;
01149 vui->matrix_coefficients = (unsigned int) iVui->matrix_coefficients;
01150 vui->chroma_location_info_present_flag = (Boolean) iVui->chroma_location_info_present_flag;
01151 vui->chroma_sample_loc_type_top_field = (unsigned int) iVui->chroma_sample_loc_type_top_field;
01152 vui->chroma_sample_loc_type_bottom_field = (unsigned int) iVui->chroma_sample_loc_type_bottom_field;
01153 vui->timing_info_present_flag = (Boolean) iVui->timing_info_present_flag;
01154 vui->num_units_in_tick = (unsigned int) iVui->num_units_in_tick;
01155 vui->time_scale = (unsigned int) iVui->time_scale;
01156 vui->fixed_frame_rate_flag = (Boolean) iVui->fixed_frame_rate_flag;
01157
01158
01159 vui->nal_hrd_parameters_present_flag = (Boolean) iVui->nal_hrd_parameters_present_flag;
01160 nal_hrd->cpb_cnt_minus1 = (unsigned int) iVui->nal_cpb_cnt_minus1;
01161 nal_hrd->bit_rate_scale = (unsigned int) iVui->nal_bit_rate_scale;
01162 nal_hrd->cpb_size_scale = (unsigned int) iVui->nal_cpb_size_scale;
01163 for ( SchedSelIdx = 0; SchedSelIdx <= nal_hrd->cpb_cnt_minus1; SchedSelIdx++ )
01164 {
01165 nal_hrd->bit_rate_value_minus1[SchedSelIdx] = (unsigned int) iVui->nal_bit_rate_value_minus1;
01166 nal_hrd->cpb_size_value_minus1[SchedSelIdx] = (unsigned int) iVui->nal_cpb_size_value_minus1;
01167 nal_hrd->cbr_flag[SchedSelIdx] = (unsigned int) iVui->nal_vbr_cbr_flag;
01168 }
01169 nal_hrd->initial_cpb_removal_delay_length_minus1 = (unsigned int) iVui->nal_initial_cpb_removal_delay_length_minus1;
01170 nal_hrd->cpb_removal_delay_length_minus1 = (unsigned int) iVui->nal_cpb_removal_delay_length_minus1;
01171 nal_hrd->dpb_output_delay_length_minus1 = (unsigned int) iVui->nal_dpb_output_delay_length_minus1;
01172 nal_hrd->time_offset_length = (unsigned int) iVui->nal_time_offset_length;
01173
01174
01175 vui->vcl_hrd_parameters_present_flag = (Boolean) iVui->vcl_hrd_parameters_present_flag;
01176 vcl_hrd->cpb_cnt_minus1 = (unsigned int) iVui->vcl_cpb_cnt_minus1;
01177 vcl_hrd->bit_rate_scale = (unsigned int) iVui->vcl_bit_rate_scale;
01178 vcl_hrd->cpb_size_scale = (unsigned int) iVui->vcl_cpb_size_scale;
01179 for ( SchedSelIdx = 0; SchedSelIdx <= vcl_hrd->cpb_cnt_minus1; SchedSelIdx++ )
01180 {
01181 vcl_hrd->bit_rate_value_minus1[SchedSelIdx] = (unsigned int) iVui->vcl_bit_rate_value_minus1;
01182 vcl_hrd->cpb_size_value_minus1[SchedSelIdx] = (unsigned int) iVui->vcl_cpb_size_value_minus1;
01183 vcl_hrd->cbr_flag[SchedSelIdx] = (unsigned int) iVui->vcl_vbr_cbr_flag;
01184 }
01185 vcl_hrd->initial_cpb_removal_delay_length_minus1 = (unsigned int) iVui->vcl_initial_cpb_removal_delay_length_minus1;
01186 vcl_hrd->cpb_removal_delay_length_minus1 = (unsigned int) iVui->vcl_cpb_removal_delay_length_minus1;
01187 vcl_hrd->dpb_output_delay_length_minus1 = (unsigned int) iVui->vcl_dpb_output_delay_length_minus1;
01188 vcl_hrd->time_offset_length = (unsigned int) iVui->vcl_time_offset_length;
01189
01190 vui->low_delay_hrd_flag = (Boolean) iVui->low_delay_hrd_flag;
01191 vui->pic_struct_present_flag = (Boolean) iVui->pic_struct_present_flag;
01192 vui->bitstream_restriction_flag = (Boolean) iVui->bitstream_restriction_flag;
01193 vui->motion_vectors_over_pic_boundaries_flag = (Boolean) iVui->motion_vectors_over_pic_boundaries_flag;
01194 vui->max_bytes_per_pic_denom = (unsigned int) iVui->max_bytes_per_pic_denom;
01195 vui->max_bits_per_mb_denom = (unsigned int) iVui->max_bits_per_mb_denom;
01196 vui->log2_max_mv_length_horizontal = (unsigned int) iVui->log2_max_mv_length_horizontal;
01197 vui->log2_max_mv_length_vertical = (unsigned int) iVui->log2_max_mv_length_vertical;
01198 vui->num_reorder_frames = (unsigned int) iVui->num_reorder_frames;
01199 vui->max_dec_frame_buffering = (unsigned int) iVui->max_dec_frame_buffering;
01200
01201
01202 if (p_Inp->output.color_model != CM_YUV && p_Inp->output.yuv_format == YUV444)
01203 {
01204 printf ("VUI: writing Sequence Parameter VUI to signal RGB format\n");
01205
01206 vui->aspect_ratio_info_present_flag = FALSE;
01207 vui->overscan_info_present_flag = FALSE;
01208 vui->video_signal_type_present_flag = TRUE;
01209 vui->video_format = 2;
01210 vui->video_full_range_flag = TRUE;
01211 vui->colour_description_present_flag = TRUE;
01212 vui->colour_primaries = 2;
01213 vui->transfer_characteristics = 2;
01214 vui->matrix_coefficients = 0;
01215 vui->chroma_location_info_present_flag = FALSE;
01216 vui->timing_info_present_flag = FALSE;
01217 vui->nal_hrd_parameters_present_flag = FALSE;
01218 vui->vcl_hrd_parameters_present_flag = FALSE;
01219 vui->pic_struct_present_flag = FALSE;
01220 vui->bitstream_restriction_flag = FALSE;
01221 }
01222 }