Browse Source

Fixed media demo; Refactored mediaCount to be unsigned (aka size type)

Staz M 4 years ago
parent
commit
16208d00ca

+ 1 - 1
examples/media/main.cpp

@@ -67,7 +67,7 @@ int main() {
 
 		auto track = pc->addTrack(media);
 
-		auto session = std::make_shared<rtc::RtcpSession>();
+		auto session = std::make_shared<rtc::RtcpReceivingSession>();
 		track->setRtcpHandler(session);
 
 		track->onMessage(

+ 1 - 1
include/rtc/description.hpp

@@ -202,7 +202,7 @@ public:
 
 	std::variant<Media *, Application *> media(int index);
 	std::variant<const Media *, const Application *> media(int index) const;
-	int mediaCount() const;
+	unsigned int mediaCount() const;
 
 	Application *application();
 

+ 1 - 1
src/description.cpp

@@ -364,7 +364,7 @@ Description::media(int index) const {
 	}
 }
 
-int Description::mediaCount() const { return int(mEntries.size()); }
+unsigned int Description::mediaCount() const { return mEntries.size(); }
 
 Description::Entry::Entry(const string &mline, string mid, Direction dir)
     : mMid(std::move(mid)), mDirection(dir) {

+ 7 - 31
src/dtlssrtptransport.cpp

@@ -262,35 +262,11 @@ void DtlsSrtpTransport::postHandshake() {
 	serverSalt = clientSalt + SRTP_SALT_LEN;
 #endif
 
-	std::memcpy(clientSessionKey, clientKey, SRTP_AES_128_KEY_LEN);
-	std::memcpy(clientSessionKey + SRTP_AES_128_KEY_LEN, clientSalt, SRTP_SALT_LEN);
-
-	std::memcpy(serverSessionKey, serverKey, SRTP_AES_128_KEY_LEN);
-	std::memcpy(serverSessionKey + SRTP_AES_128_KEY_LEN, serverSalt, SRTP_SALT_LEN);
-
-//	srtp_policy_t inbound = {};
-//	srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&inbound.rtp);
-//	srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&inbound.rtcp);
-//	inbound.ssrc.type = ssrc_any_inbound;
-//	inbound.ssrc.value = 0;
-//	inbound.key = mIsClient ? serverSessionKey : clientSessionKey;
-//	inbound.next = nullptr;
-//
-//	if (srtp_err_status_t err = srtp_add_stream(mSrtpIn, &inbound))
-//		throw std::runtime_error("SRTP add inbound stream failed, status=" +
-//		                         to_string(static_cast<int>(err)));
-//
-//	srtp_policy_t outbound = {};
-//	srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&outbound.rtp);
-//	srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&outbound.rtcp);
-//	outbound.ssrc.type = ssrc_any_outbound;
-//	outbound.ssrc.value = 0;
-//	outbound.key = mIsClient ? clientSessionKey : serverSessionKey;
-//	outbound.next = nullptr;
-//
-//	if (srtp_err_status_t err = srtp_add_stream(mSrtpOut, &outbound))
-//		throw std::runtime_error("SRTP add outbound stream failed, status=" +
-//		                         to_string(static_cast<int>(err)));
+	std::memcpy(mClientSessionKey, clientKey, SRTP_AES_128_KEY_LEN);
+	std::memcpy(mClientSessionKey + SRTP_AES_128_KEY_LEN, clientSalt, SRTP_SALT_LEN);
+
+	std::memcpy(mServerSessionKey, serverKey, SRTP_AES_128_KEY_LEN);
+	std::memcpy(mServerSessionKey + SRTP_AES_128_KEY_LEN, serverSalt, SRTP_SALT_LEN);
 
 	mInitDone = true;
 }
@@ -301,7 +277,7 @@ void DtlsSrtpTransport::addSSRC(uint32_t ssrc) {
     srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&inbound.rtcp);
     inbound.ssrc.type = ssrc_specific;
     inbound.ssrc.value = ssrc;
-    inbound.key = mIsClient ? serverSessionKey : clientSessionKey;
+    inbound.key = mIsClient ? mServerSessionKey : mClientSessionKey;
     inbound.next = nullptr;
 
     if (srtp_err_status_t err = srtp_add_stream(mSrtpIn, &inbound))
@@ -314,7 +290,7 @@ void DtlsSrtpTransport::addSSRC(uint32_t ssrc) {
     srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&outbound.rtcp);
     outbound.ssrc.type = ssrc_specific;
     outbound.ssrc.value = ssrc;
-    outbound.key = mIsClient ? clientSessionKey : serverSessionKey;
+    outbound.key = mIsClient ? mClientSessionKey : mServerSessionKey;
     outbound.next = nullptr;
 
     if (srtp_err_status_t err = srtp_add_stream(mSrtpOut, &outbound))

+ 2 - 2
src/dtlssrtptransport.hpp

@@ -50,8 +50,8 @@ private:
 	srtp_t mSrtpIn, mSrtpOut;
 	bool mInitDone = false;
 
-    unsigned char clientSessionKey[SRTP_AES_ICM_128_KEY_LEN_WSALT];
-    unsigned char serverSessionKey[SRTP_AES_ICM_128_KEY_LEN_WSALT];
+    unsigned char mClientSessionKey[SRTP_AES_ICM_128_KEY_LEN_WSALT];
+    unsigned char mServerSessionKey[SRTP_AES_ICM_128_KEY_LEN_WSALT];
 };
 
 } // namespace rtc

+ 3 - 3
src/peerconnection.cpp

@@ -106,7 +106,7 @@ void PeerConnection::setRemoteDescription(Description description) {
 		throw std::invalid_argument("Remote description has no media line");
 
 	int activeMediaCount = 0;
-	for (int i = 0; i < description.mediaCount(); ++i)
+	for (unsigned int i = 0; i < description.mediaCount(); ++i)
 		std::visit( // reciprocate each media
 		    rtc::overloaded{[&](Description::Application *) { ++activeMediaCount; },
 		                    [&](Description::Media *media) {
@@ -568,7 +568,7 @@ void PeerConnection::forwardMedia(message_ptr message) {
 		if (!mLocalDescription)
 			return;
 
-		for (int i = 0; i < mRemoteDescription->mediaCount(); ++i) {
+		for (unsigned int i = 0; i < mRemoteDescription->mediaCount(); ++i) {
 			if (auto found = std::visit(
 			        rtc::overloaded{[&](Description::Application *) -> std::optional<string> {
 				                        return std::nullopt;
@@ -728,7 +728,7 @@ void PeerConnection::processLocalDescription(Description description) {
     auto remote = remoteDescription();
 	if (remote && remote->type() == Description::Type::Offer) {
 		// Reciprocate remote description
-		for (int i = 0; i < remote->mediaCount(); ++i)
+		for (unsigned int i = 0; i < remote->mediaCount(); ++i)
 			std::visit( // reciprocate each media
 			    rtc::overloaded{
 			        [&](Description::Application *app) {