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

Add IsEnabled() to Producer and Consumer

上级 41b97e73
# TODO in mediasoup v2 (server-side)
* worker: All the RTC emthods in Producer and Consumer do a `MS_ASSERT(Enabled();` (meaning that they already have `transport` and `rtpParameters`). Producers/Consumers without them are not present in the Router `mapProducerConsumers`/`mapConsumerProducer` maps. However *THEY DO EXIST* in the Sets of `producers` and `consumers` of the Transport.
- So: before calling any RTC method on a Producer/Consumer, the Transport must check `producer/consumer->IsEnabled()` and ignore if not.
* JS: Do we need to close Producers/Consumers in Peer.close? If we close Transports then Producers and Consumers get also closed in the worker. The C++ Transport closes all its Producers and Consumers, and the client side gets producer.on('unhandled'), there is no need to close/destroy its local Producer.
- So, do we need to `producerClosed` notification? I don't think so...
......
......@@ -108,8 +108,6 @@ class Producer extends EnhancedEventEmitter
/**
* Close the Producer.
*
* @private
*
* @param {Any} [appData] - App custom data.
* @param {Boolean} [notifyChannel=true] - Private.
*/
......@@ -122,6 +120,12 @@ class Producer extends EnhancedEventEmitter
this._closed = true;
// If our Transport is still alive, it means that the app really wants to close
// the client-side Producer. Otherwise, if the Transport is closed the client-side
// Producer will get 'unhandled', so don't close it from here.
if (!this.transport.closed)
this.emit('@notify', 'producerClosed', { id: this.id, appData });
this.emit('@close');
this.safeEmit('close', 'local', appData);
......
......@@ -40,6 +40,7 @@ namespace Channel
PRODUCER_SET_RTP_OBJECT_EVENT,
CONSUMER_CLOSE,
CONSUMER_DUMP,
CONSUMER_SEND,
CONSUMER_PAUSE,
CONSUMER_RESUME
};
......
......@@ -26,6 +26,7 @@ namespace RTC
Channel::Notifier* notifier,
uint32_t consumerId,
RTC::Media::Kind kind,
uint32_t sourceProducerId,
RTC::Transport* transport);
private:
......@@ -37,9 +38,8 @@ namespace RTC
void HandleRequest(Channel::Request* request);
void AddListener(RTC::ConsumerListener* listener);
void RemoveListener(RTC::ConsumerListener* listener);
void Send(RTC::RtpParameters* rtpParameters);
RTC::RtpParameters* GetParameters() const; // TODO: What for?
bool GetEnabled() const;
bool IsEnabled() const;
RTC::RtpParameters* GetParameters() const;
void SendRtpPacket(RTC::RtpPacket* packet);
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket);
......@@ -55,6 +55,7 @@ namespace RTC
// Passed by argument.
uint32_t consumerId{ 0 };
RTC::Media::Kind kind;
uint32_t sourceProducerId{ 0 };
private:
// Passed by argument.
......@@ -65,8 +66,8 @@ namespace RTC
RTC::RtpParameters* rtpParameters{ nullptr };
RTC::RtpStreamSend* rtpStream{ nullptr };
// Others.
std::unordered_set<uint8_t> supportedCodecPayloadTypes;
bool paused{ false };
std::unordered_set<uint8_t> supportedPayloadTypes; // TODO: NO
// Timestamp when last RTCP was sent.
uint64_t lastRtcpSentTime{ 0 };
uint16_t maxRtcpInterval{ 0 };
......@@ -87,14 +88,14 @@ namespace RTC
this->listeners.erase(listener);
}
inline RTC::RtpParameters* Consumer::GetParameters() const
inline bool Consumer::IsEnabled() const
{
return this->rtpParameters;
return this->transport && this->rtpParameters && this->rtpStream;
}
inline bool Consumer::GetEnabled() const
inline RTC::RtpParameters* Consumer::GetParameters() const
{
return this->transport;
return this->rtpParameters;
}
inline uint32_t Consumer::GetTransmissionRate(uint64_t now)
......
......@@ -13,9 +13,9 @@
#include "RTC/RtpStreamRecv.hpp"
#include "RTC/Transport.hpp"
#include <json/json.h>
#include <unordered_set>
#include <map>
#include <string>
#include <unordered_set>
namespace RTC
{
......@@ -52,6 +52,7 @@ namespace RTC
void HandleRequest(Channel::Request* request);
void AddListener(RTC::ProducerListener* listener);
void RemoveListener(RTC::ProducerListener* listener);
bool IsEnabled() const;
RTC::RtpParameters* GetParameters() const;
void ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
......@@ -63,7 +64,6 @@ namespace RTC
private:
void CreateRtpMapping(Json::Value& rtpMapping);
void CreateRtpStream(RTC::RtpEncodingParameters& encoding);
void ClearRtpStreams();
void ApplyRtpMapping(RTC::RtpPacket* packet);
/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
......@@ -108,6 +108,11 @@ namespace RTC
this->listeners.erase(listener);
}
inline bool Producer::IsEnabled() const
{
return this->transport && this->rtpParameters && this->rtpStreams.size();
}
inline RTC::RtpParameters* Producer::GetParameters() const
{
return this->rtpParameters;
......
......@@ -35,6 +35,7 @@ namespace Channel
{ "producer.setRtpObjectEvent", Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT },
{ "consumer.close", Request::MethodId::CONSUMER_CLOSE },
{ "consumer.dump", Request::MethodId::CONSUMER_DUMP },
{ "consumer.send", Request::MethodId::CONSUMER_SEND },
{ "consumer.pause", Request::MethodId::CONSUMER_PAUSE },
{ "consumer.resume", Request::MethodId::CONSUMER_RESUME }
};
......
......@@ -18,8 +18,8 @@ namespace RTC
/* Instance methods. */
Consumer::Consumer(
Channel::Notifier* notifier, uint32_t consumerId, RTC::Media::Kind kind, RTC::Transport* transport)
: consumerId(consumerId), kind(kind), notifier(notifier), transport(transport)
Channel::Notifier* notifier, uint32_t consumerId, RTC::Media::Kind kind, uint32_t sourceProducerId, RTC::Transport* transport)
: consumerId(consumerId), kind(kind), sourceProducerId(sourceProducerId), notifier(notifier), transport(transport)
{
MS_TRACE();
......@@ -56,11 +56,11 @@ namespace RTC
static const Json::StaticString JsonStringConsumerId{ "consumerId" };
static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringSourceProducerId{ "sourceProducerId" };
static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" };
static const Json::StaticString JsonStringHasTransport{ "hasTransport" };
static const Json::StaticString JsonStringEnabled{ "enabled" };
static const Json::StaticString JsonStringSupportedPayloadTypes{ "supportedPayloadTypes" };
static const Json::StaticString JsonStringRtpStream{ "rtpStream" };
static const Json::StaticString JsonStringSupportedCodecPayloadTypes{ "supportedCodecPayloadTypes" };
static const Json::StaticString JsonStringPaused{ "paused" };
Json::Value json(Json::objectValue);
......@@ -68,24 +68,24 @@ namespace RTC
json[JsonStringKind] = RTC::Media::GetJsonString(this->kind);
json[JsonStringSourceProducerId] = Json::UInt{ this->sourceProducerId };
if (this->rtpParameters != nullptr)
json[JsonStringRtpParameters] = this->rtpParameters->ToJson();
else
json[JsonStringRtpParameters] = Json::nullValue;
json[JsonStringHasTransport] = this->transport != nullptr;
json[JsonStringEnabled] = this->GetEnabled();
if (this->rtpStream != nullptr)
json[JsonStringRtpStream] = this->rtpStream->ToJson();
json[JsonStringSupportedPayloadTypes] = Json::arrayValue;
json[JsonStringSupportedCodecPayloadTypes] = Json::arrayValue;
for (auto payloadType : this->supportedPayloadTypes)
for (auto payloadType : this->supportedCodecPayloadTypes)
{
json[JsonStringSupportedPayloadTypes].append(Json::UInt{ payloadType });
json[JsonStringSupportedCodecPayloadTypes].append(Json::UInt{ payloadType });
}
if (this->rtpStream != nullptr)
json[JsonStringRtpStream] = this->rtpStream->ToJson();
json[JsonStringPaused] = this->paused;
return json;
}
......@@ -105,6 +105,49 @@ namespace RTC
break;
}
case Channel::Request::MethodId::CONSUMER_SEND:
{
static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" };
if (!request->data[JsonStringRtpParameters].isObject())
{
request->Reject("missing data.rtpParameters");
return;
}
if (this->rtpParameters)
{
request->Reject("Consumer already has RTP parameters");
return;
}
try
{
// NOTE: This may throw.
this->rtpParameters = new RTC::RtpParameters(request->data[JsonStringRtpParameters]);
for (auto& listener : this->listeners)
{
listener->OnConsumerRtpParameters(this);
}
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
// Create RtpStreamSend instance.
CreateRtpStream(this->rtpParameters->encodings[0]);
request->Accept();
break;
}
case Channel::Request::MethodId::CONSUMER_PAUSE:
{
this->paused = true;
......@@ -142,39 +185,11 @@ namespace RTC
}
}
void Consumer::Send(RTC::RtpParameters* rtpParameters)
{
MS_TRACE();
MS_ASSERT(rtpParameters, "no RTP parameters given");
// Free the previous RTP parameters.
if (this->rtpParameters)
delete this->rtpParameters;
// Delete previous RtpStreamSend (if any).
if (this->rtpStream != nullptr)
{
delete this->rtpStream;
this->rtpStream = nullptr;
}
// Clone given RTP parameters so we manage our own parameters.
this->rtpParameters = new RTC::RtpParameters(rtpParameters);
// NOTE: We assume a single stream/encoding when sending to remote peers.
// TODO
// CreateRtpStream(encodings[0]);
}
void Consumer::SendRtpPacket(RTC::RtpPacket* packet)
{
MS_TRACE();
if (!this->GetEnabled())
return;
MS_ASSERT(this->rtpStream, "no RtpStream set");
MS_ASSERT(IsEnabled(), "Consumer not enabled");
// TODO: Must refactor for simulcast.
// Ignore the packet if the SSRC is not the single one in the sender
......@@ -188,14 +203,15 @@ namespace RTC
// Map the payload type.
uint8_t payloadType = packet->GetPayloadType();
auto it = this->supportedPayloadTypes.find(payloadType);
auto it = this->supportedCodecPayloadTypes.find(payloadType);
// NOTE: This may happen if this peer supports just some codecs from the
// given RtpParameters.
// TODO: We should just ignore those packets as they have non been negotiated.
if (it == this->supportedPayloadTypes.end())
if (it == this->supportedCodecPayloadTypes.end())
{
MS_DEBUG_TAG(rtp, "payload type not supported [payloadType:%" PRIu8 "]", payloadType);
MS_WARN_DEV(
"payload type not supported [payloadType:%" PRIu8 "]", payloadType);
return;
}
......@@ -213,8 +229,9 @@ namespace RTC
void Consumer::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now)
{
if (this->rtpStream == nullptr)
return;
MS_TRACE();
MS_ASSERT(IsEnabled(), "Consumer not enabled");
if (static_cast<float>((now - this->lastRtcpSentTime) * 1.15) < this->maxRtcpInterval)
return;
......@@ -245,12 +262,7 @@ namespace RTC
{
MS_TRACE();
if (this->rtpStream == nullptr)
{
MS_WARN_TAG(rtp, "no RtpStreamSend");
return;
}
MS_ASSERT(IsEnabled(), "Consumer not enabled");
for (auto it = nackPacket->Begin(); it != nackPacket->End(); ++it)
{
......@@ -276,12 +288,7 @@ namespace RTC
{
MS_TRACE();
if (this->rtpStream == nullptr)
{
MS_WARN_TAG(rtp, "no RtpStreamSend");
return;
}
MS_ASSERT(IsEnabled(), "Consumer not enabled");
this->rtpStream->ReceiveRtcpReceiverReport(report);
}
......@@ -290,6 +297,8 @@ namespace RTC
{
MS_TRACE();
MS_ASSERT(IsEnabled(), "Consumer not enabled");
for (auto& listener : this->listeners)
{
listener->OnConsumerFullFrameRequired(this);
......@@ -350,12 +359,9 @@ namespace RTC
{
MS_TRACE();
if (!this->GetEnabled())
return;
MS_ASSERT(this->rtpStream, "no RtpStream set");
MS_ASSERT(IsEnabled(), "Consumer not enabled");
RTC::RtpPacket* rtxPacket = { nullptr };
RTC::RtpPacket* rtxPacket{ nullptr };
if (this->rtpStream->HasRtx())
{
......
......@@ -30,7 +30,14 @@ namespace RTC
delete this->rtpParameters;
ClearRtpStreams();
for (auto& kv : this->rtpStreams)
{
auto rtpStream = kv.second;
delete rtpStream;
}
this->rtpStreams.clear();
}
void Producer::Destroy()
......@@ -53,11 +60,12 @@ namespace RTC
static const Json::StaticString JsonStringProducerId{ "producerId" };
static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" };
static const Json::StaticString JsonStringRtpStreams{ "rtpStreams" };
static const Json::StaticString JsonStringSsrcAudioLevelId{ "ssrcAudioLevelId" };
static const Json::StaticString JsonStringAbsSendTimeId{ "absSendTimeId" };
static const Json::StaticString JsonStringPaused{ "paused" };
static const Json::StaticString JsonStringRtpRawEventEnabled{ "rtpRawEventEnabled" };
static const Json::StaticString JsonStringRtpObjectEventEnabled{ "rtpObjectEventEnabled" };
static const Json::StaticString JsonStringRtpStreams{ "rtpStreams" };
Json::Value json(Json::objectValue);
Json::Value jsonRtpStreams(Json::arrayValue);
......@@ -71,24 +79,26 @@ namespace RTC
else
json[JsonStringRtpParameters] = Json::nullValue;
for (auto& kv : this->rtpStreams)
{
auto rtpStream = kv.second;
jsonRtpStreams.append(rtpStream->ToJson());
}
json[JsonStringRtpStreams] = jsonRtpStreams;
if (this->knownHeaderExtensions.ssrcAudioLevelId)
json[JsonStringSsrcAudioLevelId] = this->knownHeaderExtensions.ssrcAudioLevelId;
if (this->knownHeaderExtensions.absSendTimeId)
json[JsonStringAbsSendTimeId] = this->knownHeaderExtensions.absSendTimeId;
json[JsonStringPaused] = this->paused;
json[JsonStringRtpRawEventEnabled] = this->rtpRawEventEnabled;
json[JsonStringRtpObjectEventEnabled] = this->rtpObjectEventEnabled;
for (auto& kv : this->rtpStreams)
{
auto rtpStream = kv.second;
jsonRtpStreams.append(rtpStream->ToJson());
}
json[JsonStringRtpStreams] = jsonRtpStreams;
return json;
}
......@@ -250,6 +260,8 @@ namespace RTC
{
MS_TRACE();
MS_ASSERT(IsEnabled(), "Producer not enabled");
static const Json::StaticString JsonStringObject{ "object" };
static const Json::StaticString JsonStringPayloadType{ "payloadType" };
static const Json::StaticString JsonStringMarker{ "marker" };
......@@ -344,6 +356,8 @@ namespace RTC
{
MS_TRACE();
MS_ASSERT(IsEnabled(), "Producer not enabled");
if (this->transport == nullptr)
return;
......@@ -363,6 +377,8 @@ namespace RTC
{
MS_TRACE();
MS_ASSERT(IsEnabled(), "Producer not enabled");
if (this->transport == nullptr)
return;
......@@ -382,6 +398,8 @@ namespace RTC
{
MS_TRACE();
MS_ASSERT(IsEnabled(), "Producer not enabled");
for (auto& kv : this->rtpStreams)
{
auto rtpStream = kv.second;
......@@ -532,22 +550,45 @@ namespace RTC
}
}
void Producer::ClearRtpStreams()
void Producer::ApplyRtpMapping(RTC::RtpPacket* packet)
{
MS_TRACE();
for (auto& kv : this->rtpStreams)
auto& codecPayloadTypeMap = this->rtpMapping.codecPayloadTypes;
auto& headerExtensionIdMap = this->rtpMapping.headerExtensionIds;
auto payloadType = packet->GetPayloadType();
// Mangle payload type.
if (codecPayloadTypeMap.find(payloadType) != codecPayloadTypeMap.end())
{
auto rtpStream = kv.second;
packet->SetPayloadType(codecPayloadTypeMap[payloadType]);
}
delete rtpStream;
// Mangle header extension ids.
packet->MangleExtensionHeaderIds(headerExtensionIdMap);
if (this->knownHeaderExtensions.ssrcAudioLevelId)
{
packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL,
this->knownHeaderExtensions.ssrcAudioLevelId);
}
this->rtpStreams.clear();
if (this->knownHeaderExtensions.absSendTimeId)
{
packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::ABS_SEND_TIME, this->knownHeaderExtensions.absSendTimeId);
}
}
void Producer::OnNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers)
{
MS_TRACE();
MS_ASSERT(IsEnabled(), "Producer not enabled");
if (this->transport == nullptr)
return;
......@@ -597,9 +638,9 @@ namespace RTC
void Producer::OnPliRequired(RTC::RtpStreamRecv* rtpStream)
{
// TODO: Can this happen?
if (this->transport == nullptr)
return;
MS_TRACE();
MS_ASSERT(IsEnabled(), "Producer not enabled");
RTC::RTCP::FeedbackPsPliPacket packet(0, rtpStream->GetSsrc());
......@@ -609,37 +650,4 @@ namespace RTC
this->transport->SendRtcpPacket(&packet);
this->transport->SendRtcpPacket(&packet);
}
void Producer::ApplyRtpMapping(RTC::RtpPacket* packet)
{
MS_TRACE();
auto& codecPayloadTypeMap = this->rtpMapping.codecPayloadTypes;
auto& headerExtensionIdMap = this->rtpMapping.headerExtensionIds;
auto payloadType = packet->GetPayloadType();
// Mangle payload type.
if (codecPayloadTypeMap.find(payloadType) != codecPayloadTypeMap.end())
{
packet->SetPayloadType(codecPayloadTypeMap[payloadType]);
}
// Mangle header extension ids.
packet->MangleExtensionHeaderIds(headerExtensionIdMap);
if (this->knownHeaderExtensions.ssrcAudioLevelId)
{
packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL,
this->knownHeaderExtensions.ssrcAudioLevelId);
}
if (this->knownHeaderExtensions.absSendTimeId)
{
packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::ABS_SEND_TIME, this->knownHeaderExtensions.absSendTimeId);
}
}
} // namespace RTC
......@@ -5,6 +5,7 @@
#include "Logger.hpp"
#include "MediaSoupError.hpp"
#include "Utils.hpp"
#include "RTC/RtpDictionaries.hpp"
#include <cmath> // std::lround()
#include <set>
#include <string>
......@@ -263,15 +264,13 @@ namespace RTC
if (!request->data[JsonStringKind].isString())
MS_THROW_ERROR("missing kind");
std::string kind = request->data[JsonStringKind].asString();
std::string kindStr = request->data[JsonStringKind].asString();
auto kind = RTC::Media::GetKind(kindStr);
// Create a Producer instance.
try
{
producer = new RTC::Producer(this->notifier, producerId, RTC::Media::GetKind(kind), transport);
// Add us as listener.
producer->AddListener(this);
producer = new RTC::Producer(this->notifier, producerId, kind, transport);
}
catch (const MediaSoupError& error)
{
......@@ -280,6 +279,9 @@ namespace RTC
return;
}
// Add us as listener.
producer->AddListener(this);
// Tell the Transport to handle the new Producer.
try
{
......@@ -306,7 +308,106 @@ namespace RTC
case Channel::Request::MethodId::ROUTER_CREATE_CONSUMER:
{
// TODO
static const Json::StaticString JsonStringKind{ "kind" };
RTC::Consumer* consumer;
RTC::Transport* transport;
RTC::Producer* producer;
uint32_t consumerId;
try
{
consumer = GetConsumerFromRequest(request, &consumerId);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (consumer != nullptr)
{
request->Reject("Consumer already exists");
return;
}
try
{
transport = GetTransportFromRequest(request);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (transport == nullptr)
{
request->Reject("Transport does not exist");
return;
}
try
{
producer = GetProducerFromRequest(request);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (producer == nullptr)
{
request->Reject("Producer does not exist");
return;
}
else if (!producer->GetParameters())
{
request->Reject("Producer has no parameters");
return;
}
// kind is mandatory.
if (!request->data[JsonStringKind].isString())
MS_THROW_ERROR("missing kind");
std::string kindStr = request->data[JsonStringKind].asString();
auto kind = RTC::Media::GetKind(kindStr);
if (kind != producer->kind)
MS_THROW_ERROR("not matching kind");
// Create a Consumer instance.
try
{
consumer = new RTC::Consumer(this->notifier, consumerId, kind, producer->producerId, transport);
// Add us as listener.
consumer->AddListener(this);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
// Tell the Transport to handle the new Consumer.
transport->HandleConsumer(consumer);
this->consumers[consumerId] = consumer;
MS_DEBUG_DEV("Consumer created [consumerId:%" PRIu32 "]", consumerId);
request->Accept();
break;
}
......@@ -490,6 +591,7 @@ namespace RTC
}
case Channel::Request::MethodId::CONSUMER_DUMP:
case Channel::Request::MethodId::CONSUMER_SEND:
case Channel::Request::MethodId::CONSUMER_PAUSE:
case Channel::Request::MethodId::CONSUMER_RESUME:
{
......@@ -658,7 +760,7 @@ namespace RTC
MS_ASSERT(
this->mapProducerConsumers.find(producer) != this->mapProducerConsumers.end(),
"Producer not present in the map");
"Producer not present in mapProducerConsumers");
auto& consumers = this->mapProducerConsumers[producer];
......@@ -715,6 +817,19 @@ namespace RTC
MS_ASSERT(consumer->GetParameters(), "Consumer has no parameters");
// TODO: Fill the mapConsumerProducer, so we need the associated Producer id.
auto producerId = consumer->sourceProducerId;
MS_ASSERT(this->producers.find(producerId) != this->producers.end(), "Producer not found");
auto* producer = this->producers[producerId];
MS_ASSERT(
this->mapProducerConsumers.find(producer) != this->mapProducerConsumers.end(),
"Producer not present in mapProducerConsumers");
this->mapProducerConsumers[producer].insert(consumer);
this->mapConsumerProducer[consumer] = producer;
}
void Router::OnConsumerFullFrameRequired(RTC::Consumer* consumer)
......@@ -723,7 +838,7 @@ namespace RTC
MS_ASSERT(
this->mapConsumerProducer.find(consumer) != this->mapConsumerProducer.end(),
"Consumer not present in the map");
"Consumer not present in mapConsumerProducer");
auto& producer = this->mapConsumerProducer[consumer];
......
......@@ -20,7 +20,7 @@ namespace RTC
static const Json::StaticString JsonStringHeaderExtensions{ "headerExtensions" };
static const Json::StaticString JsonStringRtcp{ "rtcp" };
// `muxId` is optional.
// muxId is optional.
if (data[JsonStringMuxId].isString())
{
this->muxId = data[JsonStringMuxId].asString();
......@@ -29,7 +29,7 @@ namespace RTC
MS_THROW_ERROR("empty rtpParameters.muxId");
}
// `codecs` is mandatory.
// codecs is mandatory.
if (!data[JsonStringCodecs].isArray())
MS_THROW_ERROR("missing rtpParameters.codecs");
......@@ -46,7 +46,7 @@ namespace RTC
this->codecs.push_back(codec);
}
// `encodings` is mandatory.
// encodings is mandatory.
if (!data[JsonStringEncodings].isArray())
MS_THROW_ERROR("missing rtpParameters.encodings");
......@@ -63,7 +63,7 @@ namespace RTC
this->encodings.push_back(encoding);
}
// `headerExtensions` is optional.
// headerExtensions is optional.
if (data[JsonStringHeaderExtensions].isArray())
{
auto& jsonArray = data[JsonStringHeaderExtensions];
......@@ -78,7 +78,7 @@ namespace RTC
}
}
// `rtcp` is optional.
// rtcp is optional.
if (data[JsonStringRtcp].isObject())
{
this->rtcp = RTC::RtcpParameters(data[JsonStringRtcp]);
......@@ -110,11 +110,11 @@ namespace RTC
Json::Value json(Json::objectValue);
// Add `muxId`.
// Add muxId.
if (!this->muxId.empty())
json[JsonStringMuxId] = this->muxId;
// Add `codecs`.
// Add codecs.
json[JsonStringCodecs] = Json::arrayValue;
for (auto& entry : this->codecs)
......@@ -122,7 +122,7 @@ namespace RTC
json[JsonStringCodecs].append(entry.ToJson());
}
// Add `encodings`.
// Add encodings.
json[JsonStringEncodings] = Json::arrayValue;
for (auto& entry : this->encodings)
......@@ -130,7 +130,7 @@ namespace RTC
json[JsonStringEncodings].append(entry.ToJson());
}
// Add `headerExtensions`.
// Add headerExtensions.
json[JsonStringHeaderExtensions] = Json::arrayValue;
for (auto& entry : this->headerExtensions)
......@@ -138,7 +138,7 @@ namespace RTC
json[JsonStringHeaderExtensions].append(entry.ToJson());
}
// Add `rtcp`.
// Add rtcp.
if (this->hasRtcp)
json[JsonStringRtcp] = this->rtcp.ToJson();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论