RBSP 原始字節序列載荷-->在SODB的后面填加了結尾比特(RBSP trailing bits 一個bit“1”)若干比特“0”,以便字節對齊。
EBSP 擴展字節序列載荷-->在RBSP基礎上填加了仿校驗字節(0X03)它的原因是: 在NALU加到Annexb上時,需要填加每組NALU之前的開始碼StartCodePrefix,如果該NALU對應的slice為一幀的開始則用4位字節表示,ox00000001,否則用3位字節表示ox000001.為了使NALU主體中不包括與開始碼相沖突的,在編碼時,每遇到兩個字節連續為0,就插入一個字節的0x03。解碼時將0x03去掉。也稱為脫殼操作。
網上查詢的區別:
在對整幀圖像的數據比特串(SODB)添加原始字節序列載荷(RBSP)結尾比特(RBSP trailing bits,添加一比特的“1”和若干比特“0”,以便字節對齊)后,再檢查RBSP 中是否存在連續的三字節“00000000 00000000 000000xx”;若存在這種連續的三字節碼,在第三字節前插入一字節的“0×03”,以免與起始碼競爭,形成EBSP碼流,這需要將近兩倍的整幀圖像碼流大小。為了減小存儲器需求,在每個宏塊編碼結束后即檢查該宏塊SODB中的起始碼競爭問題,并保留SODB最后兩字節的零字節個數,以便與下一宏塊的SODB的開始字節形成連續的起始碼競爭檢測;對一幀圖像的最后一個宏塊,先添加結尾停止比特,再檢測起始碼競爭。
程序:
typedef struct
{
int???????????? byte_pos;?????????? //!< current position in bitstream;
int???????????? bits_to_go;???????? //!< current bitcounter
byte??????????? byte_buf;?????????? //!< current buffer for last written byte
int???????????? stored_byte_pos;??? //!< storage for position in bitstream;
int???????????? stored_bits_to_go; //!< storage for bitcounter
byte??????????? stored_byte_buf;??? //!< storage for buffer of last written byte
byte??????????? byte_buf_skip;????? //!< current buffer for last written byte
int???????????? byte_pos_skip;????? //!< storage for position in bitstream;
int???????????? bits_to_go_skip;??? //!< storage for bitcounter
byte??????????? *streamBuffer;????? //!< actual buffer for written bytes
int???????????? write_flag;???????? //!< Bitstream contains data and needs to be written
} Bitstream; 定義比特流結構
static byte *NAL_Payload_buffer;
void SODBtoRBSP(Bitstream *currStream)
{
currStream->byte_buf <<= 1; //左移1bit
currStream->byte_buf |= 1; //在尾部填一個“1”占1bit
currStream->bits_to_go--;
currStream->byte_buf <<= currStream->bits_to_go;
currStream->streamBuffer[currStream->byte_pos++] = currStream->byte_buf;
currStream->bits_to_go = 8;
currStream->byte_buf = 0;
}
int RBSPtoEBSP(byte *streamBuffer, int begin_bytepos, int end_bytepos, int min_num_bytes)
{
int i, j, count;
for(i = begin_bytepos; i < end_bytepos; i++)
??? NAL_Payload_buffer[i] = streamBuffer[i];
count = 0;
j = begin_bytepos;
for(i = begin_bytepos; i < end_bytepos; i++)
{
??? if(count == ZEROBYTES_SHORTSTARTCODE && !(NAL_Payload_buffer[i] & 0xFC))
??? {
????? streamBuffer[j] = 0x03;
????? j++;
????? count = 0;??
??? }
??? streamBuffer[j] = NAL_Payload_buffer[i];
??? if(NAL_Payload_buffer[i] == 0x00)?????
????? count++;
??? else
????? count = 0;
??? j++;
}
while (j < begin_bytepos+min_num_bytes) {
??? streamBuffer[j] = 0x00; // cabac stuffing word
??? streamBuffer[j+1] = 0x00;
??? streamBuffer[j+2] = 0x03;
??? j += 3;
??? stat->bit_use_stuffingBits[img->type]+=16;
}
return j;
}