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

Require full MIME "type/subtype" format for codec names.

上级 d687f935
......@@ -23,7 +23,7 @@ tap.test('rtpReceiver.receive() with valid `rtpParameters` must succeed', { time
codecs :
[
{
name : 'H264',
name : 'video/H264',
payloadType : 100,
clockRate : 90000,
maxptime : 80,
......
......@@ -31,7 +31,7 @@ tap.test('alice, bob and carol create RtpReceivers and expect RtpSenders', { tim
codecs :
[
{
name : 'opus',
name : 'audio/opus',
payloadType : 101,
clockRate : 90000
}
......@@ -60,12 +60,12 @@ tap.test('alice, bob and carol create RtpReceivers and expect RtpSenders', { tim
codecs :
[
{
name : 'vp9',
name : 'video/vp9',
payloadType : 102,
clockRate : 90000
},
{
name : 'rtx',
name : 'video/rtx',
payloadType : 96,
clockRate : 90000,
parameters : { apt: 102 }
......@@ -99,12 +99,12 @@ tap.test('alice, bob and carol create RtpReceivers and expect RtpSenders', { tim
codecs :
[
{
name : 'vp9',
name : 'video/vp9',
payloadType : 103,
clockRate : 90000
},
{
name : 'rtx',
name : 'video/rtx',
payloadType : 97,
clockRate : 90000,
parameters : { apt: 103 }
......@@ -138,7 +138,7 @@ tap.test('alice, bob and carol create RtpReceivers and expect RtpSenders', { tim
codecs :
[
{
name : 'opus',
name : 'audio/opus',
payloadType : 101,
clockRate : 90000
}
......@@ -167,11 +167,11 @@ tap.test('alice, bob and carol create RtpReceivers and expect RtpSenders', { tim
codecs :
[
{
name : 'vp9',
name : 'video/vp9',
payloadType : 103
},
{
name : 'rtx',
name : 'video/rtx',
payloadType : 97,
clockRate : 90000,
parameters : { apt: 103 }
......@@ -585,7 +585,7 @@ function createRtpReceiver(t, peer, kind, transport, rtpParameters)
return rtpReceiver.receive(rtpParameters)
.then(() =>
{
t.pass(`rtpReceiver.receive() succeeded for ${peer.name}`);
t.pass(`rtpReceiver.receive() succeeded for ${peer.name} and kind "${kind}"`);
})
.catch((error) => t.fail(`rtpReceiver.receive() failed for ${peer.name}: ${error}`));
.catch((error) => t.fail(`rtpReceiver.receive() failed for ${peer.name} and kind "${kind}": ${error}`));
}
......@@ -2,6 +2,7 @@
#define MS_RTC_RTP_PARAMETERS_H
#include "common.h"
#include "RTC/RtpKind.h"
#include <string>
#include <vector>
#include <unordered_map>
......@@ -56,7 +57,19 @@ namespace RTC
class RtpCodecParameters
{
public:
RtpCodecParameters(Json::Value& data);
enum class Subtype
{
MEDIA = 1,
RTX,
ULPFEC,
FLEXFEC,
RED,
CN,
DTMF
};
public:
RtpCodecParameters(RTC::RtpKind kind, Json::Value& data);
virtual ~RtpCodecParameters();
Json::Value toJson();
......@@ -70,6 +83,10 @@ namespace RTC
uint32_t numChannels = 0;
std::vector<RtcpFeedback> rtcpFeedback;
CustomParameters parameters;
public:
RTC::RtpKind type;
Subtype subtype;
};
class RtpFecParameters
......@@ -156,7 +173,12 @@ namespace RTC
class RtpParameters
{
public:
RtpParameters(Json::Value& data);
static RtpParameters* Factory(RTC::RtpKind kind, Json::Value& data);
private:
RtpParameters(RTC::RtpKind kind, Json::Value& data);
public:
RtpParameters(const RtpParameters* RtpParameters);
virtual ~RtpParameters();
......@@ -171,6 +193,9 @@ namespace RTC
RtcpParameters rtcp;
bool hasRtcp = false;
Json::Value userParameters;
public:
RTC::RtpKind kind;
};
}
......
......@@ -6,9 +6,23 @@
namespace RTC
{
static std::unordered_map<std::string, RtpCodecParameters::Subtype> string2Subtype =
{
{ "rtx", RtpCodecParameters::Subtype::RTX },
{ "RTX", RtpCodecParameters::Subtype::RTX },
{ "ulpfec", RtpCodecParameters::Subtype::ULPFEC },
{ "flexfec", RtpCodecParameters::Subtype::FLEXFEC },
{ "red", RtpCodecParameters::Subtype::RED },
{ "RED", RtpCodecParameters::Subtype::RED },
{ "cn", RtpCodecParameters::Subtype::CN },
{ "CN", RtpCodecParameters::Subtype::CN },
{ "telephone-event", RtpCodecParameters::Subtype::DTMF },
{ "dtmf", RtpCodecParameters::Subtype::DTMF }
};
/* Instance methods. */
RtpCodecParameters::RtpCodecParameters(Json::Value& data)
RtpCodecParameters::RtpCodecParameters(RTC::RtpKind kind, Json::Value& data)
{
MS_TRACE();
......@@ -29,8 +43,22 @@ namespace RTC
MS_THROW_ERROR("missing `RtpCodecParameters.name`");
this->name = data[k_name].asString();
if (this->name.empty())
MS_THROW_ERROR("empty `RtpCodecParameters.name`");
// Get and check name MIME type.
if (kind == RTC::RtpKind::AUDIO && this->name.compare(0, 6, "audio/") == 0)
this->type = RTC::RtpKind::AUDIO;
else if (kind == RTC::RtpKind::VIDEO && this->name.compare(0, 6, "video/") == 0)
this->type = RTC::RtpKind::VIDEO;
else
MS_THROW_ERROR("invalid `RtpCodecParameters.name` MIME type [name:%s", this->name.c_str());
// Get name MIME subtype.
std::string subtype = this->name.substr(6);
if (string2Subtype.find(subtype) == string2Subtype.end())
this->subtype = Subtype::MEDIA;
else
this->subtype = string2Subtype[subtype];
// `payloadType` is mandatory.
if (!data[k_payloadType].isUInt())
......
......@@ -6,9 +6,24 @@
namespace RTC
{
/* Class methods. */
RtpParameters* RtpParameters::Factory(RTC::RtpKind kind, Json::Value& data)
{
MS_TRACE();
// NOTE: This may throw,
auto rtpParameters = new RtpParameters(kind, data);
// TODO: check parameters and, if wrong, free them and throw.
return rtpParameters;
}
/* Instance methods. */
RtpParameters::RtpParameters(Json::Value& data)
RtpParameters::RtpParameters(RTC::RtpKind kind, Json::Value& data) :
kind(kind)
{
MS_TRACE();
......@@ -33,7 +48,7 @@ namespace RTC
for (Json::UInt i = 0; i < json_codecs.size(); i++)
{
RtpCodecParameters codec(json_codecs[i]);
RtpCodecParameters codec(this->kind, json_codecs[i]);
// Append to the codecs vector.
this->codecs.push_back(codec);
......@@ -97,6 +112,8 @@ namespace RTC
this->rtcp = rtpParameters->rtcp;
this->hasRtcp = rtpParameters->hasRtcp;
this->userParameters = rtpParameters->userParameters;
this->kind = rtpParameters->kind;
}
RtpParameters::~RtpParameters()
......
......@@ -119,7 +119,7 @@ namespace RTC
try
{
this->rtpParameters = new RTC::RtpParameters(request->data);
this->rtpParameters = RTC::RtpParameters::Factory(this->kind, request->data);
}
catch (const MediaSoupError &error)
{
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论