调整 addSSRCItem 函数 (#1224)

* update readme.

* refactor(sdp): update addSSRCItem.

* refactor(sdp): remove addSSRCItem.

* refactor(sdp): 调整逻辑,生成a=ssrc-group:FID字段
This commit is contained in:
johzzy 2021-11-18 20:55:18 +08:00 committed by GitHub
parent a95381996e
commit f7963a9032
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 43 deletions

View File

@ -126,7 +126,7 @@
你有三种方法使用ZLMediaKit分别是
- 1、使用c api作为sdk使用请参考[这里](https://github.com/xia-chu/ZLMediaKit/tree/master/api/include).
- 2、作为独立的流媒体服务器使用不想做c/c++开发的,可以参考[restful api](https://github.com/xia-chu/ZLMediaKit/wiki/MediaServer%E6%94%AF%E6%8C%81%E7%9A%84HTTP-API)和[web hook](https://github.com/xia-chu/ZLMediaKit/wiki/MediaServer%E6%94%AF%E6%8C%81%E7%9A%84HTTP-HOOK-API).
- 2、作为独立的流媒体服务器使用不想做c/c++开发的,可以参考 [restful api](https://github.com/xia-chu/ZLMediaKit/wiki/MediaServer支持的HTTP-API) 和 [web hook](https://github.com/xia-chu/ZLMediaKit/wiki/MediaServer支持的HTTP-HOOK-API ).
- 3、如果想做c/c++开发,添加业务逻辑增加功能,可以参考这里的[测试程序](https://github.com/xia-chu/ZLMediaKit/tree/master/tests).
## Docker 镜像

View File

@ -1022,6 +1022,8 @@ string RtcSession::toRtspSdp() const{
return sdp->toString();
}
void addSdpAttrSSRC(const RtcSSRC &rtp_ssrc, vector<SdpItem::Ptr> &items, uint32_t ssrc_num);
RtcSessionSdp::Ptr RtcSession::toRtcSessionSdp() const{
RtcSessionSdp::Ptr ret = std::make_shared<RtcSessionSdp>();
auto &sdp = *ret;
@ -1126,51 +1128,15 @@ RtcSessionSdp::Ptr RtcSession::toRtcSessionSdp() const{
}
}
static auto addSSRCItem = [](const RtcSSRC &rtp_ssrc, vector<SdpItem::Ptr> &items) {
CHECK(!rtp_ssrc.empty());
auto ssrc_num = rtp_ssrc.ssrc;
for (auto i = 0; i < 2; ++i) {
SdpAttrSSRC ssrc;
ssrc.ssrc = ssrc_num;
ssrc.attribute = "cname";
ssrc.attribute_value = rtp_ssrc.cname;
items.emplace_back(wrapSdpAttr(std::make_shared<SdpAttrSSRC>(ssrc)));
if (!rtp_ssrc.msid.empty()) {
ssrc.attribute = "msid";
ssrc.attribute_value = rtp_ssrc.msid;
items.emplace_back(wrapSdpAttr(std::make_shared<SdpAttrSSRC>(ssrc)));
}
if (!rtp_ssrc.mslabel.empty()) {
ssrc.attribute = "mslabel";
ssrc.attribute_value = rtp_ssrc.mslabel;
items.emplace_back(wrapSdpAttr(std::make_shared<SdpAttrSSRC>(ssrc)));
}
if (!rtp_ssrc.label.empty()) {
ssrc.attribute = "label";
ssrc.attribute_value = rtp_ssrc.label;
items.emplace_back(wrapSdpAttr(std::make_shared<SdpAttrSSRC>(ssrc)));
}
if (rtp_ssrc.rtx_ssrc) {
ssrc_num = rtp_ssrc.rtx_ssrc;
} else {
break;
}
}
};
{
for (auto &ssrc : m.rtp_rtx_ssrc) {
//添加a=ssrc字段
addSSRCItem(ssrc, sdp_media.items);
}
for (auto &ssrc : m.rtp_rtx_ssrc) {
//生成a=ssrc-group:FID字段
CHECK(!ssrc.empty());
addSdpAttrSSRC(ssrc, sdp_media.items, ssrc.ssrc);
if (ssrc.rtx_ssrc) {
addSdpAttrSSRC(ssrc, sdp_media.items, ssrc.rtx_ssrc);
//生成a=ssrc-group:FID字段
//有rtx ssrc
auto group = std::make_shared<SdpAttrSSRCGroup>();
group->type = "FID";
@ -1219,6 +1185,33 @@ RtcSessionSdp::Ptr RtcSession::toRtcSessionSdp() const{
}
return ret;
}
void addSdpAttrSSRC(const RtcSSRC &rtp_ssrc, vector<SdpItem::Ptr> &items, uint32_t ssrc_num) {
assert(ssrc_num);
SdpAttrSSRC ssrc;
ssrc.ssrc = ssrc_num;
ssrc.attribute = "cname";
ssrc.attribute_value = rtp_ssrc.cname;
items.emplace_back(wrapSdpAttr(std::make_shared<SdpAttrSSRC>(ssrc)));
if (!rtp_ssrc.msid.empty()) {
ssrc.attribute = "msid";
ssrc.attribute_value = rtp_ssrc.msid;
items.emplace_back(wrapSdpAttr(std::make_shared<SdpAttrSSRC>(ssrc)));
}
if (!rtp_ssrc.mslabel.empty()) {
ssrc.attribute = "mslabel";
ssrc.attribute_value = rtp_ssrc.mslabel;
items.emplace_back(wrapSdpAttr(std::make_shared<SdpAttrSSRC>(ssrc)));
}
if (!rtp_ssrc.label.empty()) {
ssrc.attribute = "label";
ssrc.attribute_value = rtp_ssrc.label;
items.emplace_back(wrapSdpAttr(std::make_shared<SdpAttrSSRC>(ssrc)));
}
}
string RtcSession::toString() const{
return toRtcSessionSdp()->toString();