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.

1967 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. 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. /**
  727. * Activate the client
  728. *
  729. */
  730. if (jack_activate(client1) < 0) {
  731. printf ("Fatal error : cannot activate client1\n");
  732. exit(1);
  733. }
  734. /**
  735. * Test if portrename callback have been called.
  736. *
  737. */
  738. jack_port_set_name (output_port1, "renamed-port#");
  739. jack_sleep(1 * 1000);
  740. if (port_rename_clbk == 0)
  741. printf("!!! ERROR !!! Jack_Port_Rename_Callback was not called !!.\n");
  742. /**
  743. * Test if init callback initThread have been called.
  744. *
  745. */
  746. if (init_clbk == 0)
  747. printf("!!! ERROR !!! Jack_Thread_Init_Callback was not called !!.\n");
  748. jack_sleep(10 * 1000); // test see the clock in the graph at the begining...
  749. /**
  750. * Stress Freewheel mode...
  751. * Try to enter freewheel mode. Check the realtime mode de-activation.
  752. * Check that the number of call of the process callback is greater than in non-freewheel mode.
  753. * Give an approximated speed ratio (number of process call) between the two modes.
  754. * Then return in normal mode.
  755. */
  756. t_error = 0;
  757. activated = 0;
  758. jack_sleep(1 * 1000);
  759. count1 = activated;
  760. Log("Testing activation freewheel mode...\n");
  761. linefw = linecount; // count for better graph reading with gnuplot
  762. jack_set_freewheel(client1, 1);
  763. activated = 0;
  764. jack_sleep(1 * 1000);
  765. count2 = activated;
  766. if (jack_is_realtime(client1) == 0) {
  767. t_error = 0;
  768. } else {
  769. printf("\n!!! ERROR !!! RT mode is always activated while freewheel mode is applied !\n");
  770. t_error = 1;
  771. }
  772. if (activated == 0)
  773. printf("!!! ERROR !!! Freewheel mode doesn't activate audio callback !!\n");
  774. jack_set_freewheel(client1, 0);
  775. jack_sleep(7 * 1000);
  776. if (jack_is_realtime(client1) == 1) {}
  777. else {
  778. printf("\n!!! ERROR !!! freewheel mode fail to reactivate RT mode when exiting !\n");
  779. t_error = 1;
  780. }
  781. if (t_error == 0) {
  782. Log("Freewheel mode appears to work well...\n");
  783. }
  784. if (count1 == 0) {
  785. Log("Audio Callback in 'standard' (non-freewheel) mode seems not to be called...\n");
  786. Log("Ratio speed would be unavailable...\n");
  787. } else {
  788. ratio = (float) ((count2 - count1) / count1);
  789. Log("Approximative speed ratio of freewheel mode = %f : 1.00\n", ratio);
  790. }
  791. /**
  792. * Stress buffer function...
  793. * get current buffer size.
  794. * Try to apply a new buffer size value ( 2 x the precedent buffer size value)
  795. * Then return in previous buffer size mode.
  796. *
  797. */
  798. float factor = 0.5f;
  799. old_buffer_size = jack_get_buffer_size(client1);
  800. Log("Testing BufferSize change & Callback...\n--> Current buffer size : %i.\n", old_buffer_size);
  801. linebuf = linecount;
  802. if (jack_set_buffer_size(client1, (jack_nframes_t)(old_buffer_size * factor)) < 0) {
  803. printf("!!! ERROR !!! jack_set_buffer_size fails !\n");
  804. }
  805. jack_sleep(1 * 1000);
  806. cur_buffer_size = jack_get_buffer_size(client1);
  807. if ((old_buffer_size * factor) != cur_buffer_size) {
  808. printf("!!! ERROR !!! Buffer size has not been changed !\n");
  809. printf("!!! Maybe jack was compiled without the '--enable-resize' flag...\n");
  810. } else {
  811. Log("jack_set_buffer_size() command successfully applied...\n");
  812. }
  813. jack_sleep(3 * 1000);
  814. jack_set_buffer_size(client1, old_buffer_size);
  815. cur_buffer_size = jack_get_buffer_size(client1);
  816. /**
  817. * Test the last regestered port to see if port_is_mine function the right value.
  818. * A second test will be performed later.
  819. * The result will be printed at the end.
  820. *
  821. */
  822. if (jack_port_is_mine(client1, output_port1)) {
  823. is_mine = 1;
  824. } else {
  825. is_mine = 0;
  826. }
  827. /**
  828. * Check that the ID returned by the port_by_name is right.
  829. * (it seems there is a problem here in some jack versions).
  830. *
  831. */
  832. if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
  833. printf("!!! ERROR !!! function jack_port_by_name() return bad value !\n");
  834. 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);
  835. } else {
  836. Log("Checking jack_port_by_name() return value... ok\n");
  837. }
  838. if (NULL != jack_port_by_name(client1, jack_port_short_name(output_port1))) {
  839. 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)));
  840. } else {
  841. Log("Checking jack_port_by_name() with bad argument... ok (returned id 0)\n");
  842. }
  843. /**
  844. * remove the output port previously created
  845. * no more ports should subsist here for our client.
  846. *
  847. */
  848. if (jack_port_unregister(client1, output_port1) != 0) {
  849. printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
  850. }
  851. /**
  852. * list all in ports
  853. *
  854. */
  855. inports = jack_get_ports(client1, NULL, NULL, 0);
  856. /**
  857. * Test the first PHY (physical) connection to see if it's "mine".
  858. * and report the result in the test that began before.
  859. * The result is printed later.
  860. *
  861. */
  862. if (jack_port_is_mine(client1, jack_port_by_name(client1, inports[0]))) {
  863. is_mine = 0;
  864. }
  865. /**
  866. * List all devices' flags and print them...
  867. *
  868. */
  869. Log("\nTry functions jack_get_ports, jack_port_flag & jack_port_by_name to list PHY devices...\n");
  870. Log("-----------------------------------------------------------\n");
  871. Log("---------------------------DEVICES-------------------------\n");
  872. Log("-----------------------------------------------------------\n");
  873. a = 0;
  874. while (inports[a] != NULL) {
  875. flag = jack_port_flags(jack_port_by_name(client1, inports[a]) );
  876. Log(" * %s (id : %i)\n", inports[a], jack_port_by_name(client1, inports[a]));
  877. Log(" (");
  878. if (flag & JackPortIsInput)
  879. Log("JackPortIsInput ");
  880. if (flag & JackPortIsOutput)
  881. Log("JackPortIsOutput ");
  882. if (flag & JackPortIsPhysical)
  883. Log("JackPortIsPhysical ");
  884. if (flag & JackPortCanMonitor)
  885. Log("JackPortCanMonitor ");
  886. if (flag & JackPortIsTerminal)
  887. Log("JackPortIsTerminal ");
  888. Log(")\n\n");
  889. a++;
  890. }
  891. Log("-----------------------------------------------------------\n\n");
  892. /**
  893. * list all PHY in/out ports...
  894. * This list will be used later many times.
  895. *
  896. */
  897. outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
  898. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  899. if (outports == NULL) {
  900. printf("!!! WARNING !!! no physical capture ports founded !\n");
  901. }
  902. if (inports == NULL) {
  903. printf("!!! WARNING !!! no physical output ports founded !\n");
  904. }
  905. /**
  906. * Brute test : try to create as many ports as possible.
  907. * It stops when jack returns an error.
  908. * Then try to connect each port to physical entry...
  909. * Check also that graph reorder callback is called.
  910. *
  911. */
  912. Log("Registering as many ports as possible and connect them to physical entries...\n");
  913. lineports = linecount;
  914. t_error = 0;
  915. i = 0; // number of couple 'input-ouput'
  916. j = 0; // number of ports created
  917. port_callback_reg = 0; // number of port registration received by the callback
  918. reorder = 0; // number of graph reorder callback activation
  919. test_link = 0 ; // Test the "overconnect" function only one time
  920. while (t_error == 0) {
  921. sprintf (portname, "input_%d", i);
  922. input_port1 = jack_port_register(client1, portname,
  923. JACK_DEFAULT_AUDIO_TYPE,
  924. JackPortIsInput, 0);
  925. j++;
  926. if (input_port1 == NULL) {
  927. j--;
  928. t_error = 1;
  929. } else {
  930. // Connect created input to PHY output
  931. a = 0;
  932. while (outports[a] != NULL) {
  933. if (jack_connect(client1, outports[a], jack_port_name(input_port1))) {
  934. printf ("error : cannot connect input PHY port to client port %s\n", jack_port_name(input_port1));
  935. } else {
  936. // printf ("input PHY port %s connected to client port %s\n", outports[a], jack_port_name(input_port1));
  937. }
  938. a++;
  939. }
  940. // Try one time to "overconnect" 2 ports (the latest created)...
  941. if (test_link == 0) {
  942. if (jack_connect(client1, outports[a - 1], jack_port_name(input_port1)) == EEXIST) {
  943. // cannot over-connect input PHY port to client port. ok.
  944. test_link = 1;
  945. }
  946. }
  947. }
  948. sprintf(portname, "output_%d", i);
  949. output_port1 = jack_port_register(client1, portname,
  950. JACK_DEFAULT_AUDIO_TYPE,
  951. JackPortIsOutput, 0);
  952. j++;
  953. if (output_port1 == NULL) {
  954. t_error = 1;
  955. j--;
  956. } else {
  957. // Connect created input to PHY output
  958. a = 0;
  959. while (inports[a] != NULL) {
  960. if (jack_connect(client1, jack_port_name(output_port1), inports[a])) {
  961. printf ("error : cannot connect input PHY port %s to client port %s\n", inports[a], jack_port_name(output_port1));
  962. } else {
  963. // output PHY port %s connected to client port. ok.
  964. }
  965. a++;
  966. }
  967. // Try one time to "overconnect" 2 ports (the latest created)...
  968. if (test_link == 0) {
  969. if (jack_connect(client1, jack_port_name(output_port1), inports[a - 1]) == EEXIST) {
  970. // cannot over-connect output PHY port to client port. ok.
  971. test_link = 1;
  972. }
  973. }
  974. }
  975. i++;
  976. }
  977. jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
  978. if (j == port_callback_reg) {
  979. Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j, port_callback_reg);
  980. } else {
  981. printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j, k);
  982. }
  983. if (reorder == (2 * j)) {
  984. Log("%i graph reorder callback have been received... ok\n", reorder);
  985. } else {
  986. printf("!!! ERROR !!! %i graph reorder callback have been received (maybe non-valid value)...\n", reorder);
  987. }
  988. /**
  989. * print basic test connection functions result ...
  990. * over-connected means here that we try to connect 2 ports that are already connected.
  991. *
  992. */
  993. if (test_link) {
  994. Log("Jack links can't be 'over-connected'... ok\n");
  995. } else {
  996. printf("!!! ERROR !!! Jack links can be 'over-connected'...\n");
  997. }
  998. /**
  999. * Print the result of the two jack_is_mine test.
  1000. *
  1001. */
  1002. if (is_mine == 1) {
  1003. Log("Checking jack_port_is_mine()... ok\n");
  1004. } else {
  1005. printf("!!! ERROR !!! jack_port_is_mine() function seems to send non-valid datas !\n");
  1006. }
  1007. /**
  1008. * Free the array of the physical input and ouput ports.
  1009. * (as mentionned in the doc of jack_get_ports)
  1010. *
  1011. */
  1012. free(inports);
  1013. free(outports);
  1014. /**
  1015. * Try to "reactivate" the client whereas it's already activated...
  1016. *
  1017. */
  1018. if (jack_activate(client1) < 0) {
  1019. printf("!!! ERROR !!! Cannot activate client1 a second time...\n");
  1020. exit(1);
  1021. } else {
  1022. Log("jackd server accept client.jack_activate() re-activation (while client was already activated).\n");
  1023. }
  1024. /**
  1025. * Deregister all ports previously created.
  1026. *
  1027. */
  1028. Log("Deregistering all ports of the client...\n");
  1029. inports = jack_get_ports(client1, NULL, NULL, 0);
  1030. a = 0;
  1031. while (inports[a] != NULL) {
  1032. flag = jack_port_flags(jack_port_by_name(client1, inports[a]));
  1033. input_port1 = jack_port_by_name(client1, inports[a]);
  1034. if (jack_port_is_mine(client1, input_port1)) {
  1035. if (jack_port_unregister(client1, input_port1) != 0) {
  1036. printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
  1037. }
  1038. }
  1039. a++;
  1040. }
  1041. free(inports); // free array of ports (as mentionned in the doc of jack_get_ports)
  1042. /**
  1043. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1044. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1045. Open a new client (second one) to test some other things...
  1046. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1047. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1048. */
  1049. Log("\n\n----------------------------------------------------------------------\n");
  1050. Log("Starting second new client 'jack_test_#2'...\n");
  1051. /* open a client connection to the JACK server */
  1052. client_name2 = "jack_test_#2";
  1053. linecl2 = linecount; // reminders for graph analysis
  1054. client2 = jack_client_new(client_name2);
  1055. if (client2 == NULL) {
  1056. fprintf(stderr, "jack_client_new() failed for %s.\n"
  1057. "status = 0x%2.0x\n", client_name2, status);
  1058. if (status & JackServerFailed) {
  1059. fprintf(stderr, "Unable to connect client2 to JACK server\n");
  1060. }
  1061. exit(1);
  1062. }
  1063. // Check client registration callback
  1064. jack_sleep(1000);
  1065. if (client_register == 0)
  1066. printf("!!! ERROR !!! Client registration callback not called!\n");
  1067. /**
  1068. * Register callback for this client.
  1069. * Callbacks are the same as the first client for most of them, excepted for process audio callback.
  1070. *
  1071. */
  1072. jack_set_port_registration_callback(client2, Jack_Port_Register, 0);
  1073. jack_set_process_callback(client2, process2, 0);
  1074. jack_on_shutdown(client2, jack_shutdown, 0);
  1075. /**
  1076. * Register one input and one output for each client.
  1077. *
  1078. */
  1079. Log("registering 1 input/output ports for each client...\n");
  1080. output_port1 = jack_port_register(client1, "out1",
  1081. JACK_DEFAULT_AUDIO_TYPE,
  1082. JackPortIsOutput, 0);
  1083. output_port2 = jack_port_register(client2, "out2",
  1084. JACK_DEFAULT_AUDIO_TYPE,
  1085. JackPortIsOutput, 0);
  1086. input_port1 = jack_port_register(client1, "in1",
  1087. JACK_DEFAULT_AUDIO_TYPE,
  1088. JackPortIsInput, 0);
  1089. input_port2 = jack_port_register(client2, "in2",
  1090. JACK_DEFAULT_AUDIO_TYPE,
  1091. JackPortIsInput, 0);
  1092. if ((output_port1 == NULL) || (output_port2 == NULL) || (input_port1 == NULL) || (input_port2 == NULL)) {
  1093. printf("!!! ERROR !!! Unable to register ports...\n");
  1094. }
  1095. /**
  1096. * Set each process mode to idle and activate client2
  1097. *
  1098. */
  1099. process2_activated = -1;
  1100. process1_activated = -1;
  1101. if (jack_activate(client2) < 0) {
  1102. printf ("Fatal error : cannot activate client2\n");
  1103. exit (1);
  1104. }
  1105. /**
  1106. * Connect the two clients and check that all connections are well-done.
  1107. *
  1108. */
  1109. Log("Testing connections functions between clients...\n");
  1110. if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
  1111. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1112. }
  1113. if (jack_connect(client2, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
  1114. printf("!!! ERROR !!! while client2 intenting to connect ports...\n");
  1115. }
  1116. if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
  1117. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1118. }
  1119. /**
  1120. * Test the port_connected function...
  1121. *
  1122. */
  1123. if ((jack_port_connected(output_port1) == jack_port_connected(input_port1)) &&
  1124. (jack_port_connected(output_port2) == jack_port_connected(input_port2)) &&
  1125. (jack_port_connected(output_port2) == 1) &&
  1126. (jack_port_connected(output_port1) == 2)
  1127. ) {
  1128. Log("Checking jack_port_connected()... ok.\n");
  1129. } else {
  1130. printf("!!! ERROR !!! function jack_port_connected() return a bad value !\n");
  1131. printf("jack_port_connected(output_port1) %d\n", jack_port_connected(output_port1));
  1132. printf("jack_port_connected(output_port2) %d\n", jack_port_connected(output_port2));
  1133. printf("jack_port_connected(input_port1) %d\n", jack_port_connected(input_port1));
  1134. printf("jack_port_connected(input_port2) %d\n", jack_port_connected(input_port2));
  1135. }
  1136. /**
  1137. * Test a new time the port_by_name function...(now we are in multi-client mode)
  1138. *
  1139. */
  1140. Log("Testing again jack_port_by_name...\n");
  1141. if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
  1142. printf("!!! ERROR !!! function jack_port_by_name() return bad value in a multi-client application!\n");
  1143. printf("!!! jack_port_by_name(jack_port_name(_ID_) ) != _ID_ in multiclient application.\n");
  1144. } else {
  1145. Log("Checking jack_port_by_name() function with a multi-client application... ok\n");
  1146. }
  1147. /**
  1148. * Test the port_connected_to function...
  1149. *
  1150. */
  1151. if ((jack_port_connected_to (output_port1, jack_port_name(input_port2))) &&
  1152. (!(jack_port_connected_to (output_port2, jack_port_name(input_port2))))) {
  1153. Log("checking jack_port_connected_to()... ok\n");
  1154. } else {
  1155. printf("!!! ERROR !!! jack_port_connected_to() return bad value !\n");
  1156. }
  1157. /**
  1158. * Test the port_get_connections & port_get_all_connections functions...
  1159. *
  1160. */
  1161. Log("Testing jack_port_get_connections and jack_port_get_all_connections...\n");
  1162. a = 0;
  1163. t_error = 0;
  1164. connexions1 = jack_port_get_connections (output_port1);
  1165. connexions2 = jack_port_get_all_connections(client1, output_port1);
  1166. if ((connexions1 == NULL) || (connexions2 == NULL)) {
  1167. printf("!!! ERROR !!! port_get_connexions or port_get_all_connexions return a NULL pointer !\n");
  1168. } else {
  1169. while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
  1170. t_error = strcmp(connexions1[a], connexions2[a]);
  1171. a++;
  1172. }
  1173. if (t_error == 0) {
  1174. Log("Checking jack_port_get_connections Vs jack_port_get_all_connections... ok\n");
  1175. } else {
  1176. printf("!!! ERROR !!! while checking jack_port_get_connections Vs jack_port_get_all_connections...\n");
  1177. }
  1178. }
  1179. a = 0;
  1180. t_error = 0;
  1181. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1182. connexions1 = NULL;
  1183. assert(inports != NULL);
  1184. if (inports[0] != NULL) {
  1185. connexions1 = jack_port_get_connections (jack_port_by_name(client1, inports[0]));
  1186. connexions2 = jack_port_get_all_connections(client1, jack_port_by_name(client1, inports[0]));
  1187. }
  1188. free (inports);
  1189. if (connexions1 == NULL) {
  1190. Log("checking jack_port_get_connections() for external client... ok\n");
  1191. } else {
  1192. while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
  1193. t_error = strcmp(connexions1[a], connexions2[a]);
  1194. a++;
  1195. }
  1196. }
  1197. if (t_error == 0) {
  1198. Log("Checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port... ok\n");
  1199. } else {
  1200. printf("!!! ERROR !!! while checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port...\n");
  1201. }
  1202. if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
  1203. printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
  1204. }
  1205. if (jack_disconnect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
  1206. printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
  1207. }
  1208. // No links should subsist now...
  1209. /**
  1210. * Checking data connexion
  1211. * establishing a link between client1.out1 --> client2.in2
  1212. * Send the signal1 test on out1. Record the result into signal2. (see process functions).
  1213. ---------------------------------------------------------------------------*/
  1214. Log("Testing connections datas between clients...\n");
  1215. jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2) );
  1216. process2_activated = -1;
  1217. process1_activated = -1;
  1218. Log("process 2 : idle mode...\n");
  1219. Log("Sending datas...");
  1220. index1 = 0;
  1221. index2 = 0;
  1222. process1_activated = 1; // We start emitting first.
  1223. process2_activated = 1; // So record begin at least when we just begin to emitt the signal, else at next call of process with
  1224. // nframe = jack buffersize shifting.
  1225. while (process2_activated == 1) {
  1226. jack_sleep(1 * 1000);
  1227. Log(".");
  1228. }
  1229. index2 = 0;
  1230. Log("\nAnalysing datas...\n"); // search the first occurence of the first element of the reference signal in the recorded signal
  1231. while (signal2[index2] != signal1[1] ) {
  1232. index2++;
  1233. if (index2 == 95999) {
  1234. printf("!!! ERROR !!! Data not found in first connexion data check!\n");
  1235. break;
  1236. }
  1237. }
  1238. index1 = index2;
  1239. Log("Data founded at offset %i.\n", index2);
  1240. // And now we founded were the recorded data are, we can see if the two signals matches...
  1241. while ( (signal2[index2] == signal1[index2 - index1 + 1]) || (index2 == 95999) || ((index2 - index1 + 1) == 47999) ) {
  1242. index2++;
  1243. }
  1244. Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
  1245. if ((index2 - index1) == 48000) {
  1246. Log("Data received are valid...\n");
  1247. } else {
  1248. printf("!!! ERROR !!! data transmission seems not to be valid in first connexion data check!\n");
  1249. }
  1250. if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port2) ) != 0)
  1251. // no more connection between ports exist now...
  1252. {
  1253. printf("Error while establishing new connexion (disconnect).\n");
  1254. }
  1255. /**
  1256. * Test TIE MODE
  1257. * (This mode seems to be problematic in standard jack version 0.100. It seems that nobody
  1258. * is used to apply this mode because the tie mode doesn't work at all. A patch seems difficult to produce
  1259. * in this version of jack. Tie mode work well in MP version.)
  1260. * Test some basic thinks (tie with 2 differents client, tie non-owned ports...)
  1261. * Tie client1.in1 and client1.out1 ports, and make some data test to check the validity of the tie.
  1262. *
  1263. */
  1264. Log("Testing tie mode...\n");
  1265. if (jack_port_tie(input_port1, output_port2) != 0) {
  1266. Log("not possible to tie two ports from two differents clients... ok\n");
  1267. } else {
  1268. printf("!!! ERROR !!! port_tie has allowed a connexion between two differents clients !\n");
  1269. jack_port_untie(output_port2);
  1270. }
  1271. Log("Testing connections datas in tie mode...\n");
  1272. int g;
  1273. for (g = 0; g < 96000; g++)
  1274. signal2[g] = 0.0;
  1275. // Create a loop (emit test) client2.out2----client.in1--tie--client1.out1-----client2.in1 (receive test)
  1276. if (jack_port_tie(input_port1, output_port1) != 0) {
  1277. printf("Unable to tie... fatal error : data test will not be performed on tie mode !!\n");
  1278. } else { // begin of tie
  1279. if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
  1280. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1281. }
  1282. if (jack_connect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
  1283. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1284. }
  1285. process1_activated = -1;
  1286. process2_activated = -1;
  1287. // We can manualy check here that the tie is effective.
  1288. // ie : playing a wav with a client, connecting ports manualy with qjackctl, and listen...
  1289. // printf("manual test\n");
  1290. // jack_sleep(50);
  1291. // printf("end of manual test\n");
  1292. index1 = 0;
  1293. index2 = 0;
  1294. process1_activated = -1;
  1295. process2_activated = 2;
  1296. Log("Sending datas...");
  1297. while (process2_activated == 2) {
  1298. jack_sleep(1 * 1000);
  1299. Log(".");
  1300. }
  1301. process1_activated = -1;
  1302. process2_activated = -1;
  1303. index2 = 0;
  1304. Log("\nAnalysing datas...\n");
  1305. // We must find at least 2 identical values to ensure we are at the right place in the siusoidal array...
  1306. while (!((signal2[index2] == signal1[1]) && (signal2[index2 + 1] == signal1[2]))) {
  1307. index2++;
  1308. if (index2 == 95999) {
  1309. printf("!!! ERROR !!! Data not found in connexion check of tie mode!\n");
  1310. break;
  1311. }
  1312. }
  1313. index1 = index2;
  1314. Log("Tie mode : Data founded at offset %i.\n", index2);
  1315. while (signal2[index2] == signal1[index2 - index1 + 1]) {
  1316. index2++;
  1317. if ((index2 == 95999) || ((index2 - index1 + 1) == 47999)) {
  1318. break;
  1319. }
  1320. }
  1321. Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
  1322. if ((index2 - index1) > 47995) {
  1323. Log("Data received in tie mode are valid...\n");
  1324. } else {
  1325. // in tie mode, the buffers adress should be the same for the two tied ports.
  1326. printf("!!! ERROR !!! data transmission seems not to be valid !\n");
  1327. printf("Links topology : (emitt) client2.out2 ----> client1.in1--(tie)--client1.out1----->client2.in2 (recive)\n");
  1328. printf(" port_name : Port_adress \n");
  1329. printf(" output_port1 : %px\n", jack_port_get_buffer(output_port1, cur_buffer_size));
  1330. printf(" input_port2 : %px\n", jack_port_get_buffer(input_port2, cur_buffer_size));
  1331. printf(" output_port2 : %px\n", jack_port_get_buffer(output_port2, cur_buffer_size));
  1332. printf(" input_port1 : %px\n", jack_port_get_buffer(input_port1, cur_buffer_size));
  1333. }
  1334. jack_port_untie(output_port1);
  1335. jack_port_disconnect(client1, output_port2);
  1336. jack_port_disconnect(client1, output_port1);
  1337. } //end of tie
  1338. /**
  1339. * Testing SUMMATION CAPABILITIES OF JACK CONNECTIONS
  1340. *
  1341. * In a short test, we just check a simple summation in jack.
  1342. * A first client(client1) send two signal in phase opposition
  1343. * A second client(client2) record the summation at one of his port
  1344. * So, the result must be zero...
  1345. * See process1 for details about steps of this test
  1346. *
  1347. */
  1348. // fprintf(file, "Sum test\n");
  1349. Log("Checking summation capabilities of patching...\n");
  1350. output_port1b = jack_port_register(client1, "out1b",
  1351. JACK_DEFAULT_AUDIO_TYPE,
  1352. JackPortIsOutput, 0);
  1353. jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2));
  1354. jack_connect(client2, jack_port_name(output_port1b), jack_port_name(input_port2));
  1355. process1_activated = 3;
  1356. process2_activated = -1;
  1357. for (g = 0; g < 96000; g++)
  1358. signal2[g] = 0.0;
  1359. index1 = 0;
  1360. index2 = 0;
  1361. Log("Sending datas...");
  1362. process2_activated = 3;
  1363. while (process2_activated == 3) {
  1364. jack_sleep(1 * 1000);
  1365. Log(".");
  1366. }
  1367. process1_activated = -1;
  1368. process2_activated = -1;
  1369. index2 = 0;
  1370. Log("\nAnalysing datas...\n"); // same idea as above, with first data check...
  1371. while (!((signal2[index2] == 0.0 ) && (signal2[(index2 + 1)] == 0.0 ))) {
  1372. index2++;
  1373. if (index2 == 95999) {
  1374. printf("!!! ERROR !!! Data not found in summation check!\n");
  1375. break;
  1376. }
  1377. }
  1378. index1 = index2;
  1379. Log("Data founded at offset %i.\n", index2);
  1380. while ( signal2[index2] == 0.0 ) {
  1381. index2++;
  1382. if ((index2 > 95998) || ((index2 - index1 + 1) > 47998)) {
  1383. break;
  1384. }
  1385. }
  1386. Log("Checking difference between datas...\n");
  1387. if ((index2 - index1) > 47996) {
  1388. Log("Data mixed received are valid...\nSummation is well done.\n");
  1389. } else {
  1390. printf("!!! ERROR !!! data transmission / summation seems not to be valid !\n");
  1391. }
  1392. jack_port_disconnect(client1, output_port1);
  1393. jack_port_disconnect(client1, output_port1b);
  1394. jack_port_unregister(client1, output_port1b);
  1395. if (jack_port_name(output_port1b) != NULL ) {
  1396. printf("!!! WARNING !!! port_name return something while the port have been unregistered !\n");
  1397. printf("!!! Name of unregistered port : %s !\n", jack_port_name(output_port1b));
  1398. } else {
  1399. Log("Checking jack_port_name() with a non valid port... ok\n");
  1400. }
  1401. if (jack_port_set_name(output_port1b, "new_name") == 0 ) {
  1402. printf("!!! WARNING !!! An unregistered port can be renamed successfully !\n");
  1403. } else {
  1404. Log("Checking renaming of an unregistered port... ok\n");
  1405. }
  1406. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1407. if (jack_port_set_name(jack_port_by_name(client1, inports[0]), "new_name") == 0 ) {
  1408. printf("!!! WARNING !!! A PHYSICAL port can be renamed successfully !\n");
  1409. } else {
  1410. Log("Checking renaming of an unregistered port... ok\n");
  1411. }
  1412. free (inports);
  1413. /**
  1414. * Checking latency issues
  1415. * here are simple latency check
  1416. * We simply check that the value returned by jack seems ok
  1417. * Latency compensation is a difficult point.
  1418. * Actually, jack is not able to see "thru" client to build a full latency chain.
  1419. * Ardour use theses informations to do internally his compensations.
  1420. *
  1421. * 3 test are done : one with no connections between client, one with a serial connection, and one with parallel connection
  1422. */
  1423. Log("Checking about latency functions...\n");
  1424. t_error = 0;
  1425. jack_recompute_total_latencies(client1);
  1426. if ((jack_port_get_latency (output_port1) != 0) ||
  1427. (jack_port_get_total_latency(client1, output_port1) != 0) ) {
  1428. t_error = 1;
  1429. printf("!!! ERROR !!! default latency of a non-PHY device is not set to zero !\n");
  1430. }
  1431. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1432. outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
  1433. if (inports[0] != NULL) {
  1434. output_ext_latency = jack_port_get_latency (jack_port_by_name(client1, inports[0])); // from client to out driver (which has "inputs" ports..)
  1435. input_ext_latency = jack_port_get_latency (jack_port_by_name(client1, outports[0])); // from in driver (which has "output" ports..) to client
  1436. if (output_ext_latency != jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0]))) {
  1437. t_error = 1;
  1438. printf("!!! ERROR !!! get_latency & get_all_latency for a PHY device (unconnected) didn't return the same value !\n");
  1439. }
  1440. Log("Checking a serial model with 2 clients...\n");
  1441. jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2));
  1442. jack_connect(client1, outports[0], jack_port_name(input_port1));
  1443. jack_connect(client2, jack_port_name(output_port2), inports[0]);
  1444. jack_port_set_latency(output_port2, 256);
  1445. jack_recompute_total_latencies(client1);
  1446. if ((jack_port_get_latency (output_port1) != 0) ||
  1447. (jack_port_get_total_latency(client1, output_port1) != 0) ||
  1448. (jack_port_get_latency (jack_port_by_name(client1, inports[0])) != (output_ext_latency)) ||
  1449. (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (output_ext_latency + 256)) ||
  1450. (jack_port_get_total_latency(client1, output_port2) != (output_ext_latency + 256)) ||
  1451. (jack_port_get_total_latency(client1, input_port2) != 0) ||
  1452. (jack_port_get_total_latency(client1, input_port1) != input_ext_latency) ||
  1453. (jack_port_get_latency (jack_port_by_name(client1, outports[0])) != input_ext_latency) ||
  1454. (jack_port_get_total_latency(client1, jack_port_by_name(client1, outports[0])) != input_ext_latency)
  1455. ) {
  1456. printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
  1457. printf("!!! get_latency(output_port1) : %i (must be 0)\n", jack_port_get_latency(output_port1));
  1458. printf("!!! get_total_latency(output_port1) : %i (must be 0)\n", jack_port_get_total_latency(client1, output_port1));
  1459. 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);
  1460. 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));
  1461. printf("!!! get_total_latency(output_port2) : %i (must be %i)\n", jack_port_get_total_latency(client1, output_port2), (output_ext_latency + 256));
  1462. printf("!!! get_total_latency(input_port2) : %i (must be 0)\n", jack_port_get_total_latency(client1, input_port2));
  1463. printf("!!! get_total_latency(input_port1) : %i (must be %i)\n", jack_port_get_total_latency(client1, input_port1), input_ext_latency);
  1464. printf("!!! get_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_latency(jack_port_by_name(client1, outports[0])), input_ext_latency);
  1465. 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);
  1466. } else {
  1467. Log("get_latency & get_total_latency seems quite ok...\n");
  1468. }
  1469. jack_port_disconnect(client1, output_port1);
  1470. jack_port_disconnect(client1, output_port2);
  1471. jack_port_disconnect(client1, input_port1);
  1472. jack_port_disconnect(client1, input_port2);
  1473. Log("Checking a parallel model with 2 clients...\n");
  1474. jack_connect(client2, outports[0], jack_port_name(input_port1));
  1475. jack_connect(client2, outports[0], jack_port_name(input_port2));
  1476. jack_connect(client2, jack_port_name(output_port1), inports[0]);
  1477. jack_connect(client2, jack_port_name(output_port2), inports[0]);
  1478. jack_port_set_latency(output_port1, 256);
  1479. jack_port_set_latency(output_port2, 512);
  1480. jack_recompute_total_latencies(client1);
  1481. if ((jack_port_get_latency(output_port1) != 256 ) ||
  1482. (jack_port_get_total_latency(client1, output_port1) != (256 + output_ext_latency)) ||
  1483. (jack_port_get_latency(output_port2) != 512) ||
  1484. (jack_port_get_total_latency(client1, output_port2) != (512 + output_ext_latency)) ||
  1485. (jack_port_get_latency(jack_port_by_name(client1, inports[0])) != output_ext_latency) ||
  1486. (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (512 + output_ext_latency))
  1487. ) {
  1488. printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
  1489. printf("!!! get_latency(output_port1) : %i (must be 256)\n", jack_port_get_latency(output_port1));
  1490. printf("!!! get_total_latency(output_port1) : %i (must be 256 + output_ext_latency)\n", jack_port_get_total_latency(client1, output_port1));
  1491. printf("!!! get_latency(output_port2) : %i (must 512)\n", jack_port_get_latency(output_port2));
  1492. printf("!!! get_total_latency(output_port2) : %i (must 512 + output_ext_latency)\n", jack_port_get_total_latency(client1, output_port2));
  1493. printf("!!! get_latency(inports[0])) : %i (must output_ext_latency)\n", jack_port_get_latency(jack_port_by_name(client1, inports[0])));
  1494. 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])));
  1495. } else {
  1496. Log("get_latency & get_total_latency seems quite ok...\n");
  1497. }
  1498. } else {
  1499. printf("No physical port founded : not able to test latency functions...");
  1500. }
  1501. jack_port_disconnect(client1, input_port1);
  1502. jack_port_disconnect(client1, input_port2);
  1503. jack_port_disconnect(client1, output_port1);
  1504. jack_port_disconnect(client1, output_port2);
  1505. jack_sleep(1000);
  1506. free(inports);
  1507. free(outports);
  1508. /**
  1509. * Checking transport API.
  1510. * Simple transport test.
  1511. * Check a transport start with a "slow" client, simulating a delay around 1 sec before becoming ready.
  1512. *
  1513. */
  1514. Log("-----------------------------------------------------------\n");
  1515. Log("---------------------------TRANSPORT-----------------------\n");
  1516. Log("-----------------------------------------------------------\n");
  1517. lineports = linecount;
  1518. if (transport_mode) {
  1519. int wait_count;
  1520. ts = jack_transport_query(client1, &pos);
  1521. if (ts == JackTransportStopped) {
  1522. Log("Transport is stopped...\n");
  1523. } else {
  1524. jack_transport_stop(client1);
  1525. Log("Transport state : %i\n", ts);
  1526. }
  1527. if (jack_set_sync_callback(client2, Jack_Sync_Callback, 0) != 0)
  1528. printf("error while calling set_sync_callback...\n");
  1529. Log("starting transport...\n");
  1530. starting_state = 1; // Simulate starting state
  1531. jack_transport_start(client1);
  1532. // Wait until sync callback is called
  1533. while (!(sync_called)) {
  1534. jack_sleep(1 * 1000);
  1535. }
  1536. // Wait untill rolling : simulate sync time out
  1537. Log("Simulate a slow-sync client exceeding the time-out\n");
  1538. wait_count = 0;
  1539. do {
  1540. jack_sleep(100); // Wait 100 ms each cycle
  1541. wait_count++;
  1542. if (wait_count == 100) {
  1543. Log("!!! ERROR !!! max time-out exceedeed : sync time-out does not work correctly\n");
  1544. break;
  1545. }
  1546. ts = jack_transport_query(client2, &pos);
  1547. Log("Waiting....pos = %ld\n", pos.frame);
  1548. display_transport_state();
  1549. } while (ts != JackTransportRolling);
  1550. Log("Sync callback have been called %i times.\n", sync_called);
  1551. jack_transport_stop(client1);
  1552. // Wait until stopped
  1553. ts = jack_transport_query(client2, &pos);
  1554. while (ts != JackTransportStopped) {
  1555. jack_sleep(1 * 1000);
  1556. ts = jack_transport_query(client2, &pos);
  1557. }
  1558. // Simulate starting a slow-sync client that rolls after 0.5 sec
  1559. Log("Simulate a slow-sync client that needs 0.5 sec to start\n");
  1560. sync_called = 0;
  1561. wait_count = 0;
  1562. starting_state = 1; // Simulate starting state
  1563. Log("Starting transport...\n");
  1564. jack_transport_start(client1);
  1565. display_transport_state();
  1566. Log("Waiting 0.5 sec...\n");
  1567. jack_sleep(500);
  1568. starting_state = 0; // Simulate end of starting state after 0.5 sec
  1569. // Wait untill rolling
  1570. ts = jack_transport_query(client2, &pos);
  1571. while (ts != JackTransportRolling) {
  1572. jack_sleep(100); // Wait 100 ms each cycle
  1573. wait_count++;
  1574. if (wait_count == 10) {
  1575. Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
  1576. break;
  1577. }
  1578. ts = jack_transport_query(client2, &pos);
  1579. }
  1580. if (sync_called == 0)
  1581. Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
  1582. Log("Sync callback have been called %i times.\n", sync_called);
  1583. display_transport_state();
  1584. // Test jack_transport_locate while rolling
  1585. Log("Test jack_transport_locate while rolling\n");
  1586. ts = jack_transport_query(client2, &pos);
  1587. Log("Transport current frame = %ld\n", pos.frame);
  1588. jack_nframes_t cur_frame = pos.frame;
  1589. wait_count = 0;
  1590. do {
  1591. display_transport_state();
  1592. jack_sleep(10); // 10 ms
  1593. // locate at first...
  1594. wait_count++;
  1595. if (wait_count == 1) {
  1596. Log("Do jack_transport_locate\n");
  1597. jack_transport_locate(client1, cur_frame / 2);
  1598. } else if (wait_count == 100) {
  1599. break;
  1600. }
  1601. ts = jack_transport_query(client2, &pos);
  1602. Log("Locating.... frame = %ld\n", pos.frame);
  1603. } while (pos.frame > cur_frame);
  1604. ts = jack_transport_query(client2, &pos);
  1605. Log("Transport current frame = %ld\n", pos.frame);
  1606. if (wait_count == 100) {
  1607. printf("!!! ERROR !!! jack_transport_locate does not work correctly\n");
  1608. }
  1609. // Test jack_transport_reposition while rolling
  1610. Log("Test jack_transport_reposition while rolling\n");
  1611. ts = jack_transport_query(client2, &pos);
  1612. Log("Transport current frame = %ld\n", pos.frame);
  1613. cur_frame = pos.frame;
  1614. wait_count = 0;
  1615. do {
  1616. display_transport_state();
  1617. jack_sleep(10); // 10 ms
  1618. // locate at first...
  1619. wait_count++;
  1620. if (wait_count == 1) {
  1621. Log("Do jack_transport_reposition\n");
  1622. request_pos.frame = cur_frame / 2;
  1623. jack_transport_reposition(client1, &request_pos);
  1624. } else if (wait_count == 100) {
  1625. break;
  1626. }
  1627. ts = jack_transport_query(client2, &pos);
  1628. Log("Locating.... frame = %ld\n", pos.frame);
  1629. } while (pos.frame > cur_frame);
  1630. ts = jack_transport_query(client2, &pos);
  1631. Log("Transport current frame = %ld\n", pos.frame);
  1632. if (wait_count == 100) {
  1633. printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
  1634. }
  1635. // Test jack_transport_reposition while stopped
  1636. jack_transport_stop(client1);
  1637. ts = jack_transport_query(client2, &pos);
  1638. Log("Transport current frame = %ld\n", pos.frame);
  1639. Log("Test jack_transport_reposition while stopped\n");
  1640. wait_count = 0;
  1641. request_pos.frame = 10000;
  1642. jack_transport_reposition(client1, &request_pos);
  1643. do {
  1644. display_transport_state();
  1645. jack_sleep(100); // 100 ms
  1646. if (wait_count++ == 10)
  1647. break;
  1648. ts = jack_transport_query(client2, &pos);
  1649. Log("Locating.... frame = %ld\n", pos.frame);
  1650. } while (pos.frame != 10000);
  1651. ts = jack_transport_query(client2, &pos);
  1652. Log("Transport current frame = %ld\n", pos.frame);
  1653. if (pos.frame != 10000) {
  1654. printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
  1655. }
  1656. jack_transport_stop(client1);
  1657. /* Tell the JACK server that we are ready to roll. Our
  1658. * process() callback will start running now. */
  1659. } else {
  1660. printf("Transport check is disabled...\n");
  1661. }
  1662. time_before_exit = time_to_run;
  1663. while (time_before_exit != 0) {
  1664. jack_sleep (1 * 1000);
  1665. time_before_exit--;
  1666. }
  1667. if (jack_deactivate(client2) != 0) {
  1668. printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
  1669. }
  1670. if (jack_deactivate(client1) != 0) {
  1671. printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
  1672. }
  1673. /**
  1674. * Checking jack_frame_time.
  1675. */
  1676. Log("Testing jack_frame_time...\n");
  1677. jack_set_process_callback(client1, process4, client1);
  1678. jack_activate(client1);
  1679. jack_sleep(2 * 1000);
  1680. /**
  1681. * Checking alternate thread model
  1682. */
  1683. Log("Testing alternate thread model...\n");
  1684. jack_deactivate(client1);
  1685. jack_set_process_callback(client1, NULL, NULL); // remove callback
  1686. jack_set_process_thread(client1, jack_thread, client1);
  1687. jack_activate(client1);
  1688. jack_sleep(2 * 1000);
  1689. /**
  1690. * Checking callback exiting : when the return code is != 0, the client is desactivated.
  1691. */
  1692. Log("Testing callback exiting...\n");
  1693. jack_deactivate(client1);
  1694. jack_set_process_thread(client1, NULL, NULL); // remove thread callback
  1695. jack_set_process_callback(client1, process3, 0);
  1696. jack_activate(client1);
  1697. jack_sleep(3 * 1000);
  1698. /**
  1699. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1700. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1701. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1702. Closing program
  1703. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1704. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1705. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1706. */
  1707. if (jack_deactivate(client2) != 0) {
  1708. printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
  1709. }
  1710. if (jack_deactivate(client1) != 0) {
  1711. printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
  1712. }
  1713. if (jack_client_close(client2) != 0) {
  1714. printf("!!! ERROR !!! jack_client_close does not return 0 for client2 !\n");
  1715. }
  1716. if (jack_client_close(client1) != 0) {
  1717. printf("!!! ERROR !!! jack_client_close does not return 0 for client1 !\n");
  1718. }
  1719. if (xrun == 0) {
  1720. Log("No Xrun have been detected during this test... cool !\n");
  1721. } else {
  1722. printf("%i Xrun have been detected during this session (seen callback messages to see where are the problems).\n", xrun);
  1723. }
  1724. free(framecollect);
  1725. free(signal1);
  1726. free(signal2);
  1727. Log("Exiting jack_test...\n");
  1728. fclose(file);
  1729. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  1730. sprintf (filename, "framegraph-%i.gnu", cur_buffer_size);
  1731. file = fopen(filename, "w");
  1732. if (file == NULL) {
  1733. fprintf(stderr, "Erreur dans l'ouverture du fichier");
  1734. exit( -1);
  1735. }
  1736. fprintf(file, "reset\n");
  1737. fprintf(file, "set terminal png transparent nocrop enhanced\n");
  1738. fprintf(file, "set output 'framegraph-%i-1.png'\n", cur_buffer_size);
  1739. fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
  1740. 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));
  1741. fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
  1742. fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
  1743. fprintf(file, "set xlabel \"FrameTime\"\n");
  1744. 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);
  1745. 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);
  1746. fprintf(file, "set output 'framegraph-%i-2.png'\n", cur_buffer_size);
  1747. fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
  1748. 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)));
  1749. fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
  1750. fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
  1751. fprintf(file, "set xlabel \"FrameTime\"\n");
  1752. 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);
  1753. 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);
  1754. fclose(file);
  1755. return 0;
  1756. }