Bläddra i källkod

Added configuration flag to disable auto negotiation

Paul-Louis Ageneau 4 år sedan
förälder
incheckning
74f376e246
5 ändrade filer med 27 tillägg och 22 borttagningar
  1. 20 20
      examples/streamer/main.cpp
  2. 1 0
      include/rtc/configuration.hpp
  3. 1 0
      include/rtc/rtc.h
  4. 1 0
      src/capi.cpp
  5. 4 2
      src/peerconnection.cpp

+ 20 - 20
examples/streamer/main.cpp

@@ -161,12 +161,13 @@ int main(int argc, char **argv) try {
     string stunServer = "stun:stun.l.google.com:19302";
     cout << "Stun server is " << stunServer << endl;
     config.iceServers.emplace_back(stunServer);
-
+    config.disableAutoNegotiation = true;
 
     string localId = "server";
     cout << "The local ID is: " << localId << endl;
 
     auto ws = make_shared<WebSocket>();
+
     ws->onOpen([]() { cout << "WebSocket connected, signaling ready" << endl; });
 
     ws->onClosed([]() { cout << "WebSocket closed" << endl; });
@@ -219,15 +220,15 @@ shared_ptr<ClientTrackData> addVideo(const shared_ptr<PeerConnection> pc, const
     // create RTP configuration
     auto rtpConfig = shared_ptr<RtpPacketizationConfig>(new RtpPacketizationConfig(ssrc, cname, payloadType, H264RtpPacketizer::defaultClockRate));
     // create packetizer
-	auto packetizer = shared_ptr<H264RtpPacketizer>(new H264RtpPacketizer(H264RtpPacketizer::Separator::Length, rtpConfig));
-	// create H264 handler
-	shared_ptr<H264PacketizationHandler> h264Handler(new H264PacketizationHandler(packetizer));
-	// add RTCP SR handler
-	auto srReporter = make_shared<RtcpSrReporter>(rtpConfig);
-	h264Handler->addToChain(srReporter);
-	// add RTCP NACK handler
-	auto nackResponder = make_shared<RtcpNackResponder>();
-	h264Handler->addToChain(nackResponder);
+    auto packetizer = shared_ptr<H264RtpPacketizer>(new H264RtpPacketizer(H264RtpPacketizer::Separator::Length, rtpConfig));
+    // create H264 handler
+    shared_ptr<H264PacketizationHandler> h264Handler(new H264PacketizationHandler(packetizer));
+    // add RTCP SR handler
+    auto srReporter = make_shared<RtcpSrReporter>(rtpConfig);
+    h264Handler->addToChain(srReporter);
+    // add RTCP NACK handler
+    auto nackResponder = make_shared<RtcpNackResponder>();
+    h264Handler->addToChain(nackResponder);
     // set handler
     track->setRtcpHandler(h264Handler);
     track->onOpen(onOpen);
@@ -244,14 +245,14 @@ shared_ptr<ClientTrackData> addAudio(const shared_ptr<PeerConnection> pc, const
     auto rtpConfig = shared_ptr<RtpPacketizationConfig>(new RtpPacketizationConfig(ssrc, cname, payloadType, OpusRtpPacketizer::defaultClockRate));
     // create packetizer
     auto packetizer = make_shared<OpusRtpPacketizer>(rtpConfig);
-	// create opus handler
+    // create opus handler
     auto opusHandler = make_shared<OpusPacketizationHandler>(packetizer);
-	// add RTCP SR handler
-	auto srReporter = make_shared<RtcpSrReporter>(rtpConfig);
-	opusHandler->addToChain(srReporter);
-	// add RTCP NACK handler
-	auto nackResponder = make_shared<RtcpNackResponder>();
-	opusHandler->addToChain(nackResponder);
+    // add RTCP SR handler
+    auto srReporter = make_shared<RtcpSrReporter>(rtpConfig);
+    opusHandler->addToChain(srReporter);
+    // add RTCP NACK handler
+    auto nackResponder = make_shared<RtcpNackResponder>();
+    opusHandler->addToChain(nackResponder);
     // set handler
     track->setRtcpHandler(opusHandler);
     track->onOpen(onOpen);
@@ -263,7 +264,6 @@ shared_ptr<ClientTrackData> addAudio(const shared_ptr<PeerConnection> pc, const
 shared_ptr<Client> createPeerConnection(const Configuration &config,
                                                 weak_ptr<WebSocket> wws,
                                                 string id) {
-
     auto pc = make_shared<PeerConnection>(config);
     shared_ptr<Client> client(new Client(pc));
 
@@ -316,8 +316,8 @@ shared_ptr<Client> createPeerConnection(const Configuration &config,
         cout << "Audio from " << id << " opened" << endl;
     });
 
-	auto dc = pc->createDataChannel("ping-pong");
-	dc->onOpen([id, wdc = make_weak_ptr(dc)]() {
+    auto dc = pc->createDataChannel("ping-pong");
+    dc->onOpen([id, wdc = make_weak_ptr(dc)]() {
         if (auto dc = wdc.lock()) {
             dc->send("Ping");
         }

+ 1 - 0
include/rtc/configuration.hpp

@@ -68,6 +68,7 @@ struct RTC_CPP_EXPORT Configuration {
 	std::vector<IceServer> iceServers;
 	std::optional<ProxyServer> proxyServer;
 	bool enableIceTcp = false;
+	bool disableAutoNegotiation = false;
 	uint16_t portRangeBegin = 1024;
 	uint16_t portRangeEnd = 65535;
 	std::optional<size_t> mtu;

+ 1 - 0
include/rtc/rtc.h

@@ -120,6 +120,7 @@ typedef struct {
 	const char **iceServers;
 	int iceServersCount;
 	bool enableIceTcp;
+	bool disableAutoNegotiation;
 	uint16_t portRangeBegin;
 	uint16_t portRangeEnd;
 	int mtu; // <= 0 means automatic

+ 1 - 0
src/capi.cpp

@@ -353,6 +353,7 @@ int rtcCreatePeerConnection(const rtcConfiguration *config) {
 			c.iceServers.emplace_back(string(config->iceServers[i]));
 
 		c.enableIceTcp = config->enableIceTcp;
+		c.disableAutoNegotiation = config->disableAutoNegotiation;
 
 		if (config->portRangeBegin > 0 || config->portRangeEnd > 0) {
 			c.portRangeBegin = config->portRangeBegin;

+ 4 - 2
src/peerconnection.cpp

@@ -232,7 +232,8 @@ void PeerConnection::setRemoteDescription(Description description) {
 
 	if (type == Description::Type::Offer) {
 		// This is an offer, we need to answer
-		setLocalDescription(Description::Type::Answer);
+		if (!impl()->config.disableAutoNegotiation)
+			setLocalDescription(Description::Type::Answer);
 	} else {
 		// This is an answer
 		// Since we assumed passive role during DataChannel creation, we need to shift the
@@ -279,7 +280,8 @@ shared_ptr<DataChannel> PeerConnection::createDataChannel(string label, DataChan
 	if (!local || !local->hasApplication())
 		impl()->negotiationNeeded = true;
 
-	setLocalDescription();
+	if (!impl()->config.disableAutoNegotiation)
+		setLocalDescription();
 
 	return channel;
 }