Commit 94061367 authored by jcaceres's avatar jcaceres
Browse files

ported to qt4

parent cf0103f6
getBytesPerBuffer is being set at audioInfo.cpp (Check that)
sizeof (INT16) : bytesPerSample
=========================================================================
UDPhdr.txt
Header:
/************************************************************************/
/* values for the UDP stream type */
/* streamType is a 16-bit value at the head of each UDP stream */
/* Its bit map is as follows: (b15-msb) */
/* B15:reserved, B14:extended header, B13 Stereo, B12 not 16-bit */
/* B11-B9: 0-48 Khz, 1-44 Khz, 2-32 Khz, 3-24 Khz, */
/* 4-22 Khz, 5-16 Khz, 6-11 Khz, 7-8 Khz */
/* B8-0: Samples in packet */
/************************************************************************/
#define ETX_RSVD (0<<15)
#define ETX_XTND (1<<14)
#define ETX_STEREO (1<<13)
#define ETX_MONO (0<<13)
#define ETX_16BIT (0<<12)
#define ETX_RATE_MASK(a) (a&(0x7<<9))
#define ETX_48KHZ (0<<9)
#define ETX_44KHZ (1<<9)
#define ETX_32KHZ (2<<9)
#define ETX_24KHZ (3<<9)
#define ETX_22KHZ (4<<9)
#define ETX_16KHZ (5<<9)
#define ETX_11KHZ (6<<9)
#define ETX_8KHZ (7<<9)
#define ETX_SPP(a) (a&0x01FF) /* able to express up to 512 SPP */
/* Note that the extended header is likely to have 6 more bytes: */
/* 2 for the sequence number, and 4 for a timestamp */
// Written by Juan-Pablo Caceres
// Soundwire Group, 2008
//JamLink UDP Header:
/************************************************************************/
/* values for the UDP stream type */
/* streamType is a 16-bit value at the head of each UDP stream */
/* Its bit map is as follows: (b15-msb) */
/* B15:reserved, B14:extended header, B13 Stereo, B12 not 16-bit */
/* B11-B9: 0-48 Khz, 1-44 Khz, 2-32 Khz, 3-24 Khz, */
/* 4-22 Khz, 5-16 Khz, 6-11 Khz, 7-8 Khz */
/* B8-0: Samples in packet */
/************************************************************************/
#define ETX_RSVD (0<<15)
#define ETX_XTND (1<<14)
#define ETX_STEREO (1<<13)
#define ETX_MONO (0<<13)
#define ETX_16BIT (0<<12)
#define ETX_RATE_MASK(a) (a&(0x7<<9))
#define ETX_48KHZ (0<<9)
#define ETX_44KHZ (1<<9)
#define ETX_32KHZ (2<<9)
#define ETX_24KHZ (3<<9)
#define ETX_22KHZ (4<<9)
#define ETX_16KHZ (5<<9)
#define ETX_11KHZ (6<<9)
#define ETX_8KHZ (7<<9)
#define ETX_SPP(a) (a&0x01FF) /* able to express up to 512 SPP */
/* Note that the extended header is likely to have 6 more bytes: */
/* 2 for the sequence number, and 4 for a timestamp */
//Instpired on Thinking in C++
//http://www.linuxtopia.org/online_books/programming_books/thinking_in_c++/Chapter03_045.html
// Display a unsigned short (2 bytes) in binary
void printBinary(const unsigned short val);
#include <iostream>
#define PR(STR, EXPR) \
cout << STR; printBinary(EXPR); cout << endl;
void printBinary(const unsigned short val) {
for(int i = 15; i >= 0; i--)
if(val & (1 << i))
std::cout << "1";
else
std::cout << "0";
}
......@@ -43,14 +43,15 @@ IpHeader;
typedef struct _nshdr
{
char i_type;
char i_nchans;
char i_copies;
unsigned short i_nframes;
unsigned short i_cksum;
unsigned short i_seq;
unsigned short i_rtnseq;
unsigned short i_rtt;
//char i_type; //JPC JLink***********************************
//char i_nchans;//JPC JLink***********************************
//char i_copies;//JPC JLink***********************************
//unsigned short i_nframes;//JPC JLink***********************************
//unsigned short i_cksum;//JPC JLink***********************************
//unsigned short i_seq;
//unsigned short i_rtnseq;//JPC JLink***********************************
//unsigned short i_rtt;//JPC JLink***********************************
unsigned short i_head;//JPC JLink***********************************
}
nsHeader;
......
......@@ -6,6 +6,7 @@
#include <stdio.h>
#include <iostream.h>
#include <QHostInfo>//***JPC Port to qt4*****************
#include "jamlink.h"
extern QString *IPv4Addr (char *namebuf);
extern int set_fifo_priority (bool half);
......@@ -21,10 +22,12 @@ UDPInput::UDPInput (NetworkInfoT netInfo, AudioInfoT audInfo):
_rcvr = NULL;
packetIndex = 0;
wholeSize = sizeof (nsHeader) + (netInfo->getChunksPerPacket () * bpp) + 1;
//wholeSize = sizeof (nsHeader) + (netInfo->getChunksPerPacket () * bpp) + 1;//JPC JLink***********************************
wholeSize = sizeof (nsHeader) + (netInfo->getChunksPerPacket () * bpp);//JPC JLink***********************************
packetData = new char[wholeSize];
memset (packetData, 0, wholeSize);
numRedundantBuffers = netInfo->getChunksPerPacket() - 1;
//numRedundantBuffers = netInfo->getChunksPerPacket() - 1;//JPC JLink***********************************
numRedundantBuffers = 0;//JPC JLink***********************************
maxPacketIndex = netInfo->getMaxSeq();
}
......@@ -66,10 +69,19 @@ UDPInput::rcv (char *buf)
//cout << "***Packet Size***: " << rv << endl;//***JPC Port to qt4*****************
char *datapart;
packetIndex = ((nsHeader *) packetData)->i_seq;
datapart = packetData + sizeof (nsHeader) +
((packetIndex % ((nsHeader *) packetData)->i_copies) * bpp);
//packetIndex = ((nsHeader *) packetData)->i_seq;//JPC JLink***********************************
packetHeader = ((nsHeader *) packetData)->i_head;//JPC JLink***********************************
//datapart = packetData + sizeof (nsHeader) + //JPC JLink***********************************
// ((packetIndex % ((nsHeader *) packetData)->i_copies) * bpp);//JPC JLink***********************************
datapart = packetData + sizeof (nsHeader);//JPC JLink***********************************
memcpy (buf, datapart, bpp);
//###############JPC JLink#######################
// Binary print function
//unsigned short caca = 0xFFFF;
//PR("header in binary: ", ETX_STEREO);
//###############################################
/*
((nsHeader *) packetData)->i_type = 0;
((nsHeader *) packetData)->i_nframes = 1;
......@@ -94,14 +106,15 @@ int
UDPInput::rcvz1 (char *bufz1, int z)
{
char *datapart;
packetIndex = ((nsHeader *) packetData)->i_seq-z;
//packetIndex = ((nsHeader *) packetData)->i_seq-z;//JPC JLink***********************************
packetIndex = ((nsHeader *) packetData)->i_head-z;//JPC JLink***********************************
if (packetIndex < 0)
{
packetIndex += maxPacketIndex;
// cout << "backed below 0 (a good thing)" << endl;
}
datapart = packetData + sizeof (nsHeader) +
((packetIndex % ((nsHeader *) packetData)->i_copies) * bpp);
//datapart = packetData + sizeof (nsHeader) + //JPC JLink***********************************
// ((packetIndex % ((nsHeader *) packetData)->i_copies) * bpp);//JPC JLink***********************************
memcpy (bufz1, datapart, bpp);
return packetIndex;
}
......@@ -186,9 +199,9 @@ UDPInput::run ()
unsigned long now = 0;
unsigned long lastTickTime = usecTime ();
int ctr = 0;
double max = 0.0;
//double max = 0.0;//JPC JLink***********************************
int gap;
double gapAvg = 0.0;
//double gapAvg = 0.0; //JPC JLink***********************************
while (_running)
{
// If timeout is non-null and no error occurred
......@@ -220,7 +233,8 @@ UDPInput::run ()
stream->writeRedundant (bufz1, key, z, zseq);
z--;
}
gap = stream->writeRedundant (buf, key, 0, seq);
//gap = stream->writeRedundant (buf, key, 0, seq);//JPC JLink***********************************
stream->writeRedundant (buf, key, 0, seq);//JPC JLink***********************************
// cout << "writePosition " << gap <<"\t\t";
/*
now = usecTime ();
......
......@@ -28,6 +28,7 @@ private:
bool has_peer;
int packetIndex; //used for netdebug, checking order of incoming packets
unsigned short packetHeader;//JPC JLink***********************************
int maxPacketIndex;
char *packetData;
......
......@@ -41,14 +41,16 @@ UDPOutput::UDPOutput (NetworkInfoT netInfo, AudioInfoT audInfo):
}
packetIndex = 0;
wholeSize = sizeof (nsHeader) + (netInfo->getChunksPerPacket () * bpp) + 1;
//wholeSize = sizeof (nsHeader) + (netInfo->getChunksPerPacket () * bpp) + 1;//JPC JLink***********************************
wholeSize = sizeof (nsHeader) + (netInfo->getChunksPerPacket () * bpp)-1;//JPC JLink***********************************
packetData = new char[wholeSize];
memset (packetData, 0, wholeSize);
// fixed parameters
((nsHeader *) packetData)->i_type = 0;
((nsHeader *) packetData)->i_nframes = audInfo->getFramesPerBuffer ();
((nsHeader *) packetData)->i_nchans = audInfo->getNumAudioChans ();
((nsHeader *) packetData)->i_copies = netInfo->getChunksPerPacket ();
//((nsHeader *) packetData)->i_type = 0;//JPC JLink***********************************
//((nsHeader *) packetData)->i_nframes = audInfo->getFramesPerBuffer ();//JPC JLink***********************************
//((nsHeader *) packetData)->i_nchans = audInfo->getNumAudioChans ();//JPC JLink***********************************
//((nsHeader *) packetData)->i_copies = netInfo->getChunksPerPacket ();//JPC JLink***********************************
numBuffers = netInfo->getChunksPerPacket();
maxPacketIndex = netInfo->getMaxSeq();
......@@ -93,13 +95,15 @@ int
UDPOutput::send (char *buf)
{
packetIndex = (packetIndex + 1) % maxPacketIndex;
((nsHeader *) packetData)->i_cksum = 4;
((nsHeader *) packetData)->i_seq = packetIndex;
((nsHeader *) packetData)->i_rtnseq = 6;
((nsHeader *) packetData)->i_rtt = 7;
((nsHeader *) packetData)->i_head = packetIndex;//JPC JLink***********************************
//((nsHeader *) packetData)->i_cksum = 4;//JPC JLink***********************************
//((nsHeader *) packetData)->i_seq = packetIndex;//JPC JLink***********************************
//((nsHeader *) packetData)->i_rtnseq = 6;//JPC JLink***********************************
//((nsHeader *) packetData)->i_rtt = 7;//JPC JLink***********************************
char *datapart;
datapart = packetData + sizeof (nsHeader) +
((packetIndex % numBuffers) * bpp);
//datapart = packetData + sizeof (nsHeader) + //JPC JLink***********************************
// ((packetIndex % numBuffers) * bpp);//JPC JLink***********************************
datapart = packetData + sizeof (nsHeader);//JPC JLink***********************************
//memset(datapart,'E', bpp);
//strncpy (datapart, "Whee, i`m a fast packet.",bpp);
......
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