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

Check RtpReceivers codecs agains room capabilities.

上级 966cabd1
......@@ -48,7 +48,10 @@ gulp.task('worker', shell.task(
));
gulp.task('test', shell.task(
[ `tap --bail --color --reporter=spec ${tests.join(' ')}` ]
[ `tap --bail --color --reporter=spec ${tests.join(' ')}` ],
{
env : { DEBUG: '*ABORT*' }
}
));
gulp.task('test-debug', shell.task(
......
......@@ -65,8 +65,7 @@ class Worker extends EventEmitter
// Set of Room instances.
this._rooms = new Set();
// Be ready for 3rd party worker libraries logging to stdout/stderr.
// Be ready for 3rd party worker libraries logging to stdout.
this._child.stdout.on('data', (buffer) =>
{
buffer.toString('utf8').split('\n').forEach((line) =>
......@@ -76,12 +75,13 @@ class Worker extends EventEmitter
});
});
// In case of a worker bug, mediasoup will call abort() and log to stderr.
this._child.stderr.on('data', (buffer) =>
{
buffer.toString('utf8').split('\n').forEach((line) =>
{
if (line)
logger.error(`mediasoup-worker's stderr: ${line}`);
console.error(`mediasoup-worker's stderr: ${line}`);
});
});
......
......@@ -22,6 +22,15 @@ module.exports =
name : 'video/vp8',
clockRate : 90000
},
{
kind : 'video',
name : 'video/h264',
clockRate : 90000,
parameters :
{
packetizationMode : 0
}
},
{
kind : 'video',
name : 'video/h264',
......
......@@ -79,12 +79,20 @@ tap.test('rtpReceiver.receive() with encodings without codecPayloadType must suc
{
name : 'video/H264',
payloadType : 101,
clockRate : 90000
clockRate : 90000,
parameters :
{
packetizationMode : 0
}
},
{
name : 'video/H265',
name : 'video/H264',
payloadType : 102,
clockRate : 90000
clockRate : 90000,
parameters :
{
packetizationMode : 1
}
}
],
encodings :
......@@ -129,7 +137,7 @@ tap.test('rtpReceiver.receive() with full rtpParameters must succeed', { timeout
codecs :
[
{
name : 'video/VP9',
name : 'video/VP8',
payloadType : 100,
clockRate : 90000,
maxptime : 80,
......
......@@ -158,6 +158,9 @@ namespace RTC
Json::Value toJson();
private:
void CheckCodec();
private:
bool isRoomCodec = false;
......@@ -279,6 +282,9 @@ namespace RTC
bool MatchesCodec(RtpCodecParameters& codec);
void Reduce(RtpCodecParameters& codec);
private:
void CheckCodecCapability();
public:
Media::Kind kind = Media::Kind::ALL;
uint8_t preferredPayloadType = 0;
......
......@@ -157,6 +157,7 @@
[ 'OS != "win"', {
'cflags': [ '-std=c++11', '-Wall', '-Wextra', '-Wno-unused-parameter' ]
}],
[ 'OS == "mac"', {
'xcode_settings':
{
......
......@@ -19,7 +19,7 @@ void DepLibUV::ClassInit()
DepLibUV::loop = new uv_loop_t;
err = uv_loop_init(DepLibUV::loop);
if (err)
std::abort();
MS_ABORT("libuv initialization failed");
}
void DepLibUV::ClassDestroy()
......
......@@ -444,7 +444,7 @@ namespace RTC
hash_function = EVP_sha512();
break;
default:
MS_ABORT("unknown algorithm");
MS_THROW_ERROR("unknown algorithm");
}
ret = X509_digest(DtlsTransport::certificate, hash_function, binary_fingerprint, &size);
......
......@@ -498,10 +498,27 @@ namespace RTC
{
MS_TRACE();
// auto rtpParameters = rtpReceiver->GetParameters();
auto rtpParameters = rtpReceiver->GetParameters();
// TODO: Check codecs availability and, optionally, uniqueness of PTs.
// If it fails throw.
// Check codecs availability. If it fails, throw.
for (auto codec : rtpParameters->codecs)
{
auto it = this->rtpCapabilities.codecs.begin();
for (; it != this->rtpCapabilities.codecs.end(); ++it)
{
auto& codecCapability = *it;
if (codecCapability.MatchesCodec(codec))
break;
}
if (it == this->rtpCapabilities.codecs.end())
{
MS_THROW_ERROR("no matching codec capability found [payloadType:%" PRIu8 "]",
codec.payloadType);
}
}
}
void Room::onPeerRtpReceiverParametersDone(RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver)
......
......@@ -106,6 +106,7 @@ namespace RTC
return json;
}
inline
void RtpCapabilities::ValidateCodecs()
{
MS_TRACE();
......
......@@ -65,7 +65,8 @@ namespace RTC
if (data[k_svcMultiStreamSupport].isBool())
this->svcMultiStreamSupport = data[k_svcMultiStreamSupport].asBool();
// TODO: Check per MIME parameters.
// Check codec capability.
CheckCodecCapability();
}
Json::Value RtpCodecCapability::toJson()
......@@ -117,6 +118,8 @@ namespace RTC
{
MS_TRACE();
static std::string k_packetizationMode = "packetizationMode";
// MIME must match.
if (this->mime != codec.mime)
return false;
......@@ -137,9 +140,20 @@ namespace RTC
break;
}
case RTC::Media::Kind::VIDEO:
default:
;
}
// Per MIME checks.
switch (this->mime.subtype)
{
case RTC::RtpCodecMime::Subtype::H264:
{
// TODO: check SVC stuff.
if (!this->parameters.IncludesInteger(k_packetizationMode,
codec.parameters.GetInteger(k_packetizationMode)))
{
return false;
}
break;
}
......@@ -148,8 +162,6 @@ namespace RTC
;
}
// TODO: Match per codec parameters, etc.
return true;
}
......@@ -167,6 +179,7 @@ namespace RTC
{
std::vector<int32_t> packetizationMode;
// NOTE: `packetizationMode` is set by RtpCodecParameter if not present.
packetizationMode.push_back(codec.parameters.GetInteger(k_packetizationMode));
this->parameters.SetArrayOfIntegers(k_packetizationMode, packetizationMode);
......@@ -177,4 +190,42 @@ namespace RTC
;
}
}
inline
void RtpCodecCapability::CheckCodecCapability()
{
MS_TRACE();
static std::string k_packetizationMode = "packetizationMode";
// Check per MIME parameters and set default values.
switch (this->mime.subtype)
{
case RTC::RtpCodecMime::Subtype::OPUS:
{
// Opus default numChannels is 2.
if (this->numChannels < 2)
this->numChannels = 2;
break;
}
case RTC::RtpCodecMime::Subtype::H264:
{
// H264 default packetizationMode is 0.
std::vector<int32_t> packetizationMode = { 0 };
if (!this->parameters.HasArrayOfIntegers(k_packetizationMode))
this->parameters.SetArrayOfIntegers(k_packetizationMode, packetizationMode);
break;
}
default:
;
}
}
}
......@@ -66,8 +66,8 @@ namespace RTC
MS_THROW_ERROR("can not be a feature codec");
}
// TODO: Check per MIME parameters and set default values.
// For example, H264 default packetizationMode is 0.
// Check codec.
CheckCodec();
}
Json::Value RtpCodecParameters::toJson()
......@@ -111,4 +111,40 @@ namespace RTC
return json;
}
inline
void RtpCodecParameters::CheckCodec()
{
MS_TRACE();
static std::string k_packetizationMode = "packetizationMode";
// Check per MIME parameters and set default values.
switch (this->mime.subtype)
{
case RTC::RtpCodecMime::Subtype::OPUS:
{
// Opus default numChannels is 2.
if (this->numChannels < 2)
this->numChannels = 2;
break;
}
case RTC::RtpCodecMime::Subtype::H264:
{
// H264 default packetizationMode is 0.
if (!this->parameters.HasInteger(k_packetizationMode))
this->parameters.SetInteger(k_packetizationMode, 0);
break;
}
default:
;
}
}
}
......@@ -158,6 +158,7 @@ namespace RTC
return json;
}
inline
void RtpParameters::ValidateCodecs()
{
MS_TRACE();
......@@ -187,6 +188,7 @@ namespace RTC
}
}
inline
void RtpParameters::ValidateEncodings()
{
uint8_t firstMediaPayloadType;
......
......@@ -42,14 +42,14 @@ namespace RTC
{
err = uv_ip4_addr(Settings::configuration.rtcListenIPv4.c_str(), 0, (struct sockaddr_in*)&RTC::TcpServer::sockaddrStorageIPv4);
if (err)
MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err));
MS_THROW_ERROR("uv_ipv4_addr() failed: %s", uv_strerror(err));
}
if (!Settings::configuration.rtcListenIPv6.empty())
{
err = uv_ip6_addr(Settings::configuration.rtcListenIPv6.c_str(), 0, (struct sockaddr_in6*)&RTC::TcpServer::sockaddrStorageIPv6);
if (err)
MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err));
MS_THROW_ERROR("uv_ipv6_addr() failed: %s", uv_strerror(err));
}
TcpServer::minPort = Settings::configuration.rtcMinPort;
......
......@@ -41,14 +41,14 @@ namespace RTC
{
err = uv_ip4_addr(Settings::configuration.rtcListenIPv4.c_str(), 0, (struct sockaddr_in*)&RTC::UdpSocket::sockaddrStorageIPv4);
if (err)
MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err));
MS_THROW_ERROR("uv_ipv4_addr() failed: %s", uv_strerror(err));
}
if (Settings::configuration.hasIPv6)
{
err = uv_ip6_addr(Settings::configuration.rtcListenIPv6.c_str(), 0, (struct sockaddr_in6*)&RTC::UdpSocket::sockaddrStorageIPv6);
if (err)
MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err));
MS_THROW_ERROR("uv_ipv6_addr() failed: %s", uv_strerror(err));
}
UdpSocket::minPort = Settings::configuration.rtcMinPort;
......
......@@ -116,7 +116,6 @@ void init()
DepLibSRTP::ClassInit();
DepUsrSCTP::ClassInit();
Utils::Crypto::ClassInit();
Utils::Crypto::ClassInit();
RTC::UdpSocket::ClassInit();
RTC::TcpServer::ClassInit();
RTC::DtlsTransport::ClassInit();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论