Commit a2c55b70 authored by jcacerec's avatar jcacerec
Browse files

Jamlink mode added, First pass on mac threads

parent 02e924e5
......@@ -47,7 +47,7 @@
#include <QVector>
#include <QVarLengthArray>
#include "types.h"
#include "types_jacktrip.h"
#include "RingBuffer.h"
#include "ProcessPlugin.h"
......@@ -117,8 +117,8 @@ public:
*/
uint32_t getBufferSizeInBytes() const
{
return (getBufferSizeInSamples()*sizeof(sample_t));
};
return (getBufferSizeInSamples() * getAudioBitResolution()/8);
}
/** \brief Get the Audio Bit Resolution, in bits
*
......
......@@ -55,9 +55,11 @@ JackTrip::JackTrip(jacktripModeT JacktripMode,
dataProtocolT DataProtocolType,
int NumChans,
int BufferQueueLength,
JackAudioInterface::audioBitResolutionT AudioBitResolution) :
JackAudioInterface::audioBitResolutionT AudioBitResolution,
DataProtocol::packetHeaderTypeT PacketHeaderType) :
mJackTripMode(JacktripMode),
mDataProtocol(DataProtocolType),
mPacketHeaderType(PacketHeaderType),
mNumChans(NumChans),
mBufferQueueLength(BufferQueueLength),
mSampleRate(0),
......@@ -70,7 +72,7 @@ JackTrip::JackTrip(jacktripModeT JacktripMode,
{
setupJackAudio();
/// \todo CHECK THIS AND PUT IT IN A BETTER PLACE, also, get header type from options
createHeader(DataProtocol::DEFAULT);
createHeader(mPacketHeaderType);
}
......@@ -212,8 +214,10 @@ void JackTrip::start()
mDataProtocolReceiver->start();
#elif defined ( __MAC_OSX__ )
cout << "Using qt4 (MAC OS X) thread priority" << endl;
mDataProtocolSender->start(QThread::TimeCriticalPriority);
mDataProtocolReceiver->start(QThread::TimeCriticalPriority);
//mDataProtocolSender->start(QThread::TimeCriticalPriority);
//mDataProtocolReceiver->start(QThread::TimeCriticalPriority);
mDataProtocolSender->start();
mDataProtocolReceiver->start();
#else
std::cerr << "ERROR: Platform unknown or not supported" << endl;
std::exit(1);
......
......@@ -92,7 +92,9 @@ public:
int NumChans = 2,
int BufferQueueLength = 8,
JackAudioInterface::audioBitResolutionT AudioBitResolution =
JackAudioInterface::BIT16);
JackAudioInterface::BIT16,
DataProtocol::packetHeaderTypeT PacketHeaderType =
DataProtocol::DEFAULT);
/// \brief The class destructor
virtual ~JackTrip();
......@@ -114,16 +116,24 @@ public:
//
/// \brief Sets (override) JackTrip Mode after construction
void setJackTripMode(jacktripModeT JacktripMode)
{ mJackTripMode = JacktripMode; };
{ mJackTripMode = JacktripMode; }
/// \brief Sets (override) DataProtocol Type after construction
void setDataProtocoType(dataProtocolT DataProtocolType)
{mDataProtocol = DataProtocolType; };
{ mDataProtocol = DataProtocolType; }
/// \brief
void setPacketHeaderType(DataProtocol::packetHeaderTypeT PacketHeaderType)
{
mPacketHeaderType = PacketHeaderType;
delete mPacketHeader;
mPacketHeader = NULL;
createHeader(mPacketHeaderType);
}
/// \brief Sets (override) Number of Channels after construction
void setNumChannels(int NumChans)
{ mNumChans=NumChans; };
/// \brief Sets (override) Buffer Queue Length Mode after construction
{ mNumChans=NumChans; }
/// \brief Sets (override) Buffer Queue Length Mode after construction
void setBufferQueueLength(int BufferQueueLength)
{ mBufferQueueLength = BufferQueueLength; };
{ mBufferQueueLength = BufferQueueLength; }
/// \brief Sets (override) Audio Bit Resolution after construction
void setAudioBitResolution(JackAudioInterface::audioBitResolutionT AudioBitResolution)
{ mAudioBitResolution = AudioBitResolution; }
......@@ -157,7 +167,9 @@ private:
jacktripModeT mJackTripMode; ///< JackTrip::jacktripModeT
dataProtocolT mDataProtocol; ///< Data Protocol
dataProtocolT mDataProtocol; ///< Data Protocol Tipe
DataProtocol::packetHeaderTypeT mPacketHeaderType;
int mNumChans; ///< Number of Channels (inputs = outputs)
int mBufferQueueLength; ///< Audio Buffer from network queue length
uint32_t mSampleRate; ///< Sample Rate
......
......@@ -37,7 +37,7 @@
#include "LoopBack.h"
#include "types.h"
#include "types_jacktrip.h"
#include <cstring> // for memcpy
......
......@@ -49,6 +49,7 @@ using std::cout; using std::endl;
//#######################################################################
//####################### PacketHeader ##################################
//#######################################################################
//***********************************************************************
uint64_t PacketHeader::usecTime()
{
struct timeval tv;
......@@ -63,6 +64,7 @@ uint64_t PacketHeader::usecTime()
//#######################################################################
//####################### DefaultHeader #################################
//#######################################################################
//***********************************************************************
DefaultHeader::DefaultHeader()
{
mHeader.TimeStamp = 0;
......@@ -111,6 +113,15 @@ void DefaultHeader::printHeader() const
//#######################################################################
//####################### JamLinkHeader #################################
//#######################################################################
//***********************************************************************
JamLinkHeader::JamLinkHeader()
{
mHeader.Common = 0;
mHeader.SeqNumber = 0;
mHeader.TimeStamp = 0;
}
//***********************************************************************
void JamLinkHeader::fillHeaderCommonFromJack(const JackAudioInterface& JackAudio)
{
......
......@@ -42,7 +42,7 @@
#include <tr1/memory> // for shared_ptr
#include <cstring>
#include "types.h"
#include "types_jacktrip.h"
#include "globals.h"
class JackTrip; // Forward Declaration
class JackAudioInterface; // Forward Declaration
......@@ -113,8 +113,10 @@ struct JamLinkHeaderStuct : public HeaderStruct
class PacketHeader
{
public:
PacketHeader() {}; //: mHeader(NULL) {};
virtual ~PacketHeader() {}; // { delete mHeader; };
/// \brief The class Constructor
PacketHeader() : mSeqNumber(0) {};
/// \brief The class Destructor
virtual ~PacketHeader() {};
/** \brief Return a time stamp in microseconds
* \return Time stamp: microseconds since midnight (0 hour), January 1, 1970
......@@ -130,9 +132,20 @@ public:
*/
virtual void parseHeader() = 0;
/* \brief Increase sequence number for counter
/* \brief Increase sequence number for counter, a 16bit number
*/
virtual void increaseSequenceNumber() = 0;
virtual void increaseSequenceNumber()
{
mSeqNumber++;
};
/* \brief Returns the current sequence number
* \return 16bit Sequence number
*/
virtual uint16_t getSequenceNumber() const
{
return mSeqNumber;
}
/* \brief Get the header size in bytes
*/
......@@ -151,6 +164,9 @@ public:
* sizeof(header part) + sizeof(audio part)
*/
virtual void putHeaderInPacket(int8_t* full_packet) = 0;
private:
uint16_t mSeqNumber;
};
......@@ -217,20 +233,8 @@ public:
class JamLinkHeader : public PacketHeader
{
public:
/*
//---------JAMLINK HEADER DRAFT----------------------------
/// \brief JamLink Header Struct
struct JamLinkHeaderStuct
{
// watch out for alignment -- need to be on 4 byte chunks
uint16_t Common; ///< Common part of the header, 16 bit
uint16_t SeqNumber; ///< Sequence Number
uint32_t TimeStamp; ///< Time Stamp
};
//---------------------------------------------------------
*/
JamLinkHeader() {};
JamLinkHeader();
virtual ~JamLinkHeader() {};
virtual void fillHeaderCommonFromJack(const JackAudioInterface& JackAudio);
......@@ -240,8 +244,6 @@ public:
virtual void putHeaderInPacket(int8_t* full_packet)
{
putHeaderInPacketBaseClass(full_packet, mHeader);
//std::memcpy(full_packet, reinterpret_cast<const void*>(&mHeader),
// getHeaderSizeInBytes() );
};
private:
......
......@@ -42,7 +42,7 @@
#include <QMutex>
#include <QMutexLocker>
#include "types.h"
#include "types_jacktrip.h"
/** \brief Provides a ring-buffer (or circular-buffer) that can be written to and read from
......
......@@ -55,7 +55,8 @@ Settings::Settings() :
mNumChans(2),
mBufferQueueLength(gDefaultQueueLength),
mAudioBitResolution(JackAudioInterface::BIT16),
mLoopBack(false)
mLoopBack(false),
mJamLink(false)
{}
......@@ -82,6 +83,7 @@ void Settings::parseInput(int argc, char** argv)
{ "queue", required_argument, NULL, 'q' }, // Queue Length
{ "bitres", required_argument, NULL, 'b' }, // Audio Bit Resolution
{ "loopback", no_argument, NULL, 'l' }, // Run in loopback mode
{ "jamlink", no_argument, NULL, 'j' }, // Run in JamLink mode
{ "help", no_argument, NULL, 'h' }, // Print Help
{ NULL, 0, NULL, 0 }
};
......@@ -90,7 +92,7 @@ void Settings::parseInput(int argc, char** argv)
//----------------------------------------------------------------------------
/// \todo Specify mandatory arguments
int ch;
while ( (ch = getopt_long(argc, argv, "n:sc:q:b:lh", longopts, NULL)) != -1 )
while ( (ch = getopt_long(argc, argv, "n:sc:q:b:ljh", longopts, NULL)) != -1 )
switch (ch) {
case 'n': // Number of input and output channels
......@@ -132,10 +134,14 @@ void Settings::parseInput(int argc, char** argv)
mBufferQueueLength = atoi(optarg);
}
break;
case 'l': //loopback
case 'l': // loopback
//-------------------------------------------------------
mLoopBack = true;
break;
case 'j': // jamlink
//-------------------------------------------------------
mJamLink = true;
break;
case 'h':
//-------------------------------------------------------
printUsage();
......@@ -184,6 +190,7 @@ void Settings::printUsage()
<< gDefaultQueueLength << ")" << endl;
cout << " -b, --bitres # (8, 16, 24, 32) Audio Bit Rate Resolutions (default 16)" << endl;
cout << " -l, --loopback Run in Loop-Back Mode" << endl;
cout << " -j, --jamlink Run in JamLink Mode (Connect to a JamLink Box)" << endl;
cout << " -h, --help Prints this help" << endl;
cout << "" << endl;
}
......@@ -198,6 +205,10 @@ void Settings::startJackTrip()
if ( mJackTripMode == JackTrip::CLIENT ) {
jacktrip.setPeerAddress(mPeerAddress.toLatin1().data()); }
// Set in JamLink Mode
if ( mJamLink ) {
jacktrip.setPacketHeaderType(DataProtocol::JAMLINK); }
// Add Plugins
if ( mLoopBack ) {
cout << "Running in Loop-Back Mode..." << endl;
......
......@@ -80,8 +80,8 @@ private:
int mBufferQueueLength; ///< Audio Buffer from network queue length
JackAudioInterface::audioBitResolutionT mAudioBitResolution;
QString mPeerAddress; ///< Peer Address to use in jacktripModeT::CLIENT Mode
bool mLoopBack;
bool mLoopBack; ///< Loop-back mode
bool mJamLink; ///< JamLink mode
//char* mPeerHostOrIP; ///< Peer IP address or Host name
};
......
......@@ -175,6 +175,11 @@ void UdpDataProtocol::run()
set_fifo_priority (false);
#endif
#if defined ( __MAC_OSX__ )
set_realtime(1250000,60000,90000);
#endif
switch ( mRunMode )
{
case RECEIVER :
......
......@@ -43,7 +43,7 @@
#include <QHostAddress>
#include "DataProtocol.h"
#include "types.h"
#include "types_jacktrip.h"
/** \brief UDP implementation of DataProtocol class
......
......@@ -36,7 +36,7 @@
*/
#include "globals.h"
#include "types.h"
#include "types_jacktrip.h"
#if defined ( __LINUX__ )
#include <sched.h>
......@@ -45,17 +45,33 @@
#if defined ( __MAC_OSX__ )
#include <mach/mach.h>
#include <mach/thread_policy.h>
//#include <mach/processor.h>
#include <mach/clock.h>
#include <sys/kernel.h>
//#include <mach/clock.h>
//#include <sys/kernel.h>
//#include <mach/kern/clock.h>
#include <mach/clock.h>
#include <mach/machine.h>
#include <mach/mach_time.h>
//#include <Kernel/kern/clock.h>
//#include <kern/kern_types.h>
//m#include <kern/kern_types.h>
//#include <Kernel/kern/clock.h>
//#include <kern/clock.h>
//#include <assert.h>
//#include <CoreServices/CoreServices.h>
//#include <mach/mach.h>
//#include <mach/mach_time.h>
//#include <unistd.h>
//#include <mach/machine.h>
//#include <mach/mach_time.h>
//#include <mach/thread_call.h>
#include <mach/processor.h>
//#include <mach/processor.h>
//#include <mach/macro_help.h>
#endif //__MAC_OSX__
......@@ -64,6 +80,7 @@
#if defined ( __MAC_OSX__ )
//*******************************************************************************
//http://developer.apple.com/DOCUMENTATION/Darwin/Conceptual/KernelProgramming/scheduler/chapter_8_section_4.html
//http://lists.apple.com/archives/darwin-dev/2007/Sep/msg00035.html
int set_realtime(int period, int computation, int constraint)
{
//AbsoluteTime time;
......@@ -107,8 +124,10 @@ int get_fifo_priority (bool half)
//priority=min;
return priority;
}
#endif //__LINUX__
#if defined ( __LINUX__ )
//*******************************************************************************
int set_fifo_priority (bool half)
{
......@@ -142,8 +161,10 @@ int set_fifo_priority (bool half)
}
return priority;
}
#endif //__LINUX__
#if defined ( __LINUX__ )
//*******************************************************************************
int set_realtime_priority (void)
{
......
......@@ -84,6 +84,7 @@ const int gJackBitResolution = 32; ///< Audio Bit Resolution of the Jack Server
//*******************************************************************************
/// \name Global Functions
//@{
// Linux Specific Functions
#if defined ( __LINUX__ )
......
......@@ -28,7 +28,9 @@ qmake -makefile -o Makefile \
"CONFIG -= app_bundle" \
"QT -= gui" \
"QT += network" \
"LIBS += -ljack -framework CoreAudio -lm" \
"INCLUDEPATH+=/usr/local/include" \
"LIBS += -ljack -lm -framework CoreAudio" \
"QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.5.sdk" \
"CONFIG += x86 ppc" \
"TARGET = $APP_NAME" \
"DEFINES += APP_NAME=${APP_NAME_QUOTES} __MAC_OSX__" \
......@@ -43,3 +45,8 @@ echo "done"
## Notes:
## To link jack as framework
## "LIBS += -framework jack
## "QMAKE_LFLAGS += -L/System/Library/Frameworks/Kernel.framework" \
## "QMAKE_LFLAGS += -L/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Kernel.framework/Headers/kern" \
## "QMAKE_LFLAGS += -L/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Kernel.framework/Headers/" \
## "QMAKE_LFLAGS += -L/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Kernel.framework/"
## "LIBS += -ljack -lm -framework CoreAudio -lcrypto" \
\ No newline at end of file
......@@ -30,7 +30,7 @@
//*****************************************************************
/**
* \file jacktrip_types.h
* \file jacktrip_types_jacktrip.h
* \author Juan-Pablo Caceres
* \date June 2008
*/
......
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