调整优化webrtc sdp处理相关代码

This commit is contained in:
xiongziliang 2022-05-20 22:14:21 +08:00
parent 757001ad8a
commit b0f0bdb6ae
2 changed files with 12 additions and 11 deletions

View File

@ -286,9 +286,9 @@ void RtcSessionSdp::parse(const string &str) {
item->parse(value); item->parse(value);
} }
if (media) { if (media) {
media->items.push_back(std::move(item)); media->addItem(std::move(item));
} else { } else {
items.push_back(std::move(item)); addItem(std::move(item));
} }
} }
} }
@ -953,7 +953,7 @@ void RtcSession::loadFrom(const string &str) {
group = sdp.getItemClass<SdpAttrGroup>('a', "group"); group = sdp.getItemClass<SdpAttrGroup>('a', "group");
} }
static void toRtsp(vector <SdpItem::Ptr> &items) { void RtcSdpBase::toRtsp() {
for (auto it = items.begin(); it != items.end();) { for (auto it = items.begin(); it != items.end();) {
switch ((*it)->getKey()[0]) { switch ((*it)->getKey()[0]) {
case 'v': case 'v':
@ -1010,10 +1010,10 @@ string RtcSession::toRtspSdp() const{
CHECK(!copy.media.empty()); CHECK(!copy.media.empty());
auto sdp = copy.toRtcSessionSdp(); auto sdp = copy.toRtcSessionSdp();
toRtsp(sdp->items); sdp->toRtsp();
int i = 0; int i = 0;
for (auto &m : sdp->medias) { for (auto &m : sdp->medias) {
toRtsp(m.items); m.toRtsp();
m.addAttr(std::make_shared<SdpCommon>("control", string("trackID=") + to_string(i++))); m.addAttr(std::make_shared<SdpCommon>("control", string("trackID=") + to_string(i++)));
} }
return sdp->toString(); return sdp->toString();

View File

@ -490,18 +490,16 @@ public:
class RtcSdpBase { class RtcSdpBase {
public: public:
std::vector<SdpItem::Ptr> items; void addItem(SdpItem::Ptr item) { items.push_back(std::move(item)); }
void addItem(SdpItem::Ptr item) { items.push_back(item); }
void addAttr(SdpItem::Ptr attr) { void addAttr(SdpItem::Ptr attr) {
auto item = std::make_shared<SdpAttr>(); auto item = std::make_shared<SdpAttr>();
item->detail = std::move(attr); item->detail = std::move(attr);
items.push_back(item); items.push_back(std::move(item));
} }
SdpItem::Ptr findItem(char key) const { return getItem(key);}
SdpItem::Ptr findAttr(const char* key) const { return getItem('a', key);}
public:
virtual ~RtcSdpBase() = default; virtual ~RtcSdpBase() = default;
virtual std::string toString() const; virtual std::string toString() const;
void toRtsp();
RtpDirection getDirection() const; RtpDirection getDirection() const;
@ -548,6 +546,9 @@ public:
} }
return ret; return ret;
} }
private:
std::vector<SdpItem::Ptr> items;
}; };
class RtcSessionSdp : public RtcSdpBase{ class RtcSessionSdp : public RtcSdpBase{