Commit 97c3a441 authored by sletz's avatar sletz
Browse files

Use of latency range in all backends. ComputeTotalLatencies now a client/server call.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4151 0c269be4-1314-0410-8aa9-9f06e86f4224
parent ae993599
......@@ -34,6 +34,11 @@ Valerio Pilo
Jackdmp changes log
---------------------------
2011-03-08 Stephane Letz <letz@grame.fr>
* Use of latency range in all backends.
* ComputeTotalLatencies now a client/server call.
2011-03-04 Stephane Letz <letz@grame.fr>
* Revert r4119 (RT notification in the server). JackAudioDriver::ProcessSync now skip backend write in case of graph process failure.
......
......@@ -580,10 +580,10 @@ EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t*
uintptr_t port_aux = (uintptr_t)port;
jack_port_id_t myport = (jack_port_id_t)port_aux;
if (client == NULL) {
jack_error("jack_recompute_total_latencies called with a NULL client");
jack_error("jack_recompute_total_latency called with a NULL client");
return -1;
} else if (!CheckPort(myport)) {
jack_error("jack_recompute_total_latencies called with a NULL port");
jack_error("jack_recompute_total_latency called with a NULL port");
return -1;
} else {
WaitGraphChange();
......@@ -603,9 +603,7 @@ EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
jack_error("jack_recompute_total_latencies called with a NULL client");
return -1;
} else {
WaitGraphChange();
JackGraphManager* manager = GetGraphManager();
return (manager ? manager->ComputeTotalLatencies() : -1);
return client->ComputeTotalLatencies();
}
}
......
......@@ -101,6 +101,7 @@ int JackAudioDriver::Attach()
jack_port_id_t port_index;
char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
jack_latency_range_t range;
int i;
jack_log("JackAudioDriver::Attach fBufferSize = %ld fSampleRate = %ld", fEngineControl->fBufferSize, fEngineControl->fSampleRate);
......@@ -114,7 +115,8 @@ int JackAudioDriver::Attach()
}
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
port->SetLatency(fEngineControl->fBufferSize + fCaptureLatency);
range.min = range.max = fEngineControl->fBufferSize + fCaptureLatency;
port->SetLatencyRange(JackCaptureLatency, &range);
fCapturePortList[i] = port_index;
jack_log("JackAudioDriver::Attach fCapturePortList[i] port_index = %ld", port_index);
}
......@@ -129,7 +131,8 @@ int JackAudioDriver::Attach()
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
// Add more latency if "async" mode is used...
port->SetLatency(fEngineControl->fBufferSize + ((fEngineControl->fSyncMode) ? 0 : fEngineControl->fBufferSize) + fPlaybackLatency);
range.min = range.max = fEngineControl->fBufferSize + ((fEngineControl->fSyncMode) ? 0 : fEngineControl->fBufferSize) + fPlaybackLatency;
port->SetLatencyRange(JackPlaybackLatency, &range);
fPlaybackPortList[i] = port_index;
jack_log("JackAudioDriver::Attach fPlaybackPortList[i] port_index = %ld", port_index);
......@@ -143,7 +146,8 @@ int JackAudioDriver::Attach()
} else {
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
port->SetLatency(fEngineControl->fBufferSize);
range.min = range.max = fEngineControl->fBufferSize;
port->SetLatencyRange(JackCaptureLatency, &range);
fMonitorPortList[i] = port_index;
}
}
......
......@@ -108,6 +108,9 @@ class JackClientChannelInterface
virtual void SetFreewheel(int onoff, int* result)
{}
virtual void ComputeTotalLatencies(int* result)
{}
virtual void ReleaseTimebase(int refnum, int* result)
{}
......
......@@ -718,6 +718,13 @@ int JackClient::SetFreeWheel(int onoff)
return result;
}
int JackClient::ComputeTotalLatencies()
{
int result = -1;
fChannel->ComputeTotalLatencies(&result);
return result;
}
/*
ShutDown is called:
- from the RT thread when Execute method fails
......
......@@ -141,6 +141,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
// Context
virtual int SetBufferSize(jack_nframes_t buffer_size);
virtual int SetFreeWheel(int onoff);
virtual int ComputeTotalLatencies();
virtual void ShutDown();
virtual jack_native_thread_t GetThreadID();
......
......@@ -209,6 +209,12 @@ void JackEngine::CheckXRun(jack_time_t callback_usecs) // REVOIR les conditions
}
}
int JackEngine::ComputeTotalLatencies()
{
// TODO : jack_compute_new_latency
return 0;
}
//---------------
// Notifications
//---------------
......@@ -295,6 +301,7 @@ void JackEngine::NotifyXRun(int refnum)
void JackEngine::NotifyGraphReorder()
{
ComputeTotalLatencies();
NotifyClients(kGraphOrderCallback, false, "", 0, 0);
}
......
......@@ -129,6 +129,8 @@ class SERVER_EXPORT JackEngine : public JackLockAble
int PortRename(int refnum, jack_port_id_t port, const char* name);
int ComputeTotalLatencies();
// Graph
bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end);
......@@ -142,8 +144,9 @@ class SERVER_EXPORT JackEngine : public JackLockAble
void NotifyFreewheel(bool onoff);
void NotifyQuit();
void SessionNotify( int refnum, const char *target, jack_session_event_type_t type, const char *path, JackChannelTransaction *socket );
void SessionReply( int refnum );
// Session management
void SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, JackChannelTransaction *socket);
void SessionReply(int refnum);
void GetUUIDForClientName(const char *client_name, char *uuid_res, int *result);
void GetClientNameForUUID(const char *uuid, char *name_res, int *result);
......
......@@ -112,6 +112,11 @@ class JackInternalClientChannel : public detail::JackClientChannelInterface
*result = fServer->SetFreewheel(onoff);
}
void ComputeTotalLatencies(int* result)
{
*result = fEngine->ComputeTotalLatencies();
}
void SessionNotify( int refnum, const char *target, jack_session_event_type_t type, const char *path, jack_session_command_t **result )
{
*result = NULL;
......@@ -126,7 +131,7 @@ class JackInternalClientChannel : public detail::JackClientChannelInterface
{
*result = fServer->SetTimebaseCallback(refnum, conditional);
}
void GetInternalClientName(int refnum, int int_ref, char* name_res, int* result)
{
*result = fEngine->GetInternalClientName(int_ref, name_res);
......@@ -139,7 +144,7 @@ class JackInternalClientChannel : public detail::JackClientChannelInterface
void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int uuid, int* result)
{
*result = fServer->InternalClientLoad(client_name, so_name, objet_data, options, int_ref, uuid, status);
*result = fServer->InternalClientLoad(client_name, so_name, objet_data, options, int_ref, uuid, status);
}
void InternalClientUnload(int refnum, int int_ref, int* status, int* result)
......
......@@ -66,7 +66,7 @@ catch (...) {
\brief Locked Engine, access to methods is serialized using a mutex.
*/
class SERVER_EXPORT JackLockedEngine
class SERVER_EXPORT JackLockedEngine
{
private:
......@@ -94,7 +94,7 @@ class SERVER_EXPORT JackLockedEngine
return fEngine.Close();
CATCH_EXCEPTION_RETURN
}
// Client management
int ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status)
{
......@@ -226,6 +226,14 @@ class SERVER_EXPORT JackLockedEngine
CATCH_EXCEPTION_RETURN
}
int ComputeTotalLatencies()
{
TRY_CALL
JackLock lock(&fEngine);
return fEngine.ComputeTotalLatencies();
CATCH_EXCEPTION_RETURN
}
// Graph
bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
{
......@@ -245,7 +253,7 @@ class SERVER_EXPORT JackLockedEngine
// RT : no lock
fEngine.NotifyXRun(refnum);
}
void NotifyGraphReorder()
{
TRY_CALL
......@@ -298,7 +306,7 @@ class SERVER_EXPORT JackLockedEngine
return fEngine.GetClientRefNum(name);
CATCH_EXCEPTION_RETURN
}
void NotifyQuit()
{
TRY_CALL
......@@ -314,7 +322,7 @@ class SERVER_EXPORT JackLockedEngine
fEngine.SessionNotify(refnum, target, type, path, socket);
CATCH_EXCEPTION
}
void SessionReply(int refnum)
{
TRY_CALL
......@@ -322,7 +330,7 @@ class SERVER_EXPORT JackLockedEngine
fEngine.SessionReply(refnum);
CATCH_EXCEPTION
}
void GetUUIDForClientName(const char *client_name, char *uuid_res, int *result)
{
TRY_CALL
......
......@@ -118,10 +118,10 @@ namespace Jack
//init and restart--------------------------------------------------------------------
/*
JackNetDriver is wrapped in a JackWaitThreadedDriver decorator that behaves
JackNetDriver is wrapped in a JackWaitThreadedDriver decorator that behaves
as a "dummy driver, until Init method returns.
*/
bool JackNetDriver::Initialize()
{
jack_log("JackNetDriver::Initialize()");
......@@ -147,7 +147,7 @@ namespace Jack
//set global parameters
SetParams();
//allocate midi ports lists
fMidiCapturePortList = new jack_port_id_t [fParams.fSendMidiChannels];
fMidiPlaybackPortList = new jack_port_id_t [fParams.fReturnMidiChannels];
......@@ -216,7 +216,7 @@ namespace Jack
void JackNetDriver::FreeAll()
{
FreePorts();
delete[] fTxBuffer;
delete[] fRxBuffer;
delete fNetAudioCaptureBuffer;
......@@ -225,7 +225,7 @@ namespace Jack
delete fNetMidiPlaybackBuffer;
delete[] fMidiCapturePortList;
delete[] fMidiPlaybackPortList;
fTxBuffer = NULL;
fRxBuffer = NULL;
fNetAudioCaptureBuffer = NULL;
......@@ -234,7 +234,7 @@ namespace Jack
fNetMidiPlaybackBuffer = NULL;
fMidiCapturePortList = NULL;
fMidiPlaybackPortList = NULL;
#ifdef JACK_MONITOR
delete fNetTimeMon;
fNetTimeMon = NULL;
......@@ -253,6 +253,7 @@ namespace Jack
unsigned long port_flags;
int audio_port_index;
uint midi_port_index;
jack_latency_range_t range;
//audio
port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
......@@ -269,7 +270,8 @@ namespace Jack
port = fGraphManager->GetPort ( port_id );
port->SetAlias ( alias );
//port latency
port->SetLatency ( fEngineControl->fBufferSize );
range.min = range.max = fEngineControl->fBufferSize;
port->SetLatencyRange(JackCaptureLatency, &range);
fCapturePortList[audio_port_index] = port_id;
jack_log ( "JackNetDriver::AllocPorts() fCapturePortList[%d] audio_port_index = %ld fPortLatency = %ld", audio_port_index, port_id, port->GetLatency() );
}
......@@ -290,15 +292,16 @@ namespace Jack
switch ( fParams.fNetworkMode )
{
case 'f' :
port->SetLatency ( ( fEngineControl->fSyncMode ) ? 0 : fEngineControl->fBufferSize );
range.min = range.max = (fEngineControl->fSyncMode) ? 0 : fEngineControl->fBufferSize;
break;
case 'n' :
port->SetLatency ( fEngineControl->fBufferSize + ( fEngineControl->fSyncMode ) ? 0 : fEngineControl->fBufferSize );
range.min = range.max = (fEngineControl->fBufferSize + (fEngineControl->fSyncMode) ? 0 : fEngineControl->fBufferSize);
break;
case 's' :
port->SetLatency ( 2 * fEngineControl->fBufferSize + ( fEngineControl->fSyncMode ) ? 0 : fEngineControl->fBufferSize );
range.min = range.max = (2 * fEngineControl->fBufferSize + (fEngineControl->fSyncMode) ? 0 : fEngineControl->fBufferSize);
break;
}
port->SetLatencyRange(JackPlaybackLatency, &range);
fPlaybackPortList[audio_port_index] = port_id;
jack_log ( "JackNetDriver::AllocPorts() fPlaybackPortList[%d] audio_port_index = %ld fPortLatency = %ld", audio_port_index, port_id, port->GetLatency() );
}
......@@ -316,7 +319,8 @@ namespace Jack
}
port = fGraphManager->GetPort ( port_id );
//port latency
port->SetLatency ( fEngineControl->fBufferSize );
range.min = range.max = fEngineControl->fBufferSize;
port->SetLatencyRange(JackCaptureLatency, &range);
fMidiCapturePortList[midi_port_index] = port_id;
jack_log ( "JackNetDriver::AllocPorts() fMidiCapturePortList[%d] midi_port_index = %ld fPortLatency = %ld", midi_port_index, port_id, port->GetLatency() );
}
......@@ -337,15 +341,16 @@ namespace Jack
switch ( fParams.fNetworkMode )
{
case 'f' :
port->SetLatency ( ( fEngineControl->fSyncMode ) ? 0 : fEngineControl->fBufferSize );
range.min = range.max = (fEngineControl->fSyncMode) ? 0 : fEngineControl->fBufferSize;
break;
case 'n' :
port->SetLatency ( fEngineControl->fBufferSize + ( fEngineControl->fSyncMode ) ? 0 : fEngineControl->fBufferSize ) ;
range.min = range.max = (fEngineControl->fBufferSize + (fEngineControl->fSyncMode) ? 0 : fEngineControl->fBufferSize);
break;
case 's' :
port->SetLatency ( 2 * fEngineControl->fBufferSize + ( fEngineControl->fSyncMode ) ? 0 : fEngineControl->fBufferSize );
range.min = range.max = (2 * fEngineControl->fBufferSize + (fEngineControl->fSyncMode) ? 0 : fEngineControl->fBufferSize);
break;
}
port->SetLatencyRange(JackPlaybackLatency, &range);
fMidiPlaybackPortList[midi_port_index] = port_id;
jack_log ( "JackNetDriver::AllocPorts() fMidiPlaybackPortList[%d] midi_port_index = %ld fPortLatency = %ld", midi_port_index, port_id, port->GetLatency() );
}
......@@ -404,7 +409,7 @@ namespace Jack
//is there a transport state change to handle ?
if ( fSendTransportData.fNewState && ( fSendTransportData.fState != fEngineControl->fTransport.GetState() ) )
{
switch ( fSendTransportData.fState )
{
case JackTransportStopped :
......@@ -453,13 +458,13 @@ namespace Jack
else
fReturnTransportData.fTimebaseMaster = NO_CHANGE;
*/
//update transport state and position
fReturnTransportData.fState = fEngineControl->fTransport.Query ( &fReturnTransportData.fPosition );
//is it a new state (that the master need to know...) ?
fReturnTransportData.fNewState = (( fReturnTransportData.fState == JackTransportNetStarting) &&
( fReturnTransportData.fState != fLastTransportState ) &&
( fReturnTransportData.fState != fLastTransportState ) &&
( fReturnTransportData.fState != fSendTransportData.fState ) );
if ( fReturnTransportData.fNewState )
jack_info ( "Sending '%s'.", GetTransportState ( fReturnTransportData.fState ) );
......@@ -487,14 +492,14 @@ namespace Jack
return 0;
#ifdef JACK_MONITOR
// For timing
// For timing
fRcvSyncUst = GetMicroSeconds();
#endif
//decode sync
//if there is an error, don't return -1, it will skip Write() and the network error probably won't be identified
DecodeSyncPacket();
#ifdef JACK_MONITOR
fNetTimeMon->Add ( ( ( float ) ( GetMicroSeconds() - fRcvSyncUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f );
#endif
......@@ -529,7 +534,7 @@ namespace Jack
//sync
EncodeSyncPacket();
//send sync
if ( SyncSend() == SOCKET_ERROR )
return SOCKET_ERROR;
......
......@@ -13,7 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
......@@ -71,7 +71,8 @@ struct JackRequest
kSessionReply = 34,
kGetClientByUUID = 35,
kReserveClientName = 36,
kGetUUIDByClient = 37
kGetUUIDByClient = 37,
kComputeTotalLatencies = 38
};
RequestType fType;
......@@ -122,7 +123,7 @@ struct JackResult
{
return trans->Write(&fResult, sizeof(int));
}
};
/*!
......@@ -161,7 +162,7 @@ struct JackClientCheckRequest : public JackRequest
CheckRes(trans->Write(&fOptions, sizeof(int)));
return trans->Write(&fUUID, sizeof(int));
}
};
/*!
......@@ -197,7 +198,7 @@ struct JackClientCheckResult : public JackResult
CheckRes(trans->Write(&fStatus, sizeof(int)));
return 0;
}
};
/*!
......@@ -210,7 +211,7 @@ struct JackClientOpenRequest : public JackRequest
int fPID;
int fUUID;
char fName[JACK_CLIENT_NAME_SIZE + 1];
JackClientOpenRequest()
{}
JackClientOpenRequest(const char* name, int pid, int uuid): JackRequest(JackRequest::kClientOpen)
......@@ -234,7 +235,7 @@ struct JackClientOpenRequest : public JackRequest
CheckRes(trans->Write(&fUUID, sizeof(int)));
return trans->Write(&fName, sizeof(fName));
}
};
/*!
......@@ -247,7 +248,7 @@ struct JackClientOpenResult : public JackResult
int fSharedEngine;
int fSharedClient;
int fSharedGraph;
JackClientOpenResult()
: JackResult(), fSharedEngine(-1), fSharedClient(-1), fSharedGraph(-1)
{}
......@@ -272,7 +273,7 @@ struct JackClientOpenResult : public JackResult
CheckRes(trans->Write(&fSharedGraph, sizeof(int)));
return 0;
}
};
/*!
......@@ -299,7 +300,7 @@ struct JackClientCloseRequest : public JackRequest
CheckRes(JackRequest::Write(trans));
return trans->Write(&fRefNum, sizeof(int));
}
};
/*!
......@@ -402,7 +403,7 @@ struct JackPortRegisterRequest : public JackRequest
CheckRes(trans->Write(&fBufferSize, sizeof(unsigned int)));
return 0;
}
};
/*!
......@@ -428,7 +429,7 @@ struct JackPortRegisterResult : public JackResult
CheckRes(JackResult::Write(trans));
return trans->Write(&fPortIndex, sizeof(jack_port_id_t));
}
};
/*!
......@@ -461,7 +462,7 @@ struct JackPortUnRegisterRequest : public JackRequest
CheckRes(trans->Write(&fPortIndex, sizeof(jack_port_id_t)));
return 0;
}
};
/*!
......@@ -501,7 +502,7 @@ struct JackPortConnectNameRequest : public JackRequest
CheckRes(trans->Write(&fDst, sizeof(fDst)));
return 0;
}
};
/*!
......@@ -540,7 +541,7 @@ struct JackPortDisconnectNameRequest : public JackRequest
CheckRes(trans->Write(&fDst, sizeof(fDst)));
return 0;
}
};
/*!
......@@ -576,7 +577,7 @@ struct JackPortConnectRequest : public JackRequest
CheckRes(trans->Write(&fDst, sizeof(jack_port_id_t)));
return 0;
}
};
/*!
......@@ -612,7 +613,7 @@ struct JackPortDisconnectRequest : public JackRequest
CheckRes(trans->Write(&fDst, sizeof(jack_port_id_t)));
return 0;
}
};
/*!
......@@ -651,7 +652,7 @@ struct JackPortRenameRequest : public JackRequest
return 0;
}
};
/*!
......@@ -679,7 +680,7 @@ struct JackSetBufferSizeRequest : public JackRequest
CheckRes(JackRequest::Write(trans));
return trans->Write(&fBufferSize, sizeof(jack_nframes_t));
}
};
/*!
......@@ -707,7 +708,31 @@ struct JackSetFreeWheelRequest : public JackRequest
CheckRes(JackRequest::Write(trans));
return trans->Write(&fOnOff, sizeof(int));
}
};
/*!
\brief ComputeTotalLatencies request.
*/
struct JackComputeTotalLatenciesRequest : public JackRequest
{
JackComputeTotalLatenciesRequest()
: JackRequest(JackRequest::kComputeTotalLatencies)
{}
int Read(JackChannelTransaction* trans)
{
return 0;
}
int Write(JackChannelTransaction* trans)
{
CheckRes(JackRequest::Write(trans));
return 0;
}
};
/*!
......@@ -735,7 +760,7 @@ struct JackReleaseTimebaseRequest : public JackRequest
CheckRes(JackRequest::Write(trans));
return trans->Write(&fRefNum, sizeof(int));
}
};
/*!
......@@ -766,7 +791,7 @@ struct JackSetTimebaseCallbackRequest : public JackRequest
CheckRes(trans->Write(&fRefNum, sizeof(int)));
return trans->Write(&fConditionnal, sizeof(int));
}
};
/*!
......@@ -797,7 +822,7 @@ struct JackGetInternalClientNameRequest : public JackRequest
CheckRes(trans->Write(&fRefNum, sizeof(int)));
return trans->Write(&fIntRefNum, sizeof(int));
}
};