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

s/Loop/Worker/g

上级 2642f782
# BUGS
# TODO in mediasoup v2 (server-side)
* Does `CONSUMER_ENABLE` makes sense? IMHO it's better to keep the Consumer just in JS and call `CREATE_CONSUMER` (by passing `rtpParameters` and `transportId`) once enabled for reception in JS.
* Handle all the XXXXX_CLOSE in the parent by calling `xxxxx->Destroy()`.
* Remove all the "close" events in C++.
* Move the RTCP timer from Peer to Transport.
......@@ -10,11 +16,6 @@
+ 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"
# TODO in mediasoup v2 (server-side)
* It's hard that `join` returns an array of `Peers` since, upon creation of the new `Peer`, it will receive `newconsumer` events which will try to send a `newPeer` mediasoup notification to the client.
* 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.
* If the transport of a consumer is closed, and the consumer was "enabled", it should become "disabled" and emit event (and send `consumerDisabled` notification? I think yes. Enabled should mean "it has a transport and RTP parameters.
......
......@@ -40,7 +40,6 @@ namespace Channel
PRODUCER_SET_RTP_OBJECT_EVENT,
CONSUMER_CLOSE,
CONSUMER_DUMP,
CONSUMER_ENABLE,
CONSUMER_PAUSE,
CONSUMER_RESUME
};
......
#ifndef MS_LOOP_HPP
#define MS_LOOP_HPP
#ifndef MS_WORKER_HPP
#define MS_WORKER_HPP
#include "common.hpp"
#include "Channel/Notifier.hpp"
......@@ -9,13 +9,13 @@
#include "handles/SignalsHandler.hpp"
#include <unordered_map>
class Loop : public SignalsHandler::Listener,
public Channel::UnixStreamSocket::Listener,
public RTC::Router::Listener
class Worker : public SignalsHandler::Listener,
public Channel::UnixStreamSocket::Listener,
public RTC::Router::Listener
{
public:
explicit Loop(Channel::UnixStreamSocket* channel);
~Loop() override;
explicit Worker(Channel::UnixStreamSocket* channel);
~Worker() override;
private:
void Close();
......
......@@ -16,8 +16,8 @@
'src/DepLibUV.cpp',
'src/DepOpenSSL.cpp',
'src/Logger.cpp',
'src/Loop.cpp',
'src/Settings.cpp',
'src/Worker.cpp',
'src/Channel/Notifier.cpp',
'src/Channel/Request.cpp',
'src/Channel/UnixStreamSocket.cpp',
......@@ -97,10 +97,10 @@
'include/DepOpenSSL.hpp',
'include/LogLevel.hpp',
'include/Logger.hpp',
'include/Loop.hpp',
'include/MediaSoupError.hpp',
'include/Settings.hpp',
'include/Utils.hpp',
'include/Worker.hpp',
'include/common.hpp',
'include/Channel/Notifier.hpp',
'include/Channel/Request.hpp',
......
......@@ -35,7 +35,6 @@ namespace Channel
{ "producer.setRtpObjectEvent", Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT },
{ "consumer.close", Request::MethodId::CONSUMER_CLOSE },
{ "consumer.dump", Request::MethodId::CONSUMER_DUMP },
{ "consumer.enable", Request::MethodId::CONSUMER_ENABLE },
{ "consumer.pause", Request::MethodId::CONSUMER_PAUSE },
{ "consumer.resume", Request::MethodId::CONSUMER_RESUME }
};
......
......@@ -341,55 +341,6 @@ namespace RTC
break;
}
case Channel::Request::MethodId::CONSUMER_ENABLE:
{
// RTC::Consumer* consumer;
// try
// {
// consumer = GetConsumerFromRequest(request);
// }
// catch (const MediaSoupError& error)
// {
// request->Reject(error.what());
// return;
// }
// if (consumer == nullptr)
// {
// request->Reject("Consumer does not exist");
// return;
// }
// RTC::Transport* transport;
// try
// {
// transport = GetTransportFromRequest(request);
// }
// catch (const MediaSoupError& error)
// {
// request->Reject(error.what());
// return;
// }
// if (transport == nullptr)
// {
// request->Reject("Transport does not exist");
// return;
// }
// consumer->SetTransport(transport);
request->Accept();
break;
}
case Channel::Request::MethodId::CONSUMER_DUMP:
case Channel::Request::MethodId::CONSUMER_PAUSE:
case Channel::Request::MethodId::CONSUMER_RESUME:
......
......@@ -161,21 +161,6 @@ namespace RTC
switch (request->methodId)
{
case Channel::Request::MethodId::ROUTER_CLOSE:
{
#ifdef MS_LOG_DEV
uint32_t routerId = this->routerId;
#endif
Destroy();
MS_DEBUG_DEV("Router closed [routerId:%" PRIu32 "]", routerId);
request->Accept();
break;
}
case Channel::Request::MethodId::ROUTER_DUMP:
{
auto json = ToJson();
......@@ -230,6 +215,87 @@ namespace RTC
break;
}
case Channel::Request::MethodId::ROUTER_CREATE_PRODUCER:
{
static const Json::StaticString JsonStringKind{ "kind" };
RTC::Producer* producer;
RTC::Transport* transport;
uint32_t producerId;
try
{
producer = GetProducerFromRequest(request, &producerId);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (producer != nullptr)
{
request->Reject("Producer 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;
}
// kind is mandatory.
if (!request->data[JsonStringKind].isString())
MS_THROW_ERROR("missing kind");
std::string kind = request->data[JsonStringKind].asString();
// Create a Producer instance.
try
{
producer = new RTC::Producer(this, this->notifier, producerId, RTC::Media::GetKind(kind));
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
this->producers[producerId] = producer;
MS_DEBUG_DEV("Producer created [producerId:%" PRIu32 "]", producerId);
// Set the Transport.
producer->SetTransport(transport);
request->Accept();
break;
}
case Channel::Request::MethodId::ROUTER_CREATE_CONSUMER:
{
// TODO
break;
}
case Channel::Request::MethodId::ROUTER_SET_AUDIO_LEVELS_EVENT:
{
static const Json::StaticString JsonStringEnabled{ "enabled" };
......@@ -263,28 +329,157 @@ namespace RTC
}
case Channel::Request::MethodId::TRANSPORT_CLOSE:
{
RTC::Transport* transport;
try
{
transport = GetTransportFromRequest(request);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (transport == nullptr)
{
request->Reject("Transport does not exist");
return;
}
transport->Destroy();
break;
}
case Channel::Request::MethodId::TRANSPORT_DUMP:
case Channel::Request::MethodId::TRANSPORT_SET_REMOTE_DTLS_PARAMETERS:
case Channel::Request::MethodId::TRANSPORT_SET_MAX_BITRATE:
case Channel::Request::MethodId::TRANSPORT_CHANGE_UFRAG_PWD:
{
RTC::Transport* transport;
try
{
transport = GetTransportFromRequest(request);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (transport == nullptr)
{
request->Reject("Transport does not exist");
return;
}
transport->HandleRequest(request);
break;
}
case Channel::Request::MethodId::PRODUCER_CLOSE:
{
RTC::Producer* producer;
try
{
producer = GetProducerFromRequest(request);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (producer == nullptr)
{
request->Reject("Producer does not exist");
return;
}
producer->Destroy();
break;
}
case Channel::Request::MethodId::PRODUCER_DUMP:
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_OBJECT_EVENT:
{
RTC::Producer* producer;
try
{
producer = GetProducerFromRequest(request);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (producer == nullptr)
{
request->Reject("Producer does not exist");
return;
}
producer->HandleRequest(request);
break;
}
case Channel::Request::MethodId::CONSUMER_CLOSE:
{
RTC::Consumer* consumer;
try
{
consumer = GetConsumerFromRequest(request);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (consumer == nullptr)
{
request->Reject("Consumer does not exist");
return;
}
consumer->Destroy();
break;
}
case Channel::Request::MethodId::CONSUMER_DUMP:
case Channel::Request::MethodId::CONSUMER_ENABLE:
case Channel::Request::MethodId::CONSUMER_PAUSE:
case Channel::Request::MethodId::CONSUMER_RESUME:
{
RTC::Peer* peer;
RTC::Consumer* consumer;
try
{
peer = GetPeerFromRequest(request);
consumer = GetConsumerFromRequest(request);
}
catch (const MediaSoupError& error)
{
......@@ -293,14 +488,14 @@ namespace RTC
return;
}
if (peer == nullptr)
if (consumer == nullptr)
{
request->Reject("Peer does not exist");
request->Reject("Consumer does not exist");
return;
}
peer->HandleRequest(request);
consumer->HandleRequest(request);
break;
}
......
#define MS_CLASS "Loop"
#define MS_CLASS "Worker"
// #define MS_LOG_DEV
#include "Loop.hpp"
#include "Worker.hpp"
#include "DepLibUV.hpp"
#include "Logger.hpp"
#include "MediaSoupError.hpp"
......@@ -14,7 +14,7 @@
/* Instance methods. */
Loop::Loop(Channel::UnixStreamSocket* channel) : channel(channel)
Worker::Worker(Channel::UnixStreamSocket* channel) : channel(channel)
{
MS_TRACE();
......@@ -36,12 +36,12 @@ Loop::Loop(Channel::UnixStreamSocket* channel) : channel(channel)
MS_DEBUG_DEV("libuv loop ended");
}
Loop::~Loop()
Worker::~Worker()
{
MS_TRACE();
}
void Loop::Close()
void Worker::Close()
{
MS_TRACE();
......@@ -78,7 +78,7 @@ void Loop::Close()
this->channel->Destroy();
}
RTC::Router* Loop::GetRouterFromRequest(Channel::Request* request, uint32_t* routerId)
RTC::Router* Worker::GetRouterFromRequest(Channel::Request* request, uint32_t* routerId)
{
MS_TRACE();
......@@ -104,7 +104,7 @@ RTC::Router* Loop::GetRouterFromRequest(Channel::Request* request, uint32_t* rou
return nullptr;
}
void Loop::OnSignal(SignalsHandler* /*signalsHandler*/, int signum)
void Worker::OnSignal(SignalsHandler* /*signalsHandler*/, int signum)
{
MS_TRACE();
......@@ -125,7 +125,7 @@ void Loop::OnSignal(SignalsHandler* /*signalsHandler*/, int signum)
}
}
void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Request* request)
void Worker::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Request* request)
{
MS_TRACE();
......@@ -210,6 +210,32 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req
}
case Channel::Request::MethodId::ROUTER_CLOSE:
{
RTC::Router* router;
try
{
router = GetRouterFromRequest(request);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (router == nullptr)
{
request->Reject("Router does not exist");
return;
}
router->Destroy();
break;
}
case Channel::Request::MethodId::ROUTER_DUMP:
case Channel::Request::MethodId::ROUTER_CREATE_TRANSPORT:
case Channel::Request::MethodId::ROUTER_CREATE_PRODUCER:
......@@ -229,7 +255,6 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req
case Channel::Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT:
case Channel::Request::MethodId::CONSUMER_CLOSE:
case Channel::Request::MethodId::CONSUMER_DUMP:
case Channel::Request::MethodId::CONSUMER_ENABLE:
case Channel::Request::MethodId::CONSUMER_PAUSE:
case Channel::Request::MethodId::CONSUMER_RESUME:
{
......@@ -267,7 +292,7 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req
}
}
void Loop::OnChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* /*socket*/)
void Worker::OnChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* /*socket*/)
{
MS_TRACE_STD();
......@@ -282,7 +307,7 @@ void Loop::OnChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* /*
Close();
}
void Loop::OnRouterClosed(RTC::Router* router)
void Worker::OnRouterClosed(RTC::Router* router)
{
MS_TRACE();
......
......@@ -6,7 +6,7 @@
#include "DepLibUV.hpp"
#include "DepOpenSSL.hpp"
#include "Logger.hpp"
#include "Loop.hpp"
#include "Worker.hpp"
#include "MediaSoupError.hpp"
#include "Settings.hpp"
#include "Utils.hpp"
......@@ -46,7 +46,7 @@ int main(int argc, char* argv[])
// Initialize libuv stuff (we need it for the Channel).
DepLibUV::ClassInit();
// Set the Channel socket (this will be handled and deleted by the Loop).
// Set the Channel socket (this will be handled and deleted by the Worker).
auto* channel = new Channel::UnixStreamSocket(channelFd);
// Initialize the Logger.
......@@ -87,10 +87,10 @@ int main(int argc, char* argv[])
{
init();
// Run the Loop.
Loop loop(channel);
// Run the Worker.
Worker worker(channel);
// Loop ended.
// Worker ended.
destroy();
exitSuccess();
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论