00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "global.h"
00016 #include "memalloc.h"
00017 #include "rtp.h"
00018 #include "mbuffer.h"
00019 #include "sei.h"
00020 #include "vlc.h"
00021 #include "header.h"
00022
00023 static void InitRandomAccess (SEIParameters *p_SEI);
00024 static void CloseRandomAccess (SEIParameters *p_SEI);
00025 static void InitToneMapping (SEIParameters *p_SEI, InputParameters *p_Inp);
00026 static void CloseToneMapping (SEIParameters *p_SEI);
00027 static void CloseBufferingPeriod (SEIParameters *p_SEI);
00028 static void InitPicTiming (SEIParameters *p_SEI);
00029 static void ClosePicTiming (SEIParameters *p_SEI);
00030 static void InitDRPMRepetition (SEIParameters *p_SEI);
00031 static void CloseDRPMRepetition (SEIParameters *p_SEI);
00032 static void FinalizeDRPMRepetition (ImageParameters *p_Img);
00033 static void InitSparePicture (SEIParameters *p_SEI);
00034 static void CloseSparePicture (SEIParameters *p_SEI);
00035 static void FinalizeSpareMBMap (ImageParameters *p_Img);
00036 static void InitSubseqChar (ImageParameters *p_Img);
00037 static void ClearSubseqCharPayload (SEIParameters *p_SEI);
00038 static void CloseSubseqChar (SEIParameters *p_SEI);
00039 static void InitSubseqLayerInfo (SEIParameters *p_SEI);
00040 static void InitPanScanRectInfo (SEIParameters *p_SEI);
00041 static void ClearPanScanRectInfoPayload(SEIParameters *p_SEI);
00042 static void ClosePanScanRectInfo (SEIParameters *p_SEI);
00043 static void InitUser_data_unregistered (SEIParameters *p_SEI);
00044 static void InitUser_data_registered_itu_t_t35(SEIParameters *p_SEI);
00045 static void ClearUser_data_unregistered(SEIParameters *p_SEI);
00046 static void CloseUser_data_unregistered(SEIParameters *p_SEI);
00047 static void ClearUser_data_registered_itu_t_t35(SEIParameters *p_SEI);
00048 static void CloseUser_data_registered_itu_t_t35(SEIParameters *p_SEI);
00049 static void InitPostFilterHints (SEIParameters *p_SEI);
00050 static void ClearPostFilterHints (SEIParameters *p_SEI);
00051 static void ClosePostFilterHints (SEIParameters *p_SEI);
00052
00053
00054 void init_sei(SEIParameters *p_SEI)
00055 {
00056 p_SEI->seiHasTemporal_reference=FALSE;
00057 p_SEI->seiHasClock_timestamp=FALSE;
00058 p_SEI->seiHasPanscan_rect=FALSE;
00059 p_SEI->seiHasHrd_picture=FALSE;
00060 p_SEI->seiHasFiller_payload=FALSE;
00061 p_SEI->seiHasUser_data_registered_itu_t_t35=FALSE;
00062 p_SEI->seiHasUser_data_unregistered=FALSE;
00063 p_SEI->seiHasRecoveryPoint_info=FALSE;
00064 p_SEI->seiHasRef_pic_buffer_management_repetition=FALSE;
00065 p_SEI->seiHasSpare_picture=FALSE;
00066 p_SEI->seiHasBuffering_period=FALSE;
00067 p_SEI->seiHasPicTiming_info=FALSE;
00068 p_SEI->seiHasSceneInformation=FALSE;
00069 p_SEI->seiHasSubseq_information=FALSE;
00070 p_SEI->seiHasSubseq_layer_characteristics=FALSE;
00071 p_SEI->seiHasSubseq_characteristics=FALSE;
00072 p_SEI->seiHasTone_mapping=FALSE;
00073 p_SEI->seiHasPostFilterHints_info=FALSE;
00074 p_SEI->seiHasDRPMRepetition_info=FALSE;
00075 p_SEI->seiHasSparePicture = FALSE;
00076 p_SEI->seiHasSubseqChar = FALSE;
00077 p_SEI->seiHasSubseqInfo = FALSE;
00078 p_SEI->seiHasSubseqLayerInfo = FALSE;
00079 p_SEI->seiHasPanScanRectInfo = FALSE;
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089 void InitSEIMessages(ImageParameters *p_Img, InputParameters *p_Inp)
00090 {
00091 SEIParameters *p_SEI = p_Img->p_SEI;
00092 int i;
00093 for (i=0; i<2; i++)
00094 {
00095 p_SEI->sei_message[i].data = malloc(MAXRTPPAYLOADLEN);
00096 if( p_SEI->sei_message[i].data == NULL ) no_mem_exit("InitSEIMessages: sei_message[i].data");
00097 p_SEI->sei_message[i].subPacketType = SEI_PACKET_TYPE;
00098 clear_sei_message(p_SEI, i);
00099 }
00100
00101
00102 p_SEI->seiSparePicturePayload.data = NULL;
00103 InitSparePicture(p_SEI);
00104 if (p_Inp->NumFramesInELSubSeq != 0)
00105 {
00106 InitSubseqLayerInfo(p_SEI);
00107 InitSubseqChar(p_Img);
00108 }
00109 InitSceneInformation(p_SEI);
00110
00111 InitPanScanRectInfo(p_SEI);
00112
00113 InitUser_data_unregistered(p_SEI);
00114
00115 InitUser_data_registered_itu_t_t35(p_SEI);
00116
00117 InitRandomAccess(p_SEI);
00118
00119 InitToneMapping(p_SEI, p_Inp);
00120
00121 InitPostFilterHints(p_SEI);
00122
00123 InitBufferingPeriod(p_Img);
00124
00125 InitPicTiming(p_SEI);
00126
00127 InitDRPMRepetition(p_SEI);
00128 }
00129
00130 void CloseSEIMessages(ImageParameters *p_Img, InputParameters *p_Inp)
00131 {
00132 SEIParameters *p_SEI = p_Img->p_SEI;
00133 int i;
00134
00135 if (p_Inp->NumFramesInELSubSeq != 0)
00136 CloseSubseqLayerInfo();
00137
00138 CloseSubseqChar(p_SEI);
00139 CloseSparePicture(p_SEI);
00140 CloseSceneInformation(p_SEI);
00141 ClosePanScanRectInfo(p_SEI);
00142 CloseUser_data_unregistered(p_SEI);
00143 CloseUser_data_registered_itu_t_t35(p_SEI);
00144 CloseRandomAccess(p_SEI);
00145 CloseToneMapping(p_SEI);
00146 ClosePostFilterHints(p_SEI);
00147 CloseBufferingPeriod(p_SEI);
00148 ClosePicTiming(p_SEI);
00149 CloseDRPMRepetition(p_SEI);
00150
00151 for (i=0; i<MAX_LAYER_NUMBER; i++)
00152 {
00153 if ( p_SEI->sei_message[i].data )
00154 free( p_SEI->sei_message[i].data );
00155 p_SEI->sei_message[i].data = NULL;
00156 }
00157 }
00158
00159 Boolean HaveAggregationSEI(ImageParameters *p_Img)
00160 {
00161 SEIParameters *p_SEI = p_Img->p_SEI;
00162 if (p_SEI->sei_message[AGGREGATION_SEI].available && p_Img->type != B_SLICE)
00163 return TRUE;
00164 if (p_SEI->seiHasSubseqInfo)
00165 return TRUE;
00166 if (p_SEI->seiHasSubseqLayerInfo && p_Img->number == 0)
00167 return TRUE;
00168 if (p_SEI->seiHasSubseqChar)
00169 return TRUE;
00170 if (p_SEI->seiHasSceneInformation)
00171 return TRUE;
00172 if (p_SEI->seiHasPanScanRectInfo)
00173 return TRUE;
00174 if (p_SEI->seiHasUser_data_unregistered_info)
00175 return TRUE;
00176 if (p_SEI->seiHasUser_data_registered_itu_t_t35_info)
00177 return TRUE;
00178 if (p_SEI->seiHasRecoveryPoint_info)
00179 return TRUE;
00180 if (p_SEI->seiHasTone_mapping)
00181 return TRUE;
00182 if (p_SEI->seiHasPostFilterHints_info)
00183 return TRUE;
00184 if (p_SEI->seiHasBuffering_period)
00185 return TRUE;
00186 if (p_SEI->seiHasPicTiming_info)
00187 return TRUE;
00188 if (p_SEI->seiHasDRPMRepetition_info)
00189 return TRUE;
00190
00191 return FALSE;
00192
00193
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 static void write_sei_message(SEIParameters *p_SEI, int id, byte* payload, int payload_size, int payload_type)
00217 {
00218 int offset, type, size;
00219 assert(payload_type >= 0 && payload_type < SEI_MAX_ELEMENTS);
00220
00221 type = payload_type;
00222 size = payload_size;
00223 offset = p_SEI->sei_message[id].payloadSize;
00224
00225 while ( type > 254 )
00226 {
00227 p_SEI->sei_message[id].data[offset++] = 0xFF;
00228 type = type - 255;
00229 }
00230 p_SEI->sei_message[id].data[offset++] = (byte) type;
00231
00232 while ( size > 254 )
00233 {
00234 p_SEI->sei_message[id].data[offset++] = 0xFF;
00235 size = size - 255;
00236 }
00237 p_SEI->sei_message[id].data[offset++] = (byte) size;
00238
00239 memcpy(p_SEI->sei_message[id].data + offset, payload, payload_size);
00240 offset += payload_size;
00241
00242 p_SEI->sei_message[id].payloadSize = offset;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 static void finalize_sei_message(SEIParameters *p_SEI, int id)
00259 {
00260 int offset = p_SEI->sei_message[id].payloadSize;
00261
00262 p_SEI->sei_message[id].data[offset] = 0x80;
00263 p_SEI->sei_message[id].payloadSize++;
00264
00265 p_SEI->sei_message[id].available = TRUE;
00266 }
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 void clear_sei_message(SEIParameters *p_SEI, int id)
00283 {
00284 memset( p_SEI->sei_message[id].data, 0, MAXRTPPAYLOADLEN);
00285 p_SEI->sei_message[id].payloadSize = 0;
00286 p_SEI->sei_message[id].available = FALSE;
00287 }
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 void AppendTmpbits2Buf( Bitstream* dest, Bitstream* source )
00302 {
00303 int i, j;
00304 byte mask;
00305 int bits_in_last_byte;
00306
00307
00308 for (i=0; i<source->byte_pos; i++)
00309 {
00310 mask = 0x80;
00311 for (j=0; j<8; j++)
00312 {
00313 dest->byte_buf <<= 1;
00314 if (source->streamBuffer[i] & mask)
00315 dest->byte_buf |= 1;
00316 dest->bits_to_go--;
00317 mask >>= 1;
00318 if (dest->bits_to_go==0)
00319 {
00320 dest->bits_to_go = 8;
00321 dest->streamBuffer[dest->byte_pos++]=dest->byte_buf;
00322 dest->byte_buf = 0;
00323 }
00324 }
00325 }
00326
00327 bits_in_last_byte = 8-source->bits_to_go;
00328 if ( bits_in_last_byte > 0 )
00329 {
00330 mask = (byte) (1 << (bits_in_last_byte-1));
00331 for (j=0; j<bits_in_last_byte; j++)
00332 {
00333 dest->byte_buf <<= 1;
00334 if (source->byte_buf & mask)
00335 dest->byte_buf |= 1;
00336 dest->bits_to_go--;
00337 mask >>= 1;
00338 if (dest->bits_to_go==0)
00339 {
00340 dest->bits_to_go = 8;
00341 dest->streamBuffer[dest->byte_pos++]=dest->byte_buf;
00342 dest->byte_buf = 0;
00343 }
00344 }
00345 }
00346 }
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 static void InitSparePicture(SEIParameters *p_SEI)
00367 {
00368 if ( p_SEI->seiSparePicturePayload.data != NULL )
00369 CloseSparePicture(p_SEI);
00370
00371 p_SEI->seiSparePicturePayload.data = malloc( sizeof(Bitstream) );
00372 if ( p_SEI->seiSparePicturePayload.data == NULL ) no_mem_exit("InitSparePicture: seiSparePicturePayload.data");
00373 p_SEI->seiSparePicturePayload.data->streamBuffer = malloc(MAXRTPPAYLOADLEN);
00374 if ( p_SEI->seiSparePicturePayload.data->streamBuffer == NULL ) no_mem_exit("InitSparePicture: seiSparePicturePayload.data->streamBuffer");
00375 memset( p_SEI->seiSparePicturePayload.data->streamBuffer, 0, MAXRTPPAYLOADLEN);
00376 p_SEI->seiSparePicturePayload.num_spare_pics = 0;
00377 p_SEI->seiSparePicturePayload.target_frame_num = 0;
00378
00379 p_SEI->seiSparePicturePayload.data->bits_to_go = 8;
00380 p_SEI->seiSparePicturePayload.data->byte_pos = 0;
00381 p_SEI->seiSparePicturePayload.data->byte_buf = 0;
00382 }
00383
00384
00385
00386
00387
00388
00389
00390 static void CloseSparePicture(SEIParameters *p_SEI)
00391 {
00392 if (p_SEI->seiSparePicturePayload.data->streamBuffer)
00393 free(p_SEI->seiSparePicturePayload.data->streamBuffer);
00394 p_SEI->seiSparePicturePayload.data->streamBuffer = NULL;
00395 if (p_SEI->seiSparePicturePayload.data)
00396 free(p_SEI->seiSparePicturePayload.data);
00397 p_SEI->seiSparePicturePayload.data = NULL;
00398 p_SEI->seiSparePicturePayload.num_spare_pics = 0;
00399 p_SEI->seiSparePicturePayload.target_frame_num = 0;
00400 }
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 void CalculateSparePicture()
00414 {
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577 }
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596 void ComposeSparePictureMessage(SEIParameters *p_SEI, int delta_spare_frame_num, int ref_area_indicator, Bitstream *tmpBitstream)
00597 {
00598 Bitstream *bitstream = p_SEI->seiSparePicturePayload.data;
00599 SyntaxElement sym;
00600
00601 sym.type = SE_HEADER;
00602 sym.mapping = ue_linfo;
00603
00604 sym.value1 = delta_spare_frame_num;
00605 writeSyntaxElement2Buf_UVLC(&sym, bitstream);
00606 sym.value1 = ref_area_indicator;
00607 writeSyntaxElement2Buf_UVLC(&sym, bitstream);
00608
00609 AppendTmpbits2Buf( bitstream, tmpBitstream );
00610 }
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628 Boolean CompressSpareMBMap(ImageParameters *p_Img, unsigned char **map_sp, Bitstream *bitstream)
00629 {
00630 int j, k;
00631 int noc, bit0, bit1, bitc;
00632 SyntaxElement sym;
00633 int x, y, left, right, bottom, top, directx, directy;
00634
00635
00636 int size_uncompressed = (p_Img->height >> 4) * (p_Img->width >> 4);
00637 int size_compressed = 0;
00638 Boolean ret;
00639
00640
00641 sym.type = SE_HEADER;
00642 sym.mapping = ue_linfo;
00643 noc = 0;
00644 bit0 = 0;
00645 bit1 = 1;
00646 bitc = bit0;
00647
00648
00649 x = ( (p_Img->width >> 4) - 1 ) / 2;
00650 y = ( (p_Img->height >> 4) - 1 ) / 2;
00651 left = right = x;
00652 top = bottom = y;
00653 directx = 0;
00654 directy = 1;
00655 for (j=0; j<p_Img->height >> 4; j++)
00656 for (k=0; k<p_Img->width >> 4; k++)
00657 {
00658
00659 if ( map_sp[y][x] == bitc ) noc++;
00660 else
00661 {
00662 sym.value1 = noc;
00663 size_compressed += writeSyntaxElement2Buf_UVLC(&sym, bitstream);
00664 noc=0;
00665 }
00666
00667 if ( directx == -1 && directy == 0 )
00668 {
00669 if (x > left) x--;
00670 else if (x == 0)
00671 {
00672 y = bottom + 1;
00673 bottom++;
00674 directx = 1;
00675 directy = 0;
00676 }
00677 else if (x == left)
00678 {
00679 x--;
00680 left--;
00681 directx = 0;
00682 directy = 1;
00683 }
00684 }
00685 else if ( directx == 1 && directy == 0 )
00686 {
00687 if (x < right) x++;
00688 else if (x == (p_Img->width >> 4) - 1)
00689 {
00690 y = top - 1;
00691 top--;
00692 directx = -1;
00693 directy = 0;
00694 }
00695 else if (x == right)
00696 {
00697 x++;
00698 right++;
00699 directx = 0;
00700 directy = -1;
00701 }
00702 }
00703 else if ( directx == 0 && directy == -1 )
00704 {
00705 if ( y > top) y--;
00706 else if (y == 0)
00707 {
00708 x = left - 1;
00709 left--;
00710 directx = 0;
00711 directy = 1;
00712 }
00713 else if (y == top)
00714 {
00715 y--;
00716 top--;
00717 directx = -1;
00718 directy = 0;
00719 }
00720 }
00721 else if ( directx == 0 && directy == 1 )
00722 {
00723 if (y < bottom) y++;
00724 else if (y == (p_Img->height >> 4) - 1)
00725 {
00726 x = right+1;
00727 right++;
00728 directx = 0;
00729 directy = -1;
00730 }
00731 else if (y == bottom)
00732 {
00733 y++;
00734 bottom++;
00735 directx = 1;
00736 directy = 0;
00737 }
00738 }
00739 }
00740 if (noc!=0)
00741 {
00742 sym.value1 = noc;
00743 size_compressed += writeSyntaxElement2Buf_UVLC(&sym, bitstream);
00744 }
00745
00746 ret = (size_compressed<size_uncompressed? TRUE : FALSE);
00747 if ( !ret )
00748 {
00749
00750 bitstream->byte_buf = 0;
00751 bitstream->bits_to_go = 8;
00752 bitstream->byte_pos = 0;
00753 for (j=0; j<p_Img->height >> 4; j++)
00754 {
00755 for (k=0; k<p_Img->width >> 4; k++)
00756 {
00757 bitstream->byte_buf <<= 1;
00758 if (map_sp[j][k]) bitstream->byte_buf |= 1;
00759 bitstream->bits_to_go--;
00760 if (bitstream->bits_to_go==0)
00761 {
00762 bitstream->bits_to_go = 8;
00763 bitstream->streamBuffer[bitstream->byte_pos++]=bitstream->byte_buf;
00764 bitstream->byte_buf = 0;
00765 }
00766 }
00767 }
00768 }
00769
00770 return ret;
00771 }
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788 static void FinalizeSpareMBMap(ImageParameters *p_Img)
00789 {
00790 SEIParameters *p_SEI = p_Img->p_SEI;
00791 int CurrFrameNum = p_Img->number % MAX_FN;
00792 int delta_frame_num;
00793 SyntaxElement sym;
00794 Bitstream *dest, *source;
00795
00796 sym.type = SE_HEADER;
00797 sym.mapping = ue_linfo;
00798
00799 source = p_SEI->seiSparePicturePayload.data;
00800 dest = malloc(sizeof(Bitstream));
00801 if ( dest == NULL ) no_mem_exit("FinalizeSpareMBMap: dest");
00802 dest->streamBuffer = malloc(MAXRTPPAYLOADLEN);
00803 if ( dest->streamBuffer == NULL ) no_mem_exit("FinalizeSpareMBMap: dest->streamBuffer");
00804 dest->bits_to_go = 8;
00805 dest->byte_pos = 0;
00806 dest->byte_buf = 0;
00807 memset( dest->streamBuffer, 0, MAXRTPPAYLOADLEN);
00808
00809
00810 delta_frame_num = CurrFrameNum - p_SEI->seiSparePicturePayload.target_frame_num;
00811 if ( delta_frame_num < 0 ) delta_frame_num += MAX_FN;
00812 sym.value1 = delta_frame_num;
00813 writeSyntaxElement2Buf_UVLC(&sym, dest);
00814
00815
00816 sym.value1 = p_SEI->seiSparePicturePayload.num_spare_pics - 1;
00817 writeSyntaxElement2Buf_UVLC(&sym, dest);
00818
00819
00820 AppendTmpbits2Buf( dest, source);
00821
00822
00823 if ( dest->bits_to_go != 8 )
00824 {
00825 (dest->byte_buf) <<= 1;
00826 dest->byte_buf |= 1;
00827 dest->bits_to_go--;
00828 if ( dest->bits_to_go != 0 ) (dest->byte_buf) <<= (dest->bits_to_go);
00829 dest->bits_to_go = 8;
00830 dest->streamBuffer[dest->byte_pos++]=dest->byte_buf;
00831 dest->byte_buf = 0;
00832 }
00833 p_SEI->seiSparePicturePayload.payloadSize = dest->byte_pos;
00834
00835
00836 p_SEI->seiSparePicturePayload.data = dest;
00837 free( source->streamBuffer );
00838 free( source );
00839 }
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858 void InitSubseqInfo(SEIParameters *p_SEI, int currLayer)
00859 {
00860 static uint16 id = 0;
00861
00862 p_SEI->seiHasSubseqInfo = TRUE;
00863 p_SEI->seiSubseqInfo[currLayer].subseq_layer_num = currLayer;
00864 p_SEI->seiSubseqInfo[currLayer].subseq_id = id++;
00865 p_SEI->seiSubseqInfo[currLayer].last_picture_flag = 0;
00866 p_SEI->seiSubseqInfo[currLayer].stored_frame_cnt = (unsigned int) -1;
00867 p_SEI->seiSubseqInfo[currLayer].payloadSize = 0;
00868
00869 p_SEI->seiSubseqInfo[currLayer].data = malloc( sizeof(Bitstream) );
00870 if ( p_SEI->seiSubseqInfo[currLayer].data == NULL ) no_mem_exit("InitSubseqInfo: p_SEI->seiSubseqInfo[currLayer].data");
00871 p_SEI->seiSubseqInfo[currLayer].data->streamBuffer = malloc( MAXRTPPAYLOADLEN );
00872 if ( p_SEI->seiSubseqInfo[currLayer].data->streamBuffer == NULL ) no_mem_exit("InitSubseqInfo: p_SEI->seiSubseqInfo[currLayer].data->streamBuffer");
00873 p_SEI->seiSubseqInfo[currLayer].data->bits_to_go = 8;
00874 p_SEI->seiSubseqInfo[currLayer].data->byte_pos = 0;
00875 p_SEI->seiSubseqInfo[currLayer].data->byte_buf = 0;
00876 memset( p_SEI->seiSubseqInfo[currLayer].data->streamBuffer, 0, MAXRTPPAYLOADLEN );
00877 }
00878
00879
00880
00881
00882
00883
00884
00885 void UpdateSubseqInfo(ImageParameters *p_Img, InputParameters *p_Inp, int currLayer)
00886 {
00887 SEIParameters *p_SEI = p_Img->p_SEI;
00888 if (p_Img->type != B_SLICE)
00889 {
00890 p_SEI->seiSubseqInfo[currLayer].stored_frame_cnt ++;
00891 p_SEI->seiSubseqInfo[currLayer].stored_frame_cnt = p_SEI->seiSubseqInfo[currLayer].stored_frame_cnt % MAX_FN;
00892 }
00893
00894 if ( currLayer == 0 )
00895 {
00896 if ( p_Img->number == p_Inp->no_frm_base - 1 )
00897 p_SEI->seiSubseqInfo[currLayer].last_picture_flag = 1;
00898 else
00899 p_SEI->seiSubseqInfo[currLayer].last_picture_flag = 0;
00900 }
00901 if ( currLayer == 1 )
00902 {
00903 if ( ((p_Img->gop_number % (p_Inp->NumFramesInELSubSeq + 1) == 0) && (p_Inp->NumberBFrames != 0) && (p_Img->gop_number > 0)) ||
00904 ((p_Img->gop_number % (p_Inp->NumFramesInELSubSeq + 1) == p_Inp->NumFramesInELSubSeq) && (p_Inp->NumberBFrames==0))
00905 )
00906 p_SEI->seiSubseqInfo[currLayer].last_picture_flag = 1;
00907 else
00908 p_SEI->seiSubseqInfo[currLayer].last_picture_flag = 0;
00909 }
00910 }
00911
00912
00913
00914
00915
00916
00917
00918 static void FinalizeSubseqInfo(SEIParameters *p_SEI, int currLayer)
00919 {
00920 SyntaxElement sym;
00921 Bitstream *dest = p_SEI->seiSubseqInfo[currLayer].data;
00922
00923 sym.type = SE_HEADER;
00924 sym.mapping = ue_linfo;
00925
00926 sym.value1 = p_SEI->seiSubseqInfo[currLayer].subseq_layer_num;
00927 writeSyntaxElement2Buf_UVLC(&sym, dest);
00928 sym.value1 = p_SEI->seiSubseqInfo[currLayer].subseq_id;
00929 writeSyntaxElement2Buf_UVLC(&sym, dest);
00930 sym.bitpattern = p_SEI->seiSubseqInfo[currLayer].last_picture_flag;
00931 sym.len = 1;
00932 writeSyntaxElement2Buf_Fixed(&sym, dest);
00933 sym.value1 = p_SEI->seiSubseqInfo[currLayer].stored_frame_cnt;
00934 writeSyntaxElement2Buf_UVLC(&sym, dest);
00935
00936
00937 if ( dest->bits_to_go != 8 )
00938 {
00939 (dest->byte_buf) <<= 1;
00940 dest->byte_buf |= 1;
00941 dest->bits_to_go--;
00942 if ( dest->bits_to_go != 0 ) (dest->byte_buf) <<= (dest->bits_to_go);
00943 dest->bits_to_go = 8;
00944 dest->streamBuffer[dest->byte_pos++]=dest->byte_buf;
00945 dest->byte_buf = 0;
00946 }
00947 p_SEI->seiSubseqInfo[currLayer].payloadSize = dest->byte_pos;
00948
00949
00950 }
00951
00952
00953
00954
00955
00956
00957
00958 static void ClearSubseqInfoPayload(SEIParameters *p_SEI, int currLayer)
00959 {
00960 p_SEI->seiSubseqInfo[currLayer].data->bits_to_go = 8;
00961 p_SEI->seiSubseqInfo[currLayer].data->byte_pos = 0;
00962 p_SEI->seiSubseqInfo[currLayer].data->byte_buf = 0;
00963 memset( p_SEI->seiSubseqInfo[currLayer].data->streamBuffer, 0, MAXRTPPAYLOADLEN );
00964 p_SEI->seiSubseqInfo[currLayer].payloadSize = 0;
00965 }
00966
00967
00968
00969
00970
00971
00972
00973 void CloseSubseqInfo(SEIParameters *p_SEI, int currLayer)
00974 {
00975 p_SEI->seiSubseqInfo[currLayer].stored_frame_cnt = (unsigned int) -1;
00976 p_SEI->seiSubseqInfo[currLayer].payloadSize = 0;
00977
00978 free( p_SEI->seiSubseqInfo[currLayer].data->streamBuffer );
00979 free( p_SEI->seiSubseqInfo[currLayer].data );
00980 }
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998 static void InitSubseqLayerInfo(SEIParameters *p_SEI)
00999 {
01000 int i;
01001 p_SEI->seiHasSubseqLayerInfo = TRUE;
01002 p_SEI->seiSubseqLayerInfo.layer_number = 0;
01003 for (i=0; i<MAX_LAYER_NUMBER; i++)
01004 {
01005 p_SEI->seiSubseqLayerInfo.bit_rate[i] = 0;
01006 p_SEI->seiSubseqLayerInfo.frame_rate[i] = 0;
01007 p_SEI->seiSubseqLayerInfo.layer_number++;
01008 }
01009 }
01010
01011
01012
01013
01014
01015
01016
01017 void CloseSubseqLayerInfo()
01018 {
01019 }
01020
01021
01022
01023
01024
01025
01026
01027 static void FinalizeSubseqLayerInfo(SEIParameters *p_SEI)
01028 {
01029 int i, pos;
01030 pos = 0;
01031 p_SEI->seiSubseqLayerInfo.payloadSize = 0;
01032 for (i=0; i<p_SEI->seiSubseqLayerInfo.layer_number; i++)
01033 {
01034 *((uint16*)&(p_SEI->seiSubseqLayerInfo.data[pos])) = p_SEI->seiSubseqLayerInfo.bit_rate[i];
01035 pos += 2;
01036 *((uint16*)&(p_SEI->seiSubseqLayerInfo.data[pos])) = p_SEI->seiSubseqLayerInfo.frame_rate[i];
01037 pos += 2;
01038 p_SEI->seiSubseqLayerInfo.payloadSize += 4;
01039 }
01040 }
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052 void InitSubseqChar(ImageParameters *p_Img)
01053 {
01054 SEIParameters *p_SEI = p_Img->p_SEI;
01055 p_SEI->seiSubseqChar.data = malloc( sizeof(Bitstream) );
01056 if( p_SEI->seiSubseqChar.data == NULL ) no_mem_exit("InitSubseqChar: p_SEI->seiSubseqChar.data");
01057 p_SEI->seiSubseqChar.data->streamBuffer = malloc(MAXRTPPAYLOADLEN);
01058 if( p_SEI->seiSubseqChar.data->streamBuffer == NULL ) no_mem_exit("InitSubseqChar: p_SEI->seiSubseqChar.data->streamBuffer");
01059 ClearSubseqCharPayload(p_SEI);
01060
01061 p_SEI->seiSubseqChar.subseq_layer_num = p_Img->layer;
01062 p_SEI->seiSubseqChar.subseq_id = p_SEI->seiSubseqInfo[p_Img->layer].subseq_id;
01063 p_SEI->seiSubseqChar.duration_flag = 0;
01064 p_SEI->seiSubseqChar.average_rate_flag = 0;
01065 p_SEI->seiSubseqChar.num_referenced_subseqs = 0;
01066 }
01067
01068 static void ClearSubseqCharPayload(SEIParameters *p_SEI)
01069 {
01070 memset( p_SEI->seiSubseqChar.data->streamBuffer, 0, MAXRTPPAYLOADLEN);
01071 p_SEI->seiSubseqChar.data->bits_to_go = 8;
01072 p_SEI->seiSubseqChar.data->byte_pos = 0;
01073 p_SEI->seiSubseqChar.data->byte_buf = 0;
01074 p_SEI->seiSubseqChar.payloadSize = 0;
01075
01076 p_SEI->seiHasSubseqChar = FALSE;
01077 }
01078
01079 void UpdateSubseqChar(ImageParameters *p_Img)
01080 {
01081 SEIParameters *p_SEI = p_Img->p_SEI;
01082
01083 p_SEI->seiSubseqChar.subseq_layer_num = p_Img->layer;
01084 p_SEI->seiSubseqChar.subseq_id = p_SEI->seiSubseqInfo[p_Img->layer].subseq_id;
01085 p_SEI->seiSubseqChar.duration_flag = 0;
01086 p_SEI->seiSubseqChar.average_rate_flag = 0;
01087 p_SEI->seiSubseqChar.average_bit_rate = 100;
01088 p_SEI->seiSubseqChar.average_frame_rate = 30;
01089 p_SEI->seiSubseqChar.num_referenced_subseqs = 0;
01090 p_SEI->seiSubseqChar.ref_subseq_layer_num[0] = 1;
01091 p_SEI->seiSubseqChar.ref_subseq_id[0] = 2;
01092 p_SEI->seiSubseqChar.ref_subseq_layer_num[1] = 3;
01093 p_SEI->seiSubseqChar.ref_subseq_id[1] = 4;
01094
01095 p_SEI->seiHasSubseqChar = TRUE;
01096 }
01097
01098 static void FinalizeSubseqChar(SEIParameters *p_SEI)
01099 {
01100 int i;
01101 SyntaxElement sym;
01102 Bitstream *dest = p_SEI->seiSubseqChar.data;
01103
01104 sym.type = SE_HEADER;
01105 sym.mapping = ue_linfo;
01106
01107 sym.value1 = p_SEI->seiSubseqChar.subseq_layer_num;
01108 writeSyntaxElement2Buf_UVLC(&sym, dest);
01109 sym.value1 = p_SEI->seiSubseqChar.subseq_id;
01110 writeSyntaxElement2Buf_UVLC(&sym, dest);
01111 sym.bitpattern = p_SEI->seiSubseqChar.duration_flag;
01112 sym.len = 1;
01113 writeSyntaxElement2Buf_Fixed(&sym, dest);
01114 if ( p_SEI->seiSubseqChar.duration_flag )
01115 {
01116 sym.bitpattern = p_SEI->seiSubseqChar.subseq_duration;
01117 sym.len = 32;
01118 writeSyntaxElement2Buf_Fixed(&sym, dest);
01119 }
01120 sym.bitpattern = p_SEI->seiSubseqChar.average_rate_flag;
01121 sym.len = 1;
01122 writeSyntaxElement2Buf_Fixed(&sym, dest);
01123 if ( p_SEI->seiSubseqChar.average_rate_flag )
01124 {
01125 sym.bitpattern = p_SEI->seiSubseqChar.average_bit_rate;
01126 sym.len = 16;
01127 writeSyntaxElement2Buf_Fixed(&sym, dest);
01128 sym.bitpattern = p_SEI->seiSubseqChar.average_frame_rate;
01129 sym.len = 16;
01130 writeSyntaxElement2Buf_Fixed(&sym, dest);
01131 }
01132 sym.value1 = p_SEI->seiSubseqChar.num_referenced_subseqs;
01133 writeSyntaxElement2Buf_UVLC(&sym, dest);
01134 for (i=0; i<p_SEI->seiSubseqChar.num_referenced_subseqs; i++)
01135 {
01136 sym.value1 = p_SEI->seiSubseqChar.ref_subseq_layer_num[i];
01137 writeSyntaxElement2Buf_UVLC(&sym, dest);
01138 sym.value1 = p_SEI->seiSubseqChar.ref_subseq_id[i];
01139 writeSyntaxElement2Buf_UVLC(&sym, dest);
01140 }
01141
01142
01143 if ( dest->bits_to_go != 8 )
01144 {
01145 (dest->byte_buf) <<= 1;
01146 dest->byte_buf |= 1;
01147 dest->bits_to_go--;
01148 if ( dest->bits_to_go != 0 ) (dest->byte_buf) <<= (dest->bits_to_go);
01149 dest->bits_to_go = 8;
01150 dest->streamBuffer[dest->byte_pos++]=dest->byte_buf;
01151 dest->byte_buf = 0;
01152 }
01153 p_SEI->seiSubseqChar.payloadSize = dest->byte_pos;
01154 }
01155
01156 static void CloseSubseqChar(SEIParameters *p_SEI)
01157 {
01158 if (p_SEI->seiSubseqChar.data)
01159 {
01160 free(p_SEI->seiSubseqChar.data->streamBuffer);
01161 free(p_SEI->seiSubseqChar.data);
01162 }
01163 p_SEI->seiSubseqChar.data = NULL;
01164 }
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177 void InitSceneInformation(SEIParameters *p_SEI)
01178 {
01179 p_SEI->seiHasSceneInformation = TRUE;
01180
01181 p_SEI->seiSceneInformation.scene_id = 0;
01182 p_SEI->seiSceneInformation.scene_transition_type = 0;
01183 p_SEI->seiSceneInformation.second_scene_id = -1;
01184
01185 p_SEI->seiSceneInformation.data = malloc( sizeof(Bitstream) );
01186 if(p_SEI-> seiSceneInformation.data == NULL ) no_mem_exit("InitSceneInformation: seiSceneInformation.data");
01187 p_SEI->seiSceneInformation.data->streamBuffer = malloc( MAXRTPPAYLOADLEN );
01188 if( p_SEI->seiSceneInformation.data->streamBuffer == NULL ) no_mem_exit("InitSceneInformation: seiSceneInformation.data->streamBuffer");
01189 p_SEI->seiSceneInformation.data->bits_to_go = 8;
01190 p_SEI->seiSceneInformation.data->byte_pos = 0;
01191 p_SEI->seiSceneInformation.data->byte_buf = 0;
01192 memset( p_SEI->seiSceneInformation.data->streamBuffer, 0, MAXRTPPAYLOADLEN );
01193 }
01194
01195 void CloseSceneInformation(SEIParameters *p_SEI)
01196 {
01197 if (p_SEI->seiSceneInformation.data)
01198 {
01199 free(p_SEI->seiSceneInformation.data->streamBuffer);
01200 free(p_SEI->seiSceneInformation.data);
01201 }
01202 p_SEI->seiSceneInformation.data = NULL;
01203 }
01204
01205 void FinalizeSceneInformation(SEIParameters *p_SEI)
01206 {
01207 SyntaxElement sym;
01208 Bitstream *dest = p_SEI->seiSceneInformation.data;
01209
01210 sym.type = SE_HEADER;
01211 sym.mapping = ue_linfo;
01212
01213 sym.bitpattern = p_SEI->seiSceneInformation.scene_id;
01214 sym.len = 8;
01215 writeSyntaxElement2Buf_Fixed(&sym, dest);
01216
01217 sym.value1 = p_SEI->seiSceneInformation.scene_transition_type;
01218 writeSyntaxElement2Buf_UVLC(&sym, dest);
01219
01220 if(p_SEI->seiSceneInformation.scene_transition_type > 3)
01221 {
01222 sym.bitpattern = p_SEI->seiSceneInformation.second_scene_id;
01223 sym.len = 8;
01224 writeSyntaxElement2Buf_Fixed(&sym, dest);
01225 }
01226
01227
01228 if ( dest->bits_to_go != 8 )
01229 {
01230 (dest->byte_buf) <<= 1;
01231 dest->byte_buf |= 1;
01232 dest->bits_to_go--;
01233 if ( dest->bits_to_go != 0 ) (dest->byte_buf) <<= (dest->bits_to_go);
01234 dest->bits_to_go = 8;
01235 dest->streamBuffer[dest->byte_pos++]=dest->byte_buf;
01236 dest->byte_buf = 0;
01237 }
01238 p_SEI->seiSceneInformation.payloadSize = dest->byte_pos;
01239 }
01240
01241
01242
01243
01244 void UpdateSceneInformation(SEIParameters *p_SEI, Boolean HasSceneInformation, int sceneID, int sceneTransType, int secondSceneID)
01245 {
01246 p_SEI->seiHasSceneInformation = HasSceneInformation;
01247
01248 assert (sceneID < 256);
01249 p_SEI->seiSceneInformation.scene_id = sceneID;
01250
01251 assert (sceneTransType <= 6 );
01252 p_SEI->seiSceneInformation.scene_transition_type = sceneTransType;
01253
01254 if(sceneTransType > 3)
01255 {
01256 assert (secondSceneID < 256);
01257 p_SEI->seiSceneInformation.second_scene_id = secondSceneID;
01258 }
01259 }
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274 static void InitPanScanRectInfo(SEIParameters *p_SEI)
01275 {
01276 p_SEI->seiPanScanRectInfo.data = malloc( sizeof(Bitstream) );
01277 if( p_SEI->seiPanScanRectInfo.data == NULL ) no_mem_exit("InitPanScanRectInfo: p_SEI->seiPanScanRectInfo.data");
01278 p_SEI->seiPanScanRectInfo.data->streamBuffer = malloc(MAXRTPPAYLOADLEN);
01279 if( p_SEI->seiPanScanRectInfo.data->streamBuffer == NULL ) no_mem_exit("InitPanScanRectInfo: p_SEI->seiPanScanRectInfo.data->streamBuffer");
01280 ClearPanScanRectInfoPayload(p_SEI);
01281
01282 p_SEI->seiPanScanRectInfo.pan_scan_rect_left_offset = 0;
01283 p_SEI->seiPanScanRectInfo.pan_scan_rect_right_offset = 0;
01284 p_SEI->seiPanScanRectInfo.pan_scan_rect_top_offset = 0;
01285 p_SEI->seiPanScanRectInfo.pan_scan_rect_bottom_offset = 0;
01286
01287 }
01288
01289
01290 static void ClearPanScanRectInfoPayload(SEIParameters *p_SEI)
01291 {
01292 memset( p_SEI->seiPanScanRectInfo.data->streamBuffer, 0, MAXRTPPAYLOADLEN);
01293 p_SEI->seiPanScanRectInfo.data->bits_to_go = 8;
01294 p_SEI->seiPanScanRectInfo.data->byte_pos = 0;
01295 p_SEI->seiPanScanRectInfo.data->byte_buf = 0;
01296 p_SEI->seiPanScanRectInfo.payloadSize = 0;
01297
01298 p_SEI->seiHasPanScanRectInfo = FALSE;
01299 }
01300
01301 void UpdatePanScanRectInfo(SEIParameters *p_SEI)
01302 {
01303 p_SEI->seiPanScanRectInfo.pan_scan_rect_id = 3;
01304 p_SEI->seiPanScanRectInfo.pan_scan_rect_left_offset = 10;
01305 p_SEI->seiPanScanRectInfo.pan_scan_rect_right_offset = 40;
01306 p_SEI->seiPanScanRectInfo.pan_scan_rect_top_offset = 20;
01307 p_SEI->seiPanScanRectInfo.pan_scan_rect_bottom_offset =32;
01308 p_SEI->seiHasPanScanRectInfo = TRUE;
01309 }
01310
01311 void FinalizePanScanRectInfo(SEIParameters *p_SEI)
01312 {
01313 SyntaxElement sym;
01314 Bitstream *dest = p_SEI->seiPanScanRectInfo.data;
01315
01316
01317 sym.type = SE_HEADER;
01318 sym.mapping = ue_linfo;
01319
01320 sym.value1 = p_SEI->seiPanScanRectInfo.pan_scan_rect_id;
01321 writeSyntaxElement2Buf_UVLC(&sym, dest);
01322 sym.value1 = p_SEI->seiPanScanRectInfo.pan_scan_rect_left_offset;
01323 writeSyntaxElement2Buf_UVLC(&sym, dest);
01324 sym.value1 = p_SEI->seiPanScanRectInfo.pan_scan_rect_right_offset;
01325 writeSyntaxElement2Buf_UVLC(&sym, dest);
01326 sym.value1 = p_SEI->seiPanScanRectInfo.pan_scan_rect_top_offset;
01327 writeSyntaxElement2Buf_UVLC(&sym, dest);
01328 sym.value1 = p_SEI->seiPanScanRectInfo.pan_scan_rect_bottom_offset;
01329 writeSyntaxElement2Buf_UVLC(&sym, dest);
01330
01331
01332 #ifdef PRINT_PAN_SCAN_RECT
01333 printf("Pan Scan Id %d Left %d Right %d Top %d Bottom %d \n", p_SEI->seiPanScanRectInfo.pan_scan_rect_id, p_SEI->seiPanScanRectInfo.pan_scan_rect_left_offset, p_SEI->seiPanScanRectInfo.pan_scan_rect_right_offset, p_SEI->seiPanScanRectInfo.pan_scan_rect_top_offset, p_SEI->seiPanScanRectInfo.pan_scan_rect_bottom_offset);
01334 #endif
01335 #ifdef PRINT_PAN_SCAN_RECT
01336 #undef PRINT_PAN_SCAN_RECT
01337 #endif
01338
01339 if ( dest->bits_to_go != 8 )
01340 {
01341 (dest->byte_buf) <<= 1;
01342 dest->byte_buf |= 1;
01343 dest->bits_to_go--;
01344 if ( dest->bits_to_go != 0 ) (dest->byte_buf) <<= (dest->bits_to_go);
01345 dest->bits_to_go = 8;
01346 dest->streamBuffer[dest->byte_pos++]=dest->byte_buf;
01347 dest->byte_buf = 0;
01348 }
01349 p_SEI->seiPanScanRectInfo.payloadSize = dest->byte_pos;
01350 }
01351
01352
01353 void ClosePanScanRectInfo(SEIParameters *p_SEI)
01354 {
01355 if (p_SEI->seiPanScanRectInfo.data)
01356 {
01357 free(p_SEI->seiPanScanRectInfo.data->streamBuffer);
01358 free(p_SEI->seiPanScanRectInfo.data);
01359 }
01360 p_SEI->seiPanScanRectInfo.data = NULL;
01361 }
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372 static void InitUser_data_unregistered(SEIParameters *p_SEI)
01373 {
01374
01375 p_SEI->seiUser_data_unregistered.data = malloc( sizeof(Bitstream) );
01376 if( p_SEI->seiUser_data_unregistered.data == NULL ) no_mem_exit("InitUser_data_unregistered: p_SEI->seiUser_data_unregistered.data");
01377 p_SEI->seiUser_data_unregistered.data->streamBuffer = malloc(MAXRTPPAYLOADLEN);
01378 if( p_SEI->seiUser_data_unregistered.data->streamBuffer == NULL ) no_mem_exit("InitUser_data_unregistered: p_SEI->seiUser_data_unregistered.data->streamBuffer");
01379 p_SEI->seiUser_data_unregistered.byte = malloc(MAXRTPPAYLOADLEN);
01380 if( p_SEI->seiUser_data_unregistered.byte == NULL ) no_mem_exit("InitUser_data_unregistered: p_SEI->seiUser_data_unregistered.byte");
01381 ClearUser_data_unregistered(p_SEI);
01382
01383 }
01384
01385
01386 static void ClearUser_data_unregistered(SEIParameters *p_SEI)
01387 {
01388 memset( p_SEI->seiUser_data_unregistered.data->streamBuffer, 0, MAXRTPPAYLOADLEN);
01389 p_SEI->seiUser_data_unregistered.data->bits_to_go = 8;
01390 p_SEI->seiUser_data_unregistered.data->byte_pos = 0;
01391 p_SEI->seiUser_data_unregistered.data->byte_buf = 0;
01392 p_SEI->seiUser_data_unregistered.payloadSize = 0;
01393
01394 memset( p_SEI->seiUser_data_unregistered.byte, 0, MAXRTPPAYLOADLEN);
01395 p_SEI->seiUser_data_unregistered.total_byte = 0;
01396
01397 p_SEI->seiHasUser_data_unregistered_info = FALSE;
01398 }
01399
01400 void UpdateUser_data_unregistered(SEIParameters *p_SEI)
01401 {
01402 int i, temp_data;
01403 int total_byte;
01404
01405
01406 total_byte = 7;
01407 for(i = 0; i < total_byte; i++)
01408 {
01409 temp_data = i * 4;
01410 p_SEI->seiUser_data_unregistered.byte[i] = (char) iClip3(0, 255, temp_data);
01411 }
01412 p_SEI->seiUser_data_unregistered.total_byte = total_byte;
01413 }
01414
01415 static void FinalizeUser_data_unregistered(SEIParameters *p_SEI)
01416 {
01417 int i;
01418 SyntaxElement sym;
01419 Bitstream *dest = p_SEI->seiUser_data_unregistered.data;
01420
01421 sym.type = SE_HEADER;
01422 sym.mapping = ue_linfo;
01423
01424
01425 for( i = 0; i < p_SEI->seiUser_data_unregistered.total_byte; i++)
01426 {
01427 sym.bitpattern = p_SEI->seiUser_data_unregistered.byte[i];
01428 sym.len = 8;
01429 writeSyntaxElement2Buf_Fixed(&sym, dest);
01430 #ifdef PRINT_USER_DATA_UNREGISTERED_INFO
01431 printf("Unreg data payload_byte = %d\n", p_SEI->seiUser_data_unregistered.byte[i]);
01432 #endif
01433 }
01434 #ifdef PRINT_USER_DATA_UNREGISTERED_INFO
01435 #undef PRINT_USER_DATA_UNREGISTERED_INFO
01436 #endif
01437
01438 if ( dest->bits_to_go != 8 )
01439 {
01440 (dest->byte_buf) <<= 1;
01441 dest->byte_buf |= 1;
01442 dest->bits_to_go--;
01443 if ( dest->bits_to_go != 0 ) (dest->byte_buf) <<= (dest->bits_to_go);
01444 dest->bits_to_go = 8;
01445 dest->streamBuffer[dest->byte_pos++]=dest->byte_buf;
01446 dest->byte_buf = 0;
01447 }
01448 p_SEI->seiUser_data_unregistered.payloadSize = dest->byte_pos;
01449 }
01450
01451 static void CloseUser_data_unregistered(SEIParameters *p_SEI)
01452 {
01453 if (p_SEI->seiUser_data_unregistered.data)
01454 {
01455 free(p_SEI->seiUser_data_unregistered.data->streamBuffer);
01456 free(p_SEI->seiUser_data_unregistered.data);
01457 }
01458 p_SEI->seiUser_data_unregistered.data = NULL;
01459 if(p_SEI->seiUser_data_unregistered.byte)
01460 {
01461 free(p_SEI->seiUser_data_unregistered.byte);
01462 }
01463 }
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475 void InitUser_data_registered_itu_t_t35(SEIParameters *p_SEI)
01476 {
01477
01478 p_SEI->seiUser_data_registered_itu_t_t35.data = malloc( sizeof(Bitstream) );
01479 if( p_SEI->seiUser_data_registered_itu_t_t35.data == NULL ) no_mem_exit("InitUser_data_unregistered: p_SEI->seiUser_data_registered_itu_t_t35.data");
01480 p_SEI->seiUser_data_registered_itu_t_t35.data->streamBuffer = malloc(MAXRTPPAYLOADLEN);
01481 if( p_SEI->seiUser_data_registered_itu_t_t35.data->streamBuffer == NULL ) no_mem_exit("InitUser_data_unregistered: p_SEI->seiUser_data_registered_itu_t_t35.data->streamBuffer");
01482 p_SEI->seiUser_data_registered_itu_t_t35.byte = malloc(MAXRTPPAYLOADLEN);
01483 if( p_SEI->seiUser_data_registered_itu_t_t35.data == NULL ) no_mem_exit("InitUser_data_unregistered: p_SEI->seiUser_data_registered_itu_t_t35.byte");
01484 ClearUser_data_registered_itu_t_t35(p_SEI);
01485
01486 }
01487
01488
01489 static void ClearUser_data_registered_itu_t_t35(SEIParameters *p_SEI)
01490 {
01491 memset( p_SEI->seiUser_data_registered_itu_t_t35.data->streamBuffer, 0, MAXRTPPAYLOADLEN);
01492 p_SEI->seiUser_data_registered_itu_t_t35.data->bits_to_go = 8;
01493 p_SEI->seiUser_data_registered_itu_t_t35.data->byte_pos = 0;
01494 p_SEI->seiUser_data_registered_itu_t_t35.data->byte_buf = 0;
01495 p_SEI->seiUser_data_registered_itu_t_t35.payloadSize = 0;
01496
01497 memset( p_SEI->seiUser_data_registered_itu_t_t35.byte, 0, MAXRTPPAYLOADLEN);
01498 p_SEI->seiUser_data_registered_itu_t_t35.total_byte = 0;
01499 p_SEI->seiUser_data_registered_itu_t_t35.itu_t_t35_country_code = 0;
01500 p_SEI->seiUser_data_registered_itu_t_t35.itu_t_t35_country_code_extension_byte = 0;
01501
01502 p_SEI->seiHasUser_data_registered_itu_t_t35_info = FALSE;
01503 }
01504
01505 void UpdateUser_data_registered_itu_t_t35(SEIParameters *p_SEI)
01506 {
01507 int i, temp_data;
01508 int total_byte;
01509 int country_code = 82;
01510
01511 if(country_code < 0xFF)
01512 {
01513 p_SEI->seiUser_data_registered_itu_t_t35.itu_t_t35_country_code = country_code;
01514 }
01515 else
01516 {
01517 p_SEI->seiUser_data_registered_itu_t_t35.itu_t_t35_country_code = 0xFF;
01518 p_SEI->seiUser_data_registered_itu_t_t35.itu_t_t35_country_code_extension_byte = country_code - 0xFF;
01519 }
01520
01521 total_byte = 7;
01522 for(i = 0; i < total_byte; i++)
01523 {
01524 temp_data = i * 3;
01525 p_SEI->seiUser_data_registered_itu_t_t35.byte[i] = (char) iClip3(0, 255, temp_data);
01526 }
01527 p_SEI->seiUser_data_registered_itu_t_t35.total_byte = total_byte;
01528 }
01529
01530 static void FinalizeUser_data_registered_itu_t_t35(SEIParameters *p_SEI)
01531 {
01532 int i;
01533 SyntaxElement sym;
01534 Bitstream *dest = p_SEI->seiUser_data_registered_itu_t_t35.data;
01535
01536 sym.type = SE_HEADER;
01537 sym.mapping = ue_linfo;
01538
01539 sym.bitpattern = p_SEI->seiUser_data_registered_itu_t_t35.itu_t_t35_country_code;
01540 sym.len = 8;
01541 writeSyntaxElement2Buf_Fixed(&sym, dest);
01542
01543
01544 #ifdef PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO
01545 printf(" ITU_T_T35_COUNTRTY_CODE %d \n", p_SEI->seiUser_data_registered_itu_t_t35.itu_t_t35_country_code);
01546 #endif
01547
01548 if(p_SEI->seiUser_data_registered_itu_t_t35.itu_t_t35_country_code == 0xFF)
01549 {
01550 sym.bitpattern = p_SEI->seiUser_data_registered_itu_t_t35.itu_t_t35_country_code_extension_byte;
01551 sym.len = 8;
01552 writeSyntaxElement2Buf_Fixed(&sym, dest);
01553 #ifdef PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO
01554 printf(" ITU_T_T35_COUNTRTY_CODE_EXTENSION_BYTE %d \n", p_SEI->seiUser_data_registered_itu_t_t35.itu_t_t35_country_code_extension_byte);
01555 #endif
01556 }
01557
01558 for( i = 0; i < p_SEI->seiUser_data_registered_itu_t_t35.total_byte; i++)
01559 {
01560 sym.bitpattern = p_SEI->seiUser_data_registered_itu_t_t35.byte[i];
01561 sym.len = 8;
01562 writeSyntaxElement2Buf_Fixed(&sym, dest);
01563 #ifdef PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO
01564 printf("itu_t_t35 payload_byte = %d\n", p_SEI->seiUser_data_registered_itu_t_t35.byte[i]);
01565 #endif
01566 }
01567 #ifdef PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO
01568 #undef PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO
01569 #endif
01570
01571 if ( dest->bits_to_go != 8 )
01572 {
01573 (dest->byte_buf) <<= 1;
01574 dest->byte_buf |= 1;
01575 dest->bits_to_go--;
01576 if ( dest->bits_to_go != 0 ) (dest->byte_buf) <<= (dest->bits_to_go);
01577 dest->bits_to_go = 8;
01578 dest->streamBuffer[dest->byte_pos++]=dest->byte_buf;
01579 dest->byte_buf = 0;
01580 }
01581 p_SEI->seiUser_data_registered_itu_t_t35.payloadSize = dest->byte_pos;
01582 }
01583
01584 void CloseUser_data_registered_itu_t_t35(SEIParameters *p_SEI)
01585 {
01586 if (p_SEI->seiUser_data_registered_itu_t_t35.data)
01587 {
01588 free(p_SEI->seiUser_data_registered_itu_t_t35.data->streamBuffer);
01589 free(p_SEI->seiUser_data_registered_itu_t_t35.data);
01590 }
01591 p_SEI->seiUser_data_registered_itu_t_t35.data = NULL;
01592 if(p_SEI->seiUser_data_registered_itu_t_t35.byte)
01593 {
01594 free(p_SEI->seiUser_data_registered_itu_t_t35.byte);
01595 }
01596 }
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607 static void InitRandomAccess(SEIParameters *p_SEI)
01608 {
01609 p_SEI->seiRecoveryPoint.data = malloc( sizeof(Bitstream) );
01610 if( p_SEI->seiRecoveryPoint.data == NULL ) no_mem_exit("InitRandomAccess: seiRandomAccess.data");
01611 p_SEI->seiRecoveryPoint.data->streamBuffer = malloc(MAXRTPPAYLOADLEN);
01612 if( p_SEI->seiRecoveryPoint.data->streamBuffer == NULL ) no_mem_exit("InitRandomAccess: seiRandomAccess.data->streamBuffer");
01613 ClearRandomAccess(p_SEI);
01614 }
01615
01616
01617 void ClearRandomAccess(SEIParameters *p_SEI)
01618 {
01619 memset( p_SEI->seiRecoveryPoint.data->streamBuffer, 0, MAXRTPPAYLOADLEN);
01620 p_SEI->seiRecoveryPoint.data->bits_to_go = 8;
01621 p_SEI->seiRecoveryPoint.data->byte_pos = 0;
01622 p_SEI->seiRecoveryPoint.data->byte_buf = 0;
01623 p_SEI->seiRecoveryPoint.payloadSize = 0;
01624
01625 p_SEI->seiRecoveryPoint.recovery_frame_cnt = 0;
01626 p_SEI->seiRecoveryPoint.broken_link_flag = 0;
01627 p_SEI->seiRecoveryPoint.exact_match_flag = 0;
01628 p_SEI->seiRecoveryPoint.changing_slice_group_idc = 0;
01629
01630 p_SEI->seiHasRecoveryPoint_info = FALSE;
01631 }
01632
01633 void UpdateRandomAccess(ImageParameters *p_Img)
01634 {
01635 SEIParameters *p_SEI = p_Img->p_SEI;
01636 if(p_Img->type == I_SLICE)
01637 {
01638 p_SEI->seiRecoveryPoint.recovery_frame_cnt = 0;
01639 p_SEI->seiRecoveryPoint.exact_match_flag = 1;
01640 p_SEI->seiRecoveryPoint.broken_link_flag = 0;
01641 p_SEI->seiRecoveryPoint.changing_slice_group_idc = 0;
01642 p_SEI->seiHasRecoveryPoint_info = TRUE;
01643 }
01644 else
01645 {
01646 p_SEI->seiHasRecoveryPoint_info = FALSE;
01647 }
01648 }
01649
01650 static void FinalizeRandomAccess(SEIParameters *p_SEI)
01651 {
01652 Bitstream *bitstream = p_SEI->seiRecoveryPoint.data;
01653
01654 ue_v( "SEI: recovery_frame_cnt", p_SEI->seiRecoveryPoint.recovery_frame_cnt, bitstream);
01655 u_1 ( "SEI: exact_match_flag", p_SEI->seiRecoveryPoint.exact_match_flag, bitstream);
01656 u_1 ( "SEI: broken_link_flag", p_SEI->seiRecoveryPoint.broken_link_flag, bitstream);
01657 u_v (2, "SEI: changing_slice_group_idc", p_SEI->seiRecoveryPoint.changing_slice_group_idc, bitstream);
01658
01659
01660
01661 #ifdef PRINT_RECOVERY_POINT
01662 printf(" recovery_frame_cnt %d \n", p_SEI->seiRecoveryPoint.recovery_frame_cnt);
01663 printf(" exact_match_flag %d \n", p_SEI->seiRecoveryPoint.exact_match_flag);
01664 printf(" broken_link_flag %d \n", p_SEI->seiRecoveryPoint.broken_link_flag);
01665 printf(" changing_slice_group_idc %d \n", p_SEI->seiRecoveryPoint.changing_slice_group_idc);
01666 printf(" %d %d \n", bitstream->byte_pos, bitstream->bits_to_go);
01667
01668 #undef PRINT_RECOVERY_POINT
01669 #endif
01670
01671 if ( bitstream->bits_to_go != 8 )
01672 {
01673 (bitstream->byte_buf) <<= 1;
01674 bitstream->byte_buf |= 1;
01675 bitstream->bits_to_go--;
01676 if ( bitstream->bits_to_go != 0 )
01677 (bitstream->byte_buf) <<= (bitstream->bits_to_go);
01678 bitstream->bits_to_go = 8;
01679 bitstream->streamBuffer[bitstream->byte_pos++]=bitstream->byte_buf;
01680 bitstream->byte_buf = 0;
01681 }
01682 p_SEI->seiRecoveryPoint.payloadSize = bitstream->byte_pos;
01683 }
01684
01685 void CloseRandomAccess(SEIParameters *p_SEI)
01686 {
01687 if (p_SEI->seiRecoveryPoint.data)
01688 {
01689 free(p_SEI->seiRecoveryPoint.data->streamBuffer);
01690 free(p_SEI->seiRecoveryPoint.data);
01691 }
01692 p_SEI->seiRecoveryPoint.data = NULL;
01693 }
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704 static int ParseToneMappingConfigFile(SEIParameters *p_SEI, InputParameters *p_Inp, ToneMappingSEI *pSeiToneMapping)
01705 {
01706 int i;
01707 int ret;
01708 FILE* fp;
01709 char buf[1024];
01710 unsigned int tmp;
01711
01712 printf ("Parsing Tone mapping cfg file %s ..........\n\n", p_Inp->ToneMappingFile);
01713 if ((fp = fopen(p_Inp->ToneMappingFile, "r")) == NULL)
01714 {
01715 fprintf(stderr, "Tone mapping config file %s is not found, disable tone mapping SEI\n", p_Inp->ToneMappingFile);
01716 p_SEI->seiHasTone_mapping=FALSE;
01717
01718 return 1;
01719 }
01720
01721
01722 while (fscanf(fp, "%s", buf)!=EOF)
01723 {
01724 ret = 1;
01725 if (strcmp(buf, "tone_map_id")==0)
01726 {
01727 ret = fscanf(fp, " = %ud\n", &(pSeiToneMapping->tone_map_id));
01728 }
01729 else if (strcmp(buf, "tone_map_cancel_flag")==0)
01730 {
01731 ret = fscanf(fp, " = %ud\n", &tmp);
01732 pSeiToneMapping->tone_map_cancel_flag = (unsigned char) (tmp ? 1 : 0);
01733 }
01734 else if (strcmp(buf, "tone_map_repetition_period")==0)
01735 {
01736 ret = fscanf(fp, " = %ud\n", &(pSeiToneMapping->tone_map_repetition_period));
01737 }
01738 else if (strcmp(buf, "coded_data_bit_depth")==0)
01739 {
01740 ret = fscanf(fp, " = %ud\n", &tmp);
01741 pSeiToneMapping->coded_data_bit_depth = (unsigned char) tmp;
01742 }
01743 else if (strcmp(buf, "sei_bit_depth")==0)
01744 {
01745 ret = fscanf(fp, " = %ud\n", &tmp);
01746 pSeiToneMapping->sei_bit_depth = (unsigned char) tmp;
01747 }
01748 else if (strcmp(buf, "model_id")==0)
01749 {
01750 ret = fscanf(fp, " = %ud\n", &(pSeiToneMapping->model_id));
01751 }
01752
01753 else if (strcmp(buf, "min_value")==0)
01754 {
01755 ret = fscanf(fp, " = %d\n", &(pSeiToneMapping->min_value));
01756 }
01757 else if (strcmp(buf, "max_value")==0)
01758 {
01759 ret = fscanf(fp, " = %d\n", &(pSeiToneMapping->max_value));
01760 }
01761
01762 else if (strcmp(buf, "sigmoid_midpoint")==0)
01763 {
01764 ret = fscanf(fp, " = %d\n", &(pSeiToneMapping->sigmoid_midpoint));
01765 }
01766 else if (strcmp(buf, "sigmoid_width")==0)
01767 {
01768 ret = fscanf(fp, " = %d\n", &(pSeiToneMapping->sigmoid_width));
01769 }
01770
01771 else if (strcmp(buf, "start_of_coded_interval")==0)
01772 {
01773 int max_output_num = 1<<(pSeiToneMapping->sei_bit_depth);
01774 ret = fscanf(fp, " = ");
01775 if (ret!=0)
01776 {
01777 error ("ParseToneMappingConfigFile: error parsing tone mapping config file",500);
01778 }
01779 for (i=0; i < max_output_num; i++)
01780 {
01781 ret = fscanf(fp, "%d\n", &(pSeiToneMapping->start_of_coded_interval[i]));
01782 if (ret!=1)
01783 {
01784 error ("ParseToneMappingConfigFile: error parsing tone mapping config file",500);
01785 }
01786 }
01787 }
01788
01789 else if (strcmp(buf, "num_pivots")==0)
01790 {
01791 ret = fscanf(fp, " = %d\n", &(pSeiToneMapping->num_pivots));
01792 }
01793
01794 else if (strcmp(buf, "coded_pivot_value")==0)
01795 {
01796 ret = fscanf(fp, " = ");
01797 if (ret!=0)
01798 {
01799 error ("ParseToneMappingConfigFile: error parsing tone mapping config file",500);
01800 }
01801 for (i=0; i < pSeiToneMapping->num_pivots; i++)
01802 {
01803 ret = fscanf(fp, "%d\n", &(pSeiToneMapping->coded_pivot_value[i]));
01804 if (ret!=1)
01805 {
01806 error ("ParseToneMappingConfigFile: error parsing tone mapping config file",500);
01807 }
01808 }
01809 }
01810 else if (strcmp(buf, "sei_pivot_value")==0)
01811 {
01812 ret = fscanf(fp, " = ");
01813 if (ret!=0)
01814 {
01815 error ("ParseToneMappingConfigFile: error parsing tone mapping config file",500);
01816 }
01817 for (i=0; i < pSeiToneMapping->num_pivots; i++)
01818 {
01819 ret = fscanf(fp, "%d\n", &(pSeiToneMapping->sei_pivot_value[i]));
01820 if (ret!=1)
01821 {
01822 error ("ParseToneMappingConfigFile: error parsing tone mapping config file",500);
01823 }
01824 }
01825 }
01826 else
01827 {
01828
01829 if (NULL == fgets(buf, sizeof(buf), fp))
01830 {
01831 error ("ParseToneMappingConfigFile: error parsing tone mapping config file",500);
01832 }
01833 }
01834 if (ret!=1)
01835 {
01836 error ("ParseToneMappingConfigFile: error parsing tone mapping config file",500);
01837 }
01838 }
01839
01840 fclose(fp);
01841
01842 return 0;
01843 }
01844
01845 static void InitToneMapping(SEIParameters *p_SEI, InputParameters *p_Inp)
01846 {
01847 if (p_Inp->ToneMappingSEIPresentFlag == 0)
01848 {
01849 p_SEI->seiHasTone_mapping = FALSE;
01850 return;
01851 }
01852 else
01853 p_SEI->seiHasTone_mapping = TRUE;
01854
01855 p_SEI->seiToneMapping.data = malloc( sizeof(Bitstream) );
01856 if( p_SEI->seiToneMapping.data == NULL ) no_mem_exit("InitToneMapping: seiToneMapping.data");
01857 p_SEI->seiToneMapping.data->streamBuffer = malloc(MAXRTPPAYLOADLEN);
01858 if( p_SEI->seiToneMapping.data->streamBuffer == NULL ) no_mem_exit("InitToneMapping: seiToneMapping.data->streamBuffer");
01859 memset( p_SEI->seiToneMapping.data->streamBuffer, 0, MAXRTPPAYLOADLEN);
01860 p_SEI->seiToneMapping.data->bits_to_go = 8;
01861 p_SEI->seiToneMapping.data->byte_pos = 0;
01862 p_SEI->seiToneMapping.data->byte_buf = 0;
01863 p_SEI->seiToneMapping.payloadSize = 0;
01864
01865
01866 ParseToneMappingConfigFile(p_SEI, p_Inp, &p_SEI->seiToneMapping);
01867 }
01868
01869 static void FinalizeToneMapping(ImageParameters *p_Img)
01870 {
01871 SEIParameters *p_SEI = p_Img->p_SEI;
01872
01873 Bitstream *bitstream = p_SEI->seiToneMapping.data;
01874 int i;
01875
01876 ue_v("SEI: tone_map_id" , p_SEI->seiToneMapping.tone_map_id, bitstream);
01877 u_1("SEI: tone_map_cancel_flag" , p_SEI->seiToneMapping.tone_map_cancel_flag, bitstream);
01878
01879 #ifdef PRINT_TONE_MAPPING
01880 printf("frame %d: Tone-mapping SEI message\n", p_Img->frame_num);
01881 printf("tone_map_id = %d\n", p_SEI->seiToneMapping.tone_map_id);
01882 printf("tone_map_cancel_flag = %d\n", p_SEI->seiToneMapping.tone_map_cancel_flag);
01883 #endif
01884 if (!p_SEI->seiToneMapping.tone_map_cancel_flag)
01885 {
01886 ue_v( "SEI: tone_map_repetition_period", p_SEI->seiToneMapping.tone_map_repetition_period, bitstream);
01887 u_v (8,"SEI: coded_data_bit_depth" , p_SEI->seiToneMapping.coded_data_bit_depth, bitstream);
01888 u_v (8,"SEI: sei_bit_depth" , p_SEI->seiToneMapping.sei_bit_depth, bitstream);
01889 ue_v( "SEI: model_id" , p_SEI->seiToneMapping.model_id, bitstream);
01890
01891 #ifdef PRINT_TONE_MAPPING
01892 printf("tone_map_repetition_period = %d\n", p_SEI->seiToneMapping.tone_map_repetition_period);
01893 printf("coded_data_bit_depth = %d\n", p_SEI->seiToneMapping.coded_data_bit_depth);
01894 printf("sei_bit_depth = %d\n", p_SEI->seiToneMapping.sei_bit_depth);
01895 printf("model_id = %d\n", p_SEI->seiToneMapping.model_id);
01896 #endif
01897 if (p_SEI->seiToneMapping.model_id == 0)
01898 {
01899 u_v (32,"SEI: min_value", p_SEI->seiToneMapping.min_value, bitstream);
01900 u_v (32,"SEI: min_value", p_SEI->seiToneMapping.max_value, bitstream);
01901 #ifdef PRINT_TONE_MAPPING
01902 printf("min_value = %d, max_value = %d\n", p_SEI->seiToneMapping.min_value, p_SEI->seiToneMapping.max_value);
01903 #endif
01904 }
01905 else if (p_SEI->seiToneMapping.model_id == 1)
01906 {
01907 u_v (32,"SEI: sigmoid_midpoint", p_SEI->seiToneMapping.sigmoid_midpoint, bitstream);
01908 u_v (32,"SEI: sigmoid_width", p_SEI->seiToneMapping.sigmoid_width, bitstream);
01909 #ifdef PRINT_TONE_MAPPING
01910 printf("sigmoid_midpoint = %d, sigmoid_width = %d\n", p_SEI->seiToneMapping.sigmoid_midpoint, p_SEI->seiToneMapping.sigmoid_width);
01911 #endif
01912 }
01913 else if (p_SEI->seiToneMapping.model_id == 2)
01914 {
01915 int bit_depth_val = 1 << p_SEI->seiToneMapping.sei_bit_depth;
01916 for (i=0; i<bit_depth_val; i++)
01917 {
01918 u_v((((p_SEI->seiToneMapping.coded_data_bit_depth+7)>>3)<<3), "SEI: start_of_coded_interval", p_SEI->seiToneMapping.start_of_coded_interval[i], bitstream);
01919 #ifdef PRINT_TONE_MAPPING
01920
01921 #endif
01922 }
01923 }
01924 else if (p_SEI->seiToneMapping.model_id == 3)
01925 {
01926 u_v (16,"SEI: num_pivots", p_SEI->seiToneMapping.num_pivots, bitstream);
01927 #ifdef PRINT_TONE_MAPPING
01928 printf("num_pivots = %d\n", p_SEI->seiToneMapping.num_pivots);
01929 #endif
01930 for (i=0; i < p_SEI->seiToneMapping.num_pivots; i++)
01931 {
01932 u_v( (((p_SEI->seiToneMapping.coded_data_bit_depth+7)>>3)<<3), "SEI: coded_pivot_value", p_SEI->seiToneMapping.coded_pivot_value[i], bitstream);
01933 u_v( (((p_SEI->seiToneMapping.sei_bit_depth+7)>>3)<<3), "SEI: sei_pivot_value", p_SEI->seiToneMapping.sei_pivot_value[i], bitstream);
01934 #ifdef PRINT_TONE_MAPPING
01935 printf("coded_pivot_value[%d] = %d, sei_pivot_value[%d] = %d\n", i, p_SEI->seiToneMapping.coded_pivot_value[i], i, p_SEI->seiToneMapping.sei_pivot_value[i]);
01936 #endif
01937 }
01938 }
01939 }
01940
01941
01942 if ( bitstream->bits_to_go != 8 )
01943 {
01944 (bitstream->byte_buf) <<= 1;
01945 bitstream->byte_buf |= 1;
01946 bitstream->bits_to_go--;
01947 if ( bitstream->bits_to_go != 0 )
01948 (bitstream->byte_buf) <<= (bitstream->bits_to_go);
01949 bitstream->bits_to_go = 8;
01950 bitstream->streamBuffer[bitstream->byte_pos++]=bitstream->byte_buf;
01951 bitstream->byte_buf = 0;
01952 }
01953 p_SEI->seiToneMapping.payloadSize = bitstream->byte_pos;
01954 }
01955
01956
01957 void UpdateToneMapping(SEIParameters *p_SEI)
01958 {
01959
01960
01961
01962 }
01963
01964 static void ClearToneMapping(SEIParameters *p_SEI)
01965 {
01966 memset( p_SEI->seiToneMapping.data->streamBuffer, 0, MAXRTPPAYLOADLEN);
01967 p_SEI->seiToneMapping.data->bits_to_go = 8;
01968 p_SEI->seiToneMapping.data->byte_pos = 0;
01969 p_SEI->seiToneMapping.data->byte_buf = 0;
01970 p_SEI->seiToneMapping.payloadSize = 0;
01971
01972 p_SEI->seiHasTone_mapping=FALSE;
01973 }
01974
01975 static void CloseToneMapping(SEIParameters *p_SEI)
01976 {
01977
01978 if (p_SEI->seiToneMapping.data)
01979 {
01980 free(p_SEI->seiToneMapping.data->streamBuffer);
01981 free(p_SEI->seiToneMapping.data);
01982 }
01983 p_SEI->seiToneMapping.data = NULL;
01984 p_SEI->seiHasTone_mapping = FALSE;
01985 }
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995
01996 static void InitPostFilterHints(SEIParameters *p_SEI)
01997 {
01998 p_SEI->seiPostFilterHints.data = malloc( sizeof(Bitstream) );
01999 if( p_SEI->seiPostFilterHints.data == NULL ) no_mem_exit("InitPostFilterHints: p_SEI->seiPostFilterHints.data");
02000 p_SEI->seiPostFilterHints.data->streamBuffer = malloc(MAXRTPPAYLOADLEN);
02001 if( p_SEI->seiPostFilterHints.data->streamBuffer == NULL ) no_mem_exit("InitPostFilterHints: p_SEI->seiPostFilterHints.data->streamBuffer");
02002 ClearPostFilterHints(p_SEI);
02003 }
02004
02005 static void ClearPostFilterHints(SEIParameters *p_SEI)
02006 {
02007 memset( p_SEI->seiPostFilterHints.data->streamBuffer, 0, MAXRTPPAYLOADLEN);
02008 p_SEI->seiPostFilterHints.data->bits_to_go = 8;
02009 p_SEI->seiPostFilterHints.data->byte_pos = 0;
02010 p_SEI->seiPostFilterHints.data->byte_buf = 0;
02011 p_SEI->seiPostFilterHints.payloadSize = 0;
02012
02013 p_SEI->seiPostFilterHints.filter_hint_size_y = 0;
02014 p_SEI->seiPostFilterHints.filter_hint_size_x = 0;
02015 p_SEI->seiPostFilterHints.filter_hint_type = 0;
02016 p_SEI->seiPostFilterHints.additional_extension_flag = 0;
02017 }
02018
02019 void UpdatePostFilterHints(SEIParameters *p_SEI)
02020 {
02021 unsigned int color_component, cx, cy;
02022 p_SEI->seiPostFilterHints.filter_hint_type = 0;
02023 p_SEI->seiPostFilterHints.filter_hint_size_y = p_SEI->seiPostFilterHints.filter_hint_size_x = 5;
02024 get_mem3Dint(&p_SEI->seiPostFilterHints.filter_hint, 3, p_SEI->seiPostFilterHints.filter_hint_size_y, p_SEI->seiPostFilterHints.filter_hint_size_x);
02025
02026 for (color_component = 0; color_component < 3; color_component ++)
02027 for (cy = 0; cy < p_SEI->seiPostFilterHints.filter_hint_size_y; cy ++)
02028 for (cx = 0; cx < p_SEI->seiPostFilterHints.filter_hint_size_x; cx ++)
02029 p_SEI->seiPostFilterHints.filter_hint[color_component][cy][cx] = 1;
02030
02031 p_SEI->seiPostFilterHints.additional_extension_flag = 0;
02032 }
02033
02034 static void FinalizePostFilterHints(SEIParameters *p_SEI)
02035 {
02036 Bitstream *bitstream = p_SEI->seiPostFilterHints.data;
02037 unsigned int color_component, cx, cy;
02038
02039 ue_v( "SEI: post_filter_hint_size_y", p_SEI->seiPostFilterHints.filter_hint_size_y, bitstream);
02040 ue_v( "SEI: post_filter_hint_size_x", p_SEI->seiPostFilterHints.filter_hint_size_x, bitstream);
02041 u_v (2,"SEI: post_filter_hint_type", p_SEI->seiPostFilterHints.filter_hint_type, bitstream);
02042
02043 for (color_component = 0; color_component < 3; color_component ++)
02044 for (cy = 0; cy < p_SEI->seiPostFilterHints.filter_hint_size_y; cy ++)
02045 for (cx = 0; cx < p_SEI->seiPostFilterHints.filter_hint_size_x; cx ++)
02046 se_v("SEI: post_filter_hints", p_SEI->seiPostFilterHints.filter_hint[color_component][cy][cx], bitstream);
02047
02048 u_1 ("SEI: post_filter_additional_extension_flag", p_SEI->seiPostFilterHints.additional_extension_flag, bitstream);
02049
02050
02051 #ifdef PRINT_POST_FILTER_HINTS
02052 printf(" post_filter_hint_size_y %d \n", p_SEI->seiPostFilterHints.filter_hint_size_y);
02053 printf(" post_filter_hint_size_x %d \n", p_SEI->seiPostFilterHints.filter_hint_size_x);
02054 printf(" post_filter_hint_type %d \n", p_SEI->seiPostFilterHints.filter_hint_type);
02055 for (color_component = 0; color_component < 3; color_component ++)
02056 for (cy = 0; cy < p_SEI->seiPostFilterHints.filter_hint_size_y; cy ++)
02057 for (cx = 0; cx < p_SEI->seiPostFilterHints.filter_hint_size_x; cx ++)
02058 printf(" post_filter_hint[%d][%d][%d] %d \n", color_component, cy, cx, filter_hint[color_component][cy][cx]);
02059
02060 printf(" additional_extension_flag %d \n", p_SEI->seiPostFilterHints.additional_extension_flag);
02061
02062 #undef PRINT_POST_FILTER_HINTS
02063 #endif
02064
02065 if ( bitstream->bits_to_go != 8 )
02066 {
02067 (bitstream->byte_buf) <<= 1;
02068 bitstream->byte_buf |= 1;
02069 bitstream->bits_to_go--;
02070 if ( bitstream->bits_to_go != 0 )
02071 (bitstream->byte_buf) <<= (bitstream->bits_to_go);
02072 bitstream->bits_to_go = 8;
02073 bitstream->streamBuffer[bitstream->byte_pos++]=bitstream->byte_buf;
02074 bitstream->byte_buf = 0;
02075 }
02076 p_SEI->seiPostFilterHints.payloadSize = bitstream->byte_pos;
02077 }
02078
02079 static void ClosePostFilterHints(SEIParameters *p_SEI)
02080 {
02081 if (p_SEI->seiPostFilterHints.data)
02082 {
02083 free(p_SEI->seiPostFilterHints.data->streamBuffer);
02084 free(p_SEI->seiPostFilterHints.data);
02085 if (p_SEI->seiPostFilterHints.filter_hint)
02086 free_mem3Dint(p_SEI->seiPostFilterHints.filter_hint);
02087 }
02088 p_SEI->seiPostFilterHints.data = NULL;
02089 }
02090
02091
02092
02093
02094
02095
02096
02097 int Write_SEI_NALU(ImageParameters *p_Img, int len)
02098 {
02099 NALU_t *nalu = NULL;
02100 int RBSPlen = 0;
02101 int NALUlen;
02102 byte *rbsp;
02103
02104 if (HaveAggregationSEI(p_Img))
02105 {
02106 SEIParameters *p_SEI = p_Img->p_SEI;
02107
02108 nalu = AllocNALU(MAXNALUSIZE);
02109 rbsp = p_SEI->sei_message[AGGREGATION_SEI].data;
02110 RBSPlen = p_SEI->sei_message[AGGREGATION_SEI].payloadSize;
02111 NALUlen = RBSPtoNALU (rbsp, nalu, RBSPlen, NALU_TYPE_SEI, NALU_PRIORITY_LOW, 1);
02112 nalu->startcodeprefix_len = 4;
02113
02114 len += p_Img->WriteNALU (p_Img, nalu);
02115 FreeNALU (nalu);
02116 }
02117
02118 return len;
02119 }
02120
02121
02122
02123
02124
02125
02126
02127
02128 void InitBufferingPeriod(ImageParameters *p_Img)
02129 {
02130 SEIParameters *p_SEI = p_Img->p_SEI;
02131 p_SEI->seiBufferingPeriod.data = malloc( sizeof(Bitstream) );
02132 if( p_SEI->seiBufferingPeriod.data == NULL )
02133 no_mem_exit("InitBufferingPeriod: seiBufferingPeriod.data");
02134
02135 p_SEI->seiBufferingPeriod.data->streamBuffer = malloc(MAXRTPPAYLOADLEN);
02136 if( p_SEI->seiBufferingPeriod.data->streamBuffer == NULL )
02137 no_mem_exit("InitBufferingPeriod: seiBufferingPeriod.data->streamBuffer");
02138
02139 ClearBufferingPeriod(p_SEI, p_Img->active_sps);
02140 }
02141
02142 void ClearBufferingPeriod(SEIParameters *p_SEI, seq_parameter_set_rbsp_t *active_sps)
02143 {
02144 unsigned int SchedSelIdx;
02145 memset( p_SEI->seiBufferingPeriod.data->streamBuffer, 0, MAXRTPPAYLOADLEN);
02146
02147 p_SEI->seiBufferingPeriod.data->bits_to_go = 8;
02148 p_SEI->seiBufferingPeriod.data->byte_pos = 0;
02149 p_SEI->seiBufferingPeriod.data->byte_buf = 0;
02150 p_SEI->seiBufferingPeriod.payloadSize = 0;
02151
02152 p_SEI->seiBufferingPeriod.seq_parameter_set_id = active_sps->seq_parameter_set_id;
02153 if ( active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag )
02154 {
02155 for ( SchedSelIdx = 0; SchedSelIdx <= active_sps->vui_seq_parameters.nal_hrd_parameters.cpb_cnt_minus1; SchedSelIdx++ )
02156 {
02157 p_SEI->seiBufferingPeriod.nal_initial_cpb_removal_delay[SchedSelIdx] = 0;
02158 p_SEI->seiBufferingPeriod.nal_initial_cpb_removal_delay_offset[SchedSelIdx] = 0;
02159 }
02160 }
02161 if ( active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag )
02162 {
02163 for ( SchedSelIdx = 0; SchedSelIdx <= active_sps->vui_seq_parameters.vcl_hrd_parameters.cpb_cnt_minus1; SchedSelIdx++ )
02164 {
02165 p_SEI->seiBufferingPeriod.vcl_initial_cpb_removal_delay[SchedSelIdx] = 0;
02166 p_SEI->seiBufferingPeriod.vcl_initial_cpb_removal_delay_offset[SchedSelIdx] = 0;
02167 }
02168 }
02169
02170 p_SEI->seiHasBuffering_period = FALSE;
02171 }
02172
02173 void UpdateBufferingPeriod(ImageParameters *p_Img, InputParameters *p_Inp)
02174 {
02175 SEIParameters *p_SEI = p_Img->p_SEI;
02176 p_SEI->seiHasBuffering_period = FALSE;
02177 }
02178
02179 static void FinalizeBufferingPeriod(SEIParameters *p_SEI, seq_parameter_set_rbsp_t *active_sps)
02180 {
02181 unsigned int SchedSelIdx;
02182 Bitstream *bitstream = p_SEI->seiBufferingPeriod.data;
02183
02184 ue_v( "SEI: seq_parameter_set_id", p_SEI->seiBufferingPeriod.seq_parameter_set_id, bitstream);
02185 if ( active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag )
02186 {
02187 for ( SchedSelIdx = 0; SchedSelIdx <= active_sps->vui_seq_parameters.nal_hrd_parameters.cpb_cnt_minus1; SchedSelIdx++ )
02188 {
02189 u_v( active_sps->vui_seq_parameters.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1,
02190 "SEI: initial_cpb_removal_delay", p_SEI->seiBufferingPeriod.nal_initial_cpb_removal_delay[SchedSelIdx], bitstream);
02191 u_v( active_sps->vui_seq_parameters.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1,
02192 "SEI: initial_cpb_removal_delay_offset", p_SEI->seiBufferingPeriod.nal_initial_cpb_removal_delay_offset[SchedSelIdx], bitstream);
02193 }
02194 }
02195 if ( active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag )
02196 {
02197 for ( SchedSelIdx = 0; SchedSelIdx <= active_sps->vui_seq_parameters.vcl_hrd_parameters.cpb_cnt_minus1; SchedSelIdx++ )
02198 {
02199 u_v( active_sps->vui_seq_parameters.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1,
02200 "SEI: initial_cpb_removal_delay", p_SEI->seiBufferingPeriod.vcl_initial_cpb_removal_delay[SchedSelIdx], bitstream);
02201 u_v( active_sps->vui_seq_parameters.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1,
02202 "SEI: initial_cpb_removal_delay_offset", p_SEI->seiBufferingPeriod.vcl_initial_cpb_removal_delay_offset[SchedSelIdx], bitstream);
02203 }
02204 }
02205
02206
02207 if ( bitstream->bits_to_go != 8 )
02208 {
02209 (bitstream->byte_buf) <<= 1;
02210 bitstream->byte_buf |= 1;
02211 bitstream->bits_to_go--;
02212 if ( bitstream->bits_to_go != 0 )
02213 (bitstream->byte_buf) <<= (bitstream->bits_to_go);
02214 bitstream->bits_to_go = 8;
02215 bitstream->streamBuffer[bitstream->byte_pos++]=bitstream->byte_buf;
02216 bitstream->byte_buf = 0;
02217 }
02218 p_SEI->seiBufferingPeriod.payloadSize = bitstream->byte_pos;
02219 }
02220
02221 static void CloseBufferingPeriod(SEIParameters *p_SEI)
02222 {
02223 if (p_SEI->seiBufferingPeriod.data)
02224 {
02225 free(p_SEI->seiBufferingPeriod.data->streamBuffer);
02226 free(p_SEI->seiBufferingPeriod.data);
02227 }
02228 p_SEI->seiBufferingPeriod.data = NULL;
02229 }
02230
02231
02232
02233
02234
02235
02236
02237 void InitPicTiming(SEIParameters *p_SEI)
02238 {
02239 p_SEI->seiPicTiming.data = malloc( sizeof(Bitstream) );
02240 if( p_SEI->seiPicTiming.data == NULL )
02241 no_mem_exit("InitPicTiming: seiPicTiming.data");
02242
02243 p_SEI->seiPicTiming.data->streamBuffer = malloc(MAXRTPPAYLOADLEN);
02244 if( p_SEI->seiPicTiming.data->streamBuffer == NULL )
02245 no_mem_exit("InitPicTiming: seiPicTiming.data->streamBuffer");
02246
02247 ClearPicTiming(p_SEI);
02248 }
02249
02250
02251
02252
02253
02254
02255
02256 void ClearPicTiming(SEIParameters *p_SEI)
02257 {
02258 memset( p_SEI->seiPicTiming.data->streamBuffer, 0, MAXRTPPAYLOADLEN);
02259
02260 p_SEI->seiPicTiming.data->bits_to_go = 8;
02261 p_SEI->seiPicTiming.data->byte_pos = 0;
02262 p_SEI->seiPicTiming.data->byte_buf = 0;
02263 p_SEI->seiPicTiming.payloadSize = 0;
02264
02265
02266 p_SEI->seiPicTiming.cpb_removal_delay = 0;
02267 p_SEI->seiPicTiming.dpb_output_delay = 0;
02268 p_SEI->seiPicTiming.pic_struct = 0;
02269 memset(p_SEI->seiPicTiming.clock_timestamp_flag, 0, MAX_PIC_STRUCT_VALUE * sizeof(Boolean) );
02270 p_SEI->seiPicTiming.ct_type = 0;
02271 p_SEI->seiPicTiming.nuit_field_based_flag = FALSE;
02272 p_SEI->seiPicTiming.counting_type = 0;
02273 p_SEI->seiPicTiming.full_timestamp_flag = FALSE;
02274 p_SEI->seiPicTiming.discontinuity_flag = FALSE;
02275 p_SEI->seiPicTiming.cnt_dropped_flag = FALSE;
02276 p_SEI->seiPicTiming.n_frames = 0;
02277 p_SEI->seiPicTiming.seconds_value = 0;
02278 p_SEI->seiPicTiming.minutes_value = 0;
02279 p_SEI->seiPicTiming.hours_value = 0;
02280 p_SEI->seiPicTiming.seconds_flag = FALSE;
02281 p_SEI->seiPicTiming.minutes_flag = FALSE;
02282 p_SEI->seiPicTiming.hours_flag = FALSE;
02283 p_SEI->seiPicTiming.time_offset = 0;
02284
02285 p_SEI->seiHasPicTiming_info = FALSE;
02286 }
02287
02288
02289
02290
02291
02292
02293
02294 void UpdatePicTiming(ImageParameters *p_Img, InputParameters *p_Inp)
02295 {
02296 SEIParameters *p_SEI = p_Img->p_SEI;
02297 p_SEI->seiHasPicTiming_info = FALSE;
02298 }
02299
02300
02301
02302
02303
02304
02305
02306 static void FinalizePicTiming(ImageParameters *p_Img)
02307 {
02308 SEIParameters *p_SEI = p_Img->p_SEI;
02309 seq_parameter_set_rbsp_t *active_sps = p_Img->active_sps;
02310
02311 Bitstream *bitstream = p_SEI->seiPicTiming.data;
02312
02313 Boolean CpbDpbDelaysPresentFlag = (Boolean) (active_sps->vui_parameters_present_flag
02314 && ( (active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag != 0)
02315 ||(active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag != 0)));
02316 hrd_parameters_t *hrd = NULL;
02317
02318 assert( active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag || active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag );
02319 if (active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag)
02320 hrd = &(active_sps->vui_seq_parameters.vcl_hrd_parameters);
02321 else if (active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag)
02322 hrd = &(active_sps->vui_seq_parameters.nal_hrd_parameters);
02323 else
02324 error ("HRD structures not properly created.",-1);
02325
02326 if ( CpbDpbDelaysPresentFlag )
02327 {
02328 u_v( hrd->cpb_removal_delay_length_minus1 + 1, "SEI: cpb_removal_delay", p_SEI->seiPicTiming.cpb_removal_delay, bitstream);
02329 u_v( hrd->dpb_output_delay_length_minus1 + 1, "SEI: dpb_output_delay", p_SEI->seiPicTiming.dpb_output_delay, bitstream);
02330 }
02331 if ( active_sps->vui_seq_parameters.pic_struct_present_flag )
02332 {
02333 int NumClockTS = 0, i;
02334 int bottom_field_flag = (p_Img->structure == BOTTOM_FIELD);
02335
02336 u_v( 4, "SEI: pic_struct", p_SEI->seiPicTiming.pic_struct, bitstream);
02337
02338 switch( p_SEI->seiPicTiming.pic_struct )
02339 {
02340 case 0:
02341 default:
02342
02343 assert( p_Img->fld_flag == FALSE );
02344 NumClockTS = 1;
02345 break;
02346 case 1:
02347
02348 assert( (p_Img->fld_flag == TRUE) && (bottom_field_flag == FALSE) );
02349 NumClockTS = 1;
02350 break;
02351 case 2:
02352
02353 assert( (p_Img->fld_flag == TRUE) && (bottom_field_flag == TRUE) );
02354 NumClockTS = 1;
02355 break;
02356 case 3:
02357
02358 case 4:
02359
02360 assert( p_Img->fld_flag == FALSE );
02361 NumClockTS = 2;
02362 break;
02363 case 5:
02364
02365 case 6:
02366
02367 assert( p_Img->fld_flag == FALSE );
02368 NumClockTS = 3;
02369 case 7:
02370
02371 assert( (p_Img->fld_flag == FALSE) && active_sps->vui_seq_parameters.fixed_frame_rate_flag == 1 );
02372 NumClockTS = 2;
02373 break;
02374 case 8:
02375
02376 assert( (p_Img->fld_flag == FALSE) && active_sps->vui_seq_parameters.fixed_frame_rate_flag == 1 );
02377 NumClockTS = 3;
02378 break;
02379 }
02380 for ( i = 0; i < NumClockTS; i++ )
02381 {
02382 u_1( "SEI: clock_timestamp_flag", p_SEI->seiPicTiming.clock_timestamp_flag[i], bitstream);
02383 if ( p_SEI->seiPicTiming.clock_timestamp_flag[i] )
02384 {
02385 u_v( 2, "SEI: ct_type", p_SEI->seiPicTiming.ct_type, bitstream);
02386 u_1( "SEI: nuit_field_based_flag", p_SEI->seiPicTiming.nuit_field_based_flag, bitstream);
02387 u_v( 5, "SEI: counting_type", p_SEI->seiPicTiming.counting_type, bitstream);
02388 u_1( "SEI: full_timestamp_flag", p_SEI->seiPicTiming.full_timestamp_flag, bitstream);
02389 u_1( "SEI: discontinuity_flag", p_SEI->seiPicTiming.discontinuity_flag, bitstream);
02390 u_1( "SEI: cnt_dropped_flag", p_SEI->seiPicTiming.cnt_dropped_flag, bitstream);
02391 u_v( 8, "SEI: n_frames", p_SEI->seiPicTiming.n_frames, bitstream);
02392
02393 if ( p_SEI->seiPicTiming.full_timestamp_flag )
02394 {
02395 u_v( 6, "SEI: seconds_value", p_SEI->seiPicTiming.seconds_value, bitstream);
02396 u_v( 6, "SEI: minutes_value", p_SEI->seiPicTiming.minutes_value, bitstream);
02397 u_v( 5, "SEI: hours_value", p_SEI->seiPicTiming.hours_value, bitstream);
02398 }
02399 else
02400 {
02401 u_1( "SEI: seconds_flag", p_SEI->seiPicTiming.seconds_flag, bitstream);
02402 if (p_SEI->seiPicTiming.seconds_flag)
02403 {
02404 u_v( 6, "SEI: seconds_value", p_SEI->seiPicTiming.seconds_value, bitstream);
02405 u_1( "SEI: minutes_flag", p_SEI->seiPicTiming.minutes_flag, bitstream);
02406 if (p_SEI->seiPicTiming.minutes_flag)
02407 {
02408 u_v( 6, "SEI: minutes_value", p_SEI->seiPicTiming.minutes_value, bitstream);
02409 u_1( "SEI: hours_flag", p_SEI->seiPicTiming.hours_flag, bitstream);
02410 if (p_SEI->seiPicTiming.hours_flag)
02411 {
02412 u_v( 5, "SEI: hours_value", p_SEI->seiPicTiming.hours_value, bitstream);
02413 }
02414 }
02415 }
02416 }
02417 if ( hrd->time_offset_length )
02418 {
02419 u_v( hrd->time_offset_length, "SEI: time_offset", p_SEI->seiPicTiming.time_offset, bitstream);
02420 }
02421 }
02422 }
02423 }
02424
02425
02426 if ( bitstream->bits_to_go != 8 )
02427 {
02428 (bitstream->byte_buf) <<= 1;
02429 bitstream->byte_buf |= 1;
02430 bitstream->bits_to_go--;
02431 if ( bitstream->bits_to_go != 0 )
02432 (bitstream->byte_buf) <<= (bitstream->bits_to_go);
02433 bitstream->bits_to_go = 8;
02434 bitstream->streamBuffer[bitstream->byte_pos++]=bitstream->byte_buf;
02435 bitstream->byte_buf = 0;
02436 }
02437 p_SEI->seiPicTiming.payloadSize = bitstream->byte_pos;
02438 }
02439
02440
02441
02442
02443
02444
02445
02446 static void ClosePicTiming(SEIParameters *p_SEI)
02447 {
02448 if (p_SEI->seiPicTiming.data)
02449 {
02450 free(p_SEI->seiPicTiming.data->streamBuffer);
02451 free(p_SEI->seiPicTiming.data);
02452 }
02453 p_SEI->seiPicTiming.data = NULL;
02454 }
02455
02456
02457
02458
02459
02460
02461
02462 static void InitDRPMRepetition(SEIParameters *p_SEI)
02463 {
02464 p_SEI->seiDRPMRepetition.data = malloc( sizeof(Bitstream) );
02465 if( p_SEI->seiDRPMRepetition.data == NULL )
02466 no_mem_exit("InitDRPMRepetition: p_SEI->seiDRPMRepetition.data");
02467
02468 p_SEI->seiDRPMRepetition.data->streamBuffer = malloc(MAXRTPPAYLOADLEN);
02469 if( p_SEI->seiDRPMRepetition.data->streamBuffer == NULL )
02470 no_mem_exit("InitDRPMRepetition: p_SEI->seiDRPMRepetition.data->streamBuffer");
02471
02472 ClearDRPMRepetition(p_SEI);
02473 }
02474
02475
02476
02477
02478
02479
02480
02481 void ClearDRPMRepetition(SEIParameters *p_SEI)
02482 {
02483 memset( p_SEI->seiDRPMRepetition.data->streamBuffer, 0, MAXRTPPAYLOADLEN);
02484
02485 p_SEI->seiDRPMRepetition.data->bits_to_go = 8;
02486 p_SEI->seiDRPMRepetition.data->byte_pos = 0;
02487 p_SEI->seiDRPMRepetition.data->byte_buf = 0;
02488 p_SEI->seiDRPMRepetition.payloadSize = 0;
02489
02490 p_SEI->seiDRPMRepetition.original_bottom_field_flag = FALSE;
02491 p_SEI->seiDRPMRepetition.original_field_pic_flag = FALSE;
02492 p_SEI->seiDRPMRepetition.original_frame_num = 0;
02493 p_SEI->seiDRPMRepetition.original_idr_flag = FALSE;
02494 if ( p_SEI->seiDRPMRepetition.dec_ref_pic_marking_buffer_saved != NULL )
02495 {
02496 free_drpm_buffer( p_SEI->seiDRPMRepetition.dec_ref_pic_marking_buffer_saved );
02497 p_SEI->seiDRPMRepetition.dec_ref_pic_marking_buffer_saved = NULL;
02498 }
02499
02500 p_SEI->seiHasDRPMRepetition_info = FALSE;
02501 }
02502
02503
02504
02505
02506
02507
02508
02509 void UpdateDRPMRepetition(SEIParameters *p_SEI)
02510 {
02511 if ( p_SEI->seiDRPMRepetition.dec_ref_pic_marking_buffer_saved != NULL )
02512 {
02513 p_SEI->seiHasDRPMRepetition_info = TRUE;
02514 }
02515 else
02516 {
02517 p_SEI->seiHasDRPMRepetition_info = FALSE;
02518 }
02519 }
02520
02521
02522
02523
02524
02525
02526
02527 static void FinalizeDRPMRepetition(ImageParameters *p_Img)
02528 {
02529 SEIParameters *p_SEI = p_Img->p_SEI;
02530 seq_parameter_set_rbsp_t *active_sps = p_Img->active_sps;
02531
02532 Bitstream *bitstream = p_SEI->seiDRPMRepetition.data;
02533
02534
02535 u_1( "SEI: original_idr_flag", p_SEI->seiDRPMRepetition.original_idr_flag, bitstream);
02536 ue_v( "SEI: original_frame_num", p_SEI->seiDRPMRepetition.original_frame_num, bitstream);
02537 if ( !active_sps->frame_mbs_only_flag )
02538 {
02539 u_1( "SEI: original_field_pic_flag", p_SEI->seiDRPMRepetition.original_field_pic_flag, bitstream);
02540 if ( p_SEI->seiDRPMRepetition.original_field_pic_flag )
02541 {
02542 u_1( "SEI: original_bottom_field_flag", p_SEI->seiDRPMRepetition.original_bottom_field_flag, bitstream);
02543 }
02544 }
02545
02546 dec_ref_pic_marking( bitstream,
02547 p_SEI->seiDRPMRepetition.dec_ref_pic_marking_buffer_saved,
02548 p_SEI->seiDRPMRepetition.original_idr_flag, 0, 0);
02549
02550
02551 if ( bitstream->bits_to_go != 8 )
02552 {
02553 (bitstream->byte_buf) <<= 1;
02554 bitstream->byte_buf |= 1;
02555 bitstream->bits_to_go--;
02556 if ( bitstream->bits_to_go != 0 )
02557 (bitstream->byte_buf) <<= (bitstream->bits_to_go);
02558 bitstream->bits_to_go = 8;
02559 bitstream->streamBuffer[bitstream->byte_pos++]=bitstream->byte_buf;
02560 bitstream->byte_buf = 0;
02561 }
02562 p_SEI->seiDRPMRepetition.payloadSize = bitstream->byte_pos;
02563 }
02564
02565
02566
02567
02568
02569
02570
02571 static void CloseDRPMRepetition(SEIParameters *p_SEI)
02572 {
02573 if (p_SEI->seiDRPMRepetition.data)
02574 {
02575 free(p_SEI->seiDRPMRepetition.data->streamBuffer);
02576 free(p_SEI->seiDRPMRepetition.data);
02577 }
02578 p_SEI->seiDRPMRepetition.data = NULL;
02579 if ( p_SEI->seiDRPMRepetition.dec_ref_pic_marking_buffer_saved != NULL )
02580 {
02581 free_drpm_buffer( p_SEI->seiDRPMRepetition.dec_ref_pic_marking_buffer_saved );
02582 p_SEI->seiDRPMRepetition.dec_ref_pic_marking_buffer_saved = NULL;
02583 }
02584 }
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597 void PrepareAggregationSEIMessage(ImageParameters *p_Img)
02598 {
02599 SEIParameters *p_SEI = p_Img->p_SEI;
02600 Boolean has_aggregation_sei_message = FALSE;
02601
02602 clear_sei_message(p_SEI, AGGREGATION_SEI);
02603
02604
02605
02606 if (p_SEI->seiHasSparePicture && p_Img->type != B_SLICE)
02607 {
02608 FinalizeSpareMBMap(p_Img);
02609 assert(p_SEI->seiSparePicturePayload.data->byte_pos == p_SEI->seiSparePicturePayload.payloadSize);
02610 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiSparePicturePayload.data->streamBuffer, p_SEI->seiSparePicturePayload.payloadSize, SEI_SPARE_PIC);
02611 has_aggregation_sei_message = TRUE;
02612 }
02613
02614 if (p_SEI->seiHasSubseqInfo)
02615 {
02616 FinalizeSubseqInfo(p_SEI, p_Img->layer);
02617 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiSubseqInfo[p_Img->layer].data->streamBuffer, p_SEI->seiSubseqInfo[p_Img->layer].payloadSize, SEI_SUB_SEQ_INFO);
02618 ClearSubseqInfoPayload(p_SEI, p_Img->layer);
02619 has_aggregation_sei_message = TRUE;
02620 }
02621
02622 if (p_SEI->seiHasSubseqLayerInfo && p_Img->number == 0)
02623 {
02624 FinalizeSubseqLayerInfo(p_SEI);
02625 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiSubseqLayerInfo.data, p_SEI->seiSubseqLayerInfo.payloadSize, SEI_SUB_SEQ_LAYER_CHARACTERISTICS);
02626 p_SEI->seiHasSubseqLayerInfo = FALSE;
02627 has_aggregation_sei_message = TRUE;
02628 }
02629
02630 if (p_SEI->seiHasSubseqChar)
02631 {
02632 FinalizeSubseqChar(p_SEI);
02633 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiSubseqChar.data->streamBuffer, p_SEI->seiSubseqChar.payloadSize, SEI_SUB_SEQ_CHARACTERISTICS);
02634 ClearSubseqCharPayload(p_SEI);
02635 has_aggregation_sei_message = TRUE;
02636 }
02637
02638 if (p_SEI->seiHasPanScanRectInfo)
02639 {
02640 FinalizePanScanRectInfo(p_SEI);
02641 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiPanScanRectInfo.data->streamBuffer, p_SEI->seiPanScanRectInfo.payloadSize, SEI_PAN_SCAN_RECT);
02642 ClearPanScanRectInfoPayload(p_SEI);
02643 has_aggregation_sei_message = TRUE;
02644 }
02645
02646 if (p_SEI->seiHasUser_data_unregistered_info)
02647 {
02648 FinalizeUser_data_unregistered(p_SEI);
02649 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiUser_data_unregistered.data->streamBuffer, p_SEI->seiUser_data_unregistered.payloadSize, SEI_USER_DATA_UNREGISTERED);
02650 ClearUser_data_unregistered(p_SEI);
02651 has_aggregation_sei_message = TRUE;
02652 }
02653
02654 if (p_SEI->seiHasUser_data_registered_itu_t_t35_info)
02655 {
02656 FinalizeUser_data_registered_itu_t_t35(p_SEI);
02657 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiUser_data_registered_itu_t_t35.data->streamBuffer, p_SEI->seiUser_data_registered_itu_t_t35.payloadSize, SEI_USER_DATA_REGISTERED_ITU_T_T35);
02658 ClearUser_data_registered_itu_t_t35(p_SEI);
02659 has_aggregation_sei_message = TRUE;
02660 }
02661
02662
02663
02664 if (p_SEI->seiHasSceneInformation)
02665 {
02666 FinalizeSceneInformation(p_SEI);
02667 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiSceneInformation.data->streamBuffer, p_SEI->seiSceneInformation.payloadSize, SEI_SCENE_INFO);
02668 has_aggregation_sei_message = TRUE;
02669 }
02670
02671 if (p_SEI->seiHasTone_mapping)
02672 {
02673 FinalizeToneMapping(p_Img);
02674 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiToneMapping.data->streamBuffer, p_SEI->seiToneMapping.payloadSize, SEI_TONE_MAPPING);
02675 ClearToneMapping(p_SEI);
02676 has_aggregation_sei_message = TRUE;
02677 }
02678
02679 if (p_SEI->seiHasPostFilterHints_info)
02680 {
02681 FinalizePostFilterHints(p_SEI);
02682 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiPostFilterHints.data->streamBuffer, p_SEI->seiPostFilterHints.payloadSize, SEI_POST_FILTER_HINTS);
02683 has_aggregation_sei_message = TRUE;
02684 }
02685
02686 if (p_SEI->seiHasBuffering_period)
02687 {
02688 FinalizeBufferingPeriod(p_SEI, p_Img->active_sps);
02689 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiBufferingPeriod.data->streamBuffer, p_SEI->seiBufferingPeriod.payloadSize, SEI_BUFFERING_PERIOD);
02690 has_aggregation_sei_message = TRUE;
02691 }
02692
02693 if (p_SEI->seiHasPicTiming_info)
02694 {
02695 FinalizePicTiming(p_Img);
02696 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiPicTiming.data->streamBuffer, p_SEI->seiPicTiming.payloadSize, SEI_PIC_TIMING);
02697 has_aggregation_sei_message = TRUE;
02698 }
02699
02700 if (p_SEI->seiHasRecoveryPoint_info)
02701 {
02702 FinalizeRandomAccess(p_SEI);
02703 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiRecoveryPoint.data->streamBuffer, p_SEI->seiRecoveryPoint.payloadSize, SEI_RECOVERY_POINT);
02704 ClearRandomAccess(p_SEI);
02705 has_aggregation_sei_message = TRUE;
02706 }
02707
02708 if (p_SEI->seiHasDRPMRepetition_info)
02709 {
02710 FinalizeDRPMRepetition(p_Img);
02711 write_sei_message(p_SEI, AGGREGATION_SEI, p_SEI->seiDRPMRepetition.data->streamBuffer, p_SEI->seiDRPMRepetition.payloadSize, SEI_DEC_REF_PIC_MARKING_REPETITION);
02712 has_aggregation_sei_message = TRUE;
02713 ClearDRPMRepetition(p_SEI);
02714 }
02715
02716
02717 if (has_aggregation_sei_message)
02718 {
02719 finalize_sei_message(p_SEI, AGGREGATION_SEI);
02720 }
02721 }
02722
02723
02724
02725
02726
02727
02728
02729 void free_drpm_buffer( DecRefPicMarking_t *pDRPM )
02730 {
02731 DecRefPicMarking_t *pTmp = pDRPM, *pPrev;
02732
02733 if (pTmp == NULL)
02734 return;
02735
02736 while( pTmp->Next != NULL )
02737 {
02738 pPrev = pTmp;
02739 pTmp = pTmp->Next;
02740 free( pPrev );
02741 }
02742 free( pTmp );
02743 }
02744