Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve codecs priority #1144

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should contain integers as they are payload types, and I would suggest renaming it to a more explicit mOrderedPayloadTypes:

Suggested change
std::vector<string> mCodecsOrder;
std::vector<int> mOrderedPayloadTypes;

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method parses the first line a second time, which is not ideal.


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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here is different from the one in Entry(), meaning the behavior can be inconsistent, for instance if there are two consecutive spaces.

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
Loading