1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Perf: Refine copy RTP header.

This commit is contained in:
winlin 2021-02-27 22:00:00 +08:00
parent 81dddcbd93
commit b1457dfc16
2 changed files with 55 additions and 6 deletions

View file

@ -218,6 +218,13 @@ void SrsRtpExtensionTwcc::reset()
sn_ = 0; sn_ = 0;
} }
void SrsRtpExtensionTwcc::assign(const SrsRtpExtensionTwcc& h)
{
has_twcc_ = h.has_twcc_;
id_ = h.id_;
sn_ = h.sn_;
}
bool SrsRtpExtensionTwcc::has_twcc_ext() bool SrsRtpExtensionTwcc::has_twcc_ext()
{ {
return has_twcc_; return has_twcc_;
@ -311,6 +318,13 @@ void SrsRtpExtensionOneByte::reset()
value_ = 0; value_ = 0;
} }
void SrsRtpExtensionOneByte::assign(const SrsRtpExtensionOneByte& h)
{
has_ext_ = h.has_ext_;
id_ = h.id_;
value_ = h.value_;
}
void SrsRtpExtensionOneByte::set_id(int id) void SrsRtpExtensionOneByte::set_id(int id)
{ {
id_ = id; id_ = id;
@ -370,10 +384,21 @@ SrsRtpExtensions::~SrsRtpExtensions()
void SrsRtpExtensions::reset() void SrsRtpExtensions::reset()
{ {
has_ext_ = false;
types_ = NULL; types_ = NULL;
twcc_.reset(); twcc_.reset();
audio_level_.reset(); audio_level_.reset();
has_ext_ = false;
}
void SrsRtpExtensions::assign(const SrsRtpExtensions& h)
{
has_ext_ = h.has_ext_;
types_ = h.types_;
if (has_ext_) {
twcc_.assign(h.twcc_);
audio_level_.assign(h.audio_level_);
}
} }
srs_error_t SrsRtpExtensions::decode(SrsBuffer* buf) srs_error_t SrsRtpExtensions::decode(SrsBuffer* buf)
@ -583,6 +608,27 @@ void SrsRtpHeader::reset()
//memset(csrc, 0, sizeof(csrc)); //memset(csrc, 0, sizeof(csrc));
} }
void SrsRtpHeader::assign(const SrsRtpHeader& h)
{
// Reset the fields in protocol.
cc = h.cc;
marker = h.marker;
payload_type = h.payload_type;
sequence = h.sequence;
timestamp = h.timestamp;
ssrc = h.ssrc;
// Reset the parsed fields.
padding_length = h.padding_length;
extensions_.assign(h.extensions_);
// Reset other fields.
ignore_padding_ = h.ignore_padding_;
// The CSRC is not used yet, so we never reset it.
//memcpy(csrc, h.csrc, sizeof(csrc));
}
srs_error_t SrsRtpHeader::decode(SrsBuffer* buf) srs_error_t SrsRtpHeader::decode(SrsBuffer* buf)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -948,7 +994,7 @@ SrsRtpPacket2* SrsRtpPacket2::copy()
cp->recycle_shared_msg(); cp->recycle_shared_msg();
} }
cp->header = header; cp->header.assign(header);
cp->payload_ = payload_? payload_->copy():NULL; cp->payload_ = payload_? payload_->copy():NULL;
cp->payload_type_ = payload_type_; cp->payload_type_ = payload_type_;

View file

@ -140,14 +140,14 @@ public:
public: public:
// Reset the object to reuse it. // Reset the object to reuse it.
void reset(); void reset();
void assign(const SrsRtpExtensionTwcc& h);
public:
bool has_twcc_ext(); bool has_twcc_ext();
uint8_t get_id(); uint8_t get_id();
void set_id(uint8_t id); void set_id(uint8_t id);
uint16_t get_sn(); uint16_t get_sn();
void set_sn(uint16_t sn); void set_sn(uint16_t sn);
public:
public:
// ISrsCodec // ISrsCodec
virtual srs_error_t decode(SrsBuffer* buf); virtual srs_error_t decode(SrsBuffer* buf);
virtual srs_error_t encode(SrsBuffer* buf); virtual srs_error_t encode(SrsBuffer* buf);
@ -166,7 +166,8 @@ public:
public: public:
// Reset the object to reuse it. // Reset the object to reuse it.
void reset(); void reset();
void assign(const SrsRtpExtensionOneByte& h);
public:
bool exists() { return has_ext_; } bool exists() { return has_ext_; }
int get_id() { return id_; } int get_id() { return id_; }
uint8_t get_value() { return value_; } uint8_t get_value() { return value_; }
@ -197,6 +198,7 @@ public:
public: public:
// Reset the object to reuse it. // Reset the object to reuse it.
void reset(); void reset();
void assign(const SrsRtpExtensions& h);
public: public:
bool exists(); bool exists();
void set_types_(SrsRtpExtensionTypes* types); void set_types_(SrsRtpExtensionTypes* types);
@ -234,6 +236,7 @@ public:
public: public:
// Reset the object to reuse it. // Reset the object to reuse it.
void reset(); void reset();
void assign(const SrsRtpHeader& h);
public: public:
virtual srs_error_t decode(SrsBuffer* buf); virtual srs_error_t decode(SrsBuffer* buf);
private: private: