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

more

上级 5f1372af
# TODO in mediasoup v2 (server-side) # TODO in mediasoup v2 (server-side)
* `transport.iceLocalParameters` must include `iceLite: true`. * If the transport of a consumer is closed, and the consumer was "enabled", it should become "disabled" and emit event? I think yes. Enabled should mean "it has a transport". Period.
* `transport.dtlsLocalParameters` must have an array of `fingerprints` as in ORTC (rather than the current `Object`). Also, `transportsetRemoteDtlsParameters()` should accept the same format. * `transport.setRemoteDtlsParameters()` should accept an array of `fingerprints` as in ORTC (rather than the current cusot object).
* Should accept `peer.createTransport()` by passing a `transportId` number. The same for `Producer`. * Should accept `peer.createTransport()` by passing a `transportId` number. The same for `Producer`.
......
...@@ -169,12 +169,6 @@ class Peer extends EventEmitter ...@@ -169,12 +169,6 @@ class Peer extends EventEmitter
// Remove notification subscriptions. // Remove notification subscriptions.
this._channel.removeAllListeners(this._internal.peerId); this._channel.removeAllListeners(this._internal.peerId);
// Close every Transport.
for (const transport of this._transports)
{
transport.close(undefined, true);
}
// Close every Producer. // Close every Producer.
for (const producer of this._producers) for (const producer of this._producers)
{ {
...@@ -187,6 +181,12 @@ class Peer extends EventEmitter ...@@ -187,6 +181,12 @@ class Peer extends EventEmitter
consumer.close(); consumer.close();
} }
// Close every Transport.
for (const transport of this._transports)
{
transport.close(undefined, true);
}
if (!dontSendChannel) if (!dontSendChannel)
{ {
// Send Channel request. // Send Channel request.
...@@ -259,25 +259,17 @@ class Peer extends EventEmitter ...@@ -259,25 +259,17 @@ class Peer extends EventEmitter
if (this._closed) if (this._closed)
throw new errors.InvalidStateError('Peer closed'); throw new errors.InvalidStateError('Peer closed');
else if (!this.rtpCapabilities)
// Ensure `kind` is 'audio' / 'video' / 'depth'. throw new errors.InvalidStateError('RTP capabilities not set');
if (KINDS.indexOf(kind) === -1) else if (KINDS.indexOf(kind) === -1)
throw new TypeError(`unsupported kind: ${kind}`); throw new TypeError(`unsupported kind: ${kind}`);
else if (!transport)
// Ensure `transport` is given.
if (!transport)
throw new TypeError('transport not given'); throw new TypeError('transport not given');
else if (!(transport instanceof Transport))
// Ensure `transport` is a Transport.
if (!(transport instanceof Transport))
throw new TypeError('transport must be a instance of Transport'); throw new TypeError('transport must be a instance of Transport');
else if (transport.closed)
// Ensure `transport` is not closed.
if (transport.closed)
throw new errors.InvalidStateError('transport is closed'); throw new errors.InvalidStateError('transport is closed');
else if (!this._transports.has(transport))
// Ensure `transport` belongs to this Peer.
if (!this._transports.has(transport))
throw new Error('transport not found'); throw new Error('transport not found');
const internal = const internal =
...@@ -455,23 +447,12 @@ class Peer extends EventEmitter ...@@ -455,23 +447,12 @@ class Peer extends EventEmitter
}) })
.then(() => .then(() =>
{ {
// TODO: This must be properly done in the worker.
transport.iceLocalParameters.iceLite = true;
transport.dtlsLocalParameters.fingerprints =
Object.keys(transport.dtlsLocalParameters.fingerprints)
.map((hash) =>
{
return {
algorithm : hash,
value : transport.dtlsLocalParameters.fingerprints[hash]
};
});
// If client's DTLS parameters are given, provide the Transport with // If client's DTLS parameters are given, provide the Transport with
// them. // them.
if (remoteDtlsParameters) if (remoteDtlsParameters)
{ {
// TODO: The Transport should accept the client's given format. // TODO: The Transport should accept the client's given format.
// Or may be we should choose here if many are given.
remoteDtlsParameters.fingerprint = remoteDtlsParameters.fingerprint =
remoteDtlsParameters.fingerprints[0]; remoteDtlsParameters.fingerprints[0];
......
...@@ -26,6 +26,7 @@ class Transport extends EventEmitter ...@@ -26,6 +26,7 @@ class Transport extends EventEmitter
// - .iceLocalParameters // - .iceLocalParameters
// - .usernameFragment // - .usernameFragment
// - .password // - .password
// - .iceLite
// - .iceLocalCandidates [] // - .iceLocalCandidates []
// - .foundation // - .foundation
// - .priority // - .priority
...@@ -310,7 +311,8 @@ class Transport extends EventEmitter ...@@ -310,7 +311,8 @@ class Transport extends EventEmitter
this._data.iceLocalParameters = this._data.iceLocalParameters =
{ {
usernameFragment : data.usernameFragment, usernameFragment : data.usernameFragment,
password : data.password password : data.password,
iceLite : this._data.iceLocalParameters.iceLite
}; };
return this; return this;
......
...@@ -41,13 +41,12 @@ namespace RTC ...@@ -41,13 +41,12 @@ namespace RTC
void Destroy(); void Destroy();
Json::Value ToJson() const; Json::Value ToJson() const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
void SetPeerCapabilities(RTC::RtpCapabilities* peerCapabilities);
void Send(RTC::RtpParameters* rtpParameters); void Send(RTC::RtpParameters* rtpParameters);
void SetTransport(RTC::Transport* transport); void SetTransport(RTC::Transport* transport);
RTC::Transport* GetTransport() const; RTC::Transport* GetTransport() const;
void RemoveTransport(RTC::Transport* transport); void RemoveTransport(RTC::Transport* transport);
RTC::RtpParameters* GetParameters() const; RTC::RtpParameters* GetParameters() const;
bool GetActive() const; bool GetEnabled() const;
void SendRtpPacket(RTC::RtpPacket* packet); void SendRtpPacket(RTC::RtpPacket* packet);
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now); void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket); void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket);
...@@ -57,7 +56,7 @@ namespace RTC ...@@ -57,7 +56,7 @@ namespace RTC
private: private:
void CreateRtpStream(RTC::RtpEncodingParameters& encoding); void CreateRtpStream(RTC::RtpEncodingParameters& encoding);
void RetransmitRtpPacket(RTC::RtpPacket* packet); void RetransmitRtpPacket(RTC::RtpPacket* packet);
void EmitActiveChange() const; void EmitEnabledChange() const;
public: public:
// Passed by argument. // Passed by argument.
...@@ -69,16 +68,11 @@ namespace RTC ...@@ -69,16 +68,11 @@ namespace RTC
Listener* listener{ nullptr }; Listener* listener{ nullptr };
Channel::Notifier* notifier{ nullptr }; Channel::Notifier* notifier{ nullptr };
RTC::Transport* transport{ nullptr }; RTC::Transport* transport{ nullptr };
RTC::RtpCapabilities* peerCapabilities{ nullptr };
// Allocated by this. // Allocated by this.
RTC::RtpParameters* rtpParameters{ nullptr }; RTC::RtpParameters* rtpParameters{ nullptr };
RTC::RtpStreamSend* rtpStream{ nullptr }; RTC::RtpStreamSend* rtpStream{ nullptr };
// Others. // Others.
std::unordered_set<uint8_t> supportedPayloadTypes; std::unordered_set<uint8_t> supportedPayloadTypes;
// Whether this Consumer is valid according to Peer capabilities.
bool available{ false };
// Whether this Consumer has been disabled by the app.
bool disabled{ false };
// Timestamp when last RTCP was sent. // Timestamp when last RTCP was sent.
uint64_t lastRtcpSentTime{ 0 }; uint64_t lastRtcpSentTime{ 0 };
uint16_t maxRtcpInterval{ 0 }; uint16_t maxRtcpInterval{ 0 };
...@@ -91,12 +85,12 @@ namespace RTC ...@@ -91,12 +85,12 @@ namespace RTC
inline void Consumer::SetTransport(RTC::Transport* transport) inline void Consumer::SetTransport(RTC::Transport* transport)
{ {
bool wasActive = this->GetActive(); bool wasEnabled = this->GetEnabled();
this->transport = transport; this->transport = transport;
if (wasActive != this->GetActive()) if (wasEnabled != this->GetEnabled())
EmitActiveChange(); EmitEnabledChange();
} }
inline RTC::Transport* Consumer::GetTransport() const inline RTC::Transport* Consumer::GetTransport() const
...@@ -106,13 +100,13 @@ namespace RTC ...@@ -106,13 +100,13 @@ namespace RTC
inline void Consumer::RemoveTransport(RTC::Transport* transport) inline void Consumer::RemoveTransport(RTC::Transport* transport)
{ {
bool wasActive = this->GetActive(); bool wasEnabled = this->GetEnabled();
if (this->transport == transport) if (this->transport == transport)
this->transport = nullptr; this->transport = nullptr;
if (wasActive != this->GetActive()) if (wasEnabled != this->GetEnabled())
EmitActiveChange(); EmitEnabledChange();
} }
inline RTC::RtpParameters* Consumer::GetParameters() const inline RTC::RtpParameters* Consumer::GetParameters() const
...@@ -120,9 +114,9 @@ namespace RTC ...@@ -120,9 +114,9 @@ namespace RTC
return this->rtpParameters; return this->rtpParameters;
} }
inline bool Consumer::GetActive() const inline bool Consumer::GetEnabled() const
{ {
return (this->available && this->transport && !this->disabled); return this->transport;
} }
inline uint32_t Consumer::GetTransmissionRate(uint64_t now) inline uint32_t Consumer::GetTransmissionRate(uint64_t now)
......
...@@ -30,7 +30,6 @@ namespace RTC ...@@ -30,7 +30,6 @@ namespace RTC
{ {
public: public:
virtual void OnPeerClosed(const RTC::Peer* peer) = 0; virtual void OnPeerClosed(const RTC::Peer* peer) = 0;
virtual void OnPeerCapabilities(RTC::Peer* peer, RTC::RtpCapabilities* capabilities) = 0;
virtual void OnPeerProducerParameters(const RTC::Peer* peer, RTC::Producer* producer) = 0; virtual void OnPeerProducerParameters(const RTC::Peer* peer, RTC::Producer* producer) = 0;
virtual void OnPeerProducerClosed(const RTC::Peer* peer, const RTC::Producer* producer) = 0; virtual void OnPeerProducerClosed(const RTC::Peer* peer, const RTC::Producer* producer) = 0;
virtual void OnPeerConsumerClosed(const RTC::Peer* peer, RTC::Consumer* consumer) = 0; virtual void OnPeerConsumerClosed(const RTC::Peer* peer, RTC::Consumer* consumer) = 0;
...@@ -57,7 +56,6 @@ namespace RTC ...@@ -57,7 +56,6 @@ namespace RTC
void Destroy(); void Destroy();
Json::Value ToJson() const; Json::Value ToJson() const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
bool HasCapabilities() const;
std::vector<RTC::Producer*> GetProducers() const; std::vector<RTC::Producer*> GetProducers() const;
std::vector<RTC::Consumer*> GetConsumers() const; std::vector<RTC::Consumer*> GetConsumers() const;
const std::unordered_map<uint32_t, RTC::Transport*>& GetTransports() const; const std::unordered_map<uint32_t, RTC::Transport*>& GetTransports() const;
...@@ -111,8 +109,6 @@ namespace RTC ...@@ -111,8 +109,6 @@ namespace RTC
Channel::Notifier* notifier{ nullptr }; Channel::Notifier* notifier{ nullptr };
// Others. // Others.
Timer* timer{ nullptr }; Timer* timer{ nullptr };
bool hasCapabilities{ false };
RTC::RtpCapabilities capabilities;
std::unordered_map<uint32_t, RTC::Transport*> transports; std::unordered_map<uint32_t, RTC::Transport*> transports;
std::unordered_map<uint32_t, RTC::Producer*> producers; std::unordered_map<uint32_t, RTC::Producer*> producers;
std::unordered_map<uint32_t, RTC::Consumer*> consumers; std::unordered_map<uint32_t, RTC::Consumer*> consumers;
...@@ -120,11 +116,6 @@ namespace RTC ...@@ -120,11 +116,6 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline bool Peer::HasCapabilities() const
{
return this->hasCapabilities;
}
inline std::vector<RTC::Producer*> Peer::GetProducers() const inline std::vector<RTC::Producer*> Peer::GetProducers() const
{ {
std::vector<RTC::Producer*> producers; std::vector<RTC::Producer*> producers;
......
...@@ -31,7 +31,7 @@ namespace RTC ...@@ -31,7 +31,7 @@ namespace RTC
}; };
public: public:
Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data); Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId);
private: private:
virtual ~Room(); virtual ~Room();
...@@ -40,17 +40,14 @@ namespace RTC ...@@ -40,17 +40,14 @@ namespace RTC
void Destroy(); void Destroy();
Json::Value ToJson() const; Json::Value ToJson() const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
const RTC::RtpCapabilities& GetCapabilities() const;
private: private:
RTC::Peer* GetPeerFromRequest(Channel::Request* request, uint32_t* peerId = nullptr) const; RTC::Peer* GetPeerFromRequest(Channel::Request* request, uint32_t* peerId = nullptr) const;
void SetCapabilities(std::vector<RTC::RtpCodecParameters>& mediaCodecs); void AddConsumerForProducer(RTC::Peer* consumerPeer, const RTC::Producer* producer);
void AddConsumerForProducer(RTC::Peer* senderPeer, const RTC::Producer* producer);
/* Pure virtual methods inherited from RTC::Peer::Listener. */ /* Pure virtual methods inherited from RTC::Peer::Listener. */
public: public:
void OnPeerClosed(const RTC::Peer* peer) override; void OnPeerClosed(const RTC::Peer* peer) override;
void OnPeerCapabilities(RTC::Peer* peer, RTC::RtpCapabilities* capabilities) override;
void OnPeerProducerParameters(const RTC::Peer* peer, RTC::Producer* producer) override; void OnPeerProducerParameters(const RTC::Peer* peer, RTC::Producer* producer) override;
void OnPeerProducerClosed(const RTC::Peer* peer, const RTC::Producer* producer) override; void OnPeerProducerClosed(const RTC::Peer* peer, const RTC::Producer* producer) override;
void OnPeerConsumerClosed(const RTC::Peer* peer, RTC::Consumer* consumer) override; void OnPeerConsumerClosed(const RTC::Peer* peer, RTC::Consumer* consumer) override;
...@@ -80,21 +77,12 @@ namespace RTC ...@@ -80,21 +77,12 @@ namespace RTC
// Allocated by this. // Allocated by this.
Timer* audioLevelsTimer{ nullptr }; Timer* audioLevelsTimer{ nullptr };
// Others. // Others.
RTC::RtpCapabilities capabilities;
std::unordered_map<uint8_t, RTC::RtpCodecParameters> mapPayloadRtxCodecParameters;
std::unordered_map<uint32_t, RTC::Peer*> peers; std::unordered_map<uint32_t, RTC::Peer*> peers;
std::unordered_map<const RTC::Producer*, std::unordered_set<RTC::Consumer*>> mapProducerConsumers; std::unordered_map<const RTC::Producer*, std::unordered_set<RTC::Consumer*>> mapProducerConsumers;
std::unordered_map<const RTC::Consumer*, const RTC::Producer*> mapConsumerProducer; std::unordered_map<const RTC::Consumer*, const RTC::Producer*> mapConsumerProducer;
std::unordered_map<RTC::Producer*, std::vector<int8_t>> mapProducerAudioLevels; std::unordered_map<RTC::Producer*, std::vector<int8_t>> mapProducerAudioLevels;
bool audioLevelsEventEnabled{ false }; bool audioLevelsEventEnabled{ false };
}; };
/* Inline static methods. */
inline const RTC::RtpCapabilities& Room::GetCapabilities() const
{
return this->capabilities;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -157,65 +157,6 @@ namespace RTC ...@@ -157,65 +157,6 @@ namespace RTC
std::string parameter; std::string parameter;
}; };
class RtpCodecCapability
{
public:
RtpCodecCapability(){};
RtpCodecCapability(Json::Value& data);
Json::Value ToJson() const;
bool Matches(RtpCodecCapability& codec, bool checkPayloadType = false);
void ReduceRtcpFeedback(std::vector<RtcpFeedback>& supportedRtcpFeedback);
private:
void CheckCodec();
public:
Media::Kind kind{ Media::Kind::ALL };
RtpCodecMimeType mime;
uint8_t payloadType{ 0 };
uint32_t clockRate{ 0 };
uint32_t maxptime{ 0 };
uint32_t ptime{ 0 };
uint32_t channels{ 1 };
RTC::Parameters parameters;
std::vector<RtcpFeedback> rtcpFeedback;
};
class RtpHeaderExtension
{
public:
explicit RtpHeaderExtension(Json::Value& data);
Json::Value ToJson() const;
public:
Media::Kind kind{ Media::Kind::ALL };
std::string uri;
RtpHeaderExtensionUri::Type type;
uint8_t preferredId{ 0 };
bool preferredEncrypt{ false };
};
class RtpCapabilities
{
public:
RtpCapabilities(){};
RtpCapabilities(Json::Value& data);
Json::Value ToJson() const;
void ReduceHeaderExtensions(std::vector<RtpHeaderExtension>& supportedHeaderExtensions);
void ReduceFecMechanisms(std::vector<std::string>& supportedFecMechanisms);
private:
void ValidateCodecs();
public:
std::vector<RtpCodecCapability> codecs;
std::vector<RtpHeaderExtension> headerExtensions;
std::vector<std::string> fecMechanisms;
};
class RtpCodecParameters class RtpCodecParameters
{ {
public: public:
...@@ -326,8 +267,6 @@ namespace RTC ...@@ -326,8 +267,6 @@ namespace RTC
explicit RtpParameters(const RtpParameters* rtpParameters); explicit RtpParameters(const RtpParameters* rtpParameters);
Json::Value ToJson() const; Json::Value ToJson() const;
void ReduceCodecsAndEncodings(RtpCapabilities& capabilities);
void ReduceHeaderExtensions(std::vector<RtpHeaderExtension>& supportedHeaderExtensions);
RTC::RtpCodecParameters& GetCodecForEncoding(RtpEncodingParameters& encoding); RTC::RtpCodecParameters& GetCodecForEncoding(RtpEncodingParameters& encoding);
RTC::RtpCodecParameters& GetRtxCodecForEncoding(RtpEncodingParameters& encoding); RTC::RtpCodecParameters& GetRtxCodecForEncoding(RtpEncodingParameters& encoding);
......
...@@ -50,7 +50,6 @@ ...@@ -50,7 +50,6 @@
'src/RTC/RtpDictionaries/RtpCodecParameters.cpp', 'src/RTC/RtpDictionaries/RtpCodecParameters.cpp',
'src/RTC/RtpDictionaries/RtpEncodingParameters.cpp', 'src/RTC/RtpDictionaries/RtpEncodingParameters.cpp',
'src/RTC/RtpDictionaries/RtpFecParameters.cpp', 'src/RTC/RtpDictionaries/RtpFecParameters.cpp',
'src/RTC/RtpDictionaries/RtpHeaderExtension.cpp',
'src/RTC/RtpDictionaries/RtpHeaderExtensionParameters.cpp', 'src/RTC/RtpDictionaries/RtpHeaderExtensionParameters.cpp',
'src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp', 'src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp',
'src/RTC/RtpDictionaries/RtpParameters.cpp', 'src/RTC/RtpDictionaries/RtpParameters.cpp',
......
...@@ -166,8 +166,6 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req ...@@ -166,8 +166,6 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req
case Channel::Request::MethodId::WORKER_CREATE_ROOM: case Channel::Request::MethodId::WORKER_CREATE_ROOM:
{ {
static const Json::StaticString JsonStringCapabilities{ "capabilities" };
RTC::Room* room; RTC::Room* room;
uint32_t roomId; uint32_t roomId;
...@@ -191,7 +189,7 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req ...@@ -191,7 +189,7 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req
try try
{ {
room = new RTC::Room(this, this->notifier, roomId, request->data); room = new RTC::Room(this, this->notifier, roomId);
} }
catch (const MediaSoupError& error) catch (const MediaSoupError& error)
{ {
...@@ -206,9 +204,6 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req ...@@ -206,9 +204,6 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req
Json::Value data(Json::objectValue); Json::Value data(Json::objectValue);
// Add `capabilities`.
data[JsonStringCapabilities] = room->GetCapabilities().ToJson();
request->Accept(data); request->Accept(data);
break; break;
...@@ -220,7 +215,6 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req ...@@ -220,7 +215,6 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req
case Channel::Request::MethodId::ROOM_SET_AUDIO_LEVELS_EVENT: case Channel::Request::MethodId::ROOM_SET_AUDIO_LEVELS_EVENT:
case Channel::Request::MethodId::PEER_CLOSE: case Channel::Request::MethodId::PEER_CLOSE:
case Channel::Request::MethodId::PEER_DUMP: case Channel::Request::MethodId::PEER_DUMP:
case Channel::Request::MethodId::PEER_SET_CAPABILITIES:
case Channel::Request::MethodId::PEER_CREATE_TRANSPORT: case Channel::Request::MethodId::PEER_CREATE_TRANSPORT:
case Channel::Request::MethodId::PEER_CREATE_PRODUCER: case Channel::Request::MethodId::PEER_CREATE_PRODUCER:
case Channel::Request::MethodId::TRANSPORT_CLOSE: case Channel::Request::MethodId::TRANSPORT_CLOSE:
......
...@@ -62,7 +62,7 @@ namespace RTC ...@@ -62,7 +62,7 @@ namespace RTC
static const Json::StaticString JsonStringKind{ "kind" }; static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" }; static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" };
static const Json::StaticString JsonStringHasTransport{ "hasTransport" }; static const Json::StaticString JsonStringHasTransport{ "hasTransport" };
static const Json::StaticString JsonStringActive{ "active" }; static const Json::StaticString JsonStringEnabled{ "enabled" };
static const Json::StaticString JsonStringSupportedPayloadTypes{ "supportedPayloadTypes" }; static const Json::StaticString JsonStringSupportedPayloadTypes{ "supportedPayloadTypes" };
static const Json::StaticString JsonStringRtpStream{ "rtpStream" }; static const Json::StaticString JsonStringRtpStream{ "rtpStream" };
...@@ -79,7 +79,7 @@ namespace RTC ...@@ -79,7 +79,7 @@ namespace RTC
json[JsonStringHasTransport] = this->transport != nullptr; json[JsonStringHasTransport] = this->transport != nullptr;
json[JsonStringActive] = this->GetActive(); json[JsonStringEnabled] = this->GetEnabled();
json[JsonStringSupportedPayloadTypes] = Json::arrayValue; json[JsonStringSupportedPayloadTypes] = Json::arrayValue;
...@@ -109,50 +109,6 @@ namespace RTC ...@@ -109,50 +109,6 @@ namespace RTC
break; break;
} }
case Channel::Request::MethodId::CONSUMER_DISABLE:
{
static const Json::StaticString JsonStringDisabled{ "disabled" };
static const Json::StaticString JsonStringEmit{ "emit" };
if (!request->data[JsonStringDisabled].isBool())
{
request->Reject("Request has invalid data.disabled");
return;
}
bool disabled = request->data[JsonStringDisabled].asBool();
bool emit = true;
if (request->data[JsonStringEmit].isBool())
emit = request->data[JsonStringEmit].asBool();
// Nothing changed.
if (this->disabled == disabled)
{
request->Accept();
return;
}
bool wasActive = this->GetActive();
this->disabled = disabled;
if (wasActive != this->GetActive())
{
if (emit)
EmitActiveChange();
if (this->GetActive())
this->listener->OnConsumerFullFrameRequired(this);
}
request->Accept();
break;
}
default: default:
{ {
MS_ERROR("unknown method"); MS_ERROR("unknown method");
...@@ -162,24 +118,14 @@ namespace RTC ...@@ -162,24 +118,14 @@ namespace RTC
} }
} }
void Consumer::SetPeerCapabilities(RTC::RtpCapabilities* peerCapabilities)
{
MS_TRACE();
MS_ASSERT(peerCapabilities, "given peerCapabilities are null");
this->peerCapabilities = peerCapabilities;
}
void Consumer::Send(RTC::RtpParameters* rtpParameters) void Consumer::Send(RTC::RtpParameters* rtpParameters)
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" }; static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" }; static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" };
static const Json::StaticString JsonStringActive{ "active" }; static const Json::StaticString JsonStringEnabled{ "enabled" };
MS_ASSERT(this->peerCapabilities, "peer capabilities unset");
MS_ASSERT(rtpParameters, "no RTP parameters given"); MS_ASSERT(rtpParameters, "no RTP parameters given");
bool hadParameters = this->rtpParameters != nullptr; bool hadParameters = this->rtpParameters != nullptr;
...@@ -195,83 +141,11 @@ namespace RTC ...@@ -195,83 +141,11 @@ namespace RTC
this->rtpStream = nullptr; this->rtpStream = nullptr;
} }
// Clone given RTP parameters so we manage our own sender parameters. // Clone given RTP parameters so we manage our own parameters.
this->rtpParameters = new RTC::RtpParameters(rtpParameters); this->rtpParameters = new RTC::RtpParameters(rtpParameters);
// Remove RTP parameters not supported by this Peer. // NOTE: We assume a single stream/encoding when sending to remote peers.
// CreateRtpStream(encodings[0]);
// Remove unsupported codecs.
auto& codecs = this->rtpParameters->codecs;
for (auto it = codecs.begin(); it != this->rtpParameters->codecs.end();)
{
auto& codec = *it;
auto it2 = codecs.begin();
for (; it2 != codecs.end(); ++it2)
{
auto& codecCapability = *it2;
if (codecCapability.Matches(codec))
break;
}
if (it2 != codecs.end())
{
this->supportedPayloadTypes.insert(codec.payloadType);
++it;
}
else
{
it = codecs.erase(it);
}
}
// Remove unsupported encodings.
auto& encodings = this->rtpParameters->encodings;
for (auto it = encodings.begin(); it != encodings.end();)
{
auto& encoding = *it;
if (supportedPayloadTypes.find(encoding.codecPayloadType) != supportedPayloadTypes.end())
{
++it;
}
else
{
it = encodings.erase(it);
}
}
// TODO: Temporal. To be refactored.
// Remove all the encodings but the first one.
if (encodings.size() > 1)
{
RTC::RtpEncodingParameters encoding = encodings[0];
encodings.clear();
encodings.push_back(encoding);
}
// Remove unsupported header extensions.
this->rtpParameters->ReduceHeaderExtensions(this->peerCapabilities->headerExtensions);
// Set a random muxId.
this->rtpParameters->muxId = Utils::Crypto::GetRandomString(8);
// If there are no encodings set not available.
if (!encodings.empty())
{
this->available = true;
// NOTE: We assume a single stream/encoding when sending to remote peers.
CreateRtpStream(encodings[0]);
}
else
{
this->available = false;
}
// Emit "parameterschange" if these are updated parameters. // Emit "parameterschange" if these are updated parameters.
if (hadParameters) if (hadParameters)
...@@ -280,7 +154,7 @@ namespace RTC ...@@ -280,7 +154,7 @@ namespace RTC
eventData[JsonStringClass] = "Consumer"; eventData[JsonStringClass] = "Consumer";
eventData[JsonStringRtpParameters] = this->rtpParameters->ToJson(); eventData[JsonStringRtpParameters] = this->rtpParameters->ToJson();
eventData[JsonStringActive] = this->GetActive(); eventData[JsonStringEnabled] = this->GetEnabled();
this->notifier->Emit(this->consumerId, "parameterschange", eventData); this->notifier->Emit(this->consumerId, "parameterschange", eventData);
} }
...@@ -290,7 +164,7 @@ namespace RTC ...@@ -290,7 +164,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (!this->GetActive()) if (!this->GetEnabled())
return; return;
MS_ASSERT(this->rtpStream, "no RtpStream set"); MS_ASSERT(this->rtpStream, "no RtpStream set");
...@@ -477,7 +351,7 @@ namespace RTC ...@@ -477,7 +351,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (!this->GetActive()) if (!this->GetEnabled())
return; return;
MS_ASSERT(this->rtpStream, "no RtpStream set"); MS_ASSERT(this->rtpStream, "no RtpStream set");
...@@ -522,17 +396,15 @@ namespace RTC ...@@ -522,17 +396,15 @@ namespace RTC
delete rtxPacket; delete rtxPacket;
} }
inline void Consumer::EmitActiveChange() const void Consumer::EmitEnabledChange() const
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" }; static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringActive{ "active" };
Json::Value eventData(Json::objectValue); Json::Value eventData(Json::objectValue);
eventData[JsonStringClass] = "Consumer"; eventData[JsonStringClass] = "Consumer";
eventData[JsonStringActive] = this->GetActive();
this->notifier->Emit(this->consumerId, "activechange", eventData); this->notifier->Emit(this->consumerId, "activechange", eventData);
} }
......
...@@ -79,7 +79,7 @@ namespace RTC ...@@ -79,7 +79,7 @@ namespace RTC
{ "server", DtlsTransport::Role::SERVER } { "server", DtlsTransport::Role::SERVER }
}; };
// clang-format on // clang-format on
Json::Value DtlsTransport::localFingerprints = Json::Value(Json::objectValue); Json::Value DtlsTransport::localFingerprints = Json::Value(Json::arrayValue);
// clang-format off // clang-format off
std::vector<DtlsTransport::SrtpProfileMapEntry> DtlsTransport::srtpProfiles = std::vector<DtlsTransport::SrtpProfileMapEntry> DtlsTransport::srtpProfiles =
{ {
...@@ -497,7 +497,12 @@ namespace RTC ...@@ -497,7 +497,12 @@ namespace RTC
MS_DEBUG_TAG(dtls, "%-7s fingerprint: %s", algorithmString.c_str(), hexFingerprint); MS_DEBUG_TAG(dtls, "%-7s fingerprint: %s", algorithmString.c_str(), hexFingerprint);
// Store in the JSON. // Store in the JSON.
DtlsTransport::localFingerprints[algorithmString] = hexFingerprint;
Json::Value fingerprint(Json::objectValue);
fingerprint["algorithm"] = algorithmString;
fingerprint["value"] = hexFingerprint;
DtlsTransport::localFingerprints.append(fingerprint);
} }
} }
......
...@@ -87,7 +87,6 @@ namespace RTC ...@@ -87,7 +87,6 @@ namespace RTC
static const Json::StaticString JsonStringPeerId{ "peerId" }; static const Json::StaticString JsonStringPeerId{ "peerId" };
static const Json::StaticString JsonStringPeerName{ "peerName" }; static const Json::StaticString JsonStringPeerName{ "peerName" };
static const Json::StaticString JsonStringCapabilities{ "capabilities" };
static const Json::StaticString JsonStringTransports{ "transports" }; static const Json::StaticString JsonStringTransports{ "transports" };
static const Json::StaticString JsonStringProducers{ "producers" }; static const Json::StaticString JsonStringProducers{ "producers" };
static const Json::StaticString JsonStringConsumers{ "consumers" }; static const Json::StaticString JsonStringConsumers{ "consumers" };
...@@ -103,10 +102,6 @@ namespace RTC ...@@ -103,10 +102,6 @@ namespace RTC
// Add `peerName`. // Add `peerName`.
json[JsonStringPeerName] = this->peerName; json[JsonStringPeerName] = this->peerName;
// Add `capabilities`.
if (this->hasCapabilities)
json[JsonStringCapabilities] = this->capabilities.ToJson();
// Add `transports`. // Add `transports`.
for (auto& kv : this->transports) for (auto& kv : this->transports)
{ {
...@@ -167,45 +162,6 @@ namespace RTC ...@@ -167,45 +162,6 @@ namespace RTC
break; break;
} }
case Channel::Request::MethodId::PEER_SET_CAPABILITIES:
{
// Capabilities must not be set.
if (this->hasCapabilities)
{
request->Reject("peer capabilities already set");
return;
}
try
{
this->capabilities = RTC::RtpCapabilities(request->data);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
this->hasCapabilities = true;
// Notify the listener (Room) who will remove capabilities to make them
// a subset of the room capabilities.
this->listener->OnPeerCapabilities(this, std::addressof(this->capabilities));
Json::Value data = this->capabilities.ToJson();
// NOTE: We accept the request *after* calling onPeerCapabilities(). This
// guarantees that the Peer will receive a "newconsumer" event for all its
// associated Consumers *before* the setCapabilities() Promise resolves.
// In other words, at the time setCapabilities() resolves, the Peer already
// has set all its current Consumers.
request->Accept(data);
break;
}
case Channel::Request::MethodId::PEER_CREATE_TRANSPORT: case Channel::Request::MethodId::PEER_CREATE_TRANSPORT:
{ {
RTC::Transport* transport; RTC::Transport* transport;
...@@ -259,14 +215,6 @@ namespace RTC ...@@ -259,14 +215,6 @@ namespace RTC
RTC::Transport* transport{ nullptr }; RTC::Transport* transport{ nullptr };
uint32_t producerId; uint32_t producerId;
// Capabilities must be set.
if (!this->hasCapabilities)
{
request->Reject("peer capabilities are not yet set");
return;
}
try try
{ {
producer = GetProducerFromRequest(request, &producerId); producer = GetProducerFromRequest(request, &producerId);
...@@ -584,16 +532,13 @@ namespace RTC ...@@ -584,16 +532,13 @@ namespace RTC
static const Json::StaticString JsonStringConsumerId{ "consumerId" }; static const Json::StaticString JsonStringConsumerId{ "consumerId" };
static const Json::StaticString JsonStringKind{ "kind" }; static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" }; static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" };
static const Json::StaticString JsonStringActive{ "active" }; static const Json::StaticString JsonStringEnabled{ "enabled" };
static const Json::StaticString JsonStringAssociatedProducerId{ "associatedProducerId" }; static const Json::StaticString JsonStringAssociatedProducerId{ "associatedProducerId" };
MS_ASSERT( MS_ASSERT(
this->consumers.find(consumer->consumerId) == this->consumers.end(), this->consumers.find(consumer->consumerId) == this->consumers.end(),
"given Consumer already exists in this Peer"); "given Consumer already exists in this Peer");
// Provide the Consumer with peer's capabilities.
consumer->SetPeerCapabilities(std::addressof(this->capabilities));
// Provide the Consumer with the received RTP parameters. // Provide the Consumer with the received RTP parameters.
consumer->Send(rtpParameters); consumer->Send(rtpParameters);
...@@ -607,7 +552,7 @@ namespace RTC ...@@ -607,7 +552,7 @@ namespace RTC
eventData[JsonStringConsumerId] = Json::UInt{ consumer->consumerId }; eventData[JsonStringConsumerId] = Json::UInt{ consumer->consumerId };
eventData[JsonStringKind] = RTC::Media::GetJsonString(consumer->kind); eventData[JsonStringKind] = RTC::Media::GetJsonString(consumer->kind);
eventData[JsonStringRtpParameters] = consumer->GetParameters()->ToJson(); eventData[JsonStringRtpParameters] = consumer->GetParameters()->ToJson();
eventData[JsonStringActive] = consumer->GetActive(); eventData[JsonStringEnabled] = consumer->GetEnabled();
eventData[JsonStringAssociatedProducerId] = Json::UInt{ associatedProducerId }; eventData[JsonStringAssociatedProducerId] = Json::UInt{ associatedProducerId };
this->notifier->Emit(this->peerId, "newconsumer", eventData); this->notifier->Emit(this->peerId, "newconsumer", eventData);
...@@ -858,13 +803,6 @@ namespace RTC ...@@ -858,13 +803,6 @@ namespace RTC
MS_TRACE(); MS_TRACE();
auto rtpParameters = producer->GetParameters(); auto rtpParameters = producer->GetParameters();
// Remove unsupported codecs and their associated encodings.
rtpParameters->ReduceCodecsAndEncodings(this->capabilities);
// Remove unsupported header extensions.
rtpParameters->ReduceHeaderExtensions(this->capabilities.headerExtensions);
auto transport = producer->GetTransport(); auto transport = producer->GetTransport();
// NOTE: This may throw. // NOTE: This may throw.
...@@ -949,8 +887,8 @@ namespace RTC ...@@ -949,8 +887,8 @@ namespace RTC
if (consumer != nullptr) if (consumer != nullptr)
{ {
// If the Consumer is not active, drop the packet. // If the Consumer is not enabled, drop the packet.
if (!consumer->GetActive()) if (!consumer->GetEnabled())
break; break;
if (feedback->GetMessageType() == RTCP::FeedbackPs::MessageType::PLI) if (feedback->GetMessageType() == RTCP::FeedbackPs::MessageType::PLI)
......
差异被折叠。
#define MS_CLASS "RTC::RtpCapabilities"
// #define MS_LOG_DEV
#include "Logger.hpp"
#include "MediaSoupError.hpp"
#include "RTC/RtpDictionaries.hpp"
#include <unordered_set>
namespace RTC
{
/* Instance methods. */
RtpCapabilities::RtpCapabilities(Json::Value& data)
{
MS_TRACE();
static const Json::StaticString JsonStringCodecs{ "codecs" };
static const Json::StaticString JsonStringHeaderExtensions{ "headerExtensions" };
static const Json::StaticString JsonStringFecMechanisms{ "fecMechanisms" };
// `codecs` is optional.
if (data[JsonStringCodecs].isArray())
{
auto& jsonCodecs = data[JsonStringCodecs];
for (auto& jsonCodec : jsonCodecs)
{
RtpCodecCapability codec(jsonCodec);
// Append to the codecs vector.
this->codecs.push_back(codec);
}
}
// `headerExtensions` is optional.
if (data[JsonStringHeaderExtensions].isArray())
{
auto& jsonArray = data[JsonStringHeaderExtensions];
for (auto& i : jsonArray)
{
RtpHeaderExtension headerExtension(i);
// If a known header extension, append to the headerExtensions vector.
if (headerExtension.type != RtpHeaderExtensionUri::Type::UNKNOWN)
this->headerExtensions.push_back(headerExtension);
}
}
// `fecMechanisms` is optional.
if (data[JsonStringFecMechanisms].isArray())
{
auto& jsonArray = data[JsonStringFecMechanisms];
for (const auto& i : jsonArray)
{
if (!i.isString())
MS_THROW_ERROR("invalid RtpCapabilities.fecMechanisms");
// Append to the fecMechanisms vector.
this->fecMechanisms.push_back(i.asString());
}
}
// Validate RTP capabilities.
ValidateCodecs();
}
Json::Value RtpCapabilities::ToJson() const
{
MS_TRACE();
static const Json::StaticString JsonStringCodecs{ "codecs" };
static const Json::StaticString JsonStringHeaderExtensions{ "headerExtensions" };
static const Json::StaticString JsonStringFecMechanisms{ "fecMechanisms" };
Json::Value json(Json::objectValue);
// Add `codecs`.
json[JsonStringCodecs] = Json::arrayValue;
for (auto& entry : this->codecs)
{
json[JsonStringCodecs].append(entry.ToJson());
}
// Add `headerExtensions`.
json[JsonStringHeaderExtensions] = Json::arrayValue;
for (auto& entry : this->headerExtensions)
{
json[JsonStringHeaderExtensions].append(entry.ToJson());
}
// Add `fecMechanisms`.
json[JsonStringFecMechanisms] = Json::arrayValue;
for (auto& entry : this->fecMechanisms)
{
json[JsonStringFecMechanisms].append(entry);
}
return json;
}
void RtpCapabilities::ReduceHeaderExtensions(
std::vector<RTC::RtpHeaderExtension>& supportedHeaderExtensions)
{
MS_TRACE();
std::vector<RTC::RtpHeaderExtension> updatedHeaderExtensions;
for (auto& headerExtension : this->headerExtensions)
{
for (auto& supportedHeaderExtension : supportedHeaderExtensions)
{
if (headerExtension.type == supportedHeaderExtension.type &&
(headerExtension.kind == supportedHeaderExtension.kind ||
supportedHeaderExtension.kind == RTC::Media::Kind::ALL))
{
// Set the same id and other properties.
headerExtension.preferredId = supportedHeaderExtension.preferredId;
headerExtension.preferredEncrypt = supportedHeaderExtension.preferredEncrypt;
updatedHeaderExtensions.push_back(headerExtension);
break;
}
}
}
this->headerExtensions = updatedHeaderExtensions;
}
void RtpCapabilities::ReduceFecMechanisms(std::vector<std::string>& supportedFecMechanisms)
{
MS_TRACE();
std::vector<std::string> updatedFecMechanisms;
for (auto& fecMechanism : this->fecMechanisms)
{
for (auto& supportedFecMechanism : supportedFecMechanisms)
{
if (fecMechanism == supportedFecMechanism)
{
updatedFecMechanisms.push_back(fecMechanism);
break;
}
}
}
this->fecMechanisms = updatedFecMechanisms;
}
inline void RtpCapabilities::ValidateCodecs()
{
MS_TRACE();
// Payload types must be unique.
std::unordered_set<uint8_t> payloadTypes;
for (auto& codec : this->codecs)
{
if (payloadTypes.find(codec.payloadType) != payloadTypes.end())
MS_THROW_ERROR("duplicated codec.payloadType");
else
payloadTypes.insert(codec.payloadType);
}
}
} // namespace RTC
#define MS_CLASS "RTC::RtpCodecCapability"
// #define MS_LOG_DEV
#include "Logger.hpp"
#include "MediaSoupError.hpp"
#include "RTC/RtpDictionaries.hpp"
namespace RTC
{
/* Instance methods. */
RtpCodecCapability::RtpCodecCapability(Json::Value& data)
{
MS_TRACE();
static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringMimeType{ "mimeType" };
static const Json::StaticString JsonStringPayloadType{ "payloadType" };
static const Json::StaticString JsonStringClockRate{ "clockRate" };
static const Json::StaticString JsonStringMaxptime{ "maxptime" };
static const Json::StaticString JsonStringPtime{ "ptime" };
static const Json::StaticString JsonStringNumChannels{ "channels" };
static const Json::StaticString JsonStringParameters{ "parameters" };
static const Json::StaticString JsonStringRtcpFeedback{ "rtcpFeedback" };
if (!data.isObject())
MS_THROW_ERROR("RtpCodecCapability is not an object");
// `kind` is mandatory.
if (!data[JsonStringKind].isString())
MS_THROW_ERROR("missing RtpCodecCapability.kind");
std::string kind = data[JsonStringKind].asString();
// NOTE: This may throw.
this->kind = RTC::Media::GetKind(kind);
// `mimeType` is mandatory.
if (!data[JsonStringMimeType].isString())
MS_THROW_ERROR("missing RtpCodec.mimeType");
std::string mimeType = data[JsonStringMimeType].asString();
// Set MIME field.
// NOTE: This may throw.
this->mime.SetMimeType(mimeType);
if (!data[JsonStringPayloadType].isUInt())
MS_THROW_ERROR("missing RtpCodecCapability.payloadType");
this->payloadType = static_cast<uint8_t>(data[JsonStringPayloadType].asUInt());
// `clockRate` is mandatory.
if (!data[JsonStringClockRate].isUInt())
MS_THROW_ERROR("missing RtpCodecCapability.clockRate");
this->clockRate = uint32_t{ data[JsonStringClockRate].asUInt() };
// `maxptime` is optional.
if (data[JsonStringMaxptime].isUInt())
this->maxptime = uint32_t{ data[JsonStringMaxptime].asUInt() };
// `ptime` is optional.
if (data[JsonStringPtime].isUInt())
this->ptime = uint32_t{ data[JsonStringPtime].asUInt() };
// `channels` is optional.
if (data[JsonStringNumChannels].isUInt())
this->channels = uint32_t{ data[JsonStringNumChannels].asUInt() };
// `parameters` is optional.
if (data[JsonStringParameters].isObject())
this->parameters.Set(data[JsonStringParameters]);
// `rtcpFeedback` is optional.
if (data[JsonStringRtcpFeedback].isArray())
{
auto& jsonRtcpFeedback = data[JsonStringRtcpFeedback];
for (auto& i : jsonRtcpFeedback)
{
RTC::RtcpFeedback rtcpFeedback(i);
// Append to the rtcpFeedback vector.
this->rtcpFeedback.push_back(rtcpFeedback);
}
}
// Check codec.
CheckCodec();
}
Json::Value RtpCodecCapability::ToJson() const
{
MS_TRACE();
static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringMimeType{ "mimeType" };
static const Json::StaticString JsonStringName{ "name" };
static const Json::StaticString JsonStringPayloadType{ "payloadType" };
static const Json::StaticString JsonStringClockRate{ "clockRate" };
static const Json::StaticString JsonStringMaxptime{ "maxptime" };
static const Json::StaticString JsonStringPtime{ "ptime" };
static const Json::StaticString JsonStringNumChannels{ "channels" };
static const Json::StaticString JsonStringParameters{ "parameters" };
static const Json::StaticString JsonStringRtcpFeedback{ "rtcpFeedback" };
Json::Value json(Json::objectValue);
// Add `kind`.
json[JsonStringKind] = RTC::Media::GetJsonString(this->kind);
// Add `mimeType`.
json[JsonStringMimeType] = this->mime.ToString();
// Add `name`.
json[JsonStringName] = this->mime.GetName();
// Add `payloadType`.
json[JsonStringPayloadType] = Json::UInt{ this->payloadType };
// Add `clockRate`.
json[JsonStringClockRate] = Json::UInt{ this->clockRate };
// Add `maxptime`.
if (this->maxptime != 0u)
json[JsonStringMaxptime] = Json::UInt{ this->maxptime };
// Add `ptime`.
if (this->ptime != 0u)
json[JsonStringPtime] = Json::UInt{ this->ptime };
// Add `channels`.
if (this->channels > 1)
json[JsonStringNumChannels] = Json::UInt{ this->channels };
// Add `parameters`.
json[JsonStringParameters] = this->parameters.ToJson();
// Add `rtcpFeedback`.
json[JsonStringRtcpFeedback] = Json::arrayValue;
for (auto& entry : this->rtcpFeedback)
{
json[JsonStringRtcpFeedback].append(entry.ToJson());
}
return json;
}
bool RtpCodecCapability::Matches(RtpCodecCapability& codec, bool checkPayloadType)
{
MS_TRACE();
static std::string jsonStringPacketizationMode{ "packetizationMode" };
// MIME must match.
if (this->mime != codec.mime)
return false;
if (checkPayloadType)
{
if (this->payloadType != codec.payloadType)
return false;
}
// Clock rate must match.
if (this->clockRate != codec.clockRate)
return false;
// Per kind checks.
switch (this->kind)
{
case RTC::Media::Kind::AUDIO:
{
// Num channels must match.
if (this->channels != codec.channels)
return false;
break;
}
default:;
}
// Per MIME checks.
switch (this->mime.subtype)
{
case RTC::RtpCodecMimeType::Subtype::H264:
{
int32_t packetizationMode = this->parameters.GetInteger(jsonStringPacketizationMode);
int32_t givenPacketizationMode = codec.parameters.GetInteger(jsonStringPacketizationMode);
if (packetizationMode != givenPacketizationMode)
return false;
break;
}
default:;
}
return true;
}
void RtpCodecCapability::ReduceRtcpFeedback(std::vector<RTC::RtcpFeedback>& supportedRtcpFeedback)
{
MS_TRACE();
std::vector<RTC::RtcpFeedback> updatedRtcpFeedback;
for (auto& rtcpFeedbackItem : this->rtcpFeedback)
{
for (auto& supportedRtcpFeedbackItem : supportedRtcpFeedback)
{
if (rtcpFeedbackItem.type == supportedRtcpFeedbackItem.type &&
rtcpFeedbackItem.parameter == supportedRtcpFeedbackItem.parameter)
{
updatedRtcpFeedback.push_back(supportedRtcpFeedbackItem);
break;
}
}
}
this->rtcpFeedback = updatedRtcpFeedback;
}
inline void RtpCodecCapability::CheckCodec()
{
MS_TRACE();
static std::string jsonStringApt{ "apt" };
static std::string jsonStringPacketizationMode{ "packetizationMode" };
// Check per MIME parameters and set default values.
switch (this->mime.subtype)
{
case RTC::RtpCodecMimeType::Subtype::RTX:
{
// A RTX codec must have 'apt' parameter.
if (!this->parameters.HasInteger(jsonStringApt))
MS_THROW_ERROR("missing apt parameter in RTX RtpCodecCapability");
break;
}
case RTC::RtpCodecMimeType::Subtype::OPUS:
{
// Opus default channels is 2.
if (this->channels < 2)
this->channels = 2;
break;
}
case RTC::RtpCodecMimeType::Subtype::H264:
{
// H264 default packetizationMode is 0.
if (!this->parameters.HasInteger(jsonStringPacketizationMode))
this->parameters.SetInteger(jsonStringPacketizationMode, 0);
break;
}
default:;
}
}
} // namespace RTC
#define MS_CLASS "RTC::RtpHeaderExtension"
// #define MS_LOG_DEV
#include "Logger.hpp"
#include "MediaSoupError.hpp"
#include "RTC/RtpDictionaries.hpp"
namespace RTC
{
/* Instance methods. */
RtpHeaderExtension::RtpHeaderExtension(Json::Value& data)
{
MS_TRACE();
static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringUri{ "uri" };
static const Json::StaticString JsonStringPreferredId{ "preferredId" };
static const Json::StaticString JsonStringPreferredEncrypt{ "preferredEncrypt" };
if (!data.isObject())
MS_THROW_ERROR("RtpHeaderExtension is not an object");
// `kind` is mandatory.
if (!data[JsonStringKind].isString())
MS_THROW_ERROR("missing RtpCodecCapability.kind");
std::string kind = data[JsonStringKind].asString();
// NOTE: This may throw.
this->kind = RTC::Media::GetKind(kind);
// `uri` is mandatory.
if (!data[JsonStringUri].isString())
MS_THROW_ERROR("missing RtpHeaderExtension.uri");
this->uri = data[JsonStringUri].asString();
if (this->uri.empty())
MS_THROW_ERROR("empty RtpHeaderExtension.uri");
// Get the type.
this->type = RTC::RtpHeaderExtensionUri::GetType(this->uri);
// `preferredId` is mandatory.
if (!data[JsonStringPreferredId].isUInt())
MS_THROW_ERROR("missing RtpHeaderExtension.preferredId");
this->preferredId = static_cast<uint8_t>(data[JsonStringPreferredId].asUInt());
// `preferredEncrypt` is optional.
if (data[JsonStringPreferredEncrypt].isBool())
this->preferredEncrypt = data[JsonStringPreferredEncrypt].asBool();
}
Json::Value RtpHeaderExtension::ToJson() const
{
MS_TRACE();
static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringUri{ "uri" };
static const Json::StaticString JsonStringPreferredId{ "preferredId" };
static const Json::StaticString JsonStringPreferredEncrypt{ "preferredEncrypt" };
Json::Value json(Json::objectValue);
// Add `kind`.
json[JsonStringKind] = RTC::Media::GetJsonString(this->kind);
// Add `uri`.
json[JsonStringUri] = this->uri;
// Add `preferredId`.
json[JsonStringPreferredId] = Json::UInt{ this->preferredId };
// Add `preferredEncrypt`.
json[JsonStringPreferredEncrypt] = this->preferredEncrypt;
return json;
}
} // namespace RTC
...@@ -155,97 +155,6 @@ namespace RTC ...@@ -155,97 +155,6 @@ namespace RTC
return json; return json;
} }
void RtpParameters::ReduceCodecsAndEncodings(RtpCapabilities& capabilities)
{
MS_TRACE();
std::vector<uint8_t> removedCodecPayloadTypes;
for (auto it = this->codecs.begin(); it != this->codecs.end();)
{
auto& codec = *it;
auto it2 = capabilities.codecs.begin();
for (; it2 != capabilities.codecs.end(); ++it2)
{
auto& codecCapability = *it2;
if (codecCapability.Matches(codec, true))
{
// Once matched, remove the unsupported RTCP feedback from the given codec.
codec.ReduceRtcpFeedback(codecCapability.rtcpFeedback);
++it;
break;
}
}
if (it2 == capabilities.codecs.end())
{
MS_WARN_DEV(
"no matching peer codec capability found [payloadType:%" PRIu8 ", mime:%s]",
codec.payloadType,
codec.mime.ToString().c_str());
removedCodecPayloadTypes.push_back(codec.payloadType);
it = this->codecs.erase(it);
}
}
// Remove encodings if associated to removed codecs.
for (auto it = this->encodings.begin(); it != this->encodings.end();)
{
auto& encoding = *it;
auto it2 = removedCodecPayloadTypes.begin();
for (; it2 != removedCodecPayloadTypes.end(); ++it2)
{
auto removedCodecPayloadType = *it2;
if (encoding.codecPayloadType == removedCodecPayloadType)
{
MS_WARN_DEV("removing encoding without matching codec");
it = this->encodings.erase(it);
break;
}
}
if (it2 == removedCodecPayloadTypes.end())
{
++it;
}
}
// Finally validate codecs and encodings.
ValidateCodecs();
ValidateEncodings();
}
void RtpParameters::ReduceHeaderExtensions(std::vector<RtpHeaderExtension>& supportedHeaderExtensions)
{
MS_TRACE();
std::vector<RTC::RtpHeaderExtensionParameters> updatedHeaderExtensions;
for (auto& headerExtension : this->headerExtensions)
{
for (auto& supportedHeaderExtension : supportedHeaderExtensions)
{
if (headerExtension.type == supportedHeaderExtension.type)
{
// Set the same id and other properties.
headerExtension.id = supportedHeaderExtension.preferredId;
headerExtension.encrypt = supportedHeaderExtension.preferredEncrypt;
updatedHeaderExtensions.push_back(headerExtension);
break;
}
}
}
this->headerExtensions = updatedHeaderExtensions;
}
RTC::RtpCodecParameters& RtpParameters::GetCodecForEncoding(RtpEncodingParameters& encoding) RTC::RtpCodecParameters& RtpParameters::GetCodecForEncoding(RtpEncodingParameters& encoding)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -262,6 +262,7 @@ namespace RTC ...@@ -262,6 +262,7 @@ namespace RTC
static const Json::StaticString JsonStringIceLocalParameters{ "iceLocalParameters" }; static const Json::StaticString JsonStringIceLocalParameters{ "iceLocalParameters" };
static const Json::StaticString JsonStringUsernameFragment{ "usernameFragment" }; static const Json::StaticString JsonStringUsernameFragment{ "usernameFragment" };
static const Json::StaticString JsonStringPassword{ "password" }; static const Json::StaticString JsonStringPassword{ "password" };
static const Json::StaticString JsonStringIceLite{ "iceLite" };
static const Json::StaticString JsonStringIceLocalCandidates{ "iceLocalCandidates" }; static const Json::StaticString JsonStringIceLocalCandidates{ "iceLocalCandidates" };
static const Json::StaticString JsonStringIceSelectedTuple{ "iceSelectedTuple" }; static const Json::StaticString JsonStringIceSelectedTuple{ "iceSelectedTuple" };
static const Json::StaticString JsonStringIceState{ "iceState" }; static const Json::StaticString JsonStringIceState{ "iceState" };
...@@ -295,6 +296,7 @@ namespace RTC ...@@ -295,6 +296,7 @@ namespace RTC
json[JsonStringIceLocalParameters][JsonStringUsernameFragment] = json[JsonStringIceLocalParameters][JsonStringUsernameFragment] =
this->iceServer->GetUsernameFragment(); this->iceServer->GetUsernameFragment();
json[JsonStringIceLocalParameters][JsonStringPassword] = this->iceServer->GetPassword(); json[JsonStringIceLocalParameters][JsonStringPassword] = this->iceServer->GetPassword();
json[JsonStringIceLocalParameters][JsonStringIceLite] = true;
// Add `iceLocalCandidates`. // Add `iceLocalCandidates`.
json[JsonStringIceLocalCandidates] = Json::arrayValue; json[JsonStringIceLocalCandidates] = Json::arrayValue;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论