2-way test infrastructure for ICE tunnelling.
This commit is contained in:
parent
e0ab8ae5f2
commit
eab423f84e
53
src/main.cpp
53
src/main.cpp
@ -211,7 +211,7 @@ int main(int argc, char *argv[]) {
|
|||||||
qRegisterMetaType<GstEnginePipeline*>("GstEnginePipeline*");
|
qRegisterMetaType<GstEnginePipeline*>("GstEnginePipeline*");
|
||||||
|
|
||||||
#ifdef HAVE_REMOTE
|
#ifdef HAVE_REMOTE
|
||||||
qRegisterMetaType<xrme::SIPInfo>("SIPInfo");
|
qRegisterMetaType<xrme::SIPInfo>("xrme::SIPInfo");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIBLASTFM
|
#ifdef HAVE_LIBLASTFM
|
||||||
@ -255,50 +255,39 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
ICESession::StaticInit();
|
ICESession::StaticInit();
|
||||||
ICESession ice;
|
ICESession ice;
|
||||||
ice.Init();
|
ice.Init(options.stun_test() == CommandlineOptions::StunTestOffer
|
||||||
|
? ICESession::DirectionControlling
|
||||||
|
: ICESession::DirectionControlled);
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QObject::connect(&ice,
|
QObject::connect(&ice,
|
||||||
SIGNAL(CandidatesAvailable(const SessionInfo&)),
|
SIGNAL(CandidatesAvailable(const xrme::SIPInfo&)),
|
||||||
&loop, SLOT(quit()));
|
&loop, SLOT(quit()));
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
const xrme::SIPInfo& candidates = ice.candidates();
|
const xrme::SIPInfo& candidates = ice.candidates();
|
||||||
qDebug() << candidates;
|
qDebug() << candidates;
|
||||||
|
|
||||||
QFile file;
|
QString sip_info;
|
||||||
file.open(stdin, QIODevice::ReadOnly);
|
{
|
||||||
QTextStream in(&file);
|
QFile file;
|
||||||
|
file.open(stdin, QIODevice::ReadOnly);
|
||||||
|
QTextStream in(&file);
|
||||||
|
in >> sip_info;
|
||||||
|
}
|
||||||
|
QStringList sip_components = sip_info.split(':');
|
||||||
|
|
||||||
xrme::SIPInfo remote_session;
|
xrme::SIPInfo remote_session;
|
||||||
qDebug() << "fragment";
|
remote_session.user_fragment = sip_components[0];
|
||||||
in >> remote_session.user_fragment;
|
remote_session.password = sip_components[1];
|
||||||
qDebug() << "password";
|
|
||||||
in >> remote_session.password;
|
|
||||||
|
|
||||||
xrme::SIPInfo::Candidate cand;
|
xrme::SIPInfo::Candidate cand;
|
||||||
QString address;
|
cand.address = sip_components[2];
|
||||||
qDebug() << "address";
|
cand.port = sip_components[3].toUShort();
|
||||||
in >> address;
|
cand.type = sip_components[4];
|
||||||
cand.address = address;
|
cand.component = sip_components[5].toInt();
|
||||||
qDebug() << "port";
|
cand.priority = sip_components[6].toInt();
|
||||||
in >> cand.port;
|
cand.foundation = sip_components[7];
|
||||||
QString type;
|
|
||||||
qDebug() << "type";
|
|
||||||
in >> type;
|
|
||||||
if (type == "host") {
|
|
||||||
cand.type = PJ_ICE_CAND_TYPE_HOST;
|
|
||||||
} else if (type == "srflx") {
|
|
||||||
cand.type = PJ_ICE_CAND_TYPE_SRFLX;
|
|
||||||
} else if (type == "prflx") {
|
|
||||||
cand.type = PJ_ICE_CAND_TYPE_PRFLX;
|
|
||||||
}
|
|
||||||
qDebug() << "component";
|
|
||||||
in >> cand.component;
|
|
||||||
qDebug() << "priority";
|
|
||||||
in >> cand.priority;
|
|
||||||
qDebug() << "foundation";
|
|
||||||
in >> cand.foundation;
|
|
||||||
|
|
||||||
remote_session.candidates << cand;
|
remote_session.candidates << cand;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ ICESession::ICESession(QObject* parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ICESession::Init() {
|
bool ICESession::Init(Direction direction) {
|
||||||
// Create instance.
|
// Create instance.
|
||||||
pj_ice_strans_cb ice_cb;
|
pj_ice_strans_cb ice_cb;
|
||||||
pj_bzero(&ice_cb, sizeof(ice_cb));
|
pj_bzero(&ice_cb, sizeof(ice_cb));
|
||||||
@ -41,7 +41,9 @@ bool ICESession::Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
pj_ice_sess_role role = PJ_ICE_SESS_ROLE_CONTROLLING;
|
pj_ice_sess_role role = direction == DirectionControlling
|
||||||
|
? PJ_ICE_SESS_ROLE_CONTROLLING
|
||||||
|
: PJ_ICE_SESS_ROLE_CONTROLLED;
|
||||||
|
|
||||||
status = pj_ice_strans_init_ice(ice_instance_, role, NULL, NULL);
|
status = pj_ice_strans_init_ice(ice_instance_, role, NULL, NULL);
|
||||||
|
|
||||||
@ -161,7 +163,8 @@ void ICESession::OnReceiveData(pj_ice_strans* ice_st,
|
|||||||
pj_size_t size,
|
pj_size_t size,
|
||||||
const pj_sockaddr_t* src_addr,
|
const pj_sockaddr_t* src_addr,
|
||||||
unsigned src_addr_len) {
|
unsigned src_addr_len) {
|
||||||
qDebug() << "Received data";
|
QByteArray data((const char*)pkt, size);
|
||||||
|
qDebug() << "Received data" << data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICESession::OnICEComplete(pj_ice_strans* ice_st,
|
void ICESession::OnICEComplete(pj_ice_strans* ice_st,
|
||||||
@ -174,9 +177,14 @@ void ICESession::OnICEComplete(pj_ice_strans* ice_st,
|
|||||||
op_name = "initialisation";
|
op_name = "initialisation";
|
||||||
me->InitialisationComplete(status);
|
me->InitialisationComplete(status);
|
||||||
break;
|
break;
|
||||||
case PJ_ICE_STRANS_OP_NEGOTIATION:
|
case PJ_ICE_STRANS_OP_NEGOTIATION: {
|
||||||
op_name = "negotation";
|
op_name = "negotation";
|
||||||
|
const char* data = "Hello, World!";
|
||||||
|
pj_sockaddr addr;
|
||||||
|
pj_getdefaultipinterface(pj_AF_INET(), &addr);
|
||||||
|
pj_ice_strans_sendto(ice_st, me->component_id_, data, strlen(data), &addr, sizeof(addr));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
op_name = "unknown";
|
op_name = "unknown";
|
||||||
}
|
}
|
||||||
@ -240,7 +248,13 @@ int ICESession::WorkerThread(void*) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ICESession::PJLog(int level, const char* data, int len) {
|
||||||
|
//qLog(Debug) << QByteArray(data, len);
|
||||||
|
}
|
||||||
|
|
||||||
void ICESession::StaticInit() {
|
void ICESession::StaticInit() {
|
||||||
|
//pj_log_set_log_func(&PJLog);
|
||||||
|
|
||||||
pj_init();
|
pj_init();
|
||||||
pjlib_util_init();
|
pjlib_util_init();
|
||||||
pjnath_init();
|
pjnath_init();
|
||||||
@ -265,17 +279,15 @@ void ICESession::StaticInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QDebug operator<< (QDebug dbg, const xrme::SIPInfo& session) {
|
QDebug operator<< (QDebug dbg, const xrme::SIPInfo& session) {
|
||||||
dbg.nospace() << "fragment:" << session.user_fragment << "\n";
|
dbg.nospace() << session.user_fragment.toAscii().constData() << ":"
|
||||||
dbg.nospace() << "password:" << session.password << "\n";
|
<< session.password.toAscii().constData() << ":";
|
||||||
|
|
||||||
foreach (const xrme::SIPInfo::Candidate& c, session.candidates) {
|
|
||||||
dbg.space() << "Candidate:" << "\n";
|
|
||||||
dbg.space() << c.address.toString() << ":" << c.port << "\n";
|
|
||||||
dbg.space() << "type:" << c.type << "\n";
|
|
||||||
dbg.space() << "component:" << c.component << "\n";
|
|
||||||
dbg.space() << "priority:" << c.priority << "\n";
|
|
||||||
dbg.space() << "foundation:" << c.foundation << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const xrme::SIPInfo::Candidate& c = session.candidates[0];
|
||||||
|
dbg.nospace() << c.address.toString().toAscii().constData() << ":"
|
||||||
|
<< c.port << ":"
|
||||||
|
<< c.type.toAscii().constData() << ":"
|
||||||
|
<< c.component << ":"
|
||||||
|
<< c.priority << ":"
|
||||||
|
<< c.foundation.toAscii().constData();
|
||||||
return dbg.space();
|
return dbg.space();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef ICESESSION_H
|
#ifndef ICESESSION_H
|
||||||
#define ICESESSION_H
|
#define ICESESSION_H
|
||||||
|
|
||||||
|
#include <pj/addr_resolv.h>
|
||||||
#include <pjlib.h>
|
#include <pjlib.h>
|
||||||
#include <pjlib-util.h>
|
#include <pjlib-util.h>
|
||||||
#include <pjnath.h>
|
#include <pjnath.h>
|
||||||
@ -15,10 +16,15 @@
|
|||||||
class ICESession : public QObject {
|
class ICESession : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
enum Direction {
|
||||||
|
DirectionControlling = 0,
|
||||||
|
DirectionControlled,
|
||||||
|
};
|
||||||
|
|
||||||
explicit ICESession(QObject* parent = 0);
|
explicit ICESession(QObject* parent = 0);
|
||||||
|
|
||||||
static void StaticInit();
|
static void StaticInit();
|
||||||
bool Init();
|
bool Init(Direction direction);
|
||||||
|
|
||||||
const xrme::SIPInfo& candidates() const { return candidates_; }
|
const xrme::SIPInfo& candidates() const { return candidates_; }
|
||||||
|
|
||||||
@ -35,6 +41,7 @@ class ICESession : public QObject {
|
|||||||
|
|
||||||
void InitialisationComplete(pj_status_t status);
|
void InitialisationComplete(pj_status_t status);
|
||||||
|
|
||||||
|
static void PJLog(int level, const char* data, int len);
|
||||||
|
|
||||||
static int HandleEvents(unsigned max_msec, unsigned* p_count);
|
static int HandleEvents(unsigned max_msec, unsigned* p_count);
|
||||||
static int WorkerThread(void*);
|
static int WorkerThread(void*);
|
||||||
|
@ -122,7 +122,6 @@ void Remote::Previous() {
|
|||||||
|
|
||||||
xrme::State Remote::state() const {
|
xrme::State Remote::state() const {
|
||||||
const Playlist* active = player_->playlists()->active();
|
const Playlist* active = player_->playlists()->active();
|
||||||
const Engine::State state = player_->GetState();
|
|
||||||
const PlaylistItemPtr current_item = player_->GetCurrentItem();
|
const PlaylistItemPtr current_item = player_->GetCurrentItem();
|
||||||
|
|
||||||
xrme::State ret;
|
xrme::State ret;
|
||||||
@ -130,7 +129,7 @@ xrme::State Remote::state() const {
|
|||||||
ret.can_go_previous = active->previous_row() != -1;
|
ret.can_go_previous = active->previous_row() != -1;
|
||||||
ret.can_seek = current_item && !current_item->Metadata().is_stream();
|
ret.can_seek = current_item && !current_item->Metadata().is_stream();
|
||||||
|
|
||||||
switch (state) {
|
switch (player_->GetState()) {
|
||||||
case Engine::Playing: ret.playback_state = xrme::State::PlaybackState_Playing; break;
|
case Engine::Playing: ret.playback_state = xrme::State::PlaybackState_Playing; break;
|
||||||
case Engine::Paused: ret.playback_state = xrme::State::PlaybackState_Paused; break;
|
case Engine::Paused: ret.playback_state = xrme::State::PlaybackState_Paused; break;
|
||||||
case Engine::Idle:
|
case Engine::Idle:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user