jack2 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.

1507 lines
46KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2006 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include "JackClient.h"
  17. #include "JackError.h"
  18. #include "JackGraphManager.h"
  19. #include "JackEngineControl.h"
  20. #include "JackClientControl.h"
  21. #include "JackGlobals.h"
  22. #include "JackTime.h"
  23. #include "JackExports.h"
  24. #include "JackAPI.h"
  25. #ifdef __APPLE__
  26. #include "JackMachThread.h"
  27. #elif WIN32
  28. #include "JackWinThread.h"
  29. #else
  30. #include "JackPosixThread.h"
  31. #endif
  32. #include <math.h>
  33. #ifdef __CLIENTDEBUG__
  34. #include "JackLibGlobals.h"
  35. #endif
  36. using namespace Jack;
  37. #ifdef __cplusplus
  38. extern "C"
  39. {
  40. #endif
  41. EXPORT int jack_client_name_size (void);
  42. EXPORT char* jack_get_client_name (jack_client_t *client);
  43. EXPORT int jack_internal_client_new (const char *client_name,
  44. const char *load_name,
  45. const char *load_init);
  46. EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name);
  47. EXPORT void jack_internal_client_close (const char *client_name);
  48. EXPORT void my_jack_internal_client_close (jack_client_t* client);
  49. EXPORT int jack_is_realtime (jack_client_t *client);
  50. EXPORT void jack_on_shutdown (jack_client_t *client,
  51. void (*function)(void *arg), void *arg);
  52. EXPORT int jack_set_process_callback (jack_client_t *client,
  53. JackProcessCallback process_callback,
  54. void *arg);
  55. EXPORT int jack_set_thread_init_callback (jack_client_t *client,
  56. JackThreadInitCallback thread_init_callback,
  57. void *arg);
  58. EXPORT int jack_set_freewheel_callback (jack_client_t *client,
  59. JackFreewheelCallback freewheel_callback,
  60. void *arg);
  61. EXPORT int jack_set_freewheel(jack_client_t* client, int onoff);
  62. EXPORT int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
  63. EXPORT int jack_set_buffer_size_callback (jack_client_t *client,
  64. JackBufferSizeCallback bufsize_callback,
  65. void *arg);
  66. EXPORT int jack_set_sample_rate_callback (jack_client_t *client,
  67. JackSampleRateCallback srate_callback,
  68. void *arg);
  69. EXPORT int jack_set_port_registration_callback (jack_client_t *,
  70. JackPortRegistrationCallback
  71. registration_callback, void *arg);
  72. EXPORT int jack_set_graph_order_callback (jack_client_t *,
  73. JackGraphOrderCallback graph_callback,
  74. void *);
  75. EXPORT int jack_set_xrun_callback (jack_client_t *,
  76. JackXRunCallback xrun_callback, void *arg);
  77. EXPORT int jack_activate (jack_client_t *client);
  78. EXPORT int jack_deactivate (jack_client_t *client);
  79. EXPORT jack_port_t * jack_port_register (jack_client_t *client,
  80. const char *port_name,
  81. const char *port_type,
  82. unsigned long flags,
  83. unsigned long buffer_size);
  84. EXPORT int jack_port_unregister (jack_client_t *, jack_port_t *);
  85. EXPORT void * jack_port_get_buffer (jack_port_t *, jack_nframes_t);
  86. EXPORT const char * jack_port_name (const jack_port_t *port);
  87. EXPORT const char * jack_port_short_name (const jack_port_t *port);
  88. EXPORT int jack_port_flags (const jack_port_t *port);
  89. EXPORT const char * jack_port_type (const jack_port_t *port);
  90. EXPORT int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
  91. EXPORT int jack_port_connected (const jack_port_t *port);
  92. EXPORT int jack_port_connected_to (const jack_port_t *port,
  93. const char *port_name);
  94. EXPORT const char ** jack_port_get_connections (const jack_port_t *port);
  95. EXPORT const char ** jack_port_get_all_connections (const jack_client_t *client,
  96. const jack_port_t *port);
  97. EXPORT int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  98. EXPORT int jack_port_untie (jack_port_t *port);
  99. EXPORT int jack_port_lock (jack_client_t *, jack_port_t *);
  100. EXPORT int jack_port_unlock (jack_client_t *, jack_port_t *);
  101. EXPORT jack_nframes_t jack_port_get_latency (jack_port_t *port);
  102. EXPORT jack_nframes_t jack_port_get_total_latency (jack_client_t *,
  103. jack_port_t *port);
  104. EXPORT void jack_port_set_latency (jack_port_t *, jack_nframes_t);
  105. EXPORT int jack_recompute_total_latencies (jack_client_t*);
  106. EXPORT int jack_port_set_name (jack_port_t *port, const char *port_name);
  107. EXPORT int jack_port_request_monitor (jack_port_t *port, int onoff);
  108. EXPORT int jack_port_request_monitor_by_name (jack_client_t *client,
  109. const char *port_name, int onoff);
  110. EXPORT int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  111. EXPORT int jack_port_monitoring_input (jack_port_t *port);
  112. EXPORT int jack_connect (jack_client_t *,
  113. const char *source_port,
  114. const char *destination_port);
  115. EXPORT int jack_disconnect (jack_client_t *,
  116. const char *source_port,
  117. const char *destination_port);
  118. EXPORT int jack_port_disconnect (jack_client_t *, jack_port_t *);
  119. EXPORT int jack_port_name_size(void);
  120. EXPORT int jack_port_type_size(void);
  121. EXPORT jack_nframes_t jack_get_sample_rate (jack_client_t *);
  122. EXPORT jack_nframes_t jack_get_buffer_size (jack_client_t *);
  123. EXPORT const char ** jack_get_ports (jack_client_t *,
  124. const char *port_name_pattern,
  125. const char *type_name_pattern,
  126. unsigned long flags);
  127. EXPORT jack_port_t * jack_port_by_name (jack_client_t *, const char *port_name);
  128. EXPORT jack_port_t * jack_port_by_id (jack_client_t *client,
  129. jack_port_id_t port_id);
  130. EXPORT int jack_engine_takeover_timebase (jack_client_t *);
  131. EXPORT jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
  132. EXPORT jack_nframes_t jack_frame_time (const jack_client_t *);
  133. EXPORT jack_nframes_t jack_last_frame_time (const jack_client_t *client);
  134. EXPORT float jack_cpu_load (jack_client_t *client);
  135. EXPORT pthread_t jack_client_thread_id (jack_client_t *);
  136. EXPORT void jack_set_error_function (void (*func)(const char *));
  137. EXPORT float jack_get_max_delayed_usecs (jack_client_t *client);
  138. EXPORT float jack_get_xrun_delayed_usecs (jack_client_t *client);
  139. EXPORT void jack_reset_max_delayed_usecs (jack_client_t *client);
  140. EXPORT int jack_release_timebase (jack_client_t *client);
  141. EXPORT int jack_set_sync_callback (jack_client_t *client,
  142. JackSyncCallback sync_callback,
  143. void *arg);
  144. EXPORT int jack_set_sync_timeout (jack_client_t *client,
  145. jack_time_t timeout);
  146. EXPORT int jack_set_timebase_callback (jack_client_t *client,
  147. int conditional,
  148. JackTimebaseCallback timebase_callback,
  149. void *arg);
  150. EXPORT int jack_transport_locate (jack_client_t *client,
  151. jack_nframes_t frame);
  152. EXPORT jack_transport_state_t jack_transport_query (const jack_client_t *client,
  153. jack_position_t *pos);
  154. EXPORT jack_nframes_t jack_get_current_transport_frame (const jack_client_t *client);
  155. EXPORT int jack_transport_reposition (jack_client_t *client,
  156. jack_position_t *pos);
  157. EXPORT void jack_transport_start (jack_client_t *client);
  158. EXPORT void jack_transport_stop (jack_client_t *client);
  159. EXPORT void jack_get_transport_info (jack_client_t *client,
  160. jack_transport_info_t *tinfo);
  161. EXPORT void jack_set_transport_info (jack_client_t *client,
  162. jack_transport_info_t *tinfo);
  163. EXPORT int jack_acquire_real_time_scheduling (pthread_t thread, int priority);
  164. EXPORT int jack_client_create_thread (jack_client_t* client,
  165. pthread_t *thread,
  166. int priority,
  167. int realtime, // boolean
  168. void *(*start_routine)(void*),
  169. void *arg);
  170. EXPORT int jack_drop_real_time_scheduling (pthread_t thread);
  171. EXPORT char * jack_get_internal_client_name (jack_client_t *client,
  172. jack_intclient_t intclient);
  173. EXPORT jack_intclient_t jack_internal_client_handle (jack_client_t *client,
  174. const char *client_name,
  175. jack_status_t *status);
  176. EXPORT jack_intclient_t jack_internal_client_load (jack_client_t *client,
  177. const char *client_name,
  178. jack_options_t options,
  179. jack_status_t *status, ...);
  180. EXPORT jack_status_t jack_internal_client_unload (jack_client_t *client,
  181. jack_intclient_t intclient);
  182. #ifdef __cplusplus
  183. }
  184. #endif
  185. #ifdef WIN32
  186. /* missing on Windows : see http://bugs.mysql.com/bug.php?id=15936 */
  187. inline double rint(double nr)
  188. {
  189. double f = floor(nr);
  190. double c = ceil(nr);
  191. return (((c -nr) >= (nr - f)) ? f : c);
  192. }
  193. #endif
  194. static inline bool CheckPort(jack_port_id_t port_index)
  195. {
  196. return (port_index < PORT_NUM);
  197. }
  198. static inline bool CheckBufferSize(jack_nframes_t buffer_size)
  199. {
  200. return (buffer_size <= BUFFER_SIZE_MAX);
  201. }
  202. static inline void WaitGraphChange()
  203. {
  204. if (GetGraphManager()->IsPendingChange()) {
  205. JackLog("WaitGraphChange...\n");
  206. JackSleep(GetEngineControl()->fPeriodUsecs * 2);
  207. }
  208. }
  209. static void default_jack_error_callback(const char *desc)
  210. {
  211. fprintf(stderr, "%s\n", desc);
  212. }
  213. void (*jack_error_callback)(const char *desc) = &default_jack_error_callback;
  214. EXPORT void jack_set_error_function (void (*func)(const char *))
  215. {
  216. jack_error_callback = func;
  217. }
  218. EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames)
  219. {
  220. #ifdef __CLIENTDEBUG__
  221. JackLibGlobals::CheckContext();
  222. #endif
  223. jack_port_id_t myport = (jack_port_id_t)port;
  224. if (!CheckPort(myport)) {
  225. jack_error("jack_port_get_buffer called with an incorrect port %ld", myport);
  226. return NULL;
  227. } else {
  228. return GetGraphManager()->GetBuffer(myport, frames);
  229. }
  230. }
  231. EXPORT const char* jack_port_name(const jack_port_t* port)
  232. {
  233. #ifdef __CLIENTDEBUG__
  234. JackLibGlobals::CheckContext();
  235. #endif
  236. jack_port_id_t myport = (jack_port_id_t)port;
  237. if (!CheckPort(myport)) {
  238. jack_error("jack_port_name called with an incorrect port %ld", myport);
  239. return NULL;
  240. } else {
  241. return GetGraphManager()->GetPort(myport)->GetName();
  242. }
  243. }
  244. EXPORT const char* jack_port_short_name(const jack_port_t* port)
  245. {
  246. #ifdef __CLIENTDEBUG__
  247. JackLibGlobals::CheckContext();
  248. #endif
  249. jack_port_id_t myport = (jack_port_id_t)port;
  250. if (!CheckPort(myport)) {
  251. jack_error("jack_port_short_name called with an incorrect port %ld", myport);
  252. return NULL;
  253. } else {
  254. return GetGraphManager()->GetPort(myport)->GetShortName();
  255. }
  256. }
  257. EXPORT int jack_port_flags(const jack_port_t* port)
  258. {
  259. #ifdef __CLIENTDEBUG__
  260. JackLibGlobals::CheckContext();
  261. #endif
  262. jack_port_id_t myport = (jack_port_id_t)port;
  263. if (!CheckPort(myport)) {
  264. jack_error("jack_port_flags called with an incorrect port %ld", myport);
  265. return -1;
  266. } else {
  267. return GetGraphManager()->GetPort(myport)->Flags();
  268. }
  269. }
  270. EXPORT const char* jack_port_type(const jack_port_t* port)
  271. {
  272. #ifdef __CLIENTDEBUG__
  273. JackLibGlobals::CheckContext();
  274. #endif
  275. jack_port_id_t myport = (jack_port_id_t)port;
  276. if (!CheckPort(myport)) {
  277. jack_error("jack_port_flags called an incorrect port %ld", myport);
  278. return NULL;
  279. } else {
  280. return GetGraphManager()->GetPort(myport)->Type();
  281. }
  282. }
  283. EXPORT int jack_port_connected(const jack_port_t* port)
  284. {
  285. #ifdef __CLIENTDEBUG__
  286. JackLibGlobals::CheckContext();
  287. #endif
  288. jack_port_id_t myport = (jack_port_id_t)port;
  289. if (!CheckPort(myport)) {
  290. jack_error("jack_port_connected called with an incorrect port %ld", myport);
  291. return -1;
  292. } else {
  293. WaitGraphChange();
  294. return GetGraphManager()->GetConnectionsNum(myport);
  295. }
  296. }
  297. EXPORT int jack_port_connected_to(const jack_port_t* port, const char* portname)
  298. {
  299. #ifdef __CLIENTDEBUG__
  300. JackLibGlobals::CheckContext();
  301. #endif
  302. jack_port_id_t myport = (jack_port_id_t)port;
  303. if (!CheckPort(myport)) {
  304. jack_error("jack_port_connected_to called with an incorrect port %ld", myport);
  305. return -1;
  306. } else if (portname == NULL) {
  307. jack_error("jack_port_connected_to called with a NULL port name");
  308. return -1;
  309. } else {
  310. WaitGraphChange();
  311. return GetGraphManager()->ConnectedTo(myport, portname);
  312. }
  313. }
  314. EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
  315. {
  316. #ifdef __CLIENTDEBUG__
  317. JackLibGlobals::CheckContext();
  318. #endif
  319. jack_port_id_t mysrc = (jack_port_id_t)src;
  320. if (!CheckPort(mysrc)) {
  321. jack_error("jack_port_tie called with a NULL src port");
  322. return -1;
  323. }
  324. jack_port_id_t mydst = (jack_port_id_t)dst;
  325. if (!CheckPort(mydst)) {
  326. jack_error("jack_port_tie called with a NULL dst port");
  327. return -1;
  328. }
  329. if (GetGraphManager()->GetPort(mysrc)->GetRefNum() != GetGraphManager()->GetPort(mydst)->GetRefNum()) {
  330. jack_error("jack_port_tie called with ports not belonging to the same client");
  331. return -1;
  332. }
  333. return GetGraphManager()->GetPort(mydst)->Tie(mysrc);
  334. }
  335. EXPORT int jack_port_untie(jack_port_t* port)
  336. {
  337. #ifdef __CLIENTDEBUG__
  338. JackLibGlobals::CheckContext();
  339. #endif
  340. jack_port_id_t myport = (jack_port_id_t)port;
  341. if (!CheckPort(myport)) {
  342. jack_error("jack_port_untie called with an incorrect port %ld", myport);
  343. return -1;
  344. } else {
  345. return GetGraphManager()->GetPort(myport)->UnTie();
  346. }
  347. }
  348. EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
  349. {
  350. #ifdef __CLIENTDEBUG__
  351. JackLibGlobals::CheckContext();
  352. #endif
  353. jack_port_id_t myport = (jack_port_id_t)port;
  354. if (!CheckPort(myport)) {
  355. jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
  356. return 0;
  357. } else {
  358. WaitGraphChange();
  359. return GetGraphManager()->GetPort(myport)->GetLatency();
  360. }
  361. }
  362. EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
  363. {
  364. #ifdef __CLIENTDEBUG__
  365. JackLibGlobals::CheckContext();
  366. #endif
  367. jack_port_id_t myport = (jack_port_id_t)port;
  368. if (!CheckPort(myport)) {
  369. jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
  370. } else {
  371. GetGraphManager()->GetPort(myport)->SetLatency(frames);
  372. }
  373. }
  374. EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
  375. {
  376. // The latency computation is done each time jack_port_get_total_latency is called
  377. return 0;
  378. }
  379. EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
  380. {
  381. #ifdef __CLIENTDEBUG__
  382. JackLibGlobals::CheckContext();
  383. #endif
  384. jack_port_id_t myport = (jack_port_id_t)port;
  385. if (!CheckPort(myport)) {
  386. jack_error("jack_port_set_name called with an incorrect port %ld", myport);
  387. return -1;
  388. } else if (name == NULL) {
  389. jack_error("jack_port_set_name called with a NULL port name");
  390. return -1;
  391. } else {
  392. return GetGraphManager()->GetPort(myport)->SetName(name);
  393. }
  394. }
  395. EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
  396. {
  397. #ifdef __CLIENTDEBUG__
  398. JackLibGlobals::CheckContext();
  399. #endif
  400. jack_port_id_t myport = (jack_port_id_t)port;
  401. if (!CheckPort(myport)) {
  402. jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
  403. return -1;
  404. } else {
  405. return GetGraphManager()->RequestMonitor(myport, onoff);
  406. }
  407. }
  408. EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
  409. {
  410. #ifdef __CLIENTDEBUG__
  411. JackLibGlobals::CheckContext();
  412. #endif
  413. JackClient* client = (JackClient*)ext_client;
  414. if (client == NULL) {
  415. jack_error("jack_port_request_monitor_by_name called with a NULL client");
  416. return -1;
  417. } else {
  418. jack_port_id_t myport = GetGraphManager()->GetPort(port_name);
  419. if (!CheckPort(myport)) {
  420. jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
  421. return -1;
  422. } else {
  423. return GetGraphManager()->RequestMonitor(myport, onoff);
  424. }
  425. }
  426. }
  427. EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
  428. {
  429. #ifdef __CLIENTDEBUG__
  430. JackLibGlobals::CheckContext();
  431. #endif
  432. jack_port_id_t myport = (jack_port_id_t)port;
  433. if (!CheckPort(myport)) {
  434. jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
  435. return -1;
  436. } else {
  437. return GetGraphManager()->GetPort(myport)->EnsureMonitor(onoff);
  438. }
  439. }
  440. EXPORT int jack_port_monitoring_input(jack_port_t* port)
  441. {
  442. #ifdef __CLIENTDEBUG__
  443. JackLibGlobals::CheckContext();
  444. #endif
  445. jack_port_id_t myport = (jack_port_id_t)port;
  446. if (!CheckPort(myport)) {
  447. jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
  448. return -1;
  449. } else {
  450. return GetGraphManager()->GetPort(myport)->MonitoringInput();
  451. }
  452. }
  453. EXPORT int jack_is_realtime(jack_client_t* ext_client)
  454. {
  455. #ifdef __CLIENTDEBUG__
  456. JackLibGlobals::CheckContext();
  457. #endif
  458. JackClient* client = (JackClient*)ext_client;
  459. if (client == NULL) {
  460. jack_error("jack_is_realtime called with a NULL client");
  461. return -1;
  462. } else {
  463. return GetEngineControl()->fRealTime;
  464. }
  465. }
  466. EXPORT void jack_on_shutdown(jack_client_t* ext_client, void (*function)(void* arg), void* arg)
  467. {
  468. #ifdef __CLIENTDEBUG__
  469. JackLibGlobals::CheckContext();
  470. #endif
  471. JackClient* client = (JackClient*)ext_client;
  472. if (client == NULL) {
  473. jack_error("jack_on_shutdown called with a NULL client");
  474. } else {
  475. client->OnShutdown(function, arg);
  476. }
  477. }
  478. EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
  479. {
  480. #ifdef __CLIENTDEBUG__
  481. JackLibGlobals::CheckContext();
  482. #endif
  483. JackClient* client = (JackClient*)ext_client;
  484. if (client == NULL) {
  485. jack_error("jack_set_process_callback called with a NULL client");
  486. return -1;
  487. } else {
  488. return client->SetProcessCallback(callback, arg);
  489. }
  490. }
  491. EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
  492. {
  493. #ifdef __CLIENTDEBUG__
  494. JackLibGlobals::CheckContext();
  495. #endif
  496. JackClient* client = (JackClient*)ext_client;
  497. if (client == NULL) {
  498. jack_error("jack_set_freewheel_callback called with a NULL client");
  499. return -1;
  500. } else {
  501. return client->SetFreewheelCallback(freewheel_callback, arg);
  502. }
  503. }
  504. EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
  505. {
  506. #ifdef __CLIENTDEBUG__
  507. JackLibGlobals::CheckContext();
  508. #endif
  509. JackClient* client = (JackClient*)ext_client;
  510. if (client == NULL) {
  511. jack_error("jack_set_freewheel called with a NULL client");
  512. return -1;
  513. } else {
  514. return client->SetFreeWheel(onoff);
  515. }
  516. }
  517. EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
  518. {
  519. #ifdef __CLIENTDEBUG__
  520. JackLibGlobals::CheckContext();
  521. #endif
  522. JackClient* client = (JackClient*)ext_client;
  523. if (client == NULL) {
  524. jack_error("jack_set_buffer_size called with a NULL client");
  525. return -1;
  526. } else if (!CheckBufferSize(buffer_size)) {
  527. return -1;
  528. } else {
  529. return client->SetBufferSize(buffer_size);
  530. }
  531. }
  532. EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
  533. {
  534. #ifdef __CLIENTDEBUG__
  535. JackLibGlobals::CheckContext();
  536. #endif
  537. JackClient* client = (JackClient*)ext_client;
  538. if (client == NULL) {
  539. jack_error("jack_set_buffer_size_callback called with a NULL client");
  540. return -1;
  541. } else {
  542. return client->SetBufferSizeCallback(bufsize_callback, arg);
  543. }
  544. }
  545. EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
  546. {
  547. #ifdef __CLIENTDEBUG__
  548. JackLibGlobals::CheckContext();
  549. #endif
  550. JackClient* client = (JackClient*)ext_client;
  551. JackLog("jack_set_sample_rate_callback ext_client %x client %x \n", ext_client, client);
  552. if (client == NULL) {
  553. jack_error("jack_set_sample_rate_callback called with a NULL client");
  554. return -1;
  555. } else {
  556. JackLog("jack_set_sample_rate_callback: deprecated\n");
  557. return -1;
  558. }
  559. }
  560. EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
  561. {
  562. #ifdef __CLIENTDEBUG__
  563. JackLibGlobals::CheckContext();
  564. #endif
  565. JackClient* client = (JackClient*)ext_client;
  566. if (client == NULL) {
  567. jack_error("jack_set_port_registration_callback called with a NULL client");
  568. return -1;
  569. } else {
  570. return client->SetPortRegistrationCallback(registration_callback, arg);
  571. }
  572. }
  573. EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
  574. {
  575. #ifdef __CLIENTDEBUG__
  576. JackLibGlobals::CheckContext();
  577. #endif
  578. JackClient* client = (JackClient*)ext_client;
  579. JackLog("jack_set_graph_order_callback ext_client %x client %x \n", ext_client, client);
  580. if (client == NULL) {
  581. jack_error("jack_set_graph_order_callback called with a NULL client");
  582. return -1;
  583. } else {
  584. return client->SetGraphOrderCallback(graph_callback, arg);
  585. }
  586. }
  587. EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
  588. {
  589. #ifdef __CLIENTDEBUG__
  590. JackLibGlobals::CheckContext();
  591. #endif
  592. JackClient* client = (JackClient*)ext_client;
  593. if (client == NULL) {
  594. jack_error("jack_set_xrun_callback called with a NULL client");
  595. return -1;
  596. } else {
  597. return client->SetXRunCallback(xrun_callback, arg);
  598. }
  599. }
  600. EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
  601. {
  602. #ifdef __CLIENTDEBUG__
  603. JackLibGlobals::CheckContext();
  604. #endif
  605. JackClient* client = (JackClient*)ext_client;
  606. JackLog("jack_set_thread_init_callback ext_client %x client %x \n", ext_client, client);
  607. if (client == NULL) {
  608. jack_error("jack_set_thread_init_callback called with a NULL client");
  609. return -1;
  610. } else {
  611. return client->SetInitCallback(init_callback, arg);
  612. }
  613. }
  614. EXPORT int jack_activate(jack_client_t* ext_client)
  615. {
  616. #ifdef __CLIENTDEBUG__
  617. JackLibGlobals::CheckContext();
  618. #endif
  619. JackClient* client = (JackClient*)ext_client;
  620. if (client == NULL) {
  621. jack_error("jack_activate called with a NULL client");
  622. return -1;
  623. } else {
  624. return client->Activate();
  625. }
  626. }
  627. EXPORT int jack_deactivate(jack_client_t* ext_client)
  628. {
  629. #ifdef __CLIENTDEBUG__
  630. JackLibGlobals::CheckContext();
  631. #endif
  632. JackClient* client = (JackClient*)ext_client;
  633. if (client == NULL) {
  634. jack_error("jack_deactivate called with a NULL client");
  635. return -1;
  636. } else {
  637. return client->Deactivate();
  638. }
  639. }
  640. EXPORT jack_port_t* jack_port_register(jack_client_t* ext_client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
  641. {
  642. #ifdef __CLIENTDEBUG__
  643. JackLibGlobals::CheckContext();
  644. #endif
  645. JackClient* client = (JackClient*)ext_client;
  646. if (client == NULL) {
  647. jack_error("jack_port_register called with a NULL client");
  648. return NULL;
  649. } else if ((port_name == NULL) || (port_type == NULL)) {
  650. jack_error("jack_port_register called with a NULL port name or a NULL port_type");
  651. return NULL;
  652. } else {
  653. return (jack_port_t *)client->PortRegister(port_name, port_type, flags, buffer_size);
  654. }
  655. }
  656. EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
  657. {
  658. #ifdef __CLIENTDEBUG__
  659. JackLibGlobals::CheckContext();
  660. #endif
  661. JackClient* client = (JackClient*)ext_client;
  662. if (client == NULL) {
  663. jack_error("jack_port_unregister called with a NULL client");
  664. return -1;
  665. }
  666. jack_port_id_t myport = (jack_port_id_t)port;
  667. if (!CheckPort(myport)) {
  668. jack_error("jack_port_unregister called with an incorrect port %ld", myport);
  669. return -1;
  670. }
  671. return client->PortUnRegister(myport);
  672. }
  673. EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
  674. {
  675. #ifdef __CLIENTDEBUG__
  676. JackLibGlobals::CheckContext();
  677. #endif
  678. JackClient* client = (JackClient*)ext_client;
  679. if (client == NULL) {
  680. jack_error("jack_port_is_mine called with a NULL client");
  681. return -1;
  682. }
  683. jack_port_id_t myport = (jack_port_id_t)port;
  684. if (!CheckPort(myport)) {
  685. jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
  686. return -1;
  687. }
  688. return client->PortIsMine(myport);
  689. }
  690. EXPORT const char** jack_port_get_connections(const jack_port_t* port)
  691. {
  692. #ifdef __CLIENTDEBUG__
  693. JackLibGlobals::CheckContext();
  694. #endif
  695. jack_port_id_t myport = (jack_port_id_t)port;
  696. if (!CheckPort(myport)) {
  697. jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
  698. return NULL;
  699. } else {
  700. WaitGraphChange();
  701. return GetGraphManager()->GetConnections(myport);
  702. }
  703. }
  704. // Calling client does not need to "own" the port
  705. EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
  706. {
  707. #ifdef __CLIENTDEBUG__
  708. JackLibGlobals::CheckContext();
  709. #endif
  710. JackClient* client = (JackClient*)ext_client;
  711. if (client == NULL) {
  712. jack_error("jack_port_get_all_connections called with a NULL client");
  713. return NULL;
  714. }
  715. jack_port_id_t myport = (jack_port_id_t)port;
  716. if (!CheckPort(myport)) {
  717. jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
  718. return NULL;
  719. } else {
  720. WaitGraphChange();
  721. return GetGraphManager()->GetConnections(myport);
  722. }
  723. }
  724. // Does not use the client parameter
  725. EXPORT int jack_port_lock(jack_client_t* ext_client, jack_port_t* port)
  726. {
  727. #ifdef __CLIENTDEBUG__
  728. JackLibGlobals::CheckContext();
  729. #endif
  730. JackClient* client = (JackClient*)ext_client;
  731. if (client == NULL) {
  732. jack_error("jack_port_lock called with a NULL client");
  733. return -1;
  734. }
  735. jack_port_id_t myport = (jack_port_id_t)port;
  736. if (!CheckPort(myport)) {
  737. jack_error("jack_port_lock called with an incorrect port %ld", myport);
  738. return -1;
  739. } else {
  740. return (myport && client->PortIsMine(myport)) ? GetGraphManager()->GetPort(myport)->Lock() : -1;
  741. }
  742. }
  743. // Does not use the client parameter
  744. EXPORT int jack_port_unlock(jack_client_t* ext_client, jack_port_t* port)
  745. {
  746. #ifdef __CLIENTDEBUG__
  747. JackLibGlobals::CheckContext();
  748. #endif
  749. JackClient* client = (JackClient*)ext_client;
  750. if (client == NULL) {
  751. jack_error("jack_port_unlock called with a NULL client");
  752. return -1;
  753. }
  754. jack_port_id_t myport = (jack_port_id_t)port;
  755. if (!CheckPort(myport)) {
  756. jack_error("jack_port_unlock called with an incorrect port %ld", myport);
  757. return -1;
  758. } else {
  759. return (myport && client->PortIsMine(myport)) ? GetGraphManager()->GetPort(myport)->Unlock() : -1;
  760. }
  761. }
  762. EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
  763. {
  764. #ifdef __CLIENTDEBUG__
  765. JackLibGlobals::CheckContext();
  766. #endif
  767. JackClient* client = (JackClient*)ext_client;
  768. if (client == NULL) {
  769. jack_error("jack_port_get_total_latency called with a NULL client");
  770. return 0;
  771. }
  772. jack_port_id_t myport = (jack_port_id_t)port;
  773. if (!CheckPort(myport)) {
  774. jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
  775. return 0;
  776. } else {
  777. // The latency computation is done each time
  778. WaitGraphChange();
  779. return GetGraphManager()->GetTotalLatency(myport);
  780. }
  781. }
  782. EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
  783. {
  784. #ifdef __CLIENTDEBUG__
  785. JackLibGlobals::CheckContext();
  786. #endif
  787. JackClient* client = (JackClient*)ext_client;
  788. if (client == NULL) {
  789. jack_error("jack_connect called with a NULL client");
  790. return -1;
  791. } else if ((src == NULL) || (dst == NULL)) {
  792. jack_error("jack_connect called with a NULL port name");
  793. return -1;
  794. } else {
  795. return client->PortConnect(src, dst);
  796. }
  797. }
  798. EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
  799. {
  800. #ifdef __CLIENTDEBUG__
  801. JackLibGlobals::CheckContext();
  802. #endif
  803. JackClient* client = (JackClient*)ext_client;
  804. if (client == NULL) {
  805. jack_error("jack_disconnect called with a NULL client");
  806. return -1;
  807. } else if ((src == NULL) || (dst == NULL)) {
  808. jack_error("jack_connect called with a NULL port name");
  809. return -1;
  810. } else {
  811. return client->PortDisconnect(src, dst);
  812. }
  813. }
  814. EXPORT int jack_port_connect(jack_client_t* ext_client, jack_port_t* src, jack_port_t* dst)
  815. {
  816. #ifdef __CLIENTDEBUG__
  817. JackLibGlobals::CheckContext();
  818. #endif
  819. JackClient* client = (JackClient*)ext_client;
  820. if (client == NULL) {
  821. jack_error("jack_port_connect called with a NULL client");
  822. return -1;
  823. }
  824. jack_port_id_t mysrc = (jack_port_id_t)src;
  825. if (!CheckPort(mysrc)) {
  826. jack_error("jack_port_connect called with a NULL src port");
  827. return -1;
  828. }
  829. jack_port_id_t mydst = (jack_port_id_t)dst;
  830. if (!CheckPort(mydst)) {
  831. jack_error("jack_port_connect called with a NULL dst port");
  832. return -1;
  833. }
  834. return client->PortConnect(mysrc, mydst);
  835. }
  836. EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
  837. {
  838. #ifdef __CLIENTDEBUG__
  839. JackLibGlobals::CheckContext();
  840. #endif
  841. JackClient* client = (JackClient*)ext_client;
  842. if (client == NULL) {
  843. jack_error("jack_port_disconnect called with a NULL client");
  844. return -1;
  845. }
  846. jack_port_id_t myport = (jack_port_id_t)src;
  847. if (!CheckPort(myport)) {
  848. jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
  849. return -1;
  850. }
  851. return client->PortDisconnect(myport);
  852. }
  853. EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
  854. {
  855. #ifdef __CLIENTDEBUG__
  856. JackLibGlobals::CheckContext();
  857. #endif
  858. JackClient* client = (JackClient*)ext_client;
  859. if (client == NULL) {
  860. jack_error("jack_get_sample_rate called with a NULL client");
  861. return 0;
  862. } else {
  863. return GetEngineControl()->fSampleRate;
  864. }
  865. }
  866. EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
  867. {
  868. #ifdef __CLIENTDEBUG__
  869. JackLibGlobals::CheckContext();
  870. #endif
  871. JackClient* client = (JackClient*)ext_client;
  872. if (client == NULL) {
  873. jack_error("jack_get_buffer_size called with a NULL client");
  874. return 0;
  875. } else {
  876. return GetEngineControl()->fBufferSize;
  877. }
  878. }
  879. EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
  880. {
  881. #ifdef __CLIENTDEBUG__
  882. JackLibGlobals::CheckContext();
  883. #endif
  884. JackClient* client = (JackClient*)ext_client;
  885. if (client == NULL) {
  886. jack_error("jack_get_ports called with a NULL client");
  887. return NULL;
  888. }
  889. return GetGraphManager()->GetPorts(port_name_pattern, type_name_pattern, flags);
  890. }
  891. EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
  892. {
  893. #ifdef __CLIENTDEBUG__
  894. JackLibGlobals::CheckContext();
  895. #endif
  896. JackClient* client = (JackClient*)ext_client;
  897. if (client == NULL) {
  898. jack_error("jack_get_ports called with a NULL client");
  899. return 0;
  900. }
  901. if (portname == NULL) {
  902. jack_error("jack_port_by_name called with a NULL port name");
  903. return NULL;
  904. } else {
  905. int res = GetGraphManager()->GetPort(portname); // returns a port index at least > 1
  906. return (res == NO_PORT) ? NULL : (jack_port_t*)res;
  907. }
  908. }
  909. EXPORT jack_port_t* jack_port_by_id(const jack_client_t* ext_client, jack_port_id_t id)
  910. {
  911. #ifdef __CLIENTDEBUG__
  912. JackLibGlobals::CheckContext();
  913. #endif
  914. /* jack_port_t* type is actually the port index */
  915. return (jack_port_t*)id;
  916. }
  917. EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
  918. {
  919. #ifdef __CLIENTDEBUG__
  920. JackLibGlobals::CheckContext();
  921. #endif
  922. JackClient* client = (JackClient*)ext_client;
  923. if (client == NULL) {
  924. jack_error("jack_engine_takeover_timebase called with a NULL client");
  925. return -1;
  926. } else {
  927. jack_error("jack_engine_takeover_timebase : not yet implemented\n");
  928. return 0;
  929. }
  930. }
  931. EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
  932. {
  933. #ifdef __CLIENTDEBUG__
  934. JackLibGlobals::CheckContext();
  935. #endif
  936. JackTimer timer;
  937. GetEngineControl()->ReadFrameTime(&timer);
  938. return (jack_nframes_t) floor((((float)GetEngineControl()->fSampleRate) / 1000000.0f) * (GetMicroSeconds() - timer.fCurrentCallback));
  939. }
  940. EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
  941. {
  942. #ifdef __CLIENTDEBUG__
  943. JackLibGlobals::CheckContext();
  944. #endif
  945. JackClient* client = (JackClient*)ext_client;
  946. if (client == NULL) {
  947. jack_error("jack_frame_time called with a NULL client");
  948. return 0;
  949. } else {
  950. JackTimer timer;
  951. GetEngineControl()->ReadFrameTime(&timer);
  952. if (timer.fInitialized) {
  953. return timer.fFrames +
  954. (long) rint(((double) ((jack_time_t)(GetMicroSeconds() - timer.fCurrentWakeup)) /
  955. ((jack_time_t)(timer.fNextWakeUp - timer.fCurrentWakeup))) * GetEngineControl()->fBufferSize);
  956. } else {
  957. return 0;
  958. }
  959. }
  960. }
  961. EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
  962. {
  963. #ifdef __CLIENTDEBUG__
  964. JackLibGlobals::CheckContext();
  965. #endif
  966. JackTimer timer;
  967. GetEngineControl()->ReadFrameTime(&timer);
  968. return timer.fFrames;
  969. }
  970. EXPORT float jack_cpu_load(jack_client_t* ext_client)
  971. {
  972. #ifdef __CLIENTDEBUG__
  973. JackLibGlobals::CheckContext();
  974. #endif
  975. JackClient* client = (JackClient*)ext_client;
  976. if (client == NULL) {
  977. jack_error("jack_cpu_load called with a NULL client");
  978. return 0.0f;
  979. } else {
  980. return GetEngineControl()->fCPULoad;
  981. }
  982. }
  983. EXPORT pthread_t jack_client_thread_id(jack_client_t* ext_client)
  984. {
  985. #ifdef __CLIENTDEBUG__
  986. JackLibGlobals::CheckContext();
  987. #endif
  988. JackClient* client = (JackClient*)ext_client;
  989. if (client == NULL) {
  990. jack_error("jack_client_thread_id called with a NULL client");
  991. return (pthread_t)NULL;
  992. } else {
  993. return client->GetThreadID();
  994. }
  995. }
  996. EXPORT char* jack_get_client_name (jack_client_t* ext_client)
  997. {
  998. #ifdef __CLIENTDEBUG__
  999. JackLibGlobals::CheckContext();
  1000. #endif
  1001. JackClient* client = (JackClient*)ext_client;
  1002. if (client == NULL) {
  1003. jack_error("jack_get_client_name called with a NULL client");
  1004. return NULL;
  1005. } else {
  1006. return client->GetClientControl()->fName;
  1007. }
  1008. }
  1009. EXPORT int jack_client_name_size(void)
  1010. {
  1011. return JACK_CLIENT_NAME_SIZE;
  1012. }
  1013. EXPORT int jack_port_name_size(void)
  1014. {
  1015. return JACK_PORT_NAME_SIZE;
  1016. }
  1017. // transport.h
  1018. EXPORT int jack_release_timebase(jack_client_t* ext_client)
  1019. {
  1020. #ifdef __CLIENTDEBUG__
  1021. JackLibGlobals::CheckContext();
  1022. #endif
  1023. JackClient* client = (JackClient*)ext_client;
  1024. if (client == NULL) {
  1025. jack_error("jack_release_timebase called with a NULL client");
  1026. return -1;
  1027. } else {
  1028. return client->ReleaseTimebase();
  1029. }
  1030. }
  1031. EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
  1032. {
  1033. #ifdef __CLIENTDEBUG__
  1034. JackLibGlobals::CheckContext();
  1035. #endif
  1036. JackClient* client = (JackClient*)ext_client;
  1037. if (client == NULL) {
  1038. jack_error("jack_set_sync_callback called with a NULL client");
  1039. return -1;
  1040. } else {
  1041. return client->SetSyncCallback(sync_callback, arg);
  1042. }
  1043. }
  1044. EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
  1045. {
  1046. #ifdef __CLIENTDEBUG__
  1047. JackLibGlobals::CheckContext();
  1048. #endif
  1049. JackClient* client = (JackClient*)ext_client;
  1050. if (client == NULL) {
  1051. jack_error("jack_set_sync_timeout called with a NULL client");
  1052. return -1;
  1053. } else {
  1054. return client->SetSyncTimeout(timeout);
  1055. }
  1056. }
  1057. EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
  1058. {
  1059. #ifdef __CLIENTDEBUG__
  1060. JackLibGlobals::CheckContext();
  1061. #endif
  1062. JackClient* client = (JackClient*)ext_client;
  1063. if (client == NULL) {
  1064. jack_error("jack_set_timebase_callback called with a NULL client");
  1065. return -1;
  1066. } else {
  1067. return client->SetTimebaseCallback(conditional, timebase_callback, arg);
  1068. }
  1069. }
  1070. EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
  1071. {
  1072. #ifdef __CLIENTDEBUG__
  1073. JackLibGlobals::CheckContext();
  1074. #endif
  1075. JackClient* client = (JackClient*)ext_client;
  1076. if (client == NULL) {
  1077. jack_error("jack_transport_locate called with a NULL client");
  1078. return -1;
  1079. } else {
  1080. return client->TransportLocate(frame);
  1081. }
  1082. }
  1083. EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
  1084. {
  1085. #ifdef __CLIENTDEBUG__
  1086. JackLibGlobals::CheckContext();
  1087. #endif
  1088. JackClient* client = (JackClient*)ext_client;
  1089. if (client == NULL) {
  1090. jack_error("jack_transport_query called with a NULL client");
  1091. return JackTransportStopped;
  1092. } else {
  1093. return client->TransportQuery(pos);
  1094. }
  1095. }
  1096. EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
  1097. {
  1098. #ifdef __CLIENTDEBUG__
  1099. JackLibGlobals::CheckContext();
  1100. #endif
  1101. JackClient* client = (JackClient*)ext_client;
  1102. if (client == NULL) {
  1103. jack_error("jack_get_current_transport_frame called with a NULL client");
  1104. return 0;
  1105. } else {
  1106. return client->GetCurrentTransportFrame();
  1107. }
  1108. }
  1109. EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
  1110. {
  1111. #ifdef __CLIENTDEBUG__
  1112. JackLibGlobals::CheckContext();
  1113. #endif
  1114. JackClient* client = (JackClient*)ext_client;
  1115. if (client == NULL) {
  1116. jack_error("jack_transport_reposition called with a NULL client");
  1117. return -1;
  1118. } else {
  1119. return client->TransportReposition(pos);
  1120. }
  1121. }
  1122. EXPORT void jack_transport_start(jack_client_t* ext_client)
  1123. {
  1124. #ifdef __CLIENTDEBUG__
  1125. JackLibGlobals::CheckContext();
  1126. #endif
  1127. JackClient* client = (JackClient*)ext_client;
  1128. if (client == NULL) {
  1129. jack_error("jack_transport_start called with a NULL client");
  1130. } else {
  1131. client->TransportStart();
  1132. }
  1133. }
  1134. EXPORT void jack_transport_stop(jack_client_t* ext_client)
  1135. {
  1136. #ifdef __CLIENTDEBUG__
  1137. JackLibGlobals::CheckContext();
  1138. #endif
  1139. JackClient* client = (JackClient*)ext_client;
  1140. if (client == NULL) {
  1141. jack_error("jack_transport_stop called with a NULL client");
  1142. } else {
  1143. client->TransportStop();
  1144. }
  1145. }
  1146. // deprecated
  1147. EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1148. {
  1149. JackLog("jack_get_transport_info : deprecated");
  1150. if (tinfo)
  1151. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1152. }
  1153. EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1154. {
  1155. JackLog("jack_set_transport_info : deprecated");
  1156. if (tinfo)
  1157. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1158. }
  1159. // statistics.h
  1160. EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
  1161. {
  1162. #ifdef __CLIENTDEBUG__
  1163. JackLibGlobals::CheckContext();
  1164. #endif
  1165. JackLog("jack_get_max_delayed_usecs: not yet implemented\n");
  1166. return 0.f;
  1167. }
  1168. EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
  1169. {
  1170. #ifdef __CLIENTDEBUG__
  1171. JackLibGlobals::CheckContext();
  1172. #endif
  1173. JackLog("jack_get_xrun_delayed_usecs: not yet implemented\n");
  1174. return 0.f;
  1175. }
  1176. EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
  1177. {
  1178. #ifdef __CLIENTDEBUG__
  1179. JackLibGlobals::CheckContext();
  1180. #endif
  1181. JackLog("jack_reset_max_delayed_usecs: not yet implemented\n");
  1182. }
  1183. // thread.h
  1184. EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority)
  1185. {
  1186. #ifdef __APPLE__
  1187. return JackMachThread::AcquireRealTimeImp(thread, 0, 500 * 1000, 500 * 1000);
  1188. #elif WIN32
  1189. return JackWinThread::AcquireRealTimeImp(thread, priority);
  1190. #else
  1191. return JackPosixThread::AcquireRealTimeImp(thread, priority);
  1192. #endif
  1193. }
  1194. EXPORT int jack_client_create_thread(jack_client_t* client,
  1195. pthread_t *thread,
  1196. int priority,
  1197. int realtime, /* boolean */
  1198. void *(*start_routine)(void*),
  1199. void *arg)
  1200. {
  1201. #ifdef __APPLE__
  1202. return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg);
  1203. #elif WIN32
  1204. return JackWinThread::StartImp(thread, priority, realtime, (ThreadCallback)start_routine, arg);
  1205. #else
  1206. return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg);
  1207. #endif
  1208. }
  1209. EXPORT int jack_drop_real_time_scheduling(pthread_t thread)
  1210. {
  1211. #ifdef __APPLE__
  1212. return JackMachThread::DropRealTimeImp(thread);
  1213. #elif WIN32
  1214. return JackWinThread::DropRealTimeImp(thread);
  1215. #else
  1216. return JackPosixThread::DropRealTimeImp(thread);
  1217. #endif
  1218. }
  1219. // intclient.h
  1220. EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
  1221. {
  1222. JackLog("jack_get_internal_client_name: not yet implemented\n");
  1223. return "";
  1224. }
  1225. EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
  1226. {
  1227. JackLog("jack_internal_client_handle: not yet implemented\n");
  1228. return 0;
  1229. }
  1230. EXPORT jack_intclient_t jack_internal_client_load(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, ...)
  1231. {
  1232. JackLog("jack_internal_client_load: not yet implemented\n");
  1233. return 0;
  1234. }
  1235. EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
  1236. {
  1237. JackLog("jack_internal_client_unload: not yet implemented\n");
  1238. return JackFailure;
  1239. }
  1240. // Automatic jack server launch
  1241. #ifndef WIN32
  1242. #define JACK_LOCATION
  1243. #define JACK_DEFAULT_DRIVER
  1244. /* Exec the JACK server in this process. Does not return. */
  1245. static void start_server_aux(const char *server_name)
  1246. {
  1247. FILE* fp = 0;
  1248. char filename[255];
  1249. char arguments[255];
  1250. char buffer[255];
  1251. char* command = 0;
  1252. size_t pos = 0;
  1253. size_t result = 0;
  1254. char** argv = 0;
  1255. int i = 0;
  1256. int good = 0;
  1257. int ret;
  1258. snprintf(filename, 255, "%s/.jackdrc", getenv("HOME"));
  1259. fp = fopen(filename, "r");
  1260. if (!fp) {
  1261. fp = fopen("/etc/jackdrc", "r");
  1262. }
  1263. /* if still not found, check old config name for backwards compatability */
  1264. if (!fp) {
  1265. fp = fopen("/etc/jackd.conf", "r");
  1266. }
  1267. if (fp) {
  1268. arguments[0] = '\0';
  1269. ret = fscanf(fp, "%s", buffer);
  1270. while(ret != 0 && ret != EOF) {
  1271. strcat(arguments, buffer);
  1272. strcat(arguments, " ");
  1273. ret = fscanf(fp, "%s", buffer);
  1274. }
  1275. if (strlen(arguments) > 0) {
  1276. good = 1;
  1277. }
  1278. }
  1279. if (!good) {
  1280. command = JACK_LOCATION "/jackdmp";
  1281. strncpy(arguments, JACK_LOCATION "/jackdmp -T -d "JACK_DEFAULT_DRIVER, 255);
  1282. } else {
  1283. result = strcspn(arguments, " ");
  1284. command = (char *) malloc(result+1);
  1285. strncpy(command, arguments, result);
  1286. command[result] = '\0';
  1287. }
  1288. argv = (char **) malloc (255);
  1289. while (1) {
  1290. /* insert -T and -nserver_name in front of arguments */
  1291. if (i == 1) {
  1292. argv[i] = (char *) malloc(strlen ("-T") + 1);
  1293. strcpy (argv[i++], "-T");
  1294. if (server_name) {
  1295. size_t optlen = strlen ("-n");
  1296. char* buf = (char*)malloc(optlen + strlen (server_name) + 1);
  1297. strcpy (buf, "-n");
  1298. strcpy (buf+optlen, server_name);
  1299. argv[i++] = buf;
  1300. }
  1301. }
  1302. result = strcspn(arguments + pos, " ");
  1303. if (result == 0) {
  1304. break;
  1305. }
  1306. argv[i] = (char*)malloc(result + 1);
  1307. strncpy(argv[i], arguments+pos, result);
  1308. argv[i][result] = '\0';
  1309. pos += result + 1;
  1310. ++i;
  1311. }
  1312. argv[i] = 0;
  1313. execv(command, argv);
  1314. /* If execv() succeeds, it does not return. There's no point
  1315. * in calling jack_error() here in the child process. */
  1316. perror("exec of JACK server failed");
  1317. }
  1318. static int start_server(const char *server_name, jack_options_t options)
  1319. {
  1320. if ((options & JackNoStartServer) || getenv("JACK_NO_START_SERVER")) {
  1321. return 1;
  1322. }
  1323. /* The double fork() forces the server to become a child of
  1324. * init, which will always clean up zombie process state on
  1325. * termination. This even works in cases where the server
  1326. * terminates but this client does not.
  1327. *
  1328. * Since fork() is usually implemented using copy-on-write
  1329. * virtual memory tricks, the overhead of the second fork() is
  1330. * probably relatively small.
  1331. */
  1332. switch (fork()) {
  1333. case 0: /* child process */
  1334. switch (fork()) {
  1335. case 0: /* grandchild process */
  1336. start_server_aux(server_name);
  1337. _exit(99); /* exec failed */
  1338. case -1:
  1339. _exit(98);
  1340. default:
  1341. _exit(0);
  1342. }
  1343. case -1: /* fork() error */
  1344. return 1; /* failed to start server */
  1345. }
  1346. /* only the original parent process goes here */
  1347. return 0; /* (probably) successful */
  1348. }
  1349. int server_connect(char* name)
  1350. {
  1351. return -1;
  1352. }
  1353. int try_start_server(jack_varargs_t* va, jack_options_t options, jack_status_t* status)
  1354. {
  1355. if (server_connect(va->server_name) < 0) {
  1356. int trys;
  1357. if (start_server(va->server_name, options)) {
  1358. int my_status1 = *status | JackFailure | JackServerFailed;
  1359. *status = (jack_status_t)my_status1;
  1360. return -1;
  1361. }
  1362. trys = 5;
  1363. do {
  1364. sleep(1);
  1365. if (--trys < 0) {
  1366. int my_status1 = *status | JackFailure | JackServerFailed;
  1367. *status = (jack_status_t)my_status1;
  1368. return -1;
  1369. }
  1370. } while (server_connect(va->server_name) < 0);
  1371. int my_status1 = *status | JackServerStarted;
  1372. *status = (jack_status_t)my_status1;
  1373. }
  1374. return 0;
  1375. }
  1376. #endif