Commit 2ef23480 authored by jcaceres's avatar jcaceres
Browse files

WORKING ON qt4 !!!

parent 8131ec61
......@@ -11,7 +11,8 @@
#include "Stk.h"
#include "stdio.h"
#include "stdlib.h"
#include "qstring.h"
//#include "qstring.h"
#include <qstring.h>
class AudioDevice;
class JackClient:public Stk
......
......@@ -9,7 +9,8 @@
//#include "../src/ui/MainWindow.h"
#include "q3ptrlist.h"
#include "qthread.h"
#include "qstring.h"
//#include "qstring.h"
#include <qstring.h>
#include "qtimer.h"
#include "StreamBD.h"
//#include "StripChart.h"
......
......@@ -579,8 +579,10 @@ StreamBD::EstablishConnection (runModeT runMode, char *hostname, UDPOutput * net
usleep (10000);
// cout << ".";
}
cout << endl << "Connection received from: " <<
netin->peer ().toString () << endl;
//**************JPC COMENTED OUT*******************
//cout << endl << "Connection received from: " <<
// netin->peer ().toString () << endl;
//*************************************************
cout << "Requesting return connection....";
netout->connect (netin->peer ());
cout << "SUCCESS!" << endl;
......
......@@ -131,7 +131,8 @@ class MainDialog;
class StreamBD:public QObject
{
Q_OBJECT public:
//Q_OBJECT public://***JPC COMENTED OUT
public:
StreamBD();
~StreamBD();
int cmd (MainDialog *eventThread);
......
......@@ -60,7 +60,7 @@ mode (mode)
case RECORD:
if (jack)
jdevice =
new JackClient (APP_NAME,
new JackClient ("jacktrip",//APP_NAME, //*JPC Hack, need to fix later
audioInfo->
getNumChans (),
audioInfo->
......@@ -85,7 +85,7 @@ mode (mode)
case PLAYBACK:
if (jack)
jdevice =
new JackClient (APP_NAME,
new JackClient ("jacktrip",//APP_NAME, //*JPC Hack, need to fix later
audioInfo->
getNumChans (),
audioInfo->
......@@ -106,7 +106,7 @@ mode (mode)
case DUPLEX:
if (jack)
jdevice =
new JackClient (APP_NAME,
new JackClient ("jacktrip",//APP_NAME, //*JPC Hack, need to fix later
audioInfo->
getNumChans (),
audioInfo->
......@@ -172,7 +172,8 @@ mode (mode)
{
readLock = new QSemaphore (1);
writeLock = new QSemaphore (1);
(*writeLock)++; // lock out write, to start with read
//(*writeLock)++; // lock out write, to start with read
(*writeLock).acquire(); //****JPC qt4 porting******
}
if (jack)
......@@ -240,7 +241,8 @@ AudioDevice::bufferPtrs (void *jib, void *job)
void
AudioDevice::unlockRead ()
{
(*readLock)--; // so audio input thread will unblock when stopped
//(*readLock)--; // so audio input thread will unblock when stopped
(*readLock).release();//****JPC qt4 porting******
}
void
......@@ -252,9 +254,11 @@ AudioDevice::readBuffer (void *to)
cerr << "ERROR: AudioDevice::readBuffer called on device in PLAYBACK mode!" << endl;
}
(*readLock)++;
//(*readLock)++;
(*readLock).acquire();//****JPC qt4 porting******
memcpy (to, buffer, bytesPerBuffer);
(*writeLock)--;
//(*writeLock)--;
(*writeLock).release();//****JPC qt4 porting******
}
......@@ -268,10 +272,12 @@ AudioDevice::writeBuffer (void *from)
if (harp == false)
{
(*writeLock)++;
//(*writeLock)++;
(*writeLock).acquire();//****JPC qt4 porting******
memcpy (buffer, from, bytesPerBuffer);
tick (); // calls tickstream, blocks
(*readLock)--;
//(*readLock)--;
(*readLock).release();//****JPC qt4 porting******
}
else
......
......@@ -19,6 +19,10 @@
#include "JackClient.h"
#include "qthread.h"
#include "StreamBD.h"
//#include <qwaitcondition.h>
#include <QWaitCondition>
#include <QSemaphore>
/**
* @brief Interfaces with an RtAudio sound device.
*/
......
......@@ -41,6 +41,7 @@ maxSeq (maxSeq)
prepareReaderWriter ();
dataLock = new QSemaphore (1);
cout << (*dataLock).available() << " FDF SDFJSDIF JSDFIJ DSIFJSDOI JOSI" << endl;
secondTry = false;
}
......@@ -93,7 +94,8 @@ CircularBuffer::write (const void *writeChunk)
this->overflowReset ();
}
if (blockOnEmpty)
(*readSemaphore)--;
//(*readSemaphore)--;
(*readSemaphore).release();//****JPC qt4 porting******
return chunkSize;
}
......@@ -102,7 +104,8 @@ CircularBuffer::writeRedundant (const void *writeChunk, int z, int seq)
{
// if (isFull () == false)
{
(*dataLock)++;
//(*dataLock)++;
(*dataLock).acquire();//****JPC qt4 porting******
int tmpPosition = writePosition - z;
if (tmpPosition < 0)
{
......@@ -124,10 +127,13 @@ CircularBuffer::writeRedundant (const void *writeChunk, int z, int seq)
// cout << "seq " << seq <<"\t";
if (z == 0)
writePosition = ++writePosition % numBufChunks;
(*dataLock)--;
//(*dataLock)--;
(*dataLock).release();//****JPC qt4 porting******
}
if (blockOnEmpty) {
//(*readSemaphore)--;
(*readSemaphore).release();//****JPC qt4 porting******
}
if (blockOnEmpty)
(*readSemaphore)--;
// return chunkSize;
return writePosition;
}
......@@ -137,7 +143,8 @@ CircularBuffer::read (void *readChunk)
{
if (blockOnEmpty)
{
(*readSemaphore)++;
//(*readSemaphore)++;
(*readSemaphore).acquire();//****JPC qt4 porting******
if (isEmpty () == false)
......@@ -158,7 +165,8 @@ CircularBuffer::read (void *readChunk)
{ // not blockOnEmpty
if (lastSeq == -1)
lastSeq = 0;
(*dataLock)++;
//(*dataLock)++;
(*dataLock).acquire();//****JPC qt4 porting******
int nextSeq = (lastSeq + 1) % maxSeq;
int i = 0;
int lag = -maxSeq;
......@@ -188,7 +196,8 @@ CircularBuffer::read (void *readChunk)
memcpy (readChunk,
(void *) ((char *) cbBuffer +
bestReadPosition * chunkSize), chunkSize);
(*dataLock)--;
//(*dataLock)--;
(*dataLock).release();//****JPC qt4 porting******
}
if (blockOnEmpty)
return chunkSize;
......@@ -199,17 +208,20 @@ CircularBuffer::read (void *readChunk)
/** Full if writer is one circular position behind the reader. */
bool CircularBuffer::isFull ()
{
(*dataLock)++;
//(*dataLock)++;
(*dataLock).acquire();//****JPC qt4 porting******
// cerr << "(" << writePosition << "," << readPosition << ") ";
// cerr << ((readPosition + numChunks - writePosition) % numChunks) << endl;
if (writePosition == (readPosition + numBufChunks - 1) % numBufChunks)
{
(*dataLock)--;
//(*dataLock)--;
(*dataLock).release();//****JPC qt4 porting******
return true;
}
else
{
(*dataLock)--;
//(*dataLock)--;
(*dataLock).release();//****JPC qt4 porting******
return false;
}
}
......@@ -218,15 +230,18 @@ bool CircularBuffer::isFull ()
/** Empty if writer is equal to reader */
bool CircularBuffer::isEmpty ()
{
(*dataLock)++;
//(*dataLock)++;
(*dataLock).acquire();//****JPC qt4 porting******
if (writePosition == readPosition)
{
(*dataLock)--;
//(*dataLock)--;
(*dataLock).release();//****JPC qt4 porting******
return true;
}
else
{
(*dataLock)--;
//(*dataLock)--;
(*dataLock).release();//****JPC qt4 porting******
return false;
}
}
......@@ -235,7 +250,8 @@ void
CircularBuffer::prepareReaderWriter ()
{
readSemaphore = new QSemaphore (1);
(*readSemaphore)++;
//(*readSemaphore)++;
(*readSemaphore).acquire();//****JPC qt4 porting******
fillChunksWithZeros (0, numBufChunks / 2 - 1);
}
......@@ -249,8 +265,10 @@ CircularBuffer::fillChunksWithZeros (int from, int to)
{
memset (((char *) cbBuffer + writePosition * chunkSize), 0,
chunkSize);
if (blockOnEmpty)
(*readSemaphore)--;
if (blockOnEmpty) {
//(*readSemaphore)--;
(*readSemaphore).release();//****JPC qt4 porting******
}
}
writePosition = writePosition % numBufChunks;
readPosition = from;
......@@ -263,10 +281,12 @@ CircularBuffer::underrunReset ()
cerr << "----output- underflow!!" << endl;
else
cerr << "-input--- underflow!!" << endl;
(*dataLock)++;
//(*dataLock)++;
(*dataLock).acquire();//****JPC qt4 porting******
delete readSemaphore;
prepareReaderWriter ();
(*dataLock)--;
//(*dataLock)--;
(*dataLock).release();//****JPC qt4 porting******
}
void
......@@ -277,7 +297,9 @@ CircularBuffer::overflowReset ()
else
cerr << "-input--- Overflow!" << endl;
(*dataLock)++;
//(*dataLock)++;
(*dataLock).acquire();//****JPC qt4 porting******
readPosition = (writePosition + (numBufChunks / 2)) % numBufChunks;
(*dataLock)--;
//(*dataLock)--;
(*dataLock).release();//****JPC qt4 porting******
}
//circularbuffer.h
#ifndef INCLUDED_CIRCULARBUFFER
#define INCLUDED_CIRCULARBUFFER
#include <qthread.h>
#ifndef INCLUDED_CIRCULARBUFFER
#define INCLUDED_CIRCULARBUFFER
#include <qthread.h>
//#include <qsemaphore.h>
#include <QSemaphore>
/**
* @brief Provides a circular buffer that can be written to and read
* from asynchronously.
......@@ -19,8 +20,8 @@
* return a buffer of 0s and print a buffer underrun error message.
* Calling write on a full buffer will clear the entire CircularBuffer,
* and print a buffer overrun error message.
*/
*/
class CircularBuffer {
int writePosition; /**< Pointer to the position to which to write the
* next audio buffer. */
......@@ -37,9 +38,9 @@ class CircularBuffer {
int *seqBuffer;
private:
// Semaphore *writeSemaphore; /**< Locks write access. */
QSemaphore *readSemaphore; /**< Locks read access. */
QSemaphore *dataLock; /**< Locks access to state variables. */
public:
QSemaphore *readSemaphore; /**< Locks read access. */
QSemaphore *dataLock; /**< Locks access to state variables. */
public:
bool isOpen; /**< Is the CircularBuffer ready to be read/written? */
bool isEmpty();
......
......@@ -13,7 +13,8 @@ APP_NAME_QUOTES=\\\"$APP_NAME\\\"
#rm -r obj
#rm -r moc
#rm $APP_NAME.pro
rm $APP_NAME.pro
rm Makefile
#echo "progen"
......
......@@ -71,7 +71,8 @@ Stream::addOutput (OutputPlugin * newout)
{ // We are going to need output synchronization locking.
// add a lock for the first output (didn't need it when it was the only one.)
tmp = new QSemaphore (10);
(*tmp)++;
//(*tmp)++;
(*tmp).acquire();//****JPC qt4 porting******
APPEND (locks, tmp);
}
......@@ -84,7 +85,8 @@ Stream::addOutput (OutputPlugin * newout)
}
tmp = new QSemaphore (10);
(*tmp)++;
//(*tmp)++;
(*tmp).acquire();//****JPC qt4 porting******
APPEND (locks, tmp);
}
......@@ -122,7 +124,8 @@ Stream::read (void *buf, int key)
#if (debugMe)
cerr << key << "->POST ";
#endif
(*sem)--;
//(*sem)--;
(*sem).release();//****JPC qt4 porting******
}
}
}
......@@ -135,7 +138,8 @@ Stream::read (void *buf, int key)
#if (debugMe)
cerr << key << "->WAIT ";
#endif
(*sem)++;
//(*sem)++;
(*sem).acquire();//****JPC qt4 porting******
}
}
......
......@@ -69,8 +69,10 @@ UDPOutput::connect (QHostAddress remote)
}
// sets peerAddress
sock->connect (remote, netInfo->getInPort ());
cout << "Connecting to " << remote.toString () << ":" << netInfo->
getInPort () << endl;
//**************JPC COMENTED OUT*******************
//cout << "Connecting to " << remote.toString () << ":" << netInfo->
// getInPort () << endl;
//*************************************************
return 0;
}
......@@ -126,8 +128,10 @@ UDPOutput::run ()
if (res < 0)
{
perror ("Send");
cout << "error sending to " << sock->peerAddress ().
toString () << endl;
//**************JPC COMENTED OUT*******************
//cout << "error sending to " << sock->peerAddress ().
// toString () << endl;
//*************************************************
return;
}
/*
......
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