[fix] fix OBU_TEMPORAL_DELIMITER and OBU_SEQUENCE_HEADER obu data building

This commit is contained in:
dijunkun
2024-10-14 17:31:08 +08:00
parent 6bda59b1a7
commit c13cffb58e
4 changed files with 30 additions and 13 deletions

View File

@@ -25,6 +25,7 @@ class ByteBufferReader {
bool ReadBytes(char* val, size_t len); bool ReadBytes(char* val, size_t len);
bool ReadUInt8(uint8_t* val); bool ReadUInt8(uint8_t* val);
bool ReadUVarint(uint64_t* val); bool ReadUVarint(uint64_t* val);
bool ReadUVarint2(uint64_t* val, size_t* len);
bool Consume(size_t size); bool Consume(size_t size);

View File

@@ -50,10 +50,13 @@ std::vector<Obu> ParseObus(uint8_t* payload, int payload_size) {
std::vector<Obu> result; std::vector<Obu> result;
ByteBufferReader payload_reader(reinterpret_cast<const char*>(payload), ByteBufferReader payload_reader(reinterpret_cast<const char*>(payload),
payload_size); payload_size);
int count = 0;
while (payload_reader.Length() > 0) { while (payload_reader.Length() > 0) {
count++;
Obu obu; Obu obu;
bool has_ext_header = false; bool has_ext_header = false;
payload_reader.ReadUInt8(&obu.header); payload_reader.ReadUInt8(&obu.header);
LOG_ERROR("obu.header = [{:B}]", obu.header);
obu.size = 1; obu.size = 1;
if (ObuHasExtension(obu.header)) { if (ObuHasExtension(obu.header)) {
if (payload_reader.Length() == 0) { if (payload_reader.Length() == 0) {
@@ -83,10 +86,14 @@ std::vector<Obu> ParseObus(uint8_t* payload, int payload_size) {
size, payload_reader.Length()); size, payload_reader.Length());
return {}; return {};
} }
if (0 == size) {
obu.payload.push_back(0);
} else {
obu.payload = std::vector<uint8_t>( obu.payload = std::vector<uint8_t>(
reinterpret_cast<const uint8_t*>(payload_reader.Data()), reinterpret_cast<const uint8_t*>(payload_reader.Data()),
reinterpret_cast<const uint8_t*>(payload_reader.Data()) + size); reinterpret_cast<const uint8_t*>(payload_reader.Data()) + size);
obu.payload.insert(obu.payload.begin(), size);
}
payload_reader.Consume(size); payload_reader.Consume(size);
LOG_ERROR("Has size = {}", size); LOG_ERROR("Has size = {}", size);
} }
@@ -97,10 +104,11 @@ std::vector<Obu> ParseObus(uint8_t* payload, int payload_size) {
obu.payload.insert(obu.payload.begin(), obu.extension_header); obu.payload.insert(obu.payload.begin(), obu.extension_header);
} }
obu.payload.insert(obu.payload.begin(), obu.header); obu.payload.insert(obu.payload.begin(), obu.header);
if (obu_type != kObuTypeTileList && // // if (obu_type != kObuTypeTileList && //
obu_type != kObuTypePadding) { // obu_type != kObuTypePadding) {
result.push_back(obu); result.push_back(obu);
} LOG_ERROR("obu size = {}", obu.payload.size());
// }
// if (obu_type != kObuTypeTemporalDelimiter && // // if (obu_type != kObuTypeTemporalDelimiter && //
// obu_type != kObuTypeTileList && // // obu_type != kObuTypeTileList && //
// obu_type != kObuTypePadding) { // obu_type != kObuTypePadding) {
@@ -108,6 +116,8 @@ std::vector<Obu> ParseObus(uint8_t* payload, int payload_size) {
// } // }
} }
LOG_ERROR("count = [{}]", count);
for (int i = 0; i < result.size(); i++) { for (int i = 0; i < result.size(); i++) {
LOG_ERROR("[{}] Obu size = [{}], Obu type [{}|{}]", i, result[i].size, LOG_ERROR("[{}] Obu size = [{}], Obu type [{}|{}]", i, result[i].size,
ObuType(result[i].payload[0]), ObuType(result[i].payload[0]),

View File

@@ -519,6 +519,8 @@ void RtpCodec::Encode(VideoFrameType frame_type, uint8_t* buffer, size_t size,
} }
} }
} else if (RtpPacket::PAYLOAD_TYPE::AV1 == payload_type_) { } else if (RtpPacket::PAYLOAD_TYPE::AV1 == payload_type_) {
LOG_ERROR("source [{:X} {:X} {:X} {:X}], size={}", buffer[0], buffer[1],
buffer[2], buffer[3], size);
std::vector<Obu> obus = ParseObus(buffer, size); std::vector<Obu> obus = ParseObus(buffer, size);
// LOG_ERROR("Total size = [{}]", size); // LOG_ERROR("Total size = [{}]", size);
@@ -531,6 +533,9 @@ void RtpCodec::Encode(VideoFrameType frame_type, uint8_t* buffer, size_t size,
// LOG_ERROR("1 [{}] Obu size = [{}], Obu type [{}]", i, obus[i].size, // LOG_ERROR("1 [{}] Obu size = [{}], Obu type [{}]", i, obus[i].size,
// ObuTypeToString((OBU_TYPE)ObuType(obus[i].header))); // ObuTypeToString((OBU_TYPE)ObuType(obus[i].header)));
LOG_ERROR("0 output [{:X} {:X}], size={}", obus[i].payload.data()[0],
obus[i].payload.data()[1], obus[i].payload.size());
if (obus[i].size <= MAX_NALU_LEN) { if (obus[i].size <= MAX_NALU_LEN) {
RtpPacket rtp_packet; RtpPacket rtp_packet;
rtp_packet.SetVerion(version_); rtp_packet.SetVerion(version_);
@@ -562,9 +567,8 @@ void RtpCodec::Encode(VideoFrameType frame_type, uint8_t* buffer, size_t size,
rtp_packet.EncodeAv1(obus[i].payload.data(), obus[i].size); rtp_packet.EncodeAv1(obus[i].payload.data(), obus[i].size);
// int type = (obus[i].payload[0] & 0b0'1111'000) >> 3; // int type = (obus[i].payload[0] & 0b0'1111'000) >> 3;
int type = (rtp_packet.Payload()[0] & 0b0'1111'000) >> 3; int type = (rtp_packet.Payload()[0] & 0b0'1111'000) >> 3;
LOG_ERROR("!!!!! Obu type = [{}]", type); LOG_ERROR("1 output [{:X} {:X}], size={}", rtp_packet.Payload()[0],
LOG_ERROR("output [{:X} {:X}]", rtp_packet.Payload()[0], rtp_packet.Payload()[1], rtp_packet.PayloadSize());
rtp_packet.Payload()[1]);
packets.emplace_back(rtp_packet); packets.emplace_back(rtp_packet);
} else { } else {

View File

@@ -16,6 +16,8 @@ RtpVideoReceiver::~RtpVideoReceiver() {
} }
void RtpVideoReceiver::InsertRtpPacket(RtpPacket& rtp_packet) { void RtpVideoReceiver::InsertRtpPacket(RtpPacket& rtp_packet) {
LOG_ERROR("1 input [{:X} {:X}], size={}", rtp_packet.Payload()[0],
rtp_packet.Payload()[1], rtp_packet.PayloadSize());
if (!rtp_statistics_) { if (!rtp_statistics_) {
rtp_statistics_ = std::make_unique<RtpStatistics>(); rtp_statistics_ = std::make_unique<RtpStatistics>();
rtp_statistics_->Start(); rtp_statistics_->Start();
@@ -237,8 +239,8 @@ bool RtpVideoReceiver::CheckIsH264FrameCompleted(RtpPacket& rtp_packet) {
} }
bool RtpVideoReceiver::CheckIsAv1FrameCompleted(RtpPacket& rtp_packet) { bool RtpVideoReceiver::CheckIsAv1FrameCompleted(RtpPacket& rtp_packet) {
LOG_ERROR("input [{:X} {:X}]", rtp_packet.Payload()[0], LOG_ERROR("2 input [{:X} {:X}], size={}", rtp_packet.Payload()[0],
rtp_packet.Payload()[1]); rtp_packet.Payload()[1], rtp_packet.PayloadSize());
if (rtp_packet.Av1FrameEnd()) { if (rtp_packet.Av1FrameEnd()) {
uint16_t end_seq = rtp_packet.SequenceNumber(); uint16_t end_seq = rtp_packet.SequenceNumber();