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.

1994 lines
78KB

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