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.

1966 lines
77KB

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