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

foo

上级 cada4592
......@@ -32,7 +32,7 @@ namespace RTC
};
public:
Consumer(Listener* listener, Channel::Notifier* notifier, uint32_t consumerId, RTC::Media::Kind kind);
Consumer(Listener* listener, Channel::Notifier* notifier, uint32_t consumerId, RTC::Media::Kind kind, RTC::Transport* transport);
private:
virtual ~Consumer();
......@@ -42,10 +42,7 @@ namespace RTC
Json::Value ToJson() const;
void HandleRequest(Channel::Request* request);
void Send(RTC::RtpParameters* rtpParameters);
void SetTransport(RTC::Transport* transport);
RTC::Transport* GetTransport() const;
void RemoveTransport(RTC::Transport* transport);
RTC::RtpParameters* GetParameters() const;
RTC::RtpParameters* GetParameters() const; // TODO: What for?
bool GetEnabled() const;
void SendRtpPacket(RTC::RtpPacket* packet);
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
......@@ -83,25 +80,6 @@ namespace RTC
/* Inline methods. */
inline void Consumer::SetTransport(RTC::Transport* transport)
{
this->transport = transport;
}
inline RTC::Transport* Consumer::GetTransport() const
{
return this->transport;
}
inline void Consumer::RemoveTransport(RTC::Transport* transport)
{
if (this->transport == transport)
this->transport = nullptr;
// TODO: More. Remove rtpParameters.
}
// TODO: What for?
inline RTC::RtpParameters* Consumer::GetParameters() const
{
return this->rtpParameters;
......
......@@ -10,16 +10,13 @@
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpStreamRecv.hpp"
#include "RTC/Transport.hpp"
#include <json/json.h>
#include <map>
#include <string>
namespace RTC
{
// Avoid cyclic #include problem by declaring classes instead of including
// the corresponding header files.
class Transport;
class Producer : public RtpStreamRecv::Listener
{
public:
......@@ -50,16 +47,15 @@ namespace RTC
public:
Producer(Listener* listener, Channel::Notifier* notifier, uint32_t producerId, RTC::Media::Kind kind, RTC::Transport* transport);
private:
public:
// Must be public because Router needs to call it.
virtual ~Producer();
public:
void Destroy();
Json::Value ToJson() const;
void HandleRequest(Channel::Request* request);
RTC::Transport* GetTransport() const; // TODO: YES?
void RemoveTransport(RTC::Transport* transport); // TODO: better close this.
RTC::RtpParameters* GetParameters() const; // TODO: What for?
RTC::RtpParameters* GetParameters() const;
void ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
......@@ -105,17 +101,6 @@ namespace RTC
/* Inline methods. */
inline RTC::Transport* Producer::GetTransport() const
{
return this->transport;
}
inline void Producer::RemoveTransport(RTC::Transport* transport)
{
if (this->transport == transport)
this->transport = nullptr;
}
inline RTC::RtpParameters* Producer::GetParameters() const
{
return this->rtpParameters;
......
......@@ -2,7 +2,6 @@
#define MS_RTC_LISTENER_HPP
#include "common.hpp"
#include "RTC/Producer.hpp"
#include "RTC/RtpPacket.hpp"
#include <string>
#include <unordered_map>
......@@ -10,6 +9,10 @@
namespace RTC
{
// Avoid cyclic #include problem by declaring classes instead of including
// the corresponding header files.
class Producer;
class RtpListener
{
public:
......
......@@ -7,7 +7,6 @@
#include "RTC/DtlsTransport.hpp"
#include "RTC/IceCandidate.hpp"
#include "RTC/IceServer.hpp"
#include "RTC/Producer.hpp"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/Packet.hpp"
#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.hpp"
......@@ -21,10 +20,16 @@
#include "RTC/UdpSocket.hpp"
#include <json/json.h>
#include <string>
#include <unordered_set>
#include <vector>
namespace RTC
{
// Avoid cyclic #include problem by declaring classes instead of including
// the corresponding header files.
class Producer;
class Consumer;
class Transport : public RTC::UdpSocket::Listener,
public RTC::TcpServer::Listener,
public RTC::TcpConnection::Listener,
......@@ -49,8 +54,8 @@ namespace RTC
void Destroy();
Json::Value ToJson() const;
void HandleRequest(Channel::Request* request);
void AddProducer(RTC::Producer* producer);
void RemoveProducer(const RTC::Producer* producer);
void HandleProducer(RTC::Producer* producer);
void HandleConsumer(RTC::Consumer* consumer);
void SendRtpPacket(RTC::RtpPacket* packet);
void SendRtcpPacket(RTC::RTCP::Packet* packet);
void SendRtcpCompoundPacket(RTC::RTCP::CompoundPacket* packet);
......@@ -137,6 +142,9 @@ namespace RTC
RTC::SrtpSession* srtpSendSession{ nullptr };
// Others.
bool allocated{ false };
// Others (Producers and Consumers).
std::unordered_set<RTC::Producer*> producers;
std::unordered_set<RTC::Consumer*> consumers;
// Others (ICE).
std::vector<IceCandidate> iceLocalCandidates;
RTC::TransportTuple* selectedTuple{ nullptr };
......@@ -145,7 +153,7 @@ namespace RTC
RTC::DtlsTransport::Role dtlsLocalRole{ RTC::DtlsTransport::Role::AUTO };
// Others (RtpListener).
RtpListener rtpListener;
// REMB and bitrate stuff.
// Others (REMB and bitrate stuff).
std::unique_ptr<RTC::RemoteBitrateEstimatorAbsSendTime> remoteBitrateEstimator;
uint32_t maxBitrate{ 0 };
uint32_t effectiveMaxBitrate{ 0 };
......@@ -154,16 +162,6 @@ namespace RTC
/* Inline instance methods. */
inline void Transport::AddProducer(RTC::Producer* producer)
{
this->rtpListener.AddProducer(producer);
}
inline void Transport::RemoveProducer(const RTC::Producer* producer)
{
this->rtpListener.RemoveProducer(producer);
}
inline RTC::Producer* Transport::GetProducer(uint32_t ssrc)
{
return this->rtpListener.GetProducer(ssrc);
......
......@@ -18,8 +18,8 @@ namespace RTC
/* Instance methods. */
Consumer::Consumer(
Listener* listener, Channel::Notifier* notifier, uint32_t consumerId, RTC::Media::Kind kind)
: consumerId(consumerId), kind(kind), listener(listener), notifier(notifier)
Listener* listener, Channel::Notifier* notifier, uint32_t consumerId, RTC::Media::Kind kind, RTC::Transport* transport)
: consumerId(consumerId), kind(kind), listener(listener), notifier(notifier), transport(transport)
{
MS_TRACE();
......@@ -41,8 +41,6 @@ namespace RTC
{
MS_TRACE();
this->notifier->Emit(this->consumerId, "close");
// Notify the listener.
this->listener->OnConsumerClosed(this);
......
......@@ -7,7 +7,6 @@
#include "RTC/RTCP/FeedbackPsPli.hpp"
#include "RTC/RTCP/FeedbackRtp.hpp"
#include "RTC/RTCP/FeedbackRtpNack.hpp"
#include "RTC/Transport.hpp"
namespace RTC
{
......@@ -38,9 +37,6 @@ namespace RTC
{
MS_TRACE();
// Notify.
this->notifier->Emit(this->producerId, "close");
// Notify the listener.
this->listener->OnProducerClosed(this);
......@@ -54,13 +50,11 @@ namespace RTC
static const Json::StaticString JsonStringProducerId{ "producerId" };
static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" };
static const Json::StaticString JsonStringHasTransport{ "hasTransport" };
static const Json::StaticString JsonStringSsrcAudioLevelId{ "ssrcAudioLevelId" };
static const Json::StaticString JsonStringAbsSendTimeId{ "absSendTimeId" };
static const Json::StaticString JsonStringRtpRawEventEnabled{ "rtpRawEventEnabled" };
static const Json::StaticString JsonStringRtpObjectEventEnabled{ "rtpObjectEventEnabled" };
static const Json::StaticString JsonStringRtpStreams{ "rtpStreams" };
static const Json::StaticString JsonStringRtpStream{ "rtpStream" };
Json::Value json(Json::objectValue);
Json::Value jsonRtpStreams(Json::arrayValue);
......@@ -74,8 +68,6 @@ namespace RTC
else
json[JsonStringRtpParameters] = Json::nullValue;
json[JsonStringHasTransport] = this->transport != nullptr;
if (this->knownHeaderExtensions.ssrcAudioLevelId)
json[JsonStringSsrcAudioLevelId] = this->knownHeaderExtensions.ssrcAudioLevelId;
......@@ -157,12 +149,6 @@ namespace RTC
// NOTE: This may throw.
this->rtpParameters = new RTC::RtpParameters(request->data[JsonStringRtpParameters]);
auto transport = GetTransport();
// NOTE: This may throw.
if (transport != nullptr)
transport->AddProducer(this);
// NOTE: This may throw.
CreateRtpMapping(request->data[JsonStringRtpMapping]);
}
......
......@@ -277,6 +277,21 @@ namespace RTC
return;
}
// Tell the Transport to handle the new Producer.
try
{
// NOTE: This may throw.
transport->HandleProducer(producer);
}
catch (const MediaSoupError& error)
{
delete producer;
request->Reject(error.what());
return;
}
this->producers[producerId] = producer;
MS_DEBUG_DEV("Producer created [producerId:%" PRIu32 "]", producerId);
......
......@@ -4,6 +4,7 @@
#include "RTC/RtpListener.hpp"
#include "Logger.hpp"
#include "MediaSoupError.hpp"
#include "RTC/Producer.hpp"
namespace RTC
{
......@@ -22,7 +23,7 @@ namespace RTC
Json::Value jsonMuxIdTable(Json::objectValue);
Json::Value jsonPtTable(Json::objectValue);
// Add `ssrcTable`.
// Add ssrcTable.
for (auto& kv : this->ssrcTable)
{
auto ssrc = kv.first;
......@@ -32,7 +33,7 @@ namespace RTC
}
json[JsonStringSsrcTable] = jsonSsrcTable;
// Add `muxIdTable`.
// Add muxIdTable.
for (auto& kv : this->muxIdTable)
{
auto muxId = kv.first;
......@@ -42,7 +43,7 @@ namespace RTC
}
json[JsonStringMuxIdTable] = jsonMuxIdTable;
// Add `ptTable`.
// Add ptTable.
for (auto& kv : this->ptTable)
{
auto payloadType = kv.first;
......
......@@ -7,6 +7,8 @@
#include "MediaSoupError.hpp"
#include "Settings.hpp"
#include "Utils.hpp"
#include "RTC/Producer.hpp"
#include "RTC/Consumer.hpp"
#include "RTC/RTCP/FeedbackPsRemb.hpp"
#include <cmath> // std::pow()
#include <iterator> // std::ostream_iterator
......@@ -47,6 +49,16 @@ namespace RTC
{
MS_TRACE();
// TODO: TMP
for (auto& producer : this->producers)
{
producer->GetParameters();
}
for (auto& consumer : this->consumers)
{
consumer->GetParameters();
}
static const Json::StaticString JsonStringUdp{ "udp" };
static const Json::StaticString JsonStringTcp{ "tcp" };
static const Json::StaticString JsonStringPreferIPv4{ "preferIPv4" };
......@@ -583,6 +595,23 @@ namespace RTC
}
}
void Transport::HandleProducer(RTC::Producer* producer)
{
MS_TRACE();
// NOTE: This may throw.
this->rtpListener.AddProducer(producer);
// TODO: add to the map
}
void Transport::HandleConsumer(RTC::Consumer* consumer)
{
MS_TRACE();
// TODO
}
void Transport::SendRtpPacket(RTC::RtpPacket* packet)
{
MS_TRACE();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论