Browse Source

Merge branch 'api_updates' of https://github.com/stazio/libdatachannel into api_updates

Staz M 4 years ago
parent
commit
875defd17f
4 changed files with 21 additions and 17 deletions
  1. 1 1
      src/description.cpp
  2. 6 3
      src/peerconnection.cpp
  3. 0 1
      src/rtcp.cpp
  4. 14 12
      src/track.cpp

+ 1 - 1
src/description.cpp

@@ -710,7 +710,7 @@ void Description::Video::addVideoCodec(int payloadType, const string &codec) {
 void Description::Audio::addAudioCodec(int payloadType, const string &codec) {
 void Description::Audio::addAudioCodec(int payloadType, const string &codec) {
     // TODO This 48000/2 should be parameterized
     // TODO This 48000/2 should be parameterized
     RTPMap map(std::to_string(payloadType) + ' ' + codec + "/48000/2");
     RTPMap map(std::to_string(payloadType) + ' ' + codec + "/48000/2");
-    map.fmtps.emplace_back("maxaveragebitrate=510000; stereo=1; sprop-stereo=1; useinbandfec=1");
+    map.fmtps.emplace_back("maxaveragebitrate=96000; stereo=1; sprop-stereo=1; useinbandfec=1");
     addRTPMap(map);
     addRTPMap(map);
 }
 }
 
 

+ 6 - 3
src/peerconnection.cpp

@@ -770,9 +770,8 @@ std::optional<std::string> PeerConnection::getMidFromSSRC(SSRC ssrc) {
     if (auto it = mMidFromSssrc.find(ssrc); it != mMidFromSssrc.end()) {
     if (auto it = mMidFromSssrc.find(ssrc); it != mMidFromSssrc.end()) {
         return it->second;
         return it->second;
     } else {
     } else {
-        std::lock_guard lock(mLocalDescriptionMutex);
-        if (!mLocalDescription)
-            return nullopt;
+        std::lock_guard lockA(mRemoteDescriptionMutex);
+        if (mRemoteDescription) {
 
 
         for (unsigned int i = 0; i < mRemoteDescription->mediaCount(); ++i) {
         for (unsigned int i = 0; i < mRemoteDescription->mediaCount(); ++i) {
             if (auto found = std::visit(
             if (auto found = std::visit(
@@ -790,7 +789,10 @@ std::optional<std::string> PeerConnection::getMidFromSSRC(SSRC ssrc) {
                 return *found;
                 return *found;
             }
             }
         }
         }
+	}
 
 
+        std::lock_guard lockB(mLocalDescriptionMutex);
+        if (mLocalDescription) {
         for (unsigned int i = 0; i < mLocalDescription->mediaCount(); ++i) {
         for (unsigned int i = 0; i < mLocalDescription->mediaCount(); ++i) {
             if (auto found = std::visit(
             if (auto found = std::visit(
                     rtc::overloaded{[&](Description::Application *) -> std::optional<string> {
                     rtc::overloaded{[&](Description::Application *) -> std::optional<string> {
@@ -807,6 +809,7 @@ std::optional<std::string> PeerConnection::getMidFromSSRC(SSRC ssrc) {
                 return *found;
                 return *found;
             }
             }
         }
         }
+	}
     }
     }
     return nullopt;
     return nullopt;
 }
 }

+ 0 - 1
src/rtcp.cpp

@@ -97,7 +97,6 @@ void RtcpReceivingSession::pushREMB(unsigned int bitrate) {
 	auto remb = reinterpret_cast<RTCP_REMB *>(msg->data());
 	auto remb = reinterpret_cast<RTCP_REMB *>(msg->data());
 	remb->preparePacket(mSsrc, 1, bitrate);
 	remb->preparePacket(mSsrc, 1, bitrate);
 	remb->setSsrc(0, mSsrc);
 	remb->setSsrc(0, mSsrc);
-//	remb->log();
 
 
     send(msg);
     send(msg);
 }
 }

+ 14 - 12
src/track.cpp

@@ -142,18 +142,20 @@ void Track::incoming(message_ptr message) {
 
 
 void Track::setRtcpHandler(std::shared_ptr<RtcpHandler> handler) {
 void Track::setRtcpHandler(std::shared_ptr<RtcpHandler> handler) {
 	mRtcpHandler = std::move(handler);
 	mRtcpHandler = std::move(handler);
-	mRtcpHandler->onOutgoing([&](const rtc::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([&](const rtc::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
+		});
+	}
 }
 }
 
 
 bool Track::requestKeyframe() {
 bool Track::requestKeyframe() {