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

Minor C++ changes.

上级 29f6079a
......@@ -17,6 +17,9 @@ class Peer extends EventEmitter
this._debugerror = debug(`mediasoup-tester:ERROR:Peer:${username}`);
this._debugerror.log = console.error.bind(console);
this._connected = false;
this._stream = null;
this._debug('new()');
// protoo-client instance
......@@ -25,23 +28,53 @@ class Peer extends EventEmitter
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
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()
{
this._debug('close()');
this._protoo.close();
try
{
this._pc.close();
}
catch (error)
{}
this.closeProtoo();
this.closePeerConnection();
}
closeProtoo()
......@@ -61,6 +94,13 @@ class Peer extends EventEmitter
}
catch (error)
{}
try
{
this._stream.getTracks().forEach((track) => track.stop());
}
catch (error)
{}
}
testTransport()
......
......@@ -41,7 +41,7 @@ function run()
let peer = new Peer(protooWsUrl, username, uuid);
// Call the 'test-transport' service
peer.once('online', () =>
peer.once('ready', () =>
{
peer.testTransport();
});
......
......@@ -171,7 +171,7 @@ app.put('/test-transport', function(req)
{
let promise = mediaPeer.createTransport(
{
udp : false,
udp : true,
tcp : true,
preferIPv4 : true,
preferUdp : true
......@@ -283,7 +283,7 @@ app.put('/test-transport', function(req)
// Create a promise
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 :
{
algorithm : remoteFingerprint.type,
......
......@@ -10,6 +10,7 @@
#include <openssl/ssl.h>
#include <openssl/bio.h>
#include <openssl/x509.h>
#include <openssl/bio.h>
#include <json/json.h>
namespace RTC
......
......@@ -9,7 +9,7 @@ namespace RTC
{
public:
/* Struct for RTCP common header. */
typedef struct CommonHeader
struct CommonHeader
{
#if defined(MS_LITTLE_ENDIAN)
MS_BYTE count:5;
......@@ -22,7 +22,7 @@ namespace RTC
#endif
MS_BYTE packet_type:8;
MS_2BYTES length:16;
} CommonHeader;
};
public:
static bool IsRTCP(const MS_BYTE* data, size_t len);
......
......@@ -9,7 +9,7 @@ namespace RTC
{
public:
/* Struct for RTP header. */
typedef struct Header
struct Header
{
#if defined(MS_LITTLE_ENDIAN)
MS_BYTE csrc_count:4;
......@@ -29,15 +29,15 @@ namespace RTC
MS_2BYTES sequence_number;
MS_4BYTES timestamp;
MS_4BYTES ssrc;
} Header;
};
/* Struct for RTP header extension. */
typedef struct ExtensionHeader
struct ExtensionHeader
{
MS_2BYTES id;
MS_2BYTES length; // Size of value in multiples of 4 bytes.
MS_BYTE* value;
} ExtensionHeader;
};
public:
static bool IsRTP(const MS_BYTE* data, size_t len);
......
......@@ -33,9 +33,8 @@ namespace RTC
static struct sockaddr_storage sockaddrStorageIPv6;
static MS_PORT minPort;
static MS_PORT maxPort;
typedef std::unordered_map<MS_PORT, bool> AvailablePorts;
static AvailablePorts availableIPv4Ports;
static AvailablePorts availableIPv6Ports;
static std::unordered_map<MS_PORT, bool> availableIPv4Ports;
static std::unordered_map<MS_PORT, bool> availableIPv6Ports;
public:
TCPServer(Listener* listener, RTC::TCPConnection::Reader* reader, uv_tcp_t* uvHandle);
......
......@@ -10,6 +10,8 @@
#include "RTC/STUNMessage.h"
#include "RTC/TransportTuple.h"
#include "RTC/DTLSTransport.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTCPPacket.h"
#include "Channel/Notifier.h"
#include <string>
#include <vector>
......
......@@ -34,9 +34,8 @@ namespace RTC
static struct sockaddr_storage sockaddrStorageIPv6;
static MS_PORT minPort;
static MS_PORT maxPort;
typedef std::unordered_map<MS_PORT, bool> AvailablePorts;
static AvailablePorts availableIPv4Ports;
static AvailablePorts availableIPv6Ports;
static std::unordered_map<MS_PORT, bool> availableIPv4Ports;
static std::unordered_map<MS_PORT, bool> availableIPv6Ports;
public:
UDPSocket(Listener* listener, uv_udp_t* uvHandle);
......
......@@ -30,7 +30,7 @@
#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define MS_BIG_ENDIAN
#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
......
......@@ -48,8 +48,7 @@ private:
// Allocated by this (may be passed by argument).
uv_tcp_t* uvHandle = nullptr;
// Others.
typedef std::unordered_set<TCPConnection*> TCPConnections;
TCPConnections connections;
std::unordered_set<TCPConnection*> connections;
bool isClosing = false;
protected:
......
......@@ -847,6 +847,8 @@ namespace RTC
char* data = nullptr;
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);
......
......@@ -29,8 +29,8 @@ namespace RTC
struct sockaddr_storage TCPServer::sockaddrStorageIPv6;
MS_PORT TCPServer::minPort;
MS_PORT TCPServer::maxPort;
TCPServer::AvailablePorts TCPServer::availableIPv4Ports;
TCPServer::AvailablePorts TCPServer::availableIPv6Ports;
std::unordered_map<MS_PORT, bool> TCPServer::availableIPv4Ports;
std::unordered_map<MS_PORT, bool> TCPServer::availableIPv6Ports;
/* Class methods. */
......@@ -112,7 +112,7 @@ namespace RTC
uint16_t attempt = 0;
uint16_t bindAttempt = 0;
int flags = 0;
AvailablePorts* available_ports;
std::unordered_map<MS_PORT, bool>* available_ports;
switch (address_family)
{
......
......@@ -647,6 +647,17 @@ namespace RTC
this->iceServer->ForceSelectedTuple(tuple);
// 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
......@@ -665,6 +676,7 @@ namespace RTC
this->iceServer->ForceSelectedTuple(tuple);
// TODO
MS_DEBUG("received RTCP data");
}
void Transport::onSTUNDataRecv(RTC::UDPSocket *socket, const MS_BYTE* data, size_t len, const struct sockaddr* remote_addr)
......
......@@ -30,8 +30,8 @@ namespace RTC
struct sockaddr_storage UDPSocket::sockaddrStorageIPv6;
MS_PORT UDPSocket::minPort;
MS_PORT UDPSocket::maxPort;
UDPSocket::AvailablePorts UDPSocket::availableIPv4Ports;
UDPSocket::AvailablePorts UDPSocket::availableIPv6Ports;
std::unordered_map<MS_PORT, bool> UDPSocket::availableIPv4Ports;
std::unordered_map<MS_PORT, bool> UDPSocket::availableIPv6Ports;
/* Class methods. */
......@@ -113,7 +113,7 @@ namespace RTC
uint16_t attempt = 0;
uint16_t bindAttempt = 0;
int flags = 0;
AvailablePorts* available_ports;
std::unordered_map<MS_PORT, bool>* available_ports;
switch (address_family)
{
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论