00001
00015 #include "contributors.h"
00016
00017 #include <math.h>
00018 #include "global.h"
00019 #include "memalloc.h"
00020 #include "sei.h"
00021 #include "vlc.h"
00022 #include "header.h"
00023 #include "mbuffer.h"
00024 #include "parset.h"
00025
00026 extern int UsedBits;
00027
00028 extern seq_parameter_set_rbsp_t SeqParSet[MAXSPS];
00029
00030 #if (ENABLE_OUTPUT_TONEMAPPING)
00031 tone_mapping_struct seiToneMapping;
00032 #endif
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00072 void InterpretSEIMessage(byte* msg, int size, ImageParameters *img)
00073 {
00074 int payload_type = 0;
00075 int payload_size = 0;
00076 int offset = 1;
00077 byte tmp_byte;
00078 do
00079 {
00080
00081 payload_type = 0;
00082 tmp_byte = msg[offset++];
00083 while (tmp_byte == 0xFF)
00084 {
00085 payload_type += 255;
00086 tmp_byte = msg[offset++];
00087 }
00088 payload_type += tmp_byte;
00089
00090 payload_size = 0;
00091 tmp_byte = msg[offset++];
00092 while (tmp_byte == 0xFF)
00093 {
00094 payload_size += 255;
00095 tmp_byte = msg[offset++];
00096 }
00097 payload_size += tmp_byte;
00098
00099 switch ( payload_type )
00100 {
00101 case SEI_BUFFERING_PERIOD:
00102 interpret_buffering_period_info( msg+offset, payload_size, img );
00103 break;
00104 case SEI_PIC_TIMING:
00105 interpret_picture_timing_info( msg+offset, payload_size, img );
00106 break;
00107 case SEI_PAN_SCAN_RECT:
00108 interpret_pan_scan_rect_info( msg+offset, payload_size, img );
00109 break;
00110 case SEI_FILLER_PAYLOAD:
00111 interpret_filler_payload_info( msg+offset, payload_size, img );
00112 break;
00113 case SEI_USER_DATA_REGISTERED_ITU_T_T35:
00114 interpret_user_data_registered_itu_t_t35_info( msg+offset, payload_size, img );
00115 break;
00116 case SEI_USER_DATA_UNREGISTERED:
00117 interpret_user_data_unregistered_info( msg+offset, payload_size, img );
00118 break;
00119 case SEI_RECOVERY_POINT:
00120 interpret_recovery_point_info( msg+offset, payload_size, img );
00121 break;
00122 case SEI_DEC_REF_PIC_MARKING_REPETITION:
00123 interpret_dec_ref_pic_marking_repetition_info( msg+offset, payload_size, img );
00124 break;
00125 case SEI_SPARE_PIC:
00126 interpret_spare_pic( msg+offset, payload_size, img );
00127 break;
00128 case SEI_SCENE_INFO:
00129 interpret_scene_information( msg+offset, payload_size, img );
00130 break;
00131 case SEI_SUB_SEQ_INFO:
00132 interpret_subsequence_info( msg+offset, payload_size, img );
00133 break;
00134 case SEI_SUB_SEQ_LAYER_CHARACTERISTICS:
00135 interpret_subsequence_layer_characteristics_info( msg+offset, payload_size, img );
00136 break;
00137 case SEI_SUB_SEQ_CHARACTERISTICS:
00138 interpret_subsequence_characteristics_info( msg+offset, payload_size, img );
00139 break;
00140 case SEI_FULL_FRAME_FREEZE:
00141 interpret_full_frame_freeze_info( msg+offset, payload_size, img );
00142 break;
00143 case SEI_FULL_FRAME_FREEZE_RELEASE:
00144 interpret_full_frame_freeze_release_info( msg+offset, payload_size, img );
00145 break;
00146 case SEI_FULL_FRAME_SNAPSHOT:
00147 interpret_full_frame_snapshot_info( msg+offset, payload_size, img );
00148 break;
00149 case SEI_PROGRESSIVE_REFINEMENT_SEGMENT_START:
00150 interpret_progressive_refinement_start_info( msg+offset, payload_size, img );
00151 break;
00152 case SEI_PROGRESSIVE_REFINEMENT_SEGMENT_END:
00153 interpret_progressive_refinement_end_info( msg+offset, payload_size, img );
00154 break;
00155 case SEI_MOTION_CONSTRAINED_SLICE_GROUP_SET:
00156 interpret_motion_constrained_slice_group_set_info( msg+offset, payload_size, img );
00157 case SEI_FILM_GRAIN_CHARACTERISTICS:
00158 interpret_film_grain_characteristics_info ( msg+offset, payload_size, img );
00159 break;
00160 case SEI_DEBLOCKING_FILTER_DISPLAY_PREFERENCE:
00161 interpret_deblocking_filter_display_preference_info ( msg+offset, payload_size, img );
00162 break;
00163 case SEI_STEREO_VIDEO_INFO:
00164 interpret_stereo_video_info_info ( msg+offset, payload_size, img );
00165 break;
00166 case SEI_TONE_MAPPING:
00167 interpret_tone_mapping( msg+offset, payload_size, img );
00168 break;
00169 case SEI_POST_FILTER_HINTS:
00170 interpret_post_filter_hints_info ( msg+offset, payload_size, img );
00171 default:
00172 interpret_reserved_info( msg+offset, payload_size, img );
00173 break;
00174 }
00175 offset += payload_size;
00176
00177 } while( msg[offset] != 0x80 );
00178
00179 assert(msg[offset] == 0x80);
00180 assert( offset+1 == size );
00181 }
00182
00183
00197 void interpret_spare_pic( byte* payload, int size, ImageParameters *img )
00198 {
00199 int i,x,y;
00200 Bitstream* buf;
00201 int bit0, bit1, bitc, no_bit0;
00202 int target_frame_num = 0;
00203 int num_spare_pics;
00204 int delta_spare_frame_num, CandidateSpareFrameNum, SpareFrameNum = 0;
00205 int ref_area_indicator;
00206
00207 int m, n, left, right, top, bottom,directx, directy;
00208 byte ***map;
00209
00210 #ifdef WRITE_MAP_IMAGE
00211 int symbol_size_in_bytes = img->pic_unit_bitsize_on_disk/8;
00212 int j, k, i0, j0, tmp, kk;
00213 char filename[20] = "map_dec.yuv";
00214 FILE *fp;
00215 imgpel** Y;
00216 static int old_pn=-1;
00217 static int first = 1;
00218
00219 printf("Spare picture SEI message\n");
00220 #endif
00221
00222 UsedBits = 0;
00223
00224 assert( payload!=NULL);
00225 assert( img!=NULL);
00226
00227 buf = malloc(sizeof(Bitstream));
00228 buf->bitstream_length = size;
00229 buf->streamBuffer = payload;
00230 buf->frame_bitoffset = 0;
00231
00232 target_frame_num = ue_v("SEI: target_frame_num", buf);
00233
00234 #ifdef WRITE_MAP_IMAGE
00235 printf( "target_frame_num is %d\n", target_frame_num );
00236 #endif
00237
00238 num_spare_pics = 1 + ue_v("SEI: num_spare_pics_minus1", buf);
00239
00240 #ifdef WRITE_MAP_IMAGE
00241 printf( "num_spare_pics is %d\n", num_spare_pics );
00242 #endif
00243
00244 get_mem3D(&map, num_spare_pics, img->height/16, img->width/16);
00245
00246 for (i=0; i<num_spare_pics; i++)
00247 {
00248 if (i==0)
00249 {
00250 CandidateSpareFrameNum = target_frame_num - 1;
00251 if ( CandidateSpareFrameNum < 0 ) CandidateSpareFrameNum = MAX_FN - 1;
00252 }
00253 else
00254 CandidateSpareFrameNum = SpareFrameNum;
00255
00256 delta_spare_frame_num = ue_v("SEI: delta_spare_frame_num", buf);
00257
00258 SpareFrameNum = CandidateSpareFrameNum - delta_spare_frame_num;
00259 if( SpareFrameNum < 0 )
00260 SpareFrameNum = MAX_FN + SpareFrameNum;
00261
00262 ref_area_indicator = ue_v("SEI: ref_area_indicator", buf);
00263
00264 switch ( ref_area_indicator )
00265 {
00266 case 0:
00267 for (y=0; y<img->height/16; y++)
00268 for (x=0; x<img->width/16; x++)
00269 map[i][y][x] = 0;
00270 break;
00271 case 1:
00272 for (y=0; y<img->height/16; y++)
00273 for (x=0; x<img->width/16; x++)
00274 {
00275 map[i][y][x] = u_1("SEI: ref_mb_indicator", buf);
00276 }
00277 break;
00278 case 2:
00280 bit0 = 0;
00281 bit1 = 1;
00282 bitc = bit0;
00283 no_bit0 = -1;
00284
00285 x = ( img->width/16 - 1 ) / 2;
00286 y = ( img->height/16 - 1 ) / 2;
00287 left = right = x;
00288 top = bottom = y;
00289 directx = 0;
00290 directy = 1;
00291
00292 for (m=0; m<img->height/16; m++)
00293 for (n=0; n<img->width/16; n++)
00294 {
00295
00296 if (no_bit0<0)
00297 {
00298 no_bit0 = ue_v("SEI: zero_run_length", buf);
00299 }
00300 if (no_bit0>0)
00301 map[i][y][x] = (byte) bit0;
00302 else
00303 map[i][y][x] = (byte) bit1;
00304 no_bit0--;
00305
00306
00307 if ( directx == -1 && directy == 0 )
00308 {
00309 if (x > left) x--;
00310 else if (x == 0)
00311 {
00312 y = bottom + 1;
00313 bottom++;
00314 directx = 1;
00315 directy = 0;
00316 }
00317 else if (x == left)
00318 {
00319 x--;
00320 left--;
00321 directx = 0;
00322 directy = 1;
00323 }
00324 }
00325 else if ( directx == 1 && directy == 0 )
00326 {
00327 if (x < right) x++;
00328 else if (x == img->width/16 - 1)
00329 {
00330 y = top - 1;
00331 top--;
00332 directx = -1;
00333 directy = 0;
00334 }
00335 else if (x == right)
00336 {
00337 x++;
00338 right++;
00339 directx = 0;
00340 directy = -1;
00341 }
00342 }
00343 else if ( directx == 0 && directy == -1 )
00344 {
00345 if ( y > top) y--;
00346 else if (y == 0)
00347 {
00348 x = left - 1;
00349 left--;
00350 directx = 0;
00351 directy = 1;
00352 }
00353 else if (y == top)
00354 {
00355 y--;
00356 top--;
00357 directx = -1;
00358 directy = 0;
00359 }
00360 }
00361 else if ( directx == 0 && directy == 1 )
00362 {
00363 if (y < bottom) y++;
00364 else if (y == img->height/16 - 1)
00365 {
00366 x = right+1;
00367 right++;
00368 directx = 0;
00369 directy = -1;
00370 }
00371 else if (y == bottom)
00372 {
00373 y++;
00374 bottom++;
00375 directx = 1;
00376 directy = 0;
00377 }
00378 }
00379
00380
00381 }
00382 break;
00383 default:
00384 printf( "Wrong ref_area_indicator %d!\n", ref_area_indicator );
00385 exit(0);
00386 break;
00387 }
00388
00389 }
00390
00391 #ifdef WRITE_MAP_IMAGE
00392
00393 if ( old_pn != img->number )
00394 {
00395 old_pn = img->number;
00396 get_mem2Dpel(&Y, img->height, img->width);
00397 if (first)
00398 {
00399 fp = fopen( filename, "wb" );
00400 first = 0;
00401 }
00402 else
00403 fp = fopen( filename, "ab" );
00404 assert( fp != NULL );
00405 for (kk=0; kk<num_spare_pics; kk++)
00406 {
00407 for (i=0; i < img->height/16; i++)
00408 for (j=0; j < img->width/16; j++)
00409 {
00410 tmp=map[kk][i][j]==0? img->max_imgpel_value_comp[0] : 0;
00411 for (i0=0; i0<16; i0++)
00412 for (j0=0; j0<16; j0++)
00413 Y[i*16+i0][j*16+j0]=tmp;
00414 }
00415
00416
00417 for (i=0; i < img->height; i++)
00418 for (j=0; j < img->width; j++)
00419 fwrite(&(Y[i][j]), symbol_size_in_bytes, 1, p_out);
00420
00421 for (k=0; k < 2; k++)
00422 for (i=0; i < img->height>>1; i++)
00423 for (j=0; j < img->width>>1; j++)
00424 fwrite(&(img->dc_pred_value_comp[1]), symbol_size_in_bytes, 1, p_out);
00425 }
00426 fclose( fp );
00427 free_mem2Dpel( Y );
00428 }
00429
00430 #undef WRITE_MAP_IMAGE
00431 #endif
00432
00433 free_mem3D( map );
00434
00435 free(buf);
00436 }
00437
00438
00452 void interpret_subsequence_info( byte* payload, int size, ImageParameters *img )
00453 {
00454 Bitstream* buf;
00455 int sub_seq_layer_num, sub_seq_id, first_ref_pic_flag, leading_non_ref_pic_flag, last_pic_flag,
00456 sub_seq_frame_num_flag, sub_seq_frame_num;
00457
00458 buf = malloc(sizeof(Bitstream));
00459 buf->bitstream_length = size;
00460 buf->streamBuffer = payload;
00461 buf->frame_bitoffset = 0;
00462
00463 UsedBits = 0;
00464
00465 sub_seq_layer_num = ue_v("SEI: sub_seq_layer_num" , buf);
00466 sub_seq_id = ue_v("SEI: sub_seq_id" , buf);
00467 first_ref_pic_flag = u_1 ("SEI: first_ref_pic_flag" , buf);
00468 leading_non_ref_pic_flag = u_1 ("SEI: leading_non_ref_pic_flag", buf);
00469 last_pic_flag = u_1 ("SEI: last_pic_flag" , buf);
00470 sub_seq_frame_num_flag = u_1 ("SEI: sub_seq_frame_num_flag" , buf);
00471 if (sub_seq_frame_num_flag)
00472 {
00473 sub_seq_frame_num = ue_v("SEI: sub_seq_frame_num" , buf);
00474 }
00475
00476 #ifdef PRINT_SUBSEQUENCE_INFO
00477 printf("Sub-sequence information SEI message\n");
00478 printf("sub_seq_layer_num = %d\n", sub_seq_layer_num );
00479 printf("sub_seq_id = %d\n", sub_seq_id);
00480 printf("first_ref_pic_flag = %d\n", first_ref_pic_flag);
00481 printf("leading_non_ref_pic_flag = %d\n", leading_non_ref_pic_flag);
00482 printf("last_pic_flag = %d\n", last_pic_flag);
00483 printf("sub_seq_frame_num_flag = %d\n", sub_seq_frame_num_flag);
00484 if (sub_seq_frame_num_flag)
00485 {
00486 printf("sub_seq_frame_num = %d\n", sub_seq_frame_num);
00487 }
00488 #endif
00489
00490 free(buf);
00491 #ifdef PRINT_SUBSEQUENCE_INFO
00492 #undef PRINT_SUBSEQUENCE_INFO
00493 #endif
00494 }
00495
00509 void interpret_subsequence_layer_characteristics_info( byte* payload, int size, ImageParameters *img )
00510 {
00511 Bitstream* buf;
00512 long num_sub_layers, accurate_statistics_flag, average_bit_rate, average_frame_rate;
00513 int i;
00514
00515 buf = malloc(sizeof(Bitstream));
00516 buf->bitstream_length = size;
00517 buf->streamBuffer = payload;
00518 buf->frame_bitoffset = 0;
00519
00520 UsedBits = 0;
00521
00522 num_sub_layers = 1 + ue_v("SEI: num_sub_layers_minus1", buf);
00523
00524 #ifdef PRINT_SUBSEQUENCE_LAYER_CHAR
00525 printf("Sub-sequence layer characteristics SEI message\n");
00526 printf("num_sub_layers_minus1 = %d\n", num_sub_layers - 1);
00527 #endif
00528
00529 for (i=0; i<num_sub_layers; i++)
00530 {
00531 accurate_statistics_flag = u_1( "SEI: accurate_statistics_flag", buf);
00532 average_bit_rate = u_v(16,"SEI: average_bit_rate" , buf);
00533 average_frame_rate = u_v(16,"SEI: average_frame_rate" , buf);
00534
00535 #ifdef PRINT_SUBSEQUENCE_LAYER_CHAR
00536 printf("layer %d: accurate_statistics_flag = %ld \n", i, accurate_statistics_flag);
00537 printf("layer %d: average_bit_rate = %ld \n", i, average_bit_rate);
00538 printf("layer %d: average_frame_rate = %ld \n", i, average_frame_rate);
00539 #endif
00540 }
00541 free (buf);
00542 }
00543
00544
00558 void interpret_subsequence_characteristics_info( byte* payload, int size, ImageParameters *img )
00559 {
00560 Bitstream* buf;
00561 int i;
00562 int sub_seq_layer_num, sub_seq_id, duration_flag, average_rate_flag, accurate_statistics_flag;
00563 unsigned long sub_seq_duration, average_bit_rate, average_frame_rate;
00564 int num_referenced_subseqs, ref_sub_seq_layer_num, ref_sub_seq_id, ref_sub_seq_direction;
00565
00566 buf = malloc(sizeof(Bitstream));
00567 buf->bitstream_length = size;
00568 buf->streamBuffer = payload;
00569 buf->frame_bitoffset = 0;
00570
00571 UsedBits = 0;
00572
00573 sub_seq_layer_num = ue_v("SEI: sub_seq_layer_num", buf);
00574 sub_seq_id = ue_v("SEI: sub_seq_id", buf);
00575 duration_flag = u_1 ("SEI: duration_flag", buf);
00576
00577 #ifdef PRINT_SUBSEQUENCE_CHAR
00578 printf("Sub-sequence characteristics SEI message\n");
00579 printf("sub_seq_layer_num = %d\n", sub_seq_layer_num );
00580 printf("sub_seq_id = %d\n", sub_seq_id);
00581 printf("duration_flag = %d\n", duration_flag);
00582 #endif
00583
00584 if ( duration_flag )
00585 {
00586 sub_seq_duration = u_v (32, "SEI: duration_flag", buf);
00587 #ifdef PRINT_SUBSEQUENCE_CHAR
00588 printf("sub_seq_duration = %ld\n", sub_seq_duration);
00589 #endif
00590 }
00591
00592 average_rate_flag = u_1 ("SEI: average_rate_flag", buf);
00593
00594 #ifdef PRINT_SUBSEQUENCE_CHAR
00595 printf("average_rate_flag = %d\n", average_rate_flag);
00596 #endif
00597
00598 if ( average_rate_flag )
00599 {
00600 accurate_statistics_flag = u_1 ( "SEI: accurate_statistics_flag", buf);
00601 average_bit_rate = u_v (16, "SEI: average_bit_rate", buf);
00602 average_frame_rate = u_v (16, "SEI: average_frame_rate", buf);
00603
00604 #ifdef PRINT_SUBSEQUENCE_CHAR
00605 printf("accurate_statistics_flag = %d\n", accurate_statistics_flag);
00606 printf("average_bit_rate = %ld\n", average_bit_rate);
00607 printf("average_frame_rate = %ld\n", average_frame_rate);
00608 #endif
00609 }
00610
00611 num_referenced_subseqs = ue_v("SEI: num_referenced_subseqs", buf);
00612
00613 #ifdef PRINT_SUBSEQUENCE_CHAR
00614 printf("num_referenced_subseqs = %d\n", num_referenced_subseqs);
00615 #endif
00616
00617 for (i=0; i<num_referenced_subseqs; i++)
00618 {
00619 ref_sub_seq_layer_num = ue_v("SEI: ref_sub_seq_layer_num", buf);
00620 ref_sub_seq_id = ue_v("SEI: ref_sub_seq_id", buf);
00621 ref_sub_seq_direction = u_1 ("SEI: ref_sub_seq_direction", buf);
00622
00623 #ifdef PRINT_SUBSEQUENCE_CHAR
00624 printf("ref_sub_seq_layer_num = %d\n", ref_sub_seq_layer_num);
00625 printf("ref_sub_seq_id = %d\n", ref_sub_seq_id);
00626 printf("ref_sub_seq_direction = %d\n", ref_sub_seq_direction);
00627 #endif
00628 }
00629
00630 free( buf );
00631 #ifdef PRINT_SUBSEQUENCE_CHAR
00632 #undef PRINT_SUBSEQUENCE_CHAR
00633 #endif
00634 }
00635
00636
00650 void interpret_scene_information( byte* payload, int size, ImageParameters *img )
00651 {
00652 Bitstream* buf;
00653 int scene_id, scene_transition_type, second_scene_id;
00654
00655 buf = malloc(sizeof(Bitstream));
00656 buf->bitstream_length = size;
00657 buf->streamBuffer = payload;
00658 buf->frame_bitoffset = 0;
00659
00660 UsedBits = 0;
00661
00662 scene_id = ue_v("SEI: scene_id" , buf);
00663 scene_transition_type = ue_v("SEI: scene_transition_type", buf);
00664 if ( scene_transition_type > 3 )
00665 {
00666 second_scene_id = ue_v("SEI: scene_transition_type", buf);;
00667 }
00668
00669 #ifdef PRINT_SCENE_INFORMATION
00670 printf("Scene information SEI message\n");
00671 printf("scene_transition_type = %d\n", scene_transition_type);
00672 printf("scene_id = %d\n", scene_id);
00673 if ( scene_transition_type > 3 )
00674 {
00675 printf("second_scene_id = %d\n", second_scene_id);
00676 }
00677 #endif
00678 free( buf );
00679 #ifdef PRINT_SCENE_INFORMATION
00680 #undef PRINT_SCENE_INFORMATION
00681 #endif
00682 }
00683
00684
00698 void interpret_filler_payload_info( byte* payload, int size, ImageParameters *img )
00699 {
00700 int payload_cnt = 0;
00701
00702 while (payload_cnt<size)
00703 {
00704 if (payload[payload_cnt] == 0xFF)
00705 {
00706 payload_cnt++;
00707 }
00708 }
00709
00710
00711 #ifdef PRINT_FILLER_PAYLOAD_INFO
00712 printf("Filler payload SEI message\n");
00713 if (payload_cnt==size)
00714 {
00715 printf("read %d bytes of filler payload\n", payload_cnt);
00716 }
00717 else
00718 {
00719 printf("error reading filler payload: not all bytes are 0xFF (%d of %d)\n", payload_cnt, size);
00720 }
00721 #endif
00722
00723 #ifdef PRINT_FILLER_PAYLOAD_INFO
00724 #undef PRINT_FILLER_PAYLOAD_INFO
00725 #endif
00726 }
00727
00728
00742 void interpret_user_data_unregistered_info( byte* payload, int size, ImageParameters *img )
00743 {
00744 int offset = 0;
00745 byte payload_byte;
00746
00747 #ifdef PRINT_USER_DATA_UNREGISTERED_INFO
00748 printf("User data unregistered SEI message\n");
00749 printf("uuid_iso_11578 = 0x");
00750 #endif
00751 assert (size>=16);
00752
00753 for (offset = 0; offset < 16; offset++)
00754 {
00755 #ifdef PRINT_USER_DATA_UNREGISTERED_INFO
00756 printf("%02x",payload[offset]);
00757 #endif
00758 }
00759
00760 #ifdef PRINT_USER_DATA_UNREGISTERED_INFO
00761 printf("\n");
00762 #endif
00763
00764 while (offset < size)
00765 {
00766 payload_byte = payload[offset];
00767 offset ++;
00768 #ifdef PRINT_USER_DATA_UNREGISTERED_INFO
00769 printf("Unreg data payload_byte = %d\n", payload_byte);
00770 #endif
00771 }
00772 #ifdef PRINT_USER_DATA_UNREGISTERED_INFO
00773 #undef PRINT_USER_DATA_UNREGISTERED_INFO
00774 #endif
00775 }
00776
00777
00791 void interpret_user_data_registered_itu_t_t35_info( byte* payload, int size, ImageParameters *img )
00792 {
00793 int offset = 0;
00794 byte itu_t_t35_country_code, itu_t_t35_country_code_extension_byte, payload_byte;
00795
00796 itu_t_t35_country_code = payload[offset];
00797 offset++;
00798 #ifdef PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO
00799 printf("User data registered by ITU-T T.35 SEI message\n");
00800 printf(" itu_t_t35_country_code = %d \n", itu_t_t35_country_code);
00801 #endif
00802 if(itu_t_t35_country_code == 0xFF)
00803 {
00804 itu_t_t35_country_code_extension_byte = payload[offset];
00805 offset++;
00806 #ifdef PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO
00807 printf(" ITU_T_T35_COUNTRY_CODE_EXTENSION_BYTE %d \n", itu_t_t35_country_code_extension_byte);
00808 #endif
00809 }
00810 while (offset < size)
00811 {
00812 payload_byte = payload[offset];
00813 offset ++;
00814 #ifdef PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO
00815 printf("itu_t_t35 payload_byte = %d\n", payload_byte);
00816 #endif
00817 }
00818 #ifdef PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO
00819 #undef PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO
00820 #endif
00821 }
00822
00823
00837 void interpret_pan_scan_rect_info( byte* payload, int size, ImageParameters *img )
00838 {
00839 int pan_scan_rect_cancel_flag;
00840 int pan_scan_cnt_minus1, i;
00841 int pan_scan_rect_repetition_period;
00842 int pan_scan_rect_id, pan_scan_rect_left_offset, pan_scan_rect_right_offset;
00843 int pan_scan_rect_top_offset, pan_scan_rect_bottom_offset;
00844
00845 Bitstream* buf;
00846
00847 buf = malloc(sizeof(Bitstream));
00848 buf->bitstream_length = size;
00849 buf->streamBuffer = payload;
00850 buf->frame_bitoffset = 0;
00851
00852 UsedBits = 0;
00853
00854 pan_scan_rect_id = ue_v("SEI: pan_scan_rect_id", buf);
00855
00856 pan_scan_rect_cancel_flag = u_1("SEI: pan_scan_rect_cancel_flag", buf);
00857 if (!pan_scan_rect_cancel_flag)
00858 {
00859 pan_scan_cnt_minus1 = ue_v("SEI: pan_scan_cnt_minus1", buf);
00860 for (i = 0; i <= pan_scan_cnt_minus1; i++)
00861 {
00862 pan_scan_rect_left_offset = se_v("SEI: pan_scan_rect_left_offset" , buf);
00863 pan_scan_rect_right_offset = se_v("SEI: pan_scan_rect_right_offset" , buf);
00864 pan_scan_rect_top_offset = se_v("SEI: pan_scan_rect_top_offset" , buf);
00865 pan_scan_rect_bottom_offset = se_v("SEI: pan_scan_rect_bottom_offset", buf);
00866 #ifdef PRINT_PAN_SCAN_RECT
00867 printf("Pan scan rectangle SEI message %d/%d\n", i, pan_scan_cnt_minus1);
00868 printf("pan_scan_rect_id = %d\n", pan_scan_rect_id);
00869 printf("pan_scan_rect_left_offset = %d\n", pan_scan_rect_left_offset);
00870 printf("pan_scan_rect_right_offset = %d\n", pan_scan_rect_right_offset);
00871 printf("pan_scan_rect_top_offset = %d\n", pan_scan_rect_top_offset);
00872 printf("pan_scan_rect_bottom_offset = %d\n", pan_scan_rect_bottom_offset);
00873 #endif
00874 }
00875 pan_scan_rect_repetition_period = ue_v("SEI: pan_scan_rect_repetition_period", buf);
00876 }
00877
00878 free (buf);
00879 #ifdef PRINT_PAN_SCAN_RECT
00880 #undef PRINT_PAN_SCAN_RECT
00881 #endif
00882 }
00883
00884
00898 void interpret_recovery_point_info( byte* payload, int size, ImageParameters *img )
00899 {
00900 int recovery_frame_cnt, exact_match_flag, broken_link_flag, changing_slice_group_idc;
00901
00902
00903 Bitstream* buf;
00904
00905
00906 buf = malloc(sizeof(Bitstream));
00907 buf->bitstream_length = size;
00908 buf->streamBuffer = payload;
00909 buf->frame_bitoffset = 0;
00910
00911 UsedBits = 0;
00912
00913 recovery_frame_cnt = ue_v( "SEI: recovery_frame_cnt" , buf);
00914 exact_match_flag = u_1 ( "SEI: exact_match_flag" , buf);
00915 broken_link_flag = u_1 ( "SEI: broken_link_flag" , buf);
00916 changing_slice_group_idc = u_v ( 2, "SEI: changing_slice_group_idc", buf);
00917
00918 img->recovery_point = 1;
00919 img->recovery_frame_cnt = recovery_frame_cnt;
00920
00921 #ifdef PRINT_RECOVERY_POINT
00922 printf("Recovery point SEI message\n");
00923 printf("recovery_frame_cnt = %d\n", recovery_frame_cnt);
00924 printf("exact_match_flag = %d\n", exact_match_flag);
00925 printf("broken_link_flag = %d\n", broken_link_flag);
00926 printf("changing_slice_group_idc = %d\n", changing_slice_group_idc);
00927 #endif
00928 free (buf);
00929 #ifdef PRINT_RECOVERY_POINT
00930 #undef PRINT_RECOVERY_POINT
00931 #endif
00932 }
00933
00934
00948 void interpret_dec_ref_pic_marking_repetition_info( byte* payload, int size, ImageParameters *img )
00949 {
00950 int original_idr_flag, original_frame_num;
00951 int original_field_pic_flag, original_bottom_field_flag;
00952
00953 DecRefPicMarking_t *tmp_drpm;
00954
00955 DecRefPicMarking_t *old_drpm;
00956 int old_idr_flag , old_no_output_of_prior_pics_flag, old_long_term_reference_flag , old_adaptive_ref_pic_buffering_flag;
00957
00958
00959 Bitstream* buf;
00960
00961 buf = malloc(sizeof(Bitstream));
00962 buf->bitstream_length = size;
00963 buf->streamBuffer = payload;
00964 buf->frame_bitoffset = 0;
00965
00966 UsedBits = 0;
00967
00968 original_idr_flag = u_1 ( "SEI: original_idr_flag" , buf);
00969 original_frame_num = ue_v( "SEI: original_frame_num" , buf);
00970
00971 if ( !active_sps->frame_mbs_only_flag )
00972 {
00973 original_field_pic_flag = u_1 ( "SEI: original_field_pic_flag", buf);
00974 if ( original_field_pic_flag )
00975 {
00976 original_bottom_field_flag = u_1 ( "SEI: original_bottom_field_flag", buf);
00977 }
00978 }
00979
00980 #ifdef PRINT_DEC_REF_PIC_MARKING
00981 printf("Decoded Picture Buffer Management Repetition SEI message\n");
00982 printf("original_idr_flag = %d\n", original_idr_flag);
00983 printf("original_frame_num = %d\n", original_frame_num);
00984 if ( active_sps->frame_mbs_only_flag )
00985 {
00986 printf("original_field_pic_flag = %d\n", original_field_pic_flag);
00987 if ( original_field_pic_flag )
00988 {
00989 printf("original_bottom_field_flag = %d\n", original_bottom_field_flag);
00990 }
00991 }
00992 #endif
00993
00994
00995 old_drpm = img->dec_ref_pic_marking_buffer;
00996 old_idr_flag = img->idr_flag;
00997
00998 old_no_output_of_prior_pics_flag = img->no_output_of_prior_pics_flag;
00999 old_long_term_reference_flag = img->long_term_reference_flag;
01000 old_adaptive_ref_pic_buffering_flag = img->adaptive_ref_pic_buffering_flag;
01001
01002
01003 img->idr_flag = original_idr_flag;
01004 img->dec_ref_pic_marking_buffer = NULL;
01005
01006 dec_ref_pic_marking(buf);
01007
01008
01009 #ifdef PRINT_DEC_REF_PIC_MARKING
01010 if (img->idr_flag)
01011 {
01012 printf("no_output_of_prior_pics_flag = %d\n", img->no_output_of_prior_pics_flag);
01013 printf("long_term_reference_flag = %d\n", img->long_term_reference_flag);
01014 }
01015 else
01016 {
01017 printf("adaptive_ref_pic_buffering_flag = %d\n", img->adaptive_ref_pic_buffering_flag);
01018 if (img->adaptive_ref_pic_buffering_flag)
01019 {
01020 tmp_drpm=img->dec_ref_pic_marking_buffer;
01021 while (tmp_drpm != NULL)
01022 {
01023 printf("memory_management_control_operation = %d\n", tmp_drpm->memory_management_control_operation);
01024
01025 if ((tmp_drpm->memory_management_control_operation==1)||(tmp_drpm->memory_management_control_operation==3))
01026 {
01027 printf("difference_of_pic_nums_minus1 = %d\n", tmp_drpm->difference_of_pic_nums_minus1);
01028 }
01029 if (tmp_drpm->memory_management_control_operation==2)
01030 {
01031 printf("long_term_pic_num = %d\n", tmp_drpm->long_term_pic_num);
01032 }
01033 if ((tmp_drpm->memory_management_control_operation==3)||(tmp_drpm->memory_management_control_operation==6))
01034 {
01035 printf("long_term_frame_idx = %d\n", tmp_drpm->long_term_frame_idx);
01036 }
01037 if (tmp_drpm->memory_management_control_operation==4)
01038 {
01039 printf("max_long_term_pic_idx_plus1 = %d\n", tmp_drpm->max_long_term_frame_idx_plus1);
01040 }
01041 tmp_drpm = tmp_drpm->Next;
01042 }
01043 }
01044 }
01045 #endif
01046
01047 while (img->dec_ref_pic_marking_buffer)
01048 {
01049 tmp_drpm=img->dec_ref_pic_marking_buffer;
01050
01051 img->dec_ref_pic_marking_buffer=tmp_drpm->Next;
01052 free (tmp_drpm);
01053 }
01054
01055
01056 img->dec_ref_pic_marking_buffer = old_drpm;
01057 img->idr_flag = old_idr_flag;
01058 img->no_output_of_prior_pics_flag = old_no_output_of_prior_pics_flag;
01059 img->long_term_reference_flag = old_long_term_reference_flag;
01060 img->adaptive_ref_pic_buffering_flag = old_adaptive_ref_pic_buffering_flag;
01061
01062 free (buf);
01063 #ifdef PRINT_DEC_REF_PIC_MARKING
01064 #undef PRINT_DEC_REF_PIC_MARKING
01065 #endif
01066 }
01067
01081 void interpret_full_frame_freeze_info( byte* payload, int size, ImageParameters *img )
01082 {
01083 int full_frame_freeze_repetition_period;
01084 Bitstream* buf;
01085
01086 buf = malloc(sizeof(Bitstream));
01087 buf->bitstream_length = size;
01088 buf->streamBuffer = payload;
01089 buf->frame_bitoffset = 0;
01090
01091 full_frame_freeze_repetition_period = ue_v( "SEI: full_frame_freeze_repetition_period" , buf);
01092
01093 #ifdef PRINT_FULL_FRAME_FREEZE_INFO
01094 printf("full_frame_freeze_repetition_period = %d\n", full_frame_freeze_repetition_period);
01095 #endif
01096
01097 free (buf);
01098 #ifdef PRINT_FULL_FRAME_FREEZE_INFO
01099 #undef PRINT_FULL_FRAME_FREEZE_INFO
01100 #endif
01101 }
01102
01103
01117 void interpret_full_frame_freeze_release_info( byte* payload, int size, ImageParameters *img )
01118 {
01119 #ifdef PRINT_FULL_FRAME_FREEZE_RELEASE_INFO
01120 printf("Full-frame freeze release SEI message\n");
01121 if (size)
01122 {
01123 printf("payload size of this message should be zero, but is %d bytes.\n", size);
01124 }
01125 #endif
01126
01127 #ifdef PRINT_FULL_FRAME_FREEZE_RELEASE_INFO
01128 #undef PRINT_FULL_FRAME_FREEZE_RELEASE_INFO
01129 #endif
01130 }
01131
01145 void interpret_full_frame_snapshot_info( byte* payload, int size, ImageParameters *img )
01146 {
01147 int snapshot_id;
01148
01149 Bitstream* buf;
01150
01151 buf = malloc(sizeof(Bitstream));
01152 buf->bitstream_length = size;
01153 buf->streamBuffer = payload;
01154 buf->frame_bitoffset = 0;
01155
01156 UsedBits = 0;
01157
01158 snapshot_id = ue_v("SEI: snapshot_id", buf);
01159
01160 #ifdef PRINT_FULL_FRAME_SNAPSHOT_INFO
01161 printf("Full-frame snapshot SEI message\n");
01162 printf("snapshot_id = %d\n", snapshot_id);
01163 #endif
01164 free (buf);
01165 #ifdef PRINT_FULL_FRAME_SNAPSHOT_INFO
01166 #undef PRINT_FULL_FRAME_SNAPSHOT_INFO
01167 #endif
01168 }
01169
01183 void interpret_progressive_refinement_start_info( byte* payload, int size, ImageParameters *img )
01184 {
01185 int progressive_refinement_id, num_refinement_steps_minus1;
01186
01187 Bitstream* buf;
01188
01189 buf = malloc(sizeof(Bitstream));
01190 buf->bitstream_length = size;
01191 buf->streamBuffer = payload;
01192 buf->frame_bitoffset = 0;
01193
01194 UsedBits = 0;
01195
01196 progressive_refinement_id = ue_v("SEI: progressive_refinement_id" , buf);
01197 num_refinement_steps_minus1 = ue_v("SEI: num_refinement_steps_minus1", buf);
01198
01199 #ifdef PRINT_PROGRESSIVE_REFINEMENT_START_INFO
01200 printf("Progressive refinement segment start SEI message\n");
01201 printf("progressive_refinement_id = %d\n", progressive_refinement_id);
01202 printf("num_refinement_steps_minus1 = %d\n", num_refinement_steps_minus1);
01203 #endif
01204 free (buf);
01205 #ifdef PRINT_PROGRESSIVE_REFINEMENT_START_INFO
01206 #undef PRINT_PROGRESSIVE_REFINEMENT_START_INFO
01207 #endif
01208 }
01209
01210
01224 void interpret_progressive_refinement_end_info( byte* payload, int size, ImageParameters *img )
01225 {
01226 int progressive_refinement_id;
01227
01228 Bitstream* buf;
01229
01230 buf = malloc(sizeof(Bitstream));
01231 buf->bitstream_length = size;
01232 buf->streamBuffer = payload;
01233 buf->frame_bitoffset = 0;
01234
01235 UsedBits = 0;
01236
01237 progressive_refinement_id = ue_v("SEI: progressive_refinement_id" , buf);
01238
01239 #ifdef PRINT_PROGRESSIVE_REFINEMENT_END_INFO
01240 printf("Progressive refinement segment end SEI message\n");
01241 printf("progressive_refinement_id = %d\n", progressive_refinement_id);
01242 #endif
01243 free (buf);
01244 #ifdef PRINT_PROGRESSIVE_REFINEMENT_END_INFO
01245 #undef PRINT_PROGRESSIVE_REFINEMENT_END_INFO
01246 #endif
01247 }
01248
01249
01263 void interpret_motion_constrained_slice_group_set_info( byte* payload, int size, ImageParameters *img )
01264 {
01265 int num_slice_groups_minus1, slice_group_id, exact_match_flag, pan_scan_rect_flag, pan_scan_rect_id;
01266 int i;
01267 int sliceGroupSize;
01268
01269 Bitstream* buf;
01270
01271 buf = malloc(sizeof(Bitstream));
01272 buf->bitstream_length = size;
01273 buf->streamBuffer = payload;
01274 buf->frame_bitoffset = 0;
01275
01276 UsedBits = 0;
01277
01278 num_slice_groups_minus1 = ue_v("SEI: num_slice_groups_minus1" , buf);
01279 sliceGroupSize = CeilLog2( num_slice_groups_minus1 + 1 );
01280 #ifdef PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO
01281 printf("Motion-constrained slice group set SEI message\n");
01282 printf("num_slice_groups_minus1 = %d\n", num_slice_groups_minus1);
01283 #endif
01284
01285 for (i=0; i<=num_slice_groups_minus1;i++)
01286 {
01287
01288 slice_group_id = u_v (sliceGroupSize, "SEI: slice_group_id" , buf) ;
01289 #ifdef PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO
01290 printf("slice_group_id = %d\n", slice_group_id);
01291 #endif
01292 }
01293
01294 exact_match_flag = u_1("SEI: exact_match_flag" , buf);
01295 pan_scan_rect_flag = u_1("SEI: pan_scan_rect_flag" , buf);
01296
01297 #ifdef PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO
01298 printf("exact_match_flag = %d\n", exact_match_flag);
01299 printf("pan_scan_rect_flag = %d\n", pan_scan_rect_flag);
01300 #endif
01301
01302 if (pan_scan_rect_flag)
01303 {
01304 pan_scan_rect_id = ue_v("SEI: pan_scan_rect_id" , buf);
01305 #ifdef PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO
01306 printf("pan_scan_rect_id = %d\n", pan_scan_rect_id);
01307 #endif
01308 }
01309
01310 free (buf);
01311 #ifdef PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO
01312 #undef PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO
01313 #endif
01314 }
01315
01329 void interpret_film_grain_characteristics_info( byte* payload, int size, ImageParameters *img )
01330 {
01331 int film_grain_characteristics_cancel_flag;
01332 int model_id, separate_colour_description_present_flag;
01333 int film_grain_bit_depth_luma_minus8, film_grain_bit_depth_chroma_minus8, film_grain_full_range_flag, film_grain_colour_primaries, film_grain_transfer_characteristics, film_grain_matrix_coefficients;
01334 int blending_mode_id, log2_scale_factor, comp_model_present_flag[3];
01335 int num_intensity_intervals_minus1, num_model_values_minus1;
01336 int intensity_interval_lower_bound, intensity_interval_upper_bound;
01337 int comp_model_value;
01338 int film_grain_characteristics_repetition_period;
01339
01340 int c, i, j;
01341
01342 Bitstream* buf;
01343
01344 buf = malloc(sizeof(Bitstream));
01345 buf->bitstream_length = size;
01346 buf->streamBuffer = payload;
01347 buf->frame_bitoffset = 0;
01348
01349 film_grain_characteristics_cancel_flag = u_1("SEI: film_grain_characteristics_cancel_flag", buf);
01350 #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO
01351 printf("film_grain_characteristics_cancel_flag = %d\n", film_grain_characteristics_cancel_flag);
01352 #endif
01353 if(!film_grain_characteristics_cancel_flag)
01354 {
01355
01356 model_id = u_v(2, "SEI: model_id", buf);
01357 separate_colour_description_present_flag = u_1("SEI: separate_colour_description_present_flag", buf);
01358 #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO
01359 printf("model_id = %d\n", model_id);
01360 printf("separate_colour_description_present_flag = %d\n", separate_colour_description_present_flag);
01361 #endif
01362 if (separate_colour_description_present_flag)
01363 {
01364 film_grain_bit_depth_luma_minus8 = u_v(3, "SEI: film_grain_bit_depth_luma_minus8", buf);
01365 film_grain_bit_depth_chroma_minus8 = u_v(3, "SEI: film_grain_bit_depth_chroma_minus8", buf);
01366 film_grain_full_range_flag = u_v(1, "SEI: film_grain_full_range_flag", buf);
01367 film_grain_colour_primaries = u_v(8, "SEI: film_grain_colour_primaries", buf);
01368 film_grain_transfer_characteristics = u_v(8, "SEI: film_grain_transfer_characteristics", buf);
01369 film_grain_matrix_coefficients = u_v(8, "SEI: film_grain_matrix_coefficients", buf);
01370 #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO
01371 printf("film_grain_bit_depth_luma_minus8 = %d\n", film_grain_bit_depth_luma_minus8);
01372 printf("film_grain_bit_depth_chroma_minus8 = %d\n", film_grain_bit_depth_chroma_minus8);
01373 printf("film_grain_full_range_flag = %d\n", film_grain_full_range_flag);
01374 printf("film_grain_colour_primaries = %d\n", film_grain_colour_primaries);
01375 printf("film_grain_transfer_characteristics = %d\n", film_grain_transfer_characteristics);
01376 printf("film_grain_matrix_coefficients = %d\n", film_grain_matrix_coefficients);
01377 #endif
01378 }
01379 blending_mode_id = u_v(2, "SEI: blending_mode_id", buf);
01380 log2_scale_factor = u_v(4, "SEI: log2_scale_factor", buf);
01381 #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO
01382 printf("blending_mode_id = %d\n", blending_mode_id);
01383 printf("log2_scale_factor = %d\n", log2_scale_factor);
01384 #endif
01385 for (c = 0; c < 3; c ++)
01386 {
01387 comp_model_present_flag[c] = u_1("SEI: comp_model_present_flag", buf);
01388 #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO
01389 printf("comp_model_present_flag = %d\n", comp_model_present_flag[c]);
01390 #endif
01391 }
01392 for (c = 0; c < 3; c ++)
01393 if (comp_model_present_flag[c])
01394 {
01395 num_intensity_intervals_minus1 = u_v(8, "SEI: num_intensity_intervals_minus1", buf);
01396 num_model_values_minus1 = u_v(3, "SEI: num_model_values_minus1", buf);
01397 #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO
01398 printf("num_intensity_intervals_minus1 = %d\n", num_intensity_intervals_minus1);
01399 printf("num_model_values_minus1 = %d\n", num_model_values_minus1);
01400 #endif
01401 for (i = 0; i <= num_intensity_intervals_minus1; i ++)
01402 {
01403 intensity_interval_lower_bound = u_v(8, "SEI: intensity_interval_lower_bound", buf);
01404 intensity_interval_upper_bound = u_v(8, "SEI: intensity_interval_upper_bound", buf);
01405 #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO
01406 printf("intensity_interval_lower_bound = %d\n", intensity_interval_lower_bound);
01407 printf("intensity_interval_upper_bound = %d\n", intensity_interval_upper_bound);
01408 #endif
01409 for (j = 0; j <= num_model_values_minus1; j++)
01410 {
01411 comp_model_value = se_v("SEI: comp_model_value", buf);
01412 #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO
01413 printf("comp_model_value = %d\n", comp_model_value);
01414 #endif
01415 }
01416 }
01417 }
01418 film_grain_characteristics_repetition_period = ue_v("SEI: film_grain_characteristics_repetition_period", buf);
01419 #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO
01420 printf("film_grain_characteristics_repetition_period = %d\n", film_grain_characteristics_repetition_period);
01421 #endif
01422 }
01423
01424 free (buf);
01425 #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO
01426 #undef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO
01427 #endif
01428 }
01429
01443 void interpret_deblocking_filter_display_preference_info( byte* payload, int size, ImageParameters *img )
01444 {
01445 int deblocking_display_preference_cancel_flag;
01446 int display_prior_to_deblocking_preferred_flag, dec_frame_buffering_constraint_flag, deblocking_display_preference_repetition_period;
01447
01448 Bitstream* buf;
01449
01450 buf = malloc(sizeof(Bitstream));
01451 buf->bitstream_length = size;
01452 buf->streamBuffer = payload;
01453 buf->frame_bitoffset = 0;
01454
01455 deblocking_display_preference_cancel_flag = u_1("SEI: deblocking_display_preference_cancel_flag", buf);
01456 #ifdef PRINT_DEBLOCKING_FILTER_DISPLAY_PREFERENCE_INFO
01457 printf("deblocking_display_preference_cancel_flag = %d\n", deblocking_display_preference_cancel_flag);
01458 #endif
01459 if(!deblocking_display_preference_cancel_flag)
01460 {
01461 display_prior_to_deblocking_preferred_flag = u_1("SEI: display_prior_to_deblocking_preferred_flag", buf);
01462 dec_frame_buffering_constraint_flag = u_1("SEI: dec_frame_buffering_constraint_flag", buf);
01463 deblocking_display_preference_repetition_period = ue_v("SEI: deblocking_display_preference_repetition_period", buf);
01464 #ifdef PRINT_DEBLOCKING_FILTER_DISPLAY_PREFERENCE_INFO
01465 printf("display_prior_to_deblocking_preferred_flag = %d\n", display_prior_to_deblocking_preferred_flag);
01466 printf("dec_frame_buffering_constraint_flag = %d\n", dec_frame_buffering_constraint_flag);
01467 printf("deblocking_display_preference_repetition_period = %d\n", deblocking_display_preference_repetition_period);
01468 #endif
01469 }
01470
01471 free (buf);
01472 #ifdef PRINT_DEBLOCKING_FILTER_DISPLAY_PREFERENCE_INFO
01473 #undef PRINT_DEBLOCKING_FILTER_DISPLAY_PREFERENCE_INFO
01474 #endif
01475 }
01476
01490 void interpret_stereo_video_info_info( byte* payload, int size, ImageParameters *img )
01491 {
01492 int field_views_flags;
01493 int top_field_is_left_view_flag, current_frame_is_left_view_flag, next_frame_is_second_view_flag;
01494 int left_view_self_contained_flag;
01495 int right_view_self_contained_flag;
01496
01497 Bitstream* buf;
01498
01499 buf = malloc(sizeof(Bitstream));
01500 buf->bitstream_length = size;
01501 buf->streamBuffer = payload;
01502 buf->frame_bitoffset = 0;
01503
01504 field_views_flags = u_1("SEI: field_views_flags", buf);
01505 #ifdef PRINT_STEREO_VIDEO_INFO_INFO
01506 printf("field_views_flags = %d\n", field_views_flags);
01507 #endif
01508 if (field_views_flags)
01509 {
01510 top_field_is_left_view_flag = u_1("SEI: top_field_is_left_view_flag", buf);
01511 #ifdef PRINT_STEREO_VIDEO_INFO_INFO
01512 printf("top_field_is_left_view_flag = %d\n", top_field_is_left_view_flag);
01513 #endif
01514 }
01515 else
01516 {
01517 current_frame_is_left_view_flag = u_1("SEI: current_frame_is_left_view_flag", buf);
01518 next_frame_is_second_view_flag = u_1("SEI: next_frame_is_second_view_flag", buf);
01519 #ifdef PRINT_STEREO_VIDEO_INFO_INFO
01520 printf("current_frame_is_left_view_flag = %d\n", current_frame_is_left_view_flag);
01521 printf("next_frame_is_second_view_flag = %d\n", next_frame_is_second_view_flag);
01522 #endif
01523 }
01524
01525 left_view_self_contained_flag = u_1("SEI: left_view_self_contained_flag", buf);
01526 right_view_self_contained_flag = u_1("SEI: right_view_self_contained_flag", buf);
01527 #ifdef PRINT_STEREO_VIDEO_INFO_INFO
01528 printf("left_view_self_contained_flag = %d\n", left_view_self_contained_flag);
01529 printf("right_view_self_contained_flag = %d\n", right_view_self_contained_flag);
01530 #endif
01531
01532 free (buf);
01533 #ifdef PRINT_STEREO_VIDEO_INFO_INFO
01534 #undef PRINT_STEREO_VIDEO_INFO_INFO
01535 #endif
01536 }
01537
01551 void interpret_reserved_info( byte* payload, int size, ImageParameters *img )
01552 {
01553 int offset = 0;
01554 byte payload_byte;
01555
01556 #ifdef PRINT_RESERVED_INFO
01557 printf("Reserved SEI message\n");
01558 #endif
01559
01560 while (offset < size)
01561 {
01562 payload_byte = payload[offset];
01563 offset ++;
01564 #ifdef PRINT_RESERVED_INFO
01565 printf("reserved_sei_message_payload_byte = %d\n", payload_byte);
01566 #endif
01567 }
01568 #ifdef PRINT_RESERVED_INFO
01569 #undef PRINT_RESERVED_INFO
01570 #endif
01571 }
01572
01573
01587 void interpret_buffering_period_info( byte* payload, int size, ImageParameters *img )
01588 {
01589 int seq_parameter_set_id, initial_cpb_removal_delay, initial_cpb_removal_delay_offset;
01590 unsigned int k;
01591
01592 Bitstream* buf;
01593 seq_parameter_set_rbsp_t *sps;
01594
01595
01596 buf = malloc(sizeof(Bitstream));
01597 buf->bitstream_length = size;
01598 buf->streamBuffer = payload;
01599 buf->frame_bitoffset = 0;
01600
01601 UsedBits = 0;
01602
01603 seq_parameter_set_id = ue_v("SEI: seq_parameter_set_id" , buf);
01604
01605 sps = &SeqParSet[seq_parameter_set_id];
01606
01607 activate_sps(sps);
01608
01609 #ifdef PRINT_BUFFERING_PERIOD_INFO
01610 printf("Buffering period SEI message\n");
01611 printf("seq_parameter_set_id = %d\n", seq_parameter_set_id);
01612 #endif
01613
01614
01615 if (sps->vui_parameters_present_flag)
01616 {
01617
01618 if (sps->vui_seq_parameters.nal_hrd_parameters_present_flag)
01619 {
01620 for (k=0; k<sps->vui_seq_parameters.nal_hrd_parameters.cpb_cnt_minus1+1; k++)
01621 {
01622 initial_cpb_removal_delay = u_v(sps->vui_seq_parameters.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1+1, "SEI: initial_cpb_removal_delay" , buf);
01623 initial_cpb_removal_delay_offset = u_v(sps->vui_seq_parameters.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1+1, "SEI: initial_cpb_removal_delay_offset" , buf);
01624
01625 #ifdef PRINT_BUFFERING_PERIOD_INFO
01626 printf("nal initial_cpb_removal_delay[%d] = %d\n", k, initial_cpb_removal_delay);
01627 printf("nal initial_cpb_removal_delay_offset[%d] = %d\n", k, initial_cpb_removal_delay_offset);
01628 #endif
01629 }
01630 }
01631
01632 if (sps->vui_seq_parameters.vcl_hrd_parameters_present_flag)
01633 {
01634 for (k=0; k<sps->vui_seq_parameters.vcl_hrd_parameters.cpb_cnt_minus1+1; k++)
01635 {
01636 initial_cpb_removal_delay = u_v(sps->vui_seq_parameters.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1+1, "SEI: initial_cpb_removal_delay" , buf);
01637 initial_cpb_removal_delay_offset = u_v(sps->vui_seq_parameters.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1+1, "SEI: initial_cpb_removal_delay_offset" , buf);
01638
01639 #ifdef PRINT_BUFFERING_PERIOD_INFO
01640 printf("vcl initial_cpb_removal_delay[%d] = %d\n", k, initial_cpb_removal_delay);
01641 printf("vcl initial_cpb_removal_delay_offset[%d] = %d\n", k, initial_cpb_removal_delay_offset);
01642 #endif
01643 }
01644 }
01645 }
01646
01647 free (buf);
01648 #ifdef PRINT_BUFFERING_PERIOD_INFO
01649 #undef PRINT_BUFFERING_PERIOD_INFO
01650 #endif
01651 }
01652
01653
01667 void interpret_picture_timing_info( byte* payload, int size, ImageParameters *img )
01668 {
01669 int cpb_removal_delay, dpb_output_delay, picture_structure_present_flag, picture_structure;
01670 int clock_time_stamp_flag;
01671 int ct_type, nuit_field_based_flag, counting_type, full_timestamp_flag, discontinuity_flag, cnt_dropped_flag, nframes;
01672 int seconds_value, minutes_value, hours_value, seconds_flag, minutes_flag, hours_flag, time_offset;
01673 int NumClockTs = 0;
01674 int i;
01675
01676 int cpb_removal_len = 24;
01677 int dpb_output_len = 24;
01678
01679 Boolean CpbDpbDelaysPresentFlag;
01680
01681 Bitstream* buf;
01682
01683 if (NULL==active_sps)
01684 {
01685 fprintf (stderr, "Warning: no active SPS, timing SEI cannot be parsed\n");
01686 return;
01687 }
01688
01689 buf = malloc(sizeof(Bitstream));
01690 buf->bitstream_length = size;
01691 buf->streamBuffer = payload;
01692 buf->frame_bitoffset = 0;
01693
01694 UsedBits = 0;
01695
01696
01697 #ifdef PRINT_PCITURE_TIMING_INFO
01698 printf("Picture timing SEI message\n");
01699 #endif
01700
01701
01702 CpbDpbDelaysPresentFlag = (Boolean) (active_sps->vui_parameters_present_flag
01703 && ( (active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag != 0)
01704 ||(active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag != 0)));
01705
01706 if (CpbDpbDelaysPresentFlag )
01707 {
01708 if (active_sps->vui_parameters_present_flag)
01709 {
01710 if (active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag)
01711 {
01712 cpb_removal_len = active_sps->vui_seq_parameters.nal_hrd_parameters.cpb_removal_delay_length_minus1 + 1;
01713 dpb_output_len = active_sps->vui_seq_parameters.nal_hrd_parameters.dpb_output_delay_length_minus1 + 1;
01714 }
01715 else if (active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag)
01716 {
01717 cpb_removal_len = active_sps->vui_seq_parameters.vcl_hrd_parameters.cpb_removal_delay_length_minus1 + 1;
01718 dpb_output_len = active_sps->vui_seq_parameters.vcl_hrd_parameters.dpb_output_delay_length_minus1 + 1;
01719 }
01720 }
01721
01722 if ((active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag)||
01723 (active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag))
01724 {
01725 cpb_removal_delay = u_v(cpb_removal_len, "SEI: cpb_removal_delay" , buf);
01726 dpb_output_delay = u_v(dpb_output_len, "SEI: dpb_output_delay" , buf);
01727 #ifdef PRINT_PCITURE_TIMING_INFO
01728 printf("cpb_removal_delay = %d\n",cpb_removal_delay);
01729 printf("dpb_output_delay = %d\n",dpb_output_delay);
01730 #endif
01731 }
01732 }
01733
01734 if (!active_sps->vui_parameters_present_flag)
01735 {
01736 picture_structure_present_flag = 0;
01737 }
01738 else
01739 {
01740 picture_structure_present_flag = active_sps->vui_seq_parameters.pic_struct_present_flag;
01741 }
01742
01743 if (picture_structure_present_flag)
01744 {
01745 picture_structure = u_v(4, "SEI: pic_struct" , buf);
01746 #ifdef PRINT_PCITURE_TIMING_INFO
01747 printf("picture_structure = %d\n",picture_structure);
01748 #endif
01749 switch (picture_structure)
01750 {
01751 case 0:
01752 case 1:
01753 case 2:
01754 NumClockTs = 1;
01755 break;
01756 case 3:
01757 case 4:
01758 case 7:
01759 NumClockTs = 2;
01760 break;
01761 case 5:
01762 case 6:
01763 case 8:
01764 NumClockTs = 3;
01765 break;
01766 default:
01767 error("reserved picture_structure used (can't determine NumClockTs)", 500);
01768 }
01769 for (i=0; i<NumClockTs; i++)
01770 {
01771 clock_time_stamp_flag = u_1("SEI: clock_time_stamp_flag" , buf);
01772 #ifdef PRINT_PCITURE_TIMING_INFO
01773 printf("clock_time_stamp_flag = %d\n",clock_time_stamp_flag);
01774 #endif
01775 if (clock_time_stamp_flag)
01776 {
01777 ct_type = u_v(2, "SEI: ct_type" , buf);
01778 nuit_field_based_flag = u_1( "SEI: nuit_field_based_flag" , buf);
01779 counting_type = u_v(5, "SEI: counting_type" , buf);
01780 full_timestamp_flag = u_1( "SEI: full_timestamp_flag" , buf);
01781 discontinuity_flag = u_1( "SEI: discontinuity_flag" , buf);
01782 cnt_dropped_flag = u_1( "SEI: cnt_dropped_flag" , buf);
01783 nframes = u_v(8, "SEI: nframes" , buf);
01784
01785 #ifdef PRINT_PCITURE_TIMING_INFO
01786 printf("ct_type = %d\n",ct_type);
01787 printf("nuit_field_based_flag = %d\n",nuit_field_based_flag);
01788 printf("full_timestamp_flag = %d\n",full_timestamp_flag);
01789 printf("discontinuity_flag = %d\n",discontinuity_flag);
01790 printf("cnt_dropped_flag = %d\n",cnt_dropped_flag);
01791 printf("nframes = %d\n",nframes);
01792 #endif
01793 if (full_timestamp_flag)
01794 {
01795 seconds_value = u_v(6, "SEI: seconds_value" , buf);
01796 minutes_value = u_v(6, "SEI: minutes_value" , buf);
01797 hours_value = u_v(5, "SEI: hours_value" , buf);
01798 #ifdef PRINT_PCITURE_TIMING_INFO
01799 printf("seconds_value = %d\n",seconds_value);
01800 printf("minutes_value = %d\n",minutes_value);
01801 printf("hours_value = %d\n",hours_value);
01802 #endif
01803 }
01804 else
01805 {
01806 seconds_flag = u_1( "SEI: seconds_flag" , buf);
01807 #ifdef PRINT_PCITURE_TIMING_INFO
01808 printf("seconds_flag = %d\n",seconds_flag);
01809 #endif
01810 if (seconds_flag)
01811 {
01812 seconds_value = u_v(6, "SEI: seconds_value" , buf);
01813 minutes_flag = u_1( "SEI: minutes_flag" , buf);
01814 #ifdef PRINT_PCITURE_TIMING_INFO
01815 printf("seconds_value = %d\n",seconds_value);
01816 printf("minutes_flag = %d\n",minutes_flag);
01817 #endif
01818 if(minutes_flag)
01819 {
01820 minutes_value = u_v(6, "SEI: minutes_value" , buf);
01821 hours_flag = u_1( "SEI: hours_flag" , buf);
01822 #ifdef PRINT_PCITURE_TIMING_INFO
01823 printf("minutes_value = %d\n",minutes_value);
01824 printf("hours_flag = %d\n",hours_flag);
01825 #endif
01826 if(hours_flag)
01827 {
01828 hours_value = u_v(5, "SEI: hours_value" , buf);
01829 #ifdef PRINT_PCITURE_TIMING_INFO
01830 printf("hours_value = %d\n",hours_value);
01831 #endif
01832 }
01833 }
01834 }
01835 }
01836 {
01837 int time_offset_length;
01838 if (active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag)
01839 time_offset_length = active_sps->vui_seq_parameters.vcl_hrd_parameters.time_offset_length;
01840 else if (active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag)
01841 time_offset_length = active_sps->vui_seq_parameters.nal_hrd_parameters.time_offset_length;
01842 else
01843 time_offset_length = 24;
01844 if (time_offset_length)
01845 time_offset = i_v(time_offset_length, "SEI: time_offset" , buf);
01846 else
01847 time_offset = 0;
01848 #ifdef PRINT_PCITURE_TIMING_INFO
01849 printf("time_offset = %d\n",time_offset);
01850 #endif
01851 }
01852 }
01853 }
01854 }
01855
01856 free (buf);
01857 #ifdef PRINT_PCITURE_TIMING_INFO
01858 #undef PRINT_PCITURE_TIMING_INFO
01859 #endif
01860 }
01861
01875 typedef struct
01876 {
01877 unsigned int tone_map_id;
01878 unsigned char tone_map_cancel_flag;
01879 unsigned int tone_map_repetition_period;
01880 unsigned char coded_data_bit_depth;
01881 unsigned char sei_bit_depth;
01882 unsigned int model_id;
01883
01884 int min_value;
01885 int max_value;
01886
01887 int sigmoid_midpoint;
01888 int sigmoid_width;
01889
01890 int start_of_coded_interval[1<<MAX_SEI_BIT_DEPTH];
01891
01892 int num_pivots;
01893 int coded_pivot_value[MAX_NUM_PIVOTS];
01894 int sei_pivot_value[MAX_NUM_PIVOTS];
01895 } tone_mapping_struct_tmp;
01896
01897 void interpret_tone_mapping( byte* payload, int size, ImageParameters *img )
01898 {
01899 tone_mapping_struct_tmp seiToneMappingTmp;
01900 Bitstream* buf;
01901 int i = 0, max_coded_num, max_output_num;
01902
01903 memset (&seiToneMappingTmp, 0, sizeof (tone_mapping_struct_tmp));
01904
01905 buf = malloc(sizeof(Bitstream));
01906 buf->bitstream_length = size;
01907 buf->streamBuffer = payload;
01908 buf->frame_bitoffset = 0;
01909
01910 seiToneMappingTmp.tone_map_id = ue_v("SEI: tone_map_id", buf);
01911 seiToneMappingTmp.tone_map_cancel_flag = u_1("SEI: tone_map_cancel_flag", buf);
01912
01913 #ifdef PRINT_TONE_MAPPING
01914 printf("Tone-mapping SEI message\n");
01915 printf("tone_map_id = %d\n", seiToneMappingTmp.tone_map_id);
01916
01917 if (seiToneMappingTmp.tone_map_id != 0)
01918 printf("WARNING! Tone_map_id != 0, print the SEI message info only. The tone mapping is actually applied only when Tone_map_id==0\n\n");
01919 printf("tone_map_cancel_flag = %d\n", seiToneMappingTmp.tone_map_cancel_flag);
01920 #endif
01921
01922 if (!seiToneMappingTmp.tone_map_cancel_flag)
01923 {
01924 seiToneMappingTmp.tone_map_repetition_period = ue_v( "SEI: tone_map_repetition_period", buf);
01925 seiToneMappingTmp.coded_data_bit_depth = u_v (8,"SEI: coded_data_bit_depth" , buf);
01926 seiToneMappingTmp.sei_bit_depth = u_v (8,"SEI: sei_bit_depth" , buf);
01927 seiToneMappingTmp.model_id = ue_v( "SEI: model_id" , buf);
01928
01929 #ifdef PRINT_TONE_MAPPING
01930 printf("tone_map_repetition_period = %d\n", seiToneMappingTmp.tone_map_repetition_period);
01931 printf("coded_data_bit_depth = %d\n", seiToneMappingTmp.coded_data_bit_depth);
01932 printf("sei_bit_depth = %d\n", seiToneMappingTmp.sei_bit_depth);
01933 printf("model_id = %d\n", seiToneMappingTmp.model_id);
01934 #endif
01935
01936 max_coded_num = 1<<seiToneMappingTmp.coded_data_bit_depth;
01937 max_output_num = 1<<seiToneMappingTmp.sei_bit_depth;
01938
01939 if (seiToneMappingTmp.model_id == 0)
01940 {
01941 seiToneMappingTmp.min_value = u_v (32,"SEI: min_value", buf);
01942 seiToneMappingTmp.max_value = u_v (32,"SEI: min_value", buf);
01943 #ifdef PRINT_TONE_MAPPING
01944 printf("min_value = %d, max_value = %d\n", seiToneMappingTmp.min_value, seiToneMappingTmp.max_value);
01945 #endif
01946 }
01947 else if (seiToneMappingTmp.model_id == 1)
01948 {
01949 seiToneMappingTmp.sigmoid_midpoint = u_v (32,"SEI: sigmoid_midpoint", buf);
01950 seiToneMappingTmp.sigmoid_width = u_v (32,"SEI: sigmoid_width", buf);
01951 #ifdef PRINT_TONE_MAPPING
01952 printf("sigmoid_midpoint = %d, sigmoid_width = %d\n", seiToneMappingTmp.sigmoid_midpoint, seiToneMappingTmp.sigmoid_width);
01953 #endif
01954 }
01955 else if (seiToneMappingTmp.model_id == 2)
01956 {
01957 for (i=0; i<max_output_num; i++)
01958 {
01959 seiToneMappingTmp.start_of_coded_interval[i] = u_v((((seiToneMappingTmp.coded_data_bit_depth+7)>>3)<<3), "SEI: start_of_coded_interval" , buf);
01960 #ifdef PRINT_TONE_MAPPING // too long to print
01961
01962 #endif
01963 }
01964 }
01965 else if (seiToneMappingTmp.model_id == 3)
01966 {
01967 seiToneMappingTmp.num_pivots = u_v (16,"SEI: num_pivots", buf);
01968 #ifdef PRINT_TONE_MAPPING
01969 printf("num_pivots = %d\n", seiToneMappingTmp.num_pivots);
01970 #endif
01971 seiToneMappingTmp.coded_pivot_value[0] = 0;
01972 seiToneMappingTmp.sei_pivot_value[0] = 0;
01973 seiToneMappingTmp.coded_pivot_value[seiToneMappingTmp.num_pivots+1] = max_coded_num-1;
01974 seiToneMappingTmp.sei_pivot_value[seiToneMappingTmp.num_pivots+1] = max_output_num-1;
01975
01976 for (i=1; i < seiToneMappingTmp.num_pivots+1; i++)
01977 {
01978 seiToneMappingTmp.coded_pivot_value[i] = u_v( (((seiToneMappingTmp.coded_data_bit_depth+7)>>3)<<3), "SEI: coded_pivot_value", buf);
01979 seiToneMappingTmp.sei_pivot_value[i] = u_v( (((seiToneMappingTmp.sei_bit_depth+7)>>3)<<3), "SEI: sei_pivot_value", buf);
01980 #ifdef PRINT_TONE_MAPPING
01981 printf("coded_pivot_value[%d] = %d, sei_pivot_value[%d] = %d\n", i, seiToneMappingTmp.coded_pivot_value[i], i, seiToneMappingTmp.sei_pivot_value[i]);
01982 #endif
01983 }
01984 }
01985
01986 #if (ENABLE_OUTPUT_TONEMAPPING)
01987
01988 if (seiToneMappingTmp.tone_map_id== 0)
01989 {
01990 int j;
01991 seiToneMapping.seiHasTone_mapping = TRUE;
01992 seiToneMapping.tone_map_repetition_period = seiToneMappingTmp.tone_map_repetition_period;
01993 seiToneMapping.coded_data_bit_depth = seiToneMappingTmp.coded_data_bit_depth;
01994 seiToneMapping.sei_bit_depth = seiToneMappingTmp.sei_bit_depth;
01995 seiToneMapping.model_id = seiToneMappingTmp.model_id;
01996 seiToneMapping.count = 0;
01997
01998
01999 switch(seiToneMappingTmp.model_id)
02000 {
02001 case 0:
02002 for (i=0; i<=seiToneMappingTmp.min_value; i++)
02003 seiToneMapping.lut[i] = 0;
02004
02005 for (i=seiToneMappingTmp.min_value+1; i < seiToneMappingTmp.max_value; i++)
02006 seiToneMapping.lut[i] = (i-seiToneMappingTmp.min_value) * (max_output_num-1)/(seiToneMappingTmp.max_value- seiToneMappingTmp.min_value);
02007
02008 for (i=seiToneMappingTmp.max_value; i<max_coded_num; i++)
02009 seiToneMapping.lut[i] = max_output_num-1;
02010 break;
02011 case 1:
02012
02013 for (i=0; i < max_coded_num; i++)
02014 {
02015 #if 0
02016 int j = (int)(1 + exp( -6*(double)(i-seiToneMappingTmp.sigmoid_midpoint)/seiToneMappingTmp.sigmoid_width));
02017 seiToneMapping.lut[i] = ((max_output_num-1)+(j>>1)) / j;
02018 #else
02019 double tmp = 1.0 + exp( -6*(double)(i-seiToneMappingTmp.sigmoid_midpoint)/seiToneMappingTmp.sigmoid_width);
02020 seiToneMapping.lut[i] = (int)( (double)(max_output_num-1)/ tmp + 0.5);
02021 #endif
02022 }
02023 break;
02024 case 2:
02025 if (0 < max_output_num-1)
02026 {
02027 for (j=0; j<max_output_num-1; j++)
02028 {
02029 for (i=seiToneMappingTmp.start_of_coded_interval[j]; i<seiToneMappingTmp.start_of_coded_interval[j+1]; i++)
02030 {
02031 seiToneMapping.lut[i] = j;
02032 }
02033 }
02034 seiToneMapping.lut[i] = max_output_num-1;
02035 }
02036 break;
02037 case 3:
02038 for (j=0; j<seiToneMappingTmp.num_pivots+1; j++)
02039 {
02040 #if 0
02041 slope = ((seiToneMappingTmp.sei_pivot_value[j+1] - seiToneMappingTmp.sei_pivot_value[j])<<16)/(seiToneMappingTmp.coded_pivot_value[j+1]-seiToneMappingTmp.coded_pivot_value[j]);
02042 for (i=seiToneMappingTmp.coded_pivot_value[j]; i <= seiToneMappingTmp.coded_pivot_value[j+1]; i++)
02043 {
02044 seiToneMapping.lut[i] = seiToneMappingTmp.sei_pivot_value[j] + (( (i - seiToneMappingTmp.coded_pivot_value[j]) * slope)>>16);
02045 }
02046 #else
02047 double slope = (double)(seiToneMappingTmp.sei_pivot_value[j+1] - seiToneMappingTmp.sei_pivot_value[j])/(seiToneMappingTmp.coded_pivot_value[j+1]-seiToneMappingTmp.coded_pivot_value[j]);
02048 for (i=seiToneMappingTmp.coded_pivot_value[j]; i <= seiToneMappingTmp.coded_pivot_value[j+1]; i++)
02049 {
02050 seiToneMapping.lut[i] = seiToneMappingTmp.sei_pivot_value[j] + (int)(( (i - seiToneMappingTmp.coded_pivot_value[j]) * slope));
02051 }
02052 #endif
02053 }
02054 break;
02055
02056 default:
02057 break;
02058 }
02059 }
02060 #endif
02061 }
02062 free (buf);
02063 }
02064
02065 #if (ENABLE_OUTPUT_TONEMAPPING)
02066
02067 void tone_map (imgpel** imgX, imgpel* lut, int size_x, int size_y)
02068 {
02069 int i, j;
02070
02071 for(i=0;i<size_y;i++)
02072 {
02073 for(j=0;j<size_x;j++)
02074 {
02075 imgX[i][j] = (imgpel)lut[imgX[i][j]];
02076 }
02077 }
02078 }
02079
02080 void init_tone_mapping_sei()
02081 {
02082 seiToneMapping.seiHasTone_mapping = FALSE;
02083 seiToneMapping.count = 0;
02084 }
02085
02086 void update_tone_mapping_sei()
02087 {
02088
02089 if(seiToneMapping.tone_map_repetition_period == 0)
02090 {
02091 seiToneMapping.seiHasTone_mapping = FALSE;
02092 seiToneMapping.count = 0;
02093 }
02094 else if (seiToneMapping.tone_map_repetition_period>1)
02095 {
02096 seiToneMapping.count++;
02097 if (seiToneMapping.count>=seiToneMapping.tone_map_repetition_period)
02098 {
02099 seiToneMapping.seiHasTone_mapping = FALSE;
02100 seiToneMapping.count = 0;
02101 }
02102 }
02103 }
02104 #endif
02105
02119 void interpret_post_filter_hints_info( byte* payload, int size, ImageParameters *img )
02120 {
02121 Bitstream* buf;
02122 unsigned int filter_hint_size_y, filter_hint_size_x, filter_hint_type, color_component, cx, cy, additional_extension_flag;
02123 int ***filter_hint;
02124
02125 buf = malloc(sizeof(Bitstream));
02126 buf->bitstream_length = size;
02127 buf->streamBuffer = payload;
02128 buf->frame_bitoffset = 0;
02129
02130 UsedBits = 0;
02131
02132 filter_hint_size_y = ue_v("SEI: filter_hint_size_y", buf);
02133 filter_hint_size_x = ue_v("SEI: filter_hint_size_x", buf);
02134 filter_hint_type = u_v(2, "SEI: filter_hint_type", buf);
02135
02136 get_mem3Dint (&filter_hint, 3, filter_hint_size_y, filter_hint_size_x);
02137
02138 for (color_component = 0; color_component < 3; color_component ++)
02139 for (cy = 0; cy < filter_hint_size_y; cy ++)
02140 for (cx = 0; cx < filter_hint_size_x; cx ++)
02141 filter_hint[color_component][cy][cx] = se_v("SEI: filter_hint", buf);
02142
02143 additional_extension_flag = u_1("SEI: additional_extension_flag", buf);
02144
02145 #ifdef PRINT_POST_FILTER_HINT_INFO
02146 printf(" Post-filter hint SEI message\n");
02147 printf(" post_filter_hint_size_y %d \n", filter_hint_size_y);
02148 printf(" post_filter_hint_size_x %d \n", filter_hint_size_x);
02149 printf(" post_filter_hint_type %d \n", filter_hint_type);
02150 for (color_component = 0; color_component < 3; color_component ++)
02151 for (cy = 0; cy < filter_hint_size_y; cy ++)
02152 for (cx = 0; cx < filter_hint_size_x; cx ++)
02153 printf(" post_filter_hint[%d][%d][%d] %d \n", color_component, cy, cx, filter_hint[color_component][cy][cx]);
02154
02155 printf(" additional_extension_flag %d \n", additional_extension_flag);
02156
02157 #undef PRINT_POST_FILTER_HINT_INFO
02158 #endif
02159
02160 free_mem3Dint (filter_hint);
02161 free( buf );
02162 }