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 v6.0.75 (#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
6f42ca67cb
commit
add0f369c5
9 changed files with 339 additions and 86 deletions
|
@ -3887,6 +3887,80 @@ VOID TEST(KernelCodecTest, VideoFormatSepcial)
|
|||
}
|
||||
}
|
||||
|
||||
VOID TEST(KernelCoecTest, VideoFormatRbspData)
|
||||
{
|
||||
if (true) {
|
||||
vector<uint8_t> nalu = {
|
||||
0x25, 0x00, 0x1f, 0xe2, 0x22, 0x00, 0x00, 0x02, 0x00, 0x00, 0x80, 0xab, 0xff
|
||||
};
|
||||
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)nalu.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), nalu.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
SrsFormat f;
|
||||
vector<uint8_t> nalu = {
|
||||
0x25, 0x00, 0x1f, 0xe2, 0x22, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0x80, 0xab, 0xff
|
||||
};
|
||||
vector<uint8_t> expect = {
|
||||
0x25, 0x00, 0x1f, 0xe2, 0x22, 0x00, 0x00, 0x02, 0x00, 0x00, 0x80, 0xab, 0xff
|
||||
};
|
||||
|
||||
// |----------------|----------------------------|
|
||||
// | 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 |
|
||||
// |----------------|----------------------------|
|
||||
for (int i = 0; i <= 3; ++i) {
|
||||
nalu[8] = uint8_t(i);
|
||||
expect[7] = uint8_t(i);
|
||||
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
// 0x00 0x00 0x04 ~ 0x00 0x00 0xFF, no need to add emulation bytes.
|
||||
for (int i = 4; i <= 0xff; ++i) {
|
||||
nalu[8] = uint8_t(i);
|
||||
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)nalu.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), nalu.data(), nb_rbsp));
|
||||
}
|
||||
}
|
||||
|
||||
if (true) {
|
||||
vector<uint8_t> nalu = {
|
||||
0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x04
|
||||
};
|
||||
vector<uint8_t> expect = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x04
|
||||
};
|
||||
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
}
|
||||
|
||||
VOID TEST(KernelCodecTest, VideoFormat)
|
||||
{
|
||||
srs_error_t err;
|
||||
|
@ -6346,4 +6420,4 @@ VOID TEST(KernelUtilityTest, Base64Decode)
|
|||
HELPER_EXPECT_FAILED(srs_av_base64_decode("YWRtaW46YWRtaW", plaintext));
|
||||
EXPECT_STRNE("admin:admin", plaintext.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <srs_kernel_ts.hpp>
|
||||
#include <srs_kernel_ps.hpp>
|
||||
#include <srs_kernel_stream.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
|
||||
class MockSrsFile
|
||||
{
|
||||
|
@ -155,5 +156,7 @@ public:
|
|||
MockPsHandler* clear();
|
||||
};
|
||||
|
||||
extern int srs_rbsp_remove_emulation_bytes(SrsBuffer* stream, std::vector<uint8_t>& rbsp);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -526,3 +526,213 @@ VOID TEST(KernelCodecTest, VideoFormatSepcialAsan_DJI_M30)
|
|||
memcpy(data, "\x27\x01\x00\x00\x00\x00\x00\x00\x00", sizeof(data));
|
||||
HELPER_EXPECT_SUCCESS(f.on_video(0, data, sizeof(data)));
|
||||
}
|
||||
|
||||
VOID TEST(KernelCodecTest, VideoFormatRbspSimple)
|
||||
{
|
||||
// |---------------------|----------------------------|
|
||||
// | 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 |
|
||||
// |---------------------|----------------------------|
|
||||
if (true) {
|
||||
vector<uint8_t> nalu = {0x00, 0x00, 0x03, 0x00};
|
||||
vector<uint8_t> expect = {0x00, 0x00, 0x00};
|
||||
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
vector<uint8_t> nalu = {0x00, 0x00, 0x03, 0x01};
|
||||
vector<uint8_t> expect = {0x00, 0x00, 0x01};
|
||||
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
vector<uint8_t> nalu = {0x00, 0x00, 0x03, 0x02};
|
||||
vector<uint8_t> expect = {0x00, 0x00, 0x02};
|
||||
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
vector<uint8_t> nalu = {0x00, 0x00, 0x03, 0x03};
|
||||
vector<uint8_t> expect = {0x00, 0x00, 0x03};
|
||||
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
vector<uint8_t> nalu = {0x00, 0x00, 0x03, 0x04};
|
||||
vector<uint8_t> expect = {0x00, 0x00, 0x03, 0x04};
|
||||
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
vector<uint8_t> nalu = {0x00, 0x00, 0x03, 0xff};
|
||||
vector<uint8_t> expect = {0x00, 0x00, 0x03, 0xff};
|
||||
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
}
|
||||
|
||||
VOID TEST(KernelCodecTest, VideoFormatRbspEdge)
|
||||
{
|
||||
if (true) {
|
||||
vector<uint8_t> nalu = {0x00, 0x00, 0x03};
|
||||
vector<uint8_t> expect = {0x00, 0x00, 0x03};
|
||||
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
vector<uint8_t> nalu = {0xff, 0x00, 0x00, 0x03};
|
||||
vector<uint8_t> expect = {0xff, 0x00, 0x00, 0x03};
|
||||
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
for (uint16_t v = 0x01; v <= 0xff; v++) {
|
||||
vector<uint8_t> nalu = {(uint8_t)v, 0x00, 0x00, 0x03};
|
||||
vector<uint8_t> expect = {(uint8_t)v, 0x00, 0x00, 0x03};
|
||||
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
}
|
||||
|
||||
VOID TEST(KernelCodecTest, VideoFormatRbspNormal)
|
||||
{
|
||||
for (uint16_t v = 0x01; v <= 0xff; v++) {
|
||||
vector<uint8_t> nalu = {0x00, (uint8_t)v, 0x03, 0x00};
|
||||
vector<uint8_t> expect = {0x00, (uint8_t)v, 0x03, 0x00};
|
||||
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
for (uint16_t v = 0x01; v <= 0xff; v++) {
|
||||
vector<uint8_t> nalu = {(uint8_t)v, 0x00, 0x03, 0x00};
|
||||
vector<uint8_t> expect = {(uint8_t)v, 0x00, 0x03, 0x00};
|
||||
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
for (uint16_t v = 0x00; v <= 0xff; v++) {
|
||||
vector<uint8_t> nalu = {0x00, 0x00, (uint8_t)v};
|
||||
vector<uint8_t> expect = {0x00, 0x00, (uint8_t)v};
|
||||
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
for (uint16_t v = 0x00; v <= 0xff; v++) {
|
||||
vector<uint8_t> nalu = {0x00, (uint8_t)v};
|
||||
vector<uint8_t> expect = {0x00, (uint8_t)v};
|
||||
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
for (uint16_t v = 0x00; v <= 0xff; v++) {
|
||||
vector<uint8_t> nalu = {(uint8_t)v};
|
||||
vector<uint8_t> expect = {(uint8_t)v};
|
||||
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
for (uint16_t v = 0x00; v <= 0xff; v++) {
|
||||
vector<uint8_t> nalu = {(uint8_t)v, (uint8_t)v};
|
||||
vector<uint8_t> expect = {(uint8_t)v, (uint8_t)v};
|
||||
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
|
||||
for (uint16_t v = 0x00; v <= 0xff; v++) {
|
||||
vector<uint8_t> nalu = {(uint8_t)v, (uint8_t)v, (uint8_t)v};
|
||||
vector<uint8_t> expect = {(uint8_t)v, (uint8_t)v, (uint8_t)v};
|
||||
|
||||
vector<uint8_t> rbsp(nalu.size());
|
||||
SrsBuffer b((char*)nalu.data(), nalu.size());
|
||||
int nb_rbsp = srs_rbsp_remove_emulation_bytes(&b, rbsp);
|
||||
|
||||
ASSERT_EQ(nb_rbsp, (int)expect.size());
|
||||
EXPECT_TRUE(srs_bytes_equals(rbsp.data(), expect.data(), nb_rbsp));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue