git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4520 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.9.8
| @@ -427,7 +427,7 @@ int JackEngine::ClientCheck(const char* name, int uuid, char* name_res, int prot | |||
| *status = 0; | |||
| strcpy(name_res, name); | |||
| jack_log("Check protocol client %ld server = %ld", protocol, JACK_PROTOCOL_VERSION); | |||
| jack_log("Check protocol client = %ld server = %ld", protocol, JACK_PROTOCOL_VERSION); | |||
| if (protocol != JACK_PROTOCOL_VERSION) { | |||
| *status |= (JackFailure | JackVersionError); | |||
| @@ -198,8 +198,7 @@ struct JackNetExtMaster : public JackNetMasterInterface { | |||
| fprintf(stderr, "Can't set timeout : %s\n", StrError(NET_ERROR_CODE)); | |||
| } | |||
| //main loop, wait for data, deal with it and wait again | |||
| //utility variables | |||
| // Main loop, wait for data, deal with it and wait again | |||
| int attempt = 0; | |||
| int rx_bytes = 0; | |||
| @@ -548,7 +548,7 @@ namespace Jack | |||
| for (int audio_port_index = 0; audio_port_index < fPlaybackChannels; audio_port_index++) { | |||
| #ifdef OPTIMIZED_PROTOCOL | |||
| // Port is connected on other side... | |||
| if ((intptr_t)fNetAudioPlaybackBuffer->GetBuffer(audio_port_index) == -1) { | |||
| if (fNetAudioPlaybackBuffer->GetConnected(audio_port_index)) { | |||
| fNetAudioPlaybackBuffer->SetBuffer(audio_port_index, GetOutputBuffer(audio_port_index, true)); | |||
| } else { | |||
| fNetAudioPlaybackBuffer->SetBuffer(audio_port_index, NULL); | |||
| @@ -624,10 +624,10 @@ namespace Jack | |||
| strcpy(value.str, "'hostname'"); | |||
| jack_driver_descriptor_add_parameter(desc, &filler, "client_name", 'n', JackDriverParamString, &value, NULL, "Name of the jack client", NULL); | |||
| value.ui = 1U; | |||
| value.ui = 0U; | |||
| jack_driver_descriptor_add_parameter(desc, &filler, "transport_sync", 't', JackDriverParamUInt, &value, NULL, "Sync transport with master's", NULL); | |||
| value.ui = 2U; | |||
| value.ui = 5U; | |||
| jack_driver_descriptor_add_parameter(desc, &filler, "latency", 'l', JackDriverParamUInt, &value, NULL, "Network latency", NULL); | |||
| return desc; | |||
| @@ -649,7 +649,7 @@ namespace Jack | |||
| int midi_output_ports = 0; | |||
| int celt_encoding = -1; | |||
| bool monitor = false; | |||
| int network_latency = 2; | |||
| int network_latency = 5; | |||
| const JSList* node; | |||
| const jack_driver_param_t* param; | |||
| @@ -293,7 +293,8 @@ namespace Jack | |||
| bool JackNetMasterInterface::SetParams() | |||
| { | |||
| jack_log("JackNetMasterInterface::SetParams audio in = %d audio out = %d MIDI in = %d MIDI out = %d", | |||
| fParams.fSendAudioChannels, fParams.fReturnAudioChannels, fParams.fSendMidiChannels, fParams.fReturnMidiChannels); | |||
| fParams.fSendAudioChannels, fParams.fReturnAudioChannels, | |||
| fParams.fSendMidiChannels, fParams.fReturnMidiChannels); | |||
| JackNetInterface::SetParams(); | |||
| @@ -303,11 +304,13 @@ namespace Jack | |||
| fMaxCycleOffset = fParams.fNetworkLatency; | |||
| // midi net buffers | |||
| if (fParams.fSendMidiChannels > 0) | |||
| if (fParams.fSendMidiChannels > 0) { | |||
| fNetMidiCaptureBuffer = new NetMidiBuffer(&fParams, fParams.fSendMidiChannels, fTxData); | |||
| } | |||
| if (fParams.fReturnMidiChannels > 0) | |||
| if (fParams.fReturnMidiChannels > 0) { | |||
| fNetMidiPlaybackBuffer = new NetMidiBuffer(&fParams, fParams.fReturnMidiChannels, fRxData); | |||
| } | |||
| try { | |||
| @@ -790,11 +793,13 @@ namespace Jack | |||
| fRxHeader.fDataStream = 's'; | |||
| // midi net buffers | |||
| if (fParams.fSendMidiChannels > 0) | |||
| if (fParams.fSendMidiChannels > 0) { | |||
| fNetMidiCaptureBuffer = new NetMidiBuffer(&fParams, fParams.fSendMidiChannels, fRxData); | |||
| } | |||
| if (fParams.fReturnMidiChannels > 0) | |||
| if (fParams.fReturnMidiChannels > 0) { | |||
| fNetMidiPlaybackBuffer = new NetMidiBuffer(&fParams, fParams.fReturnMidiChannels, fTxData); | |||
| } | |||
| try { | |||
| @@ -1033,7 +1038,7 @@ namespace Jack | |||
| if (fParams.fTransportSync) { | |||
| // copy received transport data to transport data structure | |||
| memcpy(&fSendTransportData, fRxData, sizeof(net_transport_data_t)); | |||
| TransportDataNToH(&fSendTransportData, &fSendTransportData); | |||
| TransportDataNToH(&fSendTransportData, &fSendTransportData); | |||
| DecodeTransportData(); | |||
| } | |||
| // then others | |||
| @@ -412,8 +412,7 @@ namespace Jack | |||
| for (int audio_port_index = 0; audio_port_index < fParams.fSendAudioChannels; audio_port_index++) { | |||
| #ifdef OPTIMIZED_PROTOCOL | |||
| if ((intptr_t)fNetAudioCaptureBuffer->GetBuffer(audio_port_index) == -1) { | |||
| //jack_info("Process fNetAudioCaptureBuffer %d", jack_port_connected(fAudioCapturePorts[audio_port_index])); | |||
| if (fNetAudioCaptureBuffer->GetConnected(audio_port_index)) { | |||
| // Port is connected on other side... | |||
| fNetAudioCaptureBuffer->SetBuffer(audio_port_index, | |||
| ((jack_port_connected(fAudioCapturePorts[audio_port_index]) > 0) | |||
| @@ -208,13 +208,16 @@ namespace Jack | |||
| fNetBuffer = net_buffer; | |||
| fPortBuffer = new sample_t* [fNPorts]; | |||
| fConnectedPorts = new bool[fNPorts]; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| fPortBuffer[port_index] = (sample_t*)-1; | |||
| fPortBuffer[port_index] = NULL; | |||
| fConnectedPorts[port_index] = true; | |||
| } | |||
| } | |||
| NetAudioBuffer::~NetAudioBuffer() | |||
| { | |||
| delete [] fConnectedPorts; | |||
| delete [] fPortBuffer; | |||
| } | |||
| @@ -262,36 +265,37 @@ namespace Jack | |||
| int NetAudioBuffer::ActivePortsToNetwork(char* net_buffer) | |||
| { | |||
| int active_port = 0; | |||
| short* active_port_address = (short*)net_buffer; | |||
| int active_ports = 0; | |||
| int* active_port_address = (int*)net_buffer; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| // Write the active port number | |||
| if (fPortBuffer[port_index]) { | |||
| *active_port_address = port_index; | |||
| active_port_address++; | |||
| active_port++; | |||
| active_ports++; | |||
| assert(active_ports < 256); | |||
| } | |||
| } | |||
| assert(active_port < 512); | |||
| return active_port; | |||
| return active_ports; | |||
| } | |||
| void NetAudioBuffer::ActivePortsFromNetwork(char* net_buffer, uint32_t port_num) | |||
| { | |||
| short* active_port_address = (short*)net_buffer; | |||
| int* active_port_address = (int*)net_buffer; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| fPortBuffer[port_index] = NULL; | |||
| fConnectedPorts[port_index] = false; | |||
| } | |||
| for (uint port_index = 0; port_index < port_num; port_index++) { | |||
| // Use -1 when port is actually connected on other side | |||
| if (*active_port_address >= 0 && *active_port_address < fNPorts) { | |||
| fPortBuffer[*active_port_address] = (sample_t*)-1; | |||
| int active_port = *active_port_address; | |||
| if (active_port >= 0 && active_port < fNPorts) { | |||
| fConnectedPorts[active_port] = true; | |||
| } else { | |||
| jack_error("ActivePortsFromNetwork: incorrect port = %d", *active_port_address); | |||
| jack_error("ActivePortsFromNetwork: incorrect port = %d", active_port); | |||
| } | |||
| active_port_address++; | |||
| } | |||
| @@ -302,6 +306,7 @@ namespace Jack | |||
| // Count active ports | |||
| int active_ports = 0; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| if (fPortBuffer[port_index]) { | |||
| active_ports++; | |||
| } | |||
| @@ -358,7 +363,7 @@ namespace Jack | |||
| fSubPeriodSize = (period > fPeriodSize) ? fPeriodSize : period; | |||
| } | |||
| fSubPeriodBytesSize = fSubPeriodSize * sizeof(sample_t) + sizeof(uint32_t); // The port number in coded on 4 bytes | |||
| fSubPeriodBytesSize = fSubPeriodSize * sizeof(sample_t) + sizeof(int); // The port number in coded on 4 bytes | |||
| } | |||
| int NetFloatAudioBuffer::GetNumPackets(int active_ports) | |||
| @@ -423,12 +428,14 @@ namespace Jack | |||
| for (uint32_t port_index = 0; port_index < port_num; port_index++) { | |||
| // Only copy to active ports : read the active port number then audio data | |||
| uint32_t* active_port_address = (uint32_t*)(fNetBuffer + port_index * fSubPeriodBytesSize); | |||
| uint32_t active_port = (uint32_t)(*active_port_address); | |||
| int* active_port_address = (int*)(fNetBuffer + port_index * fSubPeriodBytesSize); | |||
| int active_port = *active_port_address; | |||
| /* | |||
| if (fPortBuffer[active_port]) { | |||
| memcpy(fPortBuffer[active_port] + sub_cycle * fSubPeriodSize, (char*)(active_port_address + 1), fSubPeriodBytesSize - sizeof(uint32_t)); | |||
| //RenderFromNetwork((char*)(active_port_address + 1), active_port, sub_cycle, sub_period_bytes_size - sizeof(uint32_t)); | |||
| } | |||
| */ | |||
| RenderFromNetwork((char*)(active_port_address + 1), active_port, sub_cycle); | |||
| } | |||
| } | |||
| @@ -438,30 +445,32 @@ namespace Jack | |||
| int NetFloatAudioBuffer::RenderToNetwork(int sub_cycle, uint32_t port_num) | |||
| { | |||
| int active_port = 0; | |||
| int active_ports = 0; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| // Only copy from active ports : write the active port number then audio data | |||
| if (fPortBuffer[port_index]) { | |||
| uint32_t* active_port_address = (uint32_t*)(fNetBuffer + active_port * fSubPeriodBytesSize); | |||
| int* active_port_address = (int*)(fNetBuffer + active_ports * fSubPeriodBytesSize); | |||
| *active_port_address = port_index; | |||
| memcpy((char*)(active_port_address + 1), fPortBuffer[port_index] + sub_cycle * fSubPeriodSize, fSubPeriodBytesSize - sizeof(uint32_t)); | |||
| //RenderToNetwork((char*)(active_port_address + 1), port_index, sub_cycle, fSubPeriodBytesSize - sizeof(uint32_t)); | |||
| active_port++; | |||
| //memcpy((char*)(active_port_address + 1), fPortBuffer[port_index] + sub_cycle * fSubPeriodSize, fSubPeriodBytesSize - sizeof(uint32_t)); | |||
| RenderToNetwork((char*)(active_port_address + 1), port_index, sub_cycle); | |||
| active_ports++; | |||
| } | |||
| } | |||
| return port_num * fSubPeriodBytesSize; | |||
| } | |||
| void NetFloatAudioBuffer::RenderFromNetwork(char* net_buffer, int active_port, int sub_cycle, size_t copy_size) | |||
| void NetFloatAudioBuffer::RenderFromNetwork(char* net_buffer, int active_port, int sub_cycle) | |||
| { | |||
| memcpy(fPortBuffer[active_port] + sub_cycle * fSubPeriodSize, net_buffer, copy_size); | |||
| if (fPortBuffer[active_port]) { | |||
| memcpy(fPortBuffer[active_port] + sub_cycle * fSubPeriodSize, net_buffer, fSubPeriodBytesSize - sizeof(int)); | |||
| } | |||
| } | |||
| void NetFloatAudioBuffer::RenderToNetwork(char* net_buffer, int active_port, int sub_cycle, size_t copy_size) | |||
| void NetFloatAudioBuffer::RenderToNetwork(char* net_buffer, int active_port, int sub_cycle) | |||
| { | |||
| memcpy(net_buffer, fPortBuffer[active_port] + sub_cycle * fSubPeriodSize, copy_size); | |||
| memcpy(net_buffer, fPortBuffer[active_port] + sub_cycle * fSubPeriodSize, fSubPeriodBytesSize - sizeof(int)); | |||
| } | |||
| // Celt audio buffer ********************************************************************************* | |||
| @@ -39,8 +39,8 @@ using namespace std; | |||
| #endif | |||
| #endif | |||
| #define MASTER_PROTOCOL 4 | |||
| #define SLAVE_PROTOCOL 4 | |||
| #define MASTER_PROTOCOL 5 | |||
| #define SLAVE_PROTOCOL 5 | |||
| #define NET_PACKET_ERROR -2 | |||
| @@ -281,6 +281,7 @@ namespace Jack | |||
| char* fNetBuffer; | |||
| sample_t** fPortBuffer; | |||
| bool* fConnectedPorts; | |||
| jack_nframes_t fPeriodSize; | |||
| jack_nframes_t fSubPeriodSize; | |||
| @@ -298,6 +299,9 @@ namespace Jack | |||
| NetAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer); | |||
| virtual ~NetAudioBuffer(); | |||
| bool GetConnected(int port_index) { return fConnectedPorts[port_index]; } | |||
| void SetConnected(int port_index, bool state) { fConnectedPorts[port_index] = state; } | |||
| // needed syze in bytes ofr an entire cycle | |||
| virtual size_t GetCycleSize() = 0; | |||
| @@ -350,8 +354,8 @@ namespace Jack | |||
| int RenderFromNetwork(int cycle, int sub_cycle, uint32_t port_num); | |||
| int RenderToNetwork(int sub_cycle, uint32_t port_num); | |||
| void RenderFromNetwork(char* net_buffer, int active_port, int sub_cycle, size_t copy_size); | |||
| void RenderToNetwork(char* net_buffer, int active_port, int sub_cycle, size_t copy_size); | |||
| void RenderFromNetwork(char* net_buffer, int active_port, int sub_cycle); | |||
| void RenderToNetwork(char* net_buffer, int active_port, int sub_cycle); | |||
| }; | |||