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