Przeglądaj źródła

Set the same DSCP for RTP and RTCP

Paul-Louis Ageneau 4 lat temu
rodzic
commit
9f2801b7b9
4 zmienionych plików z 47 dodań i 58 usunięć
  1. 1 1
      include/rtc/track.hpp
  2. 44 54
      src/track.cpp
  3. 1 3
      src/transport.hpp
  4. 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;

+ 44 - 54
src/track.cpp

@@ -45,10 +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;
+	}
+
+	return outgoing(std::move(message));
+}
 
 bool Track::send(const byte *data, size_t size) {
-	return outgoing(std::make_shared<Message>(data, data + size, Message::Binary));
+	return send(binary(data, data+size));
 }
 
 std::optional<message_variant> Track::receive() {
@@ -88,25 +108,33 @@ void Track::open(shared_ptr<DtlsSrtpTransport> transport) {
 }
 #endif
 
-bool Track::outgoing(message_ptr message) {
-
-	if (mRtcpHandler) {
-		message = mRtcpHandler->outgoing(message);
-		if (!message)
-			return false;
-	}
+void Track::incoming(message_ptr message) {
+	if (!message)
+		return;
 
 	auto direction = mMediaDescription.direction();
-	if ((direction == Description::Direction::RecvOnly ||
+	if ((direction == Description::Direction::SendOnly ||
 	     direction == Description::Direction::Inactive) &&
 	    message->type != Message::Control) {
-		PLOG_WARNING << "Track media direction does not allow transmission, dropping";
-		return false;
+		PLOG_WARNING << "Track media direction does not allow reception, dropping";
+		return;
 	}
 
-	if (mIsClosed)
-		throw std::runtime_error("Track is closed");
+	if (mRtcpHandler) {
+		message = mRtcpHandler->incoming(message);
+		if (!message)
+			return;
+	}
 
+	// Tail drop if queue is full
+	if (mRecvQueue.full())
+		return;
+
+	mRecvQueue.push(message);
+	triggerAvailable(mRecvQueue.size());
+}
+
+bool Track::outgoing(message_ptr message) {
 #if RTC_ENABLE_MEDIA
 	auto transport = mDtlsSrtpTransport.lock();
 	if (!transport)
@@ -126,48 +154,10 @@ bool Track::outgoing(message_ptr message) {
 #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()),