From c13cffb58e5ea803f128070be29c16010f5d4ca8 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Mon, 14 Oct 2024 17:31:08 +0800 Subject: [PATCH] [fix] fix OBU_TEMPORAL_DELIMITER and OBU_SEQUENCE_HEADER obu data building --- src/rtp/byte_buffer.h | 1 + src/rtp/obu_parser.cpp | 26 ++++++++++++++++++-------- src/rtp/rtp_codec.cpp | 10 +++++++--- src/rtp/rtp_video_receiver.cpp | 6 ++++-- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/rtp/byte_buffer.h b/src/rtp/byte_buffer.h index 374154c..a3b031f 100644 --- a/src/rtp/byte_buffer.h +++ b/src/rtp/byte_buffer.h @@ -25,6 +25,7 @@ class ByteBufferReader { bool ReadBytes(char* val, size_t len); bool ReadUInt8(uint8_t* val); bool ReadUVarint(uint64_t* val); + bool ReadUVarint2(uint64_t* val, size_t* len); bool Consume(size_t size); diff --git a/src/rtp/obu_parser.cpp b/src/rtp/obu_parser.cpp index ed71696..f57e3c1 100644 --- a/src/rtp/obu_parser.cpp +++ b/src/rtp/obu_parser.cpp @@ -50,10 +50,13 @@ std::vector ParseObus(uint8_t* payload, int payload_size) { std::vector result; ByteBufferReader payload_reader(reinterpret_cast(payload), payload_size); + int count = 0; while (payload_reader.Length() > 0) { + count++; Obu obu; bool has_ext_header = false; payload_reader.ReadUInt8(&obu.header); + LOG_ERROR("obu.header = [{:B}]", obu.header); obu.size = 1; if (ObuHasExtension(obu.header)) { if (payload_reader.Length() == 0) { @@ -83,10 +86,14 @@ std::vector ParseObus(uint8_t* payload, int payload_size) { size, payload_reader.Length()); return {}; } - - obu.payload = std::vector( - reinterpret_cast(payload_reader.Data()), - reinterpret_cast(payload_reader.Data()) + size); + if (0 == size) { + obu.payload.push_back(0); + } else { + obu.payload = std::vector( + reinterpret_cast(payload_reader.Data()), + reinterpret_cast(payload_reader.Data()) + size); + obu.payload.insert(obu.payload.begin(), size); + } payload_reader.Consume(size); LOG_ERROR("Has size = {}", size); } @@ -97,10 +104,11 @@ std::vector ParseObus(uint8_t* payload, int payload_size) { obu.payload.insert(obu.payload.begin(), obu.extension_header); } obu.payload.insert(obu.payload.begin(), obu.header); - if (obu_type != kObuTypeTileList && // - obu_type != kObuTypePadding) { - result.push_back(obu); - } + // if (obu_type != kObuTypeTileList && // + // obu_type != kObuTypePadding) { + result.push_back(obu); + LOG_ERROR("obu size = {}", obu.payload.size()); + // } // if (obu_type != kObuTypeTemporalDelimiter && // // obu_type != kObuTypeTileList && // // obu_type != kObuTypePadding) { @@ -108,6 +116,8 @@ std::vector ParseObus(uint8_t* payload, int payload_size) { // } } + LOG_ERROR("count = [{}]", count); + for (int i = 0; i < result.size(); i++) { LOG_ERROR("[{}] Obu size = [{}], Obu type [{}|{}]", i, result[i].size, ObuType(result[i].payload[0]), diff --git a/src/rtp/rtp_codec.cpp b/src/rtp/rtp_codec.cpp index 6b908a6..a75e07e 100644 --- a/src/rtp/rtp_codec.cpp +++ b/src/rtp/rtp_codec.cpp @@ -519,6 +519,8 @@ void RtpCodec::Encode(VideoFrameType frame_type, uint8_t* buffer, size_t size, } } } 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 obus = ParseObus(buffer, 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, // 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) { RtpPacket rtp_packet; 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); // int type = (obus[i].payload[0] & 0b0'1111'000) >> 3; int type = (rtp_packet.Payload()[0] & 0b0'1111'000) >> 3; - LOG_ERROR("!!!!! Obu type = [{}]", type); - LOG_ERROR("output [{:X} {:X}]", rtp_packet.Payload()[0], - rtp_packet.Payload()[1]); + LOG_ERROR("1 output [{:X} {:X}], size={}", rtp_packet.Payload()[0], + rtp_packet.Payload()[1], rtp_packet.PayloadSize()); packets.emplace_back(rtp_packet); } else { diff --git a/src/rtp/rtp_video_receiver.cpp b/src/rtp/rtp_video_receiver.cpp index 2f40fd7..5ce18b0 100644 --- a/src/rtp/rtp_video_receiver.cpp +++ b/src/rtp/rtp_video_receiver.cpp @@ -16,6 +16,8 @@ RtpVideoReceiver::~RtpVideoReceiver() { } 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_) { rtp_statistics_ = std::make_unique(); rtp_statistics_->Start(); @@ -237,8 +239,8 @@ bool RtpVideoReceiver::CheckIsH264FrameCompleted(RtpPacket& rtp_packet) { } bool RtpVideoReceiver::CheckIsAv1FrameCompleted(RtpPacket& rtp_packet) { - LOG_ERROR("input [{:X} {:X}]", rtp_packet.Payload()[0], - rtp_packet.Payload()[1]); + LOG_ERROR("2 input [{:X} {:X}], size={}", rtp_packet.Payload()[0], + rtp_packet.Payload()[1], rtp_packet.PayloadSize()); if (rtp_packet.Av1FrameEnd()) { uint16_t end_seq = rtp_packet.SequenceNumber();