Skip to content

Commit f42b9cf

Browse files
committed
Preserve codecs priority
1 parent 8296892 commit f42b9cf

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

include/rtc/description.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,15 @@ class RTC_CPP_EXPORT Description {
228228
void addRtxCodec(int payloadType, int origPayloadType, unsigned int clockRate);
229229

230230
virtual void parseSdpLine(string_view line) override;
231+
virtual void parseFirstLine(string line);
231232

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

235236
int mBas = -1;
236237

237238
std::map<int, RtpMap> mRtpMaps;
239+
std::vector<string> mCodecsOrder;
238240
std::vector<uint32_t> mSsrcs;
239241
std::map<uint32_t, string> mCNameMap;
240242
};

src/description.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,9 @@ void Description::Application::parseSdpLine(string_view line) {
885885
Description::Media::Media(const string &sdp) : Entry(get_first_line(sdp), "", Direction::Unknown) {
886886
string line;
887887
std::istringstream ss(sdp);
888-
std::getline(ss, line); // discard first line
888+
std::getline(ss, line);
889+
parseFirstLine(line); // save codecs order
890+
889891
while (ss) {
890892
std::getline(ss, line);
891893
trim_end(line);
@@ -905,8 +907,9 @@ Description::Media::Media(const string &mline, string mid, Direction dir)
905907
string Description::Media::description() const {
906908
std::ostringstream desc;
907909
desc << Entry::description();
908-
for (auto it = mRtpMaps.begin(); it != mRtpMaps.end(); ++it)
909-
desc << ' ' << it->first;
910+
for(const string&codec : mCodecsOrder) {
911+
desc << ' ' << codec;
912+
}
910913

911914
return desc.str();
912915
}
@@ -1051,6 +1054,17 @@ string Description::Media::generateSdpLines(string_view eol) const {
10511054
return sdp.str();
10521055
}
10531056

1057+
void Description::Media::parseFirstLine(string line) {
1058+
std::istringstream ss(line);
1059+
string word;
1060+
std::getline(ss, word, ' '); // audio
1061+
std::getline(ss, word, ' '); // 9
1062+
std::getline(ss, word, ' '); // UDP/TLS/RTP/SAVPF
1063+
while (std::getline(ss, word, ' ')) {
1064+
mCodecsOrder.push_back(word);
1065+
}
1066+
}
1067+
10541068
void Description::Media::parseSdpLine(string_view line) {
10551069
if (match_prefix(line, "a=")) {
10561070
string_view attr = line.substr(2);

0 commit comments

Comments
 (0)