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.

1819 lines
72KB

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