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.

2204 lines
86KB

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