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.

1892 lines
74KB

  1. /*
  2. Copyright (C) 2005 Samuel TRACOL for GRAME
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 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 General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. /** @file jack_test.c
  16. *
  17. * @brief This client test the jack API.
  18. *
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <errno.h>
  23. #ifndef WIN32
  24. #include <unistd.h>
  25. #endif
  26. #include <string.h>
  27. #include <getopt.h>
  28. #include <math.h>
  29. #include <assert.h>
  30. #include <stdarg.h>
  31. #include "jack.h"
  32. #include "transport.h"
  33. #ifdef WIN32
  34. #define M_PI 3.151592653
  35. #endif
  36. #ifdef WIN32
  37. #define jack_sleep(val) Sleep((val))
  38. #else
  39. #define jack_sleep(val) usleep((val) * 1000)
  40. #endif
  41. typedef struct
  42. {
  43. jack_nframes_t ft; // running counter frame time
  44. jack_nframes_t fcs; // from sycle start...
  45. jack_nframes_t lft; // last frame time...
  46. }
  47. FrameTimeCollector;
  48. FILE *file;
  49. FrameTimeCollector* framecollect;
  50. FrameTimeCollector perpetualcollect;
  51. FrameTimeCollector lastperpetualcollect;
  52. int frames_collected = 0;
  53. // ports
  54. jack_port_t *output_port1;
  55. jack_port_t *output_port1b;
  56. jack_port_t *input_port2;
  57. jack_port_t *output_port2;
  58. jack_port_t *input_port1;
  59. // clients
  60. jack_client_t *client1;
  61. jack_client_t *client2;
  62. const char *client_name1;
  63. const char *client_name2;
  64. unsigned long sr; // sample rate
  65. // for time -t option
  66. int time_to_run = 0;
  67. int time_before_exit = 1;
  68. // standard error count
  69. int t_error = 0;
  70. int reorder = 0; // graph reorder callback
  71. int RT = 0; // is real time or not...
  72. int FW = 0; // freewheel mode
  73. int init_clbk = 0; // init callback
  74. int i, j, k = 0;
  75. int port_callback_reg = 0;
  76. jack_nframes_t cur_buffer_size, old_buffer_size, cur_pos;
  77. int activated = 0;
  78. int count1, count2 = 0; // for freewheel
  79. int xrun = 0;
  80. int have_xrun = 0; // msg to tell the process1 function to write a special thing in the frametime file.
  81. int process1_activated = -1; // to control processing...
  82. int process2_activated = -1; // to control processing...
  83. unsigned long int index1 = 0;
  84. unsigned long int index2 = 0;
  85. jack_default_audio_sample_t *signal1; // signal source d'emission
  86. jack_default_audio_sample_t *signal2; // tableau de reception
  87. jack_transport_state_t ts;
  88. jack_position_t pos;
  89. jack_position_t request_pos;
  90. int silent_error = 0; // jack silent mode
  91. int verbose_mode = 0;
  92. int transport_mode = 1;
  93. int ext_latency = 0; // test latency for PHY devices
  94. int sync_called = 0;
  95. int starting_state = 1;
  96. int linecount = 0; // line counter for log file of sampleframe counter --> for graph function.
  97. int linebuf = 0; // reminders for graph analysis
  98. int linetransport = 0;
  99. int linefw = 0;
  100. int lineports = 0;
  101. int linecl2 = 0;
  102. /**
  103. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  104. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  105. Callbacks & basics functions
  106. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  107. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  108. */
  109. void usage()
  110. {
  111. fprintf (stderr, "\n\n"
  112. "usage: jack_test \n"
  113. " [ --time OR -t time_to_run (in seconds) ]\n"
  114. " [ --quiet OR -q (quiet mode : without jack server errors) ]\n"
  115. " [ --verbose OR -v (verbose mode : no details on tests done. Only main results & errors) ]\n"
  116. " [ --transport OR -k (Do not test transport functions.) ]\n"
  117. " --realtime OR -R (jack is in rt mode)\n\n\n"
  118. );
  119. exit(1);
  120. }
  121. void Log(char *fmt, ...)
  122. {
  123. if (verbose_mode) {
  124. va_list ap;
  125. va_start(ap, fmt);
  126. vfprintf(stderr, fmt, ap);
  127. va_end(ap);
  128. }
  129. }
  130. void Collect(FrameTimeCollector* TheFrame)
  131. {
  132. TheFrame->lft = jack_last_frame_time(client1);
  133. TheFrame->ft = jack_frame_time(client1);
  134. TheFrame->fcs = jack_frames_since_cycle_start(client1);
  135. }
  136. void Jack_Thread_Init_Callback(void *arg)
  137. {
  138. Log("Init callback has been successfully called. (msg from callback)\n");
  139. init_clbk = 1;
  140. }
  141. void Jack_Freewheel_Callback(int starting, void *arg)
  142. {
  143. Log("Freewhell callback has been successfully called with value %i. (msg from callback)\n", starting);
  144. FW = starting;
  145. }
  146. void Jack_Client_Registration_Callback(const char* name, int val, void *arg)
  147. {
  148. Log("Client registration callback name = %s has been successfully called with value %i. (msg from callback)\n", name, val);
  149. }
  150. int Jack_Update_Buffer_Size(jack_nframes_t nframes, void *arg)
  151. {
  152. cur_buffer_size = jack_get_buffer_size(client1);
  153. Log("Buffer size = %d (msg from callback)\n", cur_buffer_size);
  154. return 0;
  155. }
  156. int Jack_XRun_Callback(void *arg)
  157. {
  158. xrun++;
  159. have_xrun = 1;
  160. printf("Xrun has been detected ! (msg from callback)\n");
  161. return 0;
  162. }
  163. int Jack_Graph_Order_Callback(void *arg)
  164. {
  165. reorder++;
  166. return 0;
  167. }
  168. int Jack_Sample_Rate_Callback(jack_nframes_t nframes, void *arg)
  169. {
  170. Log("Sample rate : %i.\n", nframes);
  171. return 0;
  172. }
  173. void Jack_Error_Callback(const char *msg)
  174. {
  175. if (silent_error == 0) {
  176. fprintf(stderr, "error : %s (msg from callback)\n", msg);
  177. }
  178. }
  179. void jack_shutdown(void *arg)
  180. {
  181. printf("Jack_test has been kicked out by jackd !\n");
  182. exit (1);
  183. }
  184. void Jack_Port_Register(jack_port_id_t port, int mode, void *arg)
  185. {
  186. port_callback_reg++;
  187. }
  188. int Jack_Sync_Callback(jack_transport_state_t state, jack_position_t *pos, void *arg)
  189. {
  190. int res = 0;
  191. switch (state) {
  192. case JackTransportStarting:
  193. sync_called++;
  194. if (starting_state == 0) {
  195. Log("sync callback : Releasing status : now ready...\n");
  196. res = 1;
  197. } else {
  198. if (sync_called == 1) {
  199. Log("sync callback : Holding status...\n");
  200. }
  201. res = 0;
  202. }
  203. break;
  204. case JackTransportStopped:
  205. Log("sync callback : JackTransportStopped...\n");
  206. res = 0;
  207. break;
  208. default:
  209. res = 0;
  210. break;
  211. }
  212. return res;
  213. }
  214. /**
  215. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  216. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  217. processing functions
  218. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  219. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  220. * Proccess1 is for client1
  221. * 4 modes, activated with process1_activated
  222. *
  223. * -1 : idle mode
  224. * 0 : write zeros to output 1
  225. * 1 : write continuously signal1 (sinusoïdal test signal) to output1
  226. * 3 : mode for summation test. While record (done by process2) is not running, write signal1 to both out1 & out1b.
  227. * when record begin (index2 > 0), write signal1 in phase opposition to out1 & out2
  228. * 5 : Frames Time checking mode : write the array containing the three values of frame_time, frames cycles start and
  229. * last frame time during 150 cycles.
  230. */
  231. int process1(jack_nframes_t nframes, void *arg)
  232. {
  233. if (FW == 0) {
  234. Collect(&perpetualcollect);
  235. if (have_xrun) {
  236. fprintf(file, "%i %i\n", (perpetualcollect.ft - lastperpetualcollect.ft), (2*cur_buffer_size));
  237. have_xrun = 0;
  238. } else {
  239. fprintf(file, "%i 0\n", (perpetualcollect.ft - lastperpetualcollect.ft));
  240. }
  241. linecount++;
  242. lastperpetualcollect.ft = perpetualcollect.ft;
  243. }
  244. jack_default_audio_sample_t *out1;
  245. jack_default_audio_sample_t *out1b;
  246. activated++; // counter of callback activation
  247. if (process1_activated == 1) {
  248. out1 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1, nframes);
  249. for (int p = 0; p < nframes;p++) {
  250. out1[p] = signal1[index1];
  251. index1++;
  252. if (index1 == 48000)
  253. index1 = 0;
  254. }
  255. }
  256. if (process1_activated == 3) {
  257. out1 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1, nframes);
  258. out1b = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1b, nframes);
  259. for (int p = 0; p < nframes;p++) {
  260. out1[p] = signal1[index1];
  261. if (index2 != 0) {
  262. out1b[p] = ( -1 * signal1[index1]);
  263. } else {
  264. out1b[p] = signal1[index1];
  265. }
  266. index1++;
  267. if (index1 == 48000)
  268. index1 = 0;
  269. }
  270. }
  271. if (process1_activated == 0) {
  272. out1 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1, nframes);
  273. memset (out1, 0, sizeof (jack_default_audio_sample_t) * nframes); //écrit des zéros en sortie...
  274. }
  275. if (process1_activated == 5) {
  276. Collect(&framecollect[frames_collected]);
  277. frames_collected++;
  278. if (frames_collected > 798) {
  279. process1_activated = -1;
  280. }
  281. }
  282. return 0;
  283. }
  284. /**
  285. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  286. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  287. * Proccess2 is for client2
  288. * 3 modes, activated with process1_activated
  289. *
  290. * -1 : idle mode
  291. * 0 : idle mode
  292. * 1 : record in2 into signal2.(for first transmit test)
  293. * 2 : record in2 into signal2 while send signal1 in out2. used dor Tie data test.
  294. * 3 : record in2 into sigal2 for summation data test.
  295. * In records modes, at the end of the record (signal2 is full), it stop the test, setting both activation states to -1.
  296. */
  297. int process2(jack_nframes_t nframes, void *arg)
  298. {
  299. jack_default_audio_sample_t *out2;
  300. jack_default_audio_sample_t *in2;
  301. if (process2_activated == 1) { // Reception du process1 pour comparer les donnees
  302. in2 = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port2, nframes);
  303. for (int p = 0; p < nframes;p++) {
  304. signal2[index2] = in2[p];
  305. if (index2 == 95999) {
  306. process2_activated = 0;
  307. process1_activated = 0;
  308. //index2 = 0;
  309. } else {
  310. index2++;
  311. }
  312. }
  313. }
  314. if (process2_activated == 2) { // envoie de signal1 pour test tie mode et le récupère direct + latence de la boucle jack...
  315. out2 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port2, nframes);
  316. in2 = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port2, nframes);
  317. for (int p = 0; p < nframes;p++) {
  318. out2[p] = signal1[index1];
  319. index1++;
  320. if (index1 == 48000)
  321. index1 = 0;
  322. signal2[index2] = in2[p];
  323. if (index2 == 95999) {
  324. process2_activated = -1;
  325. //index2 = 0;
  326. } else {
  327. index2++;
  328. }
  329. }
  330. }
  331. if (process2_activated == 3) { // envoie de -signal1 pour sommation en oppo de phase par jack
  332. in2 = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port2, nframes);
  333. for (int p = 0; p < nframes;p++) {
  334. signal2[index2] = in2[p];
  335. if (index2 == 95999) {
  336. process2_activated = 0;
  337. process1_activated = 0;
  338. //index2 = 0;
  339. } else {
  340. index2++;
  341. }
  342. }
  343. }
  344. return 0;
  345. }
  346. // To test callback exiting
  347. int process3(jack_nframes_t nframes, void *arg)
  348. {
  349. static int process3_call = 0;
  350. if (process3_call++ > 10) {
  351. Log("process3 callback : exiting...\n");
  352. return -1;
  353. } else {
  354. Log("calling process3 callback : process3_call = %ld\n", process3_call);
  355. return 0;
  356. }
  357. }
  358. int process4(jack_nframes_t nframes, void *arg)
  359. {
  360. static jack_nframes_t last_time = jack_frame_time((jack_client_t*)arg);
  361. static jack_nframes_t tolerance = (jack_nframes_t)(cur_buffer_size * 0.1f);
  362. jack_nframes_t cur_time = jack_frame_time((jack_client_t*)arg);
  363. jack_nframes_t delta_time = cur_time - last_time;
  364. Log("calling process4 callback : jack_frame_time = %ld delta_time = %ld\n", cur_time, delta_time);
  365. if (delta_time > 0 && abs(delta_time - cur_buffer_size) > tolerance) {
  366. printf("!!! ERROR !!! jack_frame_time seems to return incorrect values cur_buffer_size = %ld, delta_time = %ld\n", cur_buffer_size, delta_time);
  367. }
  368. last_time = cur_time;
  369. return 0;
  370. }
  371. static void display_transport_state()
  372. {
  373. jack_transport_state_t ts;
  374. jack_position_t pos;
  375. ts = jack_transport_query(client2, &pos);
  376. switch (ts) {
  377. case JackTransportStopped:
  378. Log("Transport is stopped...\n");
  379. break;
  380. case JackTransportRolling:
  381. Log("Transport is rolling...\n");
  382. break;
  383. case JackTransportLooping:
  384. Log("Transport is looping...\n");
  385. break;
  386. case JackTransportStarting:
  387. Log("Transport is starting...\n");
  388. break;
  389. }
  390. }
  391. /**
  392. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  393. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  394. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  395. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  396. MAIN FUNCTION
  397. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  398. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  399. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  400. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  401. */
  402. int main (int argc, char *argv[])
  403. {
  404. const char **inports; // array of PHY input/output
  405. const char **outports; // array of PHY input/outputs
  406. const char *server_name = NULL;
  407. const char **connexions1;
  408. const char **connexions2;
  409. jack_status_t status;
  410. char portname[128] = "port";
  411. char filename[128] = "framefile.ext";
  412. char *nullportname = "";
  413. int option_index;
  414. int opt;
  415. int a = 0; // working number for in/out port (PHY)...
  416. int test_link = 0; // for testing the "overconnect" function
  417. int flag; // flag for ports...
  418. int is_mine = 0; // to test jack_port_is_mine function...
  419. int connected = 0; // check connect functions of ports
  420. const char *options = "kRnqvt:";
  421. float ratio; // for speed calculation in freewheel mode
  422. jack_options_t jack_options = JackNullOption;
  423. struct option long_options[] = {
  424. {"realtime", 0, 0, 'R'
  425. },
  426. {"non-realtime", 0, 0, 'n'},
  427. {"time", 0, 0, 't'},
  428. {"quiet", 0, 0, 'q'},
  429. {"verbose", 0, 0, 'v'},
  430. {"transport", 0, 0, 'k'},
  431. {0, 0, 0, 0}
  432. };
  433. client_name1 = "jack_test";
  434. time_to_run = 1;
  435. while ((opt = getopt_long (argc, argv, options, long_options, &option_index)) != EOF) {
  436. switch (opt) {
  437. case 'k':
  438. transport_mode = 0;
  439. break;
  440. case 'q':
  441. silent_error = 1;
  442. break;
  443. case 'v':
  444. verbose_mode = 1;
  445. printf("Verbose mode is activated...\n");
  446. break;
  447. case 't':
  448. time_to_run = atoi(optarg);
  449. break;
  450. case 'R':
  451. RT = 1;
  452. break;
  453. default:
  454. fprintf (stderr, "unknown option %c\n", opt);
  455. usage ();
  456. }
  457. }
  458. if (RT) {
  459. printf("Jack server is said being in realtime mode...\n");
  460. } else {
  461. printf("Jack server is said being in non-realtime mode...\n");
  462. }
  463. /**
  464. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  465. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  466. init signal data for test
  467. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  468. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  469. */
  470. framecollect = (FrameTimeCollector *) malloc(800 * sizeof(FrameTimeCollector));
  471. signal1 = (jack_default_audio_sample_t *) malloc(48000 * sizeof(jack_default_audio_sample_t));
  472. signal2 = (jack_default_audio_sample_t *) malloc(96000 * sizeof(jack_default_audio_sample_t));
  473. signal1[0] = 0;
  474. int p;
  475. for (p = 1; p < 48000;p++) {
  476. signal1[p] = (sin((p * 2 * M_PI * 1000 ) / 48000));
  477. }
  478. for (p = 0; p < 95999;p++) {
  479. signal2[p] = 0.0 ;
  480. }
  481. index1 = 0;
  482. index2 = 0;
  483. /**
  484. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  485. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  486. begin test
  487. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  488. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  489. */
  490. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  491. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  492. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-* Start jack server stress test *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  493. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  494. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  495. /**
  496. * Register a client...
  497. *
  498. */
  499. Log("Register a client using jack_client_open()...\n");
  500. client1 = jack_client_open(client_name1, jack_options, &status, server_name);
  501. if (client1 == NULL) {
  502. fprintf (stderr, "jack_client_open() failed, "
  503. "status = 0x%2.0x\n", status);
  504. if (status & JackServerFailed) {
  505. fprintf(stderr, "Unable to connect to JACK server\n");
  506. }
  507. exit (1);
  508. }
  509. if (status & JackServerStarted) {
  510. fprintf(stderr, "JACK server started\n");
  511. }
  512. /**
  513. * try to register another one with the same name...
  514. *
  515. */
  516. Log("trying to register a new jackd client with name %s using jack_client_new()...\n", client_name1);
  517. client2 = jack_client_new(client_name1);
  518. if (client2 == NULL) {
  519. Log ("valid : a second client with the same name cannot be registered\n");
  520. } else {
  521. printf("!!! ERROR !!! Jackd server has accepted multiples client with the same name !");
  522. jack_client_close(client2);
  523. }
  524. /**
  525. * testing client name...
  526. * Verify that the name sended at registration and the one returned by jack server is the same...
  527. *
  528. */
  529. Log("Testing name...");
  530. client_name2 = jack_get_client_name(client1);
  531. if (strcmp(client_name1, client_name2) == 0)
  532. Log(" ok\n");
  533. else
  534. printf("\n!!! ERROR !!! name returned different from the one given : %s\n", client_name2);
  535. /**
  536. * Test RT mode...
  537. * verify if the real time mode returned by jack match the optional argument defined when launching jack_test*/
  538. if (jack_is_realtime(client1) == RT)
  539. Log("Jackd is in realtime mode (RT = %i).\n", RT);
  540. else
  541. printf("!!! ERROR !!! Jackd is in a non-expected realtime mode (RT = %i).\n", RT);
  542. /**
  543. * Register all callbacks...
  544. *
  545. */
  546. if (jack_set_thread_init_callback(client1, Jack_Thread_Init_Callback, 0) != 0)
  547. printf("!!! ERROR !!! while calling jack_set_thread_init_callback()...\n");
  548. if (jack_set_freewheel_callback(client1, Jack_Freewheel_Callback, 0) != 0 )
  549. printf("\n!!! ERROR !!! while calling jack_set_freewheel_callback()...\n");
  550. if (jack_set_process_callback(client1, process1, 0) != 0) {
  551. printf("Error when calling jack_set_process_callback() !\n");
  552. }
  553. jack_on_shutdown(client1, jack_shutdown, 0);
  554. if (jack_set_buffer_size_callback(client1, Jack_Update_Buffer_Size, 0) != 0) {
  555. printf("Error when calling buffer_size_callback !\n");
  556. }
  557. if (jack_set_graph_order_callback(client1, Jack_Graph_Order_Callback, 0) != 0) {
  558. printf("Error when calling Jack_Graph_Order_Callback() !\n");
  559. }
  560. if (jack_set_xrun_callback(client1, Jack_XRun_Callback, 0 ) != 0) {
  561. printf("Error when calling jack_set_xrun_callback() !\n");
  562. }
  563. if (jack_set_sample_rate_callback(client1, Jack_Sample_Rate_Callback, 0 ) != 0) {
  564. printf("Error when calling Jack_Sample_Rate_Callback() !\n");
  565. }
  566. if (jack_set_port_registration_callback(client1, Jack_Port_Register, 0) != 0) {
  567. printf("Error when calling jack_set_port_registration_callback() !\n");
  568. }
  569. if (jack_set_client_registration_callback(client1, Jack_Client_Registration_Callback, 0) != 0) {
  570. printf("Error when calling jack_set_client_registration_callback() !\n");
  571. }
  572. jack_set_error_function(Jack_Error_Callback);
  573. /**
  574. * Create file for clock "frame time" analysis
  575. *
  576. */
  577. cur_buffer_size = jack_get_buffer_size(client1);
  578. sprintf (filename, "framefile-%i.dat", cur_buffer_size);
  579. file = fopen(filename, "w");
  580. if (file == NULL) {
  581. fprintf(stderr, "Erreur dans l'ouverture du fichier log framefile.dat");
  582. exit( -1);
  583. }
  584. /**
  585. * Try to register a client with a NULL name/zero length name...
  586. *
  587. */
  588. output_port1 = jack_port_register(client1, nullportname,
  589. JACK_DEFAULT_AUDIO_TYPE,
  590. JackPortIsOutput, 0);
  591. if (output_port1 == NULL) {
  592. Log("Can't register a port with a NULL portname... ok.\n");
  593. } else {
  594. printf("!!! ERROR !!! Can register a port with a NULL portname !\n");
  595. jack_port_unregister(client1, output_port1);
  596. }
  597. /**
  598. * Register 1 port in order to stress other functions.
  599. *
  600. */
  601. output_port1 = jack_port_register(client1, portname,
  602. JACK_DEFAULT_AUDIO_TYPE,
  603. JackPortIsOutput, 0);
  604. if (output_port1 == NULL) {
  605. printf("!!! ERROR !!! Can't register any port for the client !\n");
  606. exit(1);
  607. }
  608. /**
  609. * Test port type of the just registered port.
  610. *
  611. */
  612. if (strcmp(jack_port_type(output_port1), JACK_DEFAULT_AUDIO_TYPE) != 0) {
  613. printf("!!! ERROR !!! jack_port_type returns an incorrect value!\n");
  614. } else {
  615. Log("Checking jack_port_type()... ok.\n");
  616. }
  617. /**
  618. * Try to register another port with the same name...
  619. *
  620. */
  621. output_port2 = jack_port_register(client1, portname,
  622. JACK_DEFAULT_AUDIO_TYPE,
  623. JackPortIsOutput, 0);
  624. if (output_port2 == NULL) {
  625. Log("Can't register two ports with the same name... ok\n");
  626. } else {
  627. if (strcmp (jack_port_name(output_port1), jack_port_name(output_port2)) == 0) {
  628. printf("!!! ERROR !!! Can register two ports with the same name ! (%i : %s & %i : %s).\n", output_port1, jack_port_name(output_port1), output_port2, jack_port_name(output_port2));
  629. jack_port_unregister(client1, output_port2);
  630. } else {
  631. Log("Can't register two ports with the same name... ok (auto-rename %s into %s).\n", jack_port_name(output_port1), jack_port_name(output_port2));
  632. jack_port_unregister(client1, output_port2);
  633. }
  634. }
  635. /**
  636. * Verify that both port_name and port_short_name return correct results...
  637. *
  638. */
  639. sprintf (portname, "%s:%s", jack_get_client_name(client1), jack_port_short_name(output_port1));
  640. if (strcmp(jack_port_name(output_port1), portname) != 0) {
  641. printf("!!! ERROR !!! functions jack_port_name and/or jack_short_port_name seems to be invalid !\n");
  642. printf("client_name = %s\n short_port_name = %s\n port_name = %s\n", jack_get_client_name(client1), jack_port_short_name(output_port1), jack_port_name(output_port1));
  643. }
  644. /**
  645. * Verify the function port_set_name
  646. *
  647. */
  648. if (jack_port_set_name (output_port1, "renamed-port#") == 0 ) {
  649. if (strcmp(jack_port_name(output_port1), "renamed-port#") == 0) {
  650. printf("!!! ERROR !!! functions jack_port_set_name seems to be invalid !\n");
  651. printf("Jack_port_name return '%s' whereas 'renamed-port#' was expected...\n");
  652. } else {
  653. Log("Checking jack_port_set_name()... ok\n");
  654. jack_port_set_name (output_port1, "port");
  655. }
  656. } else {
  657. printf("error : port_set_name function can't be tested...\n");
  658. }
  659. /**
  660. * Activate the client
  661. *
  662. */
  663. if (jack_activate(client1) < 0) {
  664. printf ("Fatal error : cannot activate client1\n");
  665. exit (1);
  666. }
  667. /**
  668. * Test if init callback initThread have been called.
  669. *
  670. */
  671. if (init_clbk == 0)
  672. printf("!!! ERROR !!! JackThreadInitCallback was not called !!.\n");
  673. jack_sleep(10 * 1000); // test see the clock in the graph at the begining...
  674. /**
  675. * Stress Freewheel mode...
  676. * Try to enter freewheel mode. Check the realtime mode de-activation.
  677. * Check that the number of call of the process callback is greater than in non-freewheel mode.
  678. * Give an approximated speed ratio (number of process call) between the two modes.
  679. * Then return in normal mode.
  680. */
  681. t_error = 0;
  682. activated = 0;
  683. jack_sleep(1 * 1000);
  684. count1 = activated;
  685. Log("Testing activation freewheel mode...\n");
  686. linefw = linecount; // count for better graph reading with gnuplot
  687. jack_set_freewheel(client1, 1);
  688. activated = 0;
  689. jack_sleep(1 * 1000);
  690. count2 = activated;
  691. if (jack_is_realtime(client1) == 0) {
  692. t_error = 0;
  693. } else {
  694. printf("\n!!! ERROR !!! RT mode is always activated while freewheel mode is applied !\n");
  695. t_error = 1;
  696. }
  697. if (activated == 0)
  698. printf("!!! ERROR !!! Freewheel mode doesn't activate audio callback !!\n");
  699. jack_set_freewheel(client1, 0);
  700. jack_sleep(7 * 1000);
  701. if (jack_is_realtime(client1) == 1) {}
  702. else {
  703. printf("\n!!! ERROR !!! freewheel mode fail to reactivate RT mode when exiting !\n");
  704. t_error = 1;
  705. }
  706. if (t_error == 0) {
  707. Log("Freewheel mode appears to work well...\n");
  708. }
  709. if (count1 == 0) {
  710. Log("Audio Callback in 'standard' (non-freewheel) mode seems not to be called...\n");
  711. Log("Ratio speed would be unavailable...\n");
  712. } else {
  713. ratio = (float) ((count2 - count1) / count1);
  714. Log("Approximative speed ratio of freewheel mode = %f : 1.00\n", ratio);
  715. }
  716. /**
  717. * Stress buffer function...
  718. * get current buffer size.
  719. * Try to apply a new buffer size value ( 2 x the precedent buffer size value)
  720. * Then return in previous buffer size mode.
  721. *
  722. */
  723. float factor = 0.5f;
  724. old_buffer_size = jack_get_buffer_size(client1);
  725. Log("Testing BufferSize change & Callback...\n--> Current buffer size : %i.\n", old_buffer_size);
  726. linebuf = linecount;
  727. if (jack_set_buffer_size(client1, (jack_nframes_t)(old_buffer_size * factor)) < 0) {
  728. printf("!!! ERROR !!! jack_set_buffer_size fails !\n");
  729. }
  730. jack_sleep(1 * 1000);
  731. cur_buffer_size = jack_get_buffer_size(client1);
  732. if ((old_buffer_size * factor) != cur_buffer_size) {
  733. printf("!!! ERROR !!! Buffer size has not been changed !\n");
  734. printf("!!! Maybe jack was compiled without the '--enable-resize' flag...\n");
  735. } else {
  736. Log("jack_set_buffer_size() command successfully applied...\n");
  737. }
  738. jack_sleep(3 * 1000);
  739. jack_set_buffer_size(client1, old_buffer_size);
  740. cur_buffer_size = jack_get_buffer_size(client1);
  741. /**
  742. * Test the last regestered port to see if port_is_mine function the right value.
  743. * A second test will be performed later.
  744. * The result will be printed at the end.
  745. *
  746. */
  747. if (jack_port_is_mine(client1, output_port1)) {
  748. is_mine = 1;
  749. } else {
  750. is_mine = 0;
  751. }
  752. /**
  753. * Check that the ID returned by the port_by_name is right.
  754. * (it seems there is a problem here in some jack versions).
  755. *
  756. */
  757. if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
  758. printf("!!! ERROR !!! function jack_port_by_name() return bad value !\n");
  759. printf("!!! jack_port_by_name(jack_port_name(_ID_) ) != _ID_returned_at_port_registering ! (%i != %i)\n", jack_port_by_name(client1, jack_port_name(output_port1)), output_port1);
  760. } else {
  761. Log("Checking jack_port_by_name() return value... ok\n");
  762. }
  763. if (NULL != jack_port_by_name(client1, jack_port_short_name(output_port1))) {
  764. printf("!!! ERROR !!! function jack_port_by_name() return a value (%i) while name is incomplete !\n", jack_port_by_name(client1, jack_port_short_name(output_port1)));
  765. } else {
  766. Log("Checking jack_port_by_name() with bad argument... ok (returned id 0)\n");
  767. }
  768. /**
  769. * remove the output port previously created
  770. * no more ports should subsist here for our client.
  771. *
  772. */
  773. if (jack_port_unregister(client1, output_port1) != 0) {
  774. printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
  775. }
  776. /**
  777. * list all in ports
  778. *
  779. */
  780. inports = jack_get_ports(client1, NULL, NULL, 0);
  781. /**
  782. * Test the first PHY (physical) connection to see if it's "mine".
  783. * and report the result in the test that began before.
  784. * The result is printed later.
  785. *
  786. */
  787. if (jack_port_is_mine(client1, jack_port_by_name(client1, inports[0]))) {
  788. is_mine = 0;
  789. }
  790. /**
  791. * List all devices' flags and print them...
  792. *
  793. */
  794. Log("\nTry functions jack_get_ports, jack_port_flag & jack_port_by_name to list PHY devices...\n");
  795. Log("-----------------------------------------------------------\n");
  796. Log("---------------------------DEVICES-------------------------\n");
  797. Log("-----------------------------------------------------------\n");
  798. a = 0;
  799. while (inports[a] != NULL) {
  800. flag = jack_port_flags(jack_port_by_name(client1, inports[a]) );
  801. Log(" * %s (id : %i)\n", inports[a], jack_port_by_name(client1, inports[a]));
  802. Log(" (");
  803. if (flag & JackPortIsInput)
  804. Log("JackPortIsInput ");
  805. if (flag & JackPortIsOutput)
  806. Log("JackPortIsOutput ");
  807. if (flag & JackPortIsPhysical)
  808. Log("JackPortIsPhysical ");
  809. if (flag & JackPortCanMonitor)
  810. Log("JackPortCanMonitor ");
  811. if (flag & JackPortIsTerminal)
  812. Log("JackPortIsTerminal ");
  813. Log(")\n\n");
  814. a++;
  815. }
  816. Log("-----------------------------------------------------------\n\n");
  817. /**
  818. * list all PHY in/out ports...
  819. * This list will be used later many times.
  820. *
  821. */
  822. outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
  823. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  824. if (outports == NULL) {
  825. printf("!!! WARNING !!! no physical capture ports founded !\n");
  826. }
  827. if (inports == NULL) {
  828. printf("!!! WARNING !!! no physical output ports founded !\n");
  829. }
  830. /**
  831. * Brute test : try to create as many ports as possible.
  832. * It stops when jack returns an error.
  833. * Then try to connect each port to physical entry...
  834. * Check also that graph reorder callback is called.
  835. *
  836. */
  837. Log("Registering as many ports as possible and connect them to physical entries...\n");
  838. lineports = linecount;
  839. t_error = 0;
  840. i = 0; // number of couple 'input-ouput'
  841. j = 0; // number of ports created
  842. port_callback_reg = 0; // number of port registration received by the callback
  843. reorder = 0; // number of graph reorder callback activation
  844. test_link = 0 ; // Test the "overconnect" function only one time
  845. while (t_error == 0) {
  846. sprintf (portname, "input_%d", i);
  847. input_port1 = jack_port_register(client1, portname,
  848. JACK_DEFAULT_AUDIO_TYPE,
  849. JackPortIsInput, 0);
  850. j++;
  851. if (input_port1 == NULL) {
  852. j--;
  853. t_error = 1;
  854. } else {
  855. // Connect created input to PHY output
  856. a = 0;
  857. while (outports[a] != NULL) {
  858. if (jack_connect(client1, outports[a], jack_port_name(input_port1))) {
  859. printf ("error : cannot connect input PHY port to client port %s\n", jack_port_name(input_port1));
  860. } else {
  861. // printf ("input PHY port %s connected to client port %s\n", outports[a], jack_port_name(input_port1));
  862. }
  863. a++;
  864. }
  865. // Try one time to "overconnect" 2 ports (the latest created)...
  866. if (test_link == 0) {
  867. if (jack_connect(client1, outports[a - 1], jack_port_name(input_port1)) == EEXIST) {
  868. // cannot over-connect input PHY port to client port. ok.
  869. test_link = 1;
  870. }
  871. }
  872. }
  873. sprintf(portname, "output_%d", i);
  874. output_port1 = jack_port_register(client1, portname,
  875. JACK_DEFAULT_AUDIO_TYPE,
  876. JackPortIsOutput, 0);
  877. j++;
  878. if (output_port1 == NULL) {
  879. t_error = 1;
  880. j--;
  881. } else {
  882. // Connect created input to PHY output
  883. a = 0;
  884. while (inports[a] != NULL) {
  885. if (jack_connect(client1, jack_port_name(output_port1), inports[a])) {
  886. printf ("error : cannot connect input PHY port %s to client port %s\n", inports[a], jack_port_name(output_port1));
  887. } else {
  888. // output PHY port %s connected to client port. ok.
  889. }
  890. a++;
  891. }
  892. // Try one time to "overconnect" 2 ports (the latest created)...
  893. if (test_link == 0) {
  894. if (jack_connect(client1, jack_port_name(output_port1), inports[a - 1]) == EEXIST) {
  895. // cannot over-connect output PHY port to client port. ok.
  896. test_link = 1;
  897. }
  898. }
  899. }
  900. i++;
  901. }
  902. jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
  903. if (j == port_callback_reg) {
  904. Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j, port_callback_reg);
  905. } else {
  906. printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j, k);
  907. }
  908. if (reorder == (2 * j)) {
  909. Log("%i graph reorder callback have been received... ok\n", reorder);
  910. } else {
  911. printf("!!! ERROR !!! %i graph reorder callback have been received (maybe non-valid value)...\n", reorder);
  912. }
  913. /**
  914. * print basic test connection functions result ...
  915. * over-connected means here that we try to connect 2 ports that are already connected.
  916. *
  917. */
  918. if (test_link) {
  919. Log("Jack links can't be 'over-connected'... ok\n");
  920. } else {
  921. printf("!!! ERROR !!! Jack links can be 'over-connected'...\n");
  922. }
  923. /**
  924. * Print the result of the two jack_is_mine test.
  925. *
  926. */
  927. if (is_mine == 1) {
  928. Log("Checking jack_port_is_mine()... ok\n");
  929. } else {
  930. printf("!!! ERROR !!! jack_port_is_mine() function seems to send non-valid datas !\n");
  931. }
  932. /**
  933. * Free the array of the physical input and ouput ports.
  934. * (as mentionned in the doc of jack_get_ports)
  935. *
  936. */
  937. free(inports);
  938. free(outports);
  939. /**
  940. * Try to "reactivate" the client whereas it's already activated...
  941. *
  942. */
  943. if (jack_activate(client1) < 0) {
  944. printf("!!! ERROR !!! Cannot activate client1 a second time...\n");
  945. exit(1);
  946. } else {
  947. Log("jackd server accept client.jack_activate() re-activation (while client was already activated).\n");
  948. }
  949. /**
  950. * Deregister all ports previously created.
  951. *
  952. */
  953. Log("Deregistering all ports of the client...\n");
  954. inports = jack_get_ports(client1, NULL, NULL, 0);
  955. a = 0;
  956. while (inports[a] != NULL) {
  957. flag = jack_port_flags(jack_port_by_name(client1, inports[a]));
  958. input_port1 = jack_port_by_name(client1, inports[a]);
  959. if (jack_port_is_mine(client1, input_port1)) {
  960. if (jack_port_unregister(client1, input_port1) != 0) {
  961. printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
  962. }
  963. }
  964. a++;
  965. }
  966. free(inports); // free array of ports (as mentionned in the doc of jack_get_ports)
  967. /**
  968. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  969. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  970. Open a new client (second one) to test some other things...
  971. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  972. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  973. */
  974. Log("\n\n----------------------------------------------------------------------\n");
  975. Log("Starting second new client 'jack_test_#2'...\n");
  976. /* open a client connection to the JACK server */
  977. client_name2 = "jack_test_#2";
  978. linecl2 = linecount; // reminders for graph analysis
  979. client2 = jack_client_new(client_name2);
  980. if (client2 == NULL) {
  981. fprintf(stderr, "jack_client_new() failed for %s.\n"
  982. "status = 0x%2.0x\n", client_name2, status);
  983. if (status & JackServerFailed) {
  984. fprintf(stderr, "Unable to connect client2 to JACK server\n");
  985. }
  986. exit(1);
  987. }
  988. /**
  989. * Register callback for this client.
  990. * Callbacks are the same as the first client for most of them, excepted for process audio callback.
  991. *
  992. */
  993. jack_set_port_registration_callback(client2, Jack_Port_Register, 0);
  994. jack_set_process_callback(client2, process2, 0);
  995. jack_on_shutdown(client2, jack_shutdown, 0);
  996. /**
  997. * Register one input and one output for each client.
  998. *
  999. */
  1000. Log("registering 1 input/output ports for each client...\n");
  1001. output_port1 = jack_port_register(client1, "out1",
  1002. JACK_DEFAULT_AUDIO_TYPE,
  1003. JackPortIsOutput, 0);
  1004. output_port2 = jack_port_register(client2, "out2",
  1005. JACK_DEFAULT_AUDIO_TYPE,
  1006. JackPortIsOutput, 0);
  1007. input_port1 = jack_port_register(client1, "in1",
  1008. JACK_DEFAULT_AUDIO_TYPE,
  1009. JackPortIsInput, 0);
  1010. input_port2 = jack_port_register(client2, "in2",
  1011. JACK_DEFAULT_AUDIO_TYPE,
  1012. JackPortIsInput, 0);
  1013. if ((output_port1 == NULL) || (output_port2 == NULL) || (input_port1 == NULL) || (input_port2 == NULL)) {
  1014. printf("!!! ERROR !!! Unable to register ports...\n");
  1015. }
  1016. /**
  1017. * Set each process mode to idle and activate client2
  1018. *
  1019. */
  1020. process2_activated = -1;
  1021. process1_activated = -1;
  1022. if (jack_activate(client2) < 0) {
  1023. printf ("Fatal error : cannot activate client2\n");
  1024. exit (1);
  1025. }
  1026. /**
  1027. * Connect the two clients and check that all connections are well-done.
  1028. *
  1029. */
  1030. Log("Testing connections functions between clients...\n");
  1031. if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
  1032. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1033. }
  1034. if (jack_connect(client2, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
  1035. printf("!!! ERROR !!! while client2 intenting to connect ports...\n");
  1036. }
  1037. if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
  1038. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1039. }
  1040. /**
  1041. * Test the port_connected function...
  1042. *
  1043. */
  1044. if ((jack_port_connected(output_port1) == jack_port_connected(input_port1)) &&
  1045. (jack_port_connected(output_port2) == jack_port_connected(input_port2)) &&
  1046. (jack_port_connected(output_port2) == 1) &&
  1047. (jack_port_connected(output_port1) == 2)
  1048. ) {
  1049. Log("Checking jack_port_connected()... ok.\n");
  1050. } else {
  1051. printf("!!! ERROR !!! function jack_port_connected() return a bad value !\n");
  1052. printf("jack_port_connected(output_port1) %ld\n", jack_port_connected(output_port1));
  1053. printf("jack_port_connected(output_port2) %ld\n", jack_port_connected(output_port2));
  1054. printf("jack_port_connected(input_port1) %ld\n", jack_port_connected(input_port1));
  1055. printf("jack_port_connected(input_port2) %ld\n", jack_port_connected(input_port2));
  1056. }
  1057. /**
  1058. * Test a new time the port_by_name function...(now we are in multi-client mode)
  1059. *
  1060. */
  1061. Log("Testing again jack_port_by_name...\n");
  1062. if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
  1063. printf("!!! ERROR !!! function jack_port_by_name() return bad value in a multi-client application!\n");
  1064. printf("!!! jack_port_by_name(jack_port_name(_ID_) ) != _ID_ in multiclient application.\n");
  1065. } else {
  1066. Log("Checking jack_port_by_name() function with a multi-client application... ok\n");
  1067. }
  1068. /**
  1069. * Test the port_connected_to function...
  1070. *
  1071. */
  1072. if ((jack_port_connected_to (output_port1, jack_port_name(input_port2))) &&
  1073. (!(jack_port_connected_to (output_port2, jack_port_name(input_port2))))) {
  1074. Log("checking jack_port_connected_to()... ok\n");
  1075. } else {
  1076. printf("!!! ERROR !!! jack_port_connected_to() return bad value !\n");
  1077. }
  1078. /**
  1079. * Test the port_get_connections & port_get_all_connections functions...
  1080. *
  1081. */
  1082. Log("Testing jack_port_get_connections and jack_port_get_all_connections...\n");
  1083. a = 0;
  1084. t_error = 0;
  1085. connexions1 = jack_port_get_connections (output_port1);
  1086. connexions2 = jack_port_get_all_connections(client1, output_port1);
  1087. if ((connexions1 == NULL) || (connexions2 == NULL)) {
  1088. printf("!!! ERROR !!! port_get_connexions or port_get_all_connexions return a NULL pointer !\n");
  1089. } else {
  1090. while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
  1091. t_error = strcmp(connexions1[a], connexions2[a]);
  1092. a++;
  1093. }
  1094. if (t_error == 0) {
  1095. Log("Checking jack_port_get_connections Vs jack_port_get_all_connections... ok\n");
  1096. } else {
  1097. printf("!!! ERROR !!! while checking jack_port_get_connections Vs jack_port_get_all_connections...\n");
  1098. }
  1099. }
  1100. a = 0;
  1101. t_error = 0;
  1102. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1103. connexions1 = NULL;
  1104. assert(inports != NULL);
  1105. if (inports[0] != NULL) {
  1106. connexions1 = jack_port_get_connections (jack_port_by_name(client1, inports[0]));
  1107. connexions2 = jack_port_get_all_connections(client1, jack_port_by_name(client1, inports[0]));
  1108. }
  1109. free (inports);
  1110. if (connexions1 == NULL) {
  1111. Log("checking jack_port_get_connections() for external client... ok\n");
  1112. } else {
  1113. while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
  1114. t_error = strcmp(connexions1[a], connexions2[a]);
  1115. a++;
  1116. }
  1117. }
  1118. if (t_error == 0) {
  1119. Log("Checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port... ok\n");
  1120. } else {
  1121. printf("!!! ERROR !!! while checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port...\n");
  1122. }
  1123. /**
  1124. * Test port locking function
  1125. * Check the validity of the lock...
  1126. *
  1127. */
  1128. Log("Testing connections locks between clients...\n");
  1129. if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
  1130. printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
  1131. }
  1132. if (jack_port_lock(client2, output_port2) != 0) {
  1133. printf("Error while calling port_lock... jack_lock will not be checked !\n");
  1134. } else {
  1135. Log("Locking port 'out2'...ok\n");
  1136. if (jack_disconnect(client2, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
  1137. Log("Checking lock status with disconnect... ok\n");
  1138. } else {
  1139. printf("!!! ERRROR !!! Jack_lock didn't lock port_connections with disconnect!\n");
  1140. }
  1141. if (jack_port_disconnect(client1, output_port2) != 0) {
  1142. Log("Checking lock status with port_disconnect... ok\n");
  1143. } else {
  1144. printf("!!! ERRROR !!! Jack_lock didn't lock port_connections with port_disconnect!\n");
  1145. }
  1146. if (jack_connect(client2, jack_port_name(output_port2), jack_port_name(input_port2)) != 0) {
  1147. Log("Checking lock status with connect... ok\n");
  1148. } else {
  1149. printf("!!! ERRROR !!! Jack_lock didn't lock port_connections with connect!\n");
  1150. jack_disconnect(client2, jack_port_name(output_port2), jack_port_name(input_port2));
  1151. }
  1152. if (jack_port_unlock(client1, output_port2) != 0) {
  1153. Log("Checking unlock by another client... ok\n");
  1154. } else {
  1155. printf("!!! ERROR !!! a client can unlock a port locked previously by another client... \n");
  1156. }
  1157. if (jack_port_unlock(client2, output_port2) != 0) {
  1158. printf("Error while calling port_unlock... \n");
  1159. }
  1160. if (jack_port_lock(client2, output_port1) != 0) {
  1161. Log("Checking lock of port of an other client... ok\n");
  1162. } else {
  1163. printf("!!! ERROR !!! a port can be locked by a non-owner client !\n");
  1164. jack_port_unlock(client2, output_port1);
  1165. }
  1166. }
  1167. jack_disconnect(client1, jack_port_name(output_port2), jack_port_name(input_port1));
  1168. // No links should subsist now...
  1169. /**
  1170. * Checking data connexion
  1171. * establishing a link between client1.out1 --> client2.in2
  1172. * Send the signal1 test on out1. Record the result into signal2. (see process functions).
  1173. ---------------------------------------------------------------------------*/
  1174. Log("Testing connections datas between clients...\n");
  1175. jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2) );
  1176. process2_activated = -1;
  1177. process1_activated = -1;
  1178. Log("process 2 : idle mode...\n");
  1179. Log("Sending datas...");
  1180. index1 = 0;
  1181. index2 = 0;
  1182. process1_activated = 1; // We start emitting first.
  1183. process2_activated = 1; // So record begin at least when we just begin to emitt the signal, else at next call of process with
  1184. // nframe = jack buffersize shifting.
  1185. while (process2_activated == 1) {
  1186. jack_sleep(1 * 1000);
  1187. Log(".");
  1188. }
  1189. index2 = 0;
  1190. Log("\nAnalysing datas...\n"); // search the first occurence of the first element of the reference signal in the recorded signal
  1191. while (signal2[index2] != signal1[1] ) {
  1192. index2++;
  1193. if (index2 == 95999) {
  1194. printf("!!! ERROR !!! Data not found in first connexion data check!\n");
  1195. break;
  1196. }
  1197. }
  1198. index1 = index2;
  1199. Log("Data founded at offset %i.\n", index2);
  1200. // And now we founded were the recorded data are, we can see if the two signals matches...
  1201. while ( (signal2[index2] == signal1[index2 - index1 + 1]) || (index2 == 95999) || ((index2 - index1 + 1) == 47999) ) {
  1202. index2++;
  1203. }
  1204. Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
  1205. if ((index2 - index1) == 48000) {
  1206. Log("Data received are valid...\n");
  1207. } else {
  1208. printf("!!! ERROR !!! data transmission seems not to be valid in first connexion data check!\n");
  1209. }
  1210. if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port2) ) != 0)
  1211. // no more connection between ports exist now...
  1212. {
  1213. printf("Error while establishing new connexion (disconnect).\n");
  1214. }
  1215. /**
  1216. * Test TIE MODE
  1217. * (This mode seems to be problematic in standard jack version 0.100. It seems that nobody
  1218. * is used to apply this mode because the tie mode doesn't work at all. A patch seems difficult to produce
  1219. * in this version of jack. Tie mode work well in MP version.)
  1220. * Test some basic thinks (tie with 2 differents client, tie non-owned ports...)
  1221. * Tie client1.in1 and client1.out1 ports, and make some data test to check the validity of the tie.
  1222. *
  1223. */
  1224. Log("Testing tie mode...\n");
  1225. if (jack_port_tie(input_port1, output_port2) != 0) {
  1226. Log("not possible to tie two ports from two differents clients... ok\n");
  1227. } else {
  1228. printf("!!! ERROR !!! port_tie has allowed a connexion between two differents clients !\n");
  1229. jack_port_untie(output_port2);
  1230. }
  1231. Log("Testing connections datas in tie mode...\n");
  1232. int g;
  1233. for (g = 0; g < 96000; g++)
  1234. signal2[g] = 0.0;
  1235. // Create a loop (emit test) client2.out2----client.in1--tie--client1.out1-----client2.in1 (receive test)
  1236. if (jack_port_tie(input_port1, output_port1) != 0) {
  1237. printf("Unable to tie... fatal error : data test will not be performed on tie mode !!\n");
  1238. } else { // begin of tie
  1239. if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
  1240. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1241. }
  1242. if (jack_connect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
  1243. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1244. }
  1245. process1_activated = -1;
  1246. process2_activated = -1;
  1247. // We can manualy check here that the tie is effective.
  1248. // ie : playing a wav with a client, connecting ports manualy with qjackctl, and listen...
  1249. // printf("manual test\n");
  1250. // jack_sleep(50);
  1251. // printf("end of manual test\n");
  1252. index1 = 0;
  1253. index2 = 0;
  1254. process1_activated = -1;
  1255. process2_activated = 2;
  1256. Log("Sending datas...");
  1257. while (process2_activated == 2) {
  1258. jack_sleep(1 * 1000);
  1259. Log(".");
  1260. }
  1261. process1_activated = -1;
  1262. process2_activated = -1;
  1263. index2 = 0;
  1264. Log("\nAnalysing datas...\n");
  1265. // We must find at least 2 identical values to ensure we are at the right place in the siusoidal array...
  1266. while (!((signal2[index2] == signal1[1]) && (signal2[index2 + 1] == signal1[2]))) {
  1267. index2++;
  1268. if (index2 == 95999) {
  1269. printf("!!! ERROR !!! Data not found in connexion check of tie mode!\n");
  1270. break;
  1271. }
  1272. }
  1273. index1 = index2;
  1274. Log("Tie mode : Data founded at offset %i.\n", index2);
  1275. while (signal2[index2] == signal1[index2 - index1 + 1]) {
  1276. index2++;
  1277. if ((index2 == 95999) || ((index2 - index1 + 1) == 47999)) {
  1278. break;
  1279. }
  1280. }
  1281. Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
  1282. if ((index2 - index1) > 47995) {
  1283. Log("Data received in tie mode are valid...\n");
  1284. } else {
  1285. // in tie mode, the buffers adress should be the same for the two tied ports.
  1286. printf("!!! ERROR !!! data transmission seems not to be valid !\n");
  1287. printf("Links topology : (emitt) client2.out2 ----> client1.in1--(tie)--client1.out1----->client2.in2 (recive)\n");
  1288. printf(" port_name : Port_adress \n");
  1289. printf(" output_port1 : %x\n", jack_port_get_buffer(output_port1, cur_buffer_size));
  1290. printf(" input_port2 : %x\n", jack_port_get_buffer(input_port2, cur_buffer_size));
  1291. printf(" output_port2 : %x\n", jack_port_get_buffer(output_port2, cur_buffer_size));
  1292. printf(" input_port1 : %x\n", jack_port_get_buffer(input_port1, cur_buffer_size));
  1293. }
  1294. jack_port_untie(output_port1);
  1295. jack_port_disconnect(client1, output_port2);
  1296. jack_port_disconnect(client1, output_port1);
  1297. } //end of tie
  1298. /**
  1299. * Testing SUMMATION CAPABILITIES OF JACK CONNECTIONS
  1300. *
  1301. * In a short test, we just check a simple summation in jack.
  1302. * A first client(client1) send two signal in phase opposition
  1303. * A second client(client2) record the summation at one of his port
  1304. * So, the result must be zero...
  1305. * See process1 for details about steps of this test
  1306. *
  1307. */
  1308. // fprintf(file, "Sum test\n");
  1309. Log("Checking summation capabilities of patching...\n");
  1310. output_port1b = jack_port_register(client1, "out1b",
  1311. JACK_DEFAULT_AUDIO_TYPE,
  1312. JackPortIsOutput, 0);
  1313. jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2));
  1314. jack_connect(client2, jack_port_name(output_port1b), jack_port_name(input_port2));
  1315. process1_activated = 3;
  1316. process2_activated = -1;
  1317. for (g = 0; g < 96000; g++)
  1318. signal2[g] = 0.0;
  1319. index1 = 0;
  1320. index2 = 0;
  1321. Log("Sending datas...");
  1322. process2_activated = 3;
  1323. while (process2_activated == 3) {
  1324. jack_sleep(1 * 1000);
  1325. Log(".");
  1326. }
  1327. process1_activated = -1;
  1328. process2_activated = -1;
  1329. index2 = 0;
  1330. Log("\nAnalysing datas...\n"); // same idea as above, with first data check...
  1331. while (!((signal2[index2] == 0.0 ) && (signal2[(index2 + 1)] == 0.0 ))) {
  1332. index2++;
  1333. if (index2 == 95999) {
  1334. printf("!!! ERROR !!! Data not found in summation check!\n");
  1335. break;
  1336. }
  1337. }
  1338. index1 = index2;
  1339. Log("Data founded at offset %i.\n", index2);
  1340. while ( signal2[index2] == 0.0 ) {
  1341. index2++;
  1342. if ((index2 > 95998) || ((index2 - index1 + 1) > 47998)) {
  1343. break;
  1344. }
  1345. }
  1346. Log("Checking difference between datas...\n");
  1347. if ((index2 - index1) > 47996) {
  1348. Log("Data mixed received are valid...\nSummation is well done.\n");
  1349. } else {
  1350. printf("!!! ERROR !!! data transmission / summation seems not to be valid !\n");
  1351. }
  1352. jack_port_disconnect(client1, output_port1);
  1353. jack_port_disconnect(client1, output_port1b);
  1354. jack_port_unregister(client1, output_port1b);
  1355. if (jack_port_name(output_port1b) != NULL ) {
  1356. printf("!!! WARNING !!! port_name return something while the port have been unregistered !\n");
  1357. printf("!!! Name of unregistered port : %s !\n", jack_port_name(output_port1b));
  1358. } else {
  1359. Log("Checking jack_port_name() with a non valid port... ok\n");
  1360. }
  1361. if (jack_port_set_name(output_port1b, "new_name") == 0 ) {
  1362. printf("!!! WARNING !!! An unregistered port can be renamed successfully !\n");
  1363. } else {
  1364. Log("Checking renaming of an unregistered port... ok\n");
  1365. }
  1366. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1367. if (jack_port_set_name(jack_port_by_name(client1, inports[0]), "new_name") == 0 ) {
  1368. printf("!!! WARNING !!! A PHYSICAL port can be renamed successfully !\n");
  1369. } else {
  1370. Log("Checking renaming of an unregistered port... ok\n");
  1371. }
  1372. free (inports);
  1373. /**
  1374. * Checking latency issues
  1375. * here are simple latency check
  1376. * We simply check that the value returned by jack seems ok
  1377. * Latency compensation is a difficult point.
  1378. * Actually, jack is not able to see "thru" client to build a full latency chain.
  1379. * Ardour use theses informations to do internally his compensations.
  1380. *
  1381. * 3 test are done : one with no connections between client, one with a serial connection, and one with parallel connection
  1382. */
  1383. Log("Checking about latency functions...\n");
  1384. t_error = 0;
  1385. jack_recompute_total_latencies(client1);
  1386. if ((jack_port_get_latency (output_port1) != 0) ||
  1387. (jack_port_get_total_latency(client1, output_port1) != 0) ) {
  1388. t_error = 1;
  1389. printf("!!! ERROR !!! default latency of a non-PHY device is not set to zero !\n");
  1390. }
  1391. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1392. outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
  1393. if (inports[0] != NULL) {
  1394. ext_latency = jack_port_get_latency (jack_port_by_name(client1, inports[0]));
  1395. if (ext_latency != jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0]))) {
  1396. t_error = 1;
  1397. printf("!!! ERROR !!! get_latency & get_all_latency for a PHY device (unconnected) didn't return the same value !\n");
  1398. }
  1399. Log("Checking a serial model with 2 clients...\n");
  1400. jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2));
  1401. jack_connect(client1, outports[0], jack_port_name(input_port1));
  1402. jack_connect(client2, jack_port_name(output_port2), inports[0]);
  1403. jack_port_set_latency (output_port2, 256);
  1404. jack_recompute_total_latencies(client1);
  1405. if ((jack_port_get_latency (output_port1) != 0) ||
  1406. (jack_port_get_total_latency(client1, output_port1) != 0) ||
  1407. (jack_port_get_latency (jack_port_by_name(client1, inports[0])) != (ext_latency)) ||
  1408. (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (ext_latency + 256)) ||
  1409. (jack_port_get_total_latency(client1, output_port2) != (ext_latency + 256)) ||
  1410. (jack_port_get_total_latency(client1, input_port2) != 0) ||
  1411. (jack_port_get_total_latency(client1, input_port1) != ext_latency) ||
  1412. (jack_port_get_latency (jack_port_by_name(client1, outports[0])) != ext_latency) ||
  1413. (jack_port_get_total_latency(client1, jack_port_by_name(client1, outports[0])) != ext_latency)
  1414. ) {
  1415. printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
  1416. printf("!!! get_latency(output_port1) : %i (must be 0)\n", jack_port_get_latency (output_port1) );
  1417. printf("!!! get_total_latency(output_port1) : %i (must be 0)\n", jack_port_get_total_latency(client1, output_port1));
  1418. printf("!!! get_latency(PHY[0]) : %i (must be external latency : %i)\n", jack_port_get_latency (jack_port_by_name(client1, inports[0])), ext_latency);
  1419. printf("!!! get_total_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) , (ext_latency + 256));
  1420. printf("!!! get_total_latency(output_port2) : %i (must be %i)\n", jack_port_get_total_latency(client1, output_port2), (ext_latency + 256));
  1421. printf("!!! get_total_latency(input_port2) : %i (must be 0)\n", jack_port_get_total_latency(client1, input_port2));
  1422. printf("!!! get_total_latency(input_port1) : %i (must be %i)\n", jack_port_get_total_latency(client1, input_port1), ext_latency);
  1423. printf("!!! get_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_latency (jack_port_by_name(client1, outports[0])), ext_latency);
  1424. printf("!!! get_total_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_total_latency(client1, jack_port_by_name(client1, outports[0])), ext_latency);
  1425. } else {
  1426. Log("get_latency & get_total_latency seems quite ok...\n");
  1427. }
  1428. jack_port_disconnect(client1, output_port1);
  1429. jack_port_disconnect(client1, output_port2);
  1430. jack_port_disconnect(client1, input_port1);
  1431. jack_port_disconnect(client1, input_port2);
  1432. Log("Checking a parallel model with 2 clients...\n");
  1433. jack_connect(client2, outports[0], jack_port_name(input_port1) );
  1434. jack_connect(client2, outports[0], jack_port_name(input_port2) );
  1435. jack_connect(client2, jack_port_name(output_port1), inports[0] );
  1436. jack_connect(client2, jack_port_name(output_port2), inports[0] );
  1437. jack_port_set_latency (output_port1, 256);
  1438. jack_port_set_latency (output_port2, 512);
  1439. jack_recompute_total_latencies(client1);
  1440. if ((jack_port_get_latency (output_port1) != 256 ) ||
  1441. (jack_port_get_total_latency(client1, output_port1) != (256 + ext_latency)) ||
  1442. (jack_port_get_latency (output_port2) != 512) ||
  1443. (jack_port_get_total_latency(client1, output_port2) != (512 + ext_latency)) ||
  1444. (jack_port_get_latency (jack_port_by_name(client1, inports[0])) != ext_latency) ||
  1445. (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (512 + ext_latency))
  1446. ) {
  1447. printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
  1448. } else {
  1449. Log("get_latency & get_total_latency seems quite ok...\n");
  1450. }
  1451. } else {
  1452. printf("No physical port founded : not able to test latency functions...");
  1453. }
  1454. jack_port_disconnect(client1, input_port1);
  1455. jack_port_disconnect(client1, input_port2);
  1456. jack_port_disconnect(client1, output_port1);
  1457. jack_port_disconnect(client1, output_port2);
  1458. free(inports);
  1459. free(outports);
  1460. /**
  1461. * Checking transport API.
  1462. * Simple transport test.
  1463. * Check a transport start with a "slow" client, simulating a delay around 1 sec before becoming ready.
  1464. *
  1465. */
  1466. Log("-----------------------------------------------------------\n");
  1467. Log("---------------------------TRANSPORT-----------------------\n");
  1468. Log("-----------------------------------------------------------\n");
  1469. lineports = linecount;
  1470. if (transport_mode) {
  1471. int wait_count;
  1472. ts = jack_transport_query(client1, &pos);
  1473. if (ts == JackTransportStopped) {
  1474. Log("Transport is stopped...\n");
  1475. } else {
  1476. jack_transport_stop(client1);
  1477. Log("Transport state : %i\n", ts);
  1478. }
  1479. if (jack_set_sync_callback(client2, Jack_Sync_Callback, 0) != 0)
  1480. printf("error while calling set_sync_callback...\n");
  1481. Log("starting transport...\n");
  1482. starting_state = 1; // Simulate starting state
  1483. jack_transport_start(client1);
  1484. // Wait until sync callback is called
  1485. while (!(sync_called)) {
  1486. jack_sleep(1 * 1000);
  1487. }
  1488. // Wait untill rolling : simulate sync time out
  1489. Log("Simulate a slow-sync client exceeding the time-out\n");
  1490. wait_count = 0;
  1491. do {
  1492. jack_sleep(100); // Wait 100 ms each cycle
  1493. wait_count++;
  1494. if (wait_count == 100) {
  1495. Log("!!! ERROR !!! max time-out exceedeed : sync time-out does not work correctly\n");
  1496. break;
  1497. }
  1498. ts = jack_transport_query(client2, &pos);
  1499. Log("Waiting....pos = %ld\n", pos.frame);
  1500. display_transport_state();
  1501. } while (ts != JackTransportRolling);
  1502. Log("Sync callback have been called %i times.\n", sync_called);
  1503. jack_transport_stop(client1);
  1504. // Wait until stopped
  1505. ts = jack_transport_query(client2, &pos);
  1506. while (ts != JackTransportStopped) {
  1507. jack_sleep(1 * 1000);
  1508. ts = jack_transport_query(client2, &pos);
  1509. }
  1510. // Simulate starting a slow-sync client that rolls after 0.5 sec
  1511. Log("Simulate a slow-sync client that needs 0.5 sec to start\n");
  1512. sync_called = 0;
  1513. wait_count = 0;
  1514. starting_state = 1; // Simulate starting state
  1515. Log("Starting transport...\n");
  1516. jack_transport_start(client1);
  1517. display_transport_state();
  1518. Log("Waiting 0.5 sec...\n");
  1519. jack_sleep(500);
  1520. starting_state = 0; // Simulate end of starting state after 0.5 sec
  1521. // Wait untill rolling
  1522. ts = jack_transport_query(client2, &pos);
  1523. while (ts != JackTransportRolling) {
  1524. jack_sleep(100); // Wait 100 ms each cycle
  1525. wait_count++;
  1526. if (wait_count == 10) {
  1527. Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
  1528. break;
  1529. }
  1530. ts = jack_transport_query(client2, &pos);
  1531. }
  1532. if (sync_called == 0)
  1533. Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
  1534. Log("Sync callback have been called %i times.\n", sync_called);
  1535. display_transport_state();
  1536. // Test jack_transport_locate while rolling
  1537. Log("Test jack_transport_locate while rolling\n");
  1538. ts = jack_transport_query(client2, &pos);
  1539. Log("Transport current frame = %ld\n", pos.frame);
  1540. jack_nframes_t cur_frame = pos.frame;
  1541. wait_count = 0;
  1542. do {
  1543. display_transport_state();
  1544. jack_sleep(10); // 10 ms
  1545. // locate at first...
  1546. wait_count++;
  1547. if (wait_count == 1) {
  1548. Log("Do jack_transport_locate\n");
  1549. jack_transport_locate(client1, cur_frame / 2);
  1550. } else if (wait_count == 100) {
  1551. break;
  1552. }
  1553. ts = jack_transport_query(client2, &pos);
  1554. Log("Locating.... frame = %ld\n", pos.frame);
  1555. } while (pos.frame > cur_frame);
  1556. ts = jack_transport_query(client2, &pos);
  1557. Log("Transport current frame = %ld\n", pos.frame);
  1558. if (wait_count == 100) {
  1559. printf("!!! ERROR !!! jack_transport_locate does not work correctly\n");
  1560. }
  1561. // Test jack_transport_reposition while rolling
  1562. Log("Test jack_transport_reposition while rolling\n");
  1563. ts = jack_transport_query(client2, &pos);
  1564. Log("Transport current frame = %ld\n", pos.frame);
  1565. cur_frame = pos.frame;
  1566. wait_count = 0;
  1567. do {
  1568. display_transport_state();
  1569. jack_sleep(10); // 10 ms
  1570. // locate at first...
  1571. wait_count++;
  1572. if (wait_count == 1) {
  1573. Log("Do jack_transport_reposition\n");
  1574. request_pos.frame = cur_frame / 2;
  1575. jack_transport_reposition(client1, &request_pos);
  1576. } else if (wait_count == 100) {
  1577. break;
  1578. }
  1579. ts = jack_transport_query(client2, &pos);
  1580. Log("Locating.... frame = %ld\n", pos.frame);
  1581. } while (pos.frame > cur_frame);
  1582. ts = jack_transport_query(client2, &pos);
  1583. Log("Transport current frame = %ld\n", pos.frame);
  1584. if (wait_count == 100) {
  1585. printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
  1586. }
  1587. // Test jack_transport_reposition while stopped
  1588. jack_transport_stop(client1);
  1589. ts = jack_transport_query(client2, &pos);
  1590. Log("Transport current frame = %ld\n", pos.frame);
  1591. Log("Test jack_transport_reposition while stopped\n");
  1592. wait_count = 0;
  1593. request_pos.frame = 10000;
  1594. jack_transport_reposition(client1, &request_pos);
  1595. do {
  1596. display_transport_state();
  1597. jack_sleep(100); // 100 ms
  1598. if (wait_count++ == 10)
  1599. break;
  1600. ts = jack_transport_query(client2, &pos);
  1601. Log("Locating.... frame = %ld\n", pos.frame);
  1602. } while (pos.frame != 10000);
  1603. ts = jack_transport_query(client2, &pos);
  1604. Log("Transport current frame = %ld\n", pos.frame);
  1605. if (pos.frame != 10000) {
  1606. printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
  1607. }
  1608. jack_transport_stop(client1);
  1609. /* Tell the JACK server that we are ready to roll. Our
  1610. * process() callback will start running now. */
  1611. } else {
  1612. printf("Transport check is disabled...\n");
  1613. }
  1614. time_before_exit = time_to_run;
  1615. while (time_before_exit != 0) {
  1616. jack_sleep (1 * 1000);
  1617. time_before_exit--;
  1618. }
  1619. if (jack_deactivate(client2) != 0) {
  1620. printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
  1621. }
  1622. if (jack_deactivate(client1) != 0) {
  1623. printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
  1624. }
  1625. /**
  1626. * Checking jack_frame_time.
  1627. */
  1628. Log("Testing jack_frame_time...\n");
  1629. jack_set_process_callback(client1, process4, client1);
  1630. jack_activate(client1);
  1631. jack_sleep(2 * 1000);
  1632. /**
  1633. * Checking callback exiting : when the return code is != 0, the client is desactivated.
  1634. */
  1635. Log("Testing callback exiting...\n");
  1636. jack_deactivate(client1);
  1637. jack_set_process_callback(client1, process3, 0);
  1638. jack_activate(client1);
  1639. jack_sleep(3 * 1000);
  1640. /**
  1641. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1642. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1643. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1644. Closing program
  1645. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1646. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1647. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1648. */
  1649. if (jack_deactivate(client2) != 0) {
  1650. printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
  1651. }
  1652. if (jack_deactivate(client1) != 0) {
  1653. printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
  1654. }
  1655. if (jack_client_close(client2) != 0) {
  1656. printf("!!! ERROR !!! jack_client_close does not return 0 for client2 !\n");
  1657. }
  1658. if (jack_client_close(client1) != 0) {
  1659. printf("!!! ERROR !!! jack_client_close does not return 0 for client1 !\n");
  1660. }
  1661. if (xrun == 0) {
  1662. Log("No Xrun have been detected during this test... cool !\n");
  1663. } else {
  1664. printf("%i Xrun have been detected during this session (seen callback messages to see where are the problems).\n");
  1665. }
  1666. free(framecollect);
  1667. free(signal1);
  1668. free(signal2);
  1669. Log("Exiting jack_test...\n");
  1670. fclose(file);
  1671. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  1672. sprintf (filename, "framegraph-%i.gnu", cur_buffer_size);
  1673. file = fopen(filename, "w");
  1674. if (file == NULL) {
  1675. fprintf(stderr, "Erreur dans l'ouverture du fichier");
  1676. exit( -1);
  1677. }
  1678. fprintf(file, "reset\n");
  1679. fprintf(file, "set terminal png transparent nocrop enhanced\n");
  1680. fprintf(file, "set output 'framegraph-%i-1.png'\n", cur_buffer_size);
  1681. fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
  1682. fprintf(file, "set yrange [ %i.00000 : %i.0000 ] noreverse nowriteback\n", cur_buffer_size - (cur_buffer_size / 8), cur_buffer_size + (cur_buffer_size / 8));
  1683. fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
  1684. fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
  1685. fprintf(file, "set xlabel \"FrameTime\"\n");
  1686. fprintf(file, "set label \"| buf.siz:%i | fr.wl:%i | rg.ports:%i | 2nd.client:%i | trsprt:%i |\" at graph 0.01, 0.04\n", linebuf, linefw, lineports, linecl2, linetransport);
  1687. fprintf(file, "plot 'framefile-%i.dat' using 2 with impulses title \"Xruns\",'framefile-%i.dat' using 1 with line title \"Sampletime variation at %i\"\n", cur_buffer_size, cur_buffer_size, cur_buffer_size);
  1688. fprintf(file, "set output 'framegraph-%i-2.png'\n", cur_buffer_size);
  1689. fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
  1690. fprintf(file, "set yrange [ %i.00000 : %i.0000 ] noreverse nowriteback\n", (int) (cur_buffer_size / 2), (int) (2*cur_buffer_size + (cur_buffer_size / 8)));
  1691. fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
  1692. fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
  1693. fprintf(file, "set xlabel \"FrameTime\"\n");
  1694. fprintf(file, "set label \"| buf.siz:%i | fr.wl:%i | rg.ports:%i | 2nd.client:%i | trsprt:%i |\" at graph 0.01, 0.04\n", linebuf, linefw, lineports, linecl2, linetransport);
  1695. fprintf(file, "plot 'framefile-%i.dat' using 2 with impulses title \"Xruns\",'framefile-%i.dat' using 1 with line title \"Sampletime variation at %i\"\n", cur_buffer_size, cur_buffer_size, cur_buffer_size);
  1696. fclose(file);
  1697. exit(0);
  1698. }