Commit 4f5e3ecd authored by sletz's avatar sletz
Browse files

Correct driver lifetime management.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4266 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 169d3ef8
......@@ -34,6 +34,10 @@ Valerio Pilo
Jackdmp changes log
---------------------------
2011-04-04 Stephane Letz <letz@grame.fr>
* Correct driver lifetime management.
2011-04-03 Stephane Letz <letz@grame.fr>
* Fix in JackCoreAudioDriver::Read when there is no inputs.
......
......@@ -101,7 +101,8 @@ struct jackctl_driver
jack_driver_desc_t * desc_ptr;
JSList * parameters;
JSList * set_parameters;
JackDriverInfo* info;
//JackDriverInfo* info;
JSList * infos;
};
struct jackctl_internal
......@@ -308,6 +309,7 @@ jackctl_drivers_load(
driver_ptr->desc_ptr = (jack_driver_desc_t *)descriptor_node_ptr->data;
driver_ptr->parameters = NULL;
driver_ptr->set_parameters = NULL;
driver_ptr->infos = NULL;
if (!jackctl_add_driver_parameters(driver_ptr))
{
......@@ -377,6 +379,7 @@ jackctl_internals_load(
internal_ptr->desc_ptr = (jack_driver_desc_t *)descriptor_node_ptr->data;
internal_ptr->parameters = NULL;
internal_ptr->set_parameters = NULL;
internal_ptr->refnum = -1;
if (!jackctl_add_driver_parameters((struct jackctl_driver *)internal_ptr))
{
......@@ -1214,8 +1217,13 @@ EXPORT bool jackctl_server_add_slave(jackctl_server * server_ptr, jackctl_driver
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);
JackDriverInfo* info = server_ptr->engine->AddSlave(driver_ptr->desc_ptr, driver_ptr->set_parameters);
if (info) {
driver_ptr->infos = jack_slist_append(driver_ptr->infos, info);
return true;
} else {
return false;
}
}
} else {
return false;
......@@ -1229,8 +1237,10 @@ EXPORT bool jackctl_server_remove_slave(jackctl_server * server_ptr, jackctl_dri
jack_error("cannot remove a slave from a running server");
return false;
} else {
server_ptr->engine->RemoveSlave(driver_ptr->info);
delete driver_ptr->info;
JackDriverInfo* info = (JackDriverInfo*)driver_ptr->infos->data;
driver_ptr->infos = jack_slist_remove(driver_ptr->infos, info);
server_ptr->engine->RemoveSlave(info);
delete info;
return true;
}
} else {
......
......@@ -376,6 +376,12 @@ int JackDriver::Start()
return 0;
}
int JackDriver::Stop()
{
fIsRunning = false;
return 0;
}
int JackDriver::StartSlaves()
{
int res = 0;
......@@ -394,12 +400,6 @@ int JackDriver::StartSlaves()
return res;
}
int JackDriver::Stop()
{
fIsRunning = false;
return 0;
}
int JackDriver::StopSlaves()
{
int res = 0;
......
......@@ -137,7 +137,6 @@ int JackServer::Close()
fChannel.Close();
fAudioDriver->Detach();
fAudioDriver->Close();
fFreewheelDriver->Close();
fEngine->Close();
// TODO: move that in reworked JackServerGlobals::Destroy()
JackMessageBuffer::Destroy();
......
......@@ -533,6 +533,19 @@ int main(int argc, char* argv[])
fprintf(stderr, "Cannot stop server...\n");
}
close_server:
if (loopback > 0) {
jackctl_server_remove_slave(server_ctl, loopback_driver_ctl);
}
// Slave drivers
for (it = slaves_list.begin(); it != slaves_list.end(); it++) {
jackctl_driver_t * slave_driver_ctl = jackctl_server_get_driver(server_ctl, *it);
jackctl_server_remove_slave(server_ctl, slave_driver_ctl);
}
// Internal clients
for (it = internals_list.begin(); it != internals_list.end(); it++) {
jackctl_internal_t * internal_driver_ctl = jackctl_server_get_internal(server_ctl, *it);
jackctl_server_unload_internal(server_ctl, internal_driver_ctl);
}
jackctl_server_close(server_ctl);
destroy_server:
jackctl_server_destroy(server_ctl);
......
......@@ -48,9 +48,7 @@ JackALSARawMidiDriver::JackALSARawMidiDriver(const char *name,
JackALSARawMidiDriver::~JackALSARawMidiDriver()
{
Stop();
delete thread;
Close();
}
int
......@@ -109,6 +107,9 @@ JackALSARawMidiDriver::Attach()
int
JackALSARawMidiDriver::Close()
{
// Generic MIDI driver close
int result = JackMidiDriver::Close();
if (input_ports) {
for (int i = 0; i < fCaptureChannels; i++) {
delete input_ports[i];
......@@ -123,7 +124,7 @@ JackALSARawMidiDriver::Close()
delete[] output_ports;
output_ports = 0;
}
return 0;
return result;
}
bool
......@@ -528,7 +529,6 @@ JackALSARawMidiDriver::Start()
int
JackALSARawMidiDriver::Stop()
{
jack_info("JackALSARawMidiDriver::Stop - stopping 'alsarawmidi' driver.");
if (fds[1] != -1) {
......
......@@ -75,10 +75,7 @@ JackCoreMidiDriver::JackCoreMidiDriver(const char *name, const char *alias,
}
JackCoreMidiDriver::~JackCoreMidiDriver()
{
Stop();
Close();
}
{}
int
JackCoreMidiDriver::Attach()
......@@ -181,7 +178,9 @@ JackCoreMidiDriver::Attach()
int
JackCoreMidiDriver::Close()
{
int result = 0;
// Generic MIDI driver close
int result = JackMidiDriver::Close();
OSStatus status;
if (physical_input_ports) {
for (int i = 0; i < num_physical_inputs; i++) {
......
......@@ -53,7 +53,6 @@ JackCoreMidiOutputPort::JackCoreMidiOutputPort(double time_ratio,
JackCoreMidiOutputPort::~JackCoreMidiOutputPort()
{
Stop();
delete thread;
sem_destroy(thread_queue_semaphore);
sem_unlink(semaphore_name);
......
......@@ -35,10 +35,7 @@ JackWinMMEDriver::JackWinMMEDriver(const char *name, const char *alias,
}
JackWinMMEDriver::~JackWinMMEDriver()
{
Stop();
Close();
}
{}
int
JackWinMMEDriver::Attach()
......@@ -105,7 +102,9 @@ JackWinMMEDriver::Attach()
int
JackWinMMEDriver::Close()
{
// Generic MIDI driver close
int result = JackMidiDriver::Close();
if (input_ports) {
for (int i = 0; i < fCaptureChannels; i++) {
delete input_ports[i];
......
......@@ -111,13 +111,12 @@ JackWinMMEInputPort::JackWinMMEInputPort(const char *alias_name,
WriteInError("JackWinMMEInputPort [constructor]", "midiInClose", result);
}
delete_sysex_buffer:
delete[] sysex_buffer;
delete[] sysex_buffer;
throw std::runtime_error(error_message);
}
JackWinMMEInputPort::~JackWinMMEInputPort()
{
Stop();
MMRESULT result = midiInReset(handle);
if (result != MMSYSERR_NOERROR) {
WriteInError("JackWinMMEInputPort [destructor]", "midiInReset", result);
......@@ -164,14 +163,14 @@ JackWinMMEInputPort::ProcessJack(JackMidiBuffer *port_buffer,
if (! jack_event) {
jack_event = thread_queue->DequeueEvent();
}
for (; jack_event; jack_event = thread_queue->DequeueEvent()) {
for (; jack_event; jack_event = thread_queue->DequeueEvent()) {
switch (write_queue->EnqueueEvent(jack_event)) {
case JackMidiWriteQueue::BUFFER_TOO_SMALL:
jack_error("JackWinMMEMidiInputPort::Process - The buffer write "
"queue couldn't enqueue a %d-byte event. Dropping "
"event.", jack_event->size);
// Fallthrough on purpose
case JackMidiWriteQueue::OK:
case JackMidiWriteQueue::OK:
continue;
}
break;
......@@ -182,7 +181,7 @@ void
JackWinMMEInputPort::ProcessWinMME(UINT message, DWORD param1, DWORD param2)
{
set_threaded_log_function();
jack_nframes_t current_frame = GetCurrentFrame();
jack_nframes_t current_frame = GetCurrentFrame();
switch (message) {
case MIM_CLOSE:
......@@ -196,7 +195,7 @@ JackWinMMEInputPort::ProcessWinMME(UINT message, DWORD param1, DWORD param2)
case MIM_DATA:
jack_midi_data_t message_buffer[3];
jack_midi_data_t status = param1 & 0xff;
int length = GetMessageLength(status);
int length = GetMessageLength(status);
switch (length) {
case 3:
......@@ -218,7 +217,7 @@ JackWinMMEInputPort::ProcessWinMME(UINT message, DWORD param1, DWORD param2)
"input driver sent an MIM_DATA message with an invalid "
"status byte.");
return;
}
}
EnqueueMessage(current_frame, (size_t) length, message_buffer);
break;
case MIM_LONGDATA:
......@@ -294,3 +293,4 @@ JackWinMMEInputPort::WriteInError(const char *jack_func, const char *mm_func,
jack_error("%s - %s: %s", jack_func, mm_func, error_message);
}
......@@ -85,7 +85,7 @@ JackWinMMEOutputPort::JackWinMMEOutputPort(const char *alias_name,
index + 1);
snprintf(name, sizeof(name) - 1, "%s:playback_%d", client_name, index + 1);
read_queue_ptr.release();
thread_queue_ptr.release();
thread_queue_ptr.release();
thread_ptr.release();
return;
......@@ -99,13 +99,12 @@ JackWinMMEOutputPort::JackWinMMEOutputPort(const char *alias_name,
WriteOutError("JackWinMMEOutputPort [constructor]", "midiOutClose",
result);
}
raise_exception:
raise_exception:
throw std::runtime_error(error_message);
}
JackWinMMEOutputPort::~JackWinMMEOutputPort()
{
Stop();
MMRESULT result = midiOutReset(handle);
if (result != MMSYSERR_NOERROR) {
WriteOutError("JackWinMMEOutputPort [destructor]", "midiOutReset",
......@@ -123,7 +122,7 @@ JackWinMMEOutputPort::~JackWinMMEOutputPort()
WriteOSError("JackWinMMEOutputPort [destructor]", "CloseHandle");
}
delete read_queue;
delete thread_queue;
delete thread_queue;
delete thread;
}
......@@ -135,7 +134,7 @@ JackWinMMEOutputPort::Execute()
jack_log("JackWinMMEOutputPort::Execute BREAK");
break;
}
}
jack_midi_event_t *event = thread_queue->DequeueEvent();
if (! event) {
......@@ -261,11 +260,11 @@ JackWinMMEOutputPort::Init()
void
JackWinMMEOutputPort::ProcessJack(JackMidiBuffer *port_buffer,
jack_nframes_t frames)
{
read_queue->ResetMidiBuffer(port_buffer);
{
read_queue->ResetMidiBuffer(port_buffer);
for (jack_midi_event_t *event = read_queue->DequeueEvent(); event;
event = read_queue->DequeueEvent()) {
event = read_queue->DequeueEvent()) {
switch (thread_queue->EnqueueEvent(event, frames)) {
case JackMidiWriteQueue::BUFFER_FULL:
......@@ -310,7 +309,6 @@ JackWinMMEOutputPort::Start()
bool
JackWinMMEOutputPort::Stop()
{
jack_info("JackWinMMEOutputPort::Stop - stopping MIDI output port "
"processing thread.");
......@@ -371,3 +369,4 @@ JackWinMMEOutputPort::WriteOutError(const char *jack_func, const char *mm_func,
GetOutErrorString(result, error_message);
jack_error("%s - %s: %s", jack_func, mm_func, error_message);
}
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