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.

1813 lines
71KB

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