Commit 3085ae19 authored by Robin Gareus's avatar Robin Gareus
Browse files

netjack1/2 Opus: use only 2bytes for encoded-length

parent d94f5edb
......@@ -776,6 +776,7 @@ JackNetOneDriver::render_jack_ports_to_payload_celt (JSList *playback_ports, JSL
#endif
#if HAVE_OPUS
#define CDO (sizeof(short)) ///< compressed data offset (first 2 bytes are length)
// render functions for Opus.
void
JackNetOneDriver::render_payload_to_jack_ports_opus (void *packet_payload, jack_nframes_t net_period_down, JSList *capture_ports, JSList *capture_srcs, jack_nframes_t nframes)
......@@ -801,10 +802,9 @@ JackNetOneDriver::render_payload_to_jack_ports_opus (void *packet_payload, jack_
if( !packet_payload )
memset(buf, 0, nframes * sizeof(float));
else {
#define CDO (sizeof(size_t)) ///< compressed data offset (first 4 bytes are length)
size_t len;
memcpy(&len, packet_bufX, sizeof(size_t));
len = ntohl(len);
unsigned short len;
memcpy(&len, packet_bufX, CDO);
len = ntohs(len);
opus_custom_decode_float( decoder, packet_bufX + CDO, len, buf, nframes );
}
......@@ -849,8 +849,8 @@ JackNetOneDriver::render_jack_ports_to_payload_opus (JSList *playback_ports, JSL
memcpy(floatbuf, buf, nframes * sizeof(jack_default_audio_sample_t));
OpusCustomEncoder *encoder = (OpusCustomEncoder*) src_node->data;
encoded_bytes = opus_custom_encode_float( encoder, floatbuf, nframes, packet_bufX + CDO, net_period_up - CDO );
size_t len = htonl(encoded_bytes);
memcpy(packet_bufX, &len, sizeof(size_t));
unsigned short len = htons(encoded_bytes);
memcpy(packet_bufX, &len, CDO);
src_node = jack_slist_next( src_node );
} else if (strncmp(portname, JACK_DEFAULT_MIDI_TYPE, jack_port_type_size()) == 0) {
// encode midi events from port to packet
......
......@@ -710,7 +710,7 @@ namespace Jack
#endif
#if HAVE_OPUS
#define CDO (sizeof(size_t)) ///< compressed data offset (first 4 bytes are length)
#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)
......@@ -718,7 +718,7 @@ namespace Jack
fOpusMode = new OpusCustomMode *[fNPorts];
fOpusEncoder = new OpusCustomEncoder *[fNPorts];
fOpusDecoder = new OpusCustomDecoder *[fNPorts];
fCompressedSizesByte = new size_t [fNPorts];
fCompressedSizesByte = new unsigned short [fNPorts];
memset(fOpusMode, 0, fNPorts * sizeof(OpusCustomMode*));
memset(fOpusEncoder, 0, fNPorts * sizeof(OpusCustomEncoder*));
......@@ -854,7 +854,12 @@ namespace Jack
} else {
memset(buffer, 0, fPeriodSize * sizeof(sample_t));
}
fCompressedSizesByte[port_index] = opus_custom_encode_float(fOpusEncoder[port_index], buffer, fPeriodSize, fCompressedBuffer[port_index], fCompressedMaxSizeByte);
int res = opus_custom_encode_float(fOpusEncoder[port_index], buffer, fPeriodSize, fCompressedBuffer[port_index], fCompressedMaxSizeByte);
if (res <0 || res >= 65535) {
fCompressedSizesByte[port_index] = 0;
} else {
fCompressedSizesByte[port_index] = res;
}
}
// All ports active
......@@ -866,7 +871,7 @@ namespace Jack
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 != fPeriodSize) {
if (res < 0 || res != fPeriodSize) {
jack_error("opus_decode_float error fCompressedSizeByte = %d res = %d", fCompressedSizesByte[port_index], res);
}
}
......@@ -887,7 +892,7 @@ namespace Jack
if (sub_cycle == 0) {
for (int port_index = 0; port_index < fNPorts; port_index++) {
size_t len = *((size_t*)(fNetBuffer + port_index * fSubPeriodBytesSize));
fCompressedSizesByte[port_index] = ntohl(len);
fCompressedSizesByte[port_index] = ntohs(len);
memcpy(fCompressedBuffer[port_index] + sub_cycle * fSubPeriodBytesSize, fNetBuffer + CDO + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize - CDO);
}
} else if (sub_cycle == fNumPackets - 1) {
......@@ -908,7 +913,7 @@ namespace Jack
{
if (sub_cycle == 0) {
for (int port_index = 0; port_index < fNPorts; port_index++) {
size_t len = htonl(fCompressedSizesByte[port_index]);
unsigned short len = htons(fCompressedSizesByte[port_index]);
memcpy(fNetBuffer + port_index * fSubPeriodBytesSize, &len, CDO);
memcpy(fNetBuffer + port_index * fSubPeriodBytesSize + CDO, fCompressedBuffer[port_index], fSubPeriodBytesSize - CDO);
}
......
......@@ -419,7 +419,7 @@ namespace Jack
OpusCustomEncoder** fOpusEncoder;
OpusCustomDecoder** fOpusDecoder;
size_t *fCompressedSizesByte;
unsigned short *fCompressedSizesByte;
int fCompressedMaxSizeByte;
int fNumPackets;
......
......@@ -1356,6 +1356,7 @@ render_jack_ports_to_payload_celt (JSList *playback_ports, JSList *playback_srcs
#endif
#if HAVE_OPUS
#define CDO (sizeof(short)) ///< compressed data offset (first 2 bytes are length)
// render functions for Opus.
void
render_payload_to_jack_ports_opus (void *packet_payload, jack_nframes_t net_period_down, JSList *capture_ports, JSList *capture_srcs, jack_nframes_t nframes)
......@@ -1378,10 +1379,9 @@ render_payload_to_jack_ports_opus (void *packet_payload, jack_nframes_t net_peri
if( !packet_payload )
memset(buf, 0, nframes * sizeof(float));
else {
#define CDO (sizeof(size_t)) ///< compressed data offset (first 4 bytes are length)
size_t len;
memcpy(&len, packet_bufX, sizeof(size_t));
len = ntohl(len);
unsigned short len;
memcpy(&len, packet_bufX, CDO);
len = ntohs(len);
opus_custom_decode_float( decoder, packet_bufX + CDO, len, buf, nframes );
}
......@@ -1422,8 +1422,8 @@ render_jack_ports_to_payload_opus (JSList *playback_ports, JSList *playback_srcs
memcpy( floatbuf, buf, nframes * sizeof(float) );
OpusCustomEncoder *encoder = (OpusCustomEncoder*) src_node->data;
encoded_bytes = opus_custom_encode_float( encoder, floatbuf, nframes, packet_bufX + CDO, net_period_up - CDO );
size_t len = htonl(encoded_bytes);
memcpy(packet_bufX, &len, sizeof(size_t));
unsigned short len = htons(encoded_bytes);
memcpy(packet_bufX, &len, CDO);
src_node = jack_slist_next( src_node );
} else if (jack_port_is_midi (porttype)) {
// encode midi events from port to packet
......
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