提交 d44c1c44 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

More work in RtpReceiver and RtpListener.

上级 bc750f10
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
/worker/bin/ /worker/bin/
/worker/cldoc/ /worker/cldoc/
/worker/mediasoup-tester.sh /worker/mediasoup-tester.sh
/tester/ /demo/
/art/ /art/
/make-trace.sh /make-trace.sh
/run.js /run.js
...@@ -14,6 +14,7 @@ let tests = ...@@ -14,6 +14,7 @@ let tests =
'test/test_Peer.js', 'test/test_Peer.js',
'test/test_Transport.js', 'test/test_Transport.js',
'test/test_RtpReceiver.js', 'test/test_RtpReceiver.js',
'test/test_RtpListener.js',
'test/test_extra.js' 'test/test_extra.js'
]; ];
......
'use strict';
const tap = require('tap');
const mediasoup = require('../');
// TODO: waiting for proper parameters definition
tap.test('lalala', { timeout: 1000 }, (t) =>
{
let server = mediasoup.Server();
t.tearDown(() => server.close());
let room = server.Room();
let peer = room.Peer('alice');
peer.createTransport({ tcp: false })
.then((transport) =>
{
let rtpReceiver1 = peer.RtpReceiver(transport);
let rtpParameters1 =
{
muxId : 'abcd',
codecs :
[
{
name : 'opus',
kind : 'audio',
payloadType : 111
}
],
encodings :
[
{
ssrc : 111222330
},
{
ssrc : 111222331
}
]
};
let rtpReceiver2 = peer.RtpReceiver(transport);
let rtpParameters2 =
{
muxId : '1234',
codecs :
[
{
name : 'PCMU',
kind : 'audio',
payloadType : 0
}
],
encodings :
[
{
ssrc : 987654321
}
]
};
Promise.all(
[
rtpReceiver1.receive(rtpParameters1)
.then(() =>
{
t.pass('first rtpReceiver.receive() succeeded');
})
.catch((error) => t.fail(`first rtpReceiver.receive() failed: ${error}`)),
rtpReceiver2.receive(rtpParameters2)
.then(() =>
{
t.pass('second rtpReceiver.receive() succeeded');
})
.catch((error) => t.fail(`second rtpReceiver.receive() failed: ${error}`))
]).then(() =>
{
t.pass('both rtpReceiver.receive() succeeded');
transport.dump()
.then((data) =>
{
t.pass('transport.dump() succeeded');
t.same(Object.keys(data.rtpListener.ptTable).sort(), [ '111', '0' ].sort(), 'transport.dump() must provide the given payload types');
t.same(Object.keys(data.rtpListener.ssrcTable).sort(), [ '111222330', '111222331', '987654321' ].sort(), 'transport.dump() must provide the given ssrc values');
t.end();
})
.catch((error) => t.fail(`transport.dump() failed: ${error}`));
});
})
.catch((error) => t.fail(`peer.createTransport failed: ${error}`));
});
...@@ -26,12 +26,12 @@ tap.test('rtpReceiver.receive() with valid `rtpParameters` must succeed', { time ...@@ -26,12 +26,12 @@ tap.test('rtpReceiver.receive() with valid `rtpParameters` must succeed', { time
{ {
name : 'opus', name : 'opus',
kind : 'audio', kind : 'audio',
payloadType : 101 payloadType : 111
}, },
{ {
name : 'vp9', name : 'PCMA',
kind : 'video', kind : 'audio',
payloadType : 102, payloadType : 8,
clockRate : 50 clockRate : 50
}, },
{ {
...@@ -41,6 +41,12 @@ tap.test('rtpReceiver.receive() with valid `rtpParameters` must succeed', { time ...@@ -41,6 +41,12 @@ tap.test('rtpReceiver.receive() with valid `rtpParameters` must succeed', { time
], ],
encodings : encodings :
[ [
{
ssrc : 111222330
},
{
ssrc : 111222331
}
] ]
}; };
let expectedRtpParameters = let expectedRtpParameters =
...@@ -51,13 +57,13 @@ tap.test('rtpReceiver.receive() with valid `rtpParameters` must succeed', { time ...@@ -51,13 +57,13 @@ tap.test('rtpReceiver.receive() with valid `rtpParameters` must succeed', { time
{ {
name : 'opus', name : 'opus',
kind : 'audio', kind : 'audio',
payloadType : 101, payloadType : 111,
clockRate : null clockRate : null
}, },
{ {
name : 'vp9', name : 'PCMA',
kind : 'video', kind : 'audio',
payloadType : 102, payloadType : 8,
clockRate : 50 clockRate : 50
}, },
{ {
...@@ -69,6 +75,12 @@ tap.test('rtpReceiver.receive() with valid `rtpParameters` must succeed', { time ...@@ -69,6 +75,12 @@ tap.test('rtpReceiver.receive() with valid `rtpParameters` must succeed', { time
], ],
encodings : encodings :
[ [
{
ssrc : 111222330
},
{
ssrc : 111222331
}
] ]
}; };
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "common.h" #include "common.h"
#include "RTC/RtpReceiver.h" #include "RTC/RtpReceiver.h"
#include "RTC/RtpParameters.h" #include "RTC/RtpParameters.h"
// #include "RTC/RTPPacket.h" // TODO: yes? let's see #include "RTC/RTPPacket.h"
#include <unordered_map> #include <unordered_map>
#include <json/json.h> #include <json/json.h>
...@@ -19,9 +19,7 @@ namespace RTC ...@@ -19,9 +19,7 @@ namespace RTC
Json::Value toJson(); Json::Value toJson();
void AddRtpReceiver(RTC::RtpReceiver *rtpReceiver, RTC::RtpParameters* rtpParameters); void AddRtpReceiver(RTC::RtpReceiver *rtpReceiver, RTC::RtpParameters* rtpParameters);
void RemoveRtpReceiver(RTC::RtpReceiver* rtpReceiver); void RemoveRtpReceiver(RTC::RtpReceiver* rtpReceiver);
RTC::RtpReceiver* GetRtpReceiver(RTC::RTPPacket* packet);
// private:
// void RemoveRtpReceiverFromRtpListener(RTC::RtpReceiver* rtpReceiver);
private: private:
// Others. // Others.
......
...@@ -10,7 +10,7 @@ namespace RTC ...@@ -10,7 +10,7 @@ namespace RTC
class SRTPSession class SRTPSession
{ {
public: public:
enum class SRTPProfile enum class Profile
{ {
NONE = 0, NONE = 0,
AES_CM_128_HMAC_SHA1_80 = 1, AES_CM_128_HMAC_SHA1_80 = 1,
...@@ -34,7 +34,7 @@ namespace RTC ...@@ -34,7 +34,7 @@ namespace RTC
static uint8_t encryptBuffer[]; static uint8_t encryptBuffer[];
public: public:
SRTPSession(Type type, SRTPProfile profile, uint8_t* key, size_t key_len); SRTPSession(Type type, Profile profile, uint8_t* key, size_t key_len);
~SRTPSession(); ~SRTPSession();
bool EncryptRTP(const uint8_t** data, size_t* len); bool EncryptRTP(const uint8_t** data, size_t* len);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
std::vector<const char*> DepLibSRTP::errors = std::vector<const char*> DepLibSRTP::errors =
{ {
// From 0 (err_status_ok) to 24 (err_status_pfkey_err). // From 0 (srtp_err_status_ok) to 24 (srtp_err_status_pfkey_err).
"nothing to report (err_status_ok)", "nothing to report (err_status_ok)",
"unspecified failure (err_status_fail)", "unspecified failure (err_status_fail)",
"unsupported parameter (err_status_bad_param)", "unsupported parameter (err_status_bad_param)",
......
...@@ -80,8 +80,8 @@ namespace RTC ...@@ -80,8 +80,8 @@ namespace RTC
Json::Value DTLSTransport::localFingerprints = Json::Value(Json::objectValue); Json::Value DTLSTransport::localFingerprints = Json::Value(Json::objectValue);
std::vector<DTLSTransport::SrtpProfileMapEntry> DTLSTransport::srtpProfiles = std::vector<DTLSTransport::SrtpProfileMapEntry> DTLSTransport::srtpProfiles =
{ {
{ RTC::SRTPSession::SRTPProfile::AES_CM_128_HMAC_SHA1_80, "SRTP_AES128_CM_SHA1_80" }, { RTC::SRTPSession::Profile::AES_CM_128_HMAC_SHA1_80, "SRTP_AES128_CM_SHA1_80" },
{ RTC::SRTPSession::SRTPProfile::AES_CM_128_HMAC_SHA1_32, "SRTP_AES128_CM_SHA1_32" } { RTC::SRTPSession::Profile::AES_CM_128_HMAC_SHA1_32, "SRTP_AES128_CM_SHA1_32" }
}; };
/* Class methods. */ /* Class methods. */
...@@ -336,6 +336,8 @@ namespace RTC ...@@ -336,6 +336,8 @@ namespace RTC
SSL_CTX_set_session_cache_mode(DTLSTransport::sslCtx, SSL_SESS_CACHE_OFF); SSL_CTX_set_session_cache_mode(DTLSTransport::sslCtx, SSL_SESS_CACHE_OFF);
// Read always as much into the buffer as possible. // Read always as much into the buffer as possible.
// NOTE: This is the default for DTLS, but a bug in non latest OpenSSL
// versions makes this call required.
SSL_CTX_set_read_ahead(DTLSTransport::sslCtx, 1); SSL_CTX_set_read_ahead(DTLSTransport::sslCtx, 1);
SSL_CTX_set_verify_depth(DTLSTransport::sslCtx, 4); SSL_CTX_set_verify_depth(DTLSTransport::sslCtx, 4);
...@@ -932,10 +934,10 @@ namespace RTC ...@@ -932,10 +934,10 @@ namespace RTC
} }
// Get the negotiated SRTP profile. // Get the negotiated SRTP profile.
RTC::SRTPSession::SRTPProfile srtp_profile; RTC::SRTPSession::Profile srtp_profile;
srtp_profile = GetNegotiatedSRTPProfile(); srtp_profile = GetNegotiatedSRTPProfile();
if (srtp_profile != RTC::SRTPSession::SRTPProfile::NONE) if (srtp_profile != RTC::SRTPSession::Profile::NONE)
{ {
// Extract the SRTP keys (will notify the listener with them). // Extract the SRTP keys (will notify the listener with them).
ExtractSRTPKeys(srtp_profile); ExtractSRTPKeys(srtp_profile);
...@@ -1026,7 +1028,7 @@ namespace RTC ...@@ -1026,7 +1028,7 @@ namespace RTC
} }
inline inline
void DTLSTransport::ExtractSRTPKeys(RTC::SRTPSession::SRTPProfile srtp_profile) void DTLSTransport::ExtractSRTPKeys(RTC::SRTPSession::Profile srtp_profile)
{ {
MS_TRACE(); MS_TRACE();
...@@ -1074,11 +1076,11 @@ namespace RTC ...@@ -1074,11 +1076,11 @@ namespace RTC
} }
inline inline
RTC::SRTPSession::SRTPProfile DTLSTransport::GetNegotiatedSRTPProfile() RTC::SRTPSession::Profile DTLSTransport::GetNegotiatedSRTPProfile()
{ {
MS_TRACE(); MS_TRACE();
RTC::SRTPSession::SRTPProfile negotiated_srtp_profile = RTC::SRTPSession::SRTPProfile::NONE; RTC::SRTPSession::Profile negotiated_srtp_profile = RTC::SRTPSession::Profile::NONE;
// Ensure that the SRTP profile has been negotiated. // Ensure that the SRTP profile has been negotiated.
SRTP_PROTECTION_PROFILE* ssl_srtp_profile = SSL_get_selected_srtp_profile(this->ssl); SRTP_PROTECTION_PROFILE* ssl_srtp_profile = SSL_get_selected_srtp_profile(this->ssl);
...@@ -1100,7 +1102,7 @@ namespace RTC ...@@ -1100,7 +1102,7 @@ namespace RTC
} }
} }
MS_ASSERT(negotiated_srtp_profile != RTC::SRTPSession::SRTPProfile::NONE, "chosen SRTP profile is not an available one"); MS_ASSERT(negotiated_srtp_profile != RTC::SRTPSession::Profile::NONE, "chosen SRTP profile is not an available one");
return negotiated_srtp_profile; return negotiated_srtp_profile;
} }
......
...@@ -7,9 +7,8 @@ namespace RTC ...@@ -7,9 +7,8 @@ namespace RTC
{ {
/* Instance methods. */ /* Instance methods. */
ICEServer::ICEServer(Listener* listener, ICEServer::IceComponent iceComponent, const std::string& usernameFragment, const std::string password) : ICEServer::ICEServer(Listener* listener, const std::string& usernameFragment, const std::string password) :
listener(listener), listener(listener),
iceComponent(iceComponent),
usernameFragment(usernameFragment), usernameFragment(usernameFragment),
password(password) password(password)
{ {
......
...@@ -107,4 +107,23 @@ namespace RTC ...@@ -107,4 +107,23 @@ namespace RTC
it++; it++;
} }
} }
RTC::RtpReceiver* RtpListener::GetRtpReceiver(RTC::RTPPacket* packet)
{
MS_TRACE();
// TODO: read the ORTC doc.
// Check the SSRC table.
auto it = this->ssrcTable.find(packet->GetSSRC());
if (it == this->ssrcTable.end())
{
return nullptr;
}
else
{
return it->second;
}
}
} }
...@@ -185,7 +185,10 @@ namespace RTC ...@@ -185,7 +185,10 @@ namespace RTC
struct EncodingParameters encoding; struct EncodingParameters encoding;
if (data[k_ssrc].isUInt()) // `ssrc` is mandatory.
if (!data[k_ssrc].isUInt())
MS_THROW_ERROR("missing `ssrc`");
encoding.ssrc = (uint32_t)data[k_ssrc].asUInt(); encoding.ssrc = (uint32_t)data[k_ssrc].asUInt();
// Append to the encodings vector. // Append to the encodings vector.
......
...@@ -57,7 +57,7 @@ namespace RTC ...@@ -57,7 +57,7 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
SRTPSession::SRTPSession(Type type, SRTPProfile profile, uint8_t* key, size_t key_len) SRTPSession::SRTPSession(Type type, Profile profile, uint8_t* key, size_t key_len)
{ {
MS_TRACE(); MS_TRACE();
...@@ -69,11 +69,11 @@ namespace RTC ...@@ -69,11 +69,11 @@ namespace RTC
switch (profile) switch (profile)
{ {
case SRTPProfile::AES_CM_128_HMAC_SHA1_80: case Profile::AES_CM_128_HMAC_SHA1_80:
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp); srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp);
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
break; break;
case SRTPProfile::AES_CM_128_HMAC_SHA1_32: case Profile::AES_CM_128_HMAC_SHA1_32:
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp); srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp);
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); // NOTE: Must be 80 for RTCP!. srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); // NOTE: Must be 80 for RTCP!.
break; break;
...@@ -134,6 +134,7 @@ namespace RTC ...@@ -134,6 +134,7 @@ namespace RTC
if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE) if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE)
{ {
MS_WARN("cannot encrypt RTP packet, size too big (%zu bytes)", *len); MS_WARN("cannot encrypt RTP packet, size too big (%zu bytes)", *len);
this->lastError = srtp_err_status_fail; this->lastError = srtp_err_status_fail;
return false; return false;
} }
...@@ -144,6 +145,7 @@ namespace RTC ...@@ -144,6 +145,7 @@ namespace RTC
if (DepLibSRTP::IsError(this->lastError)) if (DepLibSRTP::IsError(this->lastError))
{ {
MS_DEBUG("srtp_protect() failed: %s", DepLibSRTP::GetErrorString(this->lastError)); MS_DEBUG("srtp_protect() failed: %s", DepLibSRTP::GetErrorString(this->lastError));
return false; return false;
} }
...@@ -161,6 +163,7 @@ namespace RTC ...@@ -161,6 +163,7 @@ namespace RTC
if (DepLibSRTP::IsError(this->lastError)) if (DepLibSRTP::IsError(this->lastError))
{ {
MS_DEBUG("srtp_unprotect() failed: %s", DepLibSRTP::GetErrorString(this->lastError)); MS_DEBUG("srtp_unprotect() failed: %s", DepLibSRTP::GetErrorString(this->lastError));
return false; return false;
} }
...@@ -175,6 +178,7 @@ namespace RTC ...@@ -175,6 +178,7 @@ namespace RTC
if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE) if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE)
{ {
MS_WARN("cannot encrypt RTCP packet, size too big (%zu bytes)", *len); MS_WARN("cannot encrypt RTCP packet, size too big (%zu bytes)", *len);
this->lastError = srtp_err_status_fail; this->lastError = srtp_err_status_fail;
return false; return false;
} }
...@@ -185,6 +189,7 @@ namespace RTC ...@@ -185,6 +189,7 @@ namespace RTC
if (DepLibSRTP::IsError(this->lastError)) if (DepLibSRTP::IsError(this->lastError))
{ {
MS_DEBUG("srtp_protect_rtcp() failed: %s", DepLibSRTP::GetErrorString(this->lastError)); MS_DEBUG("srtp_protect_rtcp() failed: %s", DepLibSRTP::GetErrorString(this->lastError));
return false; return false;
} }
...@@ -202,6 +207,7 @@ namespace RTC ...@@ -202,6 +207,7 @@ namespace RTC
if (DepLibSRTP::IsError(this->lastError)) if (DepLibSRTP::IsError(this->lastError))
{ {
MS_DEBUG("srtp_unprotect_rtcp() failed: %s", DepLibSRTP::GetErrorString(this->lastError)); MS_DEBUG("srtp_unprotect_rtcp() failed: %s", DepLibSRTP::GetErrorString(this->lastError));
return false; return false;
} }
......
...@@ -48,7 +48,7 @@ namespace RTC ...@@ -48,7 +48,7 @@ namespace RTC
// Be ready to parse more than a single frame in a single TCP chunk. // Be ready to parse more than a single frame in a single TCP chunk.
while (true) while (true)
{ {
// We may receive multiple packets in the same TCP chunk. If onw of them is // We may receive multiple packets in the same TCP chunk. If one of them is
// a DTLS Close Alert this would be closed (Close() called) so we cannot call // a DTLS Close Alert this would be closed (Close() called) so we cannot call
// our listeners anymore. // our listeners anymore.
if (IsClosing()) if (IsClosing())
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论