fix frame

This commit is contained in:
tqcq 2024-08-26 16:06:11 +08:00
parent bb0f0a2320
commit 2a1fa19f3f
7 changed files with 42 additions and 2 deletions

View File

@ -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 <<endl;

View File

@ -7,6 +7,8 @@
#include <vector>
namespace sign {
class RTPManager;
class Frame : std::enable_shared_from_this<Frame> {
public:
using Ptr = std::shared_ptr<Frame>;
@ -41,6 +43,7 @@ public:
private:
Frame(Type type, const void *data, size_t len);
friend class RTPManager;
private:
Event _event{true};

View File

@ -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

View File

@ -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
{

View File

@ -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;

View File

@ -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)
{

View File

@ -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);