mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
解析rtp ext时不再赋值类型
This commit is contained in:
parent
5756ed46e0
commit
9f95f743e7
@ -119,14 +119,6 @@ uint8_t *RtpExtTwoByte::getData() {
|
|||||||
static constexpr uint16_t kOneByteHeader = 0xBEDE;
|
static constexpr uint16_t kOneByteHeader = 0xBEDE;
|
||||||
static constexpr uint16_t kTwoByteHeader = 0x1000;
|
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<typename Type>
|
template<typename Type>
|
||||||
static bool isOneByteExt(){
|
static bool isOneByteExt(){
|
||||||
return false;
|
return false;
|
||||||
@ -138,7 +130,7 @@ static bool isOneByteExt<RtpExtOneByte>(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
static void appendExt(map<RtpExtType, RtpExt> &ret, const RtcMedia &media, uint8_t *ptr, const uint8_t *end) {
|
static void appendExt(map<uint8_t, RtpExt> &ret, uint8_t *ptr, const uint8_t *end) {
|
||||||
while (ptr < end) {
|
while (ptr < end) {
|
||||||
auto ext = reinterpret_cast<Type *>(ptr);
|
auto ext = reinterpret_cast<Type *>(ptr);
|
||||||
if (ext->getId() == (uint8_t) RtpExtType::padding) {
|
if (ext->getId() == (uint8_t) RtpExtType::padding) {
|
||||||
@ -150,20 +142,18 @@ static void appendExt(map<RtpExtType, RtpExt> &ret, const RtcMedia &media, uint8
|
|||||||
CHECK(ext->getId() < (uint8_t) RtpExtType::reserved);
|
CHECK(ext->getId() < (uint8_t) RtpExtType::reserved);
|
||||||
CHECK(reinterpret_cast<uint8_t *>(ext) + Type::kMinSize <= end);
|
CHECK(reinterpret_cast<uint8_t *>(ext) + Type::kMinSize <= end);
|
||||||
CHECK(ext->getData() + ext->getSize() <= end);
|
CHECK(ext->getData() + ext->getSize() <= end);
|
||||||
auto type = getExtTypeById(ext->getId(), media);
|
ret.emplace(ext->getId(), RtpExt(ext, isOneByteExt<Type>(), reinterpret_cast<char *>(ext->getData()), ext->getSize()));
|
||||||
ret.emplace(type, RtpExt(ext, isOneByteExt<Type>(), type, reinterpret_cast<char *>(ext->getData()), ext->getSize()));
|
|
||||||
ptr += Type::kMinSize + 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;
|
_ptr = ptr;
|
||||||
_one_byte_ext = one_byte_ext;
|
_one_byte_ext = one_byte_ext;
|
||||||
_type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
map<RtpExtType/*type*/, RtpExt/*data*/> RtpExt::getExtValue(const RtpHeader *header, const RtcMedia &media) {
|
map<uint8_t/*id*/, RtpExt/*data*/> RtpExt::getExtValue(const RtpHeader *header) {
|
||||||
map<RtpExtType, RtpExt> ret;
|
map<uint8_t, RtpExt> ret;
|
||||||
assert(header);
|
assert(header);
|
||||||
auto ext_size = header->getExtSize();
|
auto ext_size = header->getExtSize();
|
||||||
if (!ext_size) {
|
if (!ext_size) {
|
||||||
@ -173,11 +163,11 @@ map<RtpExtType/*type*/, RtpExt/*data*/> RtpExt::getExtValue(const RtpHeader *hea
|
|||||||
auto ptr = const_cast<RtpHeader *>(header)->getExtData();
|
auto ptr = const_cast<RtpHeader *>(header)->getExtData();
|
||||||
auto end = ptr + ext_size;
|
auto end = ptr + ext_size;
|
||||||
if (reserved == kOneByteHeader) {
|
if (reserved == kOneByteHeader) {
|
||||||
appendExt<RtpExtOneByte>(ret, media, ptr, end);
|
appendExt<RtpExtOneByte>(ret, ptr, end);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if ((reserved & 0xFFF0) >> 4 == kTwoByteHeader) {
|
if ((reserved & 0xFFF0) >> 4 == kTwoByteHeader) {
|
||||||
appendExt<RtpExtTwoByte>(ret, media, ptr, end);
|
appendExt<RtpExtTwoByte>(ret, ptr, end);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -534,3 +524,7 @@ void RtpExt::setExtId(uint8_t ext_id) {
|
|||||||
ptr->setId(ext_id);
|
ptr->setId(ext_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RtpExt::setType(RtpExtType type) {
|
||||||
|
_type = type;
|
||||||
|
}
|
||||||
|
@ -48,15 +48,16 @@ class RtcMedia;
|
|||||||
class RtpExt : public std::string {
|
class RtpExt : public std::string {
|
||||||
public:
|
public:
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
friend void appendExt(map<RtpExtType, RtpExt> &ret, const RtcMedia &media, uint8_t *ptr, const uint8_t *end);
|
friend void appendExt(map<uint8_t, RtpExt> &ret, uint8_t *ptr, const uint8_t *end);
|
||||||
|
|
||||||
~RtpExt() = default;
|
~RtpExt() = default;
|
||||||
|
|
||||||
static map<RtpExtType/*type*/, RtpExt/*data*/> getExtValue(const RtpHeader *header, const RtcMedia &media);
|
static map<uint8_t/*id*/, RtpExt/*data*/> getExtValue(const RtpHeader *header);
|
||||||
static RtpExtType getExtType(const string &url);
|
static RtpExtType getExtType(const string &url);
|
||||||
static const string& getExtUrl(RtpExtType type);
|
static const string& getExtUrl(RtpExtType type);
|
||||||
static const char *getExtName(RtpExtType type);
|
static const char *getExtName(RtpExtType type);
|
||||||
|
|
||||||
|
void setType(RtpExtType type);
|
||||||
string dumpString() const;
|
string dumpString() const;
|
||||||
|
|
||||||
uint8_t getAudioLevel(bool *vad) const;
|
uint8_t getAudioLevel(bool *vad) const;
|
||||||
@ -91,12 +92,12 @@ public:
|
|||||||
void setExtId(uint8_t ext_id);
|
void setExtId(uint8_t ext_id);
|
||||||
|
|
||||||
private:
|
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:
|
private:
|
||||||
void *_ptr = nullptr;
|
void *_ptr = nullptr;
|
||||||
bool _one_byte_ext = true;
|
bool _one_byte_ext = true;
|
||||||
RtpExtType _type;
|
RtpExtType _type = RtpExtType::padding;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user