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.

1637 lines
40KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. $Id$
  15. */
  16. #if defined(__APPLE__) && defined(__POWERPC__)
  17. #include "pThreadUtilities.h"
  18. #include "ipc.h"
  19. #include "fakepoll.h"
  20. #else
  21. #include <sys/poll.h>
  22. #endif
  23. #include <sys/socket.h>
  24. #include <sys/un.h>
  25. #include <pthread.h>
  26. #include <errno.h>
  27. #include <fcntl.h>
  28. #include <sys/types.h>
  29. #include <sys/ipc.h>
  30. #include <sys/mman.h>
  31. #include <stdarg.h>
  32. #include <stdio.h>
  33. #include <stdint.h>
  34. #include <regex.h>
  35. #include <config.h>
  36. #include <jack/jack.h>
  37. #include <jack/internal.h>
  38. #include <jack/engine.h>
  39. #include <jack/pool.h>
  40. #include <jack/time.h>
  41. #include <jack/jslist.h>
  42. #include <jack/version.h>
  43. #include <jack/shm.h>
  44. #include "local.h"
  45. #ifdef WITH_TIMESTAMPS
  46. #include <jack/timestamps.h>
  47. #endif /* WITH_TIMESTAMPS */
  48. #ifdef DEFAULT_TMP_DIR
  49. char *jack_server_dir = DEFAULT_TMP_DIR;
  50. #else
  51. char *jack_server_dir = "/tmp";
  52. #endif
  53. void
  54. jack_set_server_dir (const char *path)
  55. {
  56. jack_server_dir = strdup (path);
  57. }
  58. static pthread_mutex_t client_lock;
  59. static pthread_cond_t client_ready;
  60. void *jack_zero_filled_buffer = 0;
  61. #define event_fd pollfd[0].fd
  62. #define graph_wait_fd pollfd[1].fd
  63. typedef struct {
  64. int status;
  65. struct _jack_client *client;
  66. const char *client_name;
  67. } client_info;
  68. void
  69. jack_error (const char *fmt, ...)
  70. {
  71. va_list ap;
  72. char buffer[300];
  73. va_start (ap, fmt);
  74. vsnprintf (buffer, sizeof(buffer), fmt, ap);
  75. jack_error_callback (buffer);
  76. va_end (ap);
  77. }
  78. void default_jack_error_callback (const char *desc)
  79. {
  80. fprintf(stderr, "%s\n", desc);
  81. }
  82. void (*jack_error_callback)(const char *desc) = &default_jack_error_callback;
  83. static int
  84. oop_client_deliver_request (void *ptr, jack_request_t *req)
  85. {
  86. jack_client_t *client = (jack_client_t*) ptr;
  87. if (write (client->request_fd, req, sizeof (*req)) != sizeof (*req)) {
  88. jack_error ("cannot send request type %d to server", req->type);
  89. req->status = -1;
  90. }
  91. if (read (client->request_fd, req, sizeof (*req)) != sizeof (*req)) {
  92. jack_error ("cannot read result for request type %d from server (%s)", req->type, strerror (errno));
  93. req->status = -1;
  94. }
  95. return req->status;
  96. }
  97. int
  98. jack_client_deliver_request (const jack_client_t *client, jack_request_t *req)
  99. {
  100. /* indirect through the function pointer that was set
  101. either by jack_client_new() (external) or handle_new_client()
  102. in the server.
  103. */
  104. return client->control->deliver_request (client->control->deliver_arg, req);
  105. }
  106. jack_client_t *
  107. jack_client_alloc ()
  108. {
  109. jack_client_t *client;
  110. client = (jack_client_t *) malloc (sizeof (jack_client_t));
  111. client->pollfd = (struct pollfd *) malloc (sizeof (struct pollfd) * 2);
  112. client->pollmax = 2;
  113. client->request_fd = -1;
  114. client->event_fd = -1;
  115. client->graph_wait_fd = -1;
  116. client->graph_next_fd = -1;
  117. client->port_segments = NULL;
  118. client->ports = NULL;
  119. client->engine = NULL;
  120. client->control = 0;
  121. client->thread_ok = FALSE;
  122. client->first_active = TRUE;
  123. client->on_shutdown = NULL;
  124. return client;
  125. }
  126. jack_client_t *
  127. jack_client_alloc_internal (jack_client_control_t *cc, jack_control_t *ec)
  128. {
  129. jack_client_t* client;
  130. client = jack_client_alloc ();
  131. client->control = cc;
  132. client->engine = ec;
  133. return client;
  134. }
  135. static void
  136. jack_client_free (jack_client_t *client)
  137. {
  138. if (client->pollfd) {
  139. free (client->pollfd);
  140. }
  141. free (client);
  142. }
  143. void
  144. jack_client_invalidate_port_buffers (jack_client_t *client)
  145. {
  146. JSList *node;
  147. jack_port_t *port;
  148. /* This releases all local memory owned by input ports
  149. and sets the buffer pointer to NULL. This will cause
  150. jack_port_get_buffer() to reallocate space for the
  151. buffer on the next call (if there is one).
  152. */
  153. for (node = client->ports; node; node = jack_slist_next (node)) {
  154. port = (jack_port_t *) node->data;
  155. if (port->shared->flags & JackPortIsInput) {
  156. if (port->client_segment_base == 0) {
  157. jack_pool_release (
  158. (void *) port->shared->offset);
  159. port->client_segment_base = 0;
  160. port->shared->offset = 0;
  161. }
  162. }
  163. }
  164. }
  165. int
  166. jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event)
  167. {
  168. jack_port_t *control_port;
  169. jack_port_t *other;
  170. JSList *node;
  171. switch (event->type) {
  172. case PortConnected:
  173. other = jack_port_new (client, event->y.other_id, client->engine);
  174. control_port = jack_port_by_id (client, event->x.self_id);
  175. pthread_mutex_lock (&control_port->connection_lock);
  176. control_port->connections = jack_slist_prepend (control_port->connections, (void*)other);
  177. pthread_mutex_unlock (&control_port->connection_lock);
  178. break;
  179. case PortDisconnected:
  180. control_port = jack_port_by_id (client, event->x.self_id);
  181. pthread_mutex_lock (&control_port->connection_lock);
  182. for (node = control_port->connections; node; node = jack_slist_next (node)) {
  183. other = (jack_port_t *) node->data;
  184. if (other->shared->id == event->y.other_id) {
  185. control_port->connections = jack_slist_remove_link (control_port->connections, node);
  186. jack_slist_free_1 (node);
  187. free (other);
  188. break;
  189. }
  190. }
  191. pthread_mutex_unlock (&control_port->connection_lock);
  192. break;
  193. default:
  194. /* impossible */
  195. break;
  196. }
  197. return 0;
  198. }
  199. static int
  200. jack_handle_reorder (jack_client_t *client, jack_event_t *event)
  201. {
  202. char path[PATH_MAX+1];
  203. if (client->graph_wait_fd >= 0) {
  204. DEBUG ("closing graph_wait_fd==%d", client->graph_wait_fd);
  205. close (client->graph_wait_fd);
  206. client->graph_wait_fd = -1;
  207. }
  208. if (client->graph_next_fd >= 0) {
  209. DEBUG ("closing graph_next_fd==%d", client->graph_next_fd);
  210. close (client->graph_next_fd);
  211. client->graph_next_fd = -1;
  212. }
  213. sprintf (path, "%s-%" PRIu32, client->fifo_prefix, event->x.n);
  214. if ((client->graph_wait_fd = open (path, O_RDONLY|O_NONBLOCK)) < 0) {
  215. jack_error ("cannot open specified fifo [%s] for reading (%s)", path, strerror (errno));
  216. return -1;
  217. }
  218. DEBUG ("opened new graph_wait_fd %d (%s)", client->graph_wait_fd, path);
  219. sprintf (path, "%s-%" PRIu32, client->fifo_prefix, event->x.n+1);
  220. if ((client->graph_next_fd = open (path, O_WRONLY|O_NONBLOCK)) < 0) {
  221. jack_error ("cannot open specified fifo [%s] for writing (%s)", path, strerror (errno));
  222. return -1;
  223. }
  224. DEBUG ("opened new graph_next_fd %d (%s)", client->graph_next_fd, path);
  225. /* If the client registered its own callback for graph order events,
  226. execute it now.
  227. */
  228. if (client->control->graph_order) {
  229. client->control->graph_order (client->control->graph_order_arg);
  230. }
  231. return 0;
  232. }
  233. static int
  234. server_connect (int which)
  235. {
  236. int fd;
  237. struct sockaddr_un addr;
  238. if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) {
  239. jack_error ("cannot create client socket (%s)", strerror (errno));
  240. return -1;
  241. }
  242. addr.sun_family = AF_UNIX;
  243. snprintf (addr.sun_path, sizeof (addr.sun_path) - 1, "%s/jack_%d", jack_server_dir, which);
  244. if (connect (fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) {
  245. jack_error ("cannot connect to jack server", strerror (errno));
  246. close (fd);
  247. return -1;
  248. }
  249. return fd;
  250. }
  251. static int
  252. server_event_connect (jack_client_t *client)
  253. {
  254. int fd;
  255. struct sockaddr_un addr;
  256. jack_client_connect_ack_request_t req;
  257. jack_client_connect_ack_result_t res;
  258. if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) {
  259. jack_error ("cannot create client event socket (%s)", strerror (errno));
  260. return -1;
  261. }
  262. addr.sun_family = AF_UNIX;
  263. snprintf (addr.sun_path, sizeof (addr.sun_path) - 1, "%s/jack_ack_0", jack_server_dir);
  264. if (connect (fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) {
  265. jack_error ("cannot connect to jack server for events", strerror (errno));
  266. close (fd);
  267. return -1;
  268. }
  269. req.client_id = client->control->id;
  270. if (write (fd, &req, sizeof (req)) != sizeof (req)) {
  271. jack_error ("cannot write event connect request to server (%s)", strerror (errno));
  272. close (fd);
  273. return -1;
  274. }
  275. if (read (fd, &res, sizeof (res)) != sizeof (res)) {
  276. jack_error ("cannot read event connect result from server (%s)", strerror (errno));
  277. close (fd);
  278. return -1;
  279. }
  280. if (res.status != 0) {
  281. close (fd);
  282. return -1;
  283. }
  284. return fd;
  285. }
  286. static int
  287. jack_request_client (ClientType type, const char* client_name, const char* so_name,
  288. const char* so_data, jack_client_connect_result_t *res, int *req_fd)
  289. {
  290. jack_client_connect_request_t req;
  291. *req_fd = -1;
  292. memset (&req, 0, sizeof (req));
  293. if (strlen (client_name) > sizeof (req.name) - 1) {
  294. jack_error ("\"%s\" is too long to be used as a JACK client name.\n"
  295. "Please use %lu characters or less.",
  296. client_name, sizeof (req.name) - 1);
  297. return -1;
  298. }
  299. if (strlen (so_name) > sizeof (req.object_path) - 1) {
  300. jack_error ("\"%s\" is too long to be used as a JACK shared object name.\n"
  301. "Please use %lu characters or less.",
  302. so_name, sizeof (req.object_path) - 1);
  303. return -1;
  304. }
  305. if (strlen (so_data) > sizeof (req.object_data) - 1) {
  306. jack_error ("\"%s\" is too long to be used as a JACK shared object data string.\n"
  307. "Please use %lu characters or less.",
  308. so_data, sizeof (req.object_data) - 1);
  309. return -1;
  310. }
  311. if ((*req_fd = server_connect (0)) < 0) {
  312. jack_error ("cannot connect to default JACK server");
  313. goto fail;
  314. }
  315. req.load = TRUE;
  316. req.type = type;
  317. snprintf (req.name, sizeof (req.name), "%s", client_name);
  318. snprintf (req.object_path, sizeof (req.object_path), "%s", so_name);
  319. snprintf (req.object_data, sizeof (req.object_data), "%s", so_data);
  320. if (write (*req_fd, &req, sizeof (req)) != sizeof (req)) {
  321. jack_error ("cannot send request to jack server (%s)", strerror (errno));
  322. goto fail;
  323. }
  324. if (read (*req_fd, res, sizeof (*res)) != sizeof (*res)) {
  325. if (errno == 0) {
  326. /* server shut the socket */
  327. jack_error ("could not attach as client (duplicate client name?)");
  328. goto fail;
  329. }
  330. jack_error ("cannot read response from jack server (%s)", strerror (errno));
  331. goto fail;
  332. }
  333. if (res->status) {
  334. jack_error ("could not attach as client (duplicate client name?)");
  335. goto fail;
  336. }
  337. if (res->protocol_v != jack_protocol_version){
  338. jack_error ("application linked against too wrong of a version of libjack.");
  339. goto fail;
  340. }
  341. switch (type) {
  342. case ClientDriver:
  343. case ClientInternal:
  344. close (*req_fd);
  345. *req_fd = -1;
  346. break;
  347. default:
  348. break;
  349. }
  350. return 0;
  351. fail:
  352. if (*req_fd >= 0) {
  353. close (*req_fd);
  354. *req_fd = -1;
  355. }
  356. return -1;
  357. }
  358. jack_client_t *
  359. jack_client_new (const char *client_name)
  360. {
  361. int req_fd = -1;
  362. int ev_fd = -1;
  363. jack_client_connect_result_t res;
  364. jack_client_t *client;
  365. void *addr;
  366. int i;
  367. int shmid;
  368. jack_port_type_info_t* type_info;
  369. /* external clients need this initialized; internal clients
  370. will use the setup in the server's address space.
  371. */
  372. jack_init_time ();
  373. if (jack_request_client (ClientExternal, client_name, "", "",
  374. &res, &req_fd)) {
  375. return NULL;
  376. }
  377. client = jack_client_alloc ();
  378. strcpy (client->fifo_prefix, res.fifo_prefix);
  379. client->request_fd = req_fd;
  380. client->pollfd[0].events = POLLIN|POLLERR|POLLHUP|POLLNVAL;
  381. client->pollfd[1].events = POLLIN|POLLERR|POLLHUP|POLLNVAL;
  382. /* attach the engine control/info block */
  383. if ((addr = jack_get_shm (res.control_shm_name, res.control_size,
  384. O_RDWR, 0, (PROT_READ|PROT_WRITE),
  385. &shmid)) == MAP_FAILED) {
  386. jack_error ("cannot attached engine control shared memory"
  387. " segment");
  388. goto fail;
  389. }
  390. client->engine = (jack_control_t *) addr;
  391. /* now attach the client control block */
  392. if ((addr = jack_get_shm (res.client_shm_name,
  393. sizeof (jack_client_control_t), O_RDWR,
  394. 0, (PROT_READ|PROT_WRITE),
  395. &shmid)) == MAP_FAILED) {
  396. jack_error ("cannot attached client control shared memory"
  397. " segment");
  398. goto fail;
  399. }
  400. client->control = (jack_client_control_t *) addr;
  401. /* nobody else needs to access this shared memory any more, so
  402. destroy it. because we have our own link to it, it won't
  403. vanish till we exit.
  404. */
  405. jack_destroy_shm (res.client_shm_name);
  406. /* read incoming port type information so that we can get
  407. shared memory information for each one.
  408. */
  409. type_info = (jack_port_type_info_t *)
  410. malloc (sizeof (jack_port_type_info_t) * res.n_port_types);
  411. if (read (req_fd, type_info,
  412. sizeof (jack_port_type_info_t) * res.n_port_types) !=
  413. sizeof (jack_port_type_info_t) * res.n_port_types) {
  414. jack_error ("cannot read port type information during client"
  415. " connection");
  416. free (type_info);
  417. goto fail;
  418. }
  419. for (i = 0; i < res.n_port_types; ++i) {
  420. jack_client_handle_new_port_type (
  421. client, type_info[i].shm_info.shm_name,
  422. type_info[i].shm_info.size, 0);
  423. }
  424. free (type_info);
  425. /* set up the client so that it does the right thing for an
  426. * external client */
  427. client->control->deliver_request = oop_client_deliver_request;
  428. client->control->deliver_arg = client;
  429. if ((ev_fd = server_event_connect (client)) < 0) {
  430. jack_error ("cannot connect to server for event stream (%s)",
  431. strerror (errno));
  432. goto fail;
  433. }
  434. client->event_fd = ev_fd;
  435. #if defined(__APPLE__) && defined(__POWERPC__)
  436. /* specific resources for server/client real-time thread
  437. * communication */
  438. client->clienttask = mach_task_self();
  439. if (task_get_bootstrap_port(client->clienttask, &client->bp)){
  440. jack_error ("Can't find bootstrap port");
  441. goto fail;
  442. }
  443. if (allocate_mach_clientport(client, res.portnum) < 0) {
  444. jack_error("Can't allocate mach port");
  445. goto fail;
  446. };
  447. #endif
  448. return client;
  449. fail:
  450. if (client->engine) {
  451. munmap ((char *) client->engine, res.control_size);
  452. }
  453. if (client->control) {
  454. munmap ((char *) client->control,
  455. sizeof (jack_client_control_t));
  456. }
  457. if (req_fd >= 0) {
  458. close (req_fd);
  459. }
  460. if (ev_fd >= 0) {
  461. close (ev_fd);
  462. }
  463. return 0;
  464. }
  465. int
  466. jack_internal_client_new (const char *client_name, const char *so_name, const char *so_data)
  467. {
  468. jack_client_connect_result_t res;
  469. int req_fd;
  470. return jack_request_client (ClientInternal, client_name, so_name, so_data, &res, &req_fd);
  471. }
  472. void
  473. jack_internal_client_close (const char *client_name)
  474. {
  475. jack_client_connect_request_t req;
  476. int fd;
  477. req.load = FALSE;
  478. snprintf (req.name, sizeof (req.name), "%s", client_name);
  479. if ((fd = server_connect (0)) < 0) {
  480. jack_error ("cannot connect to default JACK server.");
  481. return;
  482. }
  483. if (write (fd, &req, sizeof (req)) != sizeof(req)) {
  484. jack_error ("cannot deliver ClientUnload request to JACK server.");
  485. }
  486. /* no response to this request */
  487. close (fd);
  488. return;
  489. }
  490. void
  491. jack_client_handle_new_port_type (jack_client_t *client, shm_name_t shm_name,
  492. size_t size, void* addr)
  493. {
  494. jack_port_segment_info_t *si;
  495. int shmid;
  496. /* Lookup, attach and register the port/buffer segments in use
  497. * right now. */
  498. if (client->control->type == ClientExternal) {
  499. if ((addr = jack_get_shm(shm_name, size, O_RDWR, 0,
  500. (PROT_READ|PROT_WRITE),
  501. &shmid)) == MAP_FAILED) {
  502. jack_error ("cannot attached port segment shared memory"
  503. " (%s)", strerror (errno));
  504. return;
  505. }
  506. } else {
  507. /* client is in same address space as server, so just
  508. * use `addr' directly */
  509. }
  510. si = (jack_port_segment_info_t *)
  511. malloc (sizeof (jack_port_segment_info_t));
  512. strcpy (si->shm_name, shm_name);
  513. si->address = addr;
  514. si->size = size;
  515. /* the first chunk of the first port segment is always set by
  516. * the engine to be a conveniently-sized, zero-filled lump of
  517. * memory. */
  518. if (client->port_segments == NULL) {
  519. jack_zero_filled_buffer = si->address;
  520. }
  521. client->port_segments = jack_slist_prepend (client->port_segments, si);
  522. }
  523. static void *
  524. jack_client_thread (void *arg)
  525. {
  526. jack_client_t *client = (jack_client_t *) arg;
  527. jack_client_control_t *control = client->control;
  528. jack_event_t event;
  529. char status = 0;
  530. char c;
  531. int err = 0;
  532. pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
  533. pthread_mutex_lock (&client_lock);
  534. client->thread_ok = TRUE;
  535. client->thread_id = pthread_self();
  536. pthread_cond_signal (&client_ready);
  537. pthread_mutex_unlock (&client_lock);
  538. client->control->pid = getpid();
  539. DEBUG ("client thread is now running");
  540. while (err == 0) {
  541. if (client->engine->engine_ok == 0) {
  542. jack_error ("engine unexpectedly shutdown; "
  543. "thread exiting\n");
  544. if (client->on_shutdown) {
  545. client->on_shutdown (client->on_shutdown_arg);
  546. }
  547. pthread_exit (0);
  548. }
  549. DEBUG ("client polling on event_fd and graph_wait_fd...");
  550. if (poll (client->pollfd, client->pollmax, 1000) < 0) {
  551. if (errno == EINTR) {
  552. printf ("poll interrupted\n");
  553. continue;
  554. }
  555. jack_error ("poll failed in client (%s)",
  556. strerror (errno));
  557. status = -1;
  558. break;
  559. }
  560. pthread_testcancel();
  561. /* get an accurate timestamp on waking from poll for a
  562. * process() cycle. */
  563. if (client->pollfd[1].revents & POLLIN) {
  564. control->awake_at = jack_get_microseconds();
  565. }
  566. if (client->pollfd[0].revents & ~POLLIN ||
  567. client->control->dead) {
  568. goto zombie;
  569. }
  570. if (client->pollfd[0].revents & POLLIN) {
  571. DEBUG ("client receives an event, "
  572. "now reading on event fd");
  573. /* server has sent us an event. process the
  574. * event and reply */
  575. if (read (client->event_fd, &event, sizeof (event))
  576. != sizeof (event)) {
  577. jack_error ("cannot read server event (%s)",
  578. strerror (errno));
  579. err++;
  580. break;
  581. }
  582. status = 0;
  583. switch (event.type) {
  584. case PortRegistered:
  585. if (control->port_register) {
  586. control->port_register
  587. (event.x.port_id, TRUE,
  588. control->port_register_arg);
  589. }
  590. break;
  591. case PortUnregistered:
  592. if (control->port_register) {
  593. control->port_register
  594. (event.x.port_id, FALSE,
  595. control->port_register_arg);
  596. }
  597. break;
  598. case GraphReordered:
  599. status = jack_handle_reorder (client, &event);
  600. break;
  601. case PortConnected:
  602. case PortDisconnected:
  603. status = jack_client_handle_port_connection
  604. (client, &event);
  605. break;
  606. case BufferSizeChange:
  607. jack_client_invalidate_port_buffers (client);
  608. if (control->bufsize) {
  609. status = control->bufsize
  610. (control->nframes,
  611. control->bufsize_arg);
  612. }
  613. break;
  614. case SampleRateChange:
  615. if (control->srate) {
  616. status = control->srate
  617. (control->nframes,
  618. control->srate_arg);
  619. }
  620. break;
  621. case XRun:
  622. if (control->xrun) {
  623. status = control->xrun
  624. (control->xrun_arg);
  625. }
  626. break;
  627. case NewPortType:
  628. jack_client_handle_new_port_type (
  629. client, event.x.shm_name,
  630. event.z.size, event.y.addr);
  631. break;
  632. }
  633. DEBUG ("client has dealt with the event, writing "
  634. "response on event fd");
  635. if (write (client->event_fd, &status, sizeof (status))
  636. != sizeof (status)) {
  637. jack_error ("cannot send event response to "
  638. "engine (%s)", strerror (errno));
  639. err++;
  640. break;
  641. }
  642. }
  643. if (client->pollfd[1].revents & POLLIN) {
  644. #ifdef WITH_TIMESTAMPS
  645. jack_reset_timestamps ();
  646. #endif
  647. DEBUG ("client %d signalled at %" PRIu64
  648. ", awake for process at %" PRIu64
  649. " (delay = %" PRIu64
  650. " usecs) (wakeup on graph_wait_fd==%d)",
  651. getpid(),
  652. control->signalled_at,
  653. control->awake_at,
  654. control->awake_at - control->signalled_at,
  655. client->pollfd[1].fd);
  656. control->state = Running;
  657. if (control->sync_cb)
  658. jack_call_sync_client (client);
  659. if (control->process) {
  660. if (control->process (control->nframes,
  661. control->process_arg)
  662. == 0) {
  663. control->state = Finished;
  664. }
  665. } else {
  666. control->state = Finished;
  667. }
  668. if (control->timebase_cb)
  669. jack_call_timebase_master (client);
  670. control->finished_at = jack_get_microseconds();
  671. #ifdef WITH_TIMESTAMPS
  672. jack_timestamp ("finished");
  673. #endif
  674. /* pass the execution token along */
  675. DEBUG ("client finished processing at %" PRIu64
  676. " (elapsed = %" PRIu64
  677. " usecs), writing on graph_next_fd==%d",
  678. control->finished_at,
  679. control->finished_at - control->awake_at,
  680. client->graph_next_fd);
  681. if (write (client->graph_next_fd, &c, sizeof (c))
  682. != sizeof (c)) {
  683. jack_error ("cannot continue execution of the "
  684. "processing graph (%s)",
  685. strerror(errno));
  686. err++;
  687. break;
  688. }
  689. DEBUG ("client sent message to next stage by %" PRIu64
  690. ", client reading on graph_wait_fd==%d",
  691. jack_get_microseconds(), client->graph_wait_fd);
  692. #ifdef WITH_TIMESTAMPS
  693. jack_timestamp ("read pending byte from wait");
  694. #endif
  695. DEBUG("reading cleanup byte from pipe\n");
  696. if ((read (client->graph_wait_fd, &c, sizeof (c))
  697. != sizeof (c))) {
  698. DEBUG ("WARNING: READ FAILED!");
  699. #if 0
  700. jack_error ("cannot complete execution of the "
  701. "processing graph (%s)",
  702. strerror(errno));
  703. err++;
  704. break;
  705. #endif
  706. }
  707. /* check if we were killed during the process
  708. * cycle (or whatever) */
  709. if (client->control->dead) {
  710. goto zombie;
  711. }
  712. DEBUG("process cycle fully complete\n");
  713. #ifdef WITH_TIMESTAMPS
  714. jack_timestamp ("read done");
  715. jack_dump_timestamps (stdout);
  716. #endif
  717. }
  718. }
  719. return (void *) ((intptr_t)err);
  720. zombie:
  721. if (client->on_shutdown) {
  722. jack_error ("zombified - calling shutdown handler");
  723. client->on_shutdown (client->on_shutdown_arg);
  724. } else {
  725. jack_error ("zombified - exiting from JACK");
  726. jack_client_close (client);
  727. /* Need a fix : possibly make client crash if
  728. * zombified without shutdown handler */
  729. }
  730. pthread_exit (0);
  731. /*NOTREACHED*/
  732. return 0;
  733. }
  734. #if defined(__APPLE__) && defined(__POWERPC__)
  735. /* real-time thread : separated from the normal client thread, it will communicate with the server using fast mach RPC mechanism */
  736. static void *
  737. jack_client_process_thread (void *arg)
  738. {
  739. jack_client_t *client = (jack_client_t *) arg;
  740. jack_client_control_t *control = client->control;
  741. int err = 0;
  742. client->control->pid = getpid();
  743. DEBUG ("client process thread is now running");
  744. pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
  745. while (err == 0) {
  746. if (jack_client_suspend(client) < 0) {
  747. pthread_exit (0);
  748. }
  749. control->awake_at = jack_get_microseconds();
  750. DEBUG ("client resumed");
  751. control->state = Running;
  752. if (control->process) {
  753. if (control->process (control->nframes, control->process_arg) == 0) {
  754. control->state = Finished;
  755. }
  756. } else {
  757. control->state = Finished;
  758. }
  759. control->finished_at = jack_get_microseconds();
  760. #ifdef WITH_TIMESTAMPS
  761. jack_timestamp ("finished");
  762. #endif
  763. DEBUG ("client finished processing at %Lu (elapsed = %f usecs)",
  764. control->finished_at, ((float)(control->finished_at - control->awake_at)));
  765. /* check if we were killed during the process cycle (or whatever) */
  766. if (client->control->dead) {
  767. jack_error ("jack_client_process_thread : client->control->dead");
  768. goto zombie;
  769. }
  770. DEBUG("process cycle fully complete\n");
  771. }
  772. return (void *) ((intptr_t)err);
  773. zombie:
  774. jack_error ("jack_client_process_thread : zombified");
  775. if (client->on_shutdown) {
  776. jack_error ("zombified - calling shutdown handler");
  777. client->on_shutdown (client->on_shutdown_arg);
  778. } else {
  779. jack_error ("zombified - exiting from JACK");
  780. jack_client_close (client); /* Need a fix : possibly make client crash if zombified without shutdown handler */
  781. }
  782. pthread_exit (0);
  783. /*NOTREACHED*/
  784. return 0;
  785. }
  786. #endif
  787. static int
  788. jack_start_thread (jack_client_t *client)
  789. {
  790. pthread_attr_t *attributes = 0;
  791. #ifdef USE_CAPABILITIES
  792. int policy = SCHED_OTHER;
  793. struct sched_param client_param, temp_param;
  794. #endif
  795. if (client->engine->real_time) {
  796. /* Get the client thread to run as an RT-FIFO
  797. scheduled thread of appropriate priority.
  798. */
  799. struct sched_param rt_param;
  800. attributes = (pthread_attr_t *) malloc (sizeof (pthread_attr_t));
  801. pthread_attr_init (attributes);
  802. if (pthread_attr_setschedpolicy (attributes, SCHED_FIFO)) {
  803. jack_error ("cannot set FIFO scheduling class for RT thread");
  804. return -1;
  805. }
  806. if (pthread_attr_setscope (attributes, PTHREAD_SCOPE_SYSTEM)) {
  807. jack_error ("Cannot set scheduling scope for RT thread");
  808. return -1;
  809. }
  810. memset (&rt_param, 0, sizeof (rt_param));
  811. rt_param.sched_priority = client->engine->client_priority;
  812. if (pthread_attr_setschedparam (attributes, &rt_param)) {
  813. jack_error ("Cannot set scheduling priority for RT thread (%s)", strerror (errno));
  814. return -1;
  815. }
  816. #if defined(__APPLE__) && defined(__POWERPC__)
  817. // To be implemented
  818. #else
  819. if (mlockall (MCL_CURRENT | MCL_FUTURE) != 0) {
  820. jack_error ("cannot lock down memory for RT thread (%s)", strerror (errno));
  821. return -1;
  822. }
  823. #endif
  824. }
  825. if (pthread_create (&client->thread, attributes, jack_client_thread, client)) {
  826. #ifdef USE_CAPABILITIES
  827. if (client->engine->real_time && client->engine->has_capabilities) {
  828. /* we are probably dealing with a broken glibc so try
  829. to work around the bug, see below for more details
  830. */
  831. goto capabilities_workaround;
  832. }
  833. #endif
  834. return -1;
  835. }
  836. #if defined(__APPLE__) && defined(__POWERPC__)
  837. /* a spcial real-time thread to call the "process" callback. It will communicate with the server using fast mach RPC mechanism */
  838. if (pthread_create (&client->process_thread, attributes, jack_client_process_thread, client)) {
  839. jack_error("pthread_create failed for process_thread \n");
  840. return -1;
  841. }
  842. if (client->engine->real_time){
  843. /* time constraint thread */
  844. setThreadToPriority(client->process_thread, 96, true, 10000000);
  845. }else{
  846. /* fixed priority thread */
  847. setThreadToPriority(client->process_thread, 63, true, 10000000);
  848. }
  849. #endif
  850. return 0;
  851. #ifdef USE_CAPABILITIES
  852. /* we get here only with engine running realtime and capabilities */
  853. capabilities_workaround:
  854. /* the version of glibc I've played with has a bug that makes
  855. that code fail when running under a non-root user but with the
  856. proper realtime capabilities (in short, pthread_attr_setschedpolicy
  857. does not check for capabilities, only for the uid being
  858. zero). Newer versions apparently have this fixed. This
  859. workaround temporarily switches the client thread to the
  860. proper scheduler and priority, then starts the realtime
  861. thread so that it can inherit them and finally switches the
  862. client thread back to what it was before. Sigh. For ardour
  863. I have to check again and switch the thread explicitly to
  864. realtime, don't know why or how to debug - nando
  865. */
  866. /* get current scheduler and parameters of the client process */
  867. if ((policy = sched_getscheduler (0)) < 0) {
  868. jack_error ("Cannot get current client scheduler: %s", strerror(errno));
  869. return -1;
  870. }
  871. memset (&client_param, 0, sizeof (client_param));
  872. if (sched_getparam (0, &client_param)) {
  873. jack_error ("Cannot get current client scheduler parameters: %s", strerror(errno));
  874. return -1;
  875. }
  876. /* temporarily change the client process to SCHED_FIFO so that
  877. the realtime thread can inherit the scheduler and priority
  878. */
  879. memset (&temp_param, 0, sizeof (temp_param));
  880. temp_param.sched_priority = client->engine->client_priority;
  881. if (sched_setscheduler(0, SCHED_FIFO, &temp_param)) {
  882. jack_error ("Cannot temporarily set client to RT scheduler: %s", strerror(errno));
  883. return -1;
  884. }
  885. /* prepare the attributes for the realtime thread */
  886. attributes = (pthread_attr_t *) malloc (sizeof (pthread_attr_t));
  887. pthread_attr_init (attributes);
  888. if (pthread_attr_setscope (attributes, PTHREAD_SCOPE_SYSTEM)) {
  889. sched_setscheduler (0, policy, &client_param);
  890. jack_error ("Cannot set scheduling scope for RT thread");
  891. return -1;
  892. }
  893. if (pthread_attr_setinheritsched (attributes, PTHREAD_INHERIT_SCHED)) {
  894. sched_setscheduler (0, policy, &client_param);
  895. jack_error ("Cannot set scheduler inherit policy for RT thread");
  896. return -1;
  897. }
  898. /* create the RT thread */
  899. if (pthread_create (&client->thread, attributes, jack_client_thread, client)) {
  900. sched_setscheduler (0, policy, &client_param);
  901. return -1;
  902. }
  903. /* return the client process to the scheduler it was in before */
  904. if (sched_setscheduler (0, policy, &client_param)) {
  905. jack_error ("Cannot reset original client scheduler: %s", strerror(errno));
  906. return -1;
  907. }
  908. /* check again... inheritance of policy and priority works in jack_simple_client
  909. but not in ardour! So I check again and force the policy if it is not set
  910. correctly. This does not really really work either, the manager thread
  911. of the linuxthreads implementation is left running with SCHED_OTHER,
  912. that is presumably very bad.
  913. */
  914. memset (&client_param, 0, sizeof (client_param));
  915. if (pthread_getschedparam(client->thread, &policy, &client_param) == 0) {
  916. if (policy != SCHED_FIFO) {
  917. /* jack_error ("RT thread did not go SCHED_FIFO, trying again"); */
  918. memset (&client_param, 0, sizeof (client_param));
  919. client_param.sched_priority = client->engine->client_priority;
  920. if (pthread_setschedparam (client->thread, SCHED_FIFO, &client_param)) {
  921. jack_error ("Cannot set (again) FIFO scheduling class for RT thread\n");
  922. return -1;
  923. }
  924. }
  925. }
  926. return 0;
  927. #endif
  928. }
  929. int
  930. jack_activate (jack_client_t *client)
  931. {
  932. jack_request_t req;
  933. /* we need to scribble on our stack to ensure that its memory pages are
  934. * actually mapped (more important for mlockall(2) usage in
  935. * jack_start_thread())
  936. */
  937. #if defined(__APPLE__) && defined(__POWERPC__)
  938. #define BIG_ENOUGH_STACK 10000 // a bigger stack make the application crash...
  939. #else
  940. #define BIG_ENOUGH_STACK 1048576
  941. #endif
  942. char buf[BIG_ENOUGH_STACK];
  943. int i;
  944. for (i = 0; i < BIG_ENOUGH_STACK; i++) {
  945. buf[i] = (char) (i & 0xff);
  946. }
  947. #undef BIG_ENOUGH_STACK
  948. if (client->control->type == ClientInternal || client->control->type == ClientDriver) {
  949. goto startit;
  950. }
  951. /* get the pid of the client process to pass it to engine */
  952. client->control->pid = getpid ();
  953. #ifdef USE_CAPABILITIES
  954. if (client->engine->has_capabilities != 0 &&
  955. client->control->pid != 0 && client->engine->real_time != 0) {
  956. /* we need to ask the engine for realtime capabilities
  957. before trying to start the realtime thread
  958. */
  959. req.type = SetClientCapabilities;
  960. req.x.client_id = client->control->id;
  961. jack_client_deliver_request (client, &req);
  962. if (req.status) {
  963. /* what to do? engine is running realtime, it is using capabilities and has
  964. them (otherwise we would not get an error return) but for some reason it
  965. could not give the client the required capabilities, so for now downgrade
  966. the client so that it still runs, albeit non-realtime - nando
  967. */
  968. jack_error ("could not receive realtime capabilities, client will run non-realtime");
  969. /* XXX wrong, this is a property of the engine
  970. client->engine->real_time = 0;
  971. */
  972. }
  973. }
  974. #endif
  975. if (client->first_active) {
  976. pthread_mutex_init (&client_lock, NULL);
  977. pthread_cond_init (&client_ready, NULL);
  978. pthread_mutex_lock (&client_lock);
  979. if (jack_start_thread (client)) {
  980. pthread_mutex_unlock (&client_lock);
  981. return -1;
  982. }
  983. pthread_cond_wait (&client_ready, &client_lock);
  984. pthread_mutex_unlock (&client_lock);
  985. if (!client->thread_ok) {
  986. jack_error ("could not start client thread");
  987. return -1;
  988. }
  989. client->first_active = FALSE;
  990. }
  991. startit:
  992. req.type = ActivateClient;
  993. req.x.client_id = client->control->id;
  994. return jack_client_deliver_request (client, &req);
  995. }
  996. int
  997. jack_deactivate (jack_client_t *client)
  998. {
  999. jack_request_t req;
  1000. req.type = DeactivateClient;
  1001. req.x.client_id = client->control->id;
  1002. return jack_client_deliver_request (client, &req);
  1003. }
  1004. int
  1005. jack_client_close (jack_client_t *client)
  1006. {
  1007. JSList *node;
  1008. void *status;
  1009. if (client->control->active) {
  1010. jack_deactivate (client);
  1011. }
  1012. if (client->control->type == ClientExternal) {
  1013. /* stop the thread that communicates with the jack
  1014. * server, only if it was actually running */
  1015. if (client->thread_ok){
  1016. pthread_cancel (client->thread);
  1017. pthread_join (client->thread, &status);
  1018. }
  1019. munmap ((char *) client->control,
  1020. sizeof (jack_client_control_t));
  1021. munmap ((char *) client->engine,
  1022. sizeof (jack_control_t));
  1023. for (node = client->port_segments; node;
  1024. node = jack_slist_next (node)) {
  1025. jack_port_segment_info_t *si =
  1026. (jack_port_segment_info_t *) node->data;
  1027. munmap ((char *) si->address, si->size);
  1028. free (node->data);
  1029. }
  1030. jack_slist_free (client->port_segments);
  1031. if (client->graph_wait_fd) {
  1032. close (client->graph_wait_fd);
  1033. }
  1034. if (client->graph_next_fd) {
  1035. close (client->graph_next_fd);
  1036. }
  1037. close (client->event_fd);
  1038. close (client->request_fd);
  1039. }
  1040. for (node = client->ports; node; node = jack_slist_next (node)) {
  1041. free (node->data);
  1042. }
  1043. jack_slist_free (client->ports);
  1044. jack_client_free (client);
  1045. return 0;
  1046. }
  1047. int
  1048. jack_is_realtime (jack_client_t *client)
  1049. {
  1050. return client->engine->real_time;
  1051. }
  1052. jack_nframes_t
  1053. jack_get_buffer_size (jack_client_t *client)
  1054. {
  1055. return client->engine->buffer_size;
  1056. }
  1057. int
  1058. jack_connect (jack_client_t *client, const char *source_port,
  1059. const char *destination_port)
  1060. {
  1061. jack_request_t req;
  1062. req.type = ConnectPorts;
  1063. snprintf (req.x.connect.source_port,
  1064. sizeof (req.x.connect.source_port), "%s", source_port);
  1065. snprintf (req.x.connect.destination_port,
  1066. sizeof (req.x.connect.destination_port),
  1067. "%s", destination_port);
  1068. return jack_client_deliver_request (client, &req);
  1069. }
  1070. int
  1071. jack_port_disconnect (jack_client_t *client, jack_port_t *port)
  1072. {
  1073. jack_request_t req;
  1074. pthread_mutex_lock (&port->connection_lock);
  1075. if (port->connections == NULL) {
  1076. pthread_mutex_unlock (&port->connection_lock);
  1077. return 0;
  1078. }
  1079. pthread_mutex_unlock (&port->connection_lock);
  1080. req.type = DisconnectPort;
  1081. req.x.port_info.port_id = port->shared->id;
  1082. return jack_client_deliver_request (client, &req);
  1083. }
  1084. int
  1085. jack_disconnect (jack_client_t *client, const char *source_port,
  1086. const char *destination_port)
  1087. {
  1088. jack_request_t req;
  1089. req.type = DisconnectPorts;
  1090. snprintf (req.x.connect.source_port,
  1091. sizeof (req.x.connect.source_port), "%s", source_port);
  1092. snprintf (req.x.connect.destination_port,
  1093. sizeof (req.x.connect.destination_port),
  1094. "%s", destination_port);
  1095. return jack_client_deliver_request (client, &req);
  1096. }
  1097. void
  1098. jack_set_error_function (void (*func) (const char *))
  1099. {
  1100. jack_error_callback = func;
  1101. }
  1102. int
  1103. jack_set_graph_order_callback (jack_client_t *client,
  1104. JackGraphOrderCallback callback, void *arg)
  1105. {
  1106. if (client->control->active) {
  1107. jack_error ("You cannot set callbacks on an active client.");
  1108. return -1;
  1109. }
  1110. client->control->graph_order = callback;
  1111. client->control->graph_order_arg = arg;
  1112. return 0;
  1113. }
  1114. int jack_set_xrun_callback (jack_client_t *client,
  1115. JackXRunCallback callback, void *arg)
  1116. {
  1117. if (client->control->active) {
  1118. jack_error ("You cannot set callbacks on an active client.");
  1119. return -1;
  1120. }
  1121. client->control->xrun = callback;
  1122. client->control->xrun_arg = arg;
  1123. return 0;
  1124. }
  1125. int
  1126. jack_set_process_callback (jack_client_t *client,
  1127. JackProcessCallback callback, void *arg)
  1128. {
  1129. if (client->control->active) {
  1130. jack_error ("You cannot set callbacks on an active client.");
  1131. return -1;
  1132. }
  1133. client->control->process_arg = arg;
  1134. client->control->process = callback;
  1135. return 0;
  1136. }
  1137. int
  1138. jack_set_buffer_size_callback (jack_client_t *client,
  1139. JackBufferSizeCallback callback, void *arg)
  1140. {
  1141. client->control->bufsize_arg = arg;
  1142. client->control->bufsize = callback;
  1143. return 0;
  1144. }
  1145. int
  1146. jack_set_port_registration_callback(jack_client_t *client,
  1147. JackPortRegistrationCallback callback,
  1148. void *arg)
  1149. {
  1150. if (client->control->active) {
  1151. jack_error ("You cannot set callbacks on an active client.");
  1152. return -1;
  1153. }
  1154. client->control->port_register_arg = arg;
  1155. client->control->port_register = callback;
  1156. return 0;
  1157. }
  1158. int
  1159. jack_get_process_start_fd (jack_client_t *client)
  1160. {
  1161. /* once this has been called, the client thread
  1162. does not sleep on the graph wait fd.
  1163. */
  1164. client->pollmax = 1;
  1165. return client->graph_wait_fd;
  1166. }
  1167. int
  1168. jack_get_process_done_fd (jack_client_t *client)
  1169. {
  1170. return client->graph_next_fd;
  1171. }
  1172. void
  1173. jack_on_shutdown (jack_client_t *client, void (*function)(void *arg), void *arg)
  1174. {
  1175. client->on_shutdown = function;
  1176. client->on_shutdown_arg = arg;
  1177. }
  1178. const char **
  1179. jack_get_ports (jack_client_t *client,
  1180. const char *port_name_pattern,
  1181. const char *type_name_pattern,
  1182. unsigned long flags)
  1183. {
  1184. jack_control_t *engine;
  1185. const char **matching_ports;
  1186. unsigned long match_cnt;
  1187. jack_port_shared_t *psp;
  1188. unsigned long i;
  1189. regex_t port_regex;
  1190. regex_t type_regex;
  1191. int matching;
  1192. engine = client->engine;
  1193. if (port_name_pattern && port_name_pattern[0]) {
  1194. regcomp (&port_regex, port_name_pattern, REG_EXTENDED|REG_NOSUB);
  1195. }
  1196. if (type_name_pattern && type_name_pattern[0]) {
  1197. regcomp (&type_regex, type_name_pattern, REG_EXTENDED|REG_NOSUB);
  1198. }
  1199. psp = engine->ports;
  1200. match_cnt = 0;
  1201. matching_ports = (const char **) malloc (sizeof (char *) * engine->port_max);
  1202. for (i = 0; i < engine->port_max; i++) {
  1203. matching = 1;
  1204. if (!psp[i].in_use) {
  1205. continue;
  1206. }
  1207. if (flags) {
  1208. if ((psp[i].flags & flags) != flags) {
  1209. matching = 0;
  1210. }
  1211. }
  1212. if (matching && port_name_pattern && port_name_pattern[0]) {
  1213. if (regexec (&port_regex, psp[i].name, 0, NULL, 0)) {
  1214. matching = 0;
  1215. }
  1216. }
  1217. if (matching && type_name_pattern && type_name_pattern[0]) {
  1218. if (regexec (&type_regex, psp[i].type_info.type_name, 0, NULL, 0)) {
  1219. matching = 0;
  1220. }
  1221. }
  1222. if (matching) {
  1223. matching_ports[match_cnt++] = psp[i].name;
  1224. }
  1225. }
  1226. matching_ports[match_cnt] = 0;
  1227. if (match_cnt == 0) {
  1228. free (matching_ports);
  1229. matching_ports = 0;
  1230. }
  1231. return matching_ports;
  1232. }
  1233. float
  1234. jack_cpu_load (jack_client_t *client)
  1235. {
  1236. return client->engine->cpu_load;
  1237. }
  1238. pthread_t
  1239. jack_client_thread_id (jack_client_t *client)
  1240. {
  1241. return client->thread_id;
  1242. }
  1243. #if defined(__APPLE__) && defined(__POWERPC__)
  1244. double __jack_time_ratio;
  1245. void jack_init_time ()
  1246. {
  1247. mach_timebase_info_data_t info;
  1248. mach_timebase_info(&info);
  1249. __jack_time_ratio = ((float)info.numer/info.denom) / 1000;
  1250. }
  1251. #else
  1252. jack_time_t
  1253. jack_get_mhz (void)
  1254. {
  1255. FILE *f = fopen("/proc/cpuinfo", "r");
  1256. if (f == 0)
  1257. {
  1258. perror("can't open /proc/cpuinfo\n");
  1259. exit(1);
  1260. }
  1261. for ( ; ; )
  1262. {
  1263. jack_time_t mhz;
  1264. int ret;
  1265. char buf[1000];
  1266. if (fgets(buf, sizeof(buf), f) == NULL)
  1267. {
  1268. fprintf(stderr, "cannot locate cpu MHz in /proc/cpuinfo\n");
  1269. exit(1);
  1270. }
  1271. #if defined(__powerpc__)
  1272. ret = sscanf(buf, "clock\t: %" SCNu64 "MHz", &mhz);
  1273. #elif defined( __i386__ ) || defined (__hppa__) || defined (__ia64__) || \
  1274. defined(__x86_64__)
  1275. ret = sscanf(buf, "cpu MHz : %" SCNu64, &mhz);
  1276. #elif defined( __sparc__ )
  1277. ret = sscanf(buf, "Cpu0Bogo : %" SCNu64, &mhz);
  1278. #elif defined( __mc68000__ )
  1279. ret = sscanf(buf, "Clocking: %" SCNu64, &mhz);
  1280. #elif defined( __s390__ )
  1281. ret = sscanf(buf, "bogomips per cpu: %" SCNu64, &mhz);
  1282. #else /* MIPS, ARM, alpha */
  1283. ret = sscanf(buf, "BogoMIPS : %" SCNu64, &mhz);
  1284. #endif
  1285. if (ret == 1)
  1286. {
  1287. fclose(f);
  1288. return (jack_time_t)mhz;
  1289. }
  1290. }
  1291. }
  1292. jack_time_t __jack_cpu_mhz;
  1293. void jack_init_time ()
  1294. {
  1295. __jack_cpu_mhz = jack_get_mhz ();
  1296. }
  1297. #endif