Unverified Commit 40990160 authored by cchafe's avatar cchafe Committed by GitHub
Browse files

Merge pull request #65 from jacktrip/aaron

Aaron
parents 560034bc 6618bb25
......@@ -40,6 +40,7 @@
#ifdef __WIN_32__
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
#ifndef __WIN_32__
......@@ -164,6 +165,11 @@ public:
//virtual void getPeerAddressFromFirstPacket(QHostAddress& peerHostAddress,
// uint16_t& port) = 0;
#if defined (__WIN_32__)
virtual void setSocket(SOCKET &socket) = 0;
#else
virtual void setSocket(int &socket) = 0;
#endif
signals:
......
......@@ -49,6 +49,7 @@
#include <stdexcept>
#include <QHostAddress>
#include <QHostInfo>
#include <QThread>
#include <QTcpSocket>
......@@ -155,7 +156,7 @@ void JackTrip::setupAudio(
#ifdef WAIRTOMASTER // WAIR
qDebug() << "mPeerAddress" << mPeerAddress << mPeerAddress.contains(gDOMAIN_TRIPLE);
QString VARIABLE_AUDIO_NAME = WAIR_AUDIO_NAME; // legacy for WAIR
QByteArray tmp = mPeerAddress.toLatin1();
QByteArray tmp = QString(mPeerAddress).replace(":", ".").toLatin1();
if(mPeerAddress.toStdString()!="")
mJackClientName = tmp.constData();
std::cout << "WAIR ID " << ID << " jacktrip client name set to=" <<
......@@ -403,6 +404,15 @@ void JackTrip::startProcess(
break;
}
// Have the threads share a single socket that operates at full duplex.
#if defined (__WIN_32__)
SOCKET sock_fd = INVALID_SOCKET;
#else
int sock_fd = -1;
#endif
mDataProtocolReceiver->setSocket(sock_fd);
mDataProtocolSender->setSocket(sock_fd);
// Start Threads
if (gVerboseFlag) std::cout << " JackTrip:startProcess before mDataProtocolReceiver->start" << std::endl;
mDataProtocolReceiver->start();
......@@ -493,9 +503,9 @@ throw(std::invalid_argument, std::runtime_error)
if (gVerboseFlag) std::cout << "JackTrip:serverStart before QUdpSocket UdpSockTemp" << std::endl;
QUdpSocket UdpSockTemp;// Create socket to wait for client
if (gVerboseFlag) std::cout << "JackTrip:serverStart before UdpSockTemp.bind(AnyIPv4)" << std::endl;
if (gVerboseFlag) std::cout << "JackTrip:serverStart before UdpSockTemp.bind(Any)" << std::endl;
// Bind the socket
if ( !UdpSockTemp.bind(QHostAddress::AnyIPv4, mReceiverBindPort,
if ( !UdpSockTemp.bind(QHostAddress::Any, mReceiverBindPort,
QUdpSocket::DefaultForPlatform) )
{
std::cerr << "in JackTrip: Could not bind UDP socket. It may be already binded." << endl;
......@@ -545,6 +555,8 @@ throw(std::invalid_argument, std::runtime_error)
if (mappedIPv4) {
QHostAddress ipv4Address = QHostAddress(address);
mPeerAddress = ipv4Address.toString();
} else {
mPeerAddress = peerHostAddress.toString();
}
}
else {
......@@ -589,7 +601,13 @@ int JackTrip::clientPingToServerStart() throw(std::invalid_argument)
// --------------------
QTcpSocket tcpClient;
QHostAddress serverHostAddress;
serverHostAddress.setAddress(mPeerAddress);
if (!serverHostAddress.setAddress(mPeerAddress)) {
QHostInfo info = QHostInfo::fromName(mPeerAddress);
if (!info.addresses().isEmpty()) {
// use the first IP address
serverHostAddress = info.addresses().first();
}
}
// Connect Socket to Server and wait for response
// ----------------------------------------------
......
......@@ -57,9 +57,11 @@
using std::cout; using std::endl;
//*******************************************************************************
JackTripWorker::JackTripWorker(UdpMasterListener* udpmasterlistener) :
JackTripWorker::JackTripWorker(UdpMasterListener* udpmasterlistener, int BufferQueueLength, JackTrip::underrunModeT UnderRunMode) :
mUdpMasterListener(udpmasterlistener),
m_connectDefaultAudioPorts(false),
mBufferQueueLength(BufferQueueLength),
mUnderRunMode(UnderRunMode),
mSpawning(false),
mID(0),
mNumChans(1)
......@@ -83,7 +85,7 @@ JackTripWorker::~JackTripWorker()
//*******************************************************************************
void JackTripWorker::setJackTrip(int id,
uint32_t client_address,
QString client_address,
uint16_t server_port,
uint16_t client_port,
int num_channels,
......@@ -114,7 +116,7 @@ void JackTripWorker::run()
{ QMutexLocker locker(&mMutex); mSpawning = true; }
QHostAddress ClientAddress;
//QHostAddress ClientAddress;
// Try catching any exceptions that come from JackTrip
try
......@@ -147,7 +149,7 @@ void JackTripWorker::run()
mNumNetRevChans, FORCEBUFFERQ);
JackTrip * mJackTrip = &jacktrip;
#else // endwhere
JackTrip jacktrip(JackTrip::SERVERPINGSERVER, JackTrip::UDP, mNumChans, 2);
JackTrip jacktrip(JackTrip::SERVERPINGSERVER, JackTrip::UDP, mNumChans, mBufferQueueLength);
#endif // not wair
#ifdef WAIR // WAIR
......@@ -178,6 +180,9 @@ void JackTripWorker::run()
jacktrip.setConnectDefaultAudioPorts(m_connectDefaultAudioPorts);
// Set our underrun mode
jacktrip.setUnderRunMode(mUnderRunMode);
// Connect signals and slots
// -------------------------
if (gVerboseFlag) cout << "---> JackTripWorker: Connecting signals and slots..." << endl;
......@@ -191,11 +196,12 @@ void JackTripWorker::run()
QObject::connect(this, SIGNAL(signalRemoveThread()),
&jacktrip, SLOT(slotStopProcesses()), Qt::QueuedConnection);
ClientAddress.setAddress(mClientAddress);
//ClientAddress.setAddress(mClientAddress);
// If I don't type this line, I get a bus error in the next line.
// I still haven't figure out why
ClientAddress.toString().toLatin1().constData();
jacktrip.setPeerAddress(ClientAddress.toString().toLatin1().constData());
//ClientAddress.toString().toLatin1().constData();
//jacktrip.setPeerAddress(ClientAddress.toString().toLatin1().constData());
jacktrip.setPeerAddress(mClientAddress.toLatin1().constData());
jacktrip.setBindPorts(mServerPort);
//jacktrip.setPeerPorts(mClientPort);
......
......@@ -47,6 +47,7 @@
#include <QMutex>
#include "JackTrip.h"
#include "jacktrip_globals.h"
//class JackTrip; // forward declaration
class UdpMasterListener; // forward declaration
......@@ -69,7 +70,7 @@ class JackTripWorker : public QObject, public QRunnable
public:
/// \brief The class constructor
JackTripWorker(UdpMasterListener* udpmasterlistener);
JackTripWorker(UdpMasterListener* udpmasterlistener, int BufferQueueLength = gDefaultQueueLength, JackTrip::underrunModeT UnderRunMode = JackTrip::WAVETABLE);
/// \brief The class destructor
virtual ~JackTripWorker();
......@@ -83,7 +84,7 @@ public:
/// \param id ID number
/// \param address
void setJackTrip(int id,
uint32_t client_address,
QString client_address,
uint16_t server_port,
uint16_t client_port,
int num_channels,
......@@ -112,7 +113,7 @@ private:
UdpMasterListener* mUdpMasterListener; ///< Master Listener Socket
//QHostAddress mClientAddress; ///< Client Address
uint32_t mClientAddress;
QString mClientAddress;
uint16_t mServerPort; ///< Server Ephemeral Incomming Port to use with Client
bool m_connectDefaultAudioPorts;
......@@ -123,6 +124,8 @@ private:
/// If true, the prototype is working on creating (spawning) a new thread
volatile bool mSpawning;
QMutex mMutex; ///< Mutex to protect mSpawning
JackTrip::underrunModeT mUnderRunMode;
int mBufferQueueLength;
int mID; ///< ID thread number
int mNumChans; ///< Number of Channels
......
......@@ -359,6 +359,8 @@ void Settings::printUsage()
cout << "REQUIRED ARGUMENTS: " << endl;
cout << " -s, --server Run in Server Mode" << endl;
cout << " -c, --client <peer_hostname_or_IP_num> Run in Client Mode" << endl;
cout << " -S, --jacktripserver Run in Hub Server Mode" << endl;
cout << " -C, --pingtoserver <peer_name_or_IP> Run in Hub Client Mode" << endl;
cout << endl;
cout << "OPTIONAL ARGUMENTS: " << endl;
cout << " -n, --numchannels # Number of Input and Output Channels (default: "
......@@ -370,10 +372,6 @@ void Settings::printUsage()
cout << " -H, --combfilterfeedback # comb feedback adjustment for WAIR (default "
<< gDefaultCombFilterFeedback << ")" << endl;
#endif // endwhere
cout << " -q, --queue # (2 or more) Queue Buffer Length, in Packet Size (default: "
<< gDefaultQueueLength << ")" << endl;
cout << " -r, --redundancy # (1 or more) Packet Redundancy to avoid glitches with packet losses (default: 1)"
<< endl;
cout << " -q, --queue # (2 or more) Queue Buffer Length, in Packet Size (default: "
<< gDefaultQueueLength << ")" << endl;
cout << " -r, --redundancy # (1 or more) Packet Redundancy to avoid glitches with packet losses (default: 1)"
......@@ -382,7 +380,7 @@ void Settings::printUsage()
cout << " --bindport # Set only the bind port number (default: 4464)" << endl;
cout << " --peerport # Set only the Peer port number (default: 4464)" << endl;
cout << " -b, --bitres # (8, 16, 24, 32) Audio Bit Rate Resolutions (default: 16)" << endl;
cout << " -p, --hubpatch # (0, 1, 2, 3, 4) Hub auto audio patch, only has effect if running HUB SERVER mode, 0=server-to-clients, 1=client loopback, 2=client fan out/in but not loopback, 3=reserved for TUB, 4=full mix (default: 0)" << endl;
cout << " -p, --hubpatch # (0, 1, 2, 3, 4) Hub auto audio patch, only has effect if running HUB SERVER mode, 0=server-to-clients, 1=client loopback, 2=client fan out/in but not loopback, 3=reserved for TUB, 4=full mix (default: 0)" << endl;
cout << " -z, --zerounderrun Set buffer to zeros when underrun occurs (default: wavetable)" << endl;
cout << " -l, --loopback Run in Loop-Back Mode" << endl;
cout << " -j, --jamlink Run in JamLink Mode (Connect to a JamLink Box)" << endl;
......@@ -417,6 +415,13 @@ void Settings::startJackTrip()
udpmaster->setHubPatch(mHubConnectionMode);
udpmaster->setConnectDefaultAudioPorts(mConnectDefaultAudioPorts);
if (gVerboseFlag) std::cout << "Settings:startJackTrip before udpmaster->start" << std::endl;
// Set buffers to zero when underrun
if ( mUnderrrunZero ) {
cout << "Setting buffers to zero when underrun..." << endl;
cout << gPrintSeparator << std::endl;
udpmaster->setUnderRunMode(JackTrip::ZEROS);
}
udpmaster->setBufferQueueLength(mBufferQueueLength);
udpmaster->start();
//---Thread Pool Test--------------------------------------------
......
......@@ -49,6 +49,7 @@
#ifdef __WIN_32__
//#include <winsock.h>
#include <winsock2.h> //cc need SD_SEND
#include <ws2tcpip.h> // for IPv6
#endif
#if defined (__LINUX__) || (__MAC__OSX__)
#include <sys/socket.h> // for POSIX Sockets
......@@ -74,6 +75,12 @@ UdpDataProtocol::UdpDataProtocol(JackTrip* jacktrip, const runModeT runmode,
mUdpRedundancyFactor(udp_redundancy_factor)
{
mStopped = false;
mIPv6 = false;
std::memset(&mPeerAddr, 0, sizeof(mPeerAddr));
std::memset(&mPeerAddr6, 0, sizeof(mPeerAddr6));
mPeerAddr.sin_port = htons(mPeerPort);
mPeerAddr6.sin6_port = htons(mPeerPort);
if (mRunMode == RECEIVER) {
QObject::connect(this, SIGNAL(signalWaitingTooLong(int)),
jacktrip, SLOT(slotUdpWaitingTooLongClientGoneProbably(int)), Qt::QueuedConnection);
......@@ -94,16 +101,26 @@ UdpDataProtocol::~UdpDataProtocol()
void UdpDataProtocol::setPeerAddress(const char* peerHostOrIP) throw(std::invalid_argument)
{
// Get DNS Address
QHostInfo info = QHostInfo::fromName(peerHostOrIP);
if (!info.addresses().isEmpty()) {
// use the first IP address
mPeerAddress = info.addresses().first();
#if defined (__LINUX__) || (__MAC__OSX__)
//Don't make the following code conditional on windows
//(Addresses a weird timing bug when in hub client mode)
if (!mPeerAddress.setAddress(peerHostOrIP)) {
#endif
QHostInfo info = QHostInfo::fromName(peerHostOrIP);
if (!info.addresses().isEmpty()) {
// use the first IP address
mPeerAddress = info.addresses().first();
}
//cout << "UdpDataProtocol::setPeerAddress IP Address Number: "
// << mPeerAddress.toString().toStdString() << endl;
#if defined (__LINUX__) || (__MAC__OSX__)
}
#endif
// check if the ip address is valid
if ( mPeerAddress.isNull() ) {
if ( mPeerAddress.protocol() == QAbstractSocket::IPv6Protocol ) {
mIPv6 = true;
} else if ( mPeerAddress.protocol() != QAbstractSocket::IPv4Protocol ) {
QString error_message = "Incorrect presentation format address\n '";
error_message.append(peerHostOrIP);
error_message.append("' is not a valid IP address or Host Name");
......@@ -113,18 +130,56 @@ void UdpDataProtocol::setPeerAddress(const char* peerHostOrIP) throw(std::invali
throw std::invalid_argument( error_message.toStdString());
}
/*
else {
std::cout << "Peer Address set to: "
<< mPeerAddress.toString().toStdString() << std::endl;
cout << gPrintSeparator << endl;
usleep(100);
}
*/
else {
std::cout << "Peer Address set to: "
<< mPeerAddress.toString().toStdString() << std::endl;
cout << gPrintSeparator << endl;
usleep(100);
}
*/
// Save our address as an appropriate address structure
if (mIPv6) {
mPeerAddr6.sin6_family = AF_INET6;
::inet_pton(AF_INET6, mPeerAddress.toString().toLatin1().constData(),
&mPeerAddr6.sin6_addr);
} else {
mPeerAddr.sin_family = AF_INET;
::inet_pton(AF_INET, mPeerAddress.toString().toLatin1().constData(),
&mPeerAddr.sin_addr);
}
}
#if defined (__WIN_32__)
void UdpDataProtocol::setSocket(SOCKET &socket) throw(std::runtime_error)
#else
void UdpDataProtocol::setSocket(int &socket) throw(std::runtime_error)
#endif
{
//If we haven't been passed a valid socket, then we should bind one.
#if defined (__WIN_32__)
if (socket == INVALID_SOCKET) {
#else
if (socket == -1) {
#endif
try {
if (gVerboseFlag) std::cout << " UdpDataProtocol:run" << mRunMode << " before bindSocket(UdpSocket)" << std::endl;
socket = bindSocket(); // Bind Socket
} catch ( const std::exception & e ) {
emit signalError( e.what() );
return;
}
}
mSocket = socket;
}
//*******************************************************************************
void UdpDataProtocol::bindSocket(QUdpSocket& UdpSocket) throw(std::runtime_error)
#if defined (__WIN_32__)
SOCKET UdpDataProtocol::bindSocket() throw(std::runtime_error)
#else
int UdpDataProtocol::bindSocket() throw(std::runtime_error)
#endif
{
QMutexLocker locker(&sUdpMutex);
......@@ -140,7 +195,7 @@ void UdpDataProtocol::bindSocket(QUdpSocket& UdpSocket) throw(std::runtime_error
// Tell the user that we couldn't find a useable
// winsock.dll.
return;
return INVALID_SOCKET;
}
// Confirm that the Windows Sockets DLL supports 1.1. or higher
......@@ -150,28 +205,36 @@ void UdpDataProtocol::bindSocket(QUdpSocket& UdpSocket) throw(std::runtime_error
// Tell the user that we couldn't find a useable
// winsock.dll.
WSACleanup( );
return;
return INVALID_SOCKET;
}
// Creat socket descriptor
SOCKET sock_fd;
SOCKADDR_IN local_addr;
#endif
#if defined ( __LINUX__ ) || (__MAC_OSX__)
int sock_fd;
//Set local IPv4 Address
struct sockaddr_in local_addr;
#endif
// Creat socket descriptor
sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
//::bzero(&local_addr, sizeof(local_addr));
std::memset(&local_addr, 0, sizeof(local_addr)); // set buffer to 0
local_addr.sin_family = AF_INET; //AF_INET: IPv4 Protocol
local_addr.sin_addr.s_addr = htonl(INADDR_ANY); //INADDR_ANY: let the kernel decide the active address
local_addr.sin_port = htons(mBindPort); //set local port
//Set local IPv4 or IPv6 Address
struct sockaddr_in local_addr;
struct sockaddr_in6 local_addr6;
// Create socket descriptor
if (mIPv6) {
sock_fd = socket(AF_INET6, SOCK_DGRAM, 0);
std::memset(&local_addr6, 0, sizeof(local_addr6));
local_addr6.sin6_family = AF_INET6;
local_addr6.sin6_addr = in6addr_any;
local_addr6.sin6_port = htons(mBindPort);
} else {
sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
//::bzero(&local_addr, sizeof(local_addr));
std::memset(&local_addr, 0, sizeof(local_addr)); // set buffer to 0
local_addr.sin_family = AF_INET; //AF_INET: IPv4 Protocol
local_addr.sin_addr.s_addr = htonl(INADDR_ANY); //INADDR_ANY: let the kernel decide the active address
local_addr.sin_port = htons(mBindPort); //set local port
}
// Set socket to be reusable, this is platform dependent
int one = 1;
......@@ -189,73 +252,45 @@ void UdpDataProtocol::bindSocket(QUdpSocket& UdpSocket) throw(std::runtime_error
#endif
// Bind the Socket
#if defined ( __LINUX__ ) || ( __MAC_OSX__ )
if ( (::bind(sock_fd, (struct sockaddr *) &local_addr, sizeof(local_addr))) < 0 )
{ throw std::runtime_error("ERROR: UDP Socket Bind Error"); }
#endif
#if defined (__WIN_32__)
//int bound;
//bound = bind(sock_fd, (SOCKADDR *) &local_addr, sizeof(local_addr));
if ( (bind(sock_fd, (SOCKADDR *) &local_addr, sizeof(local_addr))) == SOCKET_ERROR )
{ throw std::runtime_error("ERROR: UDP Socket Bind Error"); }
#endif
if (mIPv6) {
if ( (::bind(sock_fd, (struct sockaddr *) &local_addr6, sizeof(local_addr6))) < 0 )
{ throw std::runtime_error("ERROR: UDP Socket Bind Error"); }
} else {
if ( (::bind(sock_fd, (struct sockaddr *) &local_addr, sizeof(local_addr))) < 0 )
{ throw std::runtime_error("ERROR: UDP Socket Bind Error"); }
}
// To be able to use the two UDP sockets bound to the same port number,
// we connect the receiver and issue a SHUT_WR.
if (mRunMode == SENDER) {
// This didn't work for IPv6, so we'll instead share a full duplex socket.
/*if (mRunMode == SENDER) {
// We use the sender as an unconnected UDP socket
UdpSocket.setSocketDescriptor(sock_fd, QUdpSocket::BoundState,
QUdpSocket::WriteOnly);
}
else if (mRunMode == RECEIVER) {
#if defined (__LINUX__) || (__MAC_OSX__)
// Set peer IPv4 Address
struct sockaddr_in peer_addr;
bzero(&peer_addr, sizeof(peer_addr));
peer_addr.sin_family = AF_INET; //AF_INET: IPv4 Protocol
peer_addr.sin_addr.s_addr = htonl(INADDR_ANY); //INADDR_ANY: let the kernel decide the active address
peer_addr.sin_port = htons(mPeerPort); //set local port
// Connect the socket and issue a Write shutdown (to make it a
// reader socket only)
if ( (::inet_pton(AF_INET, mPeerAddress.toString().toLatin1().constData(),
&peer_addr.sin_addr)) < 1 )
{ throw std::runtime_error("ERROR: Invalid address presentation format"); }
if ( (::connect(sock_fd, (struct sockaddr *) &peer_addr, sizeof(peer_addr))) < 0)
}*/
if (!mIPv6) {
// Connect only if we're using IPv4.
// (Connecting presents an issue when a host has multiple IP addresses and the peer decides to send from
// a different address. While this generally won't be a problem for IPv4, it will for IPv6.)
if ( (::connect(sock_fd, (struct sockaddr *) &mPeerAddr, sizeof(mPeerAddr))) < 0)
{ throw std::runtime_error("ERROR: Could not connect UDP socket"); }
if ( (::shutdown(sock_fd,SHUT_WR)) < 0)
{ throw std::runtime_error("ERROR: Could suntdown SHUT_WR UDP socket"); }
#if defined (__LINUX__) || (__MAC_OSX__)
//if ( (::shutdown(sock_fd,SHUT_WR)) < 0)
//{ throw std::runtime_error("ERROR: Could shutdown SHUT_WR UDP socket"); }
#endif
#if defined __WIN_32__
// Set peer IPv4 Address
SOCKADDR_IN peer_addr;
std::memset(&peer_addr, 0, sizeof(peer_addr)); // set buffer to 0
peer_addr.sin_family = AF_INET; //AF_INET: IPv4 Protocol
peer_addr.sin_addr.s_addr = htonl(INADDR_ANY); //INADDR_ANY: let the kernel decide the active address
peer_addr.sin_port = htons(mPeerPort); //set local port
// Connect the socket and issue a Write shutdown (to make it a
// reader socket only)
peer_addr.sin_addr.s_addr = inet_addr(mPeerAddress.toString().toLatin1().constData());
int con = (::connect(sock_fd, (struct sockaddr *) &peer_addr, sizeof(peer_addr)));
if ( con < 0)
{
fprintf(stderr, "ERROR: Could not connect UDP socket");
throw std::runtime_error("ERROR: Could not connect UDP socket");
}
//cout<<"connect returned: "<<con<<endl;
int shut_sr = shutdown(sock_fd, SD_SEND); //shut down sender's receive function
/*int shut_sr = shutdown(sock_fd, SD_SEND); //shut down sender's receive function
if ( shut_sr< 0)
{
fprintf(stderr, "ERROR: Could not shutdown SD_SEND UDP socket");
throw std::runtime_error("ERROR: Could not shutdown SD_SEND UDP socket");
}
}*/
#endif
UdpSocket.setSocketDescriptor(sock_fd, QUdpSocket::ConnectedState,
QUdpSocket::ReadOnly);
cout << "UDP Socket Receiving in Port: " << mBindPort << endl;
cout << gPrintSeparator << endl;
}
return sock_fd;
// OLD CODE WITHOUT POSIX FIX--------------------------------------------------
/*
/// \todo if port is already used, try binding in a different port
......@@ -291,11 +326,34 @@ int UdpDataProtocol::receivePacket(QUdpSocket& UdpSocket, char* buf, const size_
//*******************************************************************************
int UdpDataProtocol::sendPacket(QUdpSocket& UdpSocket, const QHostAddress& PeerAddress,
const char* buf, const size_t n)
int UdpDataProtocol::sendPacket(const char* buf, const size_t n)
{
int n_bytes = UdpSocket.writeDatagram(buf, n, PeerAddress, mPeerPort);
/*#if defined (__WIN_32__)
//Alternative windows specific code that uses winsock equivalents of the bsd socket functions.
DWORD n_bytes;
WSABUF buffer;
int error;
buffer.len = n;
buffer.buf = (char *)buf;
if (mIPv6) {
error = WSASendTo(mSocket, &buffer, 1, &n_bytes, 0, (struct sockaddr *) &mPeerAddr6, sizeof(mPeerAddr6), 0, 0);
} else {
error = WSASend(mSocket, &buffer, 1, &n_bytes, 0, 0, 0);
}
if (error == SOCKET_ERROR) {
cout << "Socket Error: " << WSAGetLastError() << endl;
}
return (int)n_bytes;
#else*/
int n_bytes;
if (mIPv6) {
n_bytes = ::sendto(mSocket, buf, n, 0, (struct sockaddr *) &mPeerAddr6, sizeof(mPeerAddr6));
} else {
n_bytes = ::send(mSocket, buf, n, 0);
}
return n_bytes;
//#endif
}
......@@ -330,20 +388,21 @@ void UdpDataProtocol::run()
// mJackTrip, SLOT(slotStopProcesses()),
// Qt::QueuedConnection);
// Creat and bind sockets
//Wrap our socket in a QUdpSocket object if we're the receiver, for convenience.
//If we're the sender, we'll just write directly to our socket.
QUdpSocket UdpSocket;
try {
if (gVerboseFlag) std::cout << " UdpDataProtocol:run" << mRunMode << " before bindSocket(UdpSocket)" << std::endl;
bindSocket(UdpSocket); // Bind Socket
} catch ( const std::exception & e ) {
emit signalError( e.what() );
return;
if (mRunMode == RECEIVER) {
if (mIPv6) {
UdpSocket.setSocketDescriptor(mSocket, QUdpSocket::BoundState,
QUdpSocket::ReadOnly);
} else {
UdpSocket.setSocketDescriptor(mSocket, QUdpSocket::ConnectedState,
QUdpSocket::ReadOnly);
}
cout << "UDP Socket Receiving in Port: " << mBindPort << endl;
cout << gPrintSeparator << endl;
}
QHostAddress PeerAddress;
PeerAddress = mPeerAddress;
if (gVerboseFlag) std::cout << " UdpDataProtocol:run" << mRunMode << " before Setup Audio Packet buffer, Full Packet buffer, Redundancy Variables" << std::endl;
// Setup Audio Packet buffer
size_t audio_packet_size = getAudioPacketSizeInBites();
......@@ -372,7 +431,7 @@ void UdpDataProtocol::run()
// Set realtime priority (function in jacktrip_globals.h)
if (gVerboseFlag) std::cout << " UdpDataProtocol:run" << mRunMode << " before setRealtimeProcessPriority()" << std::endl;
std::cout << "Experimental version -- not using setRealtimeProcessPriority()" << std::endl;
//std::cout << "Experimental version -- not using setRealtimeProcessPriority()" << std::endl;
//setRealtimeProcessPriority();
/////////////////////
......@@ -512,6 +571,8 @@ void UdpDataProtocol::run()
break; }
case SENDER : {
//Make sure we don't start sending packets too soon.
QThread::msleep(100);
//-----------------------------------------------------------------------------------
while ( !mStopped )
{
......@@ -525,9 +586,7 @@ void UdpDataProtocol::run()
sendPacket( UdpSocket, PeerAddress, reinterpret_cast<char*>(mFullPacket), full_packet_size);
*/
//----------------------------------------------------------------------------------
sendPacketRedundancy(UdpSocket,
PeerAddress,
full_redundant_packet,
sendPacketRedundancy(full_redundant_packet,
full_redundant_packet_size,
full_packet_size);
}
......@@ -626,9 +685,7 @@ void UdpDataProtocol::receivePacketRedundancy(QUdpSocket& UdpSocket,
}
//*******************************************************************************
void UdpDataProtocol::sendPacketRedundancy(QUdpSocket& UdpSocket,
QHostAddress& PeerAddress,
int8_t* full_redundant_packet,
void UdpDataProtocol::sendPacketRedundancy(int8_t* full_redundant_packet,
int full_redundant_packet_size,
int full_packet_size)
{
......@@ -649,7 +706,7 @@ void UdpDataProtocol::sendPacketRedundancy(QUdpSocket& UdpSocket,
//int random_integer = rand();
//if ( random_integer > (RAND_MAX/10) )
//{
sendPacket( UdpSocket, PeerAddress, reinterpret_cast<char*>(full_redundant_packet),
sendPacket( reinterpret_cast<char*>(full_redundant_packet),
full_redundant_packet_size);
//}