Skip to content

Commit

Permalink
Preserve codecs priority
Browse files Browse the repository at this point in the history
  • Loading branch information
wusspuss committed Mar 28, 2024
1 parent 8296892 commit 27e2c11
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/rtc/description.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,15 @@ class RTC_CPP_EXPORT Description {
void addRtxCodec(int payloadType, int origPayloadType, unsigned int clockRate);

virtual void parseSdpLine(string_view line) override;
virtual void parseFirstLine(string line);

private:
virtual string generateSdpLines(string_view eol) const override;

int mBas = -1;

std::map<int, RtpMap> mRtpMaps;
std::vector<string> mCodecsOrder;
std::vector<uint32_t> mSsrcs;
std::map<uint32_t, string> mCNameMap;
};
Expand Down
20 changes: 17 additions & 3 deletions src/description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,9 @@ void Description::Application::parseSdpLine(string_view line) {
Description::Media::Media(const string &sdp) : Entry(get_first_line(sdp), "", Direction::Unknown) {
string line;
std::istringstream ss(sdp);
std::getline(ss, line); // discard first line
std::getline(ss, line);
parseFirstLine(line); // save codecs order

while (ss) {
std::getline(ss, line);
trim_end(line);
Expand All @@ -905,8 +907,9 @@ Description::Media::Media(const string &mline, string mid, Direction dir)
string Description::Media::description() const {
std::ostringstream desc;
desc << Entry::description();
for (auto it = mRtpMaps.begin(); it != mRtpMaps.end(); ++it)
desc << ' ' << it->first;
for(const string&codec : mCodecsOrder) {
desc << ' ' << codec;
}

return desc.str();
}
Expand Down Expand Up @@ -1051,6 +1054,17 @@ string Description::Media::generateSdpLines(string_view eol) const {
return sdp.str();
}

void Description::Media::parseFirstLine(string line) {
std::istringstream ss(line);
string word;
std::getline(ss, word, ' '); // audio
std::getline(ss, word, ' '); // 9
std::getline(ss, word, ' '); // UDP/TLS/RTP/SAVPF
while (std::getline(ss, word, ' ')) {
mCodecsOrder.push_back(word);
}
}

void Description::Media::parseSdpLine(string_view line) {
if (match_prefix(line, "a=")) {
string_view attr = line.substr(2);
Expand Down

0 comments on commit 27e2c11

Please sign in to comment.