Commit 7254ce1e authored by sletz's avatar sletz
Browse files

rebase from trunk 4180:4238

git-svn-id: http://subversion.jackaudio.org/jack/jack2/branches/libjacknet@4239 0c269be4-1314-0410-8aa9-9f06e86f4224
parent a7e83774
......@@ -34,9 +34,38 @@ Valerio Pilo
Jackdmp changes log
---------------------------
2011-03-29 Stephane Letz <letz@grame.fr>
* Synchronize JackWeakAPI.cpp with new APIs.
2011-03-28 Stephane Letz <letz@grame.fr>
* Correction of jack_connect/jack_disconnect: use of jack_activate and volatile keyword for thread shared variable.
* Correction of JackNetOneDriver for latest CELT API.
2011-03-24 Stephane Letz <letz@grame.fr>
* Implement renaming in JackDriver::Open to avoid name collision (thanks Devin Anderson).
* Correct alsa_driver_restart (thanks Devin Anderson).
2011-03-23 Stephane Letz <letz@grame.fr>
* Devin Anderson server-ctl-proposal branch merged on trunk: improved control API, slave backend reworked.
2011-03-14 Stephane Letz <letz@grame.fr>
* Correct JackEngine::NotifyGraphReorder, update JackDebugClient with latest API.
2011-03-13 Stephane Letz <letz@grame.fr>
* Rework internal slave driver management, JackServerGlobals now handle same parameters as jackdmp.
2011-03-11 Stephane Letz <letz@grame.fr>
* Correct JackNetMaster::SetBufferSize.
* Use jack_default_audio_sample_t instead of float consistently, fix ticket #201."
* -X now allows to add several slave backends, add -I to load several internal clients.
2011-03-10 Stephane Letz <letz@grame.fr>
......
This diff is collapsed.
......@@ -116,7 +116,7 @@ extern "C"
EXPORT int jack_set_xrun_callback(jack_client_t *,
JackXRunCallback xrun_callback, void *arg);
EXPORT int jack_set_latency_callback(jack_client_t *client,
JackLatencyCallback callback, void *arg);
JackLatencyCallback latency_callback, void *arg);
EXPORT int jack_activate(jack_client_t *client);
EXPORT int jack_deactivate(jack_client_t *client);
......
......@@ -36,17 +36,17 @@ namespace Jack
int JackAudioAdapter::Process (jack_nframes_t frames, void* arg)
{
JackAudioAdapter* adapter = static_cast<JackAudioAdapter*>(arg);
float* inputBuffer[adapter->fAudioAdapter->GetInputs()];
float* outputBuffer[adapter->fAudioAdapter->GetOutputs()];
jack_default_audio_sample_t* inputBuffer[adapter->fAudioAdapter->GetInputs()];
jack_default_audio_sample_t* outputBuffer[adapter->fAudioAdapter->GetOutputs()];
// Always clear output
for (int i = 0; i < adapter->fAudioAdapter->GetInputs(); i++) {
inputBuffer[i] = (float*)jack_port_get_buffer(adapter->fCapturePortList[i], frames);
memset(inputBuffer[i], 0, frames * sizeof(float));
inputBuffer[i] = (jack_default_audio_sample_t*)jack_port_get_buffer(adapter->fCapturePortList[i], frames);
memset(inputBuffer[i], 0, frames * sizeof(jack_default_audio_sample_t));
}
for (int i = 0; i < adapter->fAudioAdapter->GetOutputs(); i++) {
outputBuffer[i] = (float*)jack_port_get_buffer(adapter->fPlaybackPortList[i], frames);
outputBuffer[i] = (jack_default_audio_sample_t*)jack_port_get_buffer(adapter->fPlaybackPortList[i], frames);
}
adapter->fAudioAdapter->PullAndPush(inputBuffer, outputBuffer, frames);
......
......@@ -88,18 +88,18 @@ namespace Jack
JackResampler** fCaptureRingBuffer;
JackResampler** fPlaybackRingBuffer;
unsigned int fQuality;
unsigned int fRingbufferCurSize;
jack_time_t fPullAndPushTime;
bool fRunning;
bool fAdaptative;
void ResetRingBuffers();
void AdaptRingBufferSize();
void GrowRingBufferSize();
public:
JackAudioAdapterInterface ( jack_nframes_t buffer_size, jack_nframes_t sample_rate, jack_nframes_t ring_buffer_size = DEFAULT_ADAPTATIVE_SIZE):
......@@ -140,15 +140,15 @@ namespace Jack
{}
virtual void Reset();
virtual void Create();
virtual void Destroy();
virtual int Open()
{
return 0;
}
virtual int Close()
{
return 0;
......@@ -157,7 +157,7 @@ namespace Jack
virtual int SetHostBufferSize ( jack_nframes_t buffer_size )
{
fHostBufferSize = buffer_size;
if (fAdaptative)
if (fAdaptative)
AdaptRingBufferSize();
return 0;
}
......@@ -165,7 +165,7 @@ namespace Jack
virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size )
{
fAdaptedBufferSize = buffer_size;
if (fAdaptative)
if (fAdaptative)
AdaptRingBufferSize();
return 0;
}
......@@ -197,7 +197,7 @@ namespace Jack
SetAdaptedSampleRate ( sample_rate );
return 0;
}
void SetInputs ( int inputs )
{
jack_log ( "JackAudioAdapterInterface::SetInputs %d", inputs );
......@@ -222,8 +222,8 @@ namespace Jack
return fPlaybackChannels;
}
int PushAndPull(float** inputBuffer, float** outputBuffer, unsigned int frames);
int PullAndPush(float** inputBuffer, float** outputBuffer, unsigned int frames);
int PushAndPull(jack_default_audio_sample_t** inputBuffer, jack_default_audio_sample_t** outputBuffer, unsigned int frames);
int PullAndPush(jack_default_audio_sample_t** inputBuffer, jack_default_audio_sample_t** outputBuffer, unsigned int frames);
};
......
......@@ -138,14 +138,13 @@ int JackAudioDriver::Attach()
// Monitor ports
if (fWithMonitorPorts) {
jack_log("Create monitor port ");
jack_log("Create monitor port");
snprintf(name, sizeof(name) - 1, "%s:monitor_%u", fClientControl.fName, i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl.fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("Cannot register monitor port for %s", name);
return -1;
} else {
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
range.min = range.max = fEngineControl->fBufferSize;
port->SetLatencyRange(JackCaptureLatency, &range);
fMonitorPortList[i] = port_index;
......@@ -178,8 +177,8 @@ int JackAudioDriver::Write()
{
for (int i = 0; i < fPlaybackChannels; i++) {
if (fGraphManager->GetConnectionsNum(fPlaybackPortList[i]) > 0) {
float* buffer = GetOutputBuffer(i);
int size = sizeof(float) * fEngineControl->fBufferSize;
jack_default_audio_sample_t* buffer = GetOutputBuffer(i);
int size = sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize;
// Monitor ports
if (fWithMonitorPorts && fGraphManager->GetConnectionsNum(fMonitorPortList[i]) > 0)
memcpy(GetMonitorBuffer(i), buffer, size);
......@@ -313,6 +312,26 @@ int JackAudioDriver::ProcessGraphSync()
return res;
}
int JackAudioDriver::Start()
{
int res = JackDriver::Start();
if ((res >= 0) && fIsMaster) {
res = StartSlaves();
}
return res;
}
int JackAudioDriver::Stop()
{
int res = JackDriver::Stop();
if (fIsMaster) {
if (StopSlaves() < 0) {
res = -1;
}
}
return res;
}
void JackAudioDriver::WaitUntilNextCycle()
{
int wait_time_usec = (int((float(fEngineControl->fBufferSize) / (float(fEngineControl->fSampleRate))) * 1000000.0f));
......
......@@ -92,6 +92,9 @@ class SERVER_EXPORT JackAudioDriver : public JackDriver
virtual int Attach();
virtual int Detach();
virtual int Start();
virtual int Stop();
virtual int Write();
virtual int SetBufferSize(jack_nframes_t buffer_size);
......
......@@ -38,11 +38,11 @@ static void AudioBufferInit(void* buffer, size_t buffer_size, jack_nframes_t)
memset(buffer, 0, buffer_size);
}
static inline void MixAudioBuffer(float* mixbuffer, float* buffer, jack_nframes_t frames)
static inline void MixAudioBuffer(jack_default_audio_sample_t* mixbuffer, jack_default_audio_sample_t* buffer, jack_nframes_t frames)
{
#ifdef __APPLE__
// It seems that a vector mult only operation does not exist...
float gain = 1.0f;
jack_default_audio_sample_t gain = jack_default_audio_sample_t(1.0);
vDSP_vsma(buffer, 1, &gain, mixbuffer, 1, mixbuffer, 1, frames);
#else
jack_nframes_t frames_group = frames / 4;
......@@ -57,14 +57,14 @@ static inline void MixAudioBuffer(float* mixbuffer, float* buffer, jack_nframes_
buffer += 4;
frames_group--;
#else
register float mixFloat1 = *mixbuffer;
register float sourceFloat1 = *buffer;
register float mixFloat2 = *(mixbuffer + 1);
register float sourceFloat2 = *(buffer + 1);
register float mixFloat3 = *(mixbuffer + 2);
register float sourceFloat3 = *(buffer + 2);
register float mixFloat4 = *(mixbuffer + 3);
register float sourceFloat4 = *(buffer + 3);
register jack_default_audio_sample_t mixFloat1 = *mixbuffer;
register jack_default_audio_sample_t sourceFloat1 = *buffer;
register jack_default_audio_sample_t mixFloat2 = *(mixbuffer + 1);
register jack_default_audio_sample_t sourceFloat2 = *(buffer + 1);
register jack_default_audio_sample_t mixFloat3 = *(mixbuffer + 2);
register jack_default_audio_sample_t sourceFloat3 = *(buffer + 2);
register jack_default_audio_sample_t mixFloat4 = *(mixbuffer + 3);
register jack_default_audio_sample_t sourceFloat4 = *(buffer + 3);
buffer += 4;
frames_group--;
......@@ -84,8 +84,8 @@ static inline void MixAudioBuffer(float* mixbuffer, float* buffer, jack_nframes_
}
while (frames > 0) {
register float mixFloat1 = *mixbuffer;
register float sourceFloat1 = *buffer;
register jack_default_audio_sample_t mixFloat1 = *mixbuffer;
register jack_default_audio_sample_t sourceFloat1 = *buffer;
buffer++;
frames--;
mixFloat1 += sourceFloat1;
......@@ -104,8 +104,8 @@ static void AudioBufferMixdown(void* mixbuffer, void** src_buffers, int src_coun
jack_nframes_t frames_group = nframes / 4;
jack_nframes_t remaining_frames = nframes % 4;
float * source = static_cast<float*>(src_buffers[0]);
float * target = static_cast<float*>(mixbuffer);
jack_default_audio_sample_t * source = static_cast<jack_default_audio_sample_t*>(src_buffers[0]);
jack_default_audio_sample_t * target = static_cast<jack_default_audio_sample_t*>(mixbuffer);
while (frames_group > 0)
{
......@@ -120,19 +120,19 @@ static void AudioBufferMixdown(void* mixbuffer, void** src_buffers, int src_coun
target[i] = source[i];
#else
memcpy(mixbuffer, src_buffers[0], nframes * sizeof(float));
memcpy(mixbuffer, src_buffers[0], nframes * sizeof(jack_default_audio_sample_t));
#endif
// Mix remaining buffers
for (int i = 1; i < src_count; ++i) {
buffer = src_buffers[i];
MixAudioBuffer(static_cast<float*>(mixbuffer), static_cast<float*>(buffer), nframes);
MixAudioBuffer(static_cast<jack_default_audio_sample_t*>(mixbuffer), static_cast<jack_default_audio_sample_t*>(buffer), nframes);
}
}
static size_t AudioBufferSize()
{
return GetEngineControl()->fBufferSize * sizeof(float);
return GetEngineControl()->fBufferSize * sizeof(jack_default_audio_sample_t);
}
const JackPortType gAudioPortType =
......
......@@ -496,8 +496,8 @@ bool JackClient::Init()
// Setup RT
if (GetEngineControl()->fRealTime) {
if (fThread.AcquireRealTime(GetEngineControl()->fClientPriority) < 0) {
jack_error("JackClient::AcquireRealTime error");
if (fThread.AcquireSelfRealTime(GetEngineControl()->fClientPriority) < 0) {
jack_error("JackClient::AcquireSelfRealTime error");
}
}
......
......@@ -44,7 +44,7 @@ struct JackEngineControl;
\brief The base class for clients: share part of the implementation for JackInternalClient and JackLibClient.
*/
class JackClient : public JackClientInterface, public JackRunnableInterface
class SERVER_EXPORT JackClient : public JackClientInterface, public JackRunnableInterface
{
friend class JackDebugClient;
......@@ -195,15 +195,15 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
// RT Thread
jack_nframes_t CycleWait();
void CycleSignal(int status);
int SetProcessThread(JackThreadCallback fun, void *arg);
virtual int SetProcessThread(JackThreadCallback fun, void *arg);
// Session API
virtual jack_session_command_t* SessionNotify(const char* target, jack_session_event_type_t type, const char* path);
virtual int SessionReply(jack_session_event_t* ev);
char* GetUUIDForClientName(const char* client_name);
char* GetClientNameByUUID(const char* uuid);
int ReserveClientName(const char* client_name, const char* uuid);
int ClientHasSessionCallback(const char* client_name);
virtual char* GetUUIDForClientName(const char* client_name);
virtual char* GetClientNameByUUID(const char* uuid);
virtual int ReserveClientName(const char* client_name, const char* uuid);
virtual int ClientHasSessionCallback(const char* client_name);
// JackRunnableInterface interface
bool Init();
......
......@@ -78,15 +78,15 @@ struct jackctl_server
/* int32_t, msecs; if zero, use period size. */
union jackctl_parameter_value client_timeout;
union jackctl_parameter_value default_client_timeout;
/* uint32_t, clock source type */
union jackctl_parameter_value clock_source;
union jackctl_parameter_value default_clock_source;
/* uint32_t, max port number */
union jackctl_parameter_value port_max;
union jackctl_parameter_value default_port_max;
/* bool */
union jackctl_parameter_value replace_registry;
union jackctl_parameter_value default_replace_registry;
......@@ -366,7 +366,7 @@ jackctl_internals_load(
}
while (descriptor_node_ptr != NULL)
{
{
internal_ptr = (struct jackctl_internal *)malloc(sizeof(struct jackctl_internal));
if (internal_ptr == NULL)
{
......@@ -450,21 +450,21 @@ sigset_t
jackctl_setup_signals(
unsigned int flags)
{
if ((waitEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) {
if ((waitEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) {
jack_error("CreateEvent fails err = %ld", GetLastError());
return 0;
}
(void) signal(SIGINT, do_nothing_handler);
(void) signal(SIGINT, do_nothing_handler);
(void) signal(SIGABRT, do_nothing_handler);
(void) signal(SIGTERM, do_nothing_handler);
return (sigset_t)waitEvent;
return (sigset_t)waitEvent;
}
void jackctl_wait_signals(sigset_t signals)
{
if (WaitForSingleObject(waitEvent, INFINITE) != WAIT_OBJECT_0) {
if (WaitForSingleObject(waitEvent, INFINITE) != WAIT_OBJECT_0) {
jack_error("WaitForSingleObject fails err = %ld", GetLastError());
}
}
......@@ -539,7 +539,7 @@ jackctl_setup_signals(
* explicitly reset it
*/
pthread_sigmask(SIG_BLOCK, &signals, 0);
pthread_sigmask(SIG_BLOCK, &signals, 0);
/* install a do-nothing handler because otherwise pthreads
behaviour is undefined when we enter sigwait.
......@@ -745,7 +745,7 @@ EXPORT jackctl_server_t * jackctl_server_create(
{
goto fail_free_parameters;
}
value.ui = PORT_NUM;
if (jackctl_add_parameter(
&server_ptr->parameters,
......@@ -795,7 +795,7 @@ EXPORT jackctl_server_t * jackctl_server_create(
{
goto fail_free_parameters;
}
/* Allowed to fail */
jackctl_internals_load(server_ptr);
......@@ -826,6 +826,11 @@ EXPORT const JSList * jackctl_server_get_drivers_list(jackctl_server *server_ptr
EXPORT bool jackctl_server_stop(jackctl_server *server_ptr)
{
server_ptr->engine->Stop();
return true;
}
EXPORT bool jackctl_server_close(jackctl_server *server_ptr)
{
server_ptr->engine->Close();
delete server_ptr->engine;
......@@ -853,7 +858,7 @@ EXPORT const JSList * jackctl_server_get_parameters(jackctl_server *server_ptr)
}
EXPORT bool
jackctl_server_start(
jackctl_server_open(
jackctl_server *server_ptr,
jackctl_driver *driver_ptr)
{
......@@ -882,7 +887,7 @@ jackctl_server_start(
if (!server_ptr->realtime.b && server_ptr->client_timeout.i == 0)
server_ptr->client_timeout.i = 500; /* 0.5 sec; usable when non realtime. */
/* check port max value before allocating server */
if (server_ptr->port_max.ui > PORT_NUM_MAX) {
jack_error("JACK server started with too much ports %d (when port max can be %d)", server_ptr->port_max.ui, PORT_NUM_MAX);
......@@ -896,7 +901,7 @@ jackctl_server_start(
server_ptr->client_timeout.i,
server_ptr->realtime.b,
server_ptr->realtime_priority.i,
server_ptr->port_max.ui,
server_ptr->port_max.ui,
server_ptr->verbose.b,
(jack_timer_type_t)server_ptr->clock_source.ui,
server_ptr->name.str);
......@@ -913,18 +918,8 @@ jackctl_server_start(
goto fail_delete;
}
rc = server_ptr->engine->Start();
if (rc < 0)
{
jack_error("JackServer::Start() failed with %d", rc);
goto fail_close;
}
return true;
fail_close:
server_ptr->engine->Close();
fail_delete:
delete server_ptr->engine;
server_ptr->engine = NULL;
......@@ -946,6 +941,19 @@ fail:
return false;
}
EXPORT bool
jackctl_server_start(
jackctl_server *server_ptr)
{
int rc = server_ptr->engine->Start();
bool result = rc >= 0;
if (! result)
{
jack_error("JackServer::Start() failed with %d", rc);
}
return result;
}
EXPORT const char * jackctl_driver_get_name(jackctl_driver *driver_ptr)
{
return driver_ptr->desc_ptr->name;
......@@ -1179,7 +1187,7 @@ EXPORT bool jackctl_server_load_internal(
{
int status;
if (server_ptr->engine != NULL) {
server_ptr->engine->InternalClientLoad(internal->desc_ptr->name, internal->desc_ptr->name, internal->set_parameters, JackNullOption, &internal->refnum, -1, &status);
server_ptr->engine->InternalClientLoad2(internal->desc_ptr->name, internal->desc_ptr->name, internal->set_parameters, JackNullOption, &internal->refnum, -1, &status);
return (internal->refnum > 0);
} else {
return false;
......@@ -1192,6 +1200,7 @@ EXPORT bool jackctl_server_unload_internal(
{
int status;
if (server_ptr->engine != NULL && internal->refnum > 0) {
// Client object is internally kept in JackEngine, and will be desallocated in InternalClientUnload
return ((server_ptr->engine->GetEngine()->InternalClientUnload(internal->refnum, &status)) == 0);
} else {
return false;
......@@ -1201,8 +1210,13 @@ EXPORT bool jackctl_server_unload_internal(
EXPORT bool jackctl_server_add_slave(jackctl_server * server_ptr, jackctl_driver * driver_ptr)
{
if (server_ptr->engine != NULL) {
driver_ptr->info = server_ptr->engine->AddSlave(driver_ptr->desc_ptr, driver_ptr->set_parameters);
return (driver_ptr->info != 0);
if (server_ptr->engine->IsRunning()) {
jack_error("cannot add a slave in a running server");
return false;
} else {
driver_ptr->info = server_ptr->engine->AddSlave(driver_ptr->desc_ptr, driver_ptr->set_parameters);
return (driver_ptr->info != 0);
}
} else {
return false;
}
......@@ -1211,9 +1225,14 @@ EXPORT bool jackctl_server_add_slave(jackctl_server * server_ptr, jackctl_driver
EXPORT bool jackctl_server_remove_slave(jackctl_server * server_ptr, jackctl_driver * driver_ptr)
{
if (server_ptr->engine != NULL) {
server_ptr->engine->RemoveSlave(driver_ptr->info);
delete driver_ptr->info;
return true;
if (server_ptr->engine->IsRunning()) {
jack_error("cannot remove a slave from a running server");
return false;
} else {
server_ptr->engine->RemoveSlave(driver_ptr->info);
delete driver_ptr->info;
return true;
}
} else {
return false;
}
......
......@@ -101,13 +101,21 @@ jackctl_server_get_drivers_list(
jackctl_server_t * server);
EXPORT bool
jackctl_server_start(
jackctl_server_open(
jackctl_server_t * server,
jackctl_driver_t * driver);
EXPORT bool
jackctl_server_start(
jackctl_server_t * server);
EXPORT bool
jackctl_server_stop(
jackctl_server_t * server);
jackctl_server_t * server);
EXPORT bool
jackctl_server_close(
jackctl_server_t * server);
EXPORT const JSList *
jackctl_server_get_parameters(
......
......@@ -505,6 +505,54 @@ int JackDebugClient::SetPortRenameCallback(JackPortRenameCallback callback, void
return fClient->SetPortRenameCallback(callback, arg);
}
int JackDebugClient::SetSessionCallback(JackSessionCallback callback, void *arg)
{
CheckClient("SetSessionCallback");
return fClient->SetSessionCallback(callback, arg);
}
int JackDebugClient::SetLatencyCallback(JackLatencyCallback callback, void *arg)
{
CheckClient("SetLatencyCallback");
return fClient->SetLatencyCallback(callback, arg);
}
jack_session_command_t* JackDebugClient::SessionNotify(const char* target, jack_session_event_type_t type, const char* path)
{
CheckClient("SessionNotify");
return fClient->SessionNotify(target, type, path);
}
int JackDebugClient::SessionReply(jack_session_event_t* ev)
{
CheckClient("SessionReply");
return fClient->SessionReply(ev);
}
char* JackDebugClient::GetUUIDForClientName(const char* client_name)
{
CheckClient("GetUUIDForClientName");
return fClient->GetUUIDForClientName(client_name);
}
char* JackDebugClient::GetClientNameByUUID(const char* uuid)
{
CheckClient("GetClientNameByUUID");
return fClient->GetClientNameByUUID(uuid);
}
int JackDebugClient::ReserveClientName(const char* client_name, const char* uuid)
{
CheckClient("ReserveClientName");
return fClient->ReserveClientName(client_name, uuid);