diff audioio/AudioJACKTarget.cpp @ 70:716e9d2f91c7

* Skip ID3 block when reading MP3 files (so long as ID3 support is included) * Show progress when retrieving audio file from playlist * Avoid -- but do not actually fix -- segmentation fault on exit. I am totally stumped at the moment about why both the PA and JACK audio targets should crash when properly shut down. For the moment, we just don't shut them down... * Fix incorrect behaviour (introduced on Friday as part of a different fix) when replacing main model in situation where no current main model exists
author Chris Cannam
date Fri, 30 Nov 2007 17:31:09 +0000
parents eb596ef12041
children 19142c58cc4c
line wrap: on
line diff
--- a/audioio/AudioJACKTarget.cpp	Thu Nov 29 17:10:53 2007 +0000
+++ b/audioio/AudioJACKTarget.cpp	Fri Nov 30 17:31:09 2007 +0000
@@ -69,9 +69,9 @@
                                                jack_options_t options,
                                                jack_status_t *status, ...)
 {
-    typedef jack_client_t (*func)(const char *client_name,
-                                  jack_options_t options,
-                                  jack_status_t *status, ...);
+    typedef jack_client_t *(*func)(const char *client_name,
+                                   jack_options_t options,
+                                   jack_status_t *status, ...);
     void *s = symbol("jack_client_open");
     if (!s) return 0;
     func f = (func)s;
@@ -211,7 +211,8 @@
     AudioCallbackPlayTarget(source),
     m_client(0),
     m_bufferSize(0),
-    m_sampleRate(0)
+    m_sampleRate(0),
+    m_done(false)
 {
     JackOptions options = JackNullOption;
 #ifdef HAVE_PORTAUDIO
@@ -247,13 +248,37 @@
 AudioJACKTarget::~AudioJACKTarget()
 {
     std::cerr << "AudioJACKTarget::~AudioJACKTarget()" << std::endl;
+
+    shutdown();
+
     if (m_client) {
+
+        while (m_outputs.size() > 0) {
+            std::vector<jack_port_t *>::iterator itr = m_outputs.end();
+            --itr;
+            jack_port_t *port = *itr;
+            std::cerr << "unregister " << m_outputs.size() << std::endl;
+            if (port) jack_port_unregister(m_client, port);
+            m_outputs.erase(itr);
+        }
+        std::cerr << "Deactivating... ";
 	jack_deactivate(m_client);
+        std::cerr << "done\nClosing... ";
 	jack_client_close(m_client);
+        std::cerr << "done" << std::endl;
     }
+
+    m_client = 0;
+
     std::cerr << "AudioJACKTarget::~AudioJACKTarget() done" << std::endl;
 }
 
+void
+AudioJACKTarget::shutdown()
+{
+    m_done = true;
+}
+
 bool
 AudioJACKTarget::isOK() const
 {
@@ -342,6 +367,8 @@
 int
 AudioJACKTarget::process(jack_nframes_t nframes)
 {
+    if (m_done) return 0;
+
     if (!m_mutex.tryLock()) {
 	return 0;
     }