From 61201a8b83bcecda35e24053816dd39c0e71bf43 Mon Sep 17 00:00:00 2001 From: wusspuss Date: Wed, 27 Mar 2024 20:04:12 -0700 Subject: [PATCH] Preserve codecs priority --- include/rtc/description.hpp | 2 ++ src/description.cpp | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/rtc/description.hpp b/include/rtc/description.hpp index 0d0c58b5f..0d904b9b3 100644 --- a/include/rtc/description.hpp +++ b/include/rtc/description.hpp @@ -228,6 +228,7 @@ 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; @@ -235,6 +236,7 @@ class RTC_CPP_EXPORT Description { int mBas = -1; std::map mRtpMaps; + std::vector mCodecsOrder; std::vector mSsrcs; std::map mCNameMap; }; diff --git a/src/description.cpp b/src/description.cpp index b2165a895..66fe89cd7 100644 --- a/src/description.cpp +++ b/src/description.cpp @@ -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); @@ -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(); } @@ -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);