Commit 42b0d3a4 authored by sletz's avatar sletz
Browse files

Correct server SetBufferSize in case of failure

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1256 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 59ba02a4
......@@ -200,6 +200,11 @@ static inline bool CheckPort(jack_port_id_t port_index)
return (port_index < PORT_NUM);
}
static inline bool CheckBufferSize(jack_nframes_t buffer_size)
{
return (buffer_size <= BUFFER_SIZE_MAX);
}
static inline void WaitGraphChange()
{
if (GetGraphManager()->IsPendingChange()) {
......@@ -478,14 +483,16 @@ EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
}
}
EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t nframes)
EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
{
JackClient* client = (JackClient*)ext_client;
if (client == NULL) {
jack_error("jack_set_buffer_size called with a NULL client");
return -1;
} else {
return client->SetBufferSize(nframes);
} else if (!CheckBufferSize(buffer_size)) {
return -1;
} else {
return client->SetBufferSize(buffer_size);
}
}
......
......@@ -93,7 +93,7 @@ class JackClientChannelInterface
virtual void PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
{}
virtual void SetBufferSize(jack_nframes_t nframes, int* result)
virtual void SetBufferSize(jack_nframes_t buffer_size, int* result)
{}
virtual void SetFreewheel(int onoff, int* result)
{}
......
......@@ -462,10 +462,10 @@ int JackClient::PortIsMine(jack_port_id_t port_index)
// Context management
//--------------------
int JackClient::SetBufferSize(jack_nframes_t nframes)
int JackClient::SetBufferSize(jack_nframes_t buffer_size)
{
int result = -1;
fChannel->SetBufferSize(nframes, &result);
fChannel->SetBufferSize(buffer_size, &result);
return result;
}
......
......@@ -109,7 +109,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
virtual int Deactivate();
// Context
virtual int SetBufferSize(jack_nframes_t nframes);
virtual int SetBufferSize(jack_nframes_t buffer_size);
virtual int SetFreeWheel(int onoff);
virtual void ShutDown();
virtual pthread_t GetThreadID();
......
......@@ -328,9 +328,9 @@ int JackDebugClient::PortIsMine(jack_port_id_t port_index)
// Context management
//--------------------
int JackDebugClient::SetBufferSize(jack_nframes_t nframes)
int JackDebugClient::SetBufferSize(jack_nframes_t buffer_size)
{
return fClient->SetBufferSize(nframes);
return fClient->SetBufferSize(buffer_size);
}
int JackDebugClient::SetFreeWheel(int onoff)
......
......@@ -80,7 +80,7 @@ class JackDebugClient : public JackClient
int Deactivate();
// Context
int SetBufferSize(jack_nframes_t nframes);
int SetBufferSize(jack_nframes_t buffer_size);
int SetFreeWheel(int onoff);
void ShutDown();
pthread_t GetThreadID();
......
......@@ -70,7 +70,7 @@ class EXPORT JackDriverInterface
virtual int Write() = 0;
virtual int Start() = 0;
virtual int Stop() = 0;
virtual int SetBufferSize(jack_nframes_t nframes) = 0;
virtual int SetBufferSize(jack_nframes_t buffer_size) = 0;
virtual int Process() = 0;
......@@ -191,7 +191,7 @@ class EXPORT JackDriver : public JackDriverClient
return 0;
}
virtual int SetBufferSize(jack_nframes_t nframes)
virtual int SetBufferSize(jack_nframes_t buffer_size)
{
return 0;
}
......
......@@ -66,9 +66,9 @@ int JackDummyDriver::Process()
return 0;
}
int JackDummyDriver::SetBufferSize(jack_nframes_t nframes)
int JackDummyDriver::SetBufferSize(jack_nframes_t buffer_size)
{
fEngineControl->fBufferSize = nframes;
fEngineControl->fBufferSize = buffer_size;
fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // In microsec
return 0;
}
......
......@@ -59,7 +59,7 @@ class JackDummyDriver : public JackAudioDriver
jack_nframes_t playback_latency);
int Process();
int SetBufferSize(jack_nframes_t nframe);
int SetBufferSize(jack_nframes_t buffer_size);
void PrintState();
};
......
......@@ -40,11 +40,11 @@ static void AssertPort(jack_port_id_t port_index)
}
}
static void AssertBufferSize(jack_nframes_t frames)
static void AssertBufferSize(jack_nframes_t buffer_size)
{
if (frames > BUFFER_SIZE_MAX) {
JackLog("JackGraphManager::AssertBufferSize frames = %ld\n", frames);
assert(frames <= BUFFER_SIZE_MAX);
if (buffer_size > BUFFER_SIZE_MAX) {
JackLog("JackGraphManager::AssertBufferSize frames = %ld\n", buffer_size);
assert(buffer_size <= BUFFER_SIZE_MAX);
}
}
......@@ -151,10 +151,10 @@ bool JackGraphManager::IsDirectConnection(int ref1, int ref2)
}
// RT
void* JackGraphManager::GetBuffer(jack_port_id_t port_index, jack_nframes_t frames)
void* JackGraphManager::GetBuffer(jack_port_id_t port_index, jack_nframes_t buffer_size)
{
AssertPort(port_index);
AssertBufferSize(frames);
AssertBufferSize(buffer_size);
JackConnectionManager* manager = ReadCurrentState();
JackPort* port = GetPort(port_index);
......@@ -167,7 +167,7 @@ void* JackGraphManager::GetBuffer(jack_port_id_t port_index, jack_nframes_t fram
// Output port
if (port->fFlags & JackPortIsOutput) {
return (port->fTied != NO_PORT) ? GetBuffer(port->fTied, frames) : GetBuffer(port_index);
return (port->fTied != NO_PORT) ? GetBuffer(port->fTied, buffer_size) : GetBuffer(port_index);
}
// Input port
......@@ -175,11 +175,11 @@ void* JackGraphManager::GetBuffer(jack_port_id_t port_index, jack_nframes_t fram
if (len == 0) { // No connections: return a zero-filled buffer
float* buffer = GetBuffer(port_index);
memset(buffer, 0, frames * sizeof(float)); // Clear buffer
memset(buffer, 0, buffer_size * sizeof(float)); // Clear buffer
return buffer;
} else if (len == 1) { // One connection: use zero-copy mode - just pass the buffer of the connected (output) port.
assert(manager->GetPort(port_index, 0) != port_index); // Check recursion
return GetBuffer(manager->GetPort(port_index, 0), frames);
return GetBuffer(manager->GetPort(port_index, 0), buffer_size);
} else { // Multiple connections
const jack_int_t* connections = manager->GetConnections(port_index);
float* mixbuffer = GetBuffer(port_index);
......@@ -189,14 +189,14 @@ void* JackGraphManager::GetBuffer(jack_port_id_t port_index, jack_nframes_t fram
// Copy first buffer
src_index = connections[0];
AssertPort(src_index);
buffer = (float*)GetBuffer(src_index, frames);
memcpy(mixbuffer, buffer, frames * sizeof(float));
buffer = (float*)GetBuffer(src_index, buffer_size);
memcpy(mixbuffer, buffer, buffer_size * sizeof(float));
// Mix remaining buffers
for (int i = 1; (i < CONNECTION_NUM) && ((src_index = connections[i]) != EMPTY); i++) {
AssertPort(src_index);
buffer = (float*)GetBuffer(src_index, frames);
JackPort::MixBuffer(mixbuffer, buffer, frames);
buffer = (float*)GetBuffer(src_index, buffer_size);
JackPort::MixBuffer(mixbuffer, buffer, buffer_size);
}
return mixbuffer;
}
......@@ -748,8 +748,8 @@ const char** JackGraphManager::GetPorts(const char* port_name_pattern, const cha
do {
cur_index = GetCurrentIndex();
if (matching_ports) {
free(matching_ports);
JackLog("JackGraphManager::GetPorts retry... \n");
free(matching_ports);
JackLog("JackGraphManager::GetPorts retry... \n");
}
matching_ports = GetPortsAux(port_name_pattern, type_name_pattern, flags);
next_index = GetCurrentIndex();
......
......@@ -88,9 +88,9 @@ class JackInternalClientChannel : public JackClientChannelInterface
*result = fEngine->PortDisconnect(refnum, src, dst);
}
void SetBufferSize(jack_nframes_t nframes, int* result)
void SetBufferSize(jack_nframes_t buffer_size, int* result)
{
*result = fServer->SetBufferSize(nframes);
*result = fServer->SetBufferSize(buffer_size);
}
void SetFreewheel(int onoff, int* result)
{
......
......@@ -214,6 +214,7 @@ int JackServer::Deactivate(int refnum)
return res;
}
/*
int JackServer::SetBufferSize(jack_nframes_t nframes)
{
JackLog("JackServer::SetBufferSize nframes = %ld\n", nframes);
......@@ -241,6 +242,30 @@ int JackServer::SetBufferSize(jack_nframes_t nframes)
fEngineControl->fFrameTimer.Init();
return fAudioDriver->Start();
}
*/
int JackServer::SetBufferSize(jack_nframes_t buffer_size)
{
JackLog("JackServer::SetBufferSize nframes = %ld\n", buffer_size);
jack_nframes_t current_buffer_size = fEngineControl->fBufferSize;
if (fAudioDriver->Stop() != 0) {
jack_error("Cannot stop audio driver");
return -1;
}
if (fAudioDriver->SetBufferSize(buffer_size) == 0) {
fFreewheelDriver->SetBufferSize(buffer_size);
fEngine->NotifyBufferSize(buffer_size);
fEngineControl->fFrameTimer.Init();
return fAudioDriver->Start();
} else { // Failure: restore current value
jack_error("Cannot SetBufferSize for audio driver, restore current value %ld", current_buffer_size);
fFreewheelDriver->SetBufferSize(current_buffer_size);
fEngineControl->fFrameTimer.Init();
return fAudioDriver->Start();
}
}
/*
Freewheel mode is implemented by switching from the (audio + freewheel) driver to the freewheel driver only:
......
......@@ -76,7 +76,7 @@ class EXPORT JackServer
int Activate(int refnum);
int Deactivate(int refnum);
int SetBufferSize(jack_nframes_t nframes);
int SetBufferSize(jack_nframes_t buffer_size);
int SetFreewheel(bool onoff);
void Notify(int refnum, int notify, int value);
......
......@@ -187,9 +187,9 @@ void JackSocketClientChannel::PortDisconnect(int refnum, jack_port_id_t src, jac
ServerSyncCall(&req, &res, result);
}
void JackSocketClientChannel::SetBufferSize(jack_nframes_t nframes, int* result)
void JackSocketClientChannel::SetBufferSize(jack_nframes_t buffer_size, int* result)
{
JackSetBufferSizeRequest req(nframes);
JackSetBufferSizeRequest req(buffer_size);
JackResult res;
ServerSyncCall(&req, &res, result);
}
......
......@@ -72,7 +72,7 @@ class JackSocketClientChannel : public JackClientChannelInterface, public JackRu
void PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result);
void PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result);
void SetBufferSize(jack_nframes_t nframes, int* result);
void SetBufferSize(jack_nframes_t buffer_size, int* result);
void SetFreewheel(int onoff, int* result);
void ReleaseTimebase(int refnum, int* result);
......
......@@ -95,9 +95,9 @@ class JackThreadedDriver : public JackDriverClientInterface, public JackRunnable
virtual int Start();
virtual int Stop();
virtual int SetBufferSize(jack_nframes_t nframes)
virtual int SetBufferSize(jack_nframes_t buffer_size)
{
return fDriver->SetBufferSize(nframes);
return fDriver->SetBufferSize(buffer_size);
}
virtual void SetMaster(bool onoff)
......
......@@ -908,19 +908,19 @@ int JackCoreAudioDriver::Stop()
return (AudioOutputUnitStop(fAUHAL) == noErr) ? 0 : -1;
}
int JackCoreAudioDriver::SetBufferSize(jack_nframes_t nframes)
int JackCoreAudioDriver::SetBufferSize(jack_nframes_t buffer_size)
{
OSStatus err;
UInt32 outSize = sizeof(UInt32);
err = AudioDeviceSetProperty(fDeviceID, NULL, 0, false, kAudioDevicePropertyBufferFrameSize, outSize, &nframes);
err = AudioDeviceSetProperty(fDeviceID, NULL, 0, false, kAudioDevicePropertyBufferFrameSize, outSize, &buffer_size);
if (err != noErr) {
jack_error("Cannot set buffer size %ld\n", nframes);
jack_error("Cannot set buffer size %ld", buffer_size);
printError(err);
return -1;
}
fEngineControl->fBufferSize = nframes;
fEngineControl->fBufferSize = buffer_size;
fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // In microsec
// Input buffers do no change : prepare them only once
......
......@@ -115,7 +115,7 @@ class JackCoreAudioDriver : public JackAudioDriver
int Read();
int Write();
int SetBufferSize(jack_nframes_t nframes);
int SetBufferSize(jack_nframes_t buffer_size);
void PrintState();
};
......
......@@ -184,9 +184,9 @@ void JackMachClientChannel::PortDisconnect(int refnum, jack_port_id_t src, jack_
}
}
void JackMachClientChannel::SetBufferSize(jack_nframes_t nframes, int* result)
void JackMachClientChannel::SetBufferSize(jack_nframes_t buffer_size, int* result)
{
kern_return_t res = rpc_jack_set_buffer_size(fPrivatePort, nframes, result);
kern_return_t res = rpc_jack_set_buffer_size(fPrivatePort, buffer_size, result);
if (res != KERN_SUCCESS) {
*result = -1;
jack_error("JackMachClientChannel::SetBufferSize err = %s", mach_error_string(res));
......
......@@ -69,7 +69,7 @@ class JackMachClientChannel : public JackClientChannelInterface, public JackRunn
void PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result);
void PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result);
void SetBufferSize(jack_nframes_t nframes, int* result);
void SetBufferSize(jack_nframes_t buffer_size, int* result);
void SetFreewheel(int onoff, int* result);
void ReleaseTimebase(int refnum, int* result);
......
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