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

Code cleanup and improve internal doc.

上级 3223f806
......@@ -7,7 +7,7 @@ This documentation details how *mediasoup* rooms are created, how peers are adde
A `Room` is created by calling `server.createRoom(roomOptions)` where `roomOptions` is a mandatory object that must include a `mediaCodecs` array of media codecs supported by the room.
Each media codec must define mandatory attributes:
Each media codec must define some mandatory fields:
* `kind`: "audio"/"video"/"depth" or empty string which means all the kinds
* `name`: "audio/opus", etc
......@@ -40,3 +40,63 @@ Complementary codecs are also considered media codecs. These are:
Feature codecs ("video/rtx", "video/ulpfec", "video/flexfec" and "video/red") are **NOT** media codecs and hence MUST NOT be placed into `roomOptions.mediaCodecs` (they will be ignored if present).
Valid media codecs are inserted into a `RtpCapabilities` object. Once done, supported RTP header extensions and supported FEC mechanisms (loaded from [lib/supportedRtpCapabilities.js](../lib/supportedRtpCapabilities.js)) are also included into the `RtpCapabilities` object.
*TODO:* I'm evaluating whether mediasoup supported RTP capabilities should incudle the full list of supported codecs (including their supported RTCP feedbacks). I think I'll go that way around.
And the room is done.
## Creating a Peer
A `Peer` is created by calling `room.Peer(name)`.
Once created, peer's capabilities must be set (otherwise no `RtpReceiver` can be created) by calling `peer.setCapabilities(capabilities)`. Those capabilities include codecs, RTP header extensions and FEC mechanisms.
These codecs have the same fields as the room codecs, with some variations:
* `payloadType` is mandatory.
* `rtcpFeedback` is optional.
After that, C++ `Room::onPeerCapabilities(capabilities)` is called. This method removes peer's codecs not supported by the room and RTP header extensions and FEC mechanisms not supported by mediasoup.
*TODO:* We must remove RTP header extensions and FEC mechanisms not supported by mediasoup (and currently we support none of them).
## Creating a RtpReceiver
A `RtpReceiver` is created by calling `peer.RtpReceiver(kind, transport)` where `kind` can be "audio", "video" or "depth", and `transport` must be a `Transport` instance previously created by the peer.
Once created, `rtpReceiver.receive(parameters)` must be called (otherwise the `RtpReceiver` is ignored by the room. `parameters` is a `RtpParameters` object which the following fields:
* `muxId` is optional.
* `codecs` is mandatory.
* `encodings` is optional.
* `rtcp` is optional.
* `userParameters` is an optional object.
These codecs have the same fields as the peer's capabilities codecs above, with some variations:
* `kind` is ignored.
After that, C++ `RtpReceiver::FillRtpParameters()` is called. This method does nothing right now.
*TODO:* C++ `RtpReceiver::FillRtpParameters()` should:
* Set a random `muxId` and map the original value.
* If any SSRC value is not given, set a random one and be ready to match the unknown incoming SSRC value to it.
* If not given, set the `rtcp` field.
* Should filter unsupported RTP header extensions and map the `id` of the supported ones to a static value.
- *NOTE:* This is important so we can deal with PlanB in which all the RTP streams are sent over a single `m=` section.
*TODO:* The whole mapping system could be implemented by maintaing two `RtpParameters` objects within each `RtpReceiver`: the original one and the mmaped one (although that wouldn't be efficient when it comes to mangle each RTP packet so it may be better to handle an internal value mapping...).
After that, C++ `Peer::onRtpReceiverParametersDone()` is called, which just calls to C++ `Room::onPeerRtpReceiverParameters()`.
`Room::onPeerRtpReceiverParameters()` creates `RtpSenders` associated to this `RtpReceiver` (for every other `Peer` with its capabilities already set) by calling `Peer::AddRtpSender()` on them.
`Peer::AddRtpSender()` takes the associated `RtpParameters` of the `RtpReceiver` as parameter and call `RtpSender::Send(parameters)`.
`RtpSender::Send(parameters)` clones the given parameters and removes non supported codecs and non supported RTP header extensions.
*TODO:* This must be analyzed.
'use strict';
/**
* This file is not used by the JavaScript engine, but copied into the C++
* source code once JSONized by gulp.
*/
let supportedCapabilities =
let supportedRtpCapabilities =
{
headerExtensions :
[
......@@ -19,4 +14,4 @@ let supportedCapabilities =
fecMechanisms : []
};
module.exports = supportedCapabilities;
module.exports = supportedRtpCapabilities;
......@@ -33,7 +33,7 @@
"gulp-eslint": "^3.0.1",
"gulp-replace": "^0.5.4",
"gulp-shell": "^0.5.2",
"gulp-touch": "^1.0.1",
"gulp-touch-cmd": "0.0.1",
"tap": "^9.0.1"
},
"scripts": {
......
......@@ -30,7 +30,7 @@ namespace RTC
static void ClassInit();
private:
static RTC::RtpCapabilities supportedCapabilities;
static RTC::RtpCapabilities supportedRtpCapabilities;
static std::vector<uint8_t> availablePayloadTypes;
public:
......
......@@ -14,7 +14,7 @@ namespace RTC
{
/* Class variables. */
RTC::RtpCapabilities Room::supportedCapabilities;
RTC::RtpCapabilities Room::supportedRtpCapabilities;
/* Class methods. */
......@@ -31,13 +31,13 @@ namespace RTC
Json::CharReader* jsonReader = builder.newCharReader();
// NOTE: This line is auto-generated from data/supportedCapabilities.js.
const std::string capabilities = R"({"headerExtensions":[{"kind":"","uri":"urn:ietf:params:rtp-hdrext:sdes:mid","preferredId":1,"preferredEncrypt":false}],"fecMechanisms":[]})";
// NOTE: These lines are auto-generated from data/supportedCapabilities.js.
const std::string supportedRtpCapabilities = R"({"headerExtensions":[{"kind":"","uri":"urn:ietf:params:rtp-hdrext:sdes:mid","preferredId":1,"preferredEncrypt":false}],"fecMechanisms":[]})";
Json::Value json;
std::string json_parse_error;
if (!jsonReader->parse(capabilities.c_str(), capabilities.c_str() + capabilities.length(), &json, &json_parse_error))
if (!jsonReader->parse(supportedRtpCapabilities.c_str(), supportedRtpCapabilities.c_str() + supportedRtpCapabilities.length(), &json, &json_parse_error))
{
delete jsonReader;
......@@ -48,7 +48,7 @@ namespace RTC
try
{
Room::supportedCapabilities = RTC::RtpCapabilities(json, RTC::Scope::ROOM_CAPABILITY);
Room::supportedRtpCapabilities = RTC::RtpCapabilities(json, RTC::Scope::ROOM_CAPABILITY);
}
catch (const MediaSoupError &error)
{
......@@ -421,10 +421,10 @@ namespace RTC
}
// Add supported RTP header extensions.
this->capabilities.headerExtensions = Room::supportedCapabilities.headerExtensions;
this->capabilities.headerExtensions = Room::supportedRtpCapabilities.headerExtensions;
// Add supported FEC mechanisms.
this->capabilities.fecMechanisms = Room::supportedCapabilities.fecMechanisms;
this->capabilities.fecMechanisms = Room::supportedRtpCapabilities.fecMechanisms;
}
void Room::onPeerClosed(RTC::Peer* peer)
......@@ -509,11 +509,11 @@ namespace RTC
{
RTC::Peer* sender_peer = kv.second;
// Skip receiver peer.
// Skip receiver Peer.
if (sender_peer == peer)
continue;
// Skip peer with capabilities unset yet.
// Skip Peer with capabilities not set yet.
if (!sender_peer->HasCapabilities())
continue;
......
......@@ -287,6 +287,8 @@ namespace RTC
MS_TRACE();
// Set a random muxId.
// TODO: This is wrong, we are replacing the given muxId. Instead, this
// method should set a random muxId and map the original value.
this->rtpParameters->muxId = Utils::Crypto::GetRandomString(8);
// TODO: Fill SSRCs with random values and set some mechanism to replace
......
......@@ -132,11 +132,11 @@ namespace RTC
// Clone given RTP parameters so we manage our own sender parameters.
this->rtpParameters = new RTC::RtpParameters(rtpParameters);
// Remove RTP parameters not supported by this pper.
// Remove RTP parameters not supported by this Peer.
// Remove unsupported codecs.
std::unordered_set<uint8_t> supportedPayloadTypes;
// Remove unsupported codecs.
for (auto it = this->rtpParameters->codecs.begin(); it != this->rtpParameters->codecs.end();)
{
auto& codec = *it;
......@@ -181,16 +181,13 @@ namespace RTC
// Build the payload types map.
SetPayloadTypesMapping();
// TODO: Must check with PTs and encodings are supported so RTP packets
// handling is easy.
// If there are no encodings set not available.
if (this->rtpParameters->encodings.size() > 0)
this->available = true;
else
this->available = false;
// Emit "parameterschange" if those are new parameters.
// Emit "parameterschange" if these are updated parameters.
if (previousRtpParameters)
{
Json::Value event_data(Json::objectValue);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论