Skip to content

Commit

Permalink
Merge pull request #903 from Sean-Der/simulcast
Browse files Browse the repository at this point in the history
Add Simulcast support
  • Loading branch information
paullouisageneau authored Jun 21, 2023
2 parents 1f6f09b + f39a85a commit 1ead0ce
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
3 changes: 3 additions & 0 deletions include/rtc/description.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class RTC_CPP_EXPORT Description {
std::vector<string> attributes() const;
void addAttribute(string attr);
void removeAttribute(const string &attr);
void addRid(string rid);

struct RTC_CPP_EXPORT ExtMap {
static int parseId(string_view description);
Expand Down Expand Up @@ -119,6 +120,7 @@ class RTC_CPP_EXPORT Description {

protected:
Entry(const string &mline, string mid, Direction dir = Direction::Unknown);

virtual string generateSdpLines(string_view eol) const;

std::vector<string> mAttributes;
Expand All @@ -128,6 +130,7 @@ class RTC_CPP_EXPORT Description {
string mType;
string mDescription;
string mMid;
std::vector<string> mRids;
Direction mDirection;
bool mIsRemoved;
};
Expand Down
1 change: 1 addition & 0 deletions include/rtc/rtp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct RTC_CPP_EXPORT RtpExtensionHeader {

void clearBody();
void writeCurrentVideoOrientation(size_t offset, uint8_t id, uint8_t value);
void writeOneByteHeader(size_t offset, uint8_t id, const byte *value, size_t size);
};

struct RTC_CPP_EXPORT RtpHeader {
Expand Down
37 changes: 35 additions & 2 deletions src/description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,10 @@ void Description::addAttribute(string attr) {
mAttributes.emplace_back(std::move(attr));
}

void Description::Entry::addRid(string rid) {
mRids.emplace_back(rid);
}

void Description::removeAttribute(const string &attr) {
mAttributes.erase(
std::remove_if(mAttributes.begin(), mAttributes.end(),
Expand Down Expand Up @@ -597,8 +601,34 @@ string Description::Entry::generateSdpLines(string_view eol) const {
if (mDirection != Direction::Unknown)
sdp << "a=" << mDirection << eol;

for (const auto &attr : mAttributes)
for (const auto &attr : mAttributes) {
if (mRids.size() != 0 && match_prefix(attr, "ssrc:")) {
continue;
}

sdp << "a=" << attr << eol;
}

for (const auto &rid : mRids) {
sdp << "a=rid:" << rid << " send" << eol;
}

if (mRids.size() != 0) {
sdp << "a=simulcast:send ";

bool first = true;
for (const auto &rid : mRids) {
if (first) {
first = false;
} else {
sdp << ";";
}

sdp << rid;
}

sdp << eol;
}

return sdp.str();
}
Expand Down Expand Up @@ -695,9 +725,12 @@ void Description::Media::addSSRC(uint32_t ssrc, optional<string> name, optional<
mAttributes.emplace_back("ssrc:" + std::to_string(ssrc));
}

if (msid)
if (msid) {
mAttributes.emplace_back("ssrc:" + std::to_string(ssrc) + " msid:" + *msid + " " +
trackId.value_or(*msid));
mAttributes.emplace_back("msid:" + *msid + " " +
trackId.value_or(*msid));
}

mSsrcs.emplace_back(ssrc);
}
Expand Down
14 changes: 11 additions & 3 deletions src/rtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,20 @@ void RtpExtensionHeader::setHeaderLength(uint16_t headerLength) {

void RtpExtensionHeader::clearBody() { std::memset(getBody(), 0, getSize()); }

void RtpExtensionHeader::writeCurrentVideoOrientation(size_t offset, uint8_t id, uint8_t value) {
if ((id == 0) || (id > 14) || ((offset + 2) > getSize()))
void RtpExtensionHeader::writeOneByteHeader(size_t offset, uint8_t id, const byte *value, size_t size) {
if ((id == 0) || (id > 14) || (size == 0) || (size > 16) || ((offset + 1 + size) > getSize()))
return;
auto buf = getBody() + offset;
buf[0] = id << 4;
buf[1] = value;
if (size != 1) {
buf[0] |= (uint8_t(size) - 1);
}
std::memcpy(buf + 1, value, size);
}

void RtpExtensionHeader::writeCurrentVideoOrientation(size_t offset, const uint8_t id, uint8_t value) {
auto v = std::byte{value};
writeOneByteHeader(offset, id, &v, 1);
}

SSRC RtcpReportBlock::getSSRC() const { return ntohl(_ssrc); }
Expand Down

0 comments on commit 1ead0ce

Please sign in to comment.