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

Lot of work in room capabilities.

上级 4b8aaead
...@@ -64,7 +64,11 @@ let supportedRtpCapabilities = ...@@ -64,7 +64,11 @@ let supportedRtpCapabilities =
kind : 'video', kind : 'video',
name : 'video/H264', name : 'video/H264',
preferredPayloadType : 112, preferredPayloadType : 112,
clockRate : 90000 clockRate : 90000,
parameters :
{
packetizationMode : [ 0, 1, 2 ]
}
}, },
// Depth codecs: // Depth codecs:
{ {
......
...@@ -258,22 +258,26 @@ class Room extends EventEmitter ...@@ -258,22 +258,26 @@ class Room extends EventEmitter
} }
} }
for (let headerExtension of capabilities.headerExtensions) // Ignore if there are no media codecs of this kind.
if (kindCapabilities.codecs.length > 0)
{ {
if (headerExtension.kind === kind) for (let headerExtension of capabilities.headerExtensions)
{ {
kindCapabilities.headerExtensions.push(headerExtension); if (headerExtension.kind === kind)
{
kindCapabilities.headerExtensions.push(headerExtension);
}
else if (headerExtension.kind === '')
{
let clonedHeaderExtension = utils.cloneObject(headerExtension);
clonedHeaderExtension.kind = kind;
kindCapabilities.headerExtensions.push(clonedHeaderExtension);
}
} }
else if (headerExtension.kind === '')
{
let clonedHeaderExtension = utils.cloneObject(headerExtension);
clonedHeaderExtension.kind = kind; kindCapabilities.fecMechanisms = capabilities.fecMechanisms;
kindCapabilities.headerExtensions.push(clonedHeaderExtension);
}
} }
kindCapabilities.fecMechanisms = capabilities.fecMechanisms;
} }
} }
} }
......
...@@ -7,15 +7,30 @@ module.exports = ...@@ -7,15 +7,30 @@ module.exports =
mediaCodecs : mediaCodecs :
[ [
{ {
kind : 'audio', kind : 'audio',
name : 'audio/opus', name : 'audio/opus',
clockRate : 48000 clockRate : 48000,
numChannels : 2
},
{
kind : 'audio',
name : 'audio/PCMU',
clockRate : 8000
}, },
{ {
kind : 'video', kind : 'video',
name : 'video/vp8', name : 'video/vp8',
clockRate : 90000 clockRate : 90000
}, },
{
kind : 'video',
name : 'video/h264',
clockRate : 90000,
parameters :
{
packetizationMode : 1
}
},
{ {
kind : 'depth', kind : 'depth',
name : 'video/vp8', name : 'video/vp8',
......
...@@ -139,6 +139,11 @@ tap.test('room.getCapabilities() must retrieve current room capabilities', { tim ...@@ -139,6 +139,11 @@ tap.test('room.getCapabilities() must retrieve current room capabilities', { tim
server.createRoom(roomOptions) server.createRoom(roomOptions)
.then((room) => .then((room) =>
{ {
// TODO: REMOVE
// console.log(JSON.stringify(room.getCapabilities('audio'), null, '\t'));
// console.log(JSON.stringify(room.getCapabilities('video'), null, '\t'));
// console.log(JSON.stringify(room.getCapabilities('depth'), null, '\t'));
t.ok(room.getCapabilities('audio'), 'room.getCapabilities("audio") returns an object'); t.ok(room.getCapabilities('audio'), 'room.getCapabilities("audio") returns an object');
t.ok(room.getCapabilities('video'), 'room.getCapabilities("video") returns an object'); t.ok(room.getCapabilities('video'), 'room.getCapabilities("video") returns an object');
t.ok(room.getCapabilities('depth'), 'room.getCapabilities("depth") returns an object'); t.ok(room.getCapabilities('depth'), 'room.getCapabilities("depth") returns an object');
......
...@@ -31,6 +31,7 @@ namespace RTC ...@@ -31,6 +31,7 @@ namespace RTC
private: private:
static RTC::RtpCapabilities supportedRtpCapabilities; static RTC::RtpCapabilities supportedRtpCapabilities;
static std::vector<uint8_t> availablePayloadTypes;
public: public:
Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data); Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data);
...@@ -44,7 +45,6 @@ namespace RTC ...@@ -44,7 +45,6 @@ namespace RTC
private: private:
RTC::Peer* GetPeerFromRequest(Channel::Request* request, uint32_t* peerId = nullptr); RTC::Peer* GetPeerFromRequest(Channel::Request* request, uint32_t* peerId = nullptr);
void SetRtpCapabilities(std::vector<RTC::RtpRoomMediaCodec>& roomMediaCodecs); void SetRtpCapabilities(std::vector<RTC::RtpRoomMediaCodec>& roomMediaCodecs);
RTC::RtpCodecCapability GetRtpCodecCapability(RTC::RtpRoomMediaCodec& roomMediaCodec);
/* Pure virtual methods inherited from RTC::Peer::Listener. */ /* Pure virtual methods inherited from RTC::Peer::Listener. */
public: public:
......
...@@ -115,12 +115,12 @@ namespace RTC ...@@ -115,12 +115,12 @@ namespace RTC
RtpCodec(Json::Value& data); RtpCodec(Json::Value& data);
public: public:
RtpCodecMime mime; RtpCodecMime mime;
uint32_t clockRate = 0; uint32_t clockRate = 0;
uint32_t maxptime = 0; uint32_t maxptime = 0;
uint32_t ptime = 0; uint32_t ptime = 0;
uint32_t numChannels = 0; uint32_t numChannels = 1;
RTC::CustomParameters parameters; RTC::CustomParameters parameters;
}; };
class RTCRtpCodecRtxParameters class RTCRtpCodecRtxParameters
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "Utils.h" #include "Utils.h"
#include <string> #include <string>
#include <vector> #include <vector>
#include <set>
namespace RTC namespace RTC
{ {
...@@ -30,7 +31,7 @@ namespace RTC ...@@ -30,7 +31,7 @@ namespace RTC
Json::CharReader* jsonReader = builder.newCharReader(); Json::CharReader* jsonReader = builder.newCharReader();
// NOTE: This line is auto-generated frmo data/supportedRtpCapabilities.js. // 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":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}],"headerExtensions":[{"kind":"","uri":"urn:ietf:params:rtp-hdrext:sdes:mid","preferredId":1,"preferredEncrypt":false}]})"; 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,"parameters":{"packetizationMode":[0,1,2]}},{"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}],"headerExtensions":[{"kind":"","uri":"urn:ietf:params:rtp-hdrext:sdes:mid","preferredId":1,"preferredEncrypt":false}]})";
Json::Value json; Json::Value json;
std::string json_parse_error; std::string json_parse_error;
...@@ -39,7 +40,7 @@ namespace RTC ...@@ -39,7 +40,7 @@ namespace RTC
{ {
delete jsonReader; delete jsonReader;
MS_THROW_ERROR_STD("JSON parsing error in default RTP capabilities: %s", json_parse_error.c_str()); MS_THROW_ERROR_STD("JSON parsing error in supported RTP capabilities: %s", json_parse_error.c_str());
} }
delete jsonReader; delete jsonReader;
...@@ -50,7 +51,7 @@ namespace RTC ...@@ -50,7 +51,7 @@ namespace RTC
} }
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
{ {
MS_THROW_ERROR_STD("wrong default RTP capabilities: %s", error.what()); MS_THROW_ERROR_STD("wrong supported RTP capabilities: %s", error.what());
} }
} }
} }
...@@ -353,61 +354,138 @@ namespace RTC ...@@ -353,61 +354,138 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// Check codecs. // Set codecs.
for (auto& roomMediaCodec : roomMediaCodecs)
{ {
auto rtpCodecCapability = GetRtpCodecCapability(roomMediaCodec); // Available dynamic payload types.
static const std::vector<const uint8_t> dynamicPayloadTypes
{
100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127,
96, 97, 98, 99,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71
};
// Maximum static payload type.
static const uint8_t maxStaticPayloadType = 34;
// Iterator for available dynamic payload types.
auto dynamicPayloadTypeIt = dynamicPayloadTypes.begin();
// Payload types used by the room.
std::set<uint8_t> roomPayloadTypes;
// Given media kinds.
std::set<RTC::Media::Kind> roomKinds;
// Set the given room codecs.
for (auto& roomMediaCodec : roomMediaCodecs)
{
RTC::RtpCodecCapability codecCapability;
// Append the codec to the room capabilities. // The room has this kind.
this->rtpCapabilities.codecs.push_back(rtpCodecCapability); roomKinds.insert(roomMediaCodec.kind);
}
// TODO: Add feature codecs. // Search the given codec in the list of supported codec capabilities.
// Copy supported RTP header extensions. auto it = Room::supportedRtpCapabilities.codecs.begin();
this->rtpCapabilities.headerExtensions = Room::supportedRtpCapabilities.headerExtensions;
// Copy supported FEC mechanisms. for (; it != Room::supportedRtpCapabilities.codecs.end(); ++it)
this->rtpCapabilities.fecMechanisms = Room::supportedRtpCapabilities.fecMechanisms; {
} auto& supportedCodecCapability = *it;
RTC::RtpCodecCapability Room::GetRtpCodecCapability(RTC::RtpRoomMediaCodec& roomMediaCodec) // Kind must match.
{ if (roomMediaCodec.kind != supportedCodecCapability.kind)
MS_TRACE(); continue;
RTC::RtpCodecCapability codecCapability; // Check whether the codec capability matches the given codec.
if (supportedCodecCapability.MatchesCodec(roomMediaCodec))
{
// Deep copy.
codecCapability = supportedCodecCapability;
// Search the given codec in the list of supported codecs. break;
}
}
if (it == Room::supportedRtpCapabilities.codecs.end())
MS_THROW_ERROR("no matching codec capability found");
auto it = Room::supportedRtpCapabilities.codecs.begin(); // TODO: Reduce the capabilities of the found (and copied) codec (for
// example set the H264 packetizationMode parameter to a single value).
// NOTE: Maybe a RtpCodecCapability.Reduce(codec) method.
for (; it != Room::supportedRtpCapabilities.codecs.end(); ++it) // Set unique PT.
{
auto& supportedCodecCapability = *it;
// Kind must match. auto payloadType = codecCapability.preferredPayloadType;
if (roomMediaCodec.kind != supportedCodecCapability.kind)
continue; // If the codec capability has static PT and such a PT is not already used,
// let it untouched.
if (payloadType > maxStaticPayloadType ||
roomPayloadTypes.find(payloadType) != roomPayloadTypes.end())
{
// If there are no more dynamic PTs throw.
if (dynamicPayloadTypeIt == dynamicPayloadTypes.end())
MS_THROW_ERROR("not enough available dynamic payload types for given media codecs");
// Assign preferred PT.
payloadType = *dynamicPayloadTypeIt;
codecCapability.preferredPayloadType = payloadType;
// Increment the iterator.
dynamicPayloadTypeIt++;
}
// Check whether the codec capability matches the given codec. // Store the selected PT.
if (supportedCodecCapability.MatchesCodec(roomMediaCodec)) roomPayloadTypes.insert(payloadType);
// Append the codec to the room capabilities.
this->rtpCapabilities.codecs.push_back(codecCapability);
}
// Add feature codec capabilities.
for (auto& codecCapability : Room::supportedRtpCapabilities.codecs)
{ {
codecCapability = supportedCodecCapability; // Just feature codecs.
if (!codecCapability.mime.IsFeatureCodec())
continue;
break; // Ignore if no media codecs of this kind were given.
if (roomKinds.find(codecCapability.kind) == roomKinds.end())
continue;
// Set unique PT.
auto payloadType = codecCapability.preferredPayloadType;
if (payloadType > maxStaticPayloadType ||
roomPayloadTypes.find(payloadType) != roomPayloadTypes.end())
{
// If there are no more dynamic PTs throw.
if (dynamicPayloadTypeIt == dynamicPayloadTypes.end())
MS_THROW_ERROR("not enough available dynamic payload types for feature codecs");
// Assign preferred PT.
payloadType = *dynamicPayloadTypeIt;
codecCapability.preferredPayloadType = payloadType;
// Increment the iterator.
dynamicPayloadTypeIt++;
}
// Store the selected PT.
roomPayloadTypes.insert(payloadType);
// Append the codec to the room capabilities.
this->rtpCapabilities.codecs.push_back(codecCapability);
} }
} }
if (it == Room::supportedRtpCapabilities.codecs.end())
MS_THROW_ERROR("no matching codec capability found");
// TODO: Reduce the capabilities of the found (and copied) codec (for // Copy supported RTP header extensions.
// example set the H264 packetizationMode parameter to a single value). this->rtpCapabilities.headerExtensions = Room::supportedRtpCapabilities.headerExtensions;
// NOTE: Maybe a RtpCodecCapability.Reduce(codec) method.
// Set proper payloadType (it may not be the preferred one in some cases).
return codecCapability; // Copy supported FEC mechanisms.
this->rtpCapabilities.fecMechanisms = Room::supportedRtpCapabilities.fecMechanisms;
} }
void Room::onPeerClosed(RTC::Peer* peer) void Room::onPeerClosed(RTC::Peer* peer)
......
...@@ -106,7 +106,7 @@ namespace RTC ...@@ -106,7 +106,7 @@ namespace RTC
json[k_ptime] = (Json::UInt)this->ptime; json[k_ptime] = (Json::UInt)this->ptime;
// Add `numChannels`. // Add `numChannels`.
if (this->numChannels) if (this->numChannels > 1)
json[k_numChannels] = (Json::UInt)this->numChannels; json[k_numChannels] = (Json::UInt)this->numChannels;
// Add `rtcpFeedback`. // Add `rtcpFeedback`.
...@@ -150,14 +150,37 @@ namespace RTC ...@@ -150,14 +150,37 @@ namespace RTC
MS_TRACE(); MS_TRACE();
// MIME must match. // MIME must match.
if (codec.mime != this->mime) if (this->mime != codec.mime)
return false; return false;
// Clock rate must match. // Clock rate must match.
if (codec.clockRate != this->clockRate) if (this->clockRate != codec.clockRate)
return false; return false;
// TODO: Match per codec parameters, ptime, numChannels, etc. // Per kind checks.
switch (this->kind)
{
case RTC::Media::Kind::AUDIO:
{
// Num channels must match
if (this->numChannels != codec.numChannels)
return false;
break;
}
case RTC::Media::Kind::VIDEO:
{
// TODO: check SVC stuff.
break;
}
default:
;
}
// TODO: Match per codec parameters, etc.
return true; return true;
} }
......
...@@ -80,7 +80,7 @@ namespace RTC ...@@ -80,7 +80,7 @@ namespace RTC
json[k_ptime] = (Json::UInt)this->ptime; json[k_ptime] = (Json::UInt)this->ptime;
// Add `numChannels`. // Add `numChannels`.
if (this->numChannels) if (this->numChannels > 1)
json[k_numChannels] = (Json::UInt)this->numChannels; json[k_numChannels] = (Json::UInt)this->numChannels;
// Add `rtx` // Add `rtx`
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论