Fix loading internal client from another internal client
[jack2.git] / tests / test.cpp
blob34a436a74fd534ee0cc8d4aa00da890f6c782449
1 /*
2 Copyright (C) 2005 Samuel TRACOL for GRAME
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file jack_test.c
22 * @brief This client test the jack API.
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <errno.h>
29 #ifndef WIN32
30 #include <unistd.h>
31 #endif
32 #include <string.h>
33 #include <getopt.h>
34 #include <math.h>
35 #include <assert.h>
36 #include <stdarg.h>
37 #include <jack/jack.h>
38 #include <jack/intclient.h>
39 #include <jack/transport.h>
41 #define TEST_EXCLUDE_DEPRECATED 1
43 #if defined(WIN32) && !defined(M_PI)
44 #define M_PI 3.151592653
45 #endif
47 #ifdef WIN32
48 #define jack_sleep(val) Sleep((val))
49 #else
50 #define jack_sleep(val) usleep((val) * 1000)
51 #endif
53 typedef struct
55 jack_nframes_t ft; // running counter frame time
56 jack_nframes_t fcs; // from sycle start...
57 jack_nframes_t lft; // last frame time...
59 FrameTimeCollector;
61 FILE *file;
62 FrameTimeCollector* framecollect;
63 FrameTimeCollector perpetualcollect;
64 FrameTimeCollector lastperpetualcollect;
65 int frames_collected = 0;
67 // ports
68 jack_port_t *output_port1;
69 jack_port_t *output_port1b;
70 jack_port_t *input_port2;
71 jack_port_t *output_port2;
72 jack_port_t *input_port1;
74 // clients
75 jack_client_t *client1;
76 jack_client_t *client2;
77 const char *client_name1;
78 const char *client_name2;
80 unsigned long sr; // sample rate
81 // for time -t option
82 int time_to_run = 0;
83 int time_before_exit = 1;
84 // standard error count
85 int t_error = 0;
86 int reorder = 0; // graph reorder callback
87 int RT = 0; // is real time or not...
88 int FW = 0; // freewheel mode
89 int init_clbk = 0; // init callback
90 int port_rename_clbk = 0; // portrename callback
91 int i, j, k = 0;
92 int port_callback_reg = 0;
93 jack_nframes_t cur_buffer_size, old_buffer_size, cur_pos;
94 int activated = 0;
95 int count1, count2 = 0; // for freewheel
96 int xrun = 0;
97 int have_xrun = 0; // msg to tell the process1 function to write a special thing in the frametime file.
98 int process1_activated = -1; // to control processing...
99 int process2_activated = -1; // to control processing...
100 unsigned long int index1 = 0;
101 unsigned long int index2 = 0;
102 jack_default_audio_sample_t *signal1; // signal source d'emission
103 jack_default_audio_sample_t *signal2; // tableau de reception
104 jack_transport_state_t ts;
105 jack_position_t pos;
106 jack_position_t request_pos;
107 int silent_error = 0; // jack silent mode
108 int verbose_mode = 0;
109 int transport_mode = 1;
110 jack_nframes_t input_ext_latency = 0; // test latency for PHY devices
111 jack_nframes_t output_ext_latency = 0; // test latency for PHY devices
113 int sync_called = 0;
114 int starting_state = 1;
116 int linecount = 0; // line counter for log file of sampleframe counter --> for graph function.
117 int linebuf = 0; // reminders for graph analysis
118 int linetransport = 0;
119 int linefw = 0;
120 int lineports = 0;
121 int linecl2 = 0;
123 int client_register = 0;
126 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
127 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
129 Callbacks & basics functions
131 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
132 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
135 void usage()
137 fprintf (stderr, "\n\n"
138 "usage: jack_test \n"
139 " [ --time OR -t time_to_run (in seconds) ]\n"
140 " [ --quiet OR -q (quiet mode : without jack server errors) ]\n"
141 " [ --verbose OR -v (verbose mode : no details on tests done. Only main results & errors) ]\n"
142 " [ --transport OR -k (Do not test transport functions.) ]\n"
143 " --realtime OR -R (jack is in rt mode)\n\n\n"
145 exit(1);
148 void Log(const char *fmt, ...)
150 if (verbose_mode) {
151 va_list ap;
152 va_start(ap, fmt);
153 vfprintf(stderr, fmt, ap);
154 va_end(ap);
158 void Collect(FrameTimeCollector* TheFrame)
160 TheFrame->lft = jack_last_frame_time(client1);
161 TheFrame->ft = jack_frame_time(client1);
162 TheFrame->fcs = jack_frames_since_cycle_start(client1);
165 void Jack_Thread_Init_Callback(void *arg)
167 #ifdef WIN32
168 Log("Init callback has been successfully called from thread = %x. (msg from callback)\n", GetCurrentThread());
169 #else
170 Log("Init callback has been successfully called from thread = %x. (msg from callback)\n", pthread_self());
171 #endif
172 init_clbk = 1;
175 void Jack_Freewheel_Callback(int starting, void *arg)
177 Log("Freewheel callback has been successfully called with value %i. (msg from callback)\n", starting);
178 FW = starting;
181 void Jack_Client_Registration_Callback(const char* name, int val, void *arg)
183 Log("Client registration callback name = %s has been successfully called with value %i. (msg from callback)\n", name, val);
184 if (val)
185 client_register++;
186 else
187 client_register--;
190 void Jack_Port_Rename_Callback(jack_port_id_t port, const char* old_name, const char* new_name, void *arg)
192 Log("Rename callback has been successfully called with old_name '%s' and new_name '%s'. (msg from callback)\n", old_name, new_name);
193 port_rename_clbk = 1;
196 int Jack_Update_Buffer_Size(jack_nframes_t nframes, void *arg)
198 cur_buffer_size = jack_get_buffer_size(client1);
199 Log("Buffer size = %d (msg from callback)\n", cur_buffer_size);
200 return 0;
203 int Jack_XRun_Callback(void *arg)
205 xrun++;
206 have_xrun = 1;
207 Log("Xrun has been detected ! (msg from callback)\n");
208 return 0;
211 int Jack_Graph_Order_Callback(void *arg)
213 reorder++;
214 return 0;
217 int Jack_Sample_Rate_Callback(jack_nframes_t nframes, void *arg)
219 Log("Sample rate : %i.\n", nframes);
220 return 0;
223 void Jack_Error_Callback(const char *msg)
225 if (silent_error == 0) {
226 fprintf(stderr, "error : %s (msg from callback)\n", msg);
230 void jack_shutdown(void *arg)
232 printf("Jack_test has been kicked out by jackd !\n");
233 exit(1);
236 void jack_info_shutdown(jack_status_t code, const char* reason, void *arg)
238 printf("JACK server failure : %s\n", reason);
239 exit(1);
242 void Jack_Port_Register(jack_port_id_t port, int mode, void *arg)
244 port_callback_reg++;
247 void Jack_Port_Connect(jack_port_id_t a, jack_port_id_t b, int connect, void* arg)
249 Log("PortConnect src = %ld dst = %ld onoff = %ld (msg from callback)\n", a, b, connect);
252 int Jack_Sync_Callback(jack_transport_state_t state, jack_position_t *pos, void *arg)
254 int res = 0;
256 switch (state) {
258 case JackTransportStarting:
259 sync_called++;
260 if (starting_state == 0) {
261 Log("sync callback : Releasing status : now ready...\n");
262 res = 1;
263 } else {
264 if (sync_called == 1) {
265 Log("sync callback : Holding status...\n");
267 res = 0;
269 break;
271 case JackTransportStopped:
272 Log("sync callback : JackTransportStopped...\n");
273 res = 0;
274 break;
276 default:
277 res = 0;
278 break;
281 return res;
286 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
287 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
289 processing functions
291 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
292 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
293 * Proccess1 is for client1
294 * 4 modes, activated with process1_activated
296 * -1 : idle mode
297 * 0 : write zeros to output 1
298 * 1 : write continuously signal1 (sinusoidal test signal) to output1
299 * 3 : mode for summation test. While record (done by process2) is not running, write signal1 to both out1 & out1b.
300 * when record begin (index2 > 0), write signal1 in phase opposition to out1 & out2
301 * 5 : Frames Time checking mode : write the array containing the three values of frame_time, frames cycles start and
302 * last frame time during 150 cycles.
305 int process1(jack_nframes_t nframes, void *arg)
307 if (FW == 0) {
308 Collect(&perpetualcollect);
309 if (have_xrun) {
310 fprintf(file, "%i %i\n", (perpetualcollect.ft - lastperpetualcollect.ft), (2*cur_buffer_size));
311 have_xrun = 0;
312 } else {
313 fprintf(file, "%i 0\n", (perpetualcollect.ft - lastperpetualcollect.ft));
315 linecount++;
316 lastperpetualcollect.ft = perpetualcollect.ft;
319 jack_default_audio_sample_t *out1;
320 jack_default_audio_sample_t *out1b;
321 activated++; // counter of callback activation
322 if (process1_activated == 1) {
323 out1 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1, nframes);
324 for (jack_nframes_t p = 0; p < nframes; p++) {
325 out1[p] = signal1[index1];
326 index1++;
327 if (index1 == 48000)
328 index1 = 0;
331 if (process1_activated == 3) {
332 out1 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1, nframes);
333 out1b = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1b, nframes);
334 for (jack_nframes_t p = 0; p < nframes; p++) {
335 out1[p] = signal1[index1];
336 if (index2 != 0) {
337 out1b[p] = ( -1 * signal1[index1]);
338 } else {
339 out1b[p] = signal1[index1];
341 index1++;
342 if (index1 == 48000)
343 index1 = 0;
346 if (process1_activated == 0) {
347 out1 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1, nframes);
348 memset (out1, 0, sizeof (jack_default_audio_sample_t) * nframes); //�crit des z�ros en sortie...
350 if (process1_activated == 5) {
351 Collect(&framecollect[frames_collected]);
352 frames_collected++;
353 if (frames_collected > 798) {
354 process1_activated = -1;
357 return 0;
361 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
362 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
363 * Proccess2 is for client2
364 * 3 modes, activated with process1_activated
366 * -1 : idle mode
367 * 0 : idle mode
368 * 1 : record in2 into signal2.(for first transmit test)
369 * 2 : record in2 into signal2 while send signal1 in out2. used dor Tie data test.
370 * 3 : record in2 into sigal2 for summation data test.
371 * In records modes, at the end of the record (signal2 is full), it stop the test, setting both activation states to -1.
374 int process2(jack_nframes_t nframes, void *arg)
376 jack_default_audio_sample_t *out2;
377 jack_default_audio_sample_t *in2;
379 if (process2_activated == 1) { // Reception du process1 pour comparer les donnees
380 in2 = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port2, nframes);
381 for (unsigned int p = 0; p < nframes; p++) {
382 signal2[index2] = in2[p];
383 if (index2 == 95999) {
384 process2_activated = 0;
385 process1_activated = 0;
386 //index2 = 0;
387 } else {
388 index2++;
393 if (process2_activated == 2) { // envoie de signal1 pour test tie mode et le r�cup�re direct + latence de la boucle jack...
394 out2 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port2, nframes);
395 in2 = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port2, nframes);
397 for (unsigned int p = 0; p < nframes; p++) {
398 out2[p] = signal1[index1];
399 index1++;
400 if (index1 == 48000)
401 index1 = 0;
402 signal2[index2] = in2[p];
403 if (index2 == 95999) {
404 process2_activated = -1;
405 //index2 = 0;
406 } else {
407 index2++;
412 if (process2_activated == 3) { // envoie de -signal1 pour sommation en oppo de phase par jack
413 in2 = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port2, nframes);
415 for (unsigned int p = 0; p < nframes;p++) {
416 signal2[index2] = in2[p];
417 if (index2 == 95999) {
418 process2_activated = 0;
419 process1_activated = 0;
420 //index2 = 0;
421 } else {
422 index2++;
427 return 0;
430 // Alternate thread model
431 static int _process (jack_nframes_t nframes)
433 jack_default_audio_sample_t *in, *out;
434 in = (jack_default_audio_sample_t *)jack_port_get_buffer (input_port1, nframes);
435 out = (jack_default_audio_sample_t *)jack_port_get_buffer (output_port1, nframes);
436 memcpy (out, in, sizeof (jack_default_audio_sample_t) * nframes);
437 return 0;
440 static void* jack_thread(void *arg)
442 jack_client_t* client = (jack_client_t*) arg;
443 jack_nframes_t last_thread_time = jack_frame_time(client);
445 while (1) {
446 jack_nframes_t frames = jack_cycle_wait(client);
447 jack_nframes_t current_thread_time = jack_frame_time(client);
448 jack_nframes_t delta_time = current_thread_time - last_thread_time;
449 Log("jack_thread : delta_time = %ld\n", delta_time);
450 int status = _process(frames);
451 last_thread_time = current_thread_time;
452 jack_cycle_signal (client, status);
455 return 0;
458 // To test callback exiting
459 int process3(jack_nframes_t nframes, void *arg)
461 static int process3_call = 0;
463 if (process3_call++ > 10) {
464 Log("process3 callback : exiting...\n");
465 return -1;
466 } else {
467 Log("calling process3 callback : process3_call = %ld\n", process3_call);
468 return 0;
472 int process4(jack_nframes_t nframes, void *arg)
474 jack_client_t* client = (jack_client_t*) arg;
476 static jack_nframes_t last_time = jack_frame_time(client);
477 static jack_nframes_t tolerance = (jack_nframes_t)(cur_buffer_size * 0.1f);
479 jack_nframes_t cur_time = jack_frame_time(client);
480 jack_nframes_t delta_time = cur_time - last_time;
482 Log("calling process4 callback : jack_frame_time = %ld delta_time = %ld\n", cur_time, delta_time);
483 if (delta_time > 0 && abs((int64_t)delta_time - (int64_t)cur_buffer_size) > (int64_t)tolerance) {
484 printf("!!! ERROR !!! jack_frame_time seems to return incorrect values cur_buffer_size = %d, delta_time = %d tolerance %d\n", cur_buffer_size, delta_time, tolerance);
487 last_time = cur_time;
488 return 0;
491 int process5(jack_nframes_t nframes, void *arg)
493 jack_client_t* client = (jack_client_t*) arg;
495 static jack_nframes_t first_current_frames;
496 static jack_time_t first_current_usecs;
497 static jack_time_t first_next_usecs;
498 static float first_period_usecs;
499 static int res1 = jack_get_cycle_times(client, &first_current_frames, &first_current_usecs, &first_next_usecs, &first_period_usecs);
500 if(res1==0){}
502 jack_nframes_t current_frames;
503 jack_time_t current_usecs;
504 jack_time_t next_usecs;
505 float period_usecs;
507 int res = jack_get_cycle_times(client, &current_frames, &current_usecs, &next_usecs, &period_usecs);
508 if (res != 0) {
509 printf("!!! ERROR !!! jack_get_cycle_times fails...\n");
510 return 0;
513 Log("calling process5 callback : jack_get_cycle_times delta current_frames = %ld delta current_usecs = %ld delta next_usecs = %ld period_usecs = %f\n",
514 current_frames - first_current_frames, current_usecs - first_current_usecs, next_usecs - first_next_usecs, period_usecs);
516 first_current_frames = current_frames;
517 first_current_usecs = current_usecs;
518 first_next_usecs = next_usecs;
519 return 0;
522 static void display_transport_state()
524 jack_transport_state_t ts;
525 jack_position_t pos;
527 ts = jack_transport_query(client2, &pos);
528 switch (ts) {
529 case JackTransportStopped:
530 Log("Transport is stopped...\n");
531 break;
532 case JackTransportRolling:
533 Log("Transport is rolling...\n");
534 break;
535 case JackTransportLooping:
536 Log("Transport is looping...\n");
537 break;
538 case JackTransportStarting:
539 Log("Transport is starting...\n");
540 break;
541 case JackTransportNetStarting:
542 Log("Transport is starting with network sync...\n");
543 break;
548 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
549 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
550 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
551 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
552 MAIN FUNCTION
553 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
554 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
555 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
556 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
558 int main (int argc, char *argv[])
560 const char **inports; // array of PHY input/output
561 const char **outports; // array of PHY input/outputs
562 const char *server_name = NULL;
563 const char **connexions1;
564 const char **connexions2;
565 jack_status_t status;
566 char portname[128] = "port";
567 char filename[128] = "framefile.ext";
568 const char *nullportname = "";
569 int option_index;
570 int opt;
571 int a = 0; // working number for in/out port (PHY)...
572 int test_link = 0; // for testing the "overconnect" function
573 int flag; // flag for ports...
574 int is_mine = 0; // to test jack_port_is_mine function...
575 const char *options = "kRnqvt:";
576 float ratio; // for speed calculation in freewheel mode
577 jack_options_t jack_options = JackNullOption;
578 struct option long_options[] = {
579 {"realtime", 0, 0, 'R'},
580 {"non-realtime", 0, 0, 'n'},
581 {"time", 0, 0, 't'},
582 {"quiet", 0, 0, 'q'},
583 {"verbose", 0, 0, 'v'},
584 {"transport", 0, 0, 'k'},
585 {0, 0, 0, 0}
588 client_name1 = "jack_test";
589 time_to_run = 1;
590 //verbose_mode = 1;
591 //RT = 1;
592 while ((opt = getopt_long (argc, argv, options, long_options, &option_index)) != EOF) {
593 switch (opt) {
594 case 'k':
595 transport_mode = 0;
596 break;
597 case 'q':
598 silent_error = 1;
599 break;
600 case 'v':
601 verbose_mode = 1;
602 printf("Verbose mode is activated...\n");
603 break;
604 case 't':
605 time_to_run = atoi(optarg);
606 break;
607 case 'R':
608 RT = 1;
609 break;
610 default:
611 fprintf (stderr, "unknown option %c\n", opt);
612 usage ();
616 if (RT) {
617 printf("Jack server is said being in realtime mode...\n");
618 } else {
619 printf("Jack server is said being in non-realtime mode...\n");
622 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
623 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
624 init signal data for test
625 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
626 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
628 framecollect = (FrameTimeCollector *) malloc(800 * sizeof(FrameTimeCollector));
630 signal1 = (jack_default_audio_sample_t *) malloc(48000 * sizeof(jack_default_audio_sample_t));
631 signal2 = (jack_default_audio_sample_t *) malloc(96000 * sizeof(jack_default_audio_sample_t));
632 signal1[0] = 0;
633 int p;
634 for (p = 1; p < 48000;p++) {
635 signal1[p] = (float)(sin((p * 2 * M_PI * 1000 ) / 48000));
637 for (p = 0; p < 95999;p++) {
638 signal2[p] = 0.0 ;
640 index1 = 0;
641 index2 = 0;
643 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
644 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
645 begin test
646 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
647 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
649 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
650 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
651 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-* Start jack server stress test *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
652 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
653 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
656 * Register a client...
659 Log("Register a client using jack_client_open()...\n");
660 client1 = jack_client_open(client_name1, jack_options, &status, server_name);
661 if (client1 == NULL) {
662 fprintf (stderr, "jack_client_open() failed, "
663 "status = 0x%2.0x\n", status);
664 if (status & JackServerFailed) {
665 fprintf(stderr, "Unable to connect to JACK server\n");
667 exit (1);
669 if (status & JackServerStarted) {
670 fprintf(stderr, "JACK server started\n");
674 * Internal client tests...
677 jack_intclient_t intclient;
679 Log("trying to load the \"inprocess\" server internal client \n");
681 intclient = jack_internal_client_load (client1, "inprocess",
682 (jack_options_t)(JackLoadName|JackLoadInit),
683 &status, "inprocess", "");
685 if (intclient == 0 || status & JackFailure) {
686 printf("!!! ERROR !!! cannot load internal client \"inprocess\" intclient 0x%llX status 0x%2.0x !\n", (unsigned long long)intclient, status);
687 } else {
689 Log("\"inprocess\" server internal client loaded\n");
691 char* internal_name = jack_get_internal_client_name(client1, intclient);
692 if (strcmp(internal_name, "inprocess") == 0) {
693 Log("jack_get_internal_client_name returns %s\n", internal_name);
694 } else {
695 printf("!!! ERROR !!! jack_get_internal_client_name returns incorrect name %s\n", internal_name);
698 jack_intclient_t intclient1 = jack_internal_client_handle(client1, "inprocess", &status);
699 if (intclient1 == intclient) {
700 Log("jack_internal_client_handle returns correct handle\n");
701 } else {
702 printf("!!! ERROR !!! jack_internal_client_handle returns incorrect handle 0x%llX\n", (unsigned long long)intclient1);
705 // Unload internal client
706 status = jack_internal_client_unload (client1, intclient);
707 if (status == 0) {
708 Log("jack_internal_client_unload done first time returns correct value\n");
709 } else {
710 printf("!!! ERROR !!! jack_internal_client_unload returns incorrect value 0x%2.0x\n", status);
713 // Unload internal client second time
714 status = jack_internal_client_unload (client1, intclient);
715 if (status & JackFailure && status & JackNoSuchClient) {
716 Log("jack_internal_client_unload done second time returns correct value\n");
717 } else {
718 printf("!!! ERROR !!! jack_internal_client_unload returns incorrect value 0x%2.0x\n", status);
723 * try to register another one with the same name...
726 #ifndef TEST_EXCLUDE_DEPRECATED
727 Log("trying to register a new jackd client with name %s using jack_client_new()...\n", client_name1);
728 client2 = jack_client_new(client_name1);
729 if (client2 == NULL) {
730 Log ("valid : a second client with the same name cannot be registered\n");
731 } else {
732 printf("!!! ERROR !!! Jackd server has accepted multiples client with the same name !\n");
733 jack_client_close(client2);
735 #endif
738 * try to register another one with the same name using jack_client_open ==> since JackUseExactName is not used, an new client should be opened...
741 Log("trying to register a new jackd client with name %s using jack_client_open()...\n", client_name1);
742 client2 = jack_client_open(client_name1, jack_options, &status, server_name);
743 if (client2 != NULL) {
744 Log ("valid : a second client with the same name can be registered (client automatic renaming)\n");
745 jack_client_close(client2);
746 } else {
747 printf("!!! ERROR !!! Jackd server automatic renaming feature does not work!\n");
751 * try to register a client with maximum possible client name size
754 char client_name3[jack_client_name_size()];
755 // "jack_client_name_size" - 1 effective characters
756 memset(client_name3, 'A', sizeof(client_name3));
757 // set last expected printable to '4'
758 client_name3[jack_client_name_size()-2] = '4';
759 // And last one is the terminating '0'
760 client_name3[jack_client_name_size()-1] = 0;
761 Log("trying to register a new jackd client with maximum possible client name size...\n", client_name3);
762 client2 = jack_client_open(client_name3, jack_options, &status, server_name);
763 if (client2 != NULL) {
764 Log ("valid : a client with maximum possible client name size can be opened\n");
765 jack_client_close(client2);
766 } else {
767 printf("!!! ERROR !!! opening a client with maximum possible client name size does not work!\n");
770 // test with one less:
771 // set last expected printable to '3'
772 client_name3[jack_client_name_size()-3] = '3';
773 // And (second) last one is the terminating '0'
774 client_name3[jack_client_name_size()-2] = 0;
775 Log("trying to register a new jackd client with maximum possible client name size -1...\n", client_name3);
776 client2 = jack_client_open(client_name3, jack_options, &status, server_name);
777 if (client2 != NULL) {
778 Log ("valid : a client with maximum possible client name size -1 can be opened\n");
779 Log("Testing long name...");
780 client_name2 = jack_get_client_name(client2);
781 if (strcmp(client_name2, client_name3) == 0) {
782 Log(" ok\n");
783 } else {
784 printf("\n!!! ERROR !!! name returned different from the one given : %s\n", client_name2);
786 jack_client_close(client2);
787 } else {
788 printf("!!! ERROR !!! opening a client with maximum possible client name size -1 does not work!\n");
792 * testing client name...
793 * Verify that the name sended at registration and the one returned by jack server is the same...
796 Log("Testing name...");
797 client_name2 = jack_get_client_name(client1);
798 if (strcmp(client_name1, client_name2) == 0) {
799 Log(" ok\n");
800 } else {
801 printf("\n!!! ERROR !!! name returned different from the one given : %s\n", client_name2);
805 * Test RT mode...
806 * verify if the real time mode returned by jack match the optional argument defined when launching jack_test*/
807 if (jack_is_realtime(client1) == RT) {
808 Log("Jackd is in realtime mode (RT = %i).\n", RT);
809 } else {
810 printf("!!! ERROR !!! Jackd is in a non-expected realtime mode (RT = %i).\n", RT);
814 * Register all callbacks...
817 if (jack_set_thread_init_callback(client1, Jack_Thread_Init_Callback, 0) != 0) {
818 printf("!!! ERROR !!! while calling jack_set_thread_init_callback()...\n");
820 if (jack_set_freewheel_callback(client1, Jack_Freewheel_Callback, 0) != 0 ) {
821 printf("\n!!! ERROR !!! while calling jack_set_freewheel_callback()...\n");
825 if (jack_set_process_callback(client1, process1, 0) != 0) {
826 printf("Error when calling jack_set_process_callback() !\n");
829 jack_on_shutdown(client1, jack_shutdown, 0);
831 if (jack_on_info_shutdown) {
832 jack_on_info_shutdown(client1, jack_info_shutdown, 0);
835 if (jack_set_buffer_size_callback(client1, Jack_Update_Buffer_Size, 0) != 0) {
836 printf("Error when calling buffer_size_callback !\n");
839 if (jack_set_graph_order_callback(client1, Jack_Graph_Order_Callback, 0) != 0) {
840 printf("Error when calling Jack_Graph_Order_Callback() !\n");
843 if (jack_set_port_rename_callback(client1, Jack_Port_Rename_Callback, 0) != 0 )
844 printf("\n!!! ERROR !!! while calling jack_set_rename_callback()...\n");
846 if (jack_set_xrun_callback(client1, Jack_XRun_Callback, 0 ) != 0) {
847 printf("Error when calling jack_set_xrun_callback() !\n");
850 if (jack_set_sample_rate_callback(client1, Jack_Sample_Rate_Callback, 0 ) != 0) {
851 printf("Error when calling Jack_Sample_Rate_Callback() !\n");
854 if (jack_set_port_registration_callback(client1, Jack_Port_Register, 0) != 0) {
855 printf("Error when calling jack_set_port_registration_callback() !\n");
858 if (jack_set_port_connect_callback(client1, Jack_Port_Connect, 0) != 0) {
859 printf("Error when calling jack_set_port_connect_callback() !\n");
862 if (jack_set_client_registration_callback(client1, Jack_Client_Registration_Callback, 0) != 0) {
863 printf("Error when calling jack_set_client_registration_callback() !\n");
866 jack_set_error_function(Jack_Error_Callback);
869 * Create file for clock "frame time" analysis
872 cur_buffer_size = jack_get_buffer_size(client1);
873 sprintf (filename, "framefile-%i.dat", cur_buffer_size);
874 file = fopen(filename, "w");
875 if (file == NULL) {
876 fprintf(stderr, "Error when opening framefile.dat log file");
877 exit(-1);
881 * Try to register a client with a NULL name/zero length name...
884 output_port1 = jack_port_register(client1, nullportname,
885 JACK_DEFAULT_AUDIO_TYPE,
886 JackPortIsOutput, 0);
887 if (output_port1 == NULL) {
888 Log("Can't register a port with a NULL portname... ok.\n");
889 } else {
890 printf("!!! ERROR !!! Can register a port with a NULL portname !\n");
891 jack_port_unregister(client1, output_port1);
895 * Register 1 port in order to stress other functions.
898 output_port1 = jack_port_register(client1, portname,
899 JACK_DEFAULT_AUDIO_TYPE,
900 JackPortIsOutput, 0);
901 if (output_port1 == NULL) {
902 printf("!!! ERROR !!! Can't register any port for the client !\n");
903 exit(1);
907 * Test port type of the just registered port.
910 if (strcmp(jack_port_type(output_port1), JACK_DEFAULT_AUDIO_TYPE) != 0) {
911 printf("!!! ERROR !!! jack_port_type returns an incorrect value!\n");
912 } else {
913 Log("Checking jack_port_type()... ok.\n");
917 * Try to register another port with the same name...
920 output_port2 = jack_port_register(client1, portname,
921 JACK_DEFAULT_AUDIO_TYPE,
922 JackPortIsOutput, 0);
923 if (output_port2 == NULL) {
924 Log("Can't register two ports with the same name... ok\n");
925 } else {
926 if (strcmp (jack_port_name(output_port1), jack_port_name(output_port2)) == 0) {
927 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));
928 jack_port_unregister(client1, output_port2);
929 } else {
930 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));
931 jack_port_unregister(client1, output_port2);
936 * Verify that both port_name and port_short_name return correct results...
939 sprintf (portname, "%s:%s", jack_get_client_name(client1), jack_port_short_name(output_port1));
940 if (strcmp(jack_port_name(output_port1), portname) != 0) {
941 printf("!!! ERROR !!! functions jack_port_name and/or jack_short_port_name seems to be invalid !\n");
942 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));
946 * Verify the function port_set_name
949 #ifndef TEST_EXCLUDE_DEPRECATED
950 if (jack_port_set_name (output_port1, "renamed-port#") == 0 ) {
951 if (strcmp(jack_port_name(output_port1), "renamed-port#") == 0) {
952 printf("!!! ERROR !!! functions jack_port_set_name seems to be invalid !\n");
953 printf("jack_port_name return '%s' whereas 'renamed-port#' was expected...\n", jack_port_name(output_port1));
954 } else {
955 Log("Checking jack_port_set_name()... ok\n");
956 jack_port_set_name (output_port1, "port");
958 } else {
959 printf("error : port_set_name function can't be tested...\n");
961 #endif
963 * Verify if a port can be registered with maximum port name size (that is "short name")
966 int short_port_size_max = jack_port_name_size() - jack_client_name_size() - 1; // Port is of shape: "client_name:port_name"
967 char port_name3[short_port_size_max];
968 // "short_port_size_max" - 1 effective characters
969 for (int i = 0; i < short_port_size_max - 1; i++) {
970 port_name3[i] = 'A';
972 // And last one is the terminating '0'
973 port_name3[short_port_size_max-1] = 0;
974 jack_port_t * test_max_port = jack_port_register(client1, port_name3,
975 JACK_DEFAULT_AUDIO_TYPE,
976 JackPortIsOutput, 0);
978 if (test_max_port != NULL) {
979 Log ("valid : a port with maximum possible port name size can be registered\n");
980 jack_port_unregister(client1, test_max_port);
981 } else {
982 printf("!!! ERROR !!! registering a port with maximum possible port name size does not work!\n");
985 port_callback_reg = 0; // number of port registration received by the callback
988 * Activate the client
991 if (jack_activate(client1) < 0) {
992 printf ("Fatal error : cannot activate client1\n");
993 exit(1);
997 * Test if port rename callback have been called.
1000 #ifndef TEST_EXCLUDE_DEPRECATED
1001 jack_port_set_name (output_port1, "renamed-port#");
1002 jack_sleep(1 * 1000);
1004 if (port_rename_clbk == 0) {
1005 printf("!!! ERROR !!! Jack_Port_Rename_Callback was not called !!.\n");
1007 #endif
1010 * Test if port registration callback have been called.
1014 jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
1016 if (1 == port_callback_reg) {
1017 Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", 1, port_callback_reg);
1018 } else {
1019 printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", 1, port_callback_reg);
1023 * Test if init callback initThread have been called.
1026 if (init_clbk == 0) {
1027 printf("!!! ERROR !!! Jack_Thread_Init_Callback was not called !!.\n");
1030 jack_sleep(10 * 1000); // test see the clock in the graph at the begining...
1033 * Stress Freewheel mode...
1034 * Try to enter freewheel mode. Check the realtime mode de-activation.
1035 * Check that the number of call of the process callback is greater than in non-freewheel mode.
1036 * Give an approximated speed ratio (number of process call) between the two modes.
1037 * Then return in normal mode.
1039 t_error = 0;
1040 activated = 0;
1041 jack_sleep(1 * 1000);
1042 count1 = activated;
1043 Log("Testing activation freewheel mode...\n");
1044 linefw = linecount; // count for better graph reading with gnuplot
1045 jack_set_freewheel(client1, 1);
1046 activated = 0;
1047 jack_sleep(1 * 1000);
1048 count2 = activated;
1049 if (jack_is_realtime(client1) == 0) {
1050 t_error = 0;
1051 } else {
1052 printf("\n!!! ERROR !!! RT mode is always activated while freewheel mode is applied !\n");
1053 t_error = 1;
1055 if (activated == 0) {
1056 printf("!!! ERROR !!! Freewheel mode doesn't activate audio callback !!\n");
1059 jack_set_freewheel(client1, 0);
1060 jack_sleep(7 * 1000);
1062 if (jack_is_realtime(client1) == 1) {
1063 } else {
1064 printf("\n!!! ERROR !!! freewheel mode fail to reactivate RT mode when exiting !\n");
1065 t_error = 1;
1067 if (t_error == 0) {
1068 Log("Freewheel mode appears to work well...\n");
1070 if (count1 == 0) {
1071 Log("Audio Callback in 'standard' (non-freewheel) mode seems not to be called...\n");
1072 Log("Ratio speed would be unavailable...\n");
1073 } else {
1074 ratio = (float) ((count2 - count1) / count1);
1075 Log("Approximative speed ratio of freewheel mode = %f : 1.00\n", ratio);
1079 * Stress buffer function...
1080 * get current buffer size.
1081 * Try to apply a new buffer size value ( 2 x the precedent buffer size value)
1082 * Then return in previous buffer size mode.
1086 float factor = 0.5f;
1087 old_buffer_size = jack_get_buffer_size(client1);
1088 Log("Testing BufferSize change & Callback...\n--> Current buffer size : %d.\n", old_buffer_size);
1089 linebuf = linecount;
1090 if (jack_set_buffer_size(client1, (jack_nframes_t)(old_buffer_size * factor)) < 0) {
1091 printf("!!! ERROR !!! jack_set_buffer_size fails !\n");
1093 jack_sleep(1 * 1000);
1094 cur_buffer_size = jack_get_buffer_size(client1);
1095 if (abs((old_buffer_size * factor) - cur_buffer_size) > 5) { // Tolerance needed for dummy driver...
1096 printf("!!! ERROR !!! Buffer size has not been changed !\n");
1097 printf("!!! Maybe jack was compiled without the '--enable-resize' flag...\n");
1098 } else {
1099 Log("jack_set_buffer_size() command successfully applied...\n");
1101 jack_sleep(3 * 1000);
1102 jack_set_buffer_size(client1, old_buffer_size);
1103 cur_buffer_size = jack_get_buffer_size(client1);
1106 * Test the last regestered port to see if port_is_mine function the right value.
1107 * A second test will be performed later.
1108 * The result will be printed at the end.
1111 if (jack_port_is_mine(client1, output_port1)) {
1112 is_mine = 1;
1113 } else {
1114 is_mine = 0;
1118 * Check that the ID returned by the port_by_name is right.
1119 * (it seems there is a problem here in some jack versions).
1122 if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
1123 printf("!!! ERROR !!! function jack_port_by_name() return bad value !\n");
1124 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);
1125 } else {
1126 Log("Checking jack_port_by_name() return value... ok\n");
1128 if (NULL != jack_port_by_name(client1, jack_port_short_name(output_port1))) {
1129 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)));
1130 } else {
1131 Log("Checking jack_port_by_name() with bad argument... ok (returned id 0)\n");
1135 * remove the output port previously created
1136 * no more ports should subsist here for our client.
1139 if (jack_port_unregister(client1, output_port1) != 0) {
1140 printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
1144 * list all in ports
1147 inports = jack_get_ports(client1, NULL, NULL, 0);
1150 * Test the first PHY (physical) connection to see if it's "mine".
1151 * and report the result in the test that began before.
1152 * The result is printed later.
1155 if (jack_port_is_mine(client1, jack_port_by_name(client1, inports[0]))) {
1156 is_mine = 0;
1160 * List all devices' flags and print them...
1163 Log("\nTry functions jack_get_ports, jack_port_flag & jack_port_by_name to list PHY devices...\n");
1164 Log("-----------------------------------------------------------\n");
1165 Log("---------------------------DEVICES-------------------------\n");
1166 Log("-----------------------------------------------------------\n");
1167 a = 0;
1168 while (inports[a] != NULL) {
1169 flag = jack_port_flags(jack_port_by_name(client1, inports[a]) );
1170 Log(" * %s (id : %i)\n", inports[a], jack_port_by_name(client1, inports[a]));
1171 Log(" (");
1172 if (flag & JackPortIsInput)
1173 Log("JackPortIsInput ");
1174 if (flag & JackPortIsOutput)
1175 Log("JackPortIsOutput ");
1176 if (flag & JackPortIsPhysical)
1177 Log("JackPortIsPhysical ");
1178 if (flag & JackPortCanMonitor)
1179 Log("JackPortCanMonitor ");
1180 if (flag & JackPortIsTerminal)
1181 Log("JackPortIsTerminal ");
1182 Log(")\n\n");
1183 a++;
1185 Log("-----------------------------------------------------------\n\n");
1188 * list all PHY in/out ports...
1189 * This list will be used later many times.
1192 outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
1193 inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
1195 if (outports == NULL) {
1196 printf("!!! WARNING !!! no physical capture ports founded !\n");
1198 if (inports == NULL) {
1199 printf("!!! WARNING !!! no physical output ports founded !\n");
1203 * Brute test : try to create as many ports as possible.
1204 * It stops when jack returns an error.
1205 * Then try to connect each port to physical entry...
1206 * Check also that graph reorder callback is called.
1209 Log("Registering as many ports as possible and connect them to physical entries...\n");
1210 lineports = linecount;
1211 t_error = 0;
1213 i = 0; // number of couple 'input-ouput'
1214 j = 0; // number of ports created
1215 port_callback_reg = 0; // number of port registration received by the callback
1216 reorder = 0; // number of graph reorder callback activation
1217 test_link = 0 ; // Test the "overconnect" function only one time
1218 while (t_error == 0) {
1219 sprintf (portname, "input_%d", i);
1220 input_port1 = jack_port_register(client1, portname,
1221 JACK_DEFAULT_AUDIO_TYPE,
1222 JackPortIsInput, 0);
1223 j++;
1224 if (input_port1 == NULL) {
1225 j--;
1226 t_error = 1;
1227 } else {
1228 // Connect created input to PHY output
1229 a = 0;
1230 while (outports && outports[a] != NULL) {
1231 if (jack_connect(client1, outports[a], jack_port_name(input_port1))) {
1232 printf ("error : cannot connect input PHY port to client port %s\n", jack_port_name(input_port1));
1233 } else {
1234 // printf ("input PHY port %s connected to client port %s\n", outports[a], jack_port_name(input_port1));
1236 a++;
1238 // Try one time to "overconnect" 2 ports (the latest created)...
1239 if (test_link == 0 && outports && ((a - 1) > 0) && outports[a - 1]) {
1240 if (jack_connect(client1, outports[a - 1], jack_port_name(input_port1)) == EEXIST) {
1241 // cannot over-connect input PHY port to client port. ok.
1242 test_link = 1;
1247 sprintf(portname, "output_%d", i);
1248 output_port1 = jack_port_register(client1, portname,
1249 JACK_DEFAULT_AUDIO_TYPE,
1250 JackPortIsOutput, 0);
1251 j++;
1252 if (output_port1 == NULL) {
1253 t_error = 1;
1254 j--;
1255 } else {
1256 // Connect created input to PHY output
1257 a = 0;
1258 while (inports && inports[a] != NULL) {
1259 if (jack_connect(client1, jack_port_name(output_port1), inports[a])) {
1260 printf ("error : cannot connect input PHY port %s to client port %s\n", inports[a], jack_port_name(output_port1));
1261 } else {
1262 // output PHY port %s connected to client port. ok.
1264 a++;
1266 // Try one time to "overconnect" 2 ports (the latest created)...
1267 if (test_link == 0 && inports && ((a - 1) > 0) && inports[a - 1]) {
1268 if (jack_connect(client1, jack_port_name(output_port1), inports[a - 1]) == EEXIST) {
1269 // cannot over-connect output PHY port to client port. ok.
1270 test_link = 1;
1274 i++;
1277 jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
1279 // Check port registration callback
1280 if (j == port_callback_reg) {
1281 Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j, port_callback_reg);
1282 } else {
1283 printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j, port_callback_reg);
1286 if (reorder == (2 * j)) {
1287 Log("%i graph reorder callback have been received... ok\n", reorder);
1288 } else {
1289 printf("!!! ERROR !!! %i graph reorder callback have been received (maybe non-valid value)...\n", reorder);
1292 * print basic test connection functions result ...
1293 * over-connected means here that we try to connect 2 ports that are already connected.
1296 if (test_link) {
1297 Log("Jack links can't be 'over-connected'... ok\n");
1298 } else {
1299 printf("!!! ERROR !!! Jack links can be 'over-connected'...\n");
1302 * Print the result of the two jack_is_mine test.
1305 if (is_mine == 1) {
1306 Log("Checking jack_port_is_mine()... ok\n");
1307 } else {
1308 printf("!!! ERROR !!! jack_port_is_mine() function seems to send non-valid datas !\n");
1311 * Free the array of the physical input and ouput ports.
1312 * (as mentionned in the doc of jack_get_ports)
1315 jack_free(inports);
1316 jack_free(outports);
1319 * Try to "reactivate" the client whereas it's already activated...
1322 if (jack_activate(client1) < 0) {
1323 printf("!!! ERROR !!! Cannot activate client1 a second time...\n");
1324 exit(1);
1325 } else {
1326 Log("jackd server accept client.jack_activate() re-activation (while client was already activated).\n");
1330 * Deregister all ports previously created.
1333 port_callback_reg = 0; // to check registration callback
1334 Log("Deregistering all ports of the client...\n");
1335 inports = jack_get_ports(client1, NULL, NULL, 0);
1336 a = 0;
1337 while (inports[a] != NULL) {
1338 flag = jack_port_flags(jack_port_by_name(client1, inports[a]));
1339 input_port1 = jack_port_by_name(client1, inports[a]);
1340 if (jack_port_is_mine(client1, input_port1)) {
1341 if (jack_port_unregister(client1, input_port1) != 0) {
1342 printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
1345 a++;
1348 jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
1350 // Check port registration callback again
1351 if (j == port_callback_reg) {
1352 Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j, port_callback_reg);
1353 } else {
1354 printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j, port_callback_reg);
1357 jack_free(inports); // free array of ports (as mentionned in the doc of jack_get_ports)
1360 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1361 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1362 Open a new client (second one) to test some other things...
1363 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1364 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1367 Log("\n\n----------------------------------------------------------------------\n");
1368 Log("Starting second new client 'jack_test_#2'...\n");
1369 /* open a client connection to the JACK server */
1370 client_name2 = "jack_test_#2";
1371 linecl2 = linecount; // reminders for graph analysis
1372 // client2 = jack_client_new(client_name2);
1373 Log("Register a client using jack_client_open()...\n");
1374 client2 = jack_client_open(client_name2, jack_options, &status, server_name);
1375 if (client2 == NULL) {
1376 fprintf (stderr, "jack_client_open() failed, "
1377 "status = 0x%2.0x\n", status);
1378 if (status & JackServerFailed) {
1379 fprintf(stderr, "Unable to connect to JACK server\n");
1381 exit (1);
1384 // Check client registration callback after jack_client_new
1385 jack_sleep(2000);
1386 if (client_register == 0) {
1387 printf("!!! ERROR !!! Client registration callback not called for an opened client !\n");
1390 // Check client registration callback after jack_client_close
1391 jack_client_close(client2);
1392 jack_sleep(2000);
1393 if (client_register == 1) {
1394 printf("!!! ERROR !!! Client registration callback not called for a closed client!\n");
1397 // Open client2 again...
1398 // client2 = jack_client_new(client_name2);
1399 Log("Register a client using jack_client_open() AGAIN...\n");
1400 client2 = jack_client_open(client_name2, jack_options, &status, server_name);
1401 if (client2 == NULL) {
1402 fprintf (stderr, "jack_client_open() failed, "
1403 "status = 0x%2.0x\n", status);
1404 if (status & JackServerFailed) {
1405 fprintf(stderr, "Unable to connect to JACK server\n");
1407 exit (1);
1411 * Register callback for this client.
1412 * Callbacks are the same as the first client for most of them, excepted for process audio callback.
1415 jack_set_port_registration_callback(client2, Jack_Port_Register, 0);
1417 jack_set_process_callback(client2, process2, 0);
1419 jack_on_shutdown(client2, jack_shutdown, 0);
1422 * Register one input and one output for each client.
1425 Log("registering 1 input/output ports for each client...\n");
1427 output_port1 = jack_port_register(client1, "out1",
1428 JACK_DEFAULT_AUDIO_TYPE,
1429 JackPortIsOutput, 0);
1430 output_port2 = jack_port_register(client2, "out2",
1431 JACK_DEFAULT_AUDIO_TYPE,
1432 JackPortIsOutput, 0);
1433 input_port1 = jack_port_register(client1, "in1",
1434 JACK_DEFAULT_AUDIO_TYPE,
1435 JackPortIsInput, 0);
1436 input_port2 = jack_port_register(client2, "in2",
1437 JACK_DEFAULT_AUDIO_TYPE,
1438 JackPortIsInput, 0);
1439 if ((output_port1 == NULL) || (output_port2 == NULL) || (input_port1 == NULL) || (input_port2 == NULL)) {
1440 printf("!!! ERROR !!! Unable to register ports...\n");
1444 * Set each process mode to idle and activate client2
1447 process2_activated = -1;
1448 process1_activated = -1;
1449 if (jack_activate(client2) < 0) {
1450 printf("Fatal error : cannot activate client2\n");
1451 exit(1);
1455 * Connect the two clients and check that all connections are well-done.
1458 Log("Testing connections functions between clients...\n");
1459 if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
1460 printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
1462 if (jack_connect(client2, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
1463 printf("!!! ERROR !!! while client2 intenting to connect ports...\n");
1465 if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
1466 printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
1470 * Test the port_connected function...
1473 if ((jack_port_connected(output_port1) == jack_port_connected(input_port1)) &&
1474 (jack_port_connected(output_port2) == jack_port_connected(input_port2)) &&
1475 (jack_port_connected(output_port2) == 1) &&
1476 (jack_port_connected(output_port1) == 2)
1478 Log("Checking jack_port_connected()... ok.\n");
1479 } else {
1480 printf("!!! ERROR !!! function jack_port_connected() return a bad value !\n");
1481 printf("jack_port_connected(output_port1) %d\n", jack_port_connected(output_port1));
1482 printf("jack_port_connected(output_port2) %d\n", jack_port_connected(output_port2));
1483 printf("jack_port_connected(input_port1) %d\n", jack_port_connected(input_port1));
1484 printf("jack_port_connected(input_port2) %d\n", jack_port_connected(input_port2));
1488 * Test a new time the port_by_name function...(now we are in multi-client mode)
1491 Log("Testing again jack_port_by_name...\n");
1492 if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
1493 printf("!!! ERROR !!! function jack_port_by_name() return bad value in a multi-client application!\n");
1494 printf("!!! jack_port_by_name(jack_port_name(_ID_) ) != _ID_ in multiclient application.\n");
1495 } else {
1496 Log("Checking jack_port_by_name() function with a multi-client application... ok\n");
1500 * Test the port_connected_to function...
1503 if ((jack_port_connected_to (output_port1, jack_port_name(input_port2))) &&
1504 (!(jack_port_connected_to (output_port2, jack_port_name(input_port2))))) {
1505 Log("checking jack_port_connected_to()... ok\n");
1506 } else {
1507 printf("!!! ERROR !!! jack_port_connected_to() return bad value !\n");
1511 * Test the port_get_connections & port_get_all_connections functions...
1514 Log("Testing jack_port_get_connections and jack_port_get_all_connections...\n");
1515 a = 0;
1516 t_error = 0;
1517 connexions1 = jack_port_get_connections (output_port1);
1518 connexions2 = jack_port_get_all_connections(client1, output_port1);
1519 if ((connexions1 == NULL) || (connexions2 == NULL)) {
1520 printf("!!! ERROR !!! port_get_connexions or port_get_all_connexions return a NULL pointer !\n");
1521 } else {
1522 while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
1523 t_error = strcmp(connexions1[a], connexions2[a]);
1524 a++;
1527 if (t_error == 0) {
1528 Log("Checking jack_port_get_connections Vs jack_port_get_all_connections... ok\n");
1529 } else {
1530 printf("!!! ERROR !!! while checking jack_port_get_connections Vs jack_port_get_all_connections...\n");
1533 a = 0;
1534 t_error = 0;
1535 inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
1536 connexions1 = NULL;
1537 if (inports && inports[0] != NULL) {
1538 connexions1 = jack_port_get_connections (jack_port_by_name(client1, inports[0]));
1539 connexions2 = jack_port_get_all_connections(client1, jack_port_by_name(client1, inports[0]));
1542 jack_free (inports);
1543 if (connexions1 == NULL) {
1544 Log("checking jack_port_get_connections() for external client... ok\n");
1545 } else {
1546 while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
1547 t_error = strcmp(connexions1[a], connexions2[a]);
1548 a++;
1551 if (t_error == 0) {
1552 Log("Checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port... ok\n");
1553 } else {
1554 printf("!!! ERROR !!! while checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port...\n");
1557 if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
1558 printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
1560 if (jack_disconnect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
1561 printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
1563 // No links should subsist now...
1566 * Checking data connexion
1567 * establishing a link between client1.out1 --> client2.in2
1568 * Send the signal1 test on out1. Record the result into signal2. (see process functions).
1569 ---------------------------------------------------------------------------*/
1570 Log("Testing connections datas between clients...\n");
1571 jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2) );
1572 process2_activated = -1;
1573 process1_activated = -1;
1574 Log("process 2 : idle mode...\n");
1575 Log("Sending datas...");
1576 index1 = 0;
1577 index2 = 0;
1578 process1_activated = 1; // We start emitting first.
1579 process2_activated = 1; // So record begin at least when we just begin to emitt the signal, else at next call of process with
1580 // nframe = jack buffersize shifting.
1582 while (process2_activated == 1) {
1583 jack_sleep(1 * 1000);
1584 Log(".");
1586 index2 = 0;
1587 Log("\nAnalysing datas...\n"); // search the first occurence of the first element of the reference signal in the recorded signal
1588 while (signal2[index2] != signal1[1] ) {
1589 index2++;
1590 if (index2 == 95999) {
1591 printf("!!! ERROR !!! Data not found in first connexion data check!\n");
1592 break;
1595 index1 = index2;
1596 Log("Data founded at offset %i.\n", index2);
1597 // And now we founded were the recorded data are, we can see if the two signals matches...
1598 while ( (signal2[index2] == signal1[index2 - index1 + 1]) || (index2 == 95999) || ((index2 - index1 + 1) == 47999) ) {
1599 index2++;
1601 Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
1602 if ((index2 - index1) == 48000) {
1603 Log("Data received are valid...\n");
1604 } else {
1605 printf("!!! ERROR !!! data transmission seems not to be valid in first connexion data check!\n");
1607 if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port2) ) != 0)
1608 // no more connection between ports exist now...
1610 printf("Error while establishing new connexion (disconnect).\n");
1614 * Test TIE MODE
1615 * (This mode seems to be problematic in standard jack version 0.100. It seems that nobody
1616 * is used to apply this mode because the tie mode doesn't work at all. A patch seems difficult to produce
1617 * in this version of jack. Tie mode work well in MP version.)
1618 * Test some basic thinks (tie with 2 different client, tie non-owned ports...)
1619 * Tie client1.in1 and client1.out1 ports, and make some data test to check the validity of the tie.
1622 #ifndef TEST_EXCLUDE_DEPRECATED
1623 Log("Testing tie mode...\n");
1624 if (jack_port_tie(input_port1, output_port2) != 0) {
1625 Log("not possible to tie two ports from two different clients... ok\n");
1626 } else {
1627 printf("!!! ERROR !!! port_tie has allowed a connexion between two different clients !\n");
1628 jack_port_untie(output_port2);
1630 Log("Testing connections datas in tie mode...\n");
1631 int g;
1632 for (g = 0; g < 96000; g++)
1633 signal2[g] = 0.0;
1634 // Create a loop (emit test) client2.out2----client.in1--tie--client1.out1-----client2.in1 (receive test)
1635 if (jack_port_tie(input_port1, output_port1) != 0) {
1636 printf("Unable to tie... fatal error : data test will not be performed on tie mode !!\n");
1637 } else { // begin of tie
1638 if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
1639 printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
1641 if (jack_connect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
1642 printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
1645 process1_activated = -1;
1646 process2_activated = -1;
1648 // We can manualy check here that the tie is effective.
1649 // ie : playing a wav with a client, connecting ports manualy with qjackctl, and listen...
1650 // printf("manual test\n");
1651 // jack_sleep(50);
1652 // printf("end of manual test\n");
1654 index1 = 0;
1655 index2 = 0;
1656 process1_activated = -1;
1657 process2_activated = 2;
1659 Log("Sending datas...");
1661 while (process2_activated == 2) {
1662 jack_sleep(1 * 1000);
1663 Log(".");
1665 process1_activated = -1;
1666 process2_activated = -1;
1667 index2 = 0;
1668 Log("\nAnalysing datas...\n");
1669 // We must find at least 2 identical values to ensure we are at the right place in the siusoidal array...
1670 while (!((signal2[index2] == signal1[1]) && (signal2[index2 + 1] == signal1[2]))) {
1671 index2++;
1672 if (index2 == 95999) {
1673 printf("!!! ERROR !!! Data not found in connexion check of tie mode!\n");
1674 break;
1677 index1 = index2;
1678 Log("Tie mode : Data founded at offset %i.\n", index2);
1679 while (signal2[index2] == signal1[index2 - index1 + 1]) {
1680 index2++;
1681 if ((index2 == 95999) || ((index2 - index1 + 1) == 47999)) {
1682 break;
1685 Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
1686 if ((index2 - index1) > 47995) {
1687 Log("Data received in tie mode are valid...\n");
1688 } else {
1689 // in tie mode, the buffers adress should be the same for the two tied ports.
1690 printf("!!! ERROR !!! data transmission seems not to be valid !\n");
1691 printf("Links topology : (emitt) client2.out2 ----> client1.in1--(tie)--client1.out1----->client2.in2 (recive)\n");
1692 printf(" port_name : Port_adress \n");
1693 printf(" output_port1 : %px\n", jack_port_get_buffer(output_port1, cur_buffer_size));
1694 printf(" input_port2 : %px\n", jack_port_get_buffer(input_port2, cur_buffer_size));
1695 printf(" output_port2 : %px\n", jack_port_get_buffer(output_port2, cur_buffer_size));
1696 printf(" input_port1 : %px\n", jack_port_get_buffer(input_port1, cur_buffer_size));
1699 jack_port_untie(output_port1);
1700 jack_port_disconnect(client1, output_port2);
1701 jack_port_disconnect(client1, output_port1);
1703 } //end of tie
1704 #endif
1707 * Testing SUMMATION CAPABILITIES OF JACK CONNECTIONS
1709 * In a short test, we just check a simple summation in jack.
1710 * A first client(client1) send two signal in phase opposition
1711 * A second client(client2) record the summation at one of his port
1712 * So, the result must be zero...
1713 * See process1 for details about steps of this test
1716 // fprintf(file, "Sum test\n");
1717 Log("Checking summation capabilities of patching...\n");
1718 output_port1b = jack_port_register(client1, "out1b",
1719 JACK_DEFAULT_AUDIO_TYPE,
1720 JackPortIsOutput, 0);
1721 jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2));
1722 jack_connect(client2, jack_port_name(output_port1b), jack_port_name(input_port2));
1724 process1_activated = 3;
1725 process2_activated = -1;
1726 int h;
1727 for (h = 0; h < 96000; h++)
1728 signal2[h] = 0.0;
1729 index1 = 0;
1730 index2 = 0;
1732 Log("Sending datas...");
1733 process2_activated = 3;
1735 while (process2_activated == 3) {
1736 jack_sleep(1 * 1000);
1737 Log(".");
1739 process1_activated = -1;
1740 process2_activated = -1;
1741 index2 = 0;
1742 Log("\nAnalysing datas...\n"); // same idea as above, with first data check...
1743 while (!((signal2[index2] == 0.0 ) && (signal2[(index2 + 1)] == 0.0 ))) {
1744 index2++;
1745 if (index2 == 95999) {
1746 printf("!!! ERROR !!! Data not found in summation check!\n");
1747 break;
1750 index1 = index2;
1751 Log("Data founded at offset %i.\n", index2);
1753 while ( signal2[index2] == 0.0 ) {
1754 index2++;
1755 if ((index2 > 95998) || ((index2 - index1 + 1) > 47998)) {
1756 break;
1759 Log("Checking difference between datas...\n");
1760 if ((index2 - index1) > 47996) {
1761 Log("Data mixed received are valid...\nSummation is well done.\n");
1762 } else {
1763 printf("!!! ERROR !!! data transmission / summation seems not to be valid !\n");
1765 jack_port_disconnect(client1, output_port1);
1766 jack_port_disconnect(client1, output_port1b);
1767 jack_port_unregister(client1, output_port1b);
1769 if (jack_port_name(output_port1b) != NULL ) {
1770 printf("!!! WARNING !!! port_name return something while the port have been unregistered !\n");
1771 printf("!!! Name of unregistered port : %s !\n", jack_port_name(output_port1b));
1772 } else {
1773 Log("Checking jack_port_name() with a non valid port... ok\n");
1776 #ifndef TEST_EXCLUDE_DEPRECATED
1777 if (jack_port_set_name(output_port1b, "new_name") == 0 ) {
1778 printf("!!! WARNING !!! An unregistered port can be renamed successfully !\n");
1779 } else {
1780 Log("Checking renaming of an unregistered port... ok\n");
1782 #endif
1783 inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
1784 #ifndef TEST_EXCLUDE_DEPRECATED
1785 if (inports && jack_port_set_name(jack_port_by_name(client1, inports[0]), "new_name") == 0 ) {
1786 printf("!!! WARNING !!! A PHYSICAL port can be renamed successfully !\n");
1787 } else {
1788 Log("Checking renaming of an unregistered port... ok\n");
1790 #endif
1791 jack_free (inports);
1795 * Checking latency issues
1796 * here are simple latency check
1797 * We simply check that the value returned by jack seems ok
1798 * Latency compensation is a difficult point.
1799 * Actually, jack is not able to see "thru" client to build a full latency chain.
1800 * Ardour use theses informations to do internally his compensations.
1802 * 3 test are done : one with no connections between client, one with a serial connection, and one with parallel connection
1805 #ifndef TEST_EXCLUDE_DEPRECATED
1806 Log("Checking about latency functions...\n");
1807 t_error = 0;
1808 jack_recompute_total_latencies(client1);
1809 Log("jack_recompute_total_latencies...\n");
1810 if ((jack_port_get_latency (output_port1) != 0) ||
1811 (jack_port_get_total_latency(client1, output_port1) != 0) ) {
1812 t_error = 1;
1813 printf("!!! ERROR !!! default latency of a non-PHY device is not set to zero !\n");
1816 inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
1817 outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
1818 if (inports && outports && inports[0] != NULL && outports[0] != NULL) {
1819 output_ext_latency = jack_port_get_latency (jack_port_by_name(client1, inports[0])); // from client to out driver (which has "inputs" ports..)
1820 input_ext_latency = jack_port_get_latency (jack_port_by_name(client1, outports[0])); // from in driver (which has "output" ports..) to client
1821 if (output_ext_latency != jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0]))) {
1822 t_error = 1;
1823 printf("!!! ERROR !!! get_latency & get_all_latency for a PHY device (unconnected) didn't return the same value !\n");
1825 Log("Checking a serial model with 2 clients...\n");
1827 jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2));
1828 jack_connect(client1, outports[0], jack_port_name(input_port1));
1829 jack_connect(client2, jack_port_name(output_port2), inports[0]);
1830 jack_port_set_latency(output_port2, 256);
1831 jack_recompute_total_latencies(client1);
1833 if ((jack_port_get_latency (output_port1) != 0) ||
1834 (jack_port_get_total_latency(client1, output_port1) != 0) ||
1835 (jack_port_get_latency (jack_port_by_name(client1, inports[0])) != (output_ext_latency)) ||
1836 (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (output_ext_latency + 256)) ||
1837 (jack_port_get_total_latency(client1, output_port2) != (output_ext_latency + 256)) ||
1838 (jack_port_get_total_latency(client1, input_port2) != 0) ||
1839 (jack_port_get_total_latency(client1, input_port1) != input_ext_latency) ||
1840 (jack_port_get_latency (jack_port_by_name(client1, outports[0])) != input_ext_latency) ||
1841 (jack_port_get_total_latency(client1, jack_port_by_name(client1, outports[0])) != input_ext_latency)
1843 printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
1844 printf("!!! get_latency(output_port1) : %i (must be 0)\n", jack_port_get_latency(output_port1));
1845 printf("!!! get_total_latency(output_port1) : %i (must be 0)\n", jack_port_get_total_latency(client1, output_port1));
1846 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);
1847 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));
1848 printf("!!! get_total_latency(output_port2) : %i (must be %i)\n", jack_port_get_total_latency(client1, output_port2), (output_ext_latency + 256));
1849 printf("!!! get_total_latency(input_port2) : %i (must be 0)\n", jack_port_get_total_latency(client1, input_port2));
1850 printf("!!! get_total_latency(input_port1) : %i (must be %i)\n", jack_port_get_total_latency(client1, input_port1), input_ext_latency);
1851 printf("!!! get_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_latency(jack_port_by_name(client1, outports[0])), input_ext_latency);
1852 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);
1854 } else {
1855 Log("get_latency & get_total_latency seems quite ok...\n");
1858 jack_port_disconnect(client1, output_port1);
1859 jack_port_disconnect(client1, output_port2);
1860 jack_port_disconnect(client1, input_port1);
1861 jack_port_disconnect(client1, input_port2);
1862 Log("Checking a parallel model with 2 clients...\n");
1863 jack_connect(client2, outports[0], jack_port_name(input_port1));
1864 jack_connect(client2, outports[0], jack_port_name(input_port2));
1865 jack_connect(client2, jack_port_name(output_port1), inports[0]);
1866 jack_connect(client2, jack_port_name(output_port2), inports[0]);
1867 jack_port_set_latency(output_port1, 256);
1868 jack_port_set_latency(output_port2, 512);
1869 jack_recompute_total_latencies(client1);
1871 if ((jack_port_get_latency(output_port1) != 256 ) ||
1872 (jack_port_get_total_latency(client1, output_port1) != (256 + output_ext_latency)) ||
1873 (jack_port_get_latency(output_port2) != 512) ||
1874 (jack_port_get_total_latency(client1, output_port2) != (512 + output_ext_latency)) ||
1875 (jack_port_get_latency(jack_port_by_name(client1, inports[0])) != output_ext_latency) ||
1876 (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (512 + output_ext_latency))
1878 printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
1879 printf("!!! get_latency(output_port1) : %i (must be 256)\n", jack_port_get_latency(output_port1));
1880 printf("!!! get_total_latency(output_port1) : %i (must be 256 + output_ext_latency)\n", jack_port_get_total_latency(client1, output_port1));
1881 printf("!!! get_latency(output_port2) : %i (must 512)\n", jack_port_get_latency(output_port2));
1882 printf("!!! get_total_latency(output_port2) : %i (must 512 + output_ext_latency)\n", jack_port_get_total_latency(client1, output_port2));
1883 printf("!!! get_latency(inports[0])) : %i (must output_ext_latency)\n", jack_port_get_latency(jack_port_by_name(client1, inports[0])));
1884 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])));
1885 } else {
1886 Log("get_latency & get_total_latency seems quite ok...\n");
1888 } else {
1889 printf("No physical port founded : not able to test latency functions...");
1892 jack_port_disconnect(client1, input_port1);
1893 jack_port_disconnect(client1, input_port2);
1894 jack_port_disconnect(client1, output_port1);
1895 jack_port_disconnect(client1, output_port2);
1897 jack_sleep(1000);
1899 jack_free(inports);
1900 jack_free(outports);
1901 #endif
1904 * Checking transport API.
1905 * Simple transport test.
1906 * Check a transport start with a "slow" client, simulating a delay around 1 sec before becoming ready.
1909 Log("-----------------------------------------------------------\n");
1910 Log("---------------------------TRANSPORT-----------------------\n");
1911 Log("-----------------------------------------------------------\n");
1913 lineports = linecount;
1915 if (transport_mode) {
1916 int wait_count;
1917 ts = jack_transport_query(client1, &pos);
1918 if (ts == JackTransportStopped) {
1919 Log("Transport is stopped...\n");
1920 } else {
1921 jack_transport_stop(client1);
1922 Log("Transport state : %i\n", ts);
1924 if (jack_set_sync_callback(client2, Jack_Sync_Callback, 0) != 0) {
1925 printf("error while calling set_sync_callback...\n");
1928 Log("starting transport...\n");
1930 starting_state = 1; // Simulate starting state
1931 jack_transport_start(client1);
1933 // Wait until sync callback is called
1934 while (!(sync_called)) {
1935 jack_sleep(1 * 1000);
1938 // Wait untill rolling : simulate sync time out
1939 Log("Simulate a slow-sync client exceeding the time-out\n");
1940 wait_count = 0;
1942 do {
1943 jack_sleep(100); // Wait 100 ms each cycle
1944 wait_count++;
1945 if (wait_count == 100) {
1946 Log("!!! ERROR !!! max time-out exceedeed : sync time-out does not work correctly\n");
1947 break;
1949 ts = jack_transport_query(client2, &pos);
1950 Log("Waiting....pos = %ld\n", pos.frame);
1951 display_transport_state();
1953 } while (ts != JackTransportRolling);
1955 Log("Sync callback have been called %i times.\n", sync_called);
1956 jack_transport_stop(client1);
1958 // Wait until stopped
1959 ts = jack_transport_query(client2, &pos);
1960 while (ts != JackTransportStopped) {
1961 jack_sleep(1 * 1000);
1962 ts = jack_transport_query(client2, &pos);
1965 // Simulate starting a slow-sync client that rolls after 0.5 sec
1966 Log("Simulate a slow-sync client that needs 0.5 sec to start\n");
1967 sync_called = 0;
1968 wait_count = 0;
1969 starting_state = 1; // Simulate starting state
1971 Log("Starting transport...\n");
1972 jack_transport_start(client1);
1973 display_transport_state();
1975 Log("Waiting 0.5 sec...\n");
1976 jack_sleep(500);
1977 starting_state = 0; // Simulate end of starting state after 0.5 sec
1979 // Wait untill rolling
1980 ts = jack_transport_query(client2, &pos);
1981 while (ts != JackTransportRolling) {
1982 jack_sleep(100); // Wait 100 ms each cycle
1983 wait_count++;
1984 if (wait_count == 10) {
1985 Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
1986 break;
1988 ts = jack_transport_query(client2, &pos);
1991 if (sync_called == 0) {
1992 Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
1995 Log("Sync callback have been called %i times.\n", sync_called);
1996 display_transport_state();
1998 // Test jack_transport_locate while rolling
1999 Log("Test jack_transport_locate while rolling\n");
2000 ts = jack_transport_query(client2, &pos);
2001 Log("Transport current frame = %ld\n", pos.frame);
2002 jack_nframes_t cur_frame = pos.frame;
2004 wait_count = 0;
2005 do {
2006 display_transport_state();
2007 jack_sleep(10); // 10 ms
2008 // locate at first...
2009 wait_count++;
2010 if (wait_count == 1) {
2011 Log("Do jack_transport_locate\n");
2012 jack_transport_locate(client1, cur_frame / 2);
2013 } else if (wait_count == 100) {
2014 break;
2016 ts = jack_transport_query(client2, &pos);
2017 Log("Locating.... frame = %ld\n", pos.frame);
2018 } while (pos.frame > cur_frame);
2020 ts = jack_transport_query(client2, &pos);
2021 Log("Transport current frame = %ld\n", pos.frame);
2022 if (wait_count == 100) {
2023 printf("!!! ERROR !!! jack_transport_locate does not work correctly\n");
2026 // Test jack_transport_reposition while rolling
2027 Log("Test jack_transport_reposition while rolling\n");
2028 ts = jack_transport_query(client2, &pos);
2029 Log("Transport current frame = %ld\n", pos.frame);
2030 cur_frame = pos.frame;
2032 wait_count = 0;
2033 do {
2034 display_transport_state();
2035 jack_sleep(10); // 10 ms
2036 // locate at first...
2037 wait_count++;
2038 if (wait_count == 1) {
2039 Log("Do jack_transport_reposition\n");
2040 request_pos.frame = cur_frame / 2;
2041 jack_transport_reposition(client1, &request_pos);
2042 } else if (wait_count == 100) {
2043 break;
2045 ts = jack_transport_query(client2, &pos);
2046 Log("Locating.... frame = %ld\n", pos.frame);
2047 } while (pos.frame > cur_frame);
2049 ts = jack_transport_query(client2, &pos);
2050 Log("Transport current frame = %ld\n", pos.frame);
2051 if (wait_count == 100) {
2052 printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
2055 // Test jack_transport_reposition while stopped
2056 jack_transport_stop(client1);
2057 ts = jack_transport_query(client2, &pos);
2058 Log("Transport current frame = %ld\n", pos.frame);
2060 Log("Test jack_transport_reposition while stopped\n");
2061 wait_count = 0;
2062 request_pos.frame = 10000;
2063 jack_transport_reposition(client1, &request_pos);
2065 do {
2066 display_transport_state();
2067 jack_sleep(100); // 100 ms
2068 if (wait_count++ == 10)
2069 break;
2070 ts = jack_transport_query(client2, &pos);
2071 Log("Locating.... frame = %ld\n", pos.frame);
2072 } while (pos.frame != 10000);
2074 ts = jack_transport_query(client2, &pos);
2075 Log("Transport current frame = %ld\n", pos.frame);
2076 if (pos.frame != 10000) {
2077 printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
2080 jack_transport_stop(client1);
2082 /* Tell the JACK server that we are ready to roll. Our
2083 * process() callback will start running now. */
2085 } else {
2086 printf("Transport check is disabled...\n");
2089 time_before_exit = time_to_run;
2090 while (time_before_exit != 0) {
2091 jack_sleep (1 * 1000);
2092 time_before_exit--;
2095 if (jack_deactivate(client2) != 0) {
2096 printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
2098 if (jack_deactivate(client1) != 0) {
2099 printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
2103 * Checking jack_frame_time.
2105 Log("Testing jack_frame_time...\n");
2106 jack_set_process_callback(client1, process4, client1);
2107 jack_activate(client1);
2108 jack_sleep(2 * 1000);
2111 * Checking jack_get_cycle_times.
2113 Log("Testing jack_get_cycle_times...\n");
2114 jack_deactivate(client1);
2115 jack_set_process_callback(client1, process5, client1);
2116 jack_activate(client1);
2117 jack_sleep(3 * 1000);
2120 * Checking alternate thread model
2122 Log("Testing alternate thread model...\n");
2123 jack_deactivate(client1);
2124 jack_set_process_callback(client1, NULL, NULL); // remove callback
2125 jack_set_process_thread(client1, jack_thread, client1);
2126 jack_activate(client1);
2127 jack_sleep(2 * 1000);
2130 * Checking callback exiting : when the return code is != 0, the client is desactivated.
2132 Log("Testing callback exiting...\n");
2133 jack_deactivate(client1);
2134 jack_set_process_thread(client1, NULL, NULL); // remove thread callback
2135 jack_set_process_callback(client1, process3, 0);
2136 jack_activate(client1);
2137 jack_sleep(3 * 1000);
2140 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2141 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2142 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2143 Closing program
2144 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2145 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2146 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2149 if (jack_deactivate(client2) != 0) {
2150 printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
2152 if (jack_deactivate(client1) != 0) {
2153 printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
2155 if (jack_client_close(client2) != 0) {
2156 printf("!!! ERROR !!! jack_client_close does not return 0 for client2 !\n");
2158 if (jack_client_close(client1) != 0) {
2159 printf("!!! ERROR !!! jack_client_close does not return 0 for client1 !\n");
2162 if (xrun == 0) {
2163 Log("No Xrun have been detected during this test... cool !\n");
2164 } else {
2165 printf("%i Xrun have been detected during this session (seen callback messages to see where are the problems).\n", xrun);
2167 free(framecollect);
2168 free(signal1);
2169 free(signal2);
2170 Log("Exiting jack_test...\n");
2171 fclose(file);
2172 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
2173 sprintf (filename, "framegraph-%i.gnu", cur_buffer_size);
2174 file = fopen(filename, "w");
2175 if (file == NULL) {
2176 fprintf(stderr, "Error while opening file");
2177 exit(-1);
2179 fprintf(file, "reset\n");
2180 fprintf(file, "set terminal png transparent nocrop enhanced\n");
2181 fprintf(file, "set output 'framegraph-%i-1.png'\n", cur_buffer_size);
2182 fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
2183 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));
2184 fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
2185 fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
2186 fprintf(file, "set xlabel \"FrameTime\"\n");
2187 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);
2188 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);
2190 fprintf(file, "set output 'framegraph-%i-2.png'\n", cur_buffer_size);
2191 fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
2192 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)));
2193 fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
2194 fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
2195 fprintf(file, "set xlabel \"FrameTime\"\n");
2196 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);
2197 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);
2198 fclose(file);
2199 return 0;