2015-05-11 15:40:07 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/*
|
2015-05-11 15:40:07 -04:00
|
|
|
* libretroshare/src/serialiser: rsVOIPItems.h
|
2012-02-19 03:32:47 -05:00
|
|
|
*
|
|
|
|
* RetroShare Serialiser.
|
|
|
|
*
|
|
|
|
* Copyright 2011 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "serialiser/rsserviceids.h"
|
|
|
|
#include "serialiser/rsserial.h"
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2012-02-26 12:13:54 -05:00
|
|
|
const uint16_t RS_SERVICE_TYPE_VOIP_PLUGIN = 0xa021;
|
2012-02-26 10:36:07 -05:00
|
|
|
|
2015-08-10 22:13:50 -04:00
|
|
|
const uint8_t RS_PKT_SUBTYPE_VOIP_PING = 0x01;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_VOIP_PONG = 0x02;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_VOIP_PROTOCOL = 0x03 ;
|
|
|
|
// 0x04,0x05 is unused because of a change in the protocol
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_VOIP_BANDWIDTH = 0x06 ;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_VOIP_DATA = 0x07 ;
|
2012-02-19 16:13:20 -05:00
|
|
|
|
|
|
|
const uint8_t QOS_PRIORITY_RS_VOIP = 9 ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2014-07-15 16:04:31 -04:00
|
|
|
const uint32_t RS_VOIP_FLAGS_VIDEO_DATA = 0x0001 ;
|
|
|
|
const uint32_t RS_VOIP_FLAGS_AUDIO_DATA = 0x0002 ;
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
class RsVOIPItem: public RsItem
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
public:
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPItem(uint8_t voip_subtype)
|
2012-02-26 12:13:54 -05:00
|
|
|
: RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_VOIP_PLUGIN,voip_subtype)
|
2012-02-19 16:13:20 -05:00
|
|
|
{
|
|
|
|
setPriorityLevel(QOS_PRIORITY_RS_VOIP) ;
|
|
|
|
}
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
virtual ~RsVOIPItem() {};
|
2012-02-19 03:32:47 -05:00
|
|
|
virtual void clear() {};
|
|
|
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ;
|
2012-02-19 16:13:20 -05:00
|
|
|
|
|
|
|
virtual bool serialise(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialise themselves ?
|
|
|
|
virtual uint32_t serial_size() const = 0 ; // deserialise is handled using a constructor
|
2012-02-19 03:32:47 -05:00
|
|
|
};
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
class RsVOIPPingItem: public RsVOIPItem
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
public:
|
2015-06-28 08:50:26 -04:00
|
|
|
RsVOIPPingItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PING), mSeqNo(0), mPingTS(0) {}
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPPingItem(void *data,uint32_t size) ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
virtual bool serialise(void *data,uint32_t& size) ;
|
|
|
|
virtual uint32_t serial_size() const ;
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
virtual ~RsVOIPPingItem() {}
|
2012-02-19 03:32:47 -05:00
|
|
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
|
|
|
|
uint32_t mSeqNo;
|
|
|
|
uint64_t mPingTS;
|
|
|
|
};
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
class RsVOIPDataItem: public RsVOIPItem
|
2012-02-19 16:13:20 -05:00
|
|
|
{
|
|
|
|
public:
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPDataItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_DATA) {}
|
|
|
|
RsVOIPDataItem(void *data,uint32_t size) ; // de-serialization
|
2012-02-19 16:13:20 -05:00
|
|
|
|
|
|
|
virtual bool serialise(void *data,uint32_t& size) ;
|
|
|
|
virtual uint32_t serial_size() const ;
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
virtual ~RsVOIPDataItem()
|
2012-02-19 16:13:20 -05:00
|
|
|
{
|
|
|
|
free(voip_data) ;
|
|
|
|
voip_data = NULL ;
|
|
|
|
}
|
|
|
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
|
|
|
|
uint32_t flags ;
|
|
|
|
uint32_t data_size ;
|
2015-08-10 22:13:50 -04:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
void *voip_data ;
|
|
|
|
};
|
|
|
|
|
2015-08-10 22:13:50 -04:00
|
|
|
class RsVOIPBandwidthItem: public RsVOIPItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsVOIPBandwidthItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_BANDWIDTH) {}
|
|
|
|
RsVOIPBandwidthItem(void *data,uint32_t size) ; // de-serialization
|
|
|
|
|
|
|
|
virtual bool serialise(void *data,uint32_t& size) ;
|
|
|
|
virtual uint32_t serial_size() const ;
|
|
|
|
|
|
|
|
virtual ~RsVOIPBandwidthItem() {}
|
|
|
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
|
|
|
|
uint32_t flags ; // is that incoming or expected bandwidth?
|
|
|
|
uint32_t bytes_per_sec ; // bandwidth in bytes per sec.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
class RsVOIPProtocolItem: public RsVOIPItem
|
2012-02-19 16:13:20 -05:00
|
|
|
{
|
|
|
|
public:
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPProtocolItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PROTOCOL) {}
|
|
|
|
RsVOIPProtocolItem(void *data,uint32_t size) ;
|
2012-02-19 16:13:20 -05:00
|
|
|
|
2014-07-20 16:50:36 -04:00
|
|
|
enum { VoipProtocol_Ring = 1, VoipProtocol_Ackn = 2, VoipProtocol_Close = 3, VoipProtocol_Bandwidth = 4 } ;
|
2012-02-19 16:13:20 -05:00
|
|
|
|
|
|
|
virtual bool serialise(void *data,uint32_t& size) ;
|
|
|
|
virtual uint32_t serial_size() const ;
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
virtual ~RsVOIPProtocolItem() {}
|
2012-02-19 16:13:20 -05:00
|
|
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
|
|
|
|
uint32_t protocol ;
|
|
|
|
uint32_t flags ;
|
|
|
|
};
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
class RsVOIPPongItem: public RsVOIPItem
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
public:
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPPongItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PONG) {}
|
|
|
|
RsVOIPPongItem(void *data,uint32_t size) ;
|
2012-02-19 16:13:20 -05:00
|
|
|
|
|
|
|
virtual bool serialise(void *data,uint32_t& size) ;
|
|
|
|
virtual uint32_t serial_size() const ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
virtual ~RsVOIPPongItem() {}
|
2012-02-21 16:53:25 -05:00
|
|
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
uint32_t mSeqNo;
|
|
|
|
uint64_t mPingTS;
|
|
|
|
uint64_t mPongTS;
|
|
|
|
};
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
class RsVOIPSerialiser: public RsSerialType
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
public:
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPSerialiser()
|
2012-02-26 12:13:54 -05:00
|
|
|
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_VOIP_PLUGIN)
|
2012-02-19 16:13:20 -05:00
|
|
|
{
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
virtual ~RsVOIPSerialiser() {}
|
2012-02-19 16:13:20 -05:00
|
|
|
|
|
|
|
virtual uint32_t size (RsItem *item)
|
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
return dynamic_cast<RsVOIPItem *>(item)->serial_size() ;
|
2012-02-19 16:13:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool serialise (RsItem *item, void *data, uint32_t *size)
|
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
return dynamic_cast<RsVOIPItem *>(item)->serialise(data,*size) ;
|
2012-02-19 16:13:20 -05:00
|
|
|
}
|
|
|
|
virtual RsItem *deserialise(void *data, uint32_t *size);
|
2012-02-19 03:32:47 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|