Commit 90797017 authored by Stephane Letz's avatar Stephane Letz
Browse files

Improve partial cycle support in NetJack2.

parent 26bc2bcb
......@@ -177,7 +177,7 @@ namespace Jack
// audio
if (audio_channels > 0) {
fTxHeader.fDataType = 'a';
fTxHeader.fActivePorts = buffer->RenderFromJackPorts();
fTxHeader.fActivePorts = buffer->RenderFromJackPorts(fTxHeader.fFrames);
fTxHeader.fNumPacket = buffer->GetNumPackets(fTxHeader.fActivePorts);
for (uint subproc = 0; subproc < fTxHeader.fNumPacket; subproc++) {
......@@ -215,18 +215,19 @@ namespace Jack
fRxHeader.fSubCycle = rx_head->fSubCycle;
fRxHeader.fIsLastPckt = rx_head->fIsLastPckt;
fRxHeader.fActivePorts = rx_head->fActivePorts;
fRxHeader.fFrames = rx_head->fFrames;
rx_bytes = buffer->RenderFromNetwork(rx_head->fCycle, rx_head->fSubCycle, fRxHeader.fActivePorts);
// Last audio packet is received, so finish rendering...
if (fRxHeader.fIsLastPckt) {
buffer->RenderToJackPorts();
buffer->RenderToJackPorts(fRxHeader.fFrames);
}
return rx_bytes;
}
int JackNetInterface::FinishRecv(NetAudioBuffer* buffer)
{
buffer->RenderToJackPorts();
buffer->RenderToJackPorts(fRxHeader.fFrames);
return DATA_PACKET_ERROR;
}
......@@ -591,7 +592,6 @@ namespace Jack
if (fNetAudioCaptureBuffer) {
fNetAudioCaptureBuffer->ActivePortsFromNetwork(fRxData, rx_head->fActivePorts);
}
frames = rx_head->fFrames;
}
......
......@@ -306,7 +306,7 @@ namespace Jack
}
}
int NetAudioBuffer::RenderFromJackPorts()
int NetAudioBuffer::RenderFromJackPorts(int unused_frames)
{
// Count active ports
int active_ports = 0;
......@@ -319,7 +319,7 @@ namespace Jack
return active_ports;
}
void NetAudioBuffer::RenderToJackPorts()
void NetAudioBuffer::RenderToJackPorts(int unused_frames)
{
// Nothing to do
NextCycle();
......@@ -629,7 +629,7 @@ namespace Jack
return fNumPackets;
}
int NetCeltAudioBuffer::RenderFromJackPorts()
int NetCeltAudioBuffer::RenderFromJackPorts(int nframes)
{
float buffer[BUFFER_SIZE_MAX];
......@@ -640,7 +640,8 @@ namespace Jack
memset(buffer, 0, fPeriodSize * sizeof(sample_t));
}
#if HAVE_CELT_API_0_8 || HAVE_CELT_API_0_11
int res = celt_encode_float(fCeltEncoder[port_index], buffer, fPeriodSize, fCompressedBuffer[port_index], fCompressedSizeByte);
//int res = celt_encode_float(fCeltEncoder[port_index], buffer, fPeriodSize, fCompressedBuffer[port_index], fCompressedSizeByte);
int res = celt_encode_float(fCeltEncoder[port_index], buffer, frames, fCompressedBuffer[port_index], fCompressedSizeByte);
#else
int res = celt_encode_float(fCeltEncoder[port_index], buffer, NULL, fCompressedBuffer[port_index], fCompressedSizeByte);
#endif
......@@ -653,12 +654,13 @@ namespace Jack
return fNPorts;
}
void NetCeltAudioBuffer::RenderToJackPorts()
void NetCeltAudioBuffer::RenderToJackPorts(int nframes)
{
for (int port_index = 0; port_index < fNPorts; port_index++) {
if (fPortBuffer[port_index]) {
#if HAVE_CELT_API_0_8 || HAVE_CELT_API_0_11
int res = celt_decode_float(fCeltDecoder[port_index], fCompressedBuffer[port_index], fCompressedSizeByte, fPortBuffer[port_index], fPeriodSize);
//int res = celt_decode_float(fCeltDecoder[port_index], fCompressedBuffer[port_index], fCompressedSizeByte, fPortBuffer[port_index], fPeriodSize);
int res = celt_decode_float(fCeltDecoder[port_index], fCompressedBuffer[port_index], fCompressedSizeByte, fPortBuffer[port_index], frames);
#else
int res = celt_decode_float(fCeltDecoder[port_index], fCompressedBuffer[port_index], fCompressedSizeByte, fPortBuffer[port_index]);
#endif
......@@ -717,9 +719,9 @@ namespace Jack
#endif
#if HAVE_OPUS
#define CDO (sizeof(short)) ///< compressed data offset (first 2 bytes are length)
NetOpusAudioBuffer::NetOpusAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer, int kbps)
:NetAudioBuffer(params, nports, net_buffer)
{
......@@ -847,17 +849,19 @@ namespace Jack
return fNumPackets;
}
int NetOpusAudioBuffer::RenderFromJackPorts()
int NetOpusAudioBuffer::RenderFromJackPorts(int nframes)
{
float buffer[BUFFER_SIZE_MAX];
printf("NetOpusAudioBuffer::RenderFromJackPorts %d\n", nframes);
for (int port_index = 0; port_index < fNPorts; port_index++) {
if (fPortBuffer[port_index]) {
memcpy(buffer, fPortBuffer[port_index], fPeriodSize * sizeof(sample_t));
} else {
memset(buffer, 0, fPeriodSize * sizeof(sample_t));
}
int res = opus_custom_encode_float(fOpusEncoder[port_index], buffer, fPeriodSize, fCompressedBuffer[port_index], fCompressedMaxSizeByte);
int res = opus_custom_encode_float(fOpusEncoder[port_index], buffer, ((nframes == -1) ? fPeriodSize : nframes), fCompressedBuffer[port_index], fCompressedMaxSizeByte);
if (res < 0 || res >= 65535) {
fCompressedSizesByte[port_index] = 0;
} else {
......@@ -869,12 +873,14 @@ namespace Jack
return fNPorts;
}
void NetOpusAudioBuffer::RenderToJackPorts()
void NetOpusAudioBuffer::RenderToJackPorts(int nframes)
{
printf("NetOpusAudioBuffer::RenderToJackPorts %d\n", nframes);
for (int port_index = 0; port_index < fNPorts; port_index++) {
if (fPortBuffer[port_index]) {
int res = opus_custom_decode_float(fOpusDecoder[port_index], fCompressedBuffer[port_index], fCompressedSizesByte[port_index], fPortBuffer[port_index], fPeriodSize);
if (res < 0 || res != fPeriodSize) {
int res = opus_custom_decode_float(fOpusDecoder[port_index], fCompressedBuffer[port_index], fCompressedSizesByte[port_index], fPortBuffer[port_index], ((nframes == -1) ? fPeriodSize : nframes));
if (res < 0 || res != ((nframes == -1) ? fPeriodSize : nframes)) {
jack_error("opus_decode_float error fCompressedSizeByte = %d res = %d", fCompressedSizesByte[port_index], res);
}
}
......@@ -994,11 +1000,11 @@ namespace Jack
return fNumPackets;
}
int NetIntAudioBuffer::RenderFromJackPorts()
int NetIntAudioBuffer::RenderFromJackPorts(int nframes)
{
for (int port_index = 0; port_index < fNPorts; port_index++) {
if (fPortBuffer[port_index]) {
for (uint frame = 0; frame < fPeriodSize; frame++) {
for (int frame = 0; frame < nframes; frame++) {
fIntBuffer[port_index][frame] = short(fPortBuffer[port_index][frame] * 32767.f);
}
} else {
......@@ -1010,12 +1016,12 @@ namespace Jack
return fNPorts;
}
void NetIntAudioBuffer::RenderToJackPorts()
void NetIntAudioBuffer::RenderToJackPorts(int nframes)
{
float coef = 1.f / 32767.f;
for (int port_index = 0; port_index < fNPorts; port_index++) {
if (fPortBuffer[port_index]) {
for (uint frame = 0; frame < fPeriodSize; frame++) {
for (int frame = 0; frame < nframes; frame++) {
fPortBuffer[port_index][frame] = float(fIntBuffer[port_index][frame] * coef);
}
}
......
......@@ -320,8 +320,8 @@ namespace Jack
virtual sample_t* GetBuffer(int index);
//jack<->buffer
virtual int RenderFromJackPorts();
virtual void RenderToJackPorts();
virtual int RenderFromJackPorts(int nframes);
virtual void RenderToJackPorts(int nframes);
//network<->buffer
virtual int RenderFromNetwork(int cycle, int sub_cycle, uint32_t port_num) = 0;
......@@ -396,12 +396,12 @@ namespace Jack
int GetNumPackets(int active_ports);
//jack<->buffer
int RenderFromJackPorts();
void RenderToJackPorts();
int RenderFromJackPorts(int nframes);
void RenderToJackPorts(int nframes);
//network<->buffer
int RenderFromNetwork(int cycle, int sub_cycle, uint32_t port_num);
int RenderToNetwork(int sub_cycle, uint32_t port_num);
int RenderToNetwork(int sub_cycle, uint32_t port_num);
};
#endif
......@@ -440,8 +440,8 @@ namespace Jack
int GetNumPackets(int active_ports);
//jack<->buffer
int RenderFromJackPorts();
void RenderToJackPorts();
int RenderFromJackPorts(int nframes);
void RenderToJackPorts(int nframes);
//network<->buffer
int RenderFromNetwork(int cycle, int sub_cycle, uint32_t port_num);
......@@ -473,8 +473,8 @@ namespace Jack
int GetNumPackets(int active_ports);
//jack<->buffer
int RenderFromJackPorts();
void RenderToJackPorts();
int RenderFromJackPorts(int nframes);
void RenderToJackPorts(int nframes);
//network<->buffer
int RenderFromNetwork(int cycle, int sub_cycle, uint32_t port_num);
......
......@@ -9948,8 +9948,7 @@
"-DUSE_POSIX_SHM",
);
OTHER_CPLUSPLUSFLAGS = (
"-DHAVE_CELT_API_0_7",
"-DHAVE_CELT",
"-DHAVE_OPUS",
"-DSERVER_SIDE",
"-D__SMP__",
"-DMACH_RPC_MACH_SEMA",
......@@ -9959,7 +9958,7 @@
OTHER_CPLUSPLUSFLAGS_QUOTED_FOR_TARGET_1 = "-DADDON_DIR=\\\"/usr/local/lib/jackmp\\\"";
OTHER_CPLUSPLUSFLAGS_QUOTED_FOR_TARGET_2 = "-DLIB_DIR=\\\"lib\\\"";
OTHER_LDFLAGS = (
libcelt.a,
/usr/local/lib/libopus.a,
"-framework",
Carbon,
"-framework",
......@@ -16450,15 +16449,14 @@
"-D__SMP__",
);
OTHER_CPLUSPLUSFLAGS = (
"-DHAVE_CELT_API_0_7",
"-DHAVE_CELT",
"-DHAVE_OPUS",
"-DMACH_RPC_MACH_SEMA",
"-D__SMP__",
);
OTHER_CPLUSPLUSFLAGS_QUOTED_FOR_TARGET_1 = "-DADDON_DIR=\\\"/usr/local/lib/jackmp\\\"";
OTHER_CPLUSPLUSFLAGS_QUOTED_FOR_TARGET_2 = "-DJACK_LOCATION=\\\"/usr/local/bin\\\"";
OTHER_LDFLAGS = (
libcelt.a,
/usr/local/lib/libopus.a,
/opt/local/lib/libsamplerate.a,
"-framework",
CoreAudio,
......@@ -17686,8 +17684,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.4;
OTHER_CFLAGS = "";
OTHER_CPLUSPLUSFLAGS = (
"-DHAVE_CELT_API_0_7",
"-DHAVE_CELT",
"-DHAVE_OPUS",
"-DSERVER_SIDE",
"-DMACH_RPC_MACH_SEMA",
);
......
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