Make ICESession a QIODevice.

This commit is contained in:
John Maguire 2011-05-19 14:29:25 +00:00
parent 09bde274ed
commit 83813bb788
2 changed files with 28 additions and 2 deletions

View File

@ -14,7 +14,7 @@ pj_pool_t* ICESession::sPool;
pj_thread_t* ICESession::sThread;
ICESession::ICESession(QObject* parent)
: QObject(parent) {
: QIODevice(parent) {
}
@ -160,6 +160,22 @@ void ICESession::StartNegotiation(const xrme::SIPInfo& session) {
}
}
qint64 ICESession::readData(char* data, qint64 max_size) {
QByteArray ret = receive_buffer_.left(max_size);
receive_buffer_ = receive_buffer_.mid(ret.size());
memcpy(data, ret.constData(), ret.size());
return ret.size();
}
qint64 ICESession::writeData(const char* data, qint64 max_size) {
// This address should never actually be used.
pj_sockaddr addr;
pj_getdefaultipinterface(pj_AF_INET(), &addr);
pj_status_t ret = pj_ice_strans_sendto(
ice_instance_, component_id_, data, max_size, &addr, sizeof(addr));
return ret == PJ_SUCCESS ? max_size : -1;
}
void ICESession::OnReceiveData(pj_ice_strans* ice_st,
unsigned comp_id,
@ -167,8 +183,11 @@ void ICESession::OnReceiveData(pj_ice_strans* ice_st,
pj_size_t size,
const pj_sockaddr_t* src_addr,
unsigned src_addr_len) {
ICESession* me = reinterpret_cast<ICESession*>(pj_ice_strans_get_user_data(ice_st));
QByteArray data((const char*)pkt, size);
qDebug() << "Received data" << data;
me->receive_buffer_.append(data);
}
void ICESession::OnICEComplete(pj_ice_strans* ice_st,

View File

@ -8,12 +8,13 @@
#include <QHostAddress>
#include <QList>
#include <QIODevice>
#include <QtDebug>
#include <xrme/connection.h>
class ICESession : public QObject {
class ICESession : public QIODevice {
Q_OBJECT
public:
enum Direction {
@ -30,6 +31,10 @@ class ICESession : public QObject {
void StartNegotiation(const xrme::SIPInfo& session);
protected:
virtual qint64 readData(char* data, qint64 max_size);
virtual qint64 writeData(const char* data, qint64 max_size);
signals:
void CandidatesAvailable(const xrme::SIPInfo& candidates);
@ -39,6 +44,8 @@ class ICESession : public QObject {
xrme::SIPInfo candidates_;
QByteArray receive_buffer_;
void InitialisationComplete(pj_status_t status);
static void PJLog(int level, const char* data, int len);