Skip to content
Snippets Groups Projects
Commit e1a60176 authored by Tristan Matthews's avatar Tristan Matthews Committed by Guillaume Roguez
Browse files

sdp: drop extra payloads from SDP before handing off to libavformat

Refs #62388

Change-Id: Ia012bc490c1f54b820874162ccb7e69ff6f9f884
parent 1c438e5f
No related branches found
No related tags found
No related merge requests found
...@@ -627,20 +627,31 @@ string Sdp::getLineFromSession(const pjmedia_sdp_session *sess, const string &ke ...@@ -627,20 +627,31 @@ string Sdp::getLineFromSession(const pjmedia_sdp_session *sess, const string &ke
return ""; return "";
} }
static void remove_suffix(std::string &text, const std::string &token) // removes token from line starting with prefix
static void
remove_token(std::string& text, const char* prefix, const std::string& token)
{ {
const auto tokenPos = text.find(token.c_str()); const auto line_pos = text.find(prefix);
if (line_pos == std::string::npos)
return;
if (tokenPos != std::string::npos) const auto token_pos = text.find(token, line_pos);
text.erase(tokenPos, token.length()); if (token_pos != std::string::npos)
text.erase(token_pos, token.length());
} }
static void remove_line_with_token(std::string &text, const char *token) static void
remove_line_with_token(std::string& text, const std::string& token)
{ {
const auto tokenPos = text.find(token); const auto tokenPos = text.find(token);
if (tokenPos == std::string::npos) {
SFL_ERR("Couldn't find %s", token.c_str());
return;
}
const auto post = text.find('\n', tokenPos); const auto post = text.find('\n', tokenPos);
const auto pre = text.rfind('\n', tokenPos); const auto pre = text.rfind('\n', tokenPos);
if (post > pre)
text.erase(pre, post - pre); text.erase(pre, post - pre);
} }
...@@ -681,6 +692,37 @@ string Sdp::getIncomingVideoDescription() const ...@@ -681,6 +692,37 @@ string Sdp::getIncomingVideoDescription() const
return sessionStr; return sessionStr;
} }
static std::vector<std::string>
get_payloads(const char* prefix, const std::string& sdp)
{
const auto line_start = sdp.find(prefix);
if (line_start == std::string::npos)
return {};
// XXX: SDP lines end with \r\n
const auto line_end = sdp.find('\r', line_start);
if (line_end == std::string::npos)
return {};
// payload types are after the profile
const auto profile_pos = sdp.find("RTP/AVP ", line_start);
if (profile_pos == std::string::npos)
return {};
std::stringstream ss;
ss << sdp.substr(profile_pos, line_end - profile_pos);
std::vector<std::string> result;
std::string tmp;
int p;
while (std::getline(ss, tmp, ' '))
if (std::stringstream(tmp) >> p)
result.emplace_back(tmp);
return result;
}
// FIXME: // FIXME:
// Here we filter out parts of the SDP that libavformat doesn't need to // Here we filter out parts of the SDP that libavformat doesn't need to
// know about...we should probably give the audio decoder thread the original // know about...we should probably give the audio decoder thread the original
...@@ -715,10 +757,22 @@ std::string Sdp::getIncomingAudioDescription() const ...@@ -715,10 +757,22 @@ std::string Sdp::getIncomingAudioDescription() const
// FIXME: find a way to get rid of the "m=video..." line with PJSIP // FIXME: find a way to get rid of the "m=video..." line with PJSIP
remove_line_with_token(sessionStr, "m=video"); remove_line_with_token(sessionStr, "m=video");
// remove telephone-event as libavformat will barf on it (e.g. with speex wb and ub) // drop all but first audio payload
remove_suffix(sessionStr, " 101"); // FIXME: technically we should be able to decode any payload previously
remove_line_with_token(sessionStr, "a=rtpmap:101"); // announced by checking the payload type on the fly and switching codecs
remove_line_with_token(sessionStr, "a=fmtp:101"); // appropriately
const auto payloads = get_payloads("m=audio", sessionStr);
bool extra = false;
for (const auto& p : payloads) {
if (extra) {
SFL_WARN("Dropping payload %s", p.c_str());
remove_token(sessionStr, "m=audio", " " + p);
remove_line_with_token(sessionStr, "a=rtpmap:" + p);
remove_line_with_token(sessionStr, "a=fmtp:" + p);
}
extra = true;
}
return sessionStr; return sessionStr;
} }
......
...@@ -177,6 +177,8 @@ int VideoDecoder::setupFromAudioData() ...@@ -177,6 +177,8 @@ int VideoDecoder::setupFromAudioData()
return -1; return -1;
} }
SFL_DBG("Using %s", inputDecoder_->name);
decoderCtx_->thread_count = 1; decoderCtx_->thread_count = 1;
if (emulateRate_) { if (emulateRate_) {
SFL_DBG("Using framerate emulation"); SFL_DBG("Using framerate emulation");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment