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

More stuff in codecs

上级 a668bb05
......@@ -9,7 +9,7 @@ let supportedRtpCapabilities =
{
codecs :
[
// Audio codecs.
// Audio codecs:
{
kind : 'audio',
name : 'audio/opus',
......@@ -47,37 +47,65 @@ let supportedRtpCapabilities =
preferredPayloadType : 8,
clockRate : 8000
},
// Video codecs.
// Video codecs:
{
kind : 'video',
name : 'video/VP8',
preferredPayloadType : 100,
preferredPayloadType : 110,
clockRate : 90000
},
{
kind : 'video',
name : 'video/VP9',
preferredPayloadType : 101,
preferredPayloadType : 111,
clockRate : 90000
},
{
kind : 'video',
name : 'video/H264',
preferredPayloadType : 102,
preferredPayloadType : 112,
clockRate : 90000
},
{
kind : 'video',
name : 'video/H265',
preferredPayloadType : 103,
clockRate : 90000
},
// Depth codecs.
// Depth codecs:
{
kind : 'depth',
name : 'video/VP8',
preferredPayloadType : 110,
preferredPayloadType : 120,
clockRate : 90000
},
// Feature codecs:
{
kind : 'audio',
name : 'audio/CN',
preferredPayloadType : 77,
clockRate : 32000
},
{
kind : 'audio',
name : 'audio/CN',
preferredPayloadType : 78,
clockRate : 16000
},
{
kind : 'audio',
name : 'audio/CN',
preferredPayloadType : 13,
clockRate : 8000
},
{
kind : 'audio',
name : 'audio/telephone-event',
preferredPayloadType : 79,
clockRate : 8000
}
],
headerExtensions:
[
{
kind : '',
uri : 'urn:ietf:params:rtp-hdrext:sdes:mid',
preferredId : 1,
preferredEncrypt : false
}
]
};
......
......@@ -10,13 +10,13 @@ const shell = require('gulp-shell');
let tests =
[
'test/test_mediasoup.js',
'test/test_Server.js',
'test/test_Room.js',
'test/test_Peer.js',
'test/test_Transport.js',
// 'test/test_mediasoup.js',
// 'test/test_Server.js',
// 'test/test_Room.js',
// 'test/test_Peer.js',
// 'test/test_Transport.js',
'test/test_RtpReceiver.js',
'test/test_extra.js'
// 'test/test_extra.js'
// NOTE: Disable this test until fixed
// 'test/test_scene_1.js'
];
......
......@@ -6,9 +6,21 @@ module.exports =
{
mediaCodecs :
[
{ kind: 'audio', name: 'audio/opus' },
{ kind: 'video', name: 'video/vp8' },
{ kind: 'depth', name: 'audio/opus' }
{
kind : 'audio',
name : 'audio/opus',
clockRate : 48000
},
{
kind : 'video',
name : 'video/vp8',
clockRate : 90000
},
{
kind : 'depth',
name : 'video/vp8',
clockRate : 90000
}
]
},
......
......@@ -40,7 +40,8 @@ tap.test('rtpReceiver.receive() with no encodings must succeed', { timeout: 2000
[
{
name : 'audio/opus',
payloadType : 100
payloadType : 100,
clockRate : 48000
}
]
})
......@@ -73,11 +74,13 @@ tap.test('rtpReceiver.receive() with encodings without codecPayloadType must suc
[
{
name : 'video/H264',
payloadType : 101
payloadType : 101,
clockRate : 90000
},
{
name : 'video/H265',
payloadType : 102
payloadType : 102,
clockRate : 90000
}
],
encodings :
......@@ -148,7 +151,8 @@ tap.test('rtpReceiver.receive() with full rtpParameters must succeed', { timeout
foo : 'barœæ€',
bar : true,
baz : -123,
lol : -456.789
lol : -456.789,
ids : [ 123, 2, 3 ]
}
}
],
......@@ -243,7 +247,7 @@ tap.test('two rtpReceiver.receive() over the same transport sharing PT values mu
{
name : 'audio/opus',
payloadType : 101,
clockRate : 90000
clockRate : 48000
}
],
encodings :
......@@ -265,7 +269,7 @@ tap.test('two rtpReceiver.receive() over the same transport sharing PT values mu
{
name : 'audio/opus',
payloadType : 101,
clockRate : 90000
clockRate : 48000
}
],
encodings :
......@@ -339,7 +343,8 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
[
{
name : '/opus',
payloadType : 101
payloadType : 101,
clockRate : 48000
}
]
})
......@@ -358,7 +363,8 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
[
{
name : 'audio/',
payloadType : 101
payloadType : 101,
clockRate : 48000
}
]
})
......@@ -376,7 +382,8 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
codecs :
[
{
payloadType : 102
payloadType : 102,
clockRate : 90000
}
]
})
......@@ -394,7 +401,8 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
codecs :
[
{
name : 'audio/opus'
name : 'audio/opus',
clockRate : 48000
}
]
})
......@@ -405,6 +413,25 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
});
});
funcs.push(function()
{
return rtpReceiver.receive(
{
codecs :
[
{
name : 'audio/opus',
payloadType : 102
}
]
})
.then(() => t.fail('rtpReceiver.receive() succeeded'))
.catch((error) =>
{
t.pass(`rtpReceiver.receive() without codec.clockRate failed: ${error}`);
});
});
funcs.push(function()
{
return rtpReceiver.receive(
......@@ -414,6 +441,7 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
{
name : 'audio/opus',
payloadType : 101,
clockRate : 48000,
rtx : {}
}
]
......@@ -433,11 +461,13 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
[
{
name : 'audio/opus',
payloadType : 101
payloadType : 101,
clockRate : 48000
},
{
name : 'audio/opus',
payloadType : 101
payloadType : 101,
clockRate : 48000
}
]
})
......@@ -457,6 +487,7 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
{
name : 'audio/opus',
payloadType : 100,
clockRate : 48000,
rtx :
{
payloadType : 101
......@@ -464,7 +495,8 @@ tap.test('rtpReceiver.receive() with wrong codecs must fail', { timeout: 2000 },
},
{
name : 'audio/G722',
payloadType : 101
payloadType : 101,
clockRate : 8000
}
]
})
......@@ -497,7 +529,8 @@ tap.test('rtpReceiver.receive() with wrong encodings must fail', { timeout: 2000
[
{
name : 'audio/opus',
payloadType : 101
payloadType : 101,
clockRate : 48000
}
],
encodings :
......@@ -522,11 +555,13 @@ tap.test('rtpReceiver.receive() with wrong encodings must fail', { timeout: 2000
[
{
name : 'audio/opus',
payloadType : 101
payloadType : 101,
clockRate : 48000
},
{
name : 'audio/CN',
payloadType : 102
payloadType : 102,
clockRate : 16000
}
],
encodings :
......@@ -565,7 +600,7 @@ tap.test('two rtpReceiver.receive() over the same transport sharing PT values mu
{
name : 'audio/opus',
payloadType : 101,
clockRate : 90000
clockRate : 48000
}
]
})
......@@ -581,7 +616,7 @@ tap.test('two rtpReceiver.receive() over the same transport sharing PT values mu
{
name : 'audio/PCMU',
payloadType : 101,
clockRate : 90000
clockRate : 8000
}
]
})
......@@ -613,7 +648,8 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing
[
{
name : 'audio/opus',
payloadType : 100
payloadType : 100,
clockRate : 48000
}
]
})
......@@ -647,11 +683,13 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing
[
{
name : 'audio/opus',
payloadType : 100
payloadType : 100,
clockRate : 48000
},
{
name : 'audio/PCMU',
payloadType : 0
payloadType : 0,
clockRate : 8000
}
]
})
......@@ -688,11 +726,13 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing
[
{
name : 'audio/opus',
payloadType : 100
payloadType : 100,
clockRate : 48000
},
{
name : 'audio/PCMU',
payloadType : 0
payloadType : 0,
clockRate : 8000
}
],
encodings :
......@@ -739,11 +779,13 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing
[
{
name : 'audio/opus',
payloadType : 100
payloadType : 100,
clockRate : 48000
},
{
name : 'audio/PCMU',
payloadType : 0
payloadType : 0,
clockRate : 8000
}
],
encodings :
......@@ -788,11 +830,13 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing
[
{
name : 'audio/opus',
payloadType : 100
payloadType : 100,
clockRate : 48000
},
{
name : 'audio/PCMU',
payloadType : 0
payloadType : 0,
clockRate : 8000
}
],
encodings :
......
......@@ -17,7 +17,8 @@ namespace RTC
BOOLEAN = 1,
INTEGER,
DOUBLE,
STRING
STRING,
ARRAY_POSITIVE_INTEGER
};
public:
......@@ -43,18 +44,40 @@ namespace RTC
stringValue(stringValue)
{}
CustomParameterValue(std::vector<uint32_t>& arrayPositiveInteger) :
type(Type::ARRAY_POSITIVE_INTEGER),
arrayPositiveInteger(arrayPositiveInteger)
{}
Json::Value toJson()
{
switch (this->type)
{
case Type::BOOLEAN:
{
return this->booleanValue;
}
case Type::INTEGER:
{
return (Json::Int)this->integerValue;
}
case Type::DOUBLE:
{
return this->doubleValue;
}
case Type::STRING:
{
return this->stringValue;
}
case Type::ARRAY_POSITIVE_INTEGER:
{
Json::Value array(Json::arrayValue);
for (auto& entry : this->arrayPositiveInteger)
array.append((Json::UInt)entry);
return array;
}
default:
return Json::nullValue;
}
......@@ -90,14 +113,20 @@ namespace RTC
return this->type == Type::STRING;
}
bool IsArrayPositiveInteger()
{
return this->type == Type::ARRAY_POSITIVE_INTEGER;
}
private:
Type type;
Type type;
public:
bool booleanValue = false;
int32_t integerValue = 0;
double doubleValue = 0.0;
std::string stringValue;
bool booleanValue = false;
int32_t integerValue = 0;
double doubleValue = 0.0;
std::string stringValue;
std::vector<uint32_t> arrayPositiveInteger;
};
typedef std::unordered_map<std::string, CustomParameterValue> CustomParameters;
......
......@@ -42,6 +42,8 @@ namespace RTC
private:
RTC::Peer* GetPeerFromRequest(Channel::Request* request, uint32_t* peerId = nullptr);
void SetRtpCapabilities(std::vector<RTC::RtpRoomMediaCodec>& roomMediaCodecs);
RTC::RtpCodecCapability GetRtpCodecCapability(RTC::RtpRoomMediaCodec& roomMediaCodec);
/* Pure virtual methods inherited from RTC::Peer::Listener. */
public:
......
......@@ -18,7 +18,8 @@ namespace RTC
{
AUDIO = 1,
VIDEO,
DEPTH
DEPTH,
ALL
};
public:
......@@ -72,6 +73,16 @@ namespace RTC
public:
RtpCodecMime() {};
bool operator==(const RtpCodecMime& other)
{
return this->type == other.type && this->subtype == other.subtype;
}
bool operator!=(const RtpCodecMime& other)
{
return !(*this == other);
}
void SetName(std::string& name);
std::string& GetName()
......@@ -244,6 +255,7 @@ namespace RTC
class RtpCodecCapability
{
public:
RtpCodecCapability() {};
RtpCodecCapability(Json::Value& data);
Json::Value toJson();
......
......@@ -56,6 +56,27 @@ namespace RTC
break;
}
case Json::arrayValue:
{
std::vector<uint32_t> arrayPositiveInteger;
bool isValid = true;
for (Json::UInt i = 0; i < value.size() && isValid; i++)
{
auto& entry = value[i];
if (entry.isUInt())
arrayPositiveInteger.push_back((uint32_t)entry.asUInt());
else
isValid = false;
}
if (isValid)
parameters[key] = CustomParameterValue(arrayPositiveInteger);
break;
}
default:
; // Just ignore other value types.
}
......
......@@ -30,7 +30,7 @@ namespace RTC
Json::CharReader* jsonReader = builder.newCharReader();
// NOTE: This line is auto-generated frmo data/supportedRtpCapabilities.js.
const std::string capabilities = R"({"codecs":[{"kind":"audio","name":"audio/opus","preferredPayloadType":96,"clockRate":48000,"numChannels":2},{"kind":"audio","name":"audio/ISAC","preferredPayloadType":97,"clockRate":16000},{"kind":"audio","name":"audio/ISAC","preferredPayloadType":98,"clockRate":32000},{"kind":"audio","name":"audio/G722","preferredPayloadType":9,"clockRate":8000},{"kind":"audio","name":"audio/PCMU","preferredPayloadType":0,"clockRate":8000},{"kind":"audio","name":"audio/PCMA","preferredPayloadType":8,"clockRate":8000},{"kind":"video","name":"video/VP8","preferredPayloadType":100,"clockRate":90000},{"kind":"video","name":"video/VP9","preferredPayloadType":101,"clockRate":90000},{"kind":"video","name":"video/H264","preferredPayloadType":102,"clockRate":90000},{"kind":"video","name":"video/H265","preferredPayloadType":103,"clockRate":90000},{"kind":"depth","name":"video/VP8","preferredPayloadType":110,"clockRate":90000}]})";
const std::string capabilities = R"({"codecs":[{"kind":"audio","name":"audio/opus","preferredPayloadType":96,"clockRate":48000,"numChannels":2},{"kind":"audio","name":"audio/ISAC","preferredPayloadType":97,"clockRate":16000},{"kind":"audio","name":"audio/ISAC","preferredPayloadType":98,"clockRate":32000},{"kind":"audio","name":"audio/G722","preferredPayloadType":9,"clockRate":8000},{"kind":"audio","name":"audio/PCMU","preferredPayloadType":0,"clockRate":8000},{"kind":"audio","name":"audio/PCMA","preferredPayloadType":8,"clockRate":8000},{"kind":"video","name":"video/VP8","preferredPayloadType":110,"clockRate":90000},{"kind":"video","name":"video/VP9","preferredPayloadType":111,"clockRate":90000},{"kind":"video","name":"video/H264","preferredPayloadType":112,"clockRate":90000},{"kind":"depth","name":"video/VP8","preferredPayloadType":120,"clockRate":90000},{"kind":"audio","name":"audio/CN","preferredPayloadType":77,"clockRate":32000},{"kind":"audio","name":"audio/CN","preferredPayloadType":78,"clockRate":16000},{"kind":"audio","name":"audio/CN","preferredPayloadType":13,"clockRate":8000},{"kind":"audio","name":"audio/telephone-event","preferredPayloadType":79,"clockRate":8000}]})";
Json::Value json;
std::string json_parse_error;
......@@ -66,18 +66,12 @@ namespace RTC
static const Json::StaticString k_mediaCodecs("mediaCodecs");
// Initialize room RTP capabilities with all the supported ones.
this->rtpCapabilities = Room::supportedRtpCapabilities;
// `mediaCodecs` is mandatory.
if (!data[k_mediaCodecs].isArray())
MS_THROW_ERROR("missing mediaCodecs");
auto& json_mediaCodecs = data[k_mediaCodecs];
if (json_mediaCodecs.size() == 0)
MS_THROW_ERROR("empty mediaCodecs");
std::vector<RtpRoomMediaCodec> mediaCodecs;
for (Json::UInt i = 0; i < json_mediaCodecs.size(); i++)
......@@ -85,9 +79,11 @@ namespace RTC
RTC::RtpRoomMediaCodec mediaCodec(json_mediaCodecs[i]);
mediaCodecs.push_back(mediaCodec);
// TODO: MORE
}
// Set room RTP capabilities.
// NOTE: This may throw.
SetRtpCapabilities(mediaCodecs);
}
Room::~Room()
......@@ -360,6 +356,48 @@ namespace RTC
}
}
void Room::SetRtpCapabilities(std::vector<RTC::RtpRoomMediaCodec>& roomMediaCodecs)
{
MS_TRACE();
for (auto& roomMediaCodec : roomMediaCodecs)
{
auto rtpCodecCapability = GetRtpCodecCapability(roomMediaCodec);
}
}
RTC::RtpCodecCapability Room::GetRtpCodecCapability(RTC::RtpRoomMediaCodec& roomMediaCodec)
{
MS_TRACE();
RTC::RtpCodecCapability codecCapability;
// Search the given codec in the list of supported codecs.
auto it = Room::supportedRtpCapabilities.codecs.begin();
for (; it != Room::supportedRtpCapabilities.codecs.end(); ++it)
{
auto& supportedCodecapability = *it;
if (
// Kind must match.
(roomMediaCodec.kind == supportedCodecapability.kind) &&
// MIME must match.
(roomMediaCodec.mime == supportedCodecapability.mime) &&
// Clock rate must match.
(roomMediaCodec.clockRate == supportedCodecapability.clockRate)
)
{
codecCapability = supportedCodecapability;
}
}
if (it == Room::supportedRtpCapabilities.codecs.end())
MS_THROW_ERROR("no matching codec found");
return codecCapability;
}
void Room::onPeerClosed(RTC::Peer* peer)
{
MS_TRACE();
......
......@@ -13,14 +13,16 @@ namespace RTC
{
{ "audio", Media::Kind::AUDIO },
{ "video", Media::Kind::VIDEO },
{ "depth", Media::Kind::DEPTH }
{ "depth", Media::Kind::DEPTH },
{ "", Media::Kind::ALL }
};
std::map<Media::Kind, Json::StaticString> Media::kind2Json =
{
{ Media::Kind::AUDIO, Json::StaticString("audio") },
{ Media::Kind::VIDEO, Json::StaticString("video") },
{ Media::Kind::DEPTH, Json::StaticString("depth") }
{ Media::Kind::DEPTH, Json::StaticString("depth") },
{ Media::Kind::ALL, Json::StaticString("") }
};
/* Class methods. */
......
......@@ -53,9 +53,11 @@ namespace RTC
this->preferredPayloadType = (uint8_t)data[k_preferredPayloadType].asUInt();
// `clockRate` is optional.
if (data[k_clockRate].isUInt())
this->clockRate = (uint32_t)data[k_clockRate].asUInt();
// `clockRate` is mandatory.
if (!data[k_clockRate].isUInt())
MS_THROW_ERROR("missing RtpCodecParameters.clockRate");
this->clockRate = (uint32_t)data[k_clockRate].asUInt();
// `maxptime` is optional.
if (data[k_maxptime].isUInt())
......@@ -129,8 +131,7 @@ namespace RTC
json[k_preferredPayloadType] = (Json::UInt)this->preferredPayloadType;
// Add `clockRate`.
if (this->clockRate)
json[k_clockRate] = (Json::UInt)this->clockRate;
json[k_clockRate] = (Json::UInt)this->clockRate;
// Add `maxptime`.
if (this->maxptime)
......
......@@ -41,9 +41,11 @@ namespace RTC
this->payloadType = (uint8_t)data[k_payloadType].asUInt();
// `clockRate` is optional.
if (data[k_clockRate].isUInt())
this->clockRate = (uint32_t)data[k_clockRate].asUInt();
// `clockRate` is mandatory.
if (!data[k_clockRate].isUInt())
MS_THROW_ERROR("missing RtpCodecParameters.clockRate");
this->clockRate = (uint32_t)data[k_clockRate].asUInt();
// `maxptime` is optional.
if (data[k_maxptime].isUInt())
......@@ -106,8 +108,7 @@ namespace RTC
json[k_payloadType] = (Json::UInt)this->payloadType;
// Add `clockRate`.
if (this->clockRate)
json[k_clockRate] = (Json::UInt)this->clockRate;
json[k_clockRate] = (Json::UInt)this->clockRate;
// Add `maxptime`.
if (this->maxptime)
......
......@@ -39,12 +39,20 @@ namespace RTC
// NOTE: This may throw.
this->mime.SetName(name);
// `clockRate` is optional.
if (data[k_clockRate].isUInt())
this->clockRate = (uint32_t)data[k_clockRate].asUInt();
// `clockRate` is mandatory.
if (!data[k_clockRate].isUInt())
MS_THROW_ERROR("missing RtpCodecParameters.clockRate");
this->clockRate = (uint32_t)data[k_clockRate].asUInt();
// `parameters` is optional.
if (data[k_parameters].isObject())
RTC::FillCustomParameters(this->parameters, data[k_parameters]);
// Validate codec.
// It must not be a feature codec.
if (this->mime.IsFeatureCodec())
MS_THROW_ERROR("RtpRoomMediaCodec can not be a feature coedc");
}
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论