diff --git a/PcapSender/main.cpp b/PcapSender/main.cpp index 559c74e..4372c4d 100644 --- a/PcapSender/main.cpp +++ b/PcapSender/main.cpp @@ -159,7 +159,7 @@ ReadPcapAndSend(int socket, sockaddr_in &addr, const string &filename, const str current_time.tv_sec = inital_time.tv_sec + real_now.tv_sec; current_time.tv_nsec = inital_time.tv_nsec + real_now.tv_nsec; gaptime = TimeDiff(nowtime, current_time); - if (gaptime.tv_nsec >= 0 && gaptime.tv_sec >= 0) { + if (gaptime.tv_nsec > 0 || gaptime.tv_sec > 0) { nanosleep(&gaptime, NULL); } else { // cout<<" s:" << gaptime.tv_sec<<" ns:" << gaptime.tv_nsec < namespace sign { +class RTPManager; + class Frame : std::enable_shared_from_this { public: using Ptr = std::shared_ptr; @@ -41,6 +43,7 @@ public: private: Frame(Type type, const void *data, size_t len); + friend class RTPManager; private: Event _event{true}; diff --git a/src/base/rtp_manager.cpp b/src/base/rtp_manager.cpp index 5e758bc..1d3d95d 100644 --- a/src/base/rtp_manager.cpp +++ b/src/base/rtp_manager.cpp @@ -225,9 +225,32 @@ RTPManager::ModifySEIPacket(RTPDecoder::DecodedPacket packet, void *sei_begin, v // TODO: @tqcq 增加对padding udp rtp sei包的处理 auto last_packet = packet.ref_rtp_packets.back(); auto last_frame = last_packet->ref_frames().back(); + auto append_len = (const uint8_t *) sei_end - (const uint8_t *) sei_begin; INFOL("Modify SEI packet. seq=%d, size=%lu\n", last_packet->seq(), last_frame->size()); INFOL("SEI data size=%lu\n", (uint8_t *) sei_end - (uint8_t *) sei_begin); - INFOL("SEI data: %s\n", ToHex((const uint8_t *) sei_begin, (uint8_t *) sei_end - (uint8_t *) sei_begin).c_str()); + INFOL("SEI data: %s\n", ToHex((const uint8_t *) sei_begin, append_len).c_str()); + + if (last_frame->type() != Frame::kUDP) { + ERROL("Only support kUDP"); + return; + } + auto &buf = last_frame->_data; + + bool has_padding = last_packet->has_padding(); + uint8_t padding_len = 0; + if (has_padding) { + // remove padding + padding_len = buf.back(); + buf.resize(buf.size() - padding_len); + } + std::copy((uint8_t *) sei_begin, (uint8_t *) sei_end, std::back_inserter(buf)); + if (has_padding) { + // append_len align 4 need (4 - append_len & 0x3) + // new_padding_len = (old_padding + append_len_align_len) %4 + const uint8_t new_padding_len = ((4 - (append_len & 0x3)) + padding_len) % 4; + for (int i = 1; i < new_padding_len; ++i) { buf.push_back(0); } + buf.push_back(new_padding_len); + } } void diff --git a/src/base/rtp_packet.cpp b/src/base/rtp_packet.cpp index 2371a51..0e34a97 100644 --- a/src/base/rtp_packet.cpp +++ b/src/base/rtp_packet.cpp @@ -61,6 +61,12 @@ RTPPacket::packet_data() const return _rtp_ptr; } +bool +RTPPacket::has_padding() const +{ + return GetRTPPadding(_rtp_ptr); +} + uint8_t RTPPacket::payload_type() const { diff --git a/src/base/rtp_packet.h b/src/base/rtp_packet.h index 07b677b..61a314e 100644 --- a/src/base/rtp_packet.h +++ b/src/base/rtp_packet.h @@ -36,6 +36,7 @@ public: size_t rtp_payload_size(); // rtp header, kMissPayload or kComplete + bool has_padding() const; uint8_t payload_type() const; uint16_t seq() const; uint32_t ssrc() const; diff --git a/src/base/util.cpp b/src/base/util.cpp index 1f91b0c..7bf8f93 100644 --- a/src/base/util.cpp +++ b/src/base/util.cpp @@ -11,6 +11,12 @@ GetRTPVersion(const uint8_t *data) return (data[0] & 0xC0) >> 6; } +uint8_t +GetRTPPadding(const uint8_t *header) +{ + return (header[0] & 0x20); +} + uint8_t GetRTPPayloadType(const uint8_t *data) { diff --git a/src/base/util.h b/src/base/util.h index 4bfb326..8e6dccf 100644 --- a/src/base/util.h +++ b/src/base/util.h @@ -10,6 +10,7 @@ namespace sign { uint8_t GetRTPVersion(const uint8_t *header); +uint8_t GetRTPPadding(const uint8_t *header); uint8_t GetRTPPayloadType(const uint8_t *header); uint16_t GetRTPSequenceNumber(const uint8_t *header); uint32_t GetRTPTimestamp(const uint8_t *header);