提交 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) =>
});
// 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(
{
role : request.dtlsRole,
......@@ -71,20 +68,20 @@ signalingServer.on('invite', (request) =>
algorithm : request.remoteFingerprint.type,
value : request.remoteFingerprint.hash
}
});
})
.then((transport) =>
{
// Set our DTLS parameters into the response.
response.dtlsRole = transport.dtlsLocalParameters.role;
response.fingerprint =
{
type : 'sha-512',
hash : transport.dtlsLocalParameters.fingerprints['sha-512']
};
})
.then(() =>
{
// Set our DTLS parameters into the response.
response.dtlsRole = transport.dtlsLocalParameters.role;
response.fingerprint =
{
type : 'sha-512',
hash : transport.dtlsLocalParameters.fingerprints['sha-512']
};
// And send the response.
signalingServer.send(response);
// And send the response.
signalingServer.send(response);
});
});
});
```
......
......@@ -253,13 +253,13 @@ class Channel extends EventEmitter
}
}
// 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 eventName = msg.eventName;
let event = msg.event;
// Emit it
this.emit(targetId, eventName, msg.eventData);
this.emit(targetId, event, msg.data);
}
// Otherwise unexpected message
else
......
......@@ -184,31 +184,31 @@ app.put('/test-transport', function(req)
preferIPv6 : true,
preferTcp : true
})
.then((transport) =>
{
transport.on('close', () =>
.then((transport) =>
{
debug('transport "close" event');
});
transport.on('close', () =>
{
debug('transport "close" event');
});
transport.on('iceselectedtuplechange', (data) =>
{
debug('transport "iceselectedtuplechange" event [data.iceSelectedTuple:%o, transport.iceSelectedTuple:%o]', data.iceSelectedTuple, transport.iceSelectedTuple);
});
transport.on('iceselectedtuplechange', (data) =>
{
debug('transport "iceselectedtuplechange" event [data.iceSelectedTuple:%o, transport.iceSelectedTuple:%o]', data.iceSelectedTuple, transport.iceSelectedTuple);
});
transport.on('icestatechange', (data) =>
{
debug('transport "icestatechange" event [data.iceState:%s, transport.iceState:%s]', data.iceState, transport.iceState);
});
transport.on('icestatechange', (data) =>
{
debug('transport "icestatechange" event [data.iceState:%s, transport.iceState:%s]', data.iceState, transport.iceState);
});
transport.on('dtlsstatechange', (data) =>
{
debug('transport "dtlsstatechange" event [data.dtlsState:%s, transport.dtlsState:%s]', data.dtlsState, transport.dtlsState);
});
transport.on('dtlsstatechange', (data) =>
{
debug('transport "dtlsstatechange" event [data.dtlsState:%s, transport.dtlsState:%s]', data.dtlsState, transport.dtlsState);
});
return transport;
})
.catch((error) => debugerror('SOMETHING FAILED: %s]', error));
return transport;
})
.catch((error) => debugerror('SOMETHING FAILED: %s]', error));
// Add the transport promise to the array of promises
transportPromises.push(promise);
......
......@@ -16,8 +16,8 @@ namespace Channel
void Close();
void Emit(uint32_t targetId, std::string eventName);
void Emit(uint32_t targetId, std::string eventName, Json::Value& eventData);
void Emit(uint32_t targetId, std::string event);
void Emit(uint32_t targetId, std::string event, Json::Value& data);
public:
// Passed by argument.
......
......@@ -57,7 +57,7 @@ namespace RTC
uint16_t GetSequenceNumber();
uint32_t GetTimestamp();
uint32_t GetSSRC();
void SetSSRC(uint32_t ssrc);
void SetSSRC(uint32_t ssrc); // TODO: yes?
bool HasExtensionHeader();
uint16_t GetExtensionHeaderId();
size_t GetExtensionHeaderLength();
......@@ -138,19 +138,19 @@ namespace RTC
inline
uint16_t RTPPacket::GetSequenceNumber()
{
return ntohs(this->header->sequence_number);
return (uint16_t)ntohs(this->header->sequence_number);
}
inline
uint32_t RTPPacket::GetTimestamp()
{
return ntohl(this->header->timestamp);
return (uint32_t)ntohl(this->header->timestamp);
}
inline
uint32_t RTPPacket::GetSSRC()
{
return ntohl(this->header->ssrc);
return (uint32_t)ntohl(this->header->ssrc);
}
// 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 @@
#define MS_RTC_TRANSPORT_H
#include "common.h"
#include "RTC/RtpListener.h"
#include "RTC/UDPSocket.h"
#include "RTC/TCPServer.h"
#include "RTC/TCPConnection.h"
......@@ -23,12 +24,12 @@
namespace RTC
{
class Transport :
public RTC::RtpListener,
public RTC::UDPSocket::Listener,
public RTC::TCPServer::Listener,
public RTC::TCPConnection::Listener,
public RTC::ICEServer::Listener,
public RTC::DTLSTransport::Listener,
public RTC::RtpReceiver::RtpListener
public RTC::DTLSTransport::Listener
{
public:
class Listener
......@@ -37,17 +38,6 @@ namespace RTC
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:
Transport(Listener* listener, Channel::Notifier* notifier, uint32_t transportId, Json::Value& data, Transport* rtpTransport = nullptr);
virtual ~Transport();
......@@ -61,7 +51,6 @@ namespace RTC
private:
void MayRunDTLSTransport();
void RemoveRtpReceiverFromRtpListener(RTC::RtpReceiver* rtpReceiver);
/* Private methods to unify UDP and TCP behavior. */
private:
......@@ -100,10 +89,6 @@ namespace RTC
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;
/* 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:
// Passed by argument.
uint32_t transportId;
......@@ -132,8 +117,6 @@ namespace RTC
// Others (DTLS).
bool remoteDtlsParametersGiven = false;
RTC::DTLSTransport::Role dtlsLocalRole = RTC::DTLSTransport::Role::AUTO;
// Others (RTP listener).
RtpListener rtpListener;
};
/* Inline methods. */
......
......@@ -2,7 +2,7 @@
#define MS_SETTINGS_H
#include "common.h"
#include "logLevel.h"
#include "LogLevel.h"
#include "Channel/Request.h"
#include <map>
#include <string>
......
#ifndef MS_COMMON_H
#define MS_COMMON_H
#include <memory> // std::addressof()
#include <cstddef> // size_t
#include <cstdint> // uint8_t, etc
#include <cinttypes> // PRIu64, etc
......
......@@ -5,10 +5,6 @@
namespace Channel
{
/* Static variables. */
static Json::Value empty_data(Json::objectValue);
/* Instance methods. */
Notifier::Notifier(Channel::UnixStreamSocket* channel) :
......@@ -29,30 +25,33 @@ namespace Channel
delete this;
}
void Notifier::Emit(uint32_t targetId, std::string eventName)
void Notifier::Emit(uint32_t targetId, std::string event)
{
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();
static Json::Value empty_data(Json::objectValue);
static const Json::StaticString k_targetId("targetId");
static const Json::StaticString k_eventName("eventName");
static const Json::StaticString k_eventData("eventData");
static const Json::StaticString k_event("event");
static const Json::StaticString k_data("data");
Json::Value json;
Json::Value json(Json::objectValue);
json[k_targetId] = targetId;
json[k_eventName] = eventName;
json[k_targetId] = (Json::UInt)targetId;
json[k_event] = event;
if (eventData.isObject())
json[k_eventData] = eventData;
if (data.isObject())
json[k_data] = data;
else
json[k_eventData] = empty_data;
json[k_data] = empty_data;
this->channel->Send(json);
}
......
......@@ -6,10 +6,6 @@
namespace Channel
{
/* Static variables. */
static Json::Value empty_data(Json::objectValue);
/* Class variables. */
std::unordered_map<std::string, Request::MethodId> Request::string2MethodId =
......@@ -88,6 +84,8 @@ namespace Channel
{
MS_TRACE();
static Json::Value empty_data(Json::objectValue);
Accept(empty_data);
}
......@@ -95,16 +93,17 @@ namespace Channel
{
MS_TRACE();
MS_ASSERT(!this->replied, "Request already replied");
this->replied = true;
static Json::Value empty_data(Json::objectValue);
static const Json::StaticString k_id("id");
static const Json::StaticString k_accepted("accepted");
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;
if (data.isObject())
......@@ -130,16 +129,16 @@ namespace Channel
{
MS_TRACE();
MS_ASSERT(!this->replied, "Request already replied");
this->replied = true;
static const Json::StaticString k_id("id");
static const Json::StaticString k_rejected("rejected");
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;
if (reason)
......
......@@ -2,7 +2,6 @@
#include "RTC/ICEServer.h"
#include "Logger.h"
#include <memory> // std::addressof()
namespace RTC
{
......
......@@ -39,12 +39,12 @@ namespace RTC
static const Json::StaticString k_tcpType("tcpType");
static const Json::StaticString v_passive("passive");
Json::Value json;
Json::Value json(Json::objectValue);
json[k_foundation] = this->foundation;
json[k_priority] = this->priority;
json[k_priority] = (Json::UInt)this->priority;
json[k_ip] = this->ip;
json[k_port] = this->port;
json[k_port] = (Json::UInt)this->port;
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 @@
// #include "Utils.h" // TODO: let's see
#include "MediaSoupError.h"
#include "Logger.h"
#include <memory> // std::addressof()
namespace RTC
{
......@@ -57,7 +56,7 @@ namespace RTC
static const Json::StaticString k_encodings("encodings");
static const Json::StaticString k_ssrc("ssrc");
Json::Value json;
Json::Value json(Json::objectValue);
// Add `muxId`.
json[k_muxId] = this->muxId;
......
......@@ -45,14 +45,15 @@ namespace RTC
{
MS_TRACE();
static Json::Value null_data(Json::nullValue);
static const Json::StaticString k_rtpParameters("rtpParameters");
Json::Value json;
Json::Value json(Json::objectValue);
if (this->rtpParameters)
json[k_rtpParameters] = this->rtpParameters->toJson();
else
json[k_rtpParameters] = Json::nullValue;
json[k_rtpParameters] = null_data;
return json;
}
......
......@@ -292,11 +292,8 @@ namespace RTC
static const Json::StaticString v_closed("closed");
static const Json::StaticString v_failed("failed");
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").
json[k_iceRole] = v_controlled;
......@@ -378,31 +375,8 @@ namespace RTC
break;
}
// Add `rtpListener.ssrcTable`.
Json::Value json_ssrcTable(Json::objectValue);
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;
// Add `rtpListener`.
json[k_rtpListener] = RTC::RtpListener::toJson();
return json;
}
......@@ -511,7 +485,7 @@ namespace RTC
return;
}
Json::Value data;
Json::Value data(Json::objectValue);
switch (this->dtlsLocalRole)
{
......@@ -549,12 +523,12 @@ namespace RTC
{
MS_TRACE();
static Json::Value nullData(Json::nullValue);
static Json::Value null_data(Json::nullValue);
if (this->iceServer->GetComponent() != ICEServer::IceComponent::RTP)
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
......@@ -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
void Transport::onPacketRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len)
{
......@@ -731,6 +681,7 @@ namespace RTC
}
// 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);
// TODO
......@@ -744,6 +695,16 @@ namespace RTC
return;
}
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;
}
......@@ -808,7 +769,7 @@ namespace RTC
static const Json::StaticString k_iceSelectedTuple("iceSelectedTuple");
Json::Value eventData;
Json::Value event_data(Json::objectValue);
/*
* RFC 5245 section 11.2 "Receiving Media":
......@@ -821,8 +782,8 @@ namespace RTC
this->selectedTuple = tuple;
// Notify.
eventData[k_iceSelectedTuple] = tuple->toJson();
this->notifier->Emit(this->transportId, "iceselectedtuplechange", eventData);
event_data[k_iceSelectedTuple] = tuple->toJson();
this->notifier->Emit(this->transportId, "iceselectedtuplechange", event_data);
}
void Transport::onICEConnected(RTC::ICEServer* iceServer)
......@@ -832,13 +793,13 @@ namespace RTC
static const Json::StaticString k_iceState("iceState");
static const Json::StaticString v_connected("connected");
Json::Value eventData;
Json::Value event_data(Json::objectValue);
MS_DEBUG("ICE connected");
// Notify.
eventData[k_iceState] = v_connected;
this->notifier->Emit(this->transportId, "icestatechange", eventData);
event_data[k_iceState] = v_connected;
this->notifier->Emit(this->transportId, "icestatechange", event_data);
// If ready, run the DTLS handler.
MayRunDTLSTransport();
......@@ -851,13 +812,13 @@ namespace RTC
static const Json::StaticString k_iceState("iceState");
static const Json::StaticString v_completed("completed");
Json::Value eventData;
Json::Value event_data(Json::objectValue);
MS_DEBUG("ICE completed");
// Notify.
eventData[k_iceState] = v_completed;
this->notifier->Emit(this->transportId, "icestatechange", eventData);
event_data[k_iceState] = v_completed;
this->notifier->Emit(this->transportId, "icestatechange", event_data);
// If ready, run the DTLS handler.
MayRunDTLSTransport();
......@@ -870,7 +831,7 @@ namespace RTC
static const Json::StaticString k_iceState("iceState");
static const Json::StaticString v_disconnected("disconnected");
Json::Value eventData;
Json::Value event_data(Json::objectValue);
MS_DEBUG("ICE disconnected");
......@@ -878,8 +839,8 @@ namespace RTC
this->selectedTuple = nullptr;
// Notify.
eventData[k_iceState] = v_disconnected;
this->notifier->Emit(this->transportId, "icestatechange", eventData);
event_data[k_iceState] = v_disconnected;
this->notifier->Emit(this->transportId, "icestatechange", event_data);
// This is a fatal error so close the transport.
Close();
......@@ -892,13 +853,13 @@ namespace RTC
static const Json::StaticString k_dtlsState("dtlsState");
static const Json::StaticString v_connecting("connecting");
Json::Value eventData;
Json::Value event_data(Json::objectValue);
MS_DEBUG("DTLS connecting");
// Notify.
eventData[k_dtlsState] = v_connecting;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
event_data[k_dtlsState] = v_connecting;
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)
......@@ -908,7 +869,7 @@ namespace RTC
static const Json::StaticString k_dtlsState("dtlsState");
static const Json::StaticString v_connected("connected");
Json::Value eventData;
Json::Value event_data(Json::objectValue);
MS_DEBUG("DTLS connected");
......@@ -917,8 +878,8 @@ namespace RTC
// SetRemoteSRTPKey(srtp_profile, srtp_remote_key, srtp_remote_key_len);
// Notify.
eventData[k_dtlsState] = v_connected;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
event_data[k_dtlsState] = v_connected;
this->notifier->Emit(this->transportId, "dtlsstatechange", event_data);
}
void Transport::onDTLSFailed(RTC::DTLSTransport* dtlsTransport)
......@@ -928,13 +889,13 @@ namespace RTC
static const Json::StaticString k_dtlsState("dtlsState");
static const Json::StaticString v_failed("failed");
Json::Value eventData;
Json::Value event_data(Json::objectValue);
MS_DEBUG("DTLS failed");
// Notify.
eventData[k_dtlsState] = v_failed;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
event_data[k_dtlsState] = v_failed;
this->notifier->Emit(this->transportId, "dtlsstatechange", event_data);
// This is a fatal error so close the transport.
Close();
......@@ -947,13 +908,13 @@ namespace RTC
static const Json::StaticString k_dtlsState("dtlsState");
static const Json::StaticString v_closed("closed");
Json::Value eventData;
Json::Value event_data(Json::objectValue);
MS_DEBUG("DTLS remotely closed");
// Notify.
eventData[k_dtlsState] = v_closed;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
event_data[k_dtlsState] = v_closed;
this->notifier->Emit(this->transportId, "dtlsstatechange", event_data);
// This is a fatal error so close the transport.
Close();
......@@ -985,35 +946,4 @@ namespace RTC
// TMP
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
static const Json::StaticString v_udp("udp");
static const Json::StaticString v_tcp("tcp");
Json::Value json;
Json::Value json_local;
Json::Value json_remote;
Json::Value json(Json::objectValue);
Json::Value json_local(Json::objectValue);
Json::Value json_remote(Json::objectValue);
int ip_family;
std::string ip;
uint16_t port;
Utils::IP::GetAddressInfo(this->GetLocalAddress(), &ip_family, ip, &port);
json_local[k_ip] = ip;
json_local[k_port] = port;
json_local[k_port] = (Json::UInt)port;
if (this->GetProtocol() == RTC::TransportTuple::Protocol::UDP)
json_local[k_protocol] = v_udp;
else
......@@ -38,7 +38,7 @@ namespace RTC
Utils::IP::GetAddressInfo(this->GetRemoteAddress(), &ip_family, ip, &port);
json_remote[k_ip] = ip;
json_remote[k_port] = port;
json_remote[k_port] = (Json::UInt)port;
if (this->GetProtocol() == RTC::TransportTuple::Protocol::UDP)
json_remote[k_protocol] = v_udp;
else
......
......@@ -56,7 +56,7 @@ void Timer::Start(uint64_t timeout)
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)
MS_THROW_ERROR("uv_timer_start() failed: %s", uv_strerror(err));
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论