mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Fix RBSP issue, where 0x03 should be removed. v5.0.178 (#3597)
ISO_IEC_14496-10-AVC-2012.pdf, page 65 7.4.1.1 Encapsulation of an SODB within an RBSP (informative) ... 00 00 03 xx, the 03 byte should be drop where xx represents any 2 bit pattern: 00, 01, 10, or 11. --------- Co-authored-by: john <hondaxiao@tencent.com> Co-authored-by: chundonglinlin <chundonglinlin@163.com> Co-authored-by: winlin <winlin@vip.126.com>
This commit is contained in:
parent
fc9a44d4b4
commit
b352fd0cfe
8 changed files with 330 additions and 27 deletions
|
@ -773,6 +773,44 @@ bool SrsFormat::is_avc_sequence_header()
|
|||
&& video && video->avc_packet_type == SrsVideoAvcFrameTraitSequenceHeader;
|
||||
}
|
||||
|
||||
// Remove the emulation bytes from stream, and return num of bytes of the rbsp.
|
||||
int srs_rbsp_remove_emulation_bytes(SrsBuffer* stream, std::vector<uint8_t>& rbsp)
|
||||
{
|
||||
int nb_rbsp = 0;
|
||||
while (!stream->empty()) {
|
||||
rbsp[nb_rbsp] = stream->read_1bytes();
|
||||
|
||||
// .. 00 00 03 xx, the 03 byte should be drop where xx represents any
|
||||
// 2 bit pattern: 00, 01, 10, or 11.
|
||||
if (nb_rbsp >= 2 && rbsp[nb_rbsp - 2] == 0 && rbsp[nb_rbsp - 1] == 0 && rbsp[nb_rbsp] == 3) {
|
||||
// read 1byte more.
|
||||
if (stream->empty()) {
|
||||
nb_rbsp++;
|
||||
break;
|
||||
}
|
||||
|
||||
// |---------------------|----------------------------|
|
||||
// | rbsp | nalu with emulation bytes |
|
||||
// |---------------------|----------------------------|
|
||||
// | 0x00 0x00 0x00 | 0x00 0x00 0x03 0x00 |
|
||||
// | 0x00 0x00 0x01 | 0x00 0x00 0x03 0x01 |
|
||||
// | 0x00 0x00 0x02 | 0x00 0x00 0x03 0x02 |
|
||||
// | 0x00 0x00 0x03 | 0x00 0x00 0x03 0x03 |
|
||||
// | 0x00 0x00 0x03 0x04 | 0x00 0x00 0x03 0x04 |
|
||||
// |---------------------|----------------------------|
|
||||
uint8_t ev = stream->read_1bytes();
|
||||
if (ev > 3) {
|
||||
nb_rbsp++;
|
||||
}
|
||||
rbsp[nb_rbsp] = ev;
|
||||
}
|
||||
|
||||
nb_rbsp++;
|
||||
}
|
||||
|
||||
return nb_rbsp;
|
||||
}
|
||||
|
||||
srs_error_t SrsFormat::video_avc_demux(SrsBuffer* stream, int64_t timestamp)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
@ -961,31 +999,13 @@ srs_error_t SrsFormat::avc_demux_sps()
|
|||
|
||||
// decode the rbsp from sps.
|
||||
// rbsp[ i ] a raw byte sequence payload is specified as an ordered sequence of bytes.
|
||||
std::vector<int8_t> rbsp(vcodec->sequenceParameterSetNALUnit.size());
|
||||
std::vector<uint8_t> rbsp(vcodec->sequenceParameterSetNALUnit.size());
|
||||
|
||||
int nb_rbsp = 0;
|
||||
while (!stream.empty()) {
|
||||
rbsp[nb_rbsp] = stream.read_1bytes();
|
||||
|
||||
// XX 00 00 03 XX, the 03 byte should be drop.
|
||||
if (nb_rbsp > 2 && rbsp[nb_rbsp - 2] == 0 && rbsp[nb_rbsp - 1] == 0 && rbsp[nb_rbsp] == 3) {
|
||||
// read 1byte more.
|
||||
if (stream.empty()) {
|
||||
break;
|
||||
}
|
||||
rbsp[nb_rbsp] = stream.read_1bytes();
|
||||
nb_rbsp++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
nb_rbsp++;
|
||||
}
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&stream, rbsp);
|
||||
|
||||
return avc_demux_sps_rbsp((char*)&rbsp[0], nb_rbsp);
|
||||
}
|
||||
|
||||
|
||||
srs_error_t SrsFormat::avc_demux_sps_rbsp(char* rbsp, int nb_rbsp)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue