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