Commit ffe8e3cf authored by sletz's avatar sletz
Browse files

Improve libjacknet master mode.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4777 0c269be4-1314-0410-8aa9-9f06e86f4224
parent ec40ef29
......@@ -36,6 +36,10 @@ John Emmas
Jackdmp changes log
---------------------------
2012-02-10 Stephane Letz <letz@grame.fr>
* Improve libjacknet master mode.
2012-02-09 Stephane Letz <letz@grame.fr>
* In control API, UNIX like sigset_t replaced by more abstract jackctl_sigmask_t * opaque struct.
......
......@@ -157,6 +157,8 @@ struct JackNetExtMaster : public JackNetMasterInterface {
fSocket.SetPort(port);
fRequest.buffer_size = request->buffer_size;
fRequest.sample_rate = request->sample_rate;
fRequest.audio_input = request->audio_input;
fRequest.audio_output = request->audio_output;
fAudioCaptureBuffer = NULL;
fAudioPlaybackBuffer = NULL;
fMidiCaptureBuffer = NULL;
......@@ -224,7 +226,7 @@ struct JackNetExtMaster : public JackNetMasterInterface {
switch (GetPacketType(&fParams)) {
case SLAVE_AVAILABLE:
if (MasterInit() == 0) {
if (InitMaster(result) == 0) {
SessionParamsDisplay(&fParams);
fRunning = false;
} else {
......@@ -243,7 +245,7 @@ struct JackNetExtMaster : public JackNetMasterInterface {
}
}
while (fRunning);
// Set result parameters
result->audio_input = fParams.fSendAudioChannels;
result->audio_output = fParams.fReturnAudioChannels;
......@@ -258,7 +260,7 @@ struct JackNetExtMaster : public JackNetMasterInterface {
return -1;
}
int MasterInit()
int InitMaster(jack_slave_t* result)
{
// Check MASTER <==> SLAVE network protocol coherency
if (fParams.fProtocolVersion != MASTER_PROTOCOL) {
......@@ -269,14 +271,45 @@ struct JackNetExtMaster : public JackNetMasterInterface {
// Settings
fSocket.GetName(fParams.fMasterNetName);
fParams.fID = 1;
fParams.fSampleEncoder = JackFloatEncoder;
fParams.fPeriodSize = fRequest.buffer_size;
fParams.fSampleRate = fRequest.sample_rate;
if (fRequest.audio_input == -1) {
if (fParams.fSendAudioChannels == -1) {
jack_error("Error : master and slave use -1 for wanted inputs...");
return -1;
} else {
result->audio_input = fParams.fSendAudioChannels;
jack_info("Takes slave %d inputs", fParams.fSendAudioChannels);
}
} else if (fParams.fSendAudioChannels == -1) {
fParams.fSendAudioChannels = fRequest.audio_input;
jack_info("Takes master %d inputs", fRequest.audio_input);
} else if (fParams.fSendAudioChannels != fRequest.audio_input) {
jack_error("Error : master wants %d inputs and slave wants %d inputs...", fRequest.audio_input, fParams.fSendAudioChannels);
return -1;
}
if (fRequest.audio_output == -1) {
if (fParams.fReturnAudioChannels == -1) {
jack_error("Error : master and slave use -1 for wanted outputs...");
return -1;
} else {
result->audio_output = fParams.fReturnAudioChannels;
jack_info("Takes slave %d outputs", fParams.fReturnAudioChannels);
}
} else if (fParams.fReturnAudioChannels == -1) {
fParams.fReturnAudioChannels = fRequest.audio_output;
jack_info("Takes master %d outputs", fRequest.audio_output);
} else if (fParams.fReturnAudioChannels != fRequest.audio_output) {
jack_error("Error : master wants %d outputs and slave wants %d outputs...", fRequest.audio_output, fParams.fReturnAudioChannels);
return -1;
}
// Close request socket
fSocket.Close();
// Network slave init
/// Network init
if (!JackNetMasterInterface::Init()) {
return -1;
}
......@@ -366,7 +399,9 @@ struct JackNetExtMaster : public JackNetMasterInterface {
int Read(int audio_input, float** audio_input_buffer, int midi_input, void** midi_input_buffer)
{
try {
assert(audio_input == fParams.fReturnAudioChannels);
for (int audio_port_index = 0; audio_port_index < audio_input; audio_port_index++) {
......@@ -376,11 +411,13 @@ struct JackNetExtMaster : public JackNetMasterInterface {
for (int midi_port_index = 0; midi_port_index < midi_input; midi_port_index++) {
fNetMidiPlaybackBuffer->SetBuffer(midi_port_index, ((JackMidiBuffer**)midi_input_buffer)[midi_port_index]);
}
if (SyncRecv() == SOCKET_ERROR) {
return 0;
//receive sync
int res = SyncRecv();
if ((res == 0) || (res == SOCKET_ERROR)) {
return res;
}
DecodeSyncPacket();
return DataRecv();
......@@ -393,6 +430,7 @@ struct JackNetExtMaster : public JackNetMasterInterface {
int Write(int audio_output, float** audio_output_buffer, int midi_output, void** midi_output_buffer)
{
try {
assert(audio_output == fParams.fSendAudioChannels);
for (int audio_port_index = 0; audio_port_index < audio_output; audio_port_index++) {
......@@ -402,20 +440,32 @@ struct JackNetExtMaster : public JackNetMasterInterface {
for (int midi_port_index = 0; midi_port_index < midi_output; midi_port_index++) {
fNetMidiCaptureBuffer->SetBuffer(midi_port_index, ((JackMidiBuffer**)midi_output_buffer)[midi_port_index]);
}
if (IsSynched()) { // only send if connection is "synched"
EncodeSyncPacket();
if (SyncSend() == SOCKET_ERROR) {
return SOCKET_ERROR;
}
EncodeSyncPacket();
if (SyncSend() == SOCKET_ERROR) {
return SOCKET_ERROR;
//send data
if (DataSend() == SOCKET_ERROR) {
return SOCKET_ERROR;
}
} else {
jack_info("Connection is not synched, skip cycle...");
}
return DataSend();
return 0;
} catch (JackNetException& e) {
jack_error("Connection lost.");
return -1;
}
}
}
// Transport
void EncodeTransportData()
......
......@@ -262,7 +262,7 @@ namespace Jack
bool JackNetMasterInterface::Init()
{
jack_log("JackNetMasterInterface::Init, ID %u", fParams.fID);
jack_log("JackNetMasterInterface::Init : ID %u", fParams.fID);
session_params_t host_params;
uint attempt = 0;
......@@ -504,7 +504,7 @@ namespace Jack
while (!fRxHeader.fIsLastPckt) {
// how much data is queued on the rx buffer ?
rx_bytes = Recv(fParams.fMtu, MSG_PEEK);
// error here, problem with recv, just skip the cycle (return -1)
if (rx_bytes == SOCKET_ERROR) {
return rx_bytes;
......@@ -528,7 +528,7 @@ namespace Jack
}
}
}
return rx_bytes;
}
......
......@@ -491,7 +491,7 @@ namespace Jack
#endif
} else {
jack_error("Connection is not synched, skip cycle...");
jack_info("Connection is not synched, skip cycle...");
}
//receive sync
......
......@@ -44,10 +44,10 @@ enum JackNetEncoder {
typedef struct {
int audio_input; // from master or to slave (-1 for get master audio physical outputs)
int audio_output; // to master or from slave (-1 for get master audio physical inputs)
int midi_input; // from master or to slave (-1 for get master MIDI physical outputs)
int midi_output; // to master or from slave (-1 for get master MIDI physical inputs)
int audio_input; // from master or to slave (-1 to take master audio physical inputs)
int audio_output; // to master or from slave (-1 to take master audio physical outputs)
int midi_input; // from master or to slave (-1 to take master MIDI physical inputs)
int midi_output; // to master or from slave (-1 to take master MIDI physical outputs)
int mtu; // network Maximum Transmission Unit
int time_out; // in second, -1 means in infinite
int encoder; // encoder type (one of JackNetEncoder)
......@@ -58,10 +58,10 @@ typedef struct {
typedef struct {
int audio_input; // master audio physical outputs
int audio_output; // master audio physical inputs
int midi_input; // master MIDI physical outputs
int midi_output; // master MIDI physical inputs
int audio_input; // master audio physical outputs (-1 to take slave wanted audio inputs)
int audio_output; // master audio physical inputs (-1 to take slave wanted audio outputs)
int midi_input; // master MIDI physical outputs (-1 to take slave wanted MIDI inputs)
int midi_output; // master MIDI physical inputs (-1 to take slave wanted MIDI outputs)
jack_nframes_t buffer_size; // mater buffer size
jack_nframes_t sample_rate; // mater sample rate
char master_name[MASTER_NAME_SIZE]; // master machine name
......
......@@ -26,6 +26,7 @@
#include <signal.h>
#include <getopt.h>
#include <string.h>
#include <assert.h>
#include <jack/net.h>
......@@ -99,7 +100,8 @@ main (int argc, char *argv[])
}
int i;
jack_master_t request = { -1, -1, -1, -1, buffer_size, sample_rate, "master" };
jack_master_t request = { 4, 4, -1, -1, buffer_size, sample_rate, "master" };
//jack_master_t request = { -1, -1, -1, -1, buffer_size, sample_rate, "master" };
jack_slave_t result;
float** audio_input_buffer;
float** audio_output_buffer;
......@@ -127,6 +129,7 @@ main (int argc, char *argv[])
#endif
// Allocate buffers
audio_input_buffer = (float**)calloc(result.audio_input, sizeof(float*));
for (i = 0; i < result.audio_input; i++) {
audio_input_buffer[i] = (float*)calloc(buffer_size, sizeof(float));
......@@ -147,6 +150,7 @@ main (int argc, char *argv[])
while (1) {
// Copy input to output
assert(result.audio_input == result.audio_output);
for (i = 0; i < result.audio_input; i++) {
memcpy(audio_output_buffer[i], audio_input_buffer[i], buffer_size * sizeof(float));
}
......
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