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

Create a separate RtcListener class.

上级 d8b2c529
...@@ -60,9 +60,6 @@ signalingServer.on('invite', (request) => ...@@ -60,9 +60,6 @@ signalingServer.on('invite', (request) =>
}); });
// Set remote DTLS parameters. // Set remote DTLS parameters.
// `transport.setRemoteDtlsParameters()` returns a Promise that resolves
// with `transport` itself so it can be handled in the next `then()`
// handler.
return transport.setRemoteDtlsParameters( return transport.setRemoteDtlsParameters(
{ {
role : request.dtlsRole, role : request.dtlsRole,
...@@ -71,20 +68,20 @@ signalingServer.on('invite', (request) => ...@@ -71,20 +68,20 @@ signalingServer.on('invite', (request) =>
algorithm : request.remoteFingerprint.type, algorithm : request.remoteFingerprint.type,
value : request.remoteFingerprint.hash value : request.remoteFingerprint.hash
} }
}); })
}) .then(() =>
.then((transport) => {
{ // Set our DTLS parameters into the response.
// Set our DTLS parameters into the response. response.dtlsRole = transport.dtlsLocalParameters.role;
response.dtlsRole = transport.dtlsLocalParameters.role; response.fingerprint =
response.fingerprint = {
{ type : 'sha-512',
type : 'sha-512', hash : transport.dtlsLocalParameters.fingerprints['sha-512']
hash : transport.dtlsLocalParameters.fingerprints['sha-512'] };
};
// And send the response. // And send the response.
signalingServer.send(response); signalingServer.send(response);
});
}); });
}); });
``` ```
......
...@@ -253,13 +253,13 @@ class Channel extends EventEmitter ...@@ -253,13 +253,13 @@ class Channel extends EventEmitter
} }
} }
// If a Notification emit it to the corresponding entity // If a Notification emit it to the corresponding entity
else if (msg.targetId && msg.eventName) else if (msg.targetId && msg.event)
{ {
let targetId = msg.targetId; let targetId = msg.targetId;
let eventName = msg.eventName; let event = msg.event;
// Emit it // Emit it
this.emit(targetId, eventName, msg.eventData); this.emit(targetId, event, msg.data);
} }
// Otherwise unexpected message // Otherwise unexpected message
else else
......
...@@ -184,31 +184,31 @@ app.put('/test-transport', function(req) ...@@ -184,31 +184,31 @@ app.put('/test-transport', function(req)
preferIPv6 : true, preferIPv6 : true,
preferTcp : true preferTcp : true
}) })
.then((transport) => .then((transport) =>
{
transport.on('close', () =>
{ {
debug('transport "close" event'); transport.on('close', () =>
}); {
debug('transport "close" event');
});
transport.on('iceselectedtuplechange', (data) => transport.on('iceselectedtuplechange', (data) =>
{ {
debug('transport "iceselectedtuplechange" event [data.iceSelectedTuple:%o, transport.iceSelectedTuple:%o]', data.iceSelectedTuple, transport.iceSelectedTuple); debug('transport "iceselectedtuplechange" event [data.iceSelectedTuple:%o, transport.iceSelectedTuple:%o]', data.iceSelectedTuple, transport.iceSelectedTuple);
}); });
transport.on('icestatechange', (data) => transport.on('icestatechange', (data) =>
{ {
debug('transport "icestatechange" event [data.iceState:%s, transport.iceState:%s]', data.iceState, transport.iceState); debug('transport "icestatechange" event [data.iceState:%s, transport.iceState:%s]', data.iceState, transport.iceState);
}); });
transport.on('dtlsstatechange', (data) => transport.on('dtlsstatechange', (data) =>
{ {
debug('transport "dtlsstatechange" event [data.dtlsState:%s, transport.dtlsState:%s]', data.dtlsState, transport.dtlsState); debug('transport "dtlsstatechange" event [data.dtlsState:%s, transport.dtlsState:%s]', data.dtlsState, transport.dtlsState);
}); });
return transport; return transport;
}) })
.catch((error) => debugerror('SOMETHING FAILED: %s]', error)); .catch((error) => debugerror('SOMETHING FAILED: %s]', error));
// Add the transport promise to the array of promises // Add the transport promise to the array of promises
transportPromises.push(promise); transportPromises.push(promise);
......
...@@ -16,8 +16,8 @@ namespace Channel ...@@ -16,8 +16,8 @@ namespace Channel
void Close(); void Close();
void Emit(uint32_t targetId, std::string eventName); void Emit(uint32_t targetId, std::string event);
void Emit(uint32_t targetId, std::string eventName, Json::Value& eventData); void Emit(uint32_t targetId, std::string event, Json::Value& data);
public: public:
// Passed by argument. // Passed by argument.
......
...@@ -57,7 +57,7 @@ namespace RTC ...@@ -57,7 +57,7 @@ namespace RTC
uint16_t GetSequenceNumber(); uint16_t GetSequenceNumber();
uint32_t GetTimestamp(); uint32_t GetTimestamp();
uint32_t GetSSRC(); uint32_t GetSSRC();
void SetSSRC(uint32_t ssrc); void SetSSRC(uint32_t ssrc); // TODO: yes?
bool HasExtensionHeader(); bool HasExtensionHeader();
uint16_t GetExtensionHeaderId(); uint16_t GetExtensionHeaderId();
size_t GetExtensionHeaderLength(); size_t GetExtensionHeaderLength();
...@@ -138,19 +138,19 @@ namespace RTC ...@@ -138,19 +138,19 @@ namespace RTC
inline inline
uint16_t RTPPacket::GetSequenceNumber() uint16_t RTPPacket::GetSequenceNumber()
{ {
return ntohs(this->header->sequence_number); return (uint16_t)ntohs(this->header->sequence_number);
} }
inline inline
uint32_t RTPPacket::GetTimestamp() uint32_t RTPPacket::GetTimestamp()
{ {
return ntohl(this->header->timestamp); return (uint32_t)ntohl(this->header->timestamp);
} }
inline inline
uint32_t RTPPacket::GetSSRC() uint32_t RTPPacket::GetSSRC()
{ {
return ntohl(this->header->ssrc); return (uint32_t)ntohl(this->header->ssrc);
} }
// TODO temp // TODO temp
......
#ifndef MS_RTC_RTP_LISTENER_H
#define MS_RTC_RTP_LISTENER_H
#include "common.h"
#include "RTC/RTPPacket.h"
#include "RTC/RtpReceiver.h"
#include <unordered_map>
#include <json/json.h>
namespace RTC
{
class RtpListener :
public RTC::RtpReceiver::RtpListener
{
public:
RtpListener();
~RtpListener();
Json::Value toJson();
private:
void RemoveRtpReceiverFromRtpListener(RTC::RtpReceiver* rtpReceiver);
public:
/* Pure virtual methods inherited from RTC::RtpReceiver::RtpListener. */
virtual void onRtpListenerParameters(RTC::RtpReceiver* rtpReceiver, RTC::RtpParameters* rtpParameters) override;
virtual void onRtpReceiverClosed(RTC::RtpReceiver* rtpReceiver) override;
private:
// Others.
// - Table of SSRC / RtpReceiver pairs.
std::unordered_map<uint32_t, RTC::RtpReceiver*> ssrcTable;
// - Table of MID RTP header extension / RtpReceiver pairs.
// std::unordered_map<uint16_t, RTC::RtpReceiver*> midTable;
// - Table of RTP payload type / RtpReceiver pairs.
std::unordered_map<uint8_t, RTC::RtpReceiver*> ptTable;
};
}
#endif
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define MS_RTC_TRANSPORT_H #define MS_RTC_TRANSPORT_H
#include "common.h" #include "common.h"
#include "RTC/RtpListener.h"
#include "RTC/UDPSocket.h" #include "RTC/UDPSocket.h"
#include "RTC/TCPServer.h" #include "RTC/TCPServer.h"
#include "RTC/TCPConnection.h" #include "RTC/TCPConnection.h"
...@@ -23,12 +24,12 @@ ...@@ -23,12 +24,12 @@
namespace RTC namespace RTC
{ {
class Transport : class Transport :
public RTC::RtpListener,
public RTC::UDPSocket::Listener, public RTC::UDPSocket::Listener,
public RTC::TCPServer::Listener, public RTC::TCPServer::Listener,
public RTC::TCPConnection::Listener, public RTC::TCPConnection::Listener,
public RTC::ICEServer::Listener, public RTC::ICEServer::Listener,
public RTC::DTLSTransport::Listener, public RTC::DTLSTransport::Listener
public RTC::RtpReceiver::RtpListener
{ {
public: public:
class Listener class Listener
...@@ -37,17 +38,6 @@ namespace RTC ...@@ -37,17 +38,6 @@ namespace RTC
virtual void onTransportClosed(RTC::Transport* transport) = 0; virtual void onTransportClosed(RTC::Transport* transport) = 0;
}; };
private:
struct RtpListener
{
// - Table of SSRC / RtpReceiver pairs.
std::unordered_map<uint32_t, RTC::RtpReceiver*> ssrcTable;
// - Table of MID RTP header extension / RtpReceiver pairs.
// std::unordered_map<uint16_t, RTC::RtpReceiver*> midTable;
// - Table of RTP payload type / RtpReceiver pairs.
std::unordered_map<uint8_t, RTC::RtpReceiver*> ptTable;
};
public: public:
Transport(Listener* listener, Channel::Notifier* notifier, uint32_t transportId, Json::Value& data, Transport* rtpTransport = nullptr); Transport(Listener* listener, Channel::Notifier* notifier, uint32_t transportId, Json::Value& data, Transport* rtpTransport = nullptr);
virtual ~Transport(); virtual ~Transport();
...@@ -61,7 +51,6 @@ namespace RTC ...@@ -61,7 +51,6 @@ namespace RTC
private: private:
void MayRunDTLSTransport(); void MayRunDTLSTransport();
void RemoveRtpReceiverFromRtpListener(RTC::RtpReceiver* rtpReceiver);
/* Private methods to unify UDP and TCP behavior. */ /* Private methods to unify UDP and TCP behavior. */
private: private:
...@@ -100,10 +89,6 @@ namespace RTC ...@@ -100,10 +89,6 @@ namespace RTC
virtual void onOutgoingDTLSData(RTC::DTLSTransport* dtlsTransport, const uint8_t* data, size_t len) override; virtual void onOutgoingDTLSData(RTC::DTLSTransport* dtlsTransport, const uint8_t* data, size_t len) override;
virtual void onDTLSApplicationData(RTC::DTLSTransport* dtlsTransport, const uint8_t* data, size_t len) override; virtual void onDTLSApplicationData(RTC::DTLSTransport* dtlsTransport, const uint8_t* data, size_t len) override;
/* Pure virtual methods inherited from RTC::RtpReceiver::RtpListener. */
virtual void onRtpListenerParameters(RTC::RtpReceiver* rtpReceiver, RTC::RtpParameters* rtpParameters) override;
virtual void onRtpReceiverClosed(RTC::RtpReceiver* rtpReceiver) override;
public: public:
// Passed by argument. // Passed by argument.
uint32_t transportId; uint32_t transportId;
...@@ -132,8 +117,6 @@ namespace RTC ...@@ -132,8 +117,6 @@ namespace RTC
// Others (DTLS). // Others (DTLS).
bool remoteDtlsParametersGiven = false; bool remoteDtlsParametersGiven = false;
RTC::DTLSTransport::Role dtlsLocalRole = RTC::DTLSTransport::Role::AUTO; RTC::DTLSTransport::Role dtlsLocalRole = RTC::DTLSTransport::Role::AUTO;
// Others (RTP listener).
RtpListener rtpListener;
}; };
/* Inline methods. */ /* Inline methods. */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define MS_SETTINGS_H #define MS_SETTINGS_H
#include "common.h" #include "common.h"
#include "logLevel.h" #include "LogLevel.h"
#include "Channel/Request.h" #include "Channel/Request.h"
#include <map> #include <map>
#include <string> #include <string>
......
#ifndef MS_COMMON_H #ifndef MS_COMMON_H
#define MS_COMMON_H #define MS_COMMON_H
#include <memory> // std::addressof()
#include <cstddef> // size_t #include <cstddef> // size_t
#include <cstdint> // uint8_t, etc #include <cstdint> // uint8_t, etc
#include <cinttypes> // PRIu64, etc #include <cinttypes> // PRIu64, etc
......
...@@ -5,10 +5,6 @@ ...@@ -5,10 +5,6 @@
namespace Channel namespace Channel
{ {
/* Static variables. */
static Json::Value empty_data(Json::objectValue);
/* Instance methods. */ /* Instance methods. */
Notifier::Notifier(Channel::UnixStreamSocket* channel) : Notifier::Notifier(Channel::UnixStreamSocket* channel) :
...@@ -29,30 +25,33 @@ namespace Channel ...@@ -29,30 +25,33 @@ namespace Channel
delete this; delete this;
} }
void Notifier::Emit(uint32_t targetId, std::string eventName) void Notifier::Emit(uint32_t targetId, std::string event)
{ {
MS_TRACE(); MS_TRACE();
Emit(targetId, eventName, empty_data); static Json::Value empty_data(Json::objectValue);
Emit(targetId, event, empty_data);
} }
void Notifier::Emit(uint32_t targetId, std::string eventName, Json::Value &eventData) void Notifier::Emit(uint32_t targetId, std::string event, Json::Value &data)
{ {
MS_TRACE(); MS_TRACE();
static Json::Value empty_data(Json::objectValue);
static const Json::StaticString k_targetId("targetId"); static const Json::StaticString k_targetId("targetId");
static const Json::StaticString k_eventName("eventName"); static const Json::StaticString k_event("event");
static const Json::StaticString k_eventData("eventData"); static const Json::StaticString k_data("data");
Json::Value json; Json::Value json(Json::objectValue);
json[k_targetId] = targetId; json[k_targetId] = (Json::UInt)targetId;
json[k_eventName] = eventName; json[k_event] = event;
if (eventData.isObject()) if (data.isObject())
json[k_eventData] = eventData; json[k_data] = data;
else else
json[k_eventData] = empty_data; json[k_data] = empty_data;
this->channel->Send(json); this->channel->Send(json);
} }
......
...@@ -6,10 +6,6 @@ ...@@ -6,10 +6,6 @@
namespace Channel namespace Channel
{ {
/* Static variables. */
static Json::Value empty_data(Json::objectValue);
/* Class variables. */ /* Class variables. */
std::unordered_map<std::string, Request::MethodId> Request::string2MethodId = std::unordered_map<std::string, Request::MethodId> Request::string2MethodId =
...@@ -88,6 +84,8 @@ namespace Channel ...@@ -88,6 +84,8 @@ namespace Channel
{ {
MS_TRACE(); MS_TRACE();
static Json::Value empty_data(Json::objectValue);
Accept(empty_data); Accept(empty_data);
} }
...@@ -95,16 +93,17 @@ namespace Channel ...@@ -95,16 +93,17 @@ namespace Channel
{ {
MS_TRACE(); MS_TRACE();
MS_ASSERT(!this->replied, "Request already replied"); static Json::Value empty_data(Json::objectValue);
this->replied = true;
static const Json::StaticString k_id("id"); static const Json::StaticString k_id("id");
static const Json::StaticString k_accepted("accepted"); static const Json::StaticString k_accepted("accepted");
static const Json::StaticString k_data("data"); static const Json::StaticString k_data("data");
Json::Value json; MS_ASSERT(!this->replied, "Request already replied");
this->replied = true;
json[k_id] = this->id; Json::Value json(Json::objectValue);
json[k_id] = (Json::UInt)this->id;
json[k_accepted] = true; json[k_accepted] = true;
if (data.isObject()) if (data.isObject())
...@@ -130,16 +129,16 @@ namespace Channel ...@@ -130,16 +129,16 @@ namespace Channel
{ {
MS_TRACE(); MS_TRACE();
MS_ASSERT(!this->replied, "Request already replied");
this->replied = true;
static const Json::StaticString k_id("id"); static const Json::StaticString k_id("id");
static const Json::StaticString k_rejected("rejected"); static const Json::StaticString k_rejected("rejected");
static const Json::StaticString k_reason("reason"); static const Json::StaticString k_reason("reason");
Json::Value json; MS_ASSERT(!this->replied, "Request already replied");
this->replied = true;
Json::Value json(Json::objectValue);
json[k_id] = this->id; json[k_id] = (Json::UInt)this->id;
json[k_rejected] = true; json[k_rejected] = true;
if (reason) if (reason)
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "RTC/ICEServer.h" #include "RTC/ICEServer.h"
#include "Logger.h" #include "Logger.h"
#include <memory> // std::addressof()
namespace RTC namespace RTC
{ {
......
...@@ -39,12 +39,12 @@ namespace RTC ...@@ -39,12 +39,12 @@ namespace RTC
static const Json::StaticString k_tcpType("tcpType"); static const Json::StaticString k_tcpType("tcpType");
static const Json::StaticString v_passive("passive"); static const Json::StaticString v_passive("passive");
Json::Value json; Json::Value json(Json::objectValue);
json[k_foundation] = this->foundation; json[k_foundation] = this->foundation;
json[k_priority] = this->priority; json[k_priority] = (Json::UInt)this->priority;
json[k_ip] = this->ip; json[k_ip] = this->ip;
json[k_port] = this->port; json[k_port] = (Json::UInt)this->port;
switch (this->type) switch (this->type)
{ {
......
#define MS_CLASS "RTC::RtpListener"
#include "RTC/RtpListener.h"
#include "Logger.h"
#include <string>
namespace RTC
{
/* Instance methods. */
RtpListener::RtpListener()
{
MS_TRACE();
}
RtpListener::~RtpListener()
{
MS_TRACE();
}
Json::Value RtpListener::toJson()
{
MS_TRACE();
static const Json::StaticString k_ssrcTable("ssrcTable");
// static const Json::StaticString k_midTable("midTable"); // TODO
static const Json::StaticString k_ptTable("ptTable");
Json::Value json(Json::objectValue);
// Add `ssrcTable`.
Json::Value json_ssrcTable(Json::objectValue);
for (auto& kv : this->ssrcTable)
{
auto ssrc = kv.first;
auto rtpReceiver = kv.second;
json_ssrcTable[std::to_string(ssrc)] = std::to_string(rtpReceiver->rtpReceiverId);
}
json[k_ssrcTable] = json_ssrcTable;
// TODO: Add `midTable`.
// Add `ptTable`.
Json::Value json_ptTable(Json::objectValue);
for (auto& kv : this->ptTable)
{
auto payloadType = kv.first;
auto rtpReceiver = kv.second;
json_ptTable[std::to_string(payloadType)] = std::to_string(rtpReceiver->rtpReceiverId);
}
json[k_ptTable] = json_ptTable;
return json;
}
inline
void RtpListener::RemoveRtpReceiverFromRtpListener(RTC::RtpReceiver* rtpReceiver)
{
MS_TRACE();
for (auto it = this->ssrcTable.begin(); it != this->ssrcTable.end();)
{
if (it->second == rtpReceiver)
it = this->ssrcTable.erase(it);
else
it++;
}
// TODO: midTable
for (auto it = this->ptTable.begin(); it != this->ptTable.end();)
{
if (it->second == rtpReceiver)
it = this->ptTable.erase(it);
else
it++;
}
}
void RtpListener::onRtpListenerParameters(RTC::RtpReceiver* rtpReceiver, RTC::RtpParameters* rtpParameters)
{
MS_TRACE();
// First remove from the rtpListener all the entries pointing to the given rtpReceiver.
RemoveRtpReceiverFromRtpListener(rtpReceiver);
// Add entries into ssrcTable.
for (auto& encoding : rtpParameters->encodings)
{
// TODO: This should throw if the ssrc already exists in the table,
// and the receive() should Reject() the Request.
if (encoding.ssrc)
this->ssrcTable[encoding.ssrc] = rtpReceiver;
}
// TODO: // Add entries into midTable.
// Add entries into ptTable.
// TODO: This is wrong, pt should not be added if ssrc are added.
for (auto& codec : rtpParameters->codecs)
{
this->ptTable[codec.payloadType] = rtpReceiver;
}
}
void RtpListener::onRtpReceiverClosed(RTC::RtpReceiver* rtpReceiver)
{
MS_TRACE();
// Remove from the rtpListener all the entries pointing to the given rtpReceiver.
RemoveRtpReceiverFromRtpListener(rtpReceiver);
}
}
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
// #include "Utils.h" // TODO: let's see // #include "Utils.h" // TODO: let's see
#include "MediaSoupError.h" #include "MediaSoupError.h"
#include "Logger.h" #include "Logger.h"
#include <memory> // std::addressof()
namespace RTC namespace RTC
{ {
...@@ -57,7 +56,7 @@ namespace RTC ...@@ -57,7 +56,7 @@ namespace RTC
static const Json::StaticString k_encodings("encodings"); static const Json::StaticString k_encodings("encodings");
static const Json::StaticString k_ssrc("ssrc"); static const Json::StaticString k_ssrc("ssrc");
Json::Value json; Json::Value json(Json::objectValue);
// Add `muxId`. // Add `muxId`.
json[k_muxId] = this->muxId; json[k_muxId] = this->muxId;
......
...@@ -45,14 +45,15 @@ namespace RTC ...@@ -45,14 +45,15 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static Json::Value null_data(Json::nullValue);
static const Json::StaticString k_rtpParameters("rtpParameters"); static const Json::StaticString k_rtpParameters("rtpParameters");
Json::Value json; Json::Value json(Json::objectValue);
if (this->rtpParameters) if (this->rtpParameters)
json[k_rtpParameters] = this->rtpParameters->toJson(); json[k_rtpParameters] = this->rtpParameters->toJson();
else else
json[k_rtpParameters] = Json::nullValue; json[k_rtpParameters] = null_data;
return json; return json;
} }
......
...@@ -292,11 +292,8 @@ namespace RTC ...@@ -292,11 +292,8 @@ namespace RTC
static const Json::StaticString v_closed("closed"); static const Json::StaticString v_closed("closed");
static const Json::StaticString v_failed("failed"); static const Json::StaticString v_failed("failed");
static const Json::StaticString k_rtpListener("rtpListener"); static const Json::StaticString k_rtpListener("rtpListener");
static const Json::StaticString k_ssrcTable("ssrcTable");
// static const Json::StaticString k_midTable("midTable"); // TODO
static const Json::StaticString k_ptTable("ptTable");
Json::Value json; Json::Value json(Json::objectValue);
// Add `iceRole` (we are always "controlled"). // Add `iceRole` (we are always "controlled").
json[k_iceRole] = v_controlled; json[k_iceRole] = v_controlled;
...@@ -378,31 +375,8 @@ namespace RTC ...@@ -378,31 +375,8 @@ namespace RTC
break; break;
} }
// Add `rtpListener.ssrcTable`. // Add `rtpListener`.
Json::Value json_ssrcTable(Json::objectValue); json[k_rtpListener] = RTC::RtpListener::toJson();
for (auto& kv : this->rtpListener.ssrcTable)
{
auto ssrc = kv.first;
auto rtpReceiver = kv.second;
json_ssrcTable[std::to_string(ssrc)] = std::to_string(rtpReceiver->rtpReceiverId);
}
json[k_rtpListener][k_ssrcTable] = json_ssrcTable;
// TODO: Add `midTable`.
// Add `rtpListener.ptTable`.
Json::Value json_ptTable(Json::objectValue);
for (auto& kv : this->rtpListener.ptTable)
{
auto payloadType = kv.first;
auto rtpReceiver = kv.second;
json_ptTable[std::to_string(payloadType)] = std::to_string(rtpReceiver->rtpReceiverId);
}
json[k_rtpListener][k_ptTable] = json_ptTable;
return json; return json;
} }
...@@ -511,7 +485,7 @@ namespace RTC ...@@ -511,7 +485,7 @@ namespace RTC
return; return;
} }
Json::Value data; Json::Value data(Json::objectValue);
switch (this->dtlsLocalRole) switch (this->dtlsLocalRole)
{ {
...@@ -549,12 +523,12 @@ namespace RTC ...@@ -549,12 +523,12 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static Json::Value nullData(Json::nullValue); static Json::Value null_data(Json::nullValue);
if (this->iceServer->GetComponent() != ICEServer::IceComponent::RTP) if (this->iceServer->GetComponent() != ICEServer::IceComponent::RTP)
MS_THROW_ERROR("cannot call CreateAssociatedTransport() on a RTCP Transport"); MS_THROW_ERROR("cannot call CreateAssociatedTransport() on a RTCP Transport");
return new RTC::Transport(this->listener, this->notifier, transportId, nullData, this); return new RTC::Transport(this->listener, this->notifier, transportId, null_data, this);
} }
inline inline
...@@ -612,30 +586,6 @@ namespace RTC ...@@ -612,30 +586,6 @@ namespace RTC
} }
} }
inline
void Transport::RemoveRtpReceiverFromRtpListener(RTC::RtpReceiver* rtpReceiver)
{
MS_TRACE();
for (auto it = this->rtpListener.ssrcTable.begin(); it != this->rtpListener.ssrcTable.end();)
{
if (it->second == rtpReceiver)
it = this->rtpListener.ssrcTable.erase(it);
else
it++;
}
// TODO: midTable
for (auto it = this->rtpListener.ptTable.begin(); it != this->rtpListener.ptTable.end();)
{
if (it->second == rtpReceiver)
it = this->rtpListener.ptTable.erase(it);
else
it++;
}
}
inline inline
void Transport::onPacketRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len) void Transport::onPacketRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len)
{ {
...@@ -731,6 +681,7 @@ namespace RTC ...@@ -731,6 +681,7 @@ namespace RTC
} }
// Trick for clients performing aggressive ICE regardless we are ICE-Lite. // Trick for clients performing aggressive ICE regardless we are ICE-Lite.
// TODO: Do this just after validating SRTP and so on.
this->iceServer->ForceSelectedTuple(tuple); this->iceServer->ForceSelectedTuple(tuple);
// TODO // TODO
...@@ -744,6 +695,16 @@ namespace RTC ...@@ -744,6 +695,16 @@ namespace RTC
return; return;
} }
packet->Dump(); packet->Dump();
// Check the rtpListener tables.
// auto it = this->rtpListener.ssrcTable.find(packet->GetSSRC());
// if (it == this->rtpListener.ssrcTable.end())
// {
// MS_WARN("received RTP packet does not belong to the SSRC table");
// }
delete packet; delete packet;
} }
...@@ -808,7 +769,7 @@ namespace RTC ...@@ -808,7 +769,7 @@ namespace RTC
static const Json::StaticString k_iceSelectedTuple("iceSelectedTuple"); static const Json::StaticString k_iceSelectedTuple("iceSelectedTuple");
Json::Value eventData; Json::Value event_data(Json::objectValue);
/* /*
* RFC 5245 section 11.2 "Receiving Media": * RFC 5245 section 11.2 "Receiving Media":
...@@ -821,8 +782,8 @@ namespace RTC ...@@ -821,8 +782,8 @@ namespace RTC
this->selectedTuple = tuple; this->selectedTuple = tuple;
// Notify. // Notify.
eventData[k_iceSelectedTuple] = tuple->toJson(); event_data[k_iceSelectedTuple] = tuple->toJson();
this->notifier->Emit(this->transportId, "iceselectedtuplechange", eventData); this->notifier->Emit(this->transportId, "iceselectedtuplechange", event_data);
} }
void Transport::onICEConnected(RTC::ICEServer* iceServer) void Transport::onICEConnected(RTC::ICEServer* iceServer)
...@@ -832,13 +793,13 @@ namespace RTC ...@@ -832,13 +793,13 @@ namespace RTC
static const Json::StaticString k_iceState("iceState"); static const Json::StaticString k_iceState("iceState");
static const Json::StaticString v_connected("connected"); static const Json::StaticString v_connected("connected");
Json::Value eventData; Json::Value event_data(Json::objectValue);
MS_DEBUG("ICE connected"); MS_DEBUG("ICE connected");
// Notify. // Notify.
eventData[k_iceState] = v_connected; event_data[k_iceState] = v_connected;
this->notifier->Emit(this->transportId, "icestatechange", eventData); this->notifier->Emit(this->transportId, "icestatechange", event_data);
// If ready, run the DTLS handler. // If ready, run the DTLS handler.
MayRunDTLSTransport(); MayRunDTLSTransport();
...@@ -851,13 +812,13 @@ namespace RTC ...@@ -851,13 +812,13 @@ namespace RTC
static const Json::StaticString k_iceState("iceState"); static const Json::StaticString k_iceState("iceState");
static const Json::StaticString v_completed("completed"); static const Json::StaticString v_completed("completed");
Json::Value eventData; Json::Value event_data(Json::objectValue);
MS_DEBUG("ICE completed"); MS_DEBUG("ICE completed");
// Notify. // Notify.
eventData[k_iceState] = v_completed; event_data[k_iceState] = v_completed;
this->notifier->Emit(this->transportId, "icestatechange", eventData); this->notifier->Emit(this->transportId, "icestatechange", event_data);
// If ready, run the DTLS handler. // If ready, run the DTLS handler.
MayRunDTLSTransport(); MayRunDTLSTransport();
...@@ -870,7 +831,7 @@ namespace RTC ...@@ -870,7 +831,7 @@ namespace RTC
static const Json::StaticString k_iceState("iceState"); static const Json::StaticString k_iceState("iceState");
static const Json::StaticString v_disconnected("disconnected"); static const Json::StaticString v_disconnected("disconnected");
Json::Value eventData; Json::Value event_data(Json::objectValue);
MS_DEBUG("ICE disconnected"); MS_DEBUG("ICE disconnected");
...@@ -878,8 +839,8 @@ namespace RTC ...@@ -878,8 +839,8 @@ namespace RTC
this->selectedTuple = nullptr; this->selectedTuple = nullptr;
// Notify. // Notify.
eventData[k_iceState] = v_disconnected; event_data[k_iceState] = v_disconnected;
this->notifier->Emit(this->transportId, "icestatechange", eventData); this->notifier->Emit(this->transportId, "icestatechange", event_data);
// This is a fatal error so close the transport. // This is a fatal error so close the transport.
Close(); Close();
...@@ -892,13 +853,13 @@ namespace RTC ...@@ -892,13 +853,13 @@ namespace RTC
static const Json::StaticString k_dtlsState("dtlsState"); static const Json::StaticString k_dtlsState("dtlsState");
static const Json::StaticString v_connecting("connecting"); static const Json::StaticString v_connecting("connecting");
Json::Value eventData; Json::Value event_data(Json::objectValue);
MS_DEBUG("DTLS connecting"); MS_DEBUG("DTLS connecting");
// Notify. // Notify.
eventData[k_dtlsState] = v_connecting; event_data[k_dtlsState] = v_connecting;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); this->notifier->Emit(this->transportId, "dtlsstatechange", event_data);
} }
void Transport::onDTLSConnected(RTC::DTLSTransport* dtlsTransport, RTC::SRTPSession::SRTPProfile srtp_profile, uint8_t* srtp_local_key, size_t srtp_local_key_len, uint8_t* srtp_remote_key, size_t srtp_remote_key_len) void Transport::onDTLSConnected(RTC::DTLSTransport* dtlsTransport, RTC::SRTPSession::SRTPProfile srtp_profile, uint8_t* srtp_local_key, size_t srtp_local_key_len, uint8_t* srtp_remote_key, size_t srtp_remote_key_len)
...@@ -908,7 +869,7 @@ namespace RTC ...@@ -908,7 +869,7 @@ namespace RTC
static const Json::StaticString k_dtlsState("dtlsState"); static const Json::StaticString k_dtlsState("dtlsState");
static const Json::StaticString v_connected("connected"); static const Json::StaticString v_connected("connected");
Json::Value eventData; Json::Value event_data(Json::objectValue);
MS_DEBUG("DTLS connected"); MS_DEBUG("DTLS connected");
...@@ -917,8 +878,8 @@ namespace RTC ...@@ -917,8 +878,8 @@ namespace RTC
// SetRemoteSRTPKey(srtp_profile, srtp_remote_key, srtp_remote_key_len); // SetRemoteSRTPKey(srtp_profile, srtp_remote_key, srtp_remote_key_len);
// Notify. // Notify.
eventData[k_dtlsState] = v_connected; event_data[k_dtlsState] = v_connected;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); this->notifier->Emit(this->transportId, "dtlsstatechange", event_data);
} }
void Transport::onDTLSFailed(RTC::DTLSTransport* dtlsTransport) void Transport::onDTLSFailed(RTC::DTLSTransport* dtlsTransport)
...@@ -928,13 +889,13 @@ namespace RTC ...@@ -928,13 +889,13 @@ namespace RTC
static const Json::StaticString k_dtlsState("dtlsState"); static const Json::StaticString k_dtlsState("dtlsState");
static const Json::StaticString v_failed("failed"); static const Json::StaticString v_failed("failed");
Json::Value eventData; Json::Value event_data(Json::objectValue);
MS_DEBUG("DTLS failed"); MS_DEBUG("DTLS failed");
// Notify. // Notify.
eventData[k_dtlsState] = v_failed; event_data[k_dtlsState] = v_failed;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); this->notifier->Emit(this->transportId, "dtlsstatechange", event_data);
// This is a fatal error so close the transport. // This is a fatal error so close the transport.
Close(); Close();
...@@ -947,13 +908,13 @@ namespace RTC ...@@ -947,13 +908,13 @@ namespace RTC
static const Json::StaticString k_dtlsState("dtlsState"); static const Json::StaticString k_dtlsState("dtlsState");
static const Json::StaticString v_closed("closed"); static const Json::StaticString v_closed("closed");
Json::Value eventData; Json::Value event_data(Json::objectValue);
MS_DEBUG("DTLS remotely closed"); MS_DEBUG("DTLS remotely closed");
// Notify. // Notify.
eventData[k_dtlsState] = v_closed; event_data[k_dtlsState] = v_closed;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); this->notifier->Emit(this->transportId, "dtlsstatechange", event_data);
// This is a fatal error so close the transport. // This is a fatal error so close the transport.
Close(); Close();
...@@ -985,35 +946,4 @@ namespace RTC ...@@ -985,35 +946,4 @@ namespace RTC
// TMP // TMP
MS_DEBUG("data: %s", std::string((char*)data, len).c_str()); MS_DEBUG("data: %s", std::string((char*)data, len).c_str());
} }
void Transport::onRtpListenerParameters(RTC::RtpReceiver* rtpReceiver, RTC::RtpParameters* rtpParameters)
{
MS_TRACE();
// First remove from the rtpListener all the entries pointing to the given rtpReceiver.
RemoveRtpReceiverFromRtpListener(rtpReceiver);
// Add entries into rtpListener.ssrcTable.
for (auto& encoding : rtpParameters->encodings)
{
if (encoding.ssrc)
this->rtpListener.ssrcTable[encoding.ssrc] = rtpReceiver;
}
// TODO: // Add entries into rtpListener.midTable.
// Add entries into rtpListener.ptTable.
for (auto& codec : rtpParameters->codecs)
{
this->rtpListener.ptTable[codec.payloadType] = rtpReceiver;
}
}
void Transport::onRtpReceiverClosed(RTC::RtpReceiver* rtpReceiver)
{
MS_TRACE();
// Remove from the rtpListener all the entries pointing to the given rtpReceiver.
RemoveRtpReceiverFromRtpListener(rtpReceiver);
}
} }
...@@ -21,16 +21,16 @@ namespace RTC ...@@ -21,16 +21,16 @@ namespace RTC
static const Json::StaticString v_udp("udp"); static const Json::StaticString v_udp("udp");
static const Json::StaticString v_tcp("tcp"); static const Json::StaticString v_tcp("tcp");
Json::Value json; Json::Value json(Json::objectValue);
Json::Value json_local; Json::Value json_local(Json::objectValue);
Json::Value json_remote; Json::Value json_remote(Json::objectValue);
int ip_family; int ip_family;
std::string ip; std::string ip;
uint16_t port; uint16_t port;
Utils::IP::GetAddressInfo(this->GetLocalAddress(), &ip_family, ip, &port); Utils::IP::GetAddressInfo(this->GetLocalAddress(), &ip_family, ip, &port);
json_local[k_ip] = ip; json_local[k_ip] = ip;
json_local[k_port] = port; json_local[k_port] = (Json::UInt)port;
if (this->GetProtocol() == RTC::TransportTuple::Protocol::UDP) if (this->GetProtocol() == RTC::TransportTuple::Protocol::UDP)
json_local[k_protocol] = v_udp; json_local[k_protocol] = v_udp;
else else
...@@ -38,7 +38,7 @@ namespace RTC ...@@ -38,7 +38,7 @@ namespace RTC
Utils::IP::GetAddressInfo(this->GetRemoteAddress(), &ip_family, ip, &port); Utils::IP::GetAddressInfo(this->GetRemoteAddress(), &ip_family, ip, &port);
json_remote[k_ip] = ip; json_remote[k_ip] = ip;
json_remote[k_port] = port; json_remote[k_port] = (Json::UInt)port;
if (this->GetProtocol() == RTC::TransportTuple::Protocol::UDP) if (this->GetProtocol() == RTC::TransportTuple::Protocol::UDP)
json_remote[k_protocol] = v_udp; json_remote[k_protocol] = v_udp;
else else
......
...@@ -56,7 +56,7 @@ void Timer::Start(uint64_t timeout) ...@@ -56,7 +56,7 @@ void Timer::Start(uint64_t timeout)
int err; int err;
err = uv_timer_start(this->uvHandle, (uv_timer_cb)on_timer, (uint64_t)timeout, 0); err = uv_timer_start(this->uvHandle, (uv_timer_cb)on_timer, timeout, 0);
if (err) if (err)
MS_THROW_ERROR("uv_timer_start() failed: %s", uv_strerror(err)); MS_THROW_ERROR("uv_timer_start() failed: %s", uv_strerror(err));
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论