提交 32a8fb48 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Minor C++ changes.

上级 29f6079a
...@@ -17,6 +17,9 @@ class Peer extends EventEmitter ...@@ -17,6 +17,9 @@ class Peer extends EventEmitter
this._debugerror = debug(`mediasoup-tester:ERROR:Peer:${username}`); this._debugerror = debug(`mediasoup-tester:ERROR:Peer:${username}`);
this._debugerror.log = console.error.bind(console); this._debugerror.log = console.error.bind(console);
this._connected = false;
this._stream = null;
this._debug('new()'); this._debug('new()');
// protoo-client instance // protoo-client instance
...@@ -25,23 +28,53 @@ class Peer extends EventEmitter ...@@ -25,23 +28,53 @@ class Peer extends EventEmitter
url : `${wsUrl}/?username=${username}&uuid=${uuid}` url : `${wsUrl}/?username=${username}&uuid=${uuid}`
}); });
this._protoo.on('online', () => this.emit('online')); this._protoo.on('online', () =>
{
this._debug('protoo online');
this._connected = true;
mayRun.call(this);
});
// PeerConnection instance // PeerConnection instance
this._pc = new rtcninja.RTCPeerConnection({ iceServers: [] }); this._pc = new rtcninja.RTCPeerConnection({ iceServers: [] });
rtcninja.getUserMedia(
{ audio: true, video: false },
// callback
((stream) =>
{
this._debug('got local stream');
this._stream = stream;
mayRun.call(this);
}),
// errback
((error) =>
{
throw new Error(error);
})
);
function mayRun()
{
if (this._connected && this._stream)
{
this._debug('emitting "ready" event');
this._pc.addStream(this._stream);
this.emit('ready');
}
}
} }
close() close()
{ {
this._debug('close()'); this._debug('close()');
this._protoo.close(); this.closeProtoo();
try this.closePeerConnection();
{
this._pc.close();
}
catch (error)
{}
} }
closeProtoo() closeProtoo()
...@@ -61,6 +94,13 @@ class Peer extends EventEmitter ...@@ -61,6 +94,13 @@ class Peer extends EventEmitter
} }
catch (error) catch (error)
{} {}
try
{
this._stream.getTracks().forEach((track) => track.stop());
}
catch (error)
{}
} }
testTransport() testTransport()
......
...@@ -41,7 +41,7 @@ function run() ...@@ -41,7 +41,7 @@ function run()
let peer = new Peer(protooWsUrl, username, uuid); let peer = new Peer(protooWsUrl, username, uuid);
// Call the 'test-transport' service // Call the 'test-transport' service
peer.once('online', () => peer.once('ready', () =>
{ {
peer.testTransport(); peer.testTransport();
}); });
......
...@@ -171,7 +171,7 @@ app.put('/test-transport', function(req) ...@@ -171,7 +171,7 @@ app.put('/test-transport', function(req)
{ {
let promise = mediaPeer.createTransport( let promise = mediaPeer.createTransport(
{ {
udp : false, udp : true,
tcp : true, tcp : true,
preferIPv4 : true, preferIPv4 : true,
preferUdp : true preferUdp : true
...@@ -283,7 +283,7 @@ app.put('/test-transport', function(req) ...@@ -283,7 +283,7 @@ app.put('/test-transport', function(req)
// Create a promise // Create a promise
let promise = transport.setRemoteDtlsParameters( let promise = transport.setRemoteDtlsParameters(
{ {
role : 'auto', // SDP offer MUST always have a=setup:actpass so we can choose whatever we want role : 'client', // SDP offer MUST always have a=setup:actpass so we can choose whatever we want
fingerprint : fingerprint :
{ {
algorithm : remoteFingerprint.type, algorithm : remoteFingerprint.type,
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/bio.h> #include <openssl/bio.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/bio.h>
#include <json/json.h> #include <json/json.h>
namespace RTC namespace RTC
......
...@@ -9,7 +9,7 @@ namespace RTC ...@@ -9,7 +9,7 @@ namespace RTC
{ {
public: public:
/* Struct for RTCP common header. */ /* Struct for RTCP common header. */
typedef struct CommonHeader struct CommonHeader
{ {
#if defined(MS_LITTLE_ENDIAN) #if defined(MS_LITTLE_ENDIAN)
MS_BYTE count:5; MS_BYTE count:5;
...@@ -22,7 +22,7 @@ namespace RTC ...@@ -22,7 +22,7 @@ namespace RTC
#endif #endif
MS_BYTE packet_type:8; MS_BYTE packet_type:8;
MS_2BYTES length:16; MS_2BYTES length:16;
} CommonHeader; };
public: public:
static bool IsRTCP(const MS_BYTE* data, size_t len); static bool IsRTCP(const MS_BYTE* data, size_t len);
......
...@@ -9,7 +9,7 @@ namespace RTC ...@@ -9,7 +9,7 @@ namespace RTC
{ {
public: public:
/* Struct for RTP header. */ /* Struct for RTP header. */
typedef struct Header struct Header
{ {
#if defined(MS_LITTLE_ENDIAN) #if defined(MS_LITTLE_ENDIAN)
MS_BYTE csrc_count:4; MS_BYTE csrc_count:4;
...@@ -29,15 +29,15 @@ namespace RTC ...@@ -29,15 +29,15 @@ namespace RTC
MS_2BYTES sequence_number; MS_2BYTES sequence_number;
MS_4BYTES timestamp; MS_4BYTES timestamp;
MS_4BYTES ssrc; MS_4BYTES ssrc;
} Header; };
/* Struct for RTP header extension. */ /* Struct for RTP header extension. */
typedef struct ExtensionHeader struct ExtensionHeader
{ {
MS_2BYTES id; MS_2BYTES id;
MS_2BYTES length; // Size of value in multiples of 4 bytes. MS_2BYTES length; // Size of value in multiples of 4 bytes.
MS_BYTE* value; MS_BYTE* value;
} ExtensionHeader; };
public: public:
static bool IsRTP(const MS_BYTE* data, size_t len); static bool IsRTP(const MS_BYTE* data, size_t len);
......
...@@ -33,9 +33,8 @@ namespace RTC ...@@ -33,9 +33,8 @@ namespace RTC
static struct sockaddr_storage sockaddrStorageIPv6; static struct sockaddr_storage sockaddrStorageIPv6;
static MS_PORT minPort; static MS_PORT minPort;
static MS_PORT maxPort; static MS_PORT maxPort;
typedef std::unordered_map<MS_PORT, bool> AvailablePorts; static std::unordered_map<MS_PORT, bool> availableIPv4Ports;
static AvailablePorts availableIPv4Ports; static std::unordered_map<MS_PORT, bool> availableIPv6Ports;
static AvailablePorts availableIPv6Ports;
public: public:
TCPServer(Listener* listener, RTC::TCPConnection::Reader* reader, uv_tcp_t* uvHandle); TCPServer(Listener* listener, RTC::TCPConnection::Reader* reader, uv_tcp_t* uvHandle);
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "RTC/STUNMessage.h" #include "RTC/STUNMessage.h"
#include "RTC/TransportTuple.h" #include "RTC/TransportTuple.h"
#include "RTC/DTLSTransport.h" #include "RTC/DTLSTransport.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTCPPacket.h"
#include "Channel/Notifier.h" #include "Channel/Notifier.h"
#include <string> #include <string>
#include <vector> #include <vector>
......
...@@ -34,9 +34,8 @@ namespace RTC ...@@ -34,9 +34,8 @@ namespace RTC
static struct sockaddr_storage sockaddrStorageIPv6; static struct sockaddr_storage sockaddrStorageIPv6;
static MS_PORT minPort; static MS_PORT minPort;
static MS_PORT maxPort; static MS_PORT maxPort;
typedef std::unordered_map<MS_PORT, bool> AvailablePorts; static std::unordered_map<MS_PORT, bool> availableIPv4Ports;
static AvailablePorts availableIPv4Ports; static std::unordered_map<MS_PORT, bool> availableIPv6Ports;
static AvailablePorts availableIPv6Ports;
public: public:
UDPSocket(Listener* listener, uv_udp_t* uvHandle); UDPSocket(Listener* listener, uv_udp_t* uvHandle);
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define MS_BIG_ENDIAN #define MS_BIG_ENDIAN
#else #else
#error "cannot determine whether the processor is Little-Endian or Big-Endian" #error "cannot determine whether the CPU is Little-Endian or Big-Endian"
#endif #endif
#endif #endif
......
...@@ -48,8 +48,7 @@ private: ...@@ -48,8 +48,7 @@ private:
// Allocated by this (may be passed by argument). // Allocated by this (may be passed by argument).
uv_tcp_t* uvHandle = nullptr; uv_tcp_t* uvHandle = nullptr;
// Others. // Others.
typedef std::unordered_set<TCPConnection*> TCPConnections; std::unordered_set<TCPConnection*> connections;
TCPConnections connections;
bool isClosing = false; bool isClosing = false;
protected: protected:
......
...@@ -847,6 +847,8 @@ namespace RTC ...@@ -847,6 +847,8 @@ namespace RTC
char* data = nullptr; char* data = nullptr;
read = BIO_get_mem_data(this->sslBioToNetwork, &data); read = BIO_get_mem_data(this->sslBioToNetwork, &data);
if (read <= 0)
return;
MS_DEBUG("%ld bytes of DTLS data ready to sent to the peer", read); MS_DEBUG("%ld bytes of DTLS data ready to sent to the peer", read);
......
...@@ -29,8 +29,8 @@ namespace RTC ...@@ -29,8 +29,8 @@ namespace RTC
struct sockaddr_storage TCPServer::sockaddrStorageIPv6; struct sockaddr_storage TCPServer::sockaddrStorageIPv6;
MS_PORT TCPServer::minPort; MS_PORT TCPServer::minPort;
MS_PORT TCPServer::maxPort; MS_PORT TCPServer::maxPort;
TCPServer::AvailablePorts TCPServer::availableIPv4Ports; std::unordered_map<MS_PORT, bool> TCPServer::availableIPv4Ports;
TCPServer::AvailablePorts TCPServer::availableIPv6Ports; std::unordered_map<MS_PORT, bool> TCPServer::availableIPv6Ports;
/* Class methods. */ /* Class methods. */
...@@ -112,7 +112,7 @@ namespace RTC ...@@ -112,7 +112,7 @@ namespace RTC
uint16_t attempt = 0; uint16_t attempt = 0;
uint16_t bindAttempt = 0; uint16_t bindAttempt = 0;
int flags = 0; int flags = 0;
AvailablePorts* available_ports; std::unordered_map<MS_PORT, bool>* available_ports;
switch (address_family) switch (address_family)
{ {
......
...@@ -647,6 +647,17 @@ namespace RTC ...@@ -647,6 +647,17 @@ namespace RTC
this->iceServer->ForceSelectedTuple(tuple); this->iceServer->ForceSelectedTuple(tuple);
// TODO // TODO
MS_DEBUG("received RTP data");
RTC::RTPPacket* packet = RTC::RTPPacket::Parse(data, len);
if (!packet)
{
MS_DEBUG("data received is not a valid RTP packet");
return;
}
packet->Dump();
delete packet;
} }
inline inline
...@@ -665,6 +676,7 @@ namespace RTC ...@@ -665,6 +676,7 @@ namespace RTC
this->iceServer->ForceSelectedTuple(tuple); this->iceServer->ForceSelectedTuple(tuple);
// TODO // TODO
MS_DEBUG("received RTCP data");
} }
void Transport::onSTUNDataRecv(RTC::UDPSocket *socket, const MS_BYTE* data, size_t len, const struct sockaddr* remote_addr) void Transport::onSTUNDataRecv(RTC::UDPSocket *socket, const MS_BYTE* data, size_t len, const struct sockaddr* remote_addr)
......
...@@ -30,8 +30,8 @@ namespace RTC ...@@ -30,8 +30,8 @@ namespace RTC
struct sockaddr_storage UDPSocket::sockaddrStorageIPv6; struct sockaddr_storage UDPSocket::sockaddrStorageIPv6;
MS_PORT UDPSocket::minPort; MS_PORT UDPSocket::minPort;
MS_PORT UDPSocket::maxPort; MS_PORT UDPSocket::maxPort;
UDPSocket::AvailablePorts UDPSocket::availableIPv4Ports; std::unordered_map<MS_PORT, bool> UDPSocket::availableIPv4Ports;
UDPSocket::AvailablePorts UDPSocket::availableIPv6Ports; std::unordered_map<MS_PORT, bool> UDPSocket::availableIPv6Ports;
/* Class methods. */ /* Class methods. */
...@@ -113,7 +113,7 @@ namespace RTC ...@@ -113,7 +113,7 @@ namespace RTC
uint16_t attempt = 0; uint16_t attempt = 0;
uint16_t bindAttempt = 0; uint16_t bindAttempt = 0;
int flags = 0; int flags = 0;
AvailablePorts* available_ports; std::unordered_map<MS_PORT, bool>* available_ports;
switch (address_family) switch (address_family)
{ {
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论