?? sei.c
字號:
/*!
************************************************************************
* \file sei.c
*
* \brief
* Functions to implement SEI messages
*
* \author
* Main contributors (see contributors.h for copyright, address and affiliation details)
* - Dong Tian <tian@cs.tut.fi>
* - Karsten Suehring <suehring@hhi.de>
************************************************************************
*/
//#include "contributors.h"
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <math.h>
#include "global.h"
#include "memalloc.h"
#include "sei.h"
#include "vlc.h"
#include "header.h"
#include "mbuffer.h"
#include "parset.h"
extern int UsedBits;
extern seq_parameter_set_rbsp_t SeqParSet[MAXSPS];
#ifdef ENABLE_OUTPUT_TONEMAPPING
tone_mapping_struct seiToneMapping;
#endif
// #define PRINT_BUFFERING_PERIOD_INFO // uncomment to print buffering period SEI info
// #define PRINT_PCITURE_TIMING_INFO // uncomment to print picture timing SEI info
// #define WRITE_MAP_IMAGE // uncomment to write spare picture map
// #define PRINT_SUBSEQUENCE_INFO // uncomment to print sub-sequence SEI info
// #define PRINT_SUBSEQUENCE_LAYER_CHAR // uncomment to print sub-sequence layer characteristics SEI info
// #define PRINT_SUBSEQUENCE_CHAR // uncomment to print sub-sequence characteristics SEI info
// #define PRINT_SCENE_INFORMATION // uncomment to print scene information SEI info
// #define PRINT_PAN_SCAN_RECT // uncomment to print pan-scan rectangle SEI info
// #define PRINT_RECOVERY_POINT // uncomment to print random access point SEI info
// #define PRINT_FILLER_PAYLOAD_INFO // uncomment to print filler payload SEI info
// #define PRINT_DEC_REF_PIC_MARKING // uncomment to print decoded picture buffer management repetition SEI info
// #define PRINT_RESERVED_INFO // uncomment to print reserved SEI info
// #define PRINT_USER_DATA_UNREGISTERED_INFO // uncomment to print unregistered user data SEI info
// #define PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO // uncomment to print ITU-T T.35 user data SEI info
// #define PRINT_FULL_FRAME_FREEZE_INFO // uncomment to print full-frame freeze SEI info
// #define PRINT_FULL_FRAME_FREEZE_RELEASE_INFO // uncomment to print full-frame freeze release SEI info
// #define PRINT_FULL_FRAME_SNAPSHOT_INFO // uncomment to print full-frame snapshot SEI info
// #define PRINT_PROGRESSIVE_REFINEMENT_END_INFO // uncomment to print Progressive refinement segment start SEI info
// #define PRINT_PROGRESSIVE_REFINEMENT_END_INFO // uncomment to print Progressive refinement segment end SEI info
// #define PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO // uncomment to print Motion-constrained slice group set SEI info
// #define PRINT_FILM_GRAIN_CHARACTERISTICS_INFO // uncomment to print Film grain characteristics SEI info
// #define PRINT_DEBLOCKING_FILTER_DISPLAY_PREFERENCE_INFO // uncomment to print deblocking filter display preference SEI info
// #define PRINT_STEREO_VIDEO_INFO_INFO // uncomment to print stero video SEI info
// #define PRINT_TONE_MAPPING // uncomment to print tone-mapping SEI info
// #define PRINT_POST_FILTER_HINT_INFO // uncomment to print post-filter hint SEI info
/*!
************************************************************************
* \brief
* Interpret the SEI rbsp
* \param msg
* a pointer that point to the sei message.
* \param size
* the size of the sei message
* \param img
* the image pointer
*
************************************************************************
*/
void InterpretSEIMessage(byte* msg, int size, ImageParameters *img)
{
int payload_type = 0;
int payload_size = 0;
int offset = 1;
byte tmp_byte;
do
{
// sei_message();
payload_type = 0;
tmp_byte = msg[offset++];
while (tmp_byte == 0xFF)
{
payload_type += 255;
tmp_byte = msg[offset++];
}
payload_type += tmp_byte; // this is the last byte
payload_size = 0;
tmp_byte = msg[offset++];
while (tmp_byte == 0xFF)
{
payload_size += 255;
tmp_byte = msg[offset++];
}
payload_size += tmp_byte; // this is the last byte
switch ( payload_type ) // sei_payload( type, size );
{
case SEI_BUFFERING_PERIOD:
interpret_buffering_period_info( msg+offset, payload_size, img );
break;
case SEI_PIC_TIMING:
interpret_picture_timing_info( msg+offset, payload_size, img );
break;
case SEI_PAN_SCAN_RECT:
interpret_pan_scan_rect_info( msg+offset, payload_size, img );
break;
case SEI_FILLER_PAYLOAD:
interpret_filler_payload_info( msg+offset, payload_size, img );
break;
case SEI_USER_DATA_REGISTERED_ITU_T_T35:
interpret_user_data_registered_itu_t_t35_info( msg+offset, payload_size, img );
break;
case SEI_USER_DATA_UNREGISTERED:
interpret_user_data_unregistered_info( msg+offset, payload_size, img );
break;
case SEI_RECOVERY_POINT:
interpret_recovery_point_info( msg+offset, payload_size, img );
break;
case SEI_DEC_REF_PIC_MARKING_REPETITION:
interpret_dec_ref_pic_marking_repetition_info( msg+offset, payload_size, img );
break;
case SEI_SPARE_PIC:
interpret_spare_pic( msg+offset, payload_size, img );
break;
case SEI_SCENE_INFO:
interpret_scene_information( msg+offset, payload_size, img );
break;
case SEI_SUB_SEQ_INFO:
interpret_subsequence_info( msg+offset, payload_size, img );
break;
case SEI_SUB_SEQ_LAYER_CHARACTERISTICS:
interpret_subsequence_layer_characteristics_info( msg+offset, payload_size, img );
break;
case SEI_SUB_SEQ_CHARACTERISTICS:
interpret_subsequence_characteristics_info( msg+offset, payload_size, img );
break;
case SEI_FULL_FRAME_FREEZE:
interpret_full_frame_freeze_info( msg+offset, payload_size, img );
break;
case SEI_FULL_FRAME_FREEZE_RELEASE:
interpret_full_frame_freeze_release_info( msg+offset, payload_size, img );
break;
case SEI_FULL_FRAME_SNAPSHOT:
interpret_full_frame_snapshot_info( msg+offset, payload_size, img );
break;
case SEI_PROGRESSIVE_REFINEMENT_SEGMENT_START:
interpret_progressive_refinement_end_info( msg+offset, payload_size, img );
break;
case SEI_PROGRESSIVE_REFINEMENT_SEGMENT_END:
interpret_progressive_refinement_end_info( msg+offset, payload_size, img );
break;
case SEI_MOTION_CONSTRAINED_SLICE_GROUP_SET:
interpret_motion_constrained_slice_group_set_info( msg+offset, payload_size, img );
case SEI_FILM_GRAIN_CHARACTERISTICS:
interpret_film_grain_characteristics_info ( msg+offset, payload_size, img );
break;
case SEI_DEBLOCKING_FILTER_DISPLAY_PREFERENCE:
interpret_deblocking_filter_display_preference_info ( msg+offset, payload_size, img );
break;
case SEI_STEREO_VIDEO_INFO:
interpret_stereo_video_info_info ( msg+offset, payload_size, img );
break;
case SEI_TONE_MAPPING:
interpret_tone_mapping( msg+offset, payload_size, img );
break;
case SEI_POST_FILTER_HINTS:
interpret_post_filter_hints_info ( msg+offset, payload_size, img );
default:
interpret_reserved_info( msg+offset, payload_size, img );
break;
}
offset += payload_size;
} while( msg[offset] != 0x80 ); // more_rbsp_data() msg[offset] != 0x80
// ignore the trailing bits rbsp_trailing_bits();
assert(msg[offset] == 0x80); // this is the trailing bits
assert( offset+1 == size );
}
/*!
************************************************************************
* \brief
* Interpret the spare picture SEI message
* \param payload
* a pointer that point to the sei payload
* \param size
* the size of the sei message
* \param img
* the image pointer
*
************************************************************************
*/
void interpret_spare_pic( byte* payload, int size, ImageParameters *img )
{
int i,x,y;
Bitstream* buf;
int bit0, bit1, bitc, no_bit0;
int target_frame_num = 0;
int num_spare_pics;
int delta_spare_frame_num, CandidateSpareFrameNum, SpareFrameNum = 0;
int ref_area_indicator;
int m, n, left, right, top, bottom,directx, directy;
byte ***map;
#ifdef WRITE_MAP_IMAGE
int symbol_size_in_bytes = img->pic_unit_bitsize_on_disk/8;
int j, k, i0, j0, tmp, kk;
char filename[20] = "map_dec.yuv";
FILE *fp;
imgpel** Y;
static int old_pn=-1;
static int first = 1;
printf("Spare picture SEI message\n");
#endif
UsedBits = 0;
assert( payload!=NULL);
assert( img!=NULL);
buf = malloc(sizeof(Bitstream));
buf->bitstream_length = size;
buf->streamBuffer = payload;
buf->frame_bitoffset = 0;
target_frame_num = ue_v("SEI: target_frame_num", buf);
#ifdef WRITE_MAP_IMAGE
printf( "target_frame_num is %d\n", target_frame_num );
#endif
num_spare_pics = 1 + ue_v("SEI: num_spare_pics_minus1", buf);
#ifdef WRITE_MAP_IMAGE
printf( "num_spare_pics is %d\n", num_spare_pics );
#endif
get_mem3D(&map, num_spare_pics, img->height/16, img->width/16);
for (i=0; i<num_spare_pics; i++)
{
if (i==0)
{
CandidateSpareFrameNum = target_frame_num - 1;
if ( CandidateSpareFrameNum < 0 ) CandidateSpareFrameNum = MAX_FN - 1;
}
else
CandidateSpareFrameNum = SpareFrameNum;
delta_spare_frame_num = ue_v("SEI: delta_spare_frame_num", buf);
SpareFrameNum = CandidateSpareFrameNum - delta_spare_frame_num;
if( SpareFrameNum < 0 )
SpareFrameNum = MAX_FN + SpareFrameNum;
ref_area_indicator = ue_v("SEI: ref_area_indicator", buf);
switch ( ref_area_indicator )
{
case 0: // The whole frame can serve as spare picture
for (y=0; y<img->height/16; y++)
for (x=0; x<img->width/16; x++)
map[i][y][x] = 0;
break;
case 1: // The map is not compressed
for (y=0; y<img->height/16; y++)
for (x=0; x<img->width/16; x++)
{
map[i][y][x] = u_1("SEI: ref_mb_indicator", buf);
}
break;
case 2: // The map is compressed
//!KS: could not check this function, description is unclear (as stated in Ed. Note)
bit0 = 0;
bit1 = 1;
bitc = bit0;
no_bit0 = -1;
x = ( img->width/16 - 1 ) / 2;
y = ( img->height/16 - 1 ) / 2;
left = right = x;
top = bottom = y;
directx = 0;
directy = 1;
for (m=0; m<img->height/16; m++)
for (n=0; n<img->width/16; n++)
{
if (no_bit0<0)
{
no_bit0 = ue_v("SEI: zero_run_length", buf);
}
if (no_bit0>0) map[i][y][x] = bit0;
else map[i][y][x] = bit1;
no_bit0--;
// go to the next mb:
if ( directx == -1 && directy == 0 )
{
if (x > left) x--;
else if (x == 0)
{
y = bottom + 1;
bottom++;
directx = 1;
directy = 0;
}
else if (x == left)
{
x--;
left--;
directx = 0;
directy = 1;
}
}
else if ( directx == 1 && directy == 0 )
{
if (x < right) x++;
else if (x == img->width/16 - 1)
{
y = top - 1;
top--;
directx = -1;
directy = 0;
}
else if (x == right)
{
x++;
right++;
directx = 0;
directy = -1;
}
}
else if ( directx == 0 && directy == -1 )
{
if ( y > top) y--;
else if (y == 0)
{
x = left - 1;
left--;
directx = 0;
directy = 1;
}
else if (y == top)
{
y--;
top--;
directx = -1;
directy = 0;
}
}
else if ( directx == 0 && directy == 1 )
{
if (y < bottom) y++;
else if (y == img->height/16 - 1)
{
x = right+1;
right++;
directx = 0;
directy = -1;
}
else if (y == bottom)
{
y++;
bottom++;
directx = 1;
directy = 0;
}
}
}
break;
default:
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -