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

It works. Some details (and all the RTCP) missing.

上级 d5dfd661
# TODO in mediasoup v2 (server-side) # TODO in mediasoup v2 (server-side)
* Revisar appData en todos los mensajes. * When a Peer disconnect, others receive `peerClosed` and later `consumerClosed` for each Consumer associated to the closed Peer, so the client side complains ("peer not found"). We should avoid sending `consumerClosed` if its Peer left.
* Revisar que si un Producer JS empieza pausado, esté tb pausado en el worker y en el Consumer JS asociado. Y que si un Consumer JS se habilita pausado, que se entere tb el Consumer del worker.
- Y que si un Producer se pausa (y, por lo tanto, sus Consumers están "sourcePaused") al hacer `enable()` en esos Consumers se le diga al cliente que están pausados.
* Implement `consumer.sourcePause/Resume()`. * Revisar appData en todos los mensajes.
- No. This should be done in the Worker. When the Producer gets paused it should call `Router::OnProducerPaused()` so it calls `Consumer::SourcePause()` to all its Consumers, and each Consumer emits "paused/resumed".
* Remove DEPTH stuff. * Remove DEPTH stuff.
...@@ -19,9 +21,6 @@ ...@@ -19,9 +21,6 @@
+ I must avoid unnecesary `Promise.resolve()`. + I must avoid unnecesary `Promise.resolve()`.
- "The callback passed to a Promise constructor is always called synchronously, but the callbacks passed into then are always called asynchronously" - "The callback passed to a Promise constructor is always called synchronously, but the callbacks passed into then are always called asynchronously"
* worker: If a `Producer` is paused and a new `Peer` joins (so a new `Consumer` is generated) such a new `Consumer` does not know that its associated `Producer` is paused. When creating a `Consumer` the `Room` should check `producer->IsPaused()` and call `consumer->setSourcePaused(true)` or similar.
- NOTE: Won't happen with the new design since that's done in JS land.
* May have to react on DTLS ALERT CLOSE in the server and make it "really" close the Transport and notify the client. Bufff... I don't like this... * May have to react on DTLS ALERT CLOSE in the server and make it "really" close the Transport and notify the client. Bufff... I don't like this...
* Upon a `updateProducer` notification, map the new SSRCs of the `Producer` and send a PLI back to the browser (otherwise, consumers will get frozen video). * Upon a `updateProducer` notification, map the new SSRCs of the `Producer` and send a PLI back to the browser (otherwise, consumers will get frozen video).
......
...@@ -159,7 +159,13 @@ class Consumer extends EnhancedEventEmitter ...@@ -159,7 +159,13 @@ class Consumer extends EnhancedEventEmitter
this._closed = true; this._closed = true;
this.emit('@notify', 'consumerClosed', { id: this.id }); const data =
{
id : this.id,
peerName : this.peer.name
};
this.emit('@notify', 'consumerClosed', data);
this.emit('@close'); this.emit('@close');
this.safeEmit('close'); this.safeEmit('close');
...@@ -246,11 +252,10 @@ class Consumer extends EnhancedEventEmitter ...@@ -246,11 +252,10 @@ class Consumer extends EnhancedEventEmitter
else if (this.enabled) else if (this.enabled)
return Promise.reject(new errors.InvalidStateError('Consumer already enabled')); return Promise.reject(new errors.InvalidStateError('Consumer already enabled'));
const internal = Object.assign( const internal = Object.assign({}, this._internal,
{ {
transportId : transport.id transportId : transport.id
}, });
this._internal);
const data = Object.assign({ transport }, this._data); const data = Object.assign({ transport }, this._data);
...@@ -307,7 +312,16 @@ class Consumer extends EnhancedEventEmitter ...@@ -307,7 +312,16 @@ class Consumer extends EnhancedEventEmitter
} }
if (!this._sourcePaused) if (!this._sourcePaused)
this.emit('@notify', 'consumerPaused', { id: this.id, appData }); {
const data =
{
id : this.id,
peerName : this.peer.name,
appData : appData
};
this.emit('@notify', 'consumerPaused', data);
}
this._locallyPaused = true; this._locallyPaused = true;
...@@ -365,25 +379,6 @@ class Consumer extends EnhancedEventEmitter ...@@ -365,25 +379,6 @@ class Consumer extends EnhancedEventEmitter
this.safeEmit('pause', 'remote', appData); this.safeEmit('pause', 'remote', appData);
} }
/**
* The associated source (Producer) has been paused.
*
* @private
*
* @param {Any} [appData] - App custom data.
*/
sourcePause(appData)
{
logger.debug('sourcePause()');
if (this._closed || this._sourcePaused)
return;
this._sourcePaused = true;
// TODO
}
/** /**
* Resumes sending media. * Resumes sending media.
* *
...@@ -407,7 +402,16 @@ class Consumer extends EnhancedEventEmitter ...@@ -407,7 +402,16 @@ class Consumer extends EnhancedEventEmitter
} }
if (!this._sourcePaused) if (!this._sourcePaused)
this.emit('@notify', 'consumerResumed', { id: this.id, appData }); {
const data =
{
id : this.id,
peerName : this.peer.name,
appData : appData
};
this.emit('@notify', 'consumerResumed', data);
}
this._locallyPaused = false; this._locallyPaused = false;
...@@ -465,25 +469,6 @@ class Consumer extends EnhancedEventEmitter ...@@ -465,25 +469,6 @@ class Consumer extends EnhancedEventEmitter
this.safeEmit('resume', 'remote', appData); this.safeEmit('resume', 'remote', appData);
} }
/**
* The associated source (Producer) has been resumed.
*
* @private
*
* @param {Any} [appData] - App custom data.
*/
sourceResume(appData)
{
logger.debug('sourceResume()');
if (this._closed || !this._sourcePaused)
return;
this._sourcePaused = false;
// TODO
}
_handleWorkerNotifications() _handleWorkerNotifications()
{ {
// Subscribe to notifications. // Subscribe to notifications.
...@@ -498,6 +483,52 @@ class Consumer extends EnhancedEventEmitter ...@@ -498,6 +483,52 @@ class Consumer extends EnhancedEventEmitter
break; break;
} }
case 'sourcepaused':
{
if (this._sourcePaused)
return;
if (!this._locallyPaused)
{
const data =
{
id : this.id,
peerName : this.peer.name
};
this.emit('@notify', 'consumerPaused', data);
}
this._sourcePaused = true;
this.safeEmit('pause', 'source');
break;
}
case 'sourceresumed':
{
if (!this._sourcePaused)
return;
if (!this._locallyPaused)
{
const data =
{
id : this.id,
peerName : this.peer.name
};
this.emit('@notify', 'consumerResumed', data);
}
this._sourcePaused = false;
this.safeEmit('resume', 'source');
break;
}
default: default:
logger.error('ignoring unknown event "%s"', event); logger.error('ignoring unknown event "%s"', event);
} }
......
...@@ -4,6 +4,7 @@ const Logger = require('./Logger'); ...@@ -4,6 +4,7 @@ const Logger = require('./Logger');
const EnhancedEventEmitter = require('./EnhancedEventEmitter'); const EnhancedEventEmitter = require('./EnhancedEventEmitter');
const utils = require('./utils'); const utils = require('./utils');
const errors = require('./errors'); const errors = require('./errors');
const ortc = require('./ortc');
const Transport = require('./Transport'); const Transport = require('./Transport');
const Producer = require('./Producer'); const Producer = require('./Producer');
const Consumer = require('./Consumer'); const Consumer = require('./Consumer');
...@@ -406,11 +407,8 @@ class Peer extends EnhancedEventEmitter ...@@ -406,11 +407,8 @@ class Peer extends EnhancedEventEmitter
else if (!transport) else if (!transport)
return Promise.reject(new TypeError('Transport not found')); return Promise.reject(new TypeError('Transport not found'));
// TODO: Get the RtpParameters of the associated Producer and "merge" return consumer.enable(transport)
// them with the Peer's rtpCapabilities to produce sending rtpParameters. .then(() => {});
const rtpParameters = {};
return consumer.enable(transport, rtpParameters);
} }
default: default:
...@@ -575,12 +573,16 @@ class Peer extends EnhancedEventEmitter ...@@ -575,12 +573,16 @@ class Peer extends EnhancedEventEmitter
transportId : undefined transportId : undefined
}; };
const consumerRtpParameters =
ortc.getConsumerRtpParameters(
producer.consumableRtpParameters, this.rtpCapabilities);
const data = const data =
{ {
kind : producer.kind, kind : producer.kind,
peer : producer.peer, peer : producer.peer,
transport : undefined, transport : undefined,
rtpParameters : [], // TODO rtpParameters : consumerRtpParameters,
source : producer source : producer
}; };
...@@ -669,11 +671,24 @@ class Peer extends EnhancedEventEmitter ...@@ -669,11 +671,24 @@ class Peer extends EnhancedEventEmitter
else if (!KINDS.has(kind)) else if (!KINDS.has(kind))
return Promise.reject(new TypeError(`unsupported kind: ${kind}`)); return Promise.reject(new TypeError(`unsupported kind: ${kind}`));
let rtpMapping; let rtpMappingForWorker;
let consumableRtpParameters;
try try
{ {
rtpMapping = this._sandbox.getProducerRtpParametersMapping(rtpParameters); const rtpMapping =
this._sandbox.getProducerRtpParametersMapping(rtpParameters);
// NOTE: rtpMapping has two Maps, but we need to convert them into arrays
// of pairs for the worker.
rtpMappingForWorker =
{
codecPayloadTypes : Array.from(rtpMapping.mapCodecPayloadTypes),
headerExtensionIds : Array.from(rtpMapping.mapHeaderExtensionIds)
};
consumableRtpParameters =
this._sandbox.getConsumableRtpParameters(rtpParameters, rtpMapping);
} }
catch (error) catch (error)
{ {
...@@ -697,14 +712,15 @@ class Peer extends EnhancedEventEmitter ...@@ -697,14 +712,15 @@ class Peer extends EnhancedEventEmitter
kind : kind, kind : kind,
peer : this, peer : this,
transport : transport, transport : transport,
rtpParameters : rtpParameters rtpParameters : rtpParameters,
consumableRtpParameters : consumableRtpParameters
}; };
return this._channel.request('router.createProducer', internal, return this._channel.request('router.createProducer', internal,
{ {
kind, kind : kind,
rtpParameters, rtpParameters : rtpParameters,
rtpMapping rtpMapping : rtpMappingForWorker
}) })
.then(() => .then(() =>
{ {
......
...@@ -28,6 +28,7 @@ class Producer extends EnhancedEventEmitter ...@@ -28,6 +28,7 @@ class Producer extends EnhancedEventEmitter
// - .peer // - .peer
// - .transport // - .transport
// - .rtpParameters // - .rtpParameters
// - .consumableRtpParameters
this._data = data; this._data = data;
// Channel instance. // Channel instance.
...@@ -89,6 +90,11 @@ class Producer extends EnhancedEventEmitter ...@@ -89,6 +90,11 @@ class Producer extends EnhancedEventEmitter
return this._data.rtpParameters; return this._data.rtpParameters;
} }
get consumableRtpParameters()
{
return this._data.consumableRtpParameters;
}
/** /**
* Whether the Producer is locally paused. * Whether the Producer is locally paused.
* *
...@@ -138,7 +144,16 @@ class Producer extends EnhancedEventEmitter ...@@ -138,7 +144,16 @@ class Producer extends EnhancedEventEmitter
// the client-side Producer. Otherwise, if the Transport is closed the client-side // the client-side Producer. Otherwise, if the Transport is closed the client-side
// Producer will get 'unhandled', so don't close it from here. // Producer will get 'unhandled', so don't close it from here.
if (!this.transport.closed) if (!this.transport.closed)
this.emit('@notify', 'producerClosed', { id: this.id, appData }); {
const data =
{
id : this.id,
peerName : this.peer.name,
appData : appData
};
this.emit('@notify', 'producerClosed', data);
}
this.emit('@close'); this.emit('@close');
this.safeEmit('close', 'local', appData); this.safeEmit('close', 'local', appData);
...@@ -278,7 +293,14 @@ class Producer extends EnhancedEventEmitter ...@@ -278,7 +293,14 @@ class Producer extends EnhancedEventEmitter
return true; return true;
} }
this.emit('@notify', 'producerPaused', { id: this.id, appData }); const data =
{
id : this.id,
peerName : this.peer.name,
appData : appData
};
this.emit('@notify', 'producerPaused', data);
this._locallyPaused = true; this._locallyPaused = true;
...@@ -352,7 +374,14 @@ class Producer extends EnhancedEventEmitter ...@@ -352,7 +374,14 @@ class Producer extends EnhancedEventEmitter
return true; return true;
} }
this.emit('@notify', 'producerResumed', { id: this.id, appData }); const data =
{
id : this.id,
peerName : this.peer.name,
appData : appData
};
this.emit('@notify', 'producerResumed', data);
this._locallyPaused = false; this._locallyPaused = false;
......
...@@ -239,10 +239,17 @@ class Room extends EnhancedEventEmitter ...@@ -239,10 +239,17 @@ class Room extends EnhancedEventEmitter
const sandbox = const sandbox =
{ {
// NOTE: This may throw. // NOTE: This may throw.
getProducerRtpParametersMapping : (rtpParameters) => getProducerRtpParametersMapping : (producerRtpParameters) =>
{ {
return ortc.getProducerRtpParametersMapping( return ortc.getProducerRtpParametersMapping(
rtpParameters, this.rtpCapabilities); producerRtpParameters, this.rtpCapabilities);
},
// NOTE: This may throw.
getConsumableRtpParameters : (producerRtpParameters, rtpMapping) =>
{
return ortc.getConsumableRtpParameters(
producerRtpParameters, this.rtpCapabilities, rtpMapping);
} }
}; };
......
'use strict'; 'use strict';
const utils = require('./utils');
const supportedRtpCapabilities = require('./supportedRtpCapabilities'); const supportedRtpCapabilities = require('./supportedRtpCapabilities');
const DYNAMIC_PAYLOAD_TYPES = const DYNAMIC_PAYLOAD_TYPES =
...@@ -155,16 +156,15 @@ exports.assertCapabilitiesSubset = function(capsA, capsB) ...@@ -155,16 +156,15 @@ exports.assertCapabilitiesSubset = function(capsA, capsB)
}; };
/** /**
* Generate an Object with RTP parameters and RTP mapping. * Generate a mapping of codec payload types and header extension ids that maps
* the RTP parameters of a Producer and the associated values in the RTP
* capabilities of the Room.
* It may throw if invalid or non supported RTP parameters are given. * It may throw if invalid or non supported RTP parameters are given.
* *
* @param {RTCRtpParameters} params * @param {RTCRtpParameters} params
* @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.getProducerRtpParametersMapping = function(params, caps) exports.getProducerRtpParametersMapping = function(params, caps)
{ {
...@@ -252,9 +252,218 @@ exports.getProducerRtpParametersMapping = function(params, caps) ...@@ -252,9 +252,218 @@ exports.getProducerRtpParametersMapping = function(params, caps)
} }
return { return {
codecPayloadTypes : Array.from(mapCodecPayloadTypes), mapCodecPayloadTypes,
headerExtensionIds : Array.from(mapHeaderExtensionIds) mapHeaderExtensionIds
};
};
/**
* Generate RTP parameters for Consumers given the RTP parameters of a Producer
* and the RTP capabilities of the Room.
* It may throw if invalid or non supported RTP parameters are given.
*
* TODO: This method should also reduce encodings in case of simulcast/SVC
* so the resulting consumable RTP parameters are suitable for a Consumer.
* For now we assume a single encoding in the Producer RTP parameters.
*
* @param {RTCRtpParameters} params
* @param {RTCRtpCapabilities} caps
* @param {Object} rtpMapping - As generated by getProducerRtpParametersMapping().
*
* @return {RTCRtpParameters}
*/
exports.getConsumableRtpParameters = function(params, caps, rtpMapping)
{
const { mapCodecPayloadTypes, mapHeaderExtensionIds } = rtpMapping;
const consumableParams =
{
muxId : params.muxId,
codecs : [],
headerExtensions : [],
encodings : params.encodings,
rtcp : params.rtcp
};
for (const codec of params.codecs)
{
if (codec.name.toLowerCase() === 'rtx')
continue;
const consumableCodecPt = mapCodecPayloadTypes.get(codec.payloadType);
if (!consumableCodecPt)
{
throw new Error(
`codec payloadType mapping not found [name:${codec.name}]`);
}
const matchedCapCodec = caps.codecs
.find((capCodec) => capCodec.preferredPayloadType === consumableCodecPt);
if (!matchedCapCodec)
throw new Error(`capabilities codec not found [name:${codec.name}]`);
const consumableCodec =
{
name : matchedCapCodec.name,
mimeType : matchedCapCodec.mimeType,
clockRate : matchedCapCodec.clockRate,
payloadType : matchedCapCodec.preferredPayloadType,
channels : matchedCapCodec.channels,
rtcpFeedback : matchedCapCodec.rtcpFeedback,
parameters : matchedCapCodec.parameters
};
if (!consumableCodec.channels)
delete consumableCodec.channels;
consumableParams.codecs.push(consumableCodec);
const consumableCapRtxCodec = caps.codecs
.find((capRtxCodec) =>
{
return (
capRtxCodec.name.toLowerCase() === 'rtx' &&
capRtxCodec.parameters.apt === consumableCodec.payloadType
);
});
if (consumableCapRtxCodec)
{
const consumableRtxCodec =
{
name : consumableCapRtxCodec.name,
mimeType : consumableCapRtxCodec.mimeType,
clockRate : consumableCapRtxCodec.clockRate,
payloadType : consumableCapRtxCodec.preferredPayloadType,
channels : consumableCapRtxCodec.channels,
rtcpFeedback : consumableCapRtxCodec.rtcpFeedback,
parameters : consumableCapRtxCodec.parameters
}; };
if (!consumableRtxCodec.channels)
delete consumableRtxCodec.channels;
consumableParams.codecs.push(consumableRtxCodec);
}
}
for (const ext of params.headerExtensions)
{
const consumableExtId = mapHeaderExtensionIds.get(ext.id);
if (!consumableExtId)
{
throw new Error(
`extension header id mapping not found [uri:${ext.uri}]`);
}
const matchedCapExt = caps.headerExtensions
.find((capExt) => capExt.preferredId === consumableExtId);
if (!matchedCapExt)
throw new Error(`capabilities header extension not found [uri:${ext.uri}]`);
const consumableExt =
{
uri : matchedCapExt.uri,
id : matchedCapExt.preferredId
};
consumableParams.headerExtensions.push(consumableExt);
}
// TODO: REMOVE
// console.log('consumableParams:\n', JSON.stringify(consumableParams, null, ' '));
return consumableParams;
};
/**
* Generate RTP parameters for a specific Consumer.
*
* @param {RTCRtpParameters} consumableRtpParameters - Consumable RTP parameters.
* @param {RTCRtpCapabilities} rtpCapabilities - Peer RTP capabilities.
*
* @return {RTCRtpParameters}
*/
exports.getConsumerRtpParameters = function(consumableRtpParameters, rtpCapabilities)
{
const consumerParams =
{
muxId : consumableRtpParameters.muxId,
codecs : [],
headerExtensions : [],
encodings : [],
rtcp : consumableRtpParameters.rtcp
};
let rtxSupported = false;
for (const codec of consumableRtpParameters.codecs)
{
const matchedCapCodec = rtpCapabilities.codecs
.find((capCodec) => capCodec.preferredPayloadType === codec.payloadType);
if (!matchedCapCodec)
continue;
const consumerCodec =
{
name : matchedCapCodec.name,
mimeType : matchedCapCodec.mimeType,
clockRate : matchedCapCodec.clockRate,
payloadType : matchedCapCodec.preferredPayloadType,
channels : matchedCapCodec.channels,
rtcpFeedback : matchedCapCodec.rtcpFeedback,
parameters : matchedCapCodec.parameters
};
if (!consumerCodec.channels)
delete consumerCodec.channels;
consumerParams.codecs.push(consumerCodec);
if (consumerCodec.name.toLowerCase() === 'rtx')
rtxSupported = true;
}
for (const ext of consumableRtpParameters.headerExtensions)
{
const matchedCapExt = rtpCapabilities.headerExtensions
.find((capExt) => capExt.preferredId === ext.id);
if (!matchedCapExt)
continue;
const consumerExt =
{
uri : matchedCapExt.uri,
id : matchedCapExt.preferredId
};
consumerParams.headerExtensions.push(consumerExt);
}
const consumerEncoding =
{
ssrc : consumableRtpParameters.encodings[0].ssrc
};
if (rtxSupported)
{
consumerEncoding.rtx =
{
ssrc : utils.randomNumber()
};
}
consumerParams.encodings.push(consumerEncoding);
// TODO: REMOVE
// console.log('consumerParams:\n', JSON.stringify(consumerParams, null, ' '));
return consumerParams;
}; };
function assertCodecCapability(codec) function assertCodecCapability(codec)
......
...@@ -40,6 +40,8 @@ namespace RTC ...@@ -40,6 +40,8 @@ namespace RTC
void AddListener(RTC::ConsumerListener* listener); void AddListener(RTC::ConsumerListener* listener);
void RemoveListener(RTC::ConsumerListener* listener); void RemoveListener(RTC::ConsumerListener* listener);
const RTC::RtpParameters& GetParameters() const; const RTC::RtpParameters& GetParameters() const;
void SetSourcePaused();
void SetSourceResumed();
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);
...@@ -69,6 +71,7 @@ namespace RTC ...@@ -69,6 +71,7 @@ namespace RTC
// Others. // Others.
std::unordered_set<uint8_t> supportedCodecPayloadTypes; std::unordered_set<uint8_t> supportedCodecPayloadTypes;
bool paused{ false }; bool paused{ false };
bool sourcePaused{ 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 };
...@@ -94,6 +97,24 @@ namespace RTC ...@@ -94,6 +97,24 @@ namespace RTC
return this->rtpParameters; return this->rtpParameters;
} }
inline void Consumer::SetSourcePaused()
{
if (this->sourcePaused)
return;
this->sourcePaused = true;
this->notifier->Emit(this->consumerId, "sourcepaused");
}
inline void Consumer::SetSourceResumed()
{
if (!this->sourcePaused)
return;
this->sourcePaused = false;
this->notifier->Emit(this->consumerId, "sourceresumed");
}
inline uint32_t Consumer::GetTransmissionRate(uint64_t now) inline uint32_t Consumer::GetTransmissionRate(uint64_t now)
{ {
return this->transmittedCounter.GetRate(now) + this->retransmittedCounter.GetRate(now); return this->transmittedCounter.GetRate(now) + this->retransmittedCounter.GetRate(now);
......
...@@ -13,6 +13,8 @@ namespace RTC ...@@ -13,6 +13,8 @@ namespace RTC
{ {
public: public:
virtual void OnProducerClosed(RTC::Producer* producer) = 0; virtual void OnProducerClosed(RTC::Producer* producer) = 0;
virtual void OnProducerPaused(RTC::Producer* producer) = 0;
virtual void OnProducerResumed(RTC::Producer* producer) = 0;
virtual void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) = 0; virtual void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) = 0;
}; };
} // namespace RTC } // namespace RTC
......
...@@ -66,6 +66,8 @@ namespace RTC ...@@ -66,6 +66,8 @@ namespace RTC
/* Pure virtual methods inherited from RTC::ProducerListener. */ /* Pure virtual methods inherited from RTC::ProducerListener. */
public: public:
void OnProducerClosed(RTC::Producer* producer) override; void OnProducerClosed(RTC::Producer* producer) override;
void OnProducerPaused(RTC::Producer* producer) override;
void OnProducerResumed(RTC::Producer* producer) override;
void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) override; void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) override;
/* Pure virtual methods inherited from RTC::ConsumerListener. */ /* Pure virtual methods inherited from RTC::ConsumerListener. */
......
...@@ -131,6 +131,8 @@ namespace RTC ...@@ -131,6 +131,8 @@ namespace RTC
/* Pure virtual methods inherited from RTC::ProducerListener. */ /* Pure virtual methods inherited from RTC::ProducerListener. */
public: public:
void OnProducerClosed(RTC::Producer* producer) override; void OnProducerClosed(RTC::Producer* producer) override;
void OnProducerPaused(RTC::Producer* producer) override;
void OnProducerResumed(RTC::Producer* producer) override;
void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) override; void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) override;
/* Pure virtual methods inherited from RTC::ConsumerListener. */ /* Pure virtual methods inherited from RTC::ConsumerListener. */
......
...@@ -52,7 +52,6 @@ namespace RTC ...@@ -52,7 +52,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// Notify the listeners.
for (auto& listener : this->listeners) for (auto& listener : this->listeners)
{ {
listener->OnConsumerClosed(this); listener->OnConsumerClosed(this);
......
...@@ -60,7 +60,6 @@ namespace RTC ...@@ -60,7 +60,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// Notify the listeners.
for (auto& listener : this->listeners) for (auto& listener : this->listeners)
{ {
listener->OnProducerClosed(this); listener->OnProducerClosed(this);
...@@ -132,10 +131,20 @@ namespace RTC ...@@ -132,10 +131,20 @@ namespace RTC
case Channel::Request::MethodId::PRODUCER_PAUSE: case Channel::Request::MethodId::PRODUCER_PAUSE:
{ {
bool wasPaused = this->paused;
this->paused = true; this->paused = true;
request->Accept(); request->Accept();
if (!wasPaused)
{
for (auto& listener : this->listeners)
{
listener->OnProducerPaused(this);
}
}
break; break;
} }
...@@ -148,7 +157,14 @@ namespace RTC ...@@ -148,7 +157,14 @@ namespace RTC
request->Accept(); request->Accept();
if (wasPaused) if (wasPaused)
{
for (auto& listener : this->listeners)
{
listener->OnProducerResumed(this);
}
RequestFullFrame(); RequestFullFrame();
}
break; break;
} }
...@@ -276,7 +292,6 @@ namespace RTC ...@@ -276,7 +292,6 @@ namespace RTC
// Apply the Producer RTP mapping before dispatching the packet to the Router. // Apply the Producer RTP mapping before dispatching the packet to the Router.
ApplyRtpMapping(packet); ApplyRtpMapping(packet);
// Notify the listener.
for (auto& listener : this->listeners) for (auto& listener : this->listeners)
{ {
listener->OnProducerRtpPacket(this, packet); listener->OnProducerRtpPacket(this, packet);
......
...@@ -830,6 +830,38 @@ namespace RTC ...@@ -830,6 +830,38 @@ namespace RTC
this->mapProducerAudioLevelContainer.erase(producer); this->mapProducerAudioLevelContainer.erase(producer);
} }
void Router::OnProducerPaused(RTC::Producer* producer)
{
MS_TRACE();
MS_ASSERT(
this->mapProducerConsumers.find(producer) != this->mapProducerConsumers.end(),
"Producer not present in mapProducerConsumers");
auto& consumers = this->mapProducerConsumers[producer];
for (auto& consumer : consumers)
{
consumer->SetSourcePaused();
}
}
void Router::OnProducerResumed(RTC::Producer* producer)
{
MS_TRACE();
MS_ASSERT(
this->mapProducerConsumers.find(producer) != this->mapProducerConsumers.end(),
"Producer not present in mapProducerConsumers");
auto& consumers = this->mapProducerConsumers[producer];
for (auto& consumer : consumers)
{
consumer->SetSourceResumed();
}
}
void Router::OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) void Router::OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet)
{ {
MS_TRACE(); MS_TRACE();
...@@ -871,8 +903,6 @@ namespace RTC ...@@ -871,8 +903,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// TODO: How to tell the Transport using this Consumer.
this->consumers.erase(consumer->consumerId); this->consumers.erase(consumer->consumerId);
for (auto& kv : this->mapProducerConsumers) for (auto& kv : this->mapProducerConsumers)
......
...@@ -25,7 +25,7 @@ namespace RTC ...@@ -25,7 +25,7 @@ namespace RTC
if (!data.isObject()) if (!data.isObject())
MS_THROW_ERROR("RtpCodecParameters is not an object"); MS_THROW_ERROR("RtpCodecParameters is not an object");
// `mimeType` is mandatory. // mimeType is mandatory.
if (!data[JsonStringMimeType].isString()) if (!data[JsonStringMimeType].isString())
MS_THROW_ERROR("missing RtpCodec.mimeType"); MS_THROW_ERROR("missing RtpCodec.mimeType");
...@@ -40,29 +40,29 @@ namespace RTC ...@@ -40,29 +40,29 @@ namespace RTC
this->payloadType = static_cast<uint8_t>(data[JsonStringPayloadType].asUInt()); this->payloadType = static_cast<uint8_t>(data[JsonStringPayloadType].asUInt());
// `clockRate` is mandatory. // clockRate is mandatory.
if (!data[JsonStringClockRate].isUInt()) if (!data[JsonStringClockRate].isUInt())
MS_THROW_ERROR("missing RtpCodecParameters.clockRate"); MS_THROW_ERROR("missing RtpCodecParameters.clockRate");
this->clockRate = uint32_t{ data[JsonStringClockRate].asUInt() }; this->clockRate = uint32_t{ data[JsonStringClockRate].asUInt() };
// `maxptime` is optional. // maxptime is optional.
if (data[JsonStringMaxptime].isUInt()) if (data[JsonStringMaxptime].isUInt())
this->maxptime = uint32_t{ data[JsonStringMaxptime].asUInt() }; this->maxptime = uint32_t{ data[JsonStringMaxptime].asUInt() };
// `ptime` is optional. // ptime is optional.
if (data[JsonStringPtime].isUInt()) if (data[JsonStringPtime].isUInt())
this->ptime = uint32_t{ data[JsonStringPtime].asUInt() }; this->ptime = uint32_t{ data[JsonStringPtime].asUInt() };
// `channels` is optional. // channels is optional.
if (data[JsonStringNumChannels].isUInt()) if (data[JsonStringNumChannels].isUInt())
this->channels = uint32_t{ data[JsonStringNumChannels].asUInt() }; this->channels = uint32_t{ data[JsonStringNumChannels].asUInt() };
// `parameters` is optional. // parameters is optional.
if (data[JsonStringParameters].isObject()) if (data[JsonStringParameters].isObject())
this->parameters.Set(data[JsonStringParameters]); this->parameters.Set(data[JsonStringParameters]);
// `rtcpFeedback` is optional. // rtcpFeedback is optional.
if (data[JsonStringRtcpFeedback].isArray()) if (data[JsonStringRtcpFeedback].isArray())
{ {
auto& jsonRtcpFeedback = data[JsonStringRtcpFeedback]; auto& jsonRtcpFeedback = data[JsonStringRtcpFeedback];
...@@ -96,34 +96,34 @@ namespace RTC ...@@ -96,34 +96,34 @@ namespace RTC
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
// Add `mimeType`. // Add mimeType.
json[JsonStringMimeType] = this->mime.ToString(); json[JsonStringMimeType] = this->mime.ToString();
// Add `name`. // Add name.
json[JsonStringName] = this->mime.GetName(); json[JsonStringName] = this->mime.GetName();
// Add `payloadType`. // Add payloadType.
json[JsonStringPayloadType] = Json::UInt{ this->payloadType }; json[JsonStringPayloadType] = Json::UInt{ this->payloadType };
// Add `clockRate`. // Add clockRate.
json[JsonStringClockRate] = Json::UInt{ this->clockRate }; json[JsonStringClockRate] = Json::UInt{ this->clockRate };
// Add `maxptime`. // Add maxptime.
if (this->maxptime != 0u) if (this->maxptime != 0u)
json[JsonStringMaxptime] = Json::UInt{ this->maxptime }; json[JsonStringMaxptime] = Json::UInt{ this->maxptime };
// Add `ptime`. // Add ptime.
if (this->ptime != 0u) if (this->ptime != 0u)
json[JsonStringPtime] = Json::UInt{ this->ptime }; json[JsonStringPtime] = Json::UInt{ this->ptime };
// Add `channels`. // Add channels.
if (this->channels > 1) if (this->channels > 1)
json[JsonStringNumChannels] = Json::UInt{ this->channels }; json[JsonStringNumChannels] = Json::UInt{ this->channels };
// Add `parameters`. // Add parameters.
json[JsonStringParameters] = this->parameters.ToJson(); json[JsonStringParameters] = this->parameters.ToJson();
// Add `rtcpFeedback`. // Add rtcpFeedback.
json[JsonStringRtcpFeedback] = Json::arrayValue; json[JsonStringRtcpFeedback] = Json::arrayValue;
for (auto& entry : this->rtcpFeedback) for (auto& entry : this->rtcpFeedback)
......
...@@ -27,52 +27,52 @@ namespace RTC ...@@ -27,52 +27,52 @@ namespace RTC
if (!data.isObject()) if (!data.isObject())
MS_THROW_ERROR("RtpEncodingParameters is not an object"); MS_THROW_ERROR("RtpEncodingParameters is not an object");
// `codecPayloadType` is optional. // codecPayloadType is optional.
if (data[JsonStringCodecPayloadType].isUInt()) if (data[JsonStringCodecPayloadType].isUInt())
{ {
this->codecPayloadType = static_cast<uint8_t>(data[JsonStringCodecPayloadType].asUInt()); this->codecPayloadType = static_cast<uint8_t>(data[JsonStringCodecPayloadType].asUInt());
this->hasCodecPayloadType = true; this->hasCodecPayloadType = true;
} }
// `ssrc` is optional. // ssrc is optional.
if (data[JsonStringSsrc].isUInt()) if (data[JsonStringSsrc].isUInt())
this->ssrc = uint32_t{ data[JsonStringSsrc].asUInt() }; this->ssrc = uint32_t{ data[JsonStringSsrc].asUInt() };
// `fec` is optional. // fec is optional.
if (data[JsonStringFec].isObject()) if (data[JsonStringFec].isObject())
{ {
this->fec = RtpFecParameters(data[JsonStringFec]); this->fec = RtpFecParameters(data[JsonStringFec]);
this->hasFec = true; this->hasFec = true;
} }
// `rtx` is optional. // rtx is optional.
if (data[JsonStringRtx].isObject()) if (data[JsonStringRtx].isObject())
{ {
this->rtx = RtpRtxParameters(data[JsonStringRtx]); this->rtx = RtpRtxParameters(data[JsonStringRtx]);
this->hasRtx = true; this->hasRtx = true;
} }
// `resolutionScale` is optional. // resolutionScale is optional.
if (data[JsonStringResolutionScale].isDouble()) if (data[JsonStringResolutionScale].isDouble())
this->resolutionScale = data[JsonStringResolutionScale].asDouble(); this->resolutionScale = data[JsonStringResolutionScale].asDouble();
// `framerateScale` is optional. // framerateScale is optional.
if (data[JsonStringFramerateScale].isDouble()) if (data[JsonStringFramerateScale].isDouble())
this->framerateScale = data[JsonStringFramerateScale].asDouble(); this->framerateScale = data[JsonStringFramerateScale].asDouble();
// `maxFramerate` is optional. // maxFramerate is optional.
if (data[JsonStringMaxFramerate].isUInt()) if (data[JsonStringMaxFramerate].isUInt())
this->maxFramerate = uint32_t{ data[JsonStringMaxFramerate].asUInt() }; this->maxFramerate = uint32_t{ data[JsonStringMaxFramerate].asUInt() };
// `active` is optional. // active is optional.
if (data[JsonStringActive].isBool()) if (data[JsonStringActive].isBool())
this->active = data[JsonStringActive].asBool(); this->active = data[JsonStringActive].asBool();
// `encodingId` is optional. // encodingId is optional.
if (data[JsonStringEncodingId].isString()) if (data[JsonStringEncodingId].isString())
this->encodingId = data[JsonStringEncodingId].asString(); this->encodingId = data[JsonStringEncodingId].asString();
// `dependencyEncodingIds` is optional. // dependencyEncodingIds is optional.
if (data[JsonStringDependencyEncodingIds].isArray()) if (data[JsonStringDependencyEncodingIds].isArray())
{ {
auto& jsonArray = data[JsonStringDependencyEncodingIds]; auto& jsonArray = data[JsonStringDependencyEncodingIds];
...@@ -103,38 +103,38 @@ namespace RTC ...@@ -103,38 +103,38 @@ namespace RTC
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
// Add `codecPayloadType`. // Add codecPayloadType.
if (this->hasCodecPayloadType) if (this->hasCodecPayloadType)
json[JsonStringCodecPayloadType] = Json::UInt{ this->codecPayloadType }; json[JsonStringCodecPayloadType] = Json::UInt{ this->codecPayloadType };
// Add `ssrc`. // Add ssrc.
if (this->ssrc != 0u) if (this->ssrc != 0u)
json[JsonStringSsrc] = Json::UInt{ this->ssrc }; json[JsonStringSsrc] = Json::UInt{ this->ssrc };
// Add `fec` // Add fec
if (this->hasFec) if (this->hasFec)
json[JsonStringFec] = this->fec.ToJson(); json[JsonStringFec] = this->fec.ToJson();
// Add `rtx` // Add rtx
if (this->hasRtx) if (this->hasRtx)
json[JsonStringRtx] = this->rtx.ToJson(); json[JsonStringRtx] = this->rtx.ToJson();
// Add `resolutionScale` (if different than the default value). // Add resolutionScale (if different than the default value).
if (this->resolutionScale != 1.0) if (this->resolutionScale != 1.0)
json[JsonStringResolutionScale] = this->resolutionScale; json[JsonStringResolutionScale] = this->resolutionScale;
// Add `framerateScale` (if different than the default value). // Add framerateScale (if different than the default value).
if (this->framerateScale != 1.0) if (this->framerateScale != 1.0)
json[JsonStringFramerateScale] = this->framerateScale; json[JsonStringFramerateScale] = this->framerateScale;
// Add `maxFramerate`. // Add maxFramerate.
if (this->maxFramerate != 0u) if (this->maxFramerate != 0u)
json[JsonStringMaxFramerate] = Json::UInt{ this->maxFramerate }; json[JsonStringMaxFramerate] = Json::UInt{ this->maxFramerate };
// Add `active`. // Add active.
json[JsonStringActive] = this->active; json[JsonStringActive] = this->active;
// Add `encodingId`. // Add encodingId.
if (!this->encodingId.empty()) if (!this->encodingId.empty())
json[JsonStringEncodingId] = this->encodingId; json[JsonStringEncodingId] = this->encodingId;
......
...@@ -269,7 +269,7 @@ namespace RTC ...@@ -269,7 +269,7 @@ namespace RTC
} }
// Iterate all the encodings, set the first payloadType in all of them with // Iterate all the encodings, set the first payloadType in all of them with
// `codecPayloadType` unset, and check that others point to a media codec. // codecPayloadType unset, and check that others point to a media codec.
for (auto& encoding : this->encodings) for (auto& encoding : this->encodings)
{ {
if (!encoding.hasCodecPayloadType) if (!encoding.hasCodecPayloadType)
......
...@@ -1323,6 +1323,16 @@ namespace RTC ...@@ -1323,6 +1323,16 @@ namespace RTC
this->rtpListener.RemoveProducer(producer); this->rtpListener.RemoveProducer(producer);
} }
void Transport::OnProducerPaused(RTC::Producer* producer)
{
// Do nothing.
}
void Transport::OnProducerResumed(RTC::Producer* producer)
{
// Do nothing.
}
void Transport::OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) void Transport::OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet)
{ {
// Do nothing. // Do nothing.
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论