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.

1904 lines
74KB

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