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

producer.pause/resume() works!

上级 93eea21f
# TODO in mediasoup v2 (server-side) # TODO in mediasoup v2 (server-side)
* If the Producer is paused, should we pass the packet to the BWE?
* Before the Producer dispacthes a RTP packet to the room (via `onRtpPacket()`, we call `ApplyRtpMapping(packet)` to mangle RTP payload type and header extension ids. However, we are breaking the previously established Id mapping in the `RtpPacket` (generated via `packet->AddExtensionMapping()`). The fact is that, most probably, we should set the mapping once the `RtpStreamRecv` processes the packet. The problem is that, currently, the information to set the mapping is hold into the `RtpStreamRecv`...
* May be problems with `RtpPacket` RTX stuff due to RTP mapping in Producers? Sure, the decoded RTX packet must also be mapped (once decoded).
* Use "@xxxxx" for private events and `safeEmit("xxxx")` for public events (already done except for Producer and Consumer). * Use "@xxxxx" for private events and `safeEmit("xxxx")` for public events (already done except for Producer and Consumer).
......
...@@ -403,6 +403,27 @@ class Peer extends EnhancedEventEmitter ...@@ -403,6 +403,27 @@ class Peer extends EnhancedEventEmitter
}); });
} }
case 'restartTransport':
{
const { id } = request;
const transport = this._transports.get(id);
if (!transport)
throw new Error('Transport not found');
return transport.changeUfragPwd()
.then(() =>
{
const response =
{
iceParameters : transport.iceLocalParameters
};
return response;
});
}
case 'createProducer': case 'createProducer':
{ {
const { const {
...@@ -415,9 +436,8 @@ class Peer extends EnhancedEventEmitter ...@@ -415,9 +436,8 @@ class Peer extends EnhancedEventEmitter
} = request; } = request;
// NOTE: This may throw. // NOTE: This may throw.
const { adaptedRtpParameters, rtpMapping } = const rtpMapping =
this._sandbox.adaptProducerRtpParametersToRtpCapabilities( this._sandbox.getProducerRtpParametersMapping(rtpParameters);
rtpParameters);
return this._createProducer(id, kind, transportId) return this._createProducer(id, kind, transportId)
.then((producer) => .then((producer) =>
...@@ -427,8 +447,7 @@ class Peer extends EnhancedEventEmitter ...@@ -427,8 +447,7 @@ class Peer extends EnhancedEventEmitter
if (paused) if (paused)
producer.remotePause(); producer.remotePause();
return producer.receive( return producer.receive(rtpParameters, rtpMapping)
rtpParameters, adaptedRtpParameters, rtpMapping)
.catch((error) => .catch((error) =>
{ {
producer.close(); producer.close();
...@@ -579,7 +598,7 @@ class Peer extends EnhancedEventEmitter ...@@ -579,7 +598,7 @@ class Peer extends EnhancedEventEmitter
_createTransport(id, options) _createTransport(id, options)
{ {
logger.debug('_createTransport()'); logger.debug('_createTransport() [id:%s]', id);
const internal = const internal =
{ {
...@@ -619,7 +638,7 @@ class Peer extends EnhancedEventEmitter ...@@ -619,7 +638,7 @@ class Peer extends EnhancedEventEmitter
_createProducer(id, kind, transportId) _createProducer(id, kind, transportId)
{ {
logger.debug('_createProducer()'); logger.debug('_createProducer() [id:%s, kind:%s]', id, kind);
if (!this.rtpCapabilities) if (!this.rtpCapabilities)
return Promise.reject(new errors.InvalidStateError('RTP capabilities unset')); return Promise.reject(new errors.InvalidStateError('RTP capabilities unset'));
......
...@@ -28,7 +28,6 @@ class Producer extends EnhancedEventEmitter ...@@ -28,7 +28,6 @@ class Producer extends EnhancedEventEmitter
// - .kind // - .kind
// - .transport // - .transport
// - .rtpParameters // - .rtpParameters
// - .adaptedRtpParameters
// - .rtpMapping // - .rtpMapping
this._data = data; this._data = data;
...@@ -197,11 +196,6 @@ class Producer extends EnhancedEventEmitter ...@@ -197,11 +196,6 @@ class Producer extends EnhancedEventEmitter
return this._data.rtpParameters; return this._data.rtpParameters;
} }
get adaptedRtpParameters()
{
return this._data.adaptedRtpParameters;
}
get rtpMapping() get rtpMapping()
{ {
return this._data.rtpMapping; return this._data.rtpMapping;
...@@ -336,13 +330,11 @@ class Producer extends EnhancedEventEmitter ...@@ -336,13 +330,11 @@ class Producer extends EnhancedEventEmitter
* Start receiving media from the remote Producer. * Start receiving media from the remote Producer.
* *
* @param {RTCRtpParameters} rtpParameters - Receiving RTP parameters. * @param {RTCRtpParameters} rtpParameters - Receiving RTP parameters.
* @param {RTCRtpParameters} adaptedRtpParameters - RTP parameters adapted to the
* room RTP capabilities.
* @param {Object} rtpMapping. * @param {Object} rtpMapping.
* *
* @return {Promise} Resolves to this. * @return {Promise} Resolves to this.
*/ */
receive(rtpParameters, adaptedRtpParameters, rtpMapping) receive(rtpParameters, rtpMapping)
{ {
logger.debug('receive()'); logger.debug('receive()');
...@@ -362,7 +354,6 @@ class Producer extends EnhancedEventEmitter ...@@ -362,7 +354,6 @@ class Producer extends EnhancedEventEmitter
logger.debug('"producer.receive" request succeeded'); logger.debug('"producer.receive" request succeeded');
this._data.rtpParameters = rtpParameters; this._data.rtpParameters = rtpParameters;
this._data.adaptedRtpParameters = adaptedRtpParameters;
this._data.rtpMapping = rtpMapping; this._data.rtpMapping = rtpMapping;
return this; return this;
......
...@@ -371,9 +371,9 @@ class Room extends EnhancedEventEmitter ...@@ -371,9 +371,9 @@ class Room extends EnhancedEventEmitter
}, },
// NOTE: This may throw. // NOTE: This may throw.
adaptProducerRtpParametersToRtpCapabilities : (rtpParameters) => getProducerRtpParametersMapping : (rtpParameters) =>
{ {
return ortc.adaptProducerRtpParametersToRtpCapabilities( return ortc.getProducerRtpParametersMapping(
rtpParameters, this.rtpCapabilities); rtpParameters, this.rtpCapabilities);
} }
}; };
......
'use strict'; 'use strict';
const utils = require('./utils');
const supportedRtpCapabilities = require('./supportedRtpCapabilities'); const supportedRtpCapabilities = require('./supportedRtpCapabilities');
const DYNAMIC_PAYLOAD_TYPES = const DYNAMIC_PAYLOAD_TYPES =
...@@ -163,12 +162,12 @@ exports.assertCapabilitiesSubset = function(capsA, capsB) ...@@ -163,12 +162,12 @@ exports.assertCapabilitiesSubset = function(capsA, capsB)
* @param {RTCRtpCapabilities} caps * @param {RTCRtpCapabilities} caps
* *
* @return {Object} * @return {Object}
*
* TODO: This method should also reduce encodings in case of simulcast/SVC
* so the resulting consumableRtpParameters are suitable for a Consumer.
*/ */
exports.adaptProducerRtpParametersToRtpCapabilities = function(params, caps) exports.getProducerRtpParametersMapping = function(params, caps)
{ {
// Clone given parameters.
params = utils.cloneObject(params);
const codecToCapCodec = new Map(); const codecToCapCodec = new Map();
// Match parameters media codecs to capabilities media codecs. // Match parameters media codecs to capabilities media codecs.
...@@ -191,8 +190,6 @@ exports.adaptProducerRtpParametersToRtpCapabilities = function(params, caps) ...@@ -191,8 +190,6 @@ exports.adaptProducerRtpParametersToRtpCapabilities = function(params, caps)
codecToCapCodec.set(codec, matchedCapCodec); codecToCapCodec.set(codec, matchedCapCodec);
} }
const aptToCapApt = {};
// Match parameters RTX codecs to capabilities RTX codecs. // Match parameters RTX codecs to capabilities RTX codecs.
for (const codec of params.codecs) for (const codec of params.codecs)
{ {
...@@ -228,22 +225,17 @@ exports.adaptProducerRtpParametersToRtpCapabilities = function(params, caps) ...@@ -228,22 +225,17 @@ exports.adaptProducerRtpParametersToRtpCapabilities = function(params, caps)
`[capabilities codec PT:${capMediaCodec.preferredPayloadType}]`); `[capabilities codec PT:${capMediaCodec.preferredPayloadType}]`);
} }
aptToCapApt[codec.parameters.apt] = associatedCapRtxCodec.parameters.apt;
codecToCapCodec.set(codec, associatedCapRtxCodec); codecToCapCodec.set(codec, associatedCapRtxCodec);
} }
const codecPayloadTypeMapping = new Map(); const mapCodecPayloadTypes = new Map();
for (const [ codec, capCodec ] of codecToCapCodec) for (const [ codec, capCodec ] of codecToCapCodec)
{ {
codecPayloadTypeMapping.set(codec.payloadType, capCodec.preferredPayloadType); mapCodecPayloadTypes.set(codec.payloadType, capCodec.preferredPayloadType);
codec.payloadType = capCodec.preferredPayloadType;
if (codec.name.toLowerCase() === 'rtx')
codec.parameters.apt = aptToCapApt[codec.parameters.apt];
} }
const headerExtensionIdMapping = new Map(); const mapHeaderExtensionIds = new Map();
for (const ext of params.headerExtensions) for (const ext of params.headerExtensions)
{ {
...@@ -256,17 +248,12 @@ exports.adaptProducerRtpParametersToRtpCapabilities = function(params, caps) ...@@ -256,17 +248,12 @@ exports.adaptProducerRtpParametersToRtpCapabilities = function(params, caps)
`unsupported header extensions [uri:"${ext.uri}", id:${ext.id}]`); `unsupported header extensions [uri:"${ext.uri}", id:${ext.id}]`);
} }
headerExtensionIdMapping.set(ext.id, matchedCapExt.preferredId); mapHeaderExtensionIds.set(ext.id, matchedCapExt.preferredId);
ext.id = matchedCapExt.preferredId;
} }
return { return {
adaptedRtpParameters : params, codecPayloadTypes : Array.from(mapCodecPayloadTypes),
rtpMapping : headerExtensionIds : Array.from(mapHeaderExtensionIds)
{
codecPayloadTypes : Array.from(codecPayloadTypeMapping),
headerExtensionIds : Array.from(headerExtensionIdMapping)
}
}; };
}; };
......
...@@ -37,6 +37,8 @@ namespace Channel ...@@ -37,6 +37,8 @@ namespace Channel
PRODUCER_CLOSE, PRODUCER_CLOSE,
PRODUCER_DUMP, PRODUCER_DUMP,
PRODUCER_RECEIVE, PRODUCER_RECEIVE,
PRODUCER_PAUSE,
PRODUCER_RESUME,
PRODUCER_SET_RTP_RAW_EVENT, PRODUCER_SET_RTP_RAW_EVENT,
PRODUCER_SET_RTP_OBJECT_EVENT, PRODUCER_SET_RTP_OBJECT_EVENT,
CONSUMER_DUMP, CONSUMER_DUMP,
......
...@@ -94,6 +94,7 @@ namespace RTC ...@@ -94,6 +94,7 @@ namespace RTC
RTC::RtpParameters* rtpParameters{ nullptr }; RTC::RtpParameters* rtpParameters{ nullptr };
std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams; std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams;
std::map<uint32_t, RTC::RtpStreamRecv*> rtxStreamMap; std::map<uint32_t, RTC::RtpStreamRecv*> rtxStreamMap;
bool paused{ false };
// Others. // Others.
struct RtpMapping rtpMapping; struct RtpMapping rtpMapping;
struct KnownHeaderExtensions knownHeaderExtensions; struct KnownHeaderExtensions knownHeaderExtensions;
......
...@@ -32,6 +32,8 @@ namespace Channel ...@@ -32,6 +32,8 @@ namespace Channel
{ "producer.close", Request::MethodId::PRODUCER_CLOSE }, { "producer.close", Request::MethodId::PRODUCER_CLOSE },
{ "producer.dump", Request::MethodId::PRODUCER_DUMP }, { "producer.dump", Request::MethodId::PRODUCER_DUMP },
{ "producer.receive", Request::MethodId::PRODUCER_RECEIVE }, { "producer.receive", Request::MethodId::PRODUCER_RECEIVE },
{ "producer.pause", Request::MethodId::PRODUCER_PAUSE },
{ "producer.resume" , Request::MethodId::PRODUCER_RESUME },
{ "producer.setRtpRawEvent", Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT }, { "producer.setRtpRawEvent", Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT },
{ "producer.setRtpObjectEvent", Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT }, { "producer.setRtpObjectEvent", Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT },
{ "consumer.dump", Request::MethodId::CONSUMER_DUMP }, { "consumer.dump", Request::MethodId::CONSUMER_DUMP },
......
...@@ -225,6 +225,8 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req ...@@ -225,6 +225,8 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req
case Channel::Request::MethodId::PRODUCER_CLOSE: case Channel::Request::MethodId::PRODUCER_CLOSE:
case Channel::Request::MethodId::PRODUCER_DUMP: case Channel::Request::MethodId::PRODUCER_DUMP:
case Channel::Request::MethodId::PRODUCER_RECEIVE: case Channel::Request::MethodId::PRODUCER_RECEIVE:
case Channel::Request::MethodId::PRODUCER_PAUSE:
case Channel::Request::MethodId::PRODUCER_RESUME:
case Channel::Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT: case Channel::Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT:
case Channel::Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT: case Channel::Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT:
case Channel::Request::MethodId::CONSUMER_DUMP: case Channel::Request::MethodId::CONSUMER_DUMP:
......
...@@ -316,6 +316,8 @@ namespace RTC ...@@ -316,6 +316,8 @@ namespace RTC
case Channel::Request::MethodId::PRODUCER_CLOSE: case Channel::Request::MethodId::PRODUCER_CLOSE:
case Channel::Request::MethodId::PRODUCER_DUMP: case Channel::Request::MethodId::PRODUCER_DUMP:
case Channel::Request::MethodId::PRODUCER_RECEIVE: case Channel::Request::MethodId::PRODUCER_RECEIVE:
case Channel::Request::MethodId::PRODUCER_PAUSE:
case Channel::Request::MethodId::PRODUCER_RESUME:
case Channel::Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT: case Channel::Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT:
case Channel::Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT: case Channel::Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT:
{ {
...@@ -737,12 +739,6 @@ namespace RTC ...@@ -737,12 +739,6 @@ namespace RTC
MS_ASSERT(producer->GetParameters(), "Producer has no parameters"); MS_ASSERT(producer->GetParameters(), "Producer has no parameters");
auto transport = producer->GetTransport();
// NOTE: This may throw.
if (transport != nullptr)
transport->AddProducer(producer);
this->listener->OnPeerProducerRtpParameters(this, producer); this->listener->OnPeerProducerRtpParameters(this, producer);
} }
......
...@@ -159,13 +159,19 @@ namespace RTC ...@@ -159,13 +159,19 @@ namespace RTC
try try
{ {
// This may throw. // NOTE: This may throw.
this->rtpParameters = new RTC::RtpParameters(request->data[JsonStringRtpParameters]); this->rtpParameters = new RTC::RtpParameters(request->data[JsonStringRtpParameters]);
// This may throw. auto transport = GetTransport();
// NOTE: This may throw.
if (transport != nullptr)
transport->AddProducer(this);
// NOTE: This may throw.
CreateRtpMapping(request->data[JsonStringRtpMapping]); CreateRtpMapping(request->data[JsonStringRtpMapping]);
// This may throw. // NOTE: This may throw.
this->listener->OnProducerRtpParameters(this); this->listener->OnProducerRtpParameters(this);
} }
catch (const MediaSoupError& error) catch (const MediaSoupError& error)
...@@ -192,6 +198,29 @@ namespace RTC ...@@ -192,6 +198,29 @@ namespace RTC
break; break;
} }
case Channel::Request::MethodId::PRODUCER_PAUSE:
{
this->paused = true;
request->Accept();
break;
}
case Channel::Request::MethodId::PRODUCER_RESUME:
{
bool wasPaused = this->paused;
this->paused = false;
request->Accept();
if (wasPaused)
RequestFullFrame();
break;
}
case Channel::Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT: case Channel::Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT:
{ {
static const Json::StaticString JsonStringEnabled{ "enabled" }; static const Json::StaticString JsonStringEnabled{ "enabled" };
...@@ -209,7 +238,7 @@ namespace RTC ...@@ -209,7 +238,7 @@ namespace RTC
// If set, require a full frame. // If set, require a full frame.
if (this->rtpRawEventEnabled) if (this->rtpRawEventEnabled)
this->RequestFullFrame(); RequestFullFrame();
break; break;
} }
...@@ -231,7 +260,7 @@ namespace RTC ...@@ -231,7 +260,7 @@ namespace RTC
// If set, require a full frame. // If set, require a full frame.
if (this->rtpObjectEventEnabled) if (this->rtpObjectEventEnabled)
this->RequestFullFrame(); RequestFullFrame();
break; break;
} }
...@@ -257,8 +286,6 @@ namespace RTC ...@@ -257,8 +286,6 @@ namespace RTC
static const Json::StaticString JsonStringTimestamp{ "timestamp" }; static const Json::StaticString JsonStringTimestamp{ "timestamp" };
static const Json::StaticString JsonStringSsrc{ "ssrc" }; static const Json::StaticString JsonStringSsrc{ "ssrc" };
// TODO: Check if paused, etc (not yet done).
// Find the corresponding RtpStreamRecv. // Find the corresponding RtpStreamRecv.
uint32_t ssrc = packet->GetSsrc(); uint32_t ssrc = packet->GetSsrc();
...@@ -287,11 +314,9 @@ namespace RTC ...@@ -287,11 +314,9 @@ namespace RTC
return; return;
} }
// Apply the Producer RTP mapping before dispatching the packet to the Room. // If paused stop here.
ApplyRtpMapping(packet); if (this->paused)
return;
// Notify the listener.
this->listener->OnRtpPacket(this, packet);
// Emit "rtpraw" if enabled. // Emit "rtpraw" if enabled.
if (this->rtpRawEventEnabled) if (this->rtpRawEventEnabled)
...@@ -323,6 +348,12 @@ namespace RTC ...@@ -323,6 +348,12 @@ namespace RTC
this->notifier->EmitWithBinary( this->notifier->EmitWithBinary(
this->producerId, "rtpobject", eventData, packet->GetPayload(), packet->GetPayloadLength()); this->producerId, "rtpobject", eventData, packet->GetPayload(), packet->GetPayloadLength());
} }
// Apply the Producer RTP mapping before dispatching the packet to the Room.
ApplyRtpMapping(packet);
// Notify the listener.
this->listener->OnRtpPacket(this, packet);
} }
void Producer::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) void Producer::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now)
......
...@@ -254,6 +254,8 @@ namespace RTC ...@@ -254,6 +254,8 @@ namespace RTC
case Channel::Request::MethodId::PRODUCER_CLOSE: case Channel::Request::MethodId::PRODUCER_CLOSE:
case Channel::Request::MethodId::PRODUCER_DUMP: case Channel::Request::MethodId::PRODUCER_DUMP:
case Channel::Request::MethodId::PRODUCER_RECEIVE: case Channel::Request::MethodId::PRODUCER_RECEIVE:
case Channel::Request::MethodId::PRODUCER_PAUSE:
case Channel::Request::MethodId::PRODUCER_RESUME:
case Channel::Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT: case Channel::Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT:
case Channel::Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT: case Channel::Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT:
case Channel::Request::MethodId::CONSUMER_DUMP: case Channel::Request::MethodId::CONSUMER_DUMP:
......
...@@ -885,6 +885,9 @@ namespace RTC ...@@ -885,6 +885,9 @@ namespace RTC
// Pass the RTP packet to the corresponding Producer. // Pass the RTP packet to the corresponding Producer.
producer->ReceiveRtpPacket(packet); producer->ReceiveRtpPacket(packet);
// TODO: If the Producer is paused, should we pass the packet to the
// BWE?
// Feed the remote bitrate estimator (REMB). // Feed the remote bitrate estimator (REMB).
if (this->remoteBitrateEstimator) if (this->remoteBitrateEstimator)
{ {
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论