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.

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