Commit df0eb5a5 authored by jcacerec's avatar jcacerec
Browse files

more advances in class structure

parent d5e7dd60
......@@ -54,38 +54,19 @@ using std::cout; using std::endl;
DataProtocol::DataProtocol(JackTrip* jacktrip,
const runModeT runmode,
const packetHeaderTypeT headertype) :
mStopped(false), mHasPacketsToReceive(false), mRunMode(runmode), mHeader(NULL),
mJackTrip(jacktrip)
{
switch (headertype) {
case DEFAULT :
mHeader = new DefaultHeader;
break;
case JAMLINK :
//mHeader = new JamLinkHeader;
break;
default:
std::cerr << "ERROR: Undefined Header Type" << endl;
std::cerr << "Exiting Program..." << endl;
std::exit(1);
break;
}
/////////////////////////////////////////////////
//mJackTrip->createHeader(headertype);
/////////////////////////////////////////////////
}
mStopped(false), mHasPacketsToReceive(false), mRunMode(runmode), mJackTrip(jacktrip)
{}
//*******************************************************************************
DataProtocol::~DataProtocol()
{
delete mHeader;
}
{}
//*******************************************************************************
void DataProtocol::fillHeaderCommonFromJack(const JackAudioInterface& jackaudio)
/*
void DataProtocol::fillHeaderCommonFromAudio(const JackAudioInterface& jackaudio)
{
mHeader->fillHeaderCommonFromJack(jackaudio);
}
*/
......@@ -140,7 +140,7 @@ public:
*/
virtual void setPeerAddress(char* peerHostOrIP) = 0;
void fillHeaderCommonFromJack(const JackAudioInterface& jackaudio);
//void fillHeaderCommonFromAudio(const JackAudioInterface& jackaudio);
virtual void getPeerAddressFromFirstPacket(QHostAddress& peerHostAddress,
uint16_t& port) = 0;
......@@ -178,7 +178,7 @@ private:
/// \todo check a better way to access the header from the subclasses
protected:
PacketHeader* mHeader; ///< Packet Header
//PacketHeader* mHeader; ///< Packet Header
JackTrip* mJackTrip; ///< JackTrip mediator class
};
......
......@@ -198,7 +198,7 @@ void JackTrip::setupRingBuffers()
// Set the header from jack
/// \todo Put this in a better place
mDataProtocolSender->fillHeaderCommonFromJack(*mJackAudio);
//mPacketHeader->fillHeaderCommonFromAudio();
}
}
......@@ -315,10 +315,10 @@ void JackTrip::createHeader(const DataProtocol::packetHeaderTypeT headertype)
{
switch (headertype) {
case DataProtocol::DEFAULT :
mPacketHeader = new DefaultHeader;
mPacketHeader = new DefaultHeader(this);
break;
case DataProtocol::JAMLINK :
mPacketHeader = new JamLinkHeader;
mPacketHeader = new JamLinkHeader(this);
break;
default :
std::cerr << "ERROR: Undefined Header Type" << endl;
......@@ -332,7 +332,7 @@ void JackTrip::createHeader(const DataProtocol::packetHeaderTypeT headertype)
//*******************************************************************************
void JackTrip::putHeaderInPacket(int8_t* full_packet, int8_t* audio_packet)
{
mPacketHeader->fillHeaderCommonFromJack(*mJackAudio);
mPacketHeader->fillHeaderCommonFromAudio();
mPacketHeader->putHeaderInPacket(full_packet);
int8_t* audio_part;
......@@ -359,3 +359,10 @@ void JackTrip::parseAudioPacket(int8_t* full_packet, int8_t* audio_packet)
//std::memcpy(audio_packet, audio_part, mJackAudio->getBufferSizeInBytes());
std::memcpy(audio_packet, audio_part, mJackAudio->getSizeInBytesPerChannel() * mNumChans);
}
//*******************************************************************************
void JackTrip::checkPeerSettings(int8_t* full_packet)
{
mPacketHeader->checkPeerSettings(full_packet);
}
......@@ -165,6 +165,15 @@ public:
{ mSendRingBuffer->readSlotBlocking(ptrToReadSlot); }
void writeAudioBuffer(const int8_t* ptrToSlot)
{ mReceiveRingBuffer->insertSlotNonBlocking(ptrToSlot); }
uint32_t getBufferSizeInSamples() const
{ return mJackAudio->getBufferSizeInSamples(); }
JackAudioInterface::samplingRateT getSampleRateType() const
{ return mJackAudio->getSampleRateType(); }
int getNumInputChannels() const
{ return mJackAudio->getNumInputChannels(); }
int getNumOutputChannels() const
{return mJackAudio->getNumOutputChannels(); }
void checkPeerSettings(int8_t* full_packet);
//@}
//------------------------------------------------------------------------------------
......
......@@ -37,6 +37,7 @@
#include "PacketHeader.h"
#include "JackAudioInterface.h"
#include "JackTrip.h"
#include <sys/time.h>
#include <cstdlib>
......@@ -49,6 +50,12 @@ using std::cout; using std::endl;
//#######################################################################
//####################### PacketHeader ##################################
//#######################################################################
//***********************************************************************
PacketHeader::PacketHeader(JackTrip* jacktrip) :
mSeqNumber(0), mJackTrip(jacktrip)
{}
//***********************************************************************
uint64_t PacketHeader::usecTime()
{
......@@ -65,7 +72,8 @@ uint64_t PacketHeader::usecTime()
//####################### DefaultHeader #################################
//#######################################################################
//***********************************************************************
DefaultHeader::DefaultHeader()
DefaultHeader::DefaultHeader(JackTrip* jacktrip) :
PacketHeader(jacktrip), mJackTrip(jacktrip)
{
mHeader.TimeStamp = 0;
mHeader.SeqNumber = 0;
......@@ -78,12 +86,12 @@ DefaultHeader::DefaultHeader()
//***********************************************************************
void DefaultHeader::fillHeaderCommonFromJack(const JackAudioInterface& JackAudio)
void DefaultHeader::fillHeaderCommonFromAudio()
{
mHeader.BufferSize = JackAudio.getBufferSizeInSamples();
mHeader.SamplingRate = JackAudio.getSampleRateType ();
mHeader.NumInChannels = JackAudio.getNumInputChannels();
mHeader.NumOutChannels = JackAudio.getNumOutputChannels();
mHeader.BufferSize = mJackTrip->getBufferSizeInSamples();
mHeader.SamplingRate = mJackTrip->getSampleRateType ();
mHeader.NumInChannels = mJackTrip->getNumInputChannels();
mHeader.NumOutChannels = mJackTrip->getNumOutputChannels();
mHeader.SeqNumber = 0;
mHeader.TimeStamp = PacketHeader::usecTime();
//cout << mHeader.TimeStamp << endl;
......@@ -91,6 +99,20 @@ void DefaultHeader::fillHeaderCommonFromJack(const JackAudioInterface& JackAudio
}
//***********************************************************************
void DefaultHeader::checkPeerSettings(int8_t* full_packet)
{
cout << "CHECKING PEER" << endl;
DefaultHeaderStruct* peer_header;
peer_header = reinterpret_cast<DefaultHeaderStruct*>(full_packet);
if ( peer_header->BufferSize != mHeader.BufferSize ) {
std::cerr << "ERROR: Peer Buffer size is : " << peer_header->BufferSize << endl;
std::cerr << " Local Buffer size is : " << mHeader.BufferSize << endl;
std::exit(1);
}
}
//***********************************************************************
void DefaultHeader::printHeader() const
{
......@@ -115,7 +137,8 @@ void DefaultHeader::printHeader() const
//####################### JamLinkHeader #################################
//#######################################################################
//***********************************************************************
JamLinkHeader::JamLinkHeader()
JamLinkHeader::JamLinkHeader(JackTrip* jacktrip) :
PacketHeader(jacktrip), mJackTrip(jacktrip)
{
mHeader.Common = 0;
mHeader.SeqNumber = 0;
......@@ -124,10 +147,10 @@ JamLinkHeader::JamLinkHeader()
//***********************************************************************
void JamLinkHeader::fillHeaderCommonFromJack(const JackAudioInterface& JackAudio)
void JamLinkHeader::fillHeaderCommonFromAudio()
{
// Check number of channels
int num_inchannels = JackAudio.getNumInputChannels();
int num_inchannels = mJackTrip->getNumInputChannels();
if ( num_inchannels != 1 ) {
std::cerr << "ERROR: JamLink only support ONE channel. Run JackTrip using only one channel"
<< endl;
......@@ -137,7 +160,7 @@ void JamLinkHeader::fillHeaderCommonFromJack(const JackAudioInterface& JackAudio
mHeader.Common = (ETX_MONO | ETX_16BIT | ETX_XTND) + 64;
// Sampling Rate
int rate_type = JackAudio.getSampleRateType();
int rate_type = mJackTrip->getSampleRateType();
switch (rate_type)
{
case JackAudioInterface::SR48 :
......
......@@ -113,7 +113,7 @@ class PacketHeader
{
public:
/// \brief The class Constructor
PacketHeader() : mSeqNumber(0) {};
PacketHeader(JackTrip* jacktrip);
/// \brief The class Destructor
virtual ~PacketHeader() {};
......@@ -124,13 +124,15 @@ public:
/// \todo Implement this using a JackTrip Method (Mediator) member instead of the
/// reference to JackAudio
virtual void fillHeaderCommonFromJack(const JackAudioInterface& JackAudio) = 0;
virtual void fillHeaderCommonFromAudio() = 0;
/* \brief Parse the packet header and take appropriate measures (like change settings, or
* quit the program if peer settings don't match)
*/
virtual void parseHeader() = 0;
virtual void checkPeerSettings(int8_t* full_packet) = 0;
/* \brief Increase sequence number for counter, a 16bit number
*/
virtual void increaseSequenceNumber()
......@@ -166,6 +168,7 @@ public:
private:
uint16_t mSeqNumber;
JackTrip* mJackTrip; ///< JackTrip mediator class
};
......@@ -195,10 +198,11 @@ public:
};
//---------------------------------------------------------
*/
DefaultHeader();
DefaultHeader(JackTrip* jacktrip);
virtual ~DefaultHeader() {};
virtual void fillHeaderCommonFromJack(const JackAudioInterface& JackAudio);
virtual void fillHeaderCommonFromAudio();
virtual void parseHeader() {};
virtual void checkPeerSettings(int8_t* full_packet);
virtual void increaseSequenceNumber()
{
/*
......@@ -215,9 +219,10 @@ public:
};
void printHeader() const;
//private:
private:
//DefaultHeaderStruct mHeader; ///< Header Struct
DefaultHeaderStruct mHeader;
DefaultHeaderStruct mHeader;///< Default Header Struct
JackTrip* mJackTrip; ///< JackTrip mediator class
};
......@@ -233,11 +238,12 @@ class JamLinkHeader : public PacketHeader
{
public:
JamLinkHeader();
JamLinkHeader(JackTrip* jacktrip);
virtual ~JamLinkHeader() {};
virtual void fillHeaderCommonFromJack(const JackAudioInterface& JackAudio);
virtual void fillHeaderCommonFromAudio();
virtual void parseHeader() {};
virtual void checkPeerSettings(int8_t* full_packet) {};
virtual void increaseSequenceNumber() {};
virtual int getHeaderSizeInBytes() const { return sizeof(mHeader); };
virtual void putHeaderInPacket(int8_t* full_packet)
......@@ -247,6 +253,7 @@ public:
private:
JamLinkHeaderStuct mHeader; ///< JamLink Header Struct
JackTrip* mJackTrip; ///< JackTrip mediator class
};
......
......@@ -193,6 +193,8 @@ void UdpDataProtocol::run()
std::cout << "Waiting for Peer..." << std::endl;
// This blocks waiting for the first packet
receivePacket( reinterpret_cast<char*>(mFullPacket), full_packet_size);
// Check that peer has the same audio settings
mJackTrip->checkPeerSettings(mFullPacket);
mJackTrip->parseAudioPacket(mFullPacket, mAudioPacket);
std::cout << "Received Connection for Peer!" << std::endl;
......
......@@ -30,7 +30,7 @@ qmake -makefile -o Makefile \
"QT += network" \
"INCLUDEPATH+=/usr/local/include" \
"LIBS += -ljack -lm -framework CoreAudio" \
"QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.5.sdk" \
"QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk" \
"CONFIG += x86 ppc" \
"TARGET = $APP_NAME" \
"DEFINES += APP_NAME=${APP_NAME_QUOTES} __MAC_OSX__" \
......
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