Perf: Directly reference the extmap

pull/2204/head
winlin 4 years ago
parent e441702246
commit 0fa3646c4a

@ -165,18 +165,13 @@ int32_t srs_seq_distance(uint16_t value, uint16_t pre_value)
SrsRtpExtensionTypes::SrsRtpExtensionTypes() SrsRtpExtensionTypes::SrsRtpExtensionTypes()
{ {
reset(); memset(ids_, kRtpExtensionNone, sizeof(ids_));
} }
SrsRtpExtensionTypes::~SrsRtpExtensionTypes() SrsRtpExtensionTypes::~SrsRtpExtensionTypes()
{ {
} }
void SrsRtpExtensionTypes::reset()
{
memset(ids_, kRtpExtensionNone, sizeof(ids_));
}
bool SrsRtpExtensionTypes::register_by_uri(int id, std::string uri) bool SrsRtpExtensionTypes::register_by_uri(int id, std::string uri)
{ {
for (int i = 0; i < (int)(sizeof(kExtensions)/sizeof(kExtensions[0])); ++i) { for (int i = 0; i < (int)(sizeof(kExtensions)/sizeof(kExtensions[0])); ++i) {
@ -377,13 +372,10 @@ SrsRtpExtensions::~SrsRtpExtensions()
void SrsRtpExtensions::reset() void SrsRtpExtensions::reset()
{ {
if (has_ext_) { has_ext_ = false;
types_.reset(); types_ = NULL;
twcc_.reset(); twcc_.reset();
audio_level_.reset(); audio_level_.reset();
}
has_ext_ = false;
} }
srs_error_t SrsRtpExtensions::decode(SrsBuffer* buf) srs_error_t SrsRtpExtensions::decode(SrsBuffer* buf)
@ -445,7 +437,7 @@ srs_error_t SrsRtpExtensions::decode_0xbede(SrsBuffer* buf)
uint8_t id = (v & 0xF0) >> 4; uint8_t id = (v & 0xF0) >> 4;
uint8_t len = (v & 0x0F); uint8_t len = (v & 0x0F);
SrsRtpExtensionType xtype = types_.get_type(id); SrsRtpExtensionType xtype = types_? types_->get_type(id) : kRtpExtensionNone;
if (xtype == kRtpExtensionTransportSequenceNumber) { if (xtype == kRtpExtensionTransportSequenceNumber) {
if ((err = twcc_.decode(buf)) != srs_success) { if ((err = twcc_.decode(buf)) != srs_success) {
return srs_error_wrap(err, "decode twcc extension"); return srs_error_wrap(err, "decode twcc extension");
@ -522,11 +514,9 @@ bool SrsRtpExtensions::exists()
return has_ext_; return has_ext_;
} }
void SrsRtpExtensions::set_types_(const SrsRtpExtensionTypes* types) void SrsRtpExtensions::set_types_(SrsRtpExtensionTypes* types)
{ {
if(types) { types_ = types;
types_ = *types;
}
} }
srs_error_t SrsRtpExtensions::get_twcc_sequence_number(uint16_t& twcc_sn) srs_error_t SrsRtpExtensions::get_twcc_sequence_number(uint16_t& twcc_sn)
@ -703,7 +693,7 @@ srs_error_t SrsRtpHeader::encode(SrsBuffer* buf)
return err; return err;
} }
void SrsRtpHeader::set_extensions(const SrsRtpExtensionTypes* extmap) void SrsRtpHeader::set_extensions(SrsRtpExtensionTypes* extmap)
{ {
if (extmap) { if (extmap) {
extensions_.set_types_(extmap); extensions_.set_types_(extmap);
@ -992,7 +982,7 @@ bool SrsRtpPacket2::is_audio()
return frame_type == SrsFrameTypeAudio; return frame_type == SrsFrameTypeAudio;
} }
void SrsRtpPacket2::set_extension_types(const SrsRtpExtensionTypes* v) void SrsRtpPacket2::set_extension_types(SrsRtpExtensionTypes* v)
{ {
return header.set_extensions(v); return header.set_extensions(v);
} }

@ -122,9 +122,6 @@ public:
public: public:
SrsRtpExtensionTypes(); SrsRtpExtensionTypes();
virtual ~SrsRtpExtensionTypes(); virtual ~SrsRtpExtensionTypes();
public:
// Reset the object to reuse it.
void reset();
private: private:
bool register_id(int id, SrsRtpExtensionType type, std::string uri); bool register_id(int id, SrsRtpExtensionType type, std::string uri);
private: private:
@ -187,7 +184,11 @@ class SrsRtpExtensions// : public ISrsCodec
{ {
private: private:
bool has_ext_; bool has_ext_;
SrsRtpExtensionTypes types_; private:
// The extension types is used to decode the packet, which is reference to
// the types in publish stream.
SrsRtpExtensionTypes* types_;
private:
SrsRtpExtensionTwcc twcc_; SrsRtpExtensionTwcc twcc_;
SrsRtpExtensionOneByte audio_level_; SrsRtpExtensionOneByte audio_level_;
public: public:
@ -198,7 +199,7 @@ public:
void reset(); void reset();
public: public:
bool exists(); bool exists();
void set_types_(const SrsRtpExtensionTypes* types); void set_types_(SrsRtpExtensionTypes* types);
srs_error_t get_twcc_sequence_number(uint16_t& twcc_sn); srs_error_t get_twcc_sequence_number(uint16_t& twcc_sn);
srs_error_t set_twcc_sequence_number(uint8_t id, uint16_t sn); srs_error_t set_twcc_sequence_number(uint8_t id, uint16_t sn);
srs_error_t get_audio_level(uint8_t& level); srs_error_t get_audio_level(uint8_t& level);
@ -256,7 +257,7 @@ public:
} }
void set_padding(uint8_t v); void set_padding(uint8_t v);
uint8_t get_padding() const; uint8_t get_padding() const;
void set_extensions(const SrsRtpExtensionTypes* extmap); void set_extensions(SrsRtpExtensionTypes* extmap);
void ignore_padding(bool v); void ignore_padding(bool v);
srs_error_t get_twcc_sequence_number(uint16_t& twcc_sn); srs_error_t get_twcc_sequence_number(uint16_t& twcc_sn);
srs_error_t set_twcc_sequence_number(uint8_t id, uint16_t sn); srs_error_t set_twcc_sequence_number(uint8_t id, uint16_t sn);
@ -346,7 +347,7 @@ public:
// Whether the packet is Audio packet. // Whether the packet is Audio packet.
bool is_audio(); bool is_audio();
// Set RTP header extensions for encoding or decoding header extension // Set RTP header extensions for encoding or decoding header extension
void set_extension_types(const SrsRtpExtensionTypes* v); void set_extension_types(SrsRtpExtensionTypes* v);
// interface ISrsEncoder // interface ISrsEncoder
public: public:
virtual uint64_t nb_bytes(); virtual uint64_t nb_bytes();

Loading…
Cancel
Save