[fix] fix h264 rtp packetization error

This commit is contained in:
dijunkun
2025-02-05 17:28:57 +08:00
parent 2d5749f93a
commit 794e33c325
11 changed files with 75 additions and 85 deletions

View File

@@ -2,13 +2,7 @@
#include <string>
static FILE *file_1_ = nullptr;
static FILE *file_2_ = nullptr;
RtpPacket::RtpPacket() {
if (file_1_ == nullptr) file_1_ = fopen("file_1_.h264", "w+b");
if (file_2_ == nullptr) file_2_ = fopen("file_2_.h264", "w+b");
}
RtpPacket::RtpPacket() {}
RtpPacket::RtpPacket(size_t size) : buffer_(size) {}
@@ -20,25 +14,14 @@ RtpPacket &RtpPacket::operator=(const RtpPacket &rtp_packet) = default;
RtpPacket &RtpPacket::operator=(RtpPacket &&rtp_packet) = default;
RtpPacket::~RtpPacket() {
// if (file_1_ != nullptr) {
// fclose(file_1_);
// file_1_ = nullptr;
// }
// if (file_2_ != nullptr) {
// fclose(file_2_);
// file_2_ = nullptr;
// }
}
RtpPacket::~RtpPacket() {}
bool RtpPacket::Build(const uint8_t *buffer, uint32_t size) {
fwrite((unsigned char *)buffer, 1, size, file_1_);
if (!Parse(buffer, size)) {
LOG_WARN("RtpPacket::Build: parse failed");
return false;
}
buffer_.SetData(buffer, size);
fwrite((unsigned char *)Payload(), 1, PayloadSize(), file_2_);
size_ = size;
return true;
}

View File

@@ -263,6 +263,10 @@ class RtpPacket {
CopyOnWriteBuffer Buffer() const { return buffer_; }
size_t Size() const { return size_; }
// Header
const uint8_t *Header() { return Buffer().data(); };
size_t HeaderSize() { return payload_offset_; }
// For webrtc module use
size_t headers_size() const { return payload_offset_; }
size_t payload_size() const { return payload_size_; }

View File

@@ -17,9 +17,6 @@ bool RtpPacketH264::GetFrameHeaderInfo() {
if (rtp::NAL_UNIT_TYPE::NALU == fu_indicator_.nal_unit_type) {
add_offset_to_payload(1);
LOG_ERROR("2 [{} {} {}]", (int)fu_indicator_.forbidden_bit,
(int)fu_indicator_.nal_reference_idc,
(int)fu_indicator_.nal_unit_type);
} else if (rtp::NAL_UNIT_TYPE::FU_A == fu_indicator_.nal_unit_type) {
fu_header_.start = (frame_buffer[1] >> 7) & 0x01;
fu_header_.end = (frame_buffer[1] >> 6) & 0x01;