Skip to content

Commit a1e41e7

Browse files
committed
Fix wrong parsing of profile-level-id=42e034 (fixes versatica/libmediasoupclient#68)
1 parent 0cfab51 commit a1e41e7

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/parser.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "sdptransform.hpp"
2+
#include <unordered_map>
23
#include <cstddef> // size_t
34
#include <memory> // std::addressof()
45
#include <sstream> // std::stringstream, std::istringstream
@@ -338,9 +339,18 @@ namespace sdptransform
338339
);
339340
}
340341

342+
// @str parameters is a string like "profile-level-id=42e034".
341343
void insertParam(json& o, const std::string& str)
342344
{
343345
static const std::regex KeyValueRegex("^\\s*([^= ]+)(?:\\s*=\\s*([^ ]+))?$");
346+
static const std::unordered_map<std::string, char> WellKnownParameters =
347+
{
348+
// H264 codec parameters.
349+
{ "profile-level-id", 's' },
350+
{ "packetization-mode", 'd' },
351+
// VP9 codec parameters.
352+
{ "profile-id", 's' }
353+
};
344354

345355
std::smatch match;
346356

@@ -349,13 +359,15 @@ namespace sdptransform
349359
if (match.size() == 0)
350360
return;
351361

352-
// NOTE: match[2] maybe not exist in the given str if the param has no
353-
// value. We may insert nullptr then, but it's easier to just set an empty
354-
// string.
362+
std::string param = match[1].str();
363+
std::string value = match[2].str();
355364

365+
auto it = WellKnownParameters.find(param);
356366
char type;
357367

358-
if (isInt(match[2].str()))
368+
if (it != WellKnownParameters.end())
369+
type = it->second;
370+
else if (isInt(match[2].str()))
359371
type = 'd';
360372
else if (isFloat(match[2].str()))
361373
type = 'f';

test/data/normal.sdp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ a=candidate:3 2 UDP 1686052606 203.0.113.1 54403 typ srflx raddr 192.168.1.145 r
2121
m=video 55400 RTP/SAVPF 97 98
2222
a=rtpmap:97 H264/90000
2323
a=rtpmap:98 VP8/90000
24-
a=fmtp:97 profile-level-id=4d0028;packetization-mode=1;sprop-parameter-sets=Z0IAH5WoFAFuQA==,aM48gA==
24+
a=fmtp:97 profile-level-id=42e034;packetization-mode=1;sprop-parameter-sets=Z0IAH5WoFAFuQA==,aM48gA==
2525
a=fmtp:98 minptime=10; useinbandfec=1
2626
a=rtcp-fb:98 trr-int 100
2727
a=rtcp-fb:* nack

test/parse.test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,16 @@ SCENARIO("normalSdp", "[parse]")
8888

8989
auto vidFmtp = sdptransform::parseParams(video.at("fmtp")[0].at("config"));
9090

91-
REQUIRE(vidFmtp.at("profile-level-id") == "4d0028");
91+
REQUIRE(vidFmtp.at("profile-level-id") == "42e034");
9292
REQUIRE(vidFmtp.at("packetization-mode") == 1);
9393
REQUIRE(vidFmtp.at("sprop-parameter-sets") == "Z0IAH5WoFAFuQA==,aM48gA==");
9494

9595
// Testing json efficient access.
9696
auto profileLevelIdIterator = vidFmtp.find("profile-level-id");
9797

9898
REQUIRE(profileLevelIdIterator != vidFmtp.end());
99-
REQUIRE(*profileLevelIdIterator == "4d0028");
100-
REQUIRE(profileLevelIdIterator->get<std::string>() == "4d0028");
99+
REQUIRE(*profileLevelIdIterator == "42e034");
100+
REQUIRE(profileLevelIdIterator->get<std::string>() == "42e034");
101101

102102
REQUIRE(video.at("fmtp")[1].at("payload") == 98);
103103

0 commit comments

Comments
 (0)