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.

1936 lines
76KB

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