Commit 29bd7bc6 authored by jcacerec's avatar jcacerec
Browse files

More on headers

parent 1fe6978f
......@@ -50,9 +50,11 @@ using std::cout; using std::endl;
//*******************************************************************************
DataProtocol::DataProtocol(const runModeT runmode,
DataProtocol::DataProtocol(JackTrip* jacktrip,
const runModeT runmode,
const packetHeaderTypeT headertype) :
mStopped(false), mHasPacketsToReceive(false), mRunMode(runmode), mHeader(NULL)
mStopped(false), mHasPacketsToReceive(false), mRunMode(runmode), mHeader(NULL),
mJackTrip(jacktrip)
{
switch (headertype) {
case DEFAULT :
......@@ -67,6 +69,10 @@ DataProtocol::DataProtocol(const runModeT runmode,
std::exit(1);
break;
}
/////////////////////////////////////////////////
//mJackTrip->createHeader(headertype);
/////////////////////////////////////////////////
}
......
......@@ -50,7 +50,7 @@
#include "RingBuffer.h"
class PacketHeader; // forward declaration
class JackAudioInterface; //forward declaration
class JackTrip;
/** \brief Base class that defines the transmission protocol.
*
......@@ -105,7 +105,8 @@ public:
* \param runmode Sets the run mode, use either DataProtocol::SENDER or
* DataProtocol::RECEIVER
*/
DataProtocol(const runModeT runmode,
DataProtocol(JackTrip* jacktrip,
const runModeT runmode,
const packetHeaderTypeT headertype = DEFAULT);
/// \brief The class destructor
......@@ -181,9 +182,12 @@ private:
size_t mAudioPacketSize; ///< Packet audio part size
/// \todo check a better way to access the header from the subclasses
protected:
PacketHeader* mHeader; ///< Packet Header
JackTrip* mJackTrip;
};
#endif
......@@ -109,8 +109,8 @@ void JackTrip::setupDataProtocol()
std::cout << "Using UDP Protocol" << std::endl;
std::cout << gPrintSeparator << std::endl;
usleep(100);
mDataProtocolSender = new UdpDataProtocol(DataProtocol::SENDER);
mDataProtocolReceiver = new UdpDataProtocol(DataProtocol::RECEIVER);
mDataProtocolSender = new UdpDataProtocol(this, DataProtocol::SENDER);
mDataProtocolReceiver = new UdpDataProtocol(this, DataProtocol::RECEIVER);
break;
case TCP:
std::cerr << "ERROR: TCP Protocol is not unimplemented" << std::endl;
......@@ -260,3 +260,30 @@ void JackTrip::serverStart()
// Set the peer address to send packets (in the protocol sender)
mDataProtocolSender->setPeerAddress( mPeerAddress.toLatin1().data() );
}
void JackTrip::createHeader(const DataProtocol::packetHeaderTypeT headertype)
{
switch (headertype) {
case DataProtocol::DEFAULT :
mPacketHeader = new DefaultHeader;
break;
case DataProtocol::JAMLINK :
//mHeader = new JamLinkHeader;
break;
default :
std::cerr << "ERROR: Undefined Header Type" << endl;
std::cerr << "Exiting Program..." << endl;
std::exit(1);
break;
}
}
void JackTrip::putHeaderInPacket(int8_t* full_packet)
{
mPacketHeader->fillHeaderCommonFromJack(*mJackAudio);
}
......@@ -44,6 +44,7 @@
#include "DataProtocol.h"
#include "JackAudioInterface.h"
#include "PacketHeader.h"
/** \brief Default values
*/
......@@ -57,6 +58,7 @@ const int DefaultAudioBitResolution = 16;
/** \brief
*
* \todo FINISH THIS: This class also acts as a Mediator between all the other class
*/
class JackTrip
{
......@@ -142,6 +144,11 @@ private:
/// \brief Start for the SERVER mode
void serverStart();
void createHeader(const DataProtocol::packetHeaderTypeT headertype);
void putHeaderInPacket(int8_t* full_packet);
jacktripModeT mJackTripMode; ///< JackTrip::jacktripModeT
dataProtocolT mDataProtocol; ///< Data Protocol
int mNumChans; ///< Number of Channels (inputs = outputs)
......@@ -156,11 +163,14 @@ private:
///< Pointer to Abstract Type DataProtocol that receives packets
DataProtocol* mDataProtocolReceiver;
JackAudioInterface* mJackAudio; ///< Interface to Jack Client
PacketHeader* mPacketHeader;
/// Shared (smart) Pointer for the Send RingBuffer
std::tr1::shared_ptr<RingBuffer> mSendRingBuffer;
/// Shared (smart) Pointer for the Receive RingBuffer
std::tr1::shared_ptr<RingBuffer> mReceiveRingBuffer;
//JackTripMediator mJackTripMediator;
};
#endif
......@@ -51,8 +51,8 @@ using std::cout; using std::endl;
//*******************************************************************************
UdpDataProtocol::UdpDataProtocol(const runModeT runmode)
: DataProtocol(runmode), mRunMode(runmode)
UdpDataProtocol::UdpDataProtocol(JackTrip* jacktrip, const runModeT runmode)
: DataProtocol(jacktrip, runmode), mRunMode(runmode)
{
// Base ports gInputPort_0 and gOutputPort_0 defined at globals.h
if (mRunMode == RECEIVER) {
......@@ -149,6 +149,8 @@ void UdpDataProtocol::run()
bool timeout = false;
//mHeader->fillHeaderCommonFromJack(const JackAudioInterface& JackAudio);
//mJackTrip->putHeaderInPacket(full_packet);
#if defined ( __LINUX__ )
set_fifo_priority (false);
#endif
......
......@@ -55,7 +55,7 @@ public:
/** \brief The class constructor
* \param runmode Sets the run mode, use either SENDER or RECEIVER
*/
UdpDataProtocol(const runModeT runmode);
UdpDataProtocol(JackTrip* jacktrip, const runModeT runmode);
/** \brief The class constructor
* \param runmode Sets the run mode, use either SENDER or RECEIVER
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment