From 9f95f743e70756f9d19808406eb171dccad2ee59 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 8 May 2021 10:32:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E6=9E=90rtp=20ext=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E8=B5=8B=E5=80=BC=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/RtpExt.cpp | 28 +++++++++++----------------- webrtc/RtpExt.h | 9 +++++---- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/webrtc/RtpExt.cpp b/webrtc/RtpExt.cpp index 10542843..8189b9e9 100644 --- a/webrtc/RtpExt.cpp +++ b/webrtc/RtpExt.cpp @@ -119,14 +119,6 @@ uint8_t *RtpExtTwoByte::getData() { static constexpr uint16_t kOneByteHeader = 0xBEDE; static constexpr uint16_t kTwoByteHeader = 0x1000; -static RtpExtType getExtTypeById(uint8_t id, const RtcMedia &media){ - auto it = media.extmap.find(id); - if (it == media.extmap.end()) { - return RtpExtType::padding; - } - return RtpExt::getExtType(it->second.ext); -} - template static bool isOneByteExt(){ return false; @@ -138,7 +130,7 @@ static bool isOneByteExt(){ } template -static void appendExt(map &ret, const RtcMedia &media, uint8_t *ptr, const uint8_t *end) { +static void appendExt(map &ret, uint8_t *ptr, const uint8_t *end) { while (ptr < end) { auto ext = reinterpret_cast(ptr); if (ext->getId() == (uint8_t) RtpExtType::padding) { @@ -150,20 +142,18 @@ static void appendExt(map &ret, const RtcMedia &media, uint8 CHECK(ext->getId() < (uint8_t) RtpExtType::reserved); CHECK(reinterpret_cast(ext) + Type::kMinSize <= end); CHECK(ext->getData() + ext->getSize() <= end); - auto type = getExtTypeById(ext->getId(), media); - ret.emplace(type, RtpExt(ext, isOneByteExt(), type, reinterpret_cast(ext->getData()), ext->getSize())); + ret.emplace(ext->getId(), RtpExt(ext, isOneByteExt(), reinterpret_cast(ext->getData()), ext->getSize())); ptr += Type::kMinSize + ext->getSize(); } } -RtpExt::RtpExt(void *ptr, bool one_byte_ext, RtpExtType type, const char *str, size_t size) : std::string(str, size) { +RtpExt::RtpExt(void *ptr, bool one_byte_ext, const char *str, size_t size) : std::string(str, size) { _ptr = ptr; _one_byte_ext = one_byte_ext; - _type = type; } -map RtpExt::getExtValue(const RtpHeader *header, const RtcMedia &media) { - map ret; +map RtpExt::getExtValue(const RtpHeader *header) { + map ret; assert(header); auto ext_size = header->getExtSize(); if (!ext_size) { @@ -173,11 +163,11 @@ map RtpExt::getExtValue(const RtpHeader *hea auto ptr = const_cast(header)->getExtData(); auto end = ptr + ext_size; if (reserved == kOneByteHeader) { - appendExt(ret, media, ptr, end); + appendExt(ret, ptr, end); return ret; } if ((reserved & 0xFFF0) >> 4 == kTwoByteHeader) { - appendExt(ret, media, ptr, end); + appendExt(ret, ptr, end); return ret; } return ret; @@ -534,3 +524,7 @@ void RtpExt::setExtId(uint8_t ext_id) { ptr->setId(ext_id); } } + +void RtpExt::setType(RtpExtType type) { + _type = type; +} diff --git a/webrtc/RtpExt.h b/webrtc/RtpExt.h index 2557dc6d..d3975410 100644 --- a/webrtc/RtpExt.h +++ b/webrtc/RtpExt.h @@ -48,15 +48,16 @@ class RtcMedia; class RtpExt : public std::string { public: template - friend void appendExt(map &ret, const RtcMedia &media, uint8_t *ptr, const uint8_t *end); + friend void appendExt(map &ret, uint8_t *ptr, const uint8_t *end); ~RtpExt() = default; - static map getExtValue(const RtpHeader *header, const RtcMedia &media); + static map getExtValue(const RtpHeader *header); static RtpExtType getExtType(const string &url); static const string& getExtUrl(RtpExtType type); static const char *getExtName(RtpExtType type); + void setType(RtpExtType type); string dumpString() const; uint8_t getAudioLevel(bool *vad) const; @@ -91,12 +92,12 @@ public: void setExtId(uint8_t ext_id); private: - RtpExt(void *ptr, bool one_byte_ext, RtpExtType type, const char *str, size_t size); + RtpExt(void *ptr, bool one_byte_ext, const char *str, size_t size); private: void *_ptr = nullptr; bool _one_byte_ext = true; - RtpExtType _type; + RtpExtType _type = RtpExtType::padding; };