Commit 457b2b75 authored by Stephane Letz's avatar Stephane Letz
Browse files

Cleanup Netjack2 code.

parent 2d7d1ecd
......@@ -207,6 +207,7 @@ namespace Jack
{
fNPorts = nports;
fNetBuffer = net_buffer;
fNumPackets = 0;
fPortBuffer = new sample_t*[fNPorts];
fConnectedPorts = new bool[fNPorts];
......@@ -314,7 +315,7 @@ namespace Jack
active_ports++;
}
}
//jack_info("active_ports %d", active_ports);
return active_ports;
}
......@@ -367,6 +368,7 @@ namespace Jack
}
fSubPeriodBytesSize = fSubPeriodSize * sizeof(sample_t) + sizeof(int); // The port number in coded on 4 bytes
fNumPackets = fPeriodSize / fSubPeriodSize; // At least one packet
}
int NetFloatAudioBuffer::GetNumPackets(int active_ports)
......@@ -377,7 +379,7 @@ namespace Jack
jack_log("GetNumPackets packet = %d fPeriodSize = %d fSubPeriodSize = %d fSubPeriodBytesSize = %d",
fPeriodSize / fSubPeriodSize, fPeriodSize, fSubPeriodSize, fSubPeriodBytesSize);
*/
return fPeriodSize / fSubPeriodSize; // At least one packet
return fNumPackets;
}
//jack<->buffer
......@@ -679,15 +681,18 @@ namespace Jack
}
if (port_num > 0) {
int sub_period_bytes_size;
// Last packet of the cycle
if (sub_cycle == fNumPackets - 1) {
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(fCompressedBuffer[port_index] + sub_cycle * fSubPeriodBytesSize, fNetBuffer + port_index * fLastSubPeriodBytesSize, fLastSubPeriodBytesSize);
}
sub_period_bytes_size = fLastSubPeriodBytesSize;
} else {
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(fCompressedBuffer[port_index] + sub_cycle * fSubPeriodBytesSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize);
}
sub_period_bytes_size = fSubPeriodBytesSize;
}
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(fCompressedBuffer[port_index] + sub_cycle * fSubPeriodBytesSize, fNetBuffer + port_index * sub_period_bytes_size, sub_period_bytes_size);
}
}
......@@ -696,18 +701,19 @@ namespace Jack
int NetCeltAudioBuffer::RenderToNetwork(int sub_cycle, uint32_t port_num)
{
int sub_period_bytes_size;
// Last packet of the cycle
if (sub_cycle == fNumPackets - 1) {
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(fNetBuffer + port_index * fLastSubPeriodBytesSize, fCompressedBuffer[port_index] + sub_cycle * fSubPeriodBytesSize, fLastSubPeriodBytesSize);
}
return fNPorts * fLastSubPeriodBytesSize;
sub_period_bytes_size = fLastSubPeriodBytesSize;
} else {
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(fNetBuffer + port_index * fSubPeriodBytesSize, fCompressedBuffer[port_index] + sub_cycle * fSubPeriodBytesSize, fSubPeriodBytesSize);
}
return fNPorts * fSubPeriodBytesSize;
sub_period_bytes_size = fSubPeriodBytesSize;
}
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(fNetBuffer + port_index * sub_period_bytes_size, fCompressedBuffer[port_index] + sub_cycle * fSubPeriodBytesSize, sub_period_bytes_size);
}
return fNPorts * sub_period_bytes_size;
}
#endif
......@@ -775,9 +781,9 @@ namespace Jack
fSubPeriodBytesSize = (fCompressedMaxSizeByte + CDO) / fNumPackets;
fLastSubPeriodBytesSize = fSubPeriodBytesSize + (fCompressedMaxSizeByte + CDO) % fNumPackets;
if (fNumPackets == 1) {
fSubPeriodBytesSize = fLastSubPeriodBytesSize;
}
if (fNumPackets == 1) {
fSubPeriodBytesSize = fLastSubPeriodBytesSize;
}
jack_log("NetOpusAudioBuffer fNumPackets = %d fSubPeriodBytesSize = %d, fLastSubPeriodBytesSize = %d", fNumPackets, fSubPeriodBytesSize, fLastSubPeriodBytesSize);
......@@ -785,7 +791,7 @@ namespace Jack
fCycleBytesSize = params->fMtu * fNumPackets;
fLastSubCycle = -1;
return;
return;
}
error:
......@@ -965,7 +971,6 @@ namespace Jack
fCycleBytesSize = params->fMtu * fNumPackets;
fLastSubCycle = -1;
return;
}
NetIntAudioBuffer::~NetIntAudioBuffer()
......@@ -991,19 +996,21 @@ namespace Jack
{
return fNumPackets;
}
int NetIntAudioBuffer::RenderFromJackPorts()
{
// Count active ports
int active_ports = 0;
for (int port_index = 0; port_index < fNPorts; port_index++) {
if (fPortBuffer[port_index]) {
for (uint frame = 0; frame < fPeriodSize; frame++) {
fIntBuffer[port_index][frame] = short(fPortBuffer[port_index][frame] * 32768.f);
}
active_ports++;
}
}
// All ports active
return fNPorts;
return active_ports;
}
void NetIntAudioBuffer::RenderToJackPorts()
......@@ -1029,14 +1036,17 @@ namespace Jack
}
if (port_num > 0) {
int sub_period_bytes_size;
// Last packet
if (sub_cycle == fNumPackets - 1) {
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(fIntBuffer[port_index] + sub_cycle * fSubPeriodSize, fNetBuffer + port_index * fLastSubPeriodBytesSize, fLastSubPeriodBytesSize);
}
sub_period_bytes_size = fLastSubPeriodBytesSize;
} else {
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(fIntBuffer[port_index] + sub_cycle * fSubPeriodSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize);
}
sub_period_bytes_size = fSubPeriodBytesSize;
}
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(fIntBuffer[port_index] + sub_cycle * fSubPeriodSize, fNetBuffer + port_index * sub_period_bytes_size, sub_period_bytes_size);
}
}
......@@ -1045,18 +1055,19 @@ namespace Jack
int NetIntAudioBuffer::RenderToNetwork(int sub_cycle, uint32_t port_num)
{
// Last packet of the cycle
int sub_period_bytes_size;
// Last packet
if (sub_cycle == fNumPackets - 1) {
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(fNetBuffer + port_index * fLastSubPeriodBytesSize, fIntBuffer[port_index] + sub_cycle * fSubPeriodSize, fLastSubPeriodBytesSize);
}
return fNPorts * fLastSubPeriodBytesSize;
sub_period_bytes_size = fLastSubPeriodBytesSize;
} else {
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(fNetBuffer + port_index * fSubPeriodBytesSize, fIntBuffer[port_index] + sub_cycle * fSubPeriodSize, fSubPeriodBytesSize);
}
return fNPorts * fSubPeriodBytesSize;
sub_period_bytes_size = fSubPeriodBytesSize;
}
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(fNetBuffer + port_index * sub_period_bytes_size, fIntBuffer[port_index] + sub_cycle * fSubPeriodSize, sub_period_bytes_size);
}
return fNPorts * sub_period_bytes_size;
}
// SessionParams ************************************************************************************
......
......@@ -43,7 +43,7 @@ using namespace std;
#define NET_PACKET_ERROR -2
#define OPTIMIZED_PROTOCOL
#define OPTIMIZED_PROTOCOL 1
#define HEADER_SIZE (sizeof(packet_header_t))
#define PACKET_AVAILABLE_SIZE(params) ((params)->fMtu - sizeof(packet_header_t))
......@@ -281,6 +281,7 @@ namespace Jack
int fNPorts;
int fLastSubCycle;
int fNumPackets;
char* fNetBuffer;
sample_t** fPortBuffer;
......@@ -373,8 +374,7 @@ namespace Jack
CELTDecoder** fCeltDecoder;
int fCompressedSizeByte;
int fNumPackets;
size_t fLastSubPeriodBytesSize;
unsigned char** fCompressedBuffer;
......@@ -419,8 +419,7 @@ namespace Jack
unsigned short *fCompressedSizesByte;
int fCompressedMaxSizeByte;
int fNumPackets;
size_t fLastSubPeriodBytesSize;
unsigned char** fCompressedBuffer;
......@@ -454,8 +453,7 @@ namespace Jack
private:
int fCompressedSizeByte;
int fNumPackets;
size_t fLastSubPeriodBytesSize;
short** fIntBuffer;
......
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