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.

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