jack1 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1487 lines
37KB

  1. // u/* -*- Mode: C++ ; c-basic-offset: 4 -*- */
  2. /*
  3. JACK control API implementation
  4. Copyright (C) 2008 Nedko Arnaudov
  5. Copyright (C) 2008 Grame
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; version 2 of the License.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #ifndef WIN32
  18. #include <stdint.h>
  19. #include <dirent.h>
  20. #include <pthread.h>
  21. #endif
  22. #include "config.h"
  23. #include "internal.h"
  24. #include <string.h>
  25. #include <errno.h>
  26. #include <stdio.h>
  27. #include <assert.h>
  28. #include <signal.h>
  29. #include "jack/jslist.h"
  30. #include "jack/control.h"
  31. #include "driver_interface.h"
  32. #include "driver.h"
  33. #include "engine.h"
  34. #include "clientengine.h"
  35. //#include "JackError.h"
  36. //#include "JackServer.h"
  37. //#include "shm.h"
  38. //#include "JackTools.h"
  39. //#include "JackControlAPI.h"
  40. //#include "JackLockedEngine.h"
  41. //#include "JackConstants.h"
  42. //#include "JackDriverLoader.h"
  43. //#include "JackServerGlobals.h"
  44. /*
  45. * XXX: dont like statics here.
  46. */
  47. static JSList *drivers = NULL;
  48. struct jackctl_server {
  49. JSList * drivers;
  50. JSList * internals;
  51. JSList * parameters;
  52. jack_engine_t * engine;
  53. /* string, server name */
  54. union jackctl_parameter_value name;
  55. union jackctl_parameter_value default_name;
  56. /* bool, whether to be "realtime" */
  57. union jackctl_parameter_value realtime;
  58. union jackctl_parameter_value default_realtime;
  59. /* int32_t */
  60. union jackctl_parameter_value realtime_priority;
  61. union jackctl_parameter_value default_realtime_priority;
  62. /* bool, whether to exit once all clients have closed their connections */
  63. union jackctl_parameter_value temporary;
  64. union jackctl_parameter_value default_temporary;
  65. /* bool, whether to be verbose */
  66. union jackctl_parameter_value verbose;
  67. union jackctl_parameter_value default_verbose;
  68. /* int32_t, msecs; if zero, use period size. */
  69. union jackctl_parameter_value client_timeout;
  70. union jackctl_parameter_value default_client_timeout;
  71. /* uint32_t, clock source type */
  72. union jackctl_parameter_value clock_source;
  73. union jackctl_parameter_value default_clock_source;
  74. /* uint32_t, max port number */
  75. union jackctl_parameter_value port_max;
  76. union jackctl_parameter_value default_port_max;
  77. /* bool */
  78. union jackctl_parameter_value replace_registry;
  79. union jackctl_parameter_value default_replace_registry;
  80. /* bool, use mlock */
  81. union jackctl_parameter_value do_mlock;
  82. union jackctl_parameter_value default_do_mlock;
  83. /* bool, munlock gui libraries */
  84. union jackctl_parameter_value do_unlock;
  85. union jackctl_parameter_value default_do_unlock;
  86. /* bool, dont zombify... */
  87. union jackctl_parameter_value nozombies;
  88. union jackctl_parameter_value default_nozombies;
  89. /* int, timeout thres... */
  90. union jackctl_parameter_value timothres;
  91. union jackctl_parameter_value default_timothres;
  92. };
  93. struct jackctl_driver {
  94. jack_driver_desc_t * desc_ptr;
  95. JSList * parameters;
  96. JSList * set_parameters;
  97. };
  98. struct jackctl_internal {
  99. jack_driver_desc_t * desc_ptr;
  100. JSList * parameters;
  101. JSList * set_parameters;
  102. int refnum;
  103. };
  104. struct jackctl_parameter {
  105. const char * name;
  106. const char * short_description;
  107. const char * long_description;
  108. jackctl_param_type_t type;
  109. bool is_set;
  110. union jackctl_parameter_value * value_ptr;
  111. union jackctl_parameter_value * default_value_ptr;
  112. union jackctl_parameter_value value;
  113. union jackctl_parameter_value default_value;
  114. struct jackctl_driver * driver_ptr;
  115. char id;
  116. jack_driver_param_t * driver_parameter_ptr;
  117. jack_driver_param_constraint_desc_t * constraint_ptr;
  118. };
  119. static
  120. struct jackctl_parameter *
  121. jackctl_add_parameter (
  122. JSList ** parameters_list_ptr_ptr,
  123. char id,
  124. const char * name,
  125. const char * short_description,
  126. const char * long_description,
  127. jackctl_param_type_t type,
  128. union jackctl_parameter_value * value_ptr,
  129. union jackctl_parameter_value * default_value_ptr,
  130. union jackctl_parameter_value value,
  131. jack_driver_param_constraint_desc_t * constraint_ptr)
  132. {
  133. struct jackctl_parameter * parameter_ptr;
  134. parameter_ptr = (struct jackctl_parameter*)malloc (sizeof(struct jackctl_parameter));
  135. if (parameter_ptr == NULL) {
  136. jack_error ("Cannot allocate memory for jackctl_parameter structure.");
  137. goto fail;
  138. }
  139. parameter_ptr->name = name;
  140. parameter_ptr->short_description = short_description;
  141. parameter_ptr->long_description = long_description;
  142. parameter_ptr->type = type;
  143. parameter_ptr->is_set = false;
  144. if (value_ptr == NULL) {
  145. value_ptr = &parameter_ptr->value;
  146. }
  147. if (default_value_ptr == NULL) {
  148. default_value_ptr = &parameter_ptr->default_value;
  149. }
  150. parameter_ptr->value_ptr = value_ptr;
  151. parameter_ptr->default_value_ptr = default_value_ptr;
  152. *value_ptr = *default_value_ptr = value;
  153. parameter_ptr->driver_ptr = NULL;
  154. parameter_ptr->driver_parameter_ptr = NULL;
  155. parameter_ptr->id = id;
  156. parameter_ptr->constraint_ptr = constraint_ptr;
  157. *parameters_list_ptr_ptr = jack_slist_append (*parameters_list_ptr_ptr, parameter_ptr);
  158. return parameter_ptr;
  159. fail:
  160. return NULL;
  161. }
  162. static
  163. void
  164. jackctl_free_driver_parameters (
  165. struct jackctl_driver * driver_ptr)
  166. {
  167. JSList * next_node_ptr;
  168. while (driver_ptr->parameters) {
  169. next_node_ptr = driver_ptr->parameters->next;
  170. free (driver_ptr->parameters->data);
  171. free (driver_ptr->parameters);
  172. driver_ptr->parameters = next_node_ptr;
  173. }
  174. while (driver_ptr->set_parameters) {
  175. next_node_ptr = driver_ptr->set_parameters->next;
  176. free (driver_ptr->set_parameters->data);
  177. free (driver_ptr->set_parameters);
  178. driver_ptr->set_parameters = next_node_ptr;
  179. }
  180. }
  181. static
  182. bool
  183. jackctl_add_driver_parameters (
  184. struct jackctl_driver * driver_ptr)
  185. {
  186. uint32_t i;
  187. union jackctl_parameter_value jackctl_value;
  188. jackctl_param_type_t jackctl_type;
  189. struct jackctl_parameter * parameter_ptr;
  190. jack_driver_param_desc_t * descriptor_ptr;
  191. for (i = 0; i < driver_ptr->desc_ptr->nparams; i++) {
  192. descriptor_ptr = driver_ptr->desc_ptr->params + i;
  193. switch (descriptor_ptr->type) {
  194. case JackDriverParamInt:
  195. jackctl_type = JackParamInt;
  196. jackctl_value.i = descriptor_ptr->value.i;
  197. break;
  198. case JackDriverParamUInt:
  199. jackctl_type = JackParamUInt;
  200. jackctl_value.ui = descriptor_ptr->value.ui;
  201. break;
  202. case JackDriverParamChar:
  203. jackctl_type = JackParamChar;
  204. jackctl_value.c = descriptor_ptr->value.c;
  205. break;
  206. case JackDriverParamString:
  207. jackctl_type = JackParamString;
  208. strcpy (jackctl_value.str, descriptor_ptr->value.str);
  209. break;
  210. case JackDriverParamBool:
  211. jackctl_type = JackParamBool;
  212. jackctl_value.b = descriptor_ptr->value.i;
  213. break;
  214. default:
  215. jack_error ("unknown driver parameter type %i", (int)descriptor_ptr->type);
  216. assert (0);
  217. goto fail;
  218. }
  219. parameter_ptr = jackctl_add_parameter (
  220. &driver_ptr->parameters,
  221. descriptor_ptr->character,
  222. descriptor_ptr->name,
  223. descriptor_ptr->short_desc,
  224. descriptor_ptr->long_desc,
  225. jackctl_type,
  226. NULL,
  227. NULL,
  228. jackctl_value,
  229. descriptor_ptr->constraint);
  230. if (parameter_ptr == NULL) {
  231. goto fail;
  232. }
  233. parameter_ptr->driver_ptr = driver_ptr;
  234. }
  235. return true;
  236. fail:
  237. jackctl_free_driver_parameters (driver_ptr);
  238. return false;
  239. }
  240. static jack_driver_desc_t *
  241. jack_drivers_get_descriptor (JSList * drivers, const char * sofile)
  242. {
  243. jack_driver_desc_t * descriptor, * other_descriptor;
  244. JackDriverDescFunction so_get_descriptor;
  245. JSList * node;
  246. void * dlhandle;
  247. char * filename;
  248. const char * dlerr;
  249. int err;
  250. char* driver_dir;
  251. if ((driver_dir = getenv ("JACK_DRIVER_DIR")) == 0) {
  252. driver_dir = ADDON_DIR;
  253. }
  254. filename = malloc (strlen (driver_dir) + 1 + strlen (sofile) + 1);
  255. sprintf (filename, "%s/%s", driver_dir, sofile);
  256. // if (verbose) {
  257. // jack_info ("getting driver descriptor from %s", filename);
  258. // }
  259. if ((dlhandle = dlopen (filename, RTLD_NOW | RTLD_GLOBAL)) == NULL) {
  260. jack_error ("could not open driver .so '%s': %s\n", filename, dlerror ());
  261. free (filename);
  262. return NULL;
  263. }
  264. so_get_descriptor = (JackDriverDescFunction)
  265. dlsym (dlhandle, "driver_get_descriptor");
  266. if ((dlerr = dlerror ()) != NULL) {
  267. jack_error ("%s", dlerr);
  268. dlclose (dlhandle);
  269. free (filename);
  270. return NULL;
  271. }
  272. if ((descriptor = so_get_descriptor ()) == NULL) {
  273. jack_error ("driver from '%s' returned NULL descriptor\n", filename);
  274. dlclose (dlhandle);
  275. free (filename);
  276. return NULL;
  277. }
  278. if ((err = dlclose (dlhandle)) != 0) {
  279. jack_error ("error closing driver .so '%s': %s\n", filename, dlerror ());
  280. }
  281. /* check it doesn't exist already */
  282. for (node = drivers; node; node = jack_slist_next (node)) {
  283. other_descriptor = (jack_driver_desc_t*)node->data;
  284. if (strcmp (descriptor->name, other_descriptor->name) == 0) {
  285. jack_error ("the drivers in '%s' and '%s' both have the name '%s'; using the first\n",
  286. other_descriptor->file, filename, other_descriptor->name);
  287. /* FIXME: delete the descriptor */
  288. free (filename);
  289. return NULL;
  290. }
  291. }
  292. snprintf (descriptor->file, sizeof(descriptor->file), "%s", filename);
  293. free (filename);
  294. return descriptor;
  295. }
  296. static JSList *
  297. jack_drivers_load ()
  298. {
  299. struct dirent * dir_entry;
  300. DIR * dir_stream;
  301. const char * ptr;
  302. int err;
  303. JSList * driver_list = NULL;
  304. jack_driver_desc_t * desc;
  305. char* driver_dir;
  306. if ((driver_dir = getenv ("JACK_DRIVER_DIR")) == 0) {
  307. driver_dir = ADDON_DIR;
  308. }
  309. /* search through the driver_dir and add get descriptors
  310. from the .so files in it */
  311. dir_stream = opendir (driver_dir);
  312. if (!dir_stream) {
  313. jack_error ("could not open driver directory %s: %s\n",
  314. driver_dir, strerror (errno));
  315. return NULL;
  316. }
  317. while ( (dir_entry = readdir (dir_stream)) ) {
  318. /* check the filename is of the right format */
  319. if (strncmp ("jack_", dir_entry->d_name, 5) != 0) {
  320. continue;
  321. }
  322. ptr = strrchr (dir_entry->d_name, '.');
  323. if (!ptr) {
  324. continue;
  325. }
  326. ptr++;
  327. if (strncmp ("so", ptr, 2) != 0) {
  328. continue;
  329. }
  330. desc = jack_drivers_get_descriptor (drivers, dir_entry->d_name);
  331. if (desc) {
  332. driver_list = jack_slist_append (driver_list, desc);
  333. }
  334. }
  335. err = closedir (dir_stream);
  336. if (err) {
  337. jack_error ("error closing driver directory %s: %s\n",
  338. driver_dir, strerror (errno));
  339. }
  340. if (!driver_list) {
  341. jack_error ("could not find any drivers in %s!\n", driver_dir);
  342. return NULL;
  343. }
  344. return driver_list;
  345. }
  346. static void
  347. jack_cleanup_files (const char *server_name)
  348. {
  349. DIR *dir;
  350. struct dirent *dirent;
  351. char dir_name[PATH_MAX + 1] = "";
  352. jack_server_dir (server_name, dir_name);
  353. /* On termination, we remove all files that jackd creates so
  354. * subsequent attempts to start jackd will not believe that an
  355. * instance is already running. If the server crashes or is
  356. * terminated with SIGKILL, this is not possible. So, cleanup
  357. * is also attempted when jackd starts.
  358. *
  359. * There are several tricky issues. First, the previous JACK
  360. * server may have run for a different user ID, so its files
  361. * may be inaccessible. This is handled by using a separate
  362. * JACK_TMP_DIR subdirectory for each user. Second, there may
  363. * be other servers running with different names. Each gets
  364. * its own subdirectory within the per-user directory. The
  365. * current process has already registered as `server_name', so
  366. * we know there is no other server actively using that name.
  367. */
  368. /* nothing to do if the server directory does not exist */
  369. if ((dir = opendir (dir_name)) == NULL) {
  370. return;
  371. }
  372. /* unlink all the files in this directory, they are mine */
  373. while ((dirent = readdir (dir)) != NULL) {
  374. char fullpath[PATH_MAX + 1];
  375. if ((strcmp (dirent->d_name, ".") == 0)
  376. || (strcmp (dirent->d_name, "..") == 0)) {
  377. continue;
  378. }
  379. snprintf (fullpath, sizeof(fullpath), "%s/%s",
  380. dir_name, dirent->d_name);
  381. if (unlink (fullpath)) {
  382. jack_error ("cannot unlink `%s' (%s)", fullpath,
  383. strerror (errno));
  384. }
  385. }
  386. closedir (dir);
  387. /* now, delete the per-server subdirectory, itself */
  388. if (rmdir (dir_name)) {
  389. jack_error ("cannot remove `%s' (%s)", dir_name,
  390. strerror (errno));
  391. }
  392. /* finally, delete the per-user subdirectory, if empty */
  393. if (rmdir (jack_user_dir ())) {
  394. if (errno != ENOTEMPTY) {
  395. jack_error ("cannot remove `%s' (%s)",
  396. jack_user_dir (), strerror (errno));
  397. }
  398. }
  399. }
  400. static int
  401. jackctl_drivers_load (
  402. struct jackctl_server * server_ptr)
  403. {
  404. struct jackctl_driver * driver_ptr;
  405. JSList *node_ptr;
  406. JSList *descriptor_node_ptr;
  407. descriptor_node_ptr = jack_drivers_load ();
  408. if (descriptor_node_ptr == NULL) {
  409. jack_error ("could not find any drivers in driver directory!");
  410. return false;
  411. }
  412. while (descriptor_node_ptr != NULL) {
  413. driver_ptr = (struct jackctl_driver*)malloc (sizeof(struct jackctl_driver));
  414. if (driver_ptr == NULL) {
  415. jack_error ("memory allocation of jackctl_driver structure failed.");
  416. goto next;
  417. }
  418. driver_ptr->desc_ptr = (jack_driver_desc_t*)descriptor_node_ptr->data;
  419. driver_ptr->parameters = NULL;
  420. driver_ptr->set_parameters = NULL;
  421. if (!jackctl_add_driver_parameters (driver_ptr)) {
  422. assert (driver_ptr->parameters == NULL);
  423. free (driver_ptr);
  424. goto next;
  425. }
  426. server_ptr->drivers = jack_slist_append (server_ptr->drivers, driver_ptr);
  427. next:
  428. node_ptr = descriptor_node_ptr;
  429. descriptor_node_ptr = descriptor_node_ptr->next;
  430. free (node_ptr);
  431. }
  432. return true;
  433. }
  434. static
  435. void
  436. jackctl_server_free_drivers (
  437. struct jackctl_server * server_ptr)
  438. {
  439. JSList * next_node_ptr;
  440. struct jackctl_driver * driver_ptr;
  441. while (server_ptr->drivers) {
  442. next_node_ptr = server_ptr->drivers->next;
  443. driver_ptr = (struct jackctl_driver*)server_ptr->drivers->data;
  444. jackctl_free_driver_parameters (driver_ptr);
  445. free (driver_ptr->desc_ptr->params);
  446. free (driver_ptr->desc_ptr);
  447. free (driver_ptr);
  448. free (server_ptr->drivers);
  449. server_ptr->drivers = next_node_ptr;
  450. }
  451. }
  452. static int
  453. jackctl_internals_load (
  454. struct jackctl_server * server_ptr)
  455. {
  456. struct jackctl_internal * internal_ptr;
  457. JSList *node_ptr;
  458. JSList *descriptor_node_ptr = NULL;
  459. //XXX: jack1 doesnt support internals enumeration.
  460. //descriptor_node_ptr = jack_internals_load(NULL);
  461. if (descriptor_node_ptr == NULL) {
  462. return false;
  463. }
  464. while (descriptor_node_ptr != NULL) {
  465. internal_ptr = (struct jackctl_internal*)malloc (sizeof(struct jackctl_internal));
  466. if (internal_ptr == NULL) {
  467. jack_error ("memory allocation of jackctl_driver structure failed.");
  468. goto next;
  469. }
  470. internal_ptr->desc_ptr = (jack_driver_desc_t*)descriptor_node_ptr->data;
  471. internal_ptr->parameters = NULL;
  472. internal_ptr->set_parameters = NULL;
  473. if (!jackctl_add_driver_parameters ((struct jackctl_driver*)internal_ptr)) {
  474. assert (internal_ptr->parameters == NULL);
  475. free (internal_ptr);
  476. goto next;
  477. }
  478. server_ptr->internals = jack_slist_append (server_ptr->internals, internal_ptr);
  479. next:
  480. node_ptr = descriptor_node_ptr;
  481. descriptor_node_ptr = descriptor_node_ptr->next;
  482. free (node_ptr);
  483. }
  484. return true;
  485. }
  486. static
  487. void
  488. jackctl_server_free_internals (
  489. struct jackctl_server * server_ptr)
  490. {
  491. JSList * next_node_ptr;
  492. struct jackctl_internal * internal_ptr;
  493. while (server_ptr->internals) {
  494. next_node_ptr = server_ptr->internals->next;
  495. internal_ptr = (struct jackctl_internal*)server_ptr->internals->data;
  496. jackctl_free_driver_parameters ((struct jackctl_driver*)internal_ptr);
  497. free (internal_ptr->desc_ptr->params);
  498. free (internal_ptr->desc_ptr);
  499. free (internal_ptr);
  500. free (server_ptr->internals);
  501. server_ptr->internals = next_node_ptr;
  502. }
  503. }
  504. static
  505. void
  506. jackctl_server_free_parameters (
  507. struct jackctl_server * server_ptr)
  508. {
  509. JSList * next_node_ptr;
  510. while (server_ptr->parameters) {
  511. next_node_ptr = server_ptr->parameters->next;
  512. free (server_ptr->parameters->data);
  513. free (server_ptr->parameters);
  514. server_ptr->parameters = next_node_ptr;
  515. }
  516. }
  517. #ifdef WIN32
  518. static HANDLE waitEvent;
  519. static void do_nothing_handler (int signum)
  520. {
  521. printf ("jack main caught signal %d\n", signum);
  522. (void)signal (SIGINT, SIG_DFL);
  523. SetEvent (waitEvent);
  524. }
  525. sigset_t
  526. jackctl_setup_signals (
  527. unsigned int flags)
  528. {
  529. if ((waitEvent = CreateEvent (NULL, FALSE, FALSE, NULL)) == NULL) {
  530. jack_error ("CreateEvent fails err = %ld", GetLastError ());
  531. return 0;
  532. }
  533. (void)signal (SIGINT, do_nothing_handler);
  534. (void)signal (SIGABRT, do_nothing_handler);
  535. (void)signal (SIGTERM, do_nothing_handler);
  536. return (sigset_t)waitEvent;
  537. }
  538. void jackctl_wait_signals (sigset_t signals)
  539. {
  540. if (WaitForSingleObject (waitEvent, INFINITE) != WAIT_OBJECT_0) {
  541. jack_error ("WaitForSingleObject fails err = %ld", GetLastError ());
  542. }
  543. }
  544. #else
  545. static
  546. void
  547. do_nothing_handler (int sig)
  548. {
  549. /* this is used by the child (active) process, but it never
  550. gets called unless we are already shutting down after
  551. another signal.
  552. */
  553. char buf[64];
  554. snprintf (buf, sizeof(buf), "received signal %d during shutdown (ignored)\n", sig);
  555. }
  556. sigset_t
  557. jackctl_setup_signals (
  558. unsigned int flags)
  559. {
  560. sigset_t signals;
  561. sigset_t allsignals;
  562. struct sigaction action;
  563. int i;
  564. /* ensure that we are in our own process group so that
  565. kill (SIG, -pgrp) does the right thing.
  566. */
  567. setsid ();
  568. pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
  569. /* what's this for?
  570. POSIX says that signals are delivered like this:
  571. * if a thread has blocked that signal, it is not
  572. a candidate to receive the signal.
  573. * of all threads not blocking the signal, pick
  574. one at random, and deliver the signal.
  575. this means that a simple-minded multi-threaded program can
  576. expect to get POSIX signals delivered randomly to any one
  577. of its threads,
  578. here, we block all signals that we think we might receive
  579. and want to catch. all "child" threads will inherit this
  580. setting. if we create a thread that calls sigwait() on the
  581. same set of signals, implicitly unblocking all those
  582. signals. any of those signals that are delivered to the
  583. process will be delivered to that thread, and that thread
  584. alone. this makes cleanup for a signal-driven exit much
  585. easier, since we know which thread is doing it and more
  586. importantly, we are free to call async-unsafe functions,
  587. because the code is executing in normal thread context
  588. after a return from sigwait().
  589. */
  590. sigemptyset (&signals);
  591. sigaddset (&signals, SIGHUP);
  592. sigaddset (&signals, SIGINT);
  593. sigaddset (&signals, SIGQUIT);
  594. sigaddset (&signals, SIGPIPE);
  595. sigaddset (&signals, SIGTERM);
  596. sigaddset (&signals, SIGUSR1);
  597. sigaddset (&signals, SIGUSR2);
  598. /* all child threads will inherit this mask unless they
  599. * explicitly reset it
  600. */
  601. pthread_sigmask (SIG_BLOCK, &signals, 0);
  602. /* install a do-nothing handler because otherwise pthreads
  603. behaviour is undefined when we enter sigwait.
  604. */
  605. sigfillset (&allsignals);
  606. action.sa_handler = do_nothing_handler;
  607. action.sa_mask = allsignals;
  608. action.sa_flags = SA_RESTART | SA_RESETHAND;
  609. for (i = 1; i < NSIG; i++) {
  610. if (sigismember (&signals, i)) {
  611. sigaction (i, &action, 0);
  612. }
  613. }
  614. return signals;
  615. }
  616. void
  617. jackctl_wait_signals (sigset_t signals)
  618. {
  619. int sig;
  620. bool waiting = true;
  621. while (waiting) {
  622. #if defined(sun) && !defined(__sun__) // SUN compiler only, to check
  623. sigwait (&signals);
  624. #else
  625. sigwait (&signals, &sig);
  626. #endif
  627. fprintf (stderr, "jack main caught signal %d\n", sig);
  628. switch (sig) {
  629. case SIGUSR1:
  630. //jack_dump_configuration(engine, 1);
  631. break;
  632. case SIGUSR2:
  633. // driver exit
  634. waiting = false;
  635. break;
  636. case SIGTTOU:
  637. break;
  638. default:
  639. waiting = false;
  640. break;
  641. }
  642. }
  643. if (sig != SIGSEGV) {
  644. // unblock signals so we can see them during shutdown.
  645. // this will help prod developers not to lose sight of
  646. // bugs that cause segfaults etc. during shutdown.
  647. sigprocmask (SIG_UNBLOCK, &signals, 0);
  648. }
  649. }
  650. #endif
  651. static sigset_t
  652. jackctl_block_signals ()
  653. {
  654. sigset_t signals;
  655. sigset_t oldsignals;
  656. sigemptyset (&signals);
  657. sigaddset (&signals, SIGHUP);
  658. sigaddset (&signals, SIGINT);
  659. sigaddset (&signals, SIGQUIT);
  660. sigaddset (&signals, SIGPIPE);
  661. sigaddset (&signals, SIGTERM);
  662. sigaddset (&signals, SIGUSR1);
  663. sigaddset (&signals, SIGUSR2);
  664. pthread_sigmask (SIG_BLOCK, &signals, &oldsignals);
  665. return oldsignals;
  666. }
  667. static void
  668. jackctl_unblock_signals (sigset_t oldsignals)
  669. {
  670. pthread_sigmask (SIG_SETMASK, &oldsignals, 0);
  671. }
  672. static
  673. jack_driver_param_constraint_desc_t *
  674. get_realtime_priority_constraint ()
  675. {
  676. #ifndef __OpenBSD__
  677. jack_driver_param_constraint_desc_t * constraint_ptr;
  678. int max = sched_get_priority_max (SCHED_FIFO);
  679. int min = sched_get_priority_min (SCHED_FIFO);
  680. //jack_info("realtime priority range is (%d,%d)", min, max);
  681. constraint_ptr = (jack_driver_param_constraint_desc_t*)calloc (1, sizeof(jack_driver_param_value_enum_t));
  682. if (constraint_ptr == NULL) {
  683. jack_error ("Cannot allocate memory for jack_driver_param_constraint_desc_t structure.");
  684. return NULL;
  685. }
  686. constraint_ptr->flags = JACK_CONSTRAINT_FLAG_RANGE;
  687. constraint_ptr->constraint.range.min.i = min;
  688. constraint_ptr->constraint.range.max.i = max;
  689. return constraint_ptr;
  690. #else
  691. return NULL;
  692. #endif
  693. }
  694. jackctl_server_t * jackctl_server_create (
  695. bool (* on_device_acquire)(const char * device_name),
  696. void (* on_device_release)(const char * device_name))
  697. {
  698. struct jackctl_server * server_ptr;
  699. union jackctl_parameter_value value;
  700. server_ptr = (struct jackctl_server*)malloc (sizeof(struct jackctl_server));
  701. if (server_ptr == NULL) {
  702. jack_error ("Cannot allocate memory for jackctl_server structure.");
  703. goto fail;
  704. }
  705. server_ptr->drivers = NULL;
  706. server_ptr->internals = NULL;
  707. server_ptr->parameters = NULL;
  708. server_ptr->engine = NULL;
  709. strcpy (value.str, jack_default_server_name () );
  710. if (jackctl_add_parameter (
  711. &server_ptr->parameters,
  712. 'n',
  713. "name",
  714. "Server name to use.",
  715. "",
  716. JackParamString,
  717. &server_ptr->name,
  718. &server_ptr->default_name,
  719. value, NULL) == NULL) {
  720. goto fail_free_parameters;
  721. }
  722. value.b = false;
  723. if (jackctl_add_parameter (
  724. &server_ptr->parameters,
  725. 'R',
  726. "realtime",
  727. "Whether to use realtime mode.",
  728. "Use realtime scheduling. This is needed for reliable low-latency performance. On most systems, it requires JACK to run with special scheduler and memory allocation privileges, which may be obtained in several ways. On Linux you should use PAM.",
  729. JackParamBool,
  730. &server_ptr->realtime,
  731. &server_ptr->default_realtime,
  732. value, NULL) == NULL) {
  733. goto fail_free_parameters;
  734. }
  735. value.i = 10;
  736. if (jackctl_add_parameter (
  737. &server_ptr->parameters,
  738. 'P',
  739. "realtime-priority",
  740. "Scheduler priority when running in realtime mode.",
  741. "",
  742. JackParamInt,
  743. &server_ptr->realtime_priority,
  744. &server_ptr->default_realtime_priority,
  745. value,
  746. get_realtime_priority_constraint ()
  747. ) == NULL) {
  748. goto fail_free_parameters;
  749. }
  750. value.b = false;
  751. if (jackctl_add_parameter (
  752. &server_ptr->parameters,
  753. 'T',
  754. "temporary",
  755. "Exit once all clients have closed their connections.",
  756. "",
  757. JackParamBool,
  758. &server_ptr->temporary,
  759. &server_ptr->default_temporary,
  760. value, NULL) == NULL) {
  761. goto fail_free_parameters;
  762. }
  763. value.b = false;
  764. if (jackctl_add_parameter (
  765. &server_ptr->parameters,
  766. 'v',
  767. "verbose",
  768. "Verbose mode.",
  769. "",
  770. JackParamBool,
  771. &server_ptr->verbose,
  772. &server_ptr->default_verbose,
  773. value, NULL) == NULL) {
  774. goto fail_free_parameters;
  775. }
  776. value.i = 0;
  777. if (jackctl_add_parameter (
  778. &server_ptr->parameters,
  779. 't',
  780. "client-timeout",
  781. "Client timeout limit in milliseconds.",
  782. "",
  783. JackParamInt,
  784. &server_ptr->client_timeout,
  785. &server_ptr->default_client_timeout,
  786. value, NULL) == NULL) {
  787. goto fail_free_parameters;
  788. }
  789. value.ui = 0;
  790. if (jackctl_add_parameter (
  791. &server_ptr->parameters,
  792. 'c',
  793. "clock-source",
  794. "Clocksource type : c(ycle) | h(pet) | s(ystem).",
  795. "",
  796. JackParamUInt,
  797. &server_ptr->clock_source,
  798. &server_ptr->default_clock_source,
  799. value, NULL) == NULL) {
  800. goto fail_free_parameters;
  801. }
  802. value.ui = 128;
  803. if (jackctl_add_parameter (
  804. &server_ptr->parameters,
  805. 'p',
  806. "port-max",
  807. "Maximum number of ports.",
  808. "",
  809. JackParamUInt,
  810. &server_ptr->port_max,
  811. &server_ptr->default_port_max,
  812. value, NULL) == NULL) {
  813. goto fail_free_parameters;
  814. }
  815. value.b = false;
  816. if (jackctl_add_parameter (
  817. &server_ptr->parameters,
  818. '\0',
  819. "replace-registry",
  820. "Replace shared memory registry.",
  821. "",
  822. JackParamBool,
  823. &server_ptr->replace_registry,
  824. &server_ptr->default_replace_registry,
  825. value, NULL) == NULL) {
  826. goto fail_free_parameters;
  827. }
  828. value.b = false;
  829. if (jackctl_add_parameter (
  830. &server_ptr->parameters,
  831. 'm',
  832. "mlock",
  833. "Use mlock.",
  834. "",
  835. JackParamBool,
  836. &server_ptr->do_mlock,
  837. &server_ptr->default_do_mlock,
  838. value, NULL) == NULL) {
  839. goto fail_free_parameters;
  840. }
  841. value.b = false;
  842. if (jackctl_add_parameter (
  843. &server_ptr->parameters,
  844. 'u',
  845. "unlock",
  846. "munlock memory for big libraries",
  847. "",
  848. JackParamBool,
  849. &server_ptr->do_unlock,
  850. &server_ptr->default_do_unlock,
  851. value, NULL) == NULL) {
  852. goto fail_free_parameters;
  853. }
  854. value.b = false;
  855. if (jackctl_add_parameter (
  856. &server_ptr->parameters,
  857. 'Z',
  858. "nozombies",
  859. "dont zombifiy offending clients",
  860. "",
  861. JackParamBool,
  862. &server_ptr->nozombies,
  863. &server_ptr->default_nozombies,
  864. value, NULL) == NULL) {
  865. goto fail_free_parameters;
  866. }
  867. value.ui = 0;
  868. if (jackctl_add_parameter (
  869. &server_ptr->parameters,
  870. 'C',
  871. "timeout-threshold",
  872. "threshold for suspending processing",
  873. "",
  874. JackParamUInt,
  875. &server_ptr->timothres,
  876. &server_ptr->default_timothres,
  877. value, NULL) == NULL) {
  878. goto fail_free_parameters;
  879. }
  880. //TODO: need
  881. //JackServerGlobals::on_device_acquire = on_device_acquire;
  882. //JackServerGlobals::on_device_release = on_device_release;
  883. if (!jackctl_drivers_load (server_ptr)) {
  884. goto fail_free_parameters;
  885. }
  886. /* Allowed to fail */
  887. jackctl_internals_load (server_ptr);
  888. return server_ptr;
  889. fail_free_parameters:
  890. jackctl_server_free_parameters (server_ptr);
  891. free (server_ptr);
  892. fail:
  893. return NULL;
  894. }
  895. void jackctl_server_destroy (jackctl_server_t *server_ptr)
  896. {
  897. jackctl_server_free_drivers (server_ptr);
  898. jackctl_server_free_internals (server_ptr);
  899. jackctl_server_free_parameters (server_ptr);
  900. free (server_ptr);
  901. }
  902. const JSList * jackctl_server_get_drivers_list (jackctl_server_t *server_ptr)
  903. {
  904. return server_ptr->drivers;
  905. }
  906. bool jackctl_server_stop (jackctl_server_t *server_ptr)
  907. {
  908. //jack_engine_driver_exit (server_ptr->engine);
  909. jack_engine_delete (server_ptr->engine);
  910. /* clean up shared memory and files from this server instance */
  911. //jack_log("cleaning up shared memory");
  912. jack_cleanup_shm ();
  913. //jack_log("cleaning up files");
  914. jack_cleanup_files (server_ptr->name.str);
  915. //jack_log("unregistering server `%s'", server_ptr->name.str);
  916. jack_unregister_server (server_ptr->name.str);
  917. server_ptr->engine = NULL;
  918. return true;
  919. }
  920. const JSList * jackctl_server_get_parameters (jackctl_server_t *server_ptr)
  921. {
  922. return server_ptr->parameters;
  923. }
  924. bool
  925. jackctl_server_start (
  926. jackctl_server_t *server_ptr,
  927. jackctl_driver_t *driver_ptr)
  928. {
  929. int rc;
  930. sigset_t oldsignals;
  931. // TODO:
  932. int frame_time_offset = 0;
  933. rc = jack_register_server (server_ptr->name.str, server_ptr->replace_registry.b);
  934. switch (rc) {
  935. case EEXIST:
  936. jack_error ("`%s' server already active", server_ptr->name.str);
  937. goto fail;
  938. case ENOSPC:
  939. jack_error ("too many servers already active");
  940. goto fail;
  941. case ENOMEM:
  942. jack_error ("no access to shm registry");
  943. goto fail;
  944. }
  945. //jack_log("server `%s' registered", server_ptr->name.str);
  946. /* clean up shared memory and files from any previous
  947. * instance of this server name */
  948. jack_cleanup_shm ();
  949. jack_cleanup_files (server_ptr->name.str);
  950. if (!server_ptr->realtime.b && server_ptr->client_timeout.i == 0) {
  951. server_ptr->client_timeout.i = 500; /* 0.5 sec; usable when non realtime. */
  952. }
  953. oldsignals = jackctl_block_signals ();
  954. if ((server_ptr->engine = jack_engine_new (server_ptr->realtime.b, server_ptr->realtime_priority.i,
  955. server_ptr->do_mlock.b, server_ptr->do_unlock.b, server_ptr->name.str,
  956. server_ptr->temporary.b, server_ptr->verbose.b, server_ptr->client_timeout.i,
  957. server_ptr->port_max.i, getpid (), frame_time_offset,
  958. server_ptr->nozombies.b, server_ptr->timothres.ui, drivers)) == 0) {
  959. jack_error ("cannot create engine");
  960. goto fail_unregister;
  961. }
  962. if (jack_engine_load_driver (server_ptr->engine, driver_ptr->desc_ptr, driver_ptr->set_parameters)) {
  963. jack_error ("cannot load driver module %s", driver_ptr->desc_ptr->name);
  964. goto fail_delete;
  965. }
  966. if (server_ptr->engine->driver->start (server_ptr->engine->driver) != 0) {
  967. jack_error ("cannot start driver");
  968. goto fail_close;
  969. }
  970. jackctl_unblock_signals ( oldsignals );
  971. return true;
  972. fail_close:
  973. fail_delete:
  974. jack_engine_delete (server_ptr->engine);
  975. server_ptr->engine = NULL;
  976. fail_unregister:
  977. //jack_log("cleaning up shared memory");
  978. jack_cleanup_shm ();
  979. //jack_log("cleaning up files");
  980. jack_cleanup_files (server_ptr->name.str);
  981. //jack_log("unregistering server `%s'", server_ptr->name.str);
  982. jack_unregister_server (server_ptr->name.str);
  983. jackctl_unblock_signals ( oldsignals );
  984. fail:
  985. return false;
  986. }
  987. const char * jackctl_driver_get_name (jackctl_driver_t *driver_ptr)
  988. {
  989. return driver_ptr->desc_ptr->name;
  990. }
  991. const JSList * jackctl_driver_get_parameters (jackctl_driver_t *driver_ptr)
  992. {
  993. return driver_ptr->parameters;
  994. }
  995. jack_driver_desc_t * jackctl_driver_get_desc (jackctl_driver_t *driver_ptr)
  996. {
  997. return driver_ptr->desc_ptr;
  998. }
  999. const char * jackctl_parameter_get_name (jackctl_parameter_t *parameter_ptr)
  1000. {
  1001. return parameter_ptr->name;
  1002. }
  1003. const char * jackctl_parameter_get_short_description (jackctl_parameter_t *parameter_ptr)
  1004. {
  1005. return parameter_ptr->short_description;
  1006. }
  1007. const char * jackctl_parameter_get_long_description (jackctl_parameter_t *parameter_ptr)
  1008. {
  1009. return parameter_ptr->long_description;
  1010. }
  1011. bool jackctl_parameter_has_range_constraint (jackctl_parameter_t *parameter_ptr)
  1012. {
  1013. return parameter_ptr->constraint_ptr != NULL && (parameter_ptr->constraint_ptr->flags & JACK_CONSTRAINT_FLAG_RANGE) != 0;
  1014. }
  1015. bool jackctl_parameter_has_enum_constraint (jackctl_parameter_t *parameter_ptr)
  1016. {
  1017. return parameter_ptr->constraint_ptr != NULL && (parameter_ptr->constraint_ptr->flags & JACK_CONSTRAINT_FLAG_RANGE) == 0;
  1018. }
  1019. uint32_t jackctl_parameter_get_enum_constraints_count (jackctl_parameter_t *parameter_ptr)
  1020. {
  1021. if (!jackctl_parameter_has_enum_constraint (parameter_ptr)) {
  1022. return 0;
  1023. }
  1024. return parameter_ptr->constraint_ptr->constraint.enumeration.count;
  1025. }
  1026. union jackctl_parameter_value jackctl_parameter_get_enum_constraint_value (jackctl_parameter_t *parameter_ptr, uint32_t index)
  1027. {
  1028. jack_driver_param_value_t * value_ptr;
  1029. union jackctl_parameter_value jackctl_value;
  1030. value_ptr = &parameter_ptr->constraint_ptr->constraint.enumeration.possible_values_array[index].value;
  1031. switch (parameter_ptr->type) {
  1032. case JackParamInt:
  1033. jackctl_value.i = value_ptr->i;
  1034. break;
  1035. case JackParamUInt:
  1036. jackctl_value.ui = value_ptr->ui;
  1037. break;
  1038. case JackParamChar:
  1039. jackctl_value.c = value_ptr->c;
  1040. break;
  1041. case JackParamString:
  1042. strcpy (jackctl_value.str, value_ptr->str);
  1043. break;
  1044. default:
  1045. jack_error ("bad driver parameter type %i (enum constraint)", (int)parameter_ptr->type);
  1046. assert (0);
  1047. }
  1048. return jackctl_value;
  1049. }
  1050. const char * jackctl_parameter_get_enum_constraint_description (jackctl_parameter_t *parameter_ptr, uint32_t index)
  1051. {
  1052. return parameter_ptr->constraint_ptr->constraint.enumeration.possible_values_array[index].short_desc;
  1053. }
  1054. void jackctl_parameter_get_range_constraint (jackctl_parameter_t *parameter_ptr, union jackctl_parameter_value * min_ptr, union jackctl_parameter_value * max_ptr)
  1055. {
  1056. switch (parameter_ptr->type) {
  1057. case JackParamInt:
  1058. min_ptr->i = parameter_ptr->constraint_ptr->constraint.range.min.i;
  1059. max_ptr->i = parameter_ptr->constraint_ptr->constraint.range.max.i;
  1060. return;
  1061. case JackParamUInt:
  1062. min_ptr->ui = parameter_ptr->constraint_ptr->constraint.range.min.ui;
  1063. max_ptr->ui = parameter_ptr->constraint_ptr->constraint.range.max.ui;
  1064. return;
  1065. default:
  1066. jack_error ("bad driver parameter type %i (range constraint)", (int)parameter_ptr->type);
  1067. assert (0);
  1068. }
  1069. }
  1070. bool jackctl_parameter_constraint_is_strict (jackctl_parameter_t * parameter_ptr)
  1071. {
  1072. return parameter_ptr->constraint_ptr != NULL && (parameter_ptr->constraint_ptr->flags & JACK_CONSTRAINT_FLAG_STRICT) != 0;
  1073. }
  1074. bool jackctl_parameter_constraint_is_fake_value (jackctl_parameter_t * parameter_ptr)
  1075. {
  1076. return parameter_ptr->constraint_ptr != NULL && (parameter_ptr->constraint_ptr->flags & JACK_CONSTRAINT_FLAG_FAKE_VALUE) != 0;
  1077. }
  1078. jackctl_param_type_t jackctl_parameter_get_type (jackctl_parameter_t *parameter_ptr)
  1079. {
  1080. return parameter_ptr->type;
  1081. }
  1082. char jackctl_parameter_get_id (jackctl_parameter_t * parameter_ptr)
  1083. {
  1084. return parameter_ptr->id;
  1085. }
  1086. bool jackctl_parameter_is_set (jackctl_parameter_t *parameter_ptr)
  1087. {
  1088. return parameter_ptr->is_set;
  1089. }
  1090. union jackctl_parameter_value jackctl_parameter_get_value (jackctl_parameter_t *parameter_ptr)
  1091. {
  1092. return *(parameter_ptr->value_ptr);
  1093. }
  1094. bool jackctl_parameter_reset (jackctl_parameter_t *parameter_ptr)
  1095. {
  1096. if (!parameter_ptr->is_set) {
  1097. return true;
  1098. }
  1099. parameter_ptr->is_set = false;
  1100. *parameter_ptr->value_ptr = *parameter_ptr->default_value_ptr;
  1101. return true;
  1102. }
  1103. bool jackctl_parameter_set_value (jackctl_parameter_t *parameter_ptr, const union jackctl_parameter_value * value_ptr)
  1104. {
  1105. bool new_driver_parameter;
  1106. /* for driver parameters, set the parameter by adding jack_driver_param_t in the set_parameters list */
  1107. if (parameter_ptr->driver_ptr != NULL) {
  1108. /* jack_info("setting driver parameter %p ...", parameter_ptr); */
  1109. new_driver_parameter = parameter_ptr->driver_parameter_ptr == NULL;
  1110. if (new_driver_parameter) {
  1111. /* jack_info("new driver parameter..."); */
  1112. parameter_ptr->driver_parameter_ptr = (jack_driver_param_t*)malloc (sizeof(jack_driver_param_t));
  1113. if (parameter_ptr->driver_parameter_ptr == NULL) {
  1114. jack_error ("Allocation of jack_driver_param_t structure failed");
  1115. return false;
  1116. }
  1117. parameter_ptr->driver_parameter_ptr->character = parameter_ptr->id;
  1118. parameter_ptr->driver_ptr->set_parameters = jack_slist_append (parameter_ptr->driver_ptr->set_parameters, parameter_ptr->driver_parameter_ptr);
  1119. }
  1120. switch (parameter_ptr->type) {
  1121. case JackParamInt:
  1122. parameter_ptr->driver_parameter_ptr->value.i = value_ptr->i;
  1123. break;
  1124. case JackParamUInt:
  1125. parameter_ptr->driver_parameter_ptr->value.ui = value_ptr->ui;
  1126. break;
  1127. case JackParamChar:
  1128. parameter_ptr->driver_parameter_ptr->value.c = value_ptr->c;
  1129. break;
  1130. case JackParamString:
  1131. strcpy (parameter_ptr->driver_parameter_ptr->value.str, value_ptr->str);
  1132. break;
  1133. case JackParamBool:
  1134. parameter_ptr->driver_parameter_ptr->value.i = value_ptr->b;
  1135. break;
  1136. default:
  1137. jack_error ("unknown parameter type %i", (int)parameter_ptr->type);
  1138. assert (0);
  1139. if (new_driver_parameter) {
  1140. parameter_ptr->driver_ptr->set_parameters = jack_slist_remove (parameter_ptr->driver_ptr->set_parameters, parameter_ptr->driver_parameter_ptr);
  1141. }
  1142. return false;
  1143. }
  1144. }
  1145. parameter_ptr->is_set = true;
  1146. *parameter_ptr->value_ptr = *value_ptr;
  1147. return true;
  1148. }
  1149. union jackctl_parameter_value jackctl_parameter_get_default_value (jackctl_parameter_t *parameter_ptr)
  1150. {
  1151. return *(parameter_ptr->default_value_ptr);
  1152. }
  1153. // Internals clients
  1154. const JSList * jackctl_server_get_internals_list (jackctl_server_t *server_ptr)
  1155. {
  1156. return server_ptr->internals;
  1157. }
  1158. const char * jackctl_internal_get_name (jackctl_internal_t *internal_ptr)
  1159. {
  1160. return internal_ptr->desc_ptr->name;
  1161. }
  1162. const JSList * jackctl_internal_get_parameters (jackctl_internal_t *internal_ptr)
  1163. {
  1164. return internal_ptr->parameters;
  1165. }
  1166. bool jackctl_server_load_internal (
  1167. jackctl_server_t * server_ptr,
  1168. jackctl_internal_t * internal)
  1169. {
  1170. return false;
  1171. }
  1172. bool jackctl_server_unload_internal (
  1173. jackctl_server_t * server_ptr,
  1174. jackctl_internal_t * internal)
  1175. {
  1176. return false;
  1177. }
  1178. bool jackctl_server_add_slave (jackctl_server_t * server_ptr, jackctl_driver_t * driver_ptr)
  1179. {
  1180. return false;
  1181. }
  1182. bool jackctl_server_remove_slave (jackctl_server_t * server_ptr, jackctl_driver_t * driver_ptr)
  1183. {
  1184. return false;
  1185. }
  1186. bool jackctl_server_switch_master (jackctl_server_t * server_ptr, jackctl_driver_t * driver_ptr)
  1187. {
  1188. jack_driver_t *old_driver;
  1189. if (server_ptr->engine == NULL) {
  1190. goto fail_nostart;
  1191. }
  1192. old_driver = server_ptr->engine->driver;
  1193. if (old_driver) {
  1194. old_driver->stop (old_driver );
  1195. old_driver->detach (old_driver, server_ptr->engine);
  1196. pthread_mutex_lock (&server_ptr->engine->request_lock);
  1197. jack_lock_graph (server_ptr->engine);
  1198. jack_remove_client (server_ptr->engine, old_driver->internal_client);
  1199. jack_unlock_graph (server_ptr->engine);
  1200. pthread_mutex_unlock (&server_ptr->engine->request_lock);
  1201. server_ptr->engine->driver = NULL;
  1202. jack_driver_unload (old_driver);
  1203. }
  1204. if (jack_engine_load_driver (server_ptr->engine, driver_ptr->desc_ptr, driver_ptr->set_parameters)) {
  1205. jack_error ("cannot load driver module %s", driver_ptr->desc_ptr->name);
  1206. goto fail_nodriver;
  1207. }
  1208. if (server_ptr->engine->driver->start (server_ptr->engine->driver) != 0) {
  1209. jack_error ("cannot start driver");
  1210. jack_use_driver (server_ptr->engine, NULL);
  1211. goto fail_nodriver;
  1212. }
  1213. return true;
  1214. fail_nodriver:
  1215. jack_error ("could not initialise new driver, leaving without driver");
  1216. fail_nostart:
  1217. return false;
  1218. }