From 704e604b8fe4b65cbc4d76f88fcd61a38bb2c71c Mon Sep 17 00:00:00 2001 From: Staz M Date: Tue, 22 Sep 2020 12:56:53 -0400 Subject: [PATCH] Added Description::addSSRC --- examples/sfu-media/main.cpp | 6 +++++- include/rtc/description.hpp | 2 ++ src/description.cpp | 8 +++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/sfu-media/main.cpp b/examples/sfu-media/main.cpp index e769482..c37a7fe 100644 --- a/examples/sfu-media/main.cpp +++ b/examples/sfu-media/main.cpp @@ -65,11 +65,13 @@ int main() { auto session = std::make_shared(); track->setRtcpHandler(session); + const rtc::SSRC targetSSRC = 15; + track->onMessage( [&receivers](rtc::binary message) { // This is an RTP packet auto rtp = (rtc::RTP*) message.data(); - rtp->ssrc = htonl(15); + rtp->ssrc = htonl(targetSSRC); for (auto pc : receivers) { if (pc->track != nullptr && pc->track->isOpen()) { pc->track->send(message); @@ -109,6 +111,8 @@ int main() { media.setBitrate( 3000); // Request 3Mbps (Browsers do not encode more than 2.5MBps from a webcam) + media.addSSRC(targetSSRC, "video-send"); + pc->track = pc->conn->addTrack(media); pc->conn->setLocalDescription(); diff --git a/include/rtc/description.hpp b/include/rtc/description.hpp index 1dc0397..f8cef24 100644 --- a/include/rtc/description.hpp +++ b/include/rtc/description.hpp @@ -71,6 +71,8 @@ public: Direction direction() const { return mDirection; } void setDirection(Direction dir); + void addSSRC(uint32_t ssrc, std::string name); + operator string() const; string generateSdp(string_view eol) const; diff --git a/src/description.cpp b/src/description.cpp index 8c1ff25..2ab7000 100644 --- a/src/description.cpp +++ b/src/description.cpp @@ -374,9 +374,7 @@ Description::Entry::Entry(const string &mline, string mid, Direction dir) ss >> mType; ss >> port; // ignored ss >> mDescription; - if (direction() == Direction::SendOnly) { - mAttributes.emplace_back("ssrc:15 cname:test"); - } + } void Description::Entry::setDirection(Direction dir) { mDirection = dir; } @@ -444,6 +442,10 @@ void Description::Entry::parseSdpLine(string_view line) { } } +void Description::Entry::addSSRC(uint32_t ssrc, std::string name) { + mAttributes.emplace_back("ssrc:" + std::to_string(ssrc) + " cname:" + name); +} + Description::Application::Application(string mid) : Entry("application 9 UDP/DTLS/SCTP", std::move(mid), Direction::SendRecv) {}