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

works (RTCP missing)

上级 ed8906a9
# TODO in mediasoup v2 (server-side)
* If a Consumer is paused it should not receive RTP!!!! So `Consumer.SendRtpPacket()` should check `this->paused` (and `this->sourcePaused`?).
- Done, but we must also check whether the RTCP reports/stats we are generating are ok when paused and later resumed.
* Add a `fullFrrameRequestBlockTimer` and a `isFullFrameRequested` flag in `Producer`, so `Producer::RequestFullFrame()` check it and decides whether ask for a full frame to its streams or not.
* 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.
* If a worker Consumer is paused (or sourcePaused), should the RTCP checks or report generations behave differently?
* 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.
* Revisar appData en todos los mensajes.
* Check `appData` everywhere.
* Remove DEPTH stuff.
* Redo the compile_commands_template.json.
* Rethink the auto close of the worker `Transport`. Yes/no?
* Rethink the auto close of the worker `Transport` when receiving a DTLS CLOSE ALERT (or when it's just TCP and the connection fails...). Yes/no? BTW it's generating some issues because the JS closes the Producer/Transport and gets `request failed [id:84026423, reason:"Consumer/Transport does not exist"]` (because it was already closed due to DTLS ALERT).
* Move the RTCP timer from Peer to Transport.
* `then()` of Promises is async so if we create an instance (Peer, Producer, Transport, etc) within the `channel.request().then(....)` and an event happens for that instance immediately, such an event may be lost.
- The solution is creating the instance before calling `channel.request()`.
- DOC: https://stackoverflow.com/questions/36726890/why-are-javascript-promises-asynchronous-when-calling-only-synchronous-functions
+ 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"
* 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).
* Implement `mandatoryCodecPayloadTypes`.
## TODO per JS class
### Room
* Add `mandatoryCodecPayloadTypes`.
* Use/store `appData` when creating a `Peer`.
......@@ -165,7 +165,9 @@ class Consumer extends EnhancedEventEmitter
peerName : this.peer.name
};
this.emit('@notify', 'consumerClosed', data);
// Don't notify `consumerClosed` if the Peer is already closed.
if (!this.peer.closed)
this.emit('@notify', 'consumerClosed', data);
this.emit('@close');
this.safeEmit('close');
......@@ -240,8 +242,6 @@ class Consumer extends EnhancedEventEmitter
* Enable the Consumer for sending media.
*
* @param {Transport} transport
*
* @return {Promise} Resolves to this.
*/
enable(transport)
{
......@@ -257,12 +257,13 @@ class Consumer extends EnhancedEventEmitter
transportId : transport.id
});
const data = Object.assign({ transport }, this._data);
const data = Object.assign({}, this._data, { transport });
return this._channel.request('router.createConsumer', internal,
{
kind : this.kind,
rtpParameters : this.rtpParameters
rtpParameters : this.rtpParameters,
paused : this.locallyPaused || this.remotelyPaused
})
.then(() =>
{
......@@ -277,9 +278,10 @@ class Consumer extends EnhancedEventEmitter
{
this._internal.transportId = undefined;
this._data.transport = undefined;
this._sourcePaused = false;
});
return this;
return;
})
.catch((error) =>
{
......@@ -311,7 +313,9 @@ class Consumer extends EnhancedEventEmitter
return true;
}
if (!this._sourcePaused)
this._locallyPaused = true;
if (this.enabled && !this._sourcePaused)
{
const data =
{
......@@ -323,8 +327,6 @@ class Consumer extends EnhancedEventEmitter
this.emit('@notify', 'consumerPaused', data);
}
this._locallyPaused = true;
// Send Channel request.
if (this.enabled)
{
......@@ -401,7 +403,9 @@ class Consumer extends EnhancedEventEmitter
return true;
}
if (!this._sourcePaused)
this._locallyPaused = false;
if (this.enabled && !this._sourcePaused)
{
const data =
{
......@@ -413,8 +417,6 @@ class Consumer extends EnhancedEventEmitter
this.emit('@notify', 'consumerResumed', data);
}
this._locallyPaused = false;
if (this.enabled && !this._remotelyPaused)
{
// Send Channel request.
......@@ -488,7 +490,9 @@ class Consumer extends EnhancedEventEmitter
if (this._sourcePaused)
return;
if (!this._locallyPaused)
this._sourcePaused = true;
if (this.enabled && !this._locallyPaused)
{
const data =
{
......@@ -499,8 +503,6 @@ class Consumer extends EnhancedEventEmitter
this.emit('@notify', 'consumerPaused', data);
}
this._sourcePaused = true;
this.safeEmit('pause', 'source');
break;
......@@ -511,7 +513,9 @@ class Consumer extends EnhancedEventEmitter
if (!this._sourcePaused)
return;
if (!this._locallyPaused)
this._sourcePaused = false;
if (this.enabled && !this._locallyPaused)
{
const data =
{
......@@ -522,8 +526,6 @@ class Consumer extends EnhancedEventEmitter
this.emit('@notify', 'consumerResumed', data);
}
this._sourcePaused = false;
this.safeEmit('resume', 'source');
break;
......
......@@ -242,6 +242,7 @@ class Peer extends EnhancedEventEmitter
producers : [],
consumers : []
};
const promises = [];
for (const transport of this._transports.values())
......@@ -385,20 +386,15 @@ class Peer extends EnhancedEventEmitter
appData
} = request;
return this._createProducer(id, kind, transportId, rtpParameters, appData)
.then((producer) =>
{
if (paused)
producer.remotePause();
const remotelyPaused = paused;
return;
});
return this._createProducer(
id, kind, transportId, rtpParameters, remotelyPaused, appData);
}
case 'enableConsumer':
{
// TODO: Use paused!
const { id, transportId, paused } = request;
const { id, transportId } = request;
const consumer = this._consumers.get(id);
const transport = this._transports.get(transportId);
......@@ -408,7 +404,12 @@ class Peer extends EnhancedEventEmitter
return Promise.reject(new TypeError('Transport not found'));
return consumer.enable(transport)
.then(() => {});
.then(() =>
{
return {
paused : consumer.sourcePaused || consumer.locallyPaused
};
});
}
default:
......@@ -528,6 +529,32 @@ class Peer extends EnhancedEventEmitter
break;
}
case 'pauseConsumer':
{
const { id, appData } = notification;
const consumer = this._consumers.get(id);
if (!consumer)
throw new Error('Consumer not found');
consumer.remotePause(appData);
break;
}
case 'resumeConsumer':
{
const { id, appData } = notification;
const consumer = this._consumers.get(id);
if (!consumer)
throw new Error('Consumer not found');
consumer.remoteResume(appData);
break;
}
default:
throw new Error(`unknown notification method "${method}"`);
}
......@@ -562,9 +589,6 @@ class Peer extends EnhancedEventEmitter
*/
addConsumerForProducer(producer, notifyClient = true)
{
// TODO: Check if producer is paused.
// TODO: So Consumer.js must have sourcePause() and sourceResume() methods.
const internal =
{
routerId : this._internal.routerId,
......@@ -603,7 +627,6 @@ class Peer extends EnhancedEventEmitter
if (notifyClient)
this._sendNotification('newConsumer', consumer.toJson());
this.emit('@newconsumer', consumer);
this.safeEmit('newconsumer', consumer);
}
......@@ -662,7 +685,7 @@ class Peer extends EnhancedEventEmitter
});
}
_createProducer(id, kind, transportId, rtpParameters, appData)
_createProducer(id, kind, transportId, rtpParameters, remotelyPaused, appData)
{
logger.debug('_createProducer() [id:%s, kind:%s]', id, kind);
......@@ -716,17 +739,23 @@ class Peer extends EnhancedEventEmitter
consumableRtpParameters : consumableRtpParameters
};
const options =
{
remotelyPaused
};
return this._channel.request('router.createProducer', internal,
{
kind : kind,
rtpParameters : rtpParameters,
rtpMapping : rtpMappingForWorker
rtpMapping : rtpMappingForWorker,
paused : remotelyPaused
})
.then(() =>
{
logger.debug('"router.createProducer" request succeeded');
const producer = new Producer(internal, data, this._channel);
const producer = new Producer(internal, data, this._channel, options);
producer.appData = appData;
......@@ -742,7 +771,8 @@ class Peer extends EnhancedEventEmitter
this.emit('@newproducer', producer);
this.safeEmit('newproducer', producer);
return producer;
// Ensure we return nothing.
return;
})
.catch((error) =>
{
......
......@@ -8,7 +8,7 @@ const logger = new Logger('Producer');
class Producer extends EnhancedEventEmitter
{
constructor(internal, data, channel)
constructor(internal, data, channel, options)
{
super(logger);
......@@ -43,7 +43,7 @@ class Producer extends EnhancedEventEmitter
// Remotely paused flag.
// @type {Boolean}
this._remotelyPaused = false;
this._remotelyPaused = Boolean(options.remotelyPaused);
this._handleTransportEvents();
......@@ -293,6 +293,8 @@ class Producer extends EnhancedEventEmitter
return true;
}
this._locallyPaused = true;
const data =
{
id : this.id,
......@@ -302,8 +304,6 @@ class Producer extends EnhancedEventEmitter
this.emit('@notify', 'producerPaused', data);
this._locallyPaused = true;
// Send Channel request.
this._channel.request('producer.pause', this._internal)
.then(() =>
......@@ -374,6 +374,8 @@ class Producer extends EnhancedEventEmitter
return true;
}
this._locallyPaused = false;
const data =
{
id : this.id,
......@@ -383,8 +385,6 @@ class Producer extends EnhancedEventEmitter
this.emit('@notify', 'producerResumed', data);
this._locallyPaused = false;
if (!this._remotelyPaused)
{
// Send Channel request.
......
......@@ -28,6 +28,7 @@ namespace RTC
RTC::Media::Kind kind,
RTC::Transport* transport,
RTC::RtpParameters& rtpParameters,
bool paused,
uint32_t sourceProducerId);
private:
......
......@@ -42,7 +42,8 @@ namespace RTC
RTC::Media::Kind kind,
RTC::Transport* transport,
RTC::RtpParameters& rtpParameters,
struct RtpMapping& rtpMapping);
struct RtpMapping& rtpMapping,
bool paused);
public:
// Must be public because Router needs to call it.
......@@ -55,6 +56,7 @@ namespace RTC
void AddListener(RTC::ProducerListener* listener);
void RemoveListener(RTC::ProducerListener* listener);
const RTC::RtpParameters& GetParameters() const;
bool IsPaused() const;
void ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
......@@ -114,6 +116,11 @@ namespace RTC
return this->rtpParameters;
}
inline bool Producer::IsPaused() const
{
return this->paused;
}
inline void Producer::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report)
{
auto it = this->rtpStreams.find(report->GetSsrc());
......
......@@ -23,9 +23,10 @@ namespace RTC
RTC::Media::Kind kind,
RTC::Transport* transport,
RTC::RtpParameters& rtpParameters,
bool paused,
uint32_t sourceProducerId)
: consumerId(consumerId), kind(kind), sourceProducerId(sourceProducerId), notifier(notifier),
transport(transport), rtpParameters(rtpParameters)
transport(transport), rtpParameters(rtpParameters), paused(paused)
{
MS_TRACE();
......@@ -75,6 +76,7 @@ namespace RTC
"supportedCodecPayloadTypes"
};
static const Json::StaticString JsonStringPaused{ "paused" };
static const Json::StaticString JsonStringSourcePaused{ "sourcePaused" };
Json::Value json(Json::objectValue);
......@@ -97,6 +99,8 @@ namespace RTC
json[JsonStringPaused] = this->paused;
json[JsonStringSourcePaused] = this->sourcePaused;
return json;
}
......
......@@ -18,9 +18,10 @@ namespace RTC
RTC::Media::Kind kind,
RTC::Transport* transport,
RTC::RtpParameters& rtpParameters,
struct RtpMapping& rtpMapping)
struct RtpMapping& rtpMapping,
bool paused)
: producerId(producerId), kind(kind), notifier(notifier), transport(transport),
rtpParameters(rtpParameters)
rtpParameters(rtpParameters), paused(paused)
{
MS_TRACE();
......
......@@ -221,6 +221,7 @@ namespace RTC
static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" };
static const Json::StaticString JsonStringRtpMapping{ "rtpMapping" };
static const Json::StaticString JsonStringPaused{ "paused" };
static const Json::StaticString JsonStringCodecPayloadTypes{ "codecPayloadTypes" };
static const Json::StaticString JsonStringHeaderExtensionIds{ "headerExtensionIds" };
......@@ -345,9 +346,14 @@ namespace RTC
return;
}
bool paused = false;
if (request->data[JsonStringPaused].isBool())
paused = request->data[JsonStringPaused].asBool();
// Create a Producer instance.
producer = new RTC::Producer(
this->notifier, producerId, kind, transport, rtpParameters, rtpMapping);
this->notifier, producerId, kind, transport, rtpParameters, rtpMapping, paused);
// Add us as listener.
producer->AddListener(this);
......@@ -382,6 +388,7 @@ namespace RTC
{
static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" };
static const Json::StaticString JsonStringPaused{ "paused" };
RTC::Consumer* consumer;
RTC::Transport* transport;
......@@ -479,8 +486,17 @@ namespace RTC
else if (kind != producer->kind)
MS_THROW_ERROR("not matching kind");
bool paused = false;
if (request->data[JsonStringPaused].isBool())
paused = request->data[JsonStringPaused].asBool();
consumer = new RTC::Consumer(
this->notifier, consumerId, kind, transport, rtpParameters, producer->producerId);
this->notifier, consumerId, kind, transport, rtpParameters, paused, producer->producerId);
// If the Producer is paused tell it to the new Consumer.
if (producer->IsPaused())
consumer->SetSourcePaused();
// Add us as listener.
consumer->AddListener(this);
......@@ -876,9 +892,6 @@ namespace RTC
// from which it was received.
for (auto& consumer : consumers)
{
// TODO: just if enabled?
// Mmmm, can it be "non" enabled? how?
consumer->SendRtpPacket(packet);
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论