Browse Source

Merge pull request #271 from paullouisageneau/fix-dscp-rtcp

Send RTCP with the same DSCP as RTP
Paul-Louis Ageneau 4 years ago
parent
commit
eb4540e319
5 changed files with 51 additions and 62 deletions
  1. 1 1
      include/rtc/track.hpp
  2. 3 3
      src/peerconnection.cpp
  3. 45 55
      src/track.cpp
  4. 1 3
      src/transport.hpp
  5. 1 0
      src/websocket.cpp

+ 1 - 1
include/rtc/track.hpp

@@ -70,8 +70,8 @@ private:
 	std::weak_ptr<DtlsSrtpTransport> mDtlsSrtpTransport;
 #endif
 
-	bool outgoing(message_ptr message);
 	void incoming(message_ptr message);
+	bool outgoing(message_ptr message);
 
 	Description::Media mMediaDescription;
 	std::atomic<bool> mIsClosed = false;

+ 3 - 3
src/peerconnection.cpp

@@ -369,7 +369,7 @@ void PeerConnection::onSignalingStateChange(std::function<void(SignalingState st
 std::shared_ptr<Track> PeerConnection::addTrack(Description::Media description) {
 #if !RTC_ENABLE_MEDIA
 	if (mTracks.empty()) {
-		PLOG_WARNING << "Tracks will be inative (not compiled with SRTP support)";
+		PLOG_WARNING << "Tracks will be inative (not compiled with media support)";
 	}
 #endif
 
@@ -503,7 +503,7 @@ shared_ptr<DtlsTransport> PeerConnection::initDtlsTransport() {
 			    lower, certificate, verifierCallback,
 			    std::bind(&PeerConnection::forwardMedia, this, _1), stateChangeCallback);
 #else
-			PLOG_WARNING << "Ignoring media support (not compiled with SRTP support)";
+			PLOG_WARNING << "Ignoring media support (not compiled with media support)";
 #endif
 		}
 
@@ -872,7 +872,7 @@ void PeerConnection::incomingTrack(Description::Media description) {
 	std::unique_lock lock(mTracksMutex); // we are going to emplace
 #if !RTC_ENABLE_MEDIA
 	if (mTracks.empty()) {
-		PLOG_WARNING << "Tracks will be inative (not compiled with SRTP support)";
+		PLOG_WARNING << "Tracks will be inative (not compiled with media support)";
 	}
 #endif
 	if (mTracks.find(description.mid()) == mTracks.end()) {

+ 45 - 55
src/track.cpp

@@ -45,12 +45,30 @@ void Track::close() {
 	setRtcpHandler(nullptr);
 }
 
-bool Track::send(message_variant data) { return outgoing(make_message(std::move(data))); }
+bool Track::send(message_variant data) {
+	if (mIsClosed)
+		throw std::runtime_error("Track is closed");
+
+	auto direction = mMediaDescription.direction();
+	if ((direction == Description::Direction::RecvOnly ||
+	     direction == Description::Direction::Inactive)) {
+		PLOG_WARNING << "Track media direction does not allow transmission, dropping";
+		return false;
+	}
+
+	auto message = make_message(std::move(data));
+
+	if (mRtcpHandler) {
+		message = mRtcpHandler->outgoing(message);
+		if (!message)
+			return false;
+	}
 
-bool Track::send(const byte *data, size_t size) {
-	return outgoing(std::make_shared<Message>(data, data + size, Message::Binary));
+	return outgoing(std::move(message));
 }
 
+bool Track::send(const byte *data, size_t size) { return send(binary(data, data + size)); }
+
 std::optional<message_variant> Track::receive() {
 	if (auto next = mRecvQueue.tryPop())
 		return to_variant(std::move(**next));
@@ -88,25 +106,35 @@ void Track::open(shared_ptr<DtlsSrtpTransport> transport) {
 }
 #endif
 
-bool Track::outgoing(message_ptr message) {
+void Track::incoming(message_ptr message) {
+	if (!message)
+		return;
+
+	auto direction = mMediaDescription.direction();
+	if ((direction == Description::Direction::SendOnly ||
+	     direction == Description::Direction::Inactive) &&
+	    message->type != Message::Control) {
+		PLOG_WARNING << "Track media direction does not allow reception, dropping";
+		return;
+	}
 
 	if (mRtcpHandler) {
-		message = mRtcpHandler->outgoing(message);
+		message = mRtcpHandler->incoming(message);
 		if (!message)
-			return false;
+			return;
 	}
 
-	auto direction = mMediaDescription.direction();
-	if ((direction == Description::Direction::RecvOnly ||
-	     direction == Description::Direction::Inactive) &&
-	    message->type != Message::Control) {
-		PLOG_WARNING << "Track media direction does not allow transmission, dropping";
-		return false;
+	// Tail drop if queue is full
+	if (mRecvQueue.full()) {
+		PLOG_WARNING << "Track incoming queue is full, dropping";
+		return;
 	}
 
-	if (mIsClosed)
-		throw std::runtime_error("Track is closed");
+	mRecvQueue.push(message);
+	triggerAvailable(mRecvQueue.size());
+}
 
+bool Track::outgoing([[maybe_unused]] message_ptr message) {
 #if RTC_ENABLE_MEDIA
 	auto transport = mDtlsSrtpTransport.lock();
 	if (!transport)
@@ -121,53 +149,15 @@ bool Track::outgoing(message_ptr message) {
 
 	return transport->sendMedia(message);
 #else
-	PLOG_WARNING << "Ignoring track send (not compiled with SRTP support)";
+	PLOG_WARNING << "Ignoring track send (not compiled with media support)";
 	return false;
 #endif
 }
 
-void Track::incoming(message_ptr message) {
-	if (!message)
-		return;
-
-	if (mRtcpHandler) {
-		message = mRtcpHandler->incoming(message);
-		if (!message)
-			return;
-	}
-
-	auto direction = mMediaDescription.direction();
-	if ((direction == Description::Direction::SendOnly ||
-	     direction == Description::Direction::Inactive) &&
-	    message->type != Message::Control) {
-		PLOG_WARNING << "Track media direction does not allow reception, dropping";
-		return;
-	}
-
-	// Tail drop if queue is full
-	if (mRecvQueue.full())
-		return;
-
-	mRecvQueue.push(message);
-	triggerAvailable(mRecvQueue.size());
-}
-
 void Track::setRtcpHandler(std::shared_ptr<RtcpHandler> handler) {
 	mRtcpHandler = std::move(handler);
-	if (mRtcpHandler) {
-		mRtcpHandler->onOutgoing([&]([[maybe_unused]] message_ptr message) {
-#if RTC_ENABLE_MEDIA
-			auto transport = mDtlsSrtpTransport.lock();
-			if (!transport)
-				throw std::runtime_error("Track transport is not open");
-
-			return transport->sendMedia(message);
-#else
-			PLOG_WARNING << "Ignoring track send (not compiled with SRTP support)";
-			return false;
-#endif
-		});
-	}
+	if (mRtcpHandler)
+		mRtcpHandler->onOutgoing(std::bind(&Track::outgoing, this, std::placeholders::_1));
 }
 
 bool Track::requestKeyframe() {

+ 1 - 3
src/transport.hpp

@@ -28,8 +28,6 @@
 
 namespace rtc {
 
-using namespace std::placeholders;
-
 class Transport {
 public:
 	enum class State { Disconnected, Connecting, Connected, Completed, Failed };
@@ -57,7 +55,7 @@ public:
 	void registerIncoming() {
 		if (mLower) {
 			PLOG_VERBOSE << "Registering incoming callback";
-			mLower->onRecv(std::bind(&Transport::incoming, this, _1));
+			mLower->onRecv(std::bind(&Transport::incoming, this, std::placeholders::_1));
 		}
 	}
 

+ 1 - 0
src/websocket.cpp

@@ -36,6 +36,7 @@
 namespace rtc {
 
 using std::shared_ptr;
+using namespace std::placeholders;
 
 WebSocket::WebSocket(std::optional<Configuration> config)
     : mConfig(config ? std::move(*config) : Configuration()),