mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 19:45:31 +01:00
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*");
|
||||
|
||||
#ifdef HAVE_REMOTE
|
||||
qRegisterMetaType<xrme::SIPInfo>("SIPInfo");
|
||||
qRegisterMetaType<xrme::SIPInfo>("xrme::SIPInfo");
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBLASTFM
|
||||
@ -255,50 +255,39 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
ICESession::StaticInit();
|
||||
ICESession ice;
|
||||
ice.Init();
|
||||
ice.Init(options.stun_test() == CommandlineOptions::StunTestOffer
|
||||
? ICESession::DirectionControlling
|
||||
: ICESession::DirectionControlled);
|
||||
|
||||
QEventLoop loop;
|
||||
QObject::connect(&ice,
|
||||
SIGNAL(CandidatesAvailable(const SessionInfo&)),
|
||||
SIGNAL(CandidatesAvailable(const xrme::SIPInfo&)),
|
||||
&loop, SLOT(quit()));
|
||||
loop.exec();
|
||||
|
||||
const xrme::SIPInfo& candidates = ice.candidates();
|
||||
qDebug() << candidates;
|
||||
|
||||
QFile file;
|
||||
file.open(stdin, QIODevice::ReadOnly);
|
||||
QTextStream in(&file);
|
||||
QString sip_info;
|
||||
{
|
||||
QFile file;
|
||||
file.open(stdin, QIODevice::ReadOnly);
|
||||
QTextStream in(&file);
|
||||
in >> sip_info;
|
||||
}
|
||||
QStringList sip_components = sip_info.split(':');
|
||||
|
||||
xrme::SIPInfo remote_session;
|
||||
qDebug() << "fragment";
|
||||
in >> remote_session.user_fragment;
|
||||
qDebug() << "password";
|
||||
in >> remote_session.password;
|
||||
remote_session.user_fragment = sip_components[0];
|
||||
remote_session.password = sip_components[1];
|
||||
|
||||
xrme::SIPInfo::Candidate cand;
|
||||
QString address;
|
||||
qDebug() << "address";
|
||||
in >> address;
|
||||
cand.address = address;
|
||||
qDebug() << "port";
|
||||
in >> cand.port;
|
||||
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;
|
||||
cand.address = sip_components[2];
|
||||
cand.port = sip_components[3].toUShort();
|
||||
cand.type = sip_components[4];
|
||||
cand.component = sip_components[5].toInt();
|
||||
cand.priority = sip_components[6].toInt();
|
||||
cand.foundation = sip_components[7];
|
||||
|
||||
remote_session.candidates << cand;
|
||||
|
||||
|
@ -18,7 +18,7 @@ ICESession::ICESession(QObject* parent)
|
||||
}
|
||||
|
||||
|
||||
bool ICESession::Init() {
|
||||
bool ICESession::Init(Direction direction) {
|
||||
// Create instance.
|
||||
pj_ice_strans_cb ice_cb;
|
||||
pj_bzero(&ice_cb, sizeof(ice_cb));
|
||||
@ -41,7 +41,9 @@ bool ICESession::Init() {
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
@ -161,7 +163,8 @@ void ICESession::OnReceiveData(pj_ice_strans* ice_st,
|
||||
pj_size_t size,
|
||||
const pj_sockaddr_t* src_addr,
|
||||
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,
|
||||
@ -174,9 +177,14 @@ void ICESession::OnICEComplete(pj_ice_strans* ice_st,
|
||||
op_name = "initialisation";
|
||||
me->InitialisationComplete(status);
|
||||
break;
|
||||
case PJ_ICE_STRANS_OP_NEGOTIATION:
|
||||
case PJ_ICE_STRANS_OP_NEGOTIATION: {
|
||||
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;
|
||||
}
|
||||
default:
|
||||
op_name = "unknown";
|
||||
}
|
||||
@ -240,7 +248,13 @@ int ICESession::WorkerThread(void*) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ICESession::PJLog(int level, const char* data, int len) {
|
||||
//qLog(Debug) << QByteArray(data, len);
|
||||
}
|
||||
|
||||
void ICESession::StaticInit() {
|
||||
//pj_log_set_log_func(&PJLog);
|
||||
|
||||
pj_init();
|
||||
pjlib_util_init();
|
||||
pjnath_init();
|
||||
@ -265,17 +279,15 @@ void ICESession::StaticInit() {
|
||||
}
|
||||
|
||||
QDebug operator<< (QDebug dbg, const xrme::SIPInfo& session) {
|
||||
dbg.nospace() << "fragment:" << session.user_fragment << "\n";
|
||||
dbg.nospace() << "password:" << session.password << "\n";
|
||||
|
||||
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";
|
||||
}
|
||||
dbg.nospace() << session.user_fragment.toAscii().constData() << ":"
|
||||
<< session.password.toAscii().constData() << ":";
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef ICESESSION_H
|
||||
#define ICESESSION_H
|
||||
|
||||
#include <pj/addr_resolv.h>
|
||||
#include <pjlib.h>
|
||||
#include <pjlib-util.h>
|
||||
#include <pjnath.h>
|
||||
@ -15,10 +16,15 @@
|
||||
class ICESession : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Direction {
|
||||
DirectionControlling = 0,
|
||||
DirectionControlled,
|
||||
};
|
||||
|
||||
explicit ICESession(QObject* parent = 0);
|
||||
|
||||
static void StaticInit();
|
||||
bool Init();
|
||||
bool Init(Direction direction);
|
||||
|
||||
const xrme::SIPInfo& candidates() const { return candidates_; }
|
||||
|
||||
@ -35,6 +41,7 @@ class ICESession : public QObject {
|
||||
|
||||
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 WorkerThread(void*);
|
||||
|
@ -122,7 +122,6 @@ void Remote::Previous() {
|
||||
|
||||
xrme::State Remote::state() const {
|
||||
const Playlist* active = player_->playlists()->active();
|
||||
const Engine::State state = player_->GetState();
|
||||
const PlaylistItemPtr current_item = player_->GetCurrentItem();
|
||||
|
||||
xrme::State ret;
|
||||
@ -130,7 +129,7 @@ xrme::State Remote::state() const {
|
||||
ret.can_go_previous = active->previous_row() != -1;
|
||||
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::Paused: ret.playback_state = xrme::State::PlaybackState_Paused; break;
|
||||
case Engine::Idle:
|
||||
|
Loading…
x
Reference in New Issue
Block a user