Browse Source

Merge pull request #162 from paullouisageneau/fix-h264-firefox

Fix media example with Firefox
Paul-Louis Ageneau 5 years ago
parent
commit
d323c40c0a
2 changed files with 13 additions and 8 deletions
  1. 2 3
      include/rtc/peerconnection.hpp
  2. 11 5
      src/description.cpp

+ 2 - 3
include/rtc/peerconnection.hpp

@@ -80,6 +80,7 @@ public:
 	std::optional<Description> remoteDescription() const;
 	std::optional<string> localAddress() const;
 	std::optional<string> remoteAddress() const;
+	bool hasMedia() const;
 
 	void setLocalDescription();
 	void setRemoteDescription(Description description);
@@ -100,9 +101,7 @@ public:
 	size_t bytesReceived();
 	std::optional<std::chrono::milliseconds> rtt();
 
-	// Media support requires compilation with SRTP
-	bool hasMedia() const;
-
+	// Track media support requires compiling with libSRTP
 	std::shared_ptr<Track> createTrack(Description::Media description);
 	void onTrack(std::function<void(std::shared_ptr<Track> track)> callback);
 

+ 11 - 5
src/description.cpp

@@ -588,6 +588,12 @@ void Description::Media::addVideoCodec(int payloadType, const string &codec) {
 	RTPMap map(std::to_string(payloadType) + ' ' + codec + "/90000");
 	map.addFB("nack");
 	map.addFB("goog-remb");
+	if (codec == "H264") {
+		// Use Constrained Baseline profile Level 4.2 (necessary for Firefox)
+		// https://developer.mozilla.org/en-US/docs/Web/Media/Formats/WebRTC_codecs#Supported_video_codecs
+		// TODO: Should be 42E0 but 42C0 appears to be more compatible. Investigate this.
+		map.fmtps.emplace_back("profile-level-id=42E02A;level-asymmetry-allowed=1");
+	}
 	mRtpMap.emplace(map.pt, map);
 }
 
@@ -645,7 +651,7 @@ void Description::Media::parseSdpLine(string_view line) {
 			int pt = to_integer<int>(value.substr(0, p));
 			auto it = mRtpMap.find(pt);
 			if (it == mRtpMap.end()) {
-				PLOG_WARNING << "rtcp-fb applied before its rtpmap. Ignoring";
+				PLOG_WARNING << "rtcp-fb applied before the corresponding rtpmap, ignoring";
 			} else {
 				it->second.rtcpFbs.emplace_back(value.substr(p + 1));
 			}
@@ -654,7 +660,7 @@ void Description::Media::parseSdpLine(string_view line) {
 			int pt = to_integer<int>(value.substr(0, p));
 			auto it = mRtpMap.find(pt);
 			if (it == mRtpMap.end()) {
-				PLOG_WARNING << "fmtp applied before its rtpmap. Ignoring";
+				PLOG_WARNING << "fmtp applied before the corresponding rtpmap, ignoring";
 			} else {
 				it->second.fmtps.emplace_back(value.substr(p + 1));
 			}
@@ -692,17 +698,17 @@ Description::Media::RTPMap::RTPMap(string_view mline) {
 	}
 }
 
-void Description::Media::RTPMap::removeFB(const string &string) {
+void Description::Media::RTPMap::removeFB(const string &str) {
 	auto it = rtcpFbs.begin();
 	while (it != rtcpFbs.end()) {
-		if (it->find(string) != std::string::npos) {
+		if (it->find(str) != std::string::npos) {
 			it = rtcpFbs.erase(it);
 		} else
 			it++;
 	}
 }
 
-void Description::Media::RTPMap::addFB(const string &string) { rtcpFbs.emplace_back(string); }
+void Description::Media::RTPMap::addFB(const string &str) { rtcpFbs.emplace_back(str); }
 
 Description::Audio::Audio(string mid, Direction dir)
     : Media("audio 9 UDP/TLS/RTP/SAVPF", std::move(mid), dir) {}