Browse Source

Correct server SetBufferSize in case of failure

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1256 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/0.59
sletz 18 years ago
parent
commit
42b0d3a487
25 changed files with 90 additions and 58 deletions
  1. +10
    -3
      common/JackAPI.cpp
  2. +1
    -1
      common/JackChannel.h
  3. +2
    -2
      common/JackClient.cpp
  4. +1
    -1
      common/JackClient.h
  5. +2
    -2
      common/JackDebugClient.cpp
  6. +1
    -1
      common/JackDebugClient.h
  7. +2
    -2
      common/JackDriver.h
  8. +2
    -2
      common/JackDummyDriver.cpp
  9. +1
    -1
      common/JackDummyDriver.h
  10. +15
    -15
      common/JackGraphManager.cpp
  11. +2
    -2
      common/JackInternalClientChannel.h
  12. +25
    -0
      common/JackServer.cpp
  13. +1
    -1
      common/JackServer.h
  14. +2
    -2
      common/JackSocketClientChannel.cpp
  15. +1
    -1
      common/JackSocketClientChannel.h
  16. +2
    -2
      common/JackThreadedDriver.h
  17. +4
    -4
      macosx/JackCoreAudioDriver.cpp
  18. +1
    -1
      macosx/JackCoreAudioDriver.h
  19. +2
    -2
      macosx/JackMachClientChannel.cpp
  20. +1
    -1
      macosx/JackMachClientChannel.h
  21. +1
    -1
      tests/testSem.cpp
  22. +3
    -3
      windows/JackPortAudioDriver.cpp
  23. +1
    -1
      windows/JackPortAudioDriver.h
  24. +6
    -6
      windows/JackWinNamedPipeClientChannel.cpp
  25. +1
    -1
      windows/JackWinNamedPipeClientChannel.h

+ 10
- 3
common/JackAPI.cpp View File

@@ -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);
}
}



+ 1
- 1
common/JackChannel.h View File

@@ -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)
{}


+ 2
- 2
common/JackClient.cpp View File

@@ -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;
}



+ 1
- 1
common/JackClient.h View File

@@ -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();


+ 2
- 2
common/JackDebugClient.cpp View File

@@ -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)


+ 1
- 1
common/JackDebugClient.h View File

@@ -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();


+ 2
- 2
common/JackDriver.h View File

@@ -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;
}


+ 2
- 2
common/JackDummyDriver.cpp View File

@@ -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;
}


+ 1
- 1
common/JackDummyDriver.h View File

@@ -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();
};



+ 15
- 15
common/JackGraphManager.cpp View File

@@ -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();


+ 2
- 2
common/JackInternalClientChannel.h View File

@@ -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)
{


+ 25
- 0
common/JackServer.cpp View File

@@ -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:


+ 1
- 1
common/JackServer.h View File

@@ -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);



+ 2
- 2
common/JackSocketClientChannel.cpp View File

@@ -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);
}


+ 1
- 1
common/JackSocketClientChannel.h View File

@@ -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);


+ 2
- 2
common/JackThreadedDriver.h View File

@@ -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)


+ 4
- 4
macosx/JackCoreAudioDriver.cpp View File

@@ -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


+ 1
- 1
macosx/JackCoreAudioDriver.h View File

@@ -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();
};


+ 2
- 2
macosx/JackMachClientChannel.cpp View File

@@ -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));


+ 1
- 1
macosx/JackMachClientChannel.h View File

@@ -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);


+ 1
- 1
tests/testSem.cpp View File

@@ -194,7 +194,7 @@ int main (int argc, char * const argv[])
}
*/
if (strcmp(argv[2], "server") == 0) {
if (strcmp(argv[2], "server") == 0) {
server(sem1);
} else {
client(sem1);


+ 3
- 3
windows/JackPortAudioDriver.cpp View File

@@ -393,7 +393,7 @@ int JackPortAudioDriver::Stop()
return (err == paNoError) ? 0 : -1;
}

int JackPortAudioDriver::SetBufferSize(jack_nframes_t nframes)
int JackPortAudioDriver::SetBufferSize(jack_nframes_t buffer_size)
{
PaError err;
PaStreamParameters inputParameters;
@@ -424,7 +424,7 @@ int JackPortAudioDriver::SetBufferSize(jack_nframes_t nframes)
(fInputDevice == paNoDevice) ? 0 : &inputParameters,
(fOutputDevice == paNoDevice) ? 0 : &outputParameters,
fEngineControl->fSampleRate,
nframes,
buffer_size,
paNoFlag, // Clipping is on...
Render,
this);
@@ -433,7 +433,7 @@ int JackPortAudioDriver::SetBufferSize(jack_nframes_t nframes)
return -1;
} else {
// Only done when success
fEngineControl->fBufferSize = nframes;
fEngineControl->fBufferSize = buffer_size;
fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // In microsec
return 0;
}


+ 1
- 1
windows/JackPortAudioDriver.h View File

@@ -81,7 +81,7 @@ class JackPortAudioDriver : public JackAudioDriver
int Read();
int Write();

int SetBufferSize(jack_nframes_t nframes);
int SetBufferSize(jack_nframes_t buffer_size);

void PrintState();
};


+ 6
- 6
windows/JackWinNamedPipeClientChannel.cpp View File

@@ -62,8 +62,8 @@ error:
void JackWinNamedPipeClientChannel::Close()
{
fRequestPipe.Close();
fNotificationListenPipe.Close();
// Here the thread will correctly stop when the pipe are closed
fNotificationListenPipe.Close();
// Here the thread will correctly stop when the pipe are closed
fThread->Stop();
}

@@ -186,9 +186,9 @@ void JackWinNamedPipeClientChannel::PortDisconnect(int refnum, jack_port_id_t sr
ServerSyncCall(&req, &res, result);
}

void JackWinNamedPipeClientChannel::SetBufferSize(jack_nframes_t nframes, int* result)
void JackWinNamedPipeClientChannel::SetBufferSize(jack_nframes_t buffer_size, int* result)
{
JackSetBufferSizeRequest req(nframes);
JackSetBufferSizeRequest req(buffer_size);
JackResult res;
ServerSyncCall(&req, &res, result);
}
@@ -250,8 +250,8 @@ bool JackWinNamedPipeClientChannel::Execute()
}
return true;

error:
error:
//fClient->ShutDown(); needed ??
return false;
}


+ 1
- 1
windows/JackWinNamedPipeClientChannel.h View File

@@ -71,7 +71,7 @@ class JackWinNamedPipeClientChannel : public JackClientChannelInterface, public
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);


Loading…
Cancel
Save