开始提取汇总sdp信息

This commit is contained in:
ziyue 2021-03-29 12:00:42 +08:00
parent b714dfddda
commit ba06def4d8
2 changed files with 35 additions and 4 deletions

View File

@ -190,7 +190,7 @@ SdpItem::Ptr RtcSdpBase::getItem(char key, const char *attr_key) const {
}
auto attr = dynamic_pointer_cast<SdpAttr>(item);
if (attr && attr->detail->getKey() == attr_key) {
return item;
return attr->detail;
}
}
}
@ -869,3 +869,32 @@ void test_sdp(){
InfoL << sdp1.toString();
InfoL << sdp2.toString();
}
void RtcSession::loadFrom(const string &str) {
RtcSessionSdp sdp;
sdp.parse(str);
version = sdp.getVersion();
origin = sdp.getOrigin();
session_name = sdp.getSessionName();
session_info = sdp.getSessionInfo();
connection = sdp.getConnection();
bandwidth = sdp.getBandwidth();
auto group = sdp.getItemClass<SdpAttrGroup>('a', "group");
auto mids = group.mids;
for (auto &media : sdp.medias) {
auto mline = media.getItemClass<SdpMedia>('m');
switch (mline.type) {
case TrackVideo:
case TrackAudio:
case TrackApplication:
break;
default: throw std::invalid_argument(StrPrinter << "不识别的media类型:" << mline.toString());
}
RtcMedia rtc_media;
rtc_media.type = mline.type;
rtc_media.mid = media.getStringItem('a', "mid");
}
}

View File

@ -444,9 +444,6 @@ public:
string getRepeatTimes() const;
RtpDirection getDirection() const;
private:
SdpItem::Ptr getItem(char key, const char *attr_key = nullptr) const;
template<typename cls>
cls getItemClass(char key, const char *attr_key = nullptr) const{
auto item = dynamic_pointer_cast<cls>(getItem(key, attr_key));
@ -463,6 +460,9 @@ private:
}
return item->toString();
}
private:
SdpItem::Ptr getItem(char key, const char *attr_key = nullptr) const;
};
class RtcSessionSdp : public RtcSdpBase{
@ -551,6 +551,8 @@ public:
SdpBandwidth bandwidth;
set<TrackType> group_bundle;
vector<RtcMedia> media;
void loadFrom(const string &sdp);
};