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.
22 * @brief This client test the jack API.
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
48 #define jack_sleep(val) Sleep((val))
50 #define jack_sleep(val) usleep((val) * 1000)
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...
62 FrameTimeCollector
* framecollect
;
63 FrameTimeCollector perpetualcollect
;
64 FrameTimeCollector lastperpetualcollect
;
65 int frames_collected
= 0;
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
;
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
83 int time_before_exit
= 1;
84 // standard error count
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
92 int port_callback_reg
= 0;
93 jack_nframes_t cur_buffer_size
, old_buffer_size
, cur_pos
;
95 int count1
, count2
= 0; // for freewheel
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
;
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
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;
123 int client_register
= 0;
126 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
127 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
129 Callbacks & basics functions
131 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
132 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
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"
148 void Log(const char *fmt
, ...)
153 vfprintf(stderr
, fmt
, 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
)
168 Log("Init callback has been successfully called from thread = %x. (msg from callback)\n", GetCurrentThread());
170 Log("Init callback has been successfully called from thread = %x. (msg from callback)\n", pthread_self());
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
);
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
);
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
);
203 int Jack_XRun_Callback(void *arg
)
207 Log("Xrun has been detected ! (msg from callback)\n");
211 int Jack_Graph_Order_Callback(void *arg
)
217 int Jack_Sample_Rate_Callback(jack_nframes_t nframes
, void *arg
)
219 Log("Sample rate : %i.\n", nframes
);
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");
236 void jack_info_shutdown(jack_status_t code
, const char* reason
, void *arg
)
238 printf("JACK server failure : %s\n", reason
);
242 void Jack_Port_Register(jack_port_id_t port
, int mode
, void *arg
)
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
)
258 case JackTransportStarting
:
260 if (starting_state
== 0) {
261 Log("sync callback : Releasing status : now ready...\n");
264 if (sync_called
== 1) {
265 Log("sync callback : Holding status...\n");
271 case JackTransportStopped
:
272 Log("sync callback : JackTransportStopped...\n");
286 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
287 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
291 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
292 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
293 * Proccess1 is for client1
294 * 4 modes, activated with process1_activated
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
)
308 Collect(&perpetualcollect
);
310 fprintf(file
, "%i %i\n", (perpetualcollect
.ft
- lastperpetualcollect
.ft
), (2*cur_buffer_size
));
313 fprintf(file
, "%i 0\n", (perpetualcollect
.ft
- lastperpetualcollect
.ft
));
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
];
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
];
337 out1b
[p
] = ( -1 * signal1
[index1
]);
339 out1b
[p
] = signal1
[index1
];
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
]);
353 if (frames_collected
> 798) {
354 process1_activated
= -1;
361 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
362 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
363 * Proccess2 is for client2
364 * 3 modes, activated with process1_activated
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;
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
];
402 signal2
[index2
] = in2
[p
];
403 if (index2
== 95999) {
404 process2_activated
= -1;
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;
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
);
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
);
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
);
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");
467 Log("calling process3 callback : process3_call = %ld\n", process3_call
);
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
;
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
);
502 jack_nframes_t current_frames
;
503 jack_time_t current_usecs
;
504 jack_time_t next_usecs
;
507 int res
= jack_get_cycle_times(client
, ¤t_frames
, ¤t_usecs
, &next_usecs
, &period_usecs
);
509 printf("!!! ERROR !!! jack_get_cycle_times fails...\n");
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
;
522 static void display_transport_state()
524 jack_transport_state_t ts
;
527 ts
= jack_transport_query(client2
, &pos
);
529 case JackTransportStopped
:
530 Log("Transport is stopped...\n");
532 case JackTransportRolling
:
533 Log("Transport is rolling...\n");
535 case JackTransportLooping
:
536 Log("Transport is looping...\n");
538 case JackTransportStarting
:
539 Log("Transport is starting...\n");
541 case JackTransportNetStarting
:
542 Log("Transport is starting with network sync...\n");
548 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
549 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
550 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
551 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
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
= "";
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'},
582 {"quiet", 0, 0, 'q'},
583 {"verbose", 0, 0, 'v'},
584 {"transport", 0, 0, 'k'},
588 client_name1
= "jack_test";
592 while ((opt
= getopt_long (argc
, argv
, options
, long_options
, &option_index
)) != EOF
) {
602 printf("Verbose mode is activated...\n");
605 time_to_run
= atoi(optarg
);
611 fprintf (stderr
, "unknown option %c\n", opt
);
617 printf("Jack server is said being in realtime mode...\n");
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
));
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
++) {
643 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
644 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
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");
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
);
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
);
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");
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
);
708 Log("jack_internal_client_unload done first time returns correct value\n");
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");
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");
732 printf("!!! ERROR !!! Jackd server has accepted multiples client with the same name !\n");
733 jack_client_close(client2
);
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
);
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
);
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) {
784 printf("\n!!! ERROR !!! name returned different from the one given : %s\n", client_name2
);
786 jack_client_close(client2
);
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) {
801 printf("\n!!! ERROR !!! name returned different from the one given : %s\n", client_name2
);
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
);
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");
876 fprintf(stderr
, "Error when opening framefile.dat log file");
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");
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");
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");
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");
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
);
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
));
955 Log("Checking jack_port_set_name()... ok\n");
956 jack_port_set_name (output_port1
, "port");
959 printf("error : port_set_name function can't be tested...\n");
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
++) {
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
);
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");
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");
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
);
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 beginning...
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.
1041 jack_sleep(1 * 1000);
1043 Log("Testing activation freewheel mode...\n");
1044 linefw
= linecount
; // count for better graph reading with gnuplot
1045 jack_set_freewheel(client1
, 1);
1047 jack_sleep(1 * 1000);
1049 if (jack_is_realtime(client1
) == 0) {
1052 printf("\n!!! ERROR !!! RT mode is always activated while freewheel mode is applied !\n");
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) {
1064 printf("\n!!! ERROR !!! freewheel mode fail to reactivate RT mode when exiting !\n");
1068 Log("Freewheel mode appears to work well...\n");
1071 Log("Audio Callback in 'standard' (non-freewheel) mode seems not to be called...\n");
1072 Log("Ratio speed would be unavailable...\n");
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");
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 registered 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
)) {
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
);
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
)));
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
));
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]))) {
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");
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
]));
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 ");
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 found !\n");
1198 if (inports
== NULL
) {
1199 printf("!!! WARNING !!! no physical output ports found !\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
;
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);
1224 if (input_port1
== NULL
) {
1228 // Connect created input to PHY output
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
));
1234 // printf ("input PHY port %s connected to client port %s\n", outports[a], jack_port_name(input_port1));
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.
1247 sprintf(portname
, "output_%d", i
);
1248 output_port1
= jack_port_register(client1
, portname
,
1249 JACK_DEFAULT_AUDIO_TYPE
,
1250 JackPortIsOutput
, 0);
1252 if (output_port1
== NULL
) {
1256 // Connect created input to PHY output
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
));
1262 // output PHY port %s connected to client port. ok.
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.
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
);
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
);
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.
1297 Log("Jack links can't be 'over-connected'... ok\n");
1299 printf("!!! ERROR !!! Jack links can be 'over-connected'...\n");
1302 * Print the result of the two jack_is_mine test.
1306 Log("Checking jack_port_is_mine()... ok\n");
1308 printf("!!! ERROR !!! jack_port_is_mine() function seems to send non-valid data !\n");
1311 * Free the array of the physical input and output ports.
1312 * (as mentioned in the doc of jack_get_ports)
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");
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);
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
));
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
);
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 mentioned 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");
1384 // Check client registration callback after jack_client_new
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
);
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");
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");
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");
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");
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");
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");
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");
1522 while ((connexions1
[a
] != NULL
) && (connexions2
[a
] != NULL
) && (t_error
== 0)) {
1523 t_error
= strcmp(connexions1
[a
], connexions2
[a
]);
1528 Log("Checking jack_port_get_connections Vs jack_port_get_all_connections... ok\n");
1530 printf("!!! ERROR !!! while checking jack_port_get_connections Vs jack_port_get_all_connections...\n");
1535 inports
= jack_get_ports(client1
, NULL
, NULL
, JackPortIsPhysical
| JackPortIsInput
);
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");
1546 while ((connexions1
[a
] != NULL
) && (connexions2
[a
] != NULL
) && (t_error
== 0)) {
1547 t_error
= strcmp(connexions1
[a
], connexions2
[a
]);
1552 Log("Checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port... ok\n");
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 data 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 data...");
1578 process1_activated
= 1; // We start emitting first.
1579 process2_activated
= 1; // So record begins at least when we just begin to emit the signal, else at next call of process with
1580 // nframe = jack buffersize shifting.
1582 while (process2_activated
== 1) {
1583 jack_sleep(1 * 1000);
1587 Log("\nAnalysing data...\n"); // search the first occurrence of the first element of the reference signal in the recorded signal
1588 while (signal2
[index2
] != signal1
[1] ) {
1590 if (index2
== 95999) {
1591 printf("!!! ERROR !!! Data not found in first connexion data check!\n");
1596 Log("Data found at offset %i.\n", index2
);
1597 // Now that we've found where the recorded data is, we can see if the two signals match...
1598 while ( (signal2
[index2
] == signal1
[index2
- index1
+ 1]) || (index2
== 95999) || ((index2
- index1
+ 1) == 47999) ) {
1601 Log("Checking difference between data... %i have the same value...\n", index2
- index1
);
1602 if ((index2
- index1
) == 48000) {
1603 Log("Data received are valid...\n");
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");
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");
1627 printf("!!! ERROR !!! port_tie has allowed a connexion between two different clients !\n");
1628 jack_port_untie(output_port2
);
1630 Log("Testing connections data in tie mode...\n");
1632 for (g
= 0; g
< 96000; g
++)
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 manually check here that the tie is effective.
1649 // ie : playing a wav with a client, connecting ports manually with qjackctl, and listen...
1650 // printf("manual test\n");
1652 // printf("end of manual test\n");
1656 process1_activated
= -1;
1657 process2_activated
= 2;
1659 Log("Sending data...");
1661 while (process2_activated
== 2) {
1662 jack_sleep(1 * 1000);
1665 process1_activated
= -1;
1666 process2_activated
= -1;
1668 Log("\nAnalysing data...\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]))) {
1672 if (index2
== 95999) {
1673 printf("!!! ERROR !!! Data not found in connexion check of tie mode!\n");
1678 Log("Tie mode : Data found at offset %i.\n", index2
);
1679 while (signal2
[index2
] == signal1
[index2
- index1
+ 1]) {
1681 if ((index2
== 95999) || ((index2
- index1
+ 1) == 47999)) {
1685 Log("Checking difference between data... %i have the same value...\n", index2
- index1
);
1686 if ((index2
- index1
) > 47995) {
1687 Log("Data received in tie mode are valid...\n");
1689 // in tie mode, the buffers address 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 (receive)\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
);
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;
1727 for (h
= 0; h
< 96000; h
++)
1732 Log("Sending data...");
1733 process2_activated
= 3;
1735 while (process2_activated
== 3) {
1736 jack_sleep(1 * 1000);
1739 process1_activated
= -1;
1740 process2_activated
= -1;
1742 Log("\nAnalysing data...\n"); // same idea as above, with first data check...
1743 while (!((signal2
[index2
] == 0.0 ) && (signal2
[(index2
+ 1)] == 0.0 ))) {
1745 if (index2
== 95999) {
1746 printf("!!! ERROR !!! Data not found in summation check!\n");
1751 Log("Data found at offset %i.\n", index2
);
1753 while ( signal2
[index2
] == 0.0 ) {
1755 if ((index2
> 95998) || ((index2
- index1
+ 1) > 47998)) {
1759 Log("Checking difference between data...\n");
1760 if ((index2
- index1
) > 47996) {
1761 Log("Data mixed received are valid...\nSummation is well done.\n");
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
));
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");
1780 Log("Checking renaming of an unregistered port... ok\n");
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");
1788 Log("Checking renaming of an unregistered port... ok\n");
1791 jack_free (inports
);
1795 * Checking latency issues
1796 * here is a 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 this information to internally do its compensations.
1802 * Three tests are done:
1803 * 1) with no connections between client,
1804 * 2) with a serial connection, and
1805 * 3) with parallel connection
1808 #ifndef TEST_EXCLUDE_DEPRECATED
1809 Log("Checking latency functions...\n");
1811 jack_recompute_total_latencies(client1
);
1812 Log("jack_recompute_total_latencies...\n");
1813 if ((jack_port_get_latency (output_port1
) != 0) ||
1814 (jack_port_get_total_latency(client1
, output_port1
) != 0) ) {
1816 printf("!!! ERROR !!! default latency of a non-PHY device is not set to zero !\n");
1819 inports
= jack_get_ports(client1
, NULL
, NULL
, JackPortIsPhysical
| JackPortIsInput
);
1820 outports
= jack_get_ports(client1
, NULL
, NULL
, JackPortIsPhysical
| JackPortIsOutput
);
1821 if (inports
&& outports
&& inports
[0] != NULL
&& outports
[0] != NULL
) {
1822 output_ext_latency
= jack_port_get_latency (jack_port_by_name(client1
, inports
[0])); // from client to out driver (which has "inputs" ports..)
1823 input_ext_latency
= jack_port_get_latency (jack_port_by_name(client1
, outports
[0])); // from in driver (which has "output" ports..) to client
1824 if (output_ext_latency
!= jack_port_get_total_latency(client1
, jack_port_by_name(client1
, inports
[0]))) {
1826 printf("!!! ERROR !!! get_latency & get_all_latency for a PHY device (unconnected) didn't return the same value !\n");
1828 Log("Checking a serial model with 2 clients...\n");
1830 jack_connect(client1
, jack_port_name(output_port1
), jack_port_name(input_port2
));
1831 jack_connect(client1
, outports
[0], jack_port_name(input_port1
));
1832 jack_connect(client2
, jack_port_name(output_port2
), inports
[0]);
1833 jack_port_set_latency(output_port2
, 256);
1834 jack_recompute_total_latencies(client1
);
1836 if ((jack_port_get_latency (output_port1
) != 0) ||
1837 (jack_port_get_total_latency(client1
, output_port1
) != 0) ||
1838 (jack_port_get_latency (jack_port_by_name(client1
, inports
[0])) != (output_ext_latency
)) ||
1839 (jack_port_get_total_latency(client1
, jack_port_by_name(client1
, inports
[0])) != (output_ext_latency
+ 256)) ||
1840 (jack_port_get_total_latency(client1
, output_port2
) != (output_ext_latency
+ 256)) ||
1841 (jack_port_get_total_latency(client1
, input_port2
) != 0) ||
1842 (jack_port_get_total_latency(client1
, input_port1
) != input_ext_latency
) ||
1843 (jack_port_get_latency (jack_port_by_name(client1
, outports
[0])) != input_ext_latency
) ||
1844 (jack_port_get_total_latency(client1
, jack_port_by_name(client1
, outports
[0])) != input_ext_latency
)
1846 printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
1847 printf("!!! get_latency(output_port1) : %i (must be 0)\n", jack_port_get_latency(output_port1
));
1848 printf("!!! get_total_latency(output_port1) : %i (must be 0)\n", jack_port_get_total_latency(client1
, output_port1
));
1849 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
);
1850 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));
1851 printf("!!! get_total_latency(output_port2) : %i (must be %i)\n", jack_port_get_total_latency(client1
, output_port2
), (output_ext_latency
+ 256));
1852 printf("!!! get_total_latency(input_port2) : %i (must be 0)\n", jack_port_get_total_latency(client1
, input_port2
));
1853 printf("!!! get_total_latency(input_port1) : %i (must be %i)\n", jack_port_get_total_latency(client1
, input_port1
), input_ext_latency
);
1854 printf("!!! get_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_latency(jack_port_by_name(client1
, outports
[0])), input_ext_latency
);
1855 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
);
1858 Log("get_latency & get_total_latency seems quite ok...\n");
1861 jack_port_disconnect(client1
, output_port1
);
1862 jack_port_disconnect(client1
, output_port2
);
1863 jack_port_disconnect(client1
, input_port1
);
1864 jack_port_disconnect(client1
, input_port2
);
1865 Log("Checking a parallel model with 2 clients...\n");
1866 jack_connect(client2
, outports
[0], jack_port_name(input_port1
));
1867 jack_connect(client2
, outports
[0], jack_port_name(input_port2
));
1868 jack_connect(client2
, jack_port_name(output_port1
), inports
[0]);
1869 jack_connect(client2
, jack_port_name(output_port2
), inports
[0]);
1870 jack_port_set_latency(output_port1
, 256);
1871 jack_port_set_latency(output_port2
, 512);
1872 jack_recompute_total_latencies(client1
);
1874 if ((jack_port_get_latency(output_port1
) != 256 ) ||
1875 (jack_port_get_total_latency(client1
, output_port1
) != (256 + output_ext_latency
)) ||
1876 (jack_port_get_latency(output_port2
) != 512) ||
1877 (jack_port_get_total_latency(client1
, output_port2
) != (512 + output_ext_latency
)) ||
1878 (jack_port_get_latency(jack_port_by_name(client1
, inports
[0])) != output_ext_latency
) ||
1879 (jack_port_get_total_latency(client1
, jack_port_by_name(client1
, inports
[0])) != (512 + output_ext_latency
))
1881 printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
1882 printf("!!! get_latency(output_port1) : %i (must be 256)\n", jack_port_get_latency(output_port1
));
1883 printf("!!! get_total_latency(output_port1) : %i (must be 256 + output_ext_latency)\n", jack_port_get_total_latency(client1
, output_port1
));
1884 printf("!!! get_latency(output_port2) : %i (must 512)\n", jack_port_get_latency(output_port2
));
1885 printf("!!! get_total_latency(output_port2) : %i (must 512 + output_ext_latency)\n", jack_port_get_total_latency(client1
, output_port2
));
1886 printf("!!! get_latency(inports[0])) : %i (must output_ext_latency)\n", jack_port_get_latency(jack_port_by_name(client1
, inports
[0])));
1887 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])));
1889 Log("get_latency & get_total_latency seems quite ok...\n");
1892 printf("No physical port found : not able to test latency functions...");
1895 jack_port_disconnect(client1
, input_port1
);
1896 jack_port_disconnect(client1
, input_port2
);
1897 jack_port_disconnect(client1
, output_port1
);
1898 jack_port_disconnect(client1
, output_port2
);
1903 jack_free(outports
);
1907 * Checking transport API.
1908 * Simple transport test.
1909 * Check a transport start with a "slow" client, simulating a delay around 1 sec before becoming ready.
1912 Log("-----------------------------------------------------------\n");
1913 Log("---------------------------TRANSPORT-----------------------\n");
1914 Log("-----------------------------------------------------------\n");
1916 lineports
= linecount
;
1918 if (transport_mode
) {
1920 ts
= jack_transport_query(client1
, &pos
);
1921 if (ts
== JackTransportStopped
) {
1922 Log("Transport is stopped...\n");
1924 jack_transport_stop(client1
);
1925 Log("Transport state : %i\n", ts
);
1927 if (jack_set_sync_callback(client2
, Jack_Sync_Callback
, 0) != 0) {
1928 printf("error while calling set_sync_callback...\n");
1931 Log("starting transport...\n");
1933 starting_state
= 1; // Simulate starting state
1934 jack_transport_start(client1
);
1936 // Wait until sync callback is called
1937 while (!(sync_called
)) {
1938 jack_sleep(1 * 1000);
1941 // Wait until rolling : simulate sync time out
1942 Log("Simulate a slow-sync client exceeding the time-out\n");
1946 jack_sleep(100); // Wait 100 ms each cycle
1948 if (wait_count
== 100) {
1949 Log("!!! ERROR !!! max time-out exceedeed : sync time-out does not work correctly\n");
1952 ts
= jack_transport_query(client2
, &pos
);
1953 Log("Waiting....pos = %ld\n", pos
.frame
);
1954 display_transport_state();
1956 } while (ts
!= JackTransportRolling
);
1958 Log("Sync callback have been called %i times.\n", sync_called
);
1959 jack_transport_stop(client1
);
1961 // Wait until stopped
1962 ts
= jack_transport_query(client2
, &pos
);
1963 while (ts
!= JackTransportStopped
) {
1964 jack_sleep(1 * 1000);
1965 ts
= jack_transport_query(client2
, &pos
);
1968 // Simulate starting a slow-sync client that rolls after 0.5 sec
1969 Log("Simulate a slow-sync client that needs 0.5 sec to start\n");
1972 starting_state
= 1; // Simulate starting state
1974 Log("Starting transport...\n");
1975 jack_transport_start(client1
);
1976 display_transport_state();
1978 Log("Waiting 0.5 sec...\n");
1980 starting_state
= 0; // Simulate end of starting state after 0.5 sec
1982 // Wait until rolling
1983 ts
= jack_transport_query(client2
, &pos
);
1984 while (ts
!= JackTransportRolling
) {
1985 jack_sleep(100); // Wait 100 ms each cycle
1987 if (wait_count
== 10) {
1988 Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
1991 ts
= jack_transport_query(client2
, &pos
);
1994 if (sync_called
== 0) {
1995 Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
1998 Log("Sync callback have been called %i times.\n", sync_called
);
1999 display_transport_state();
2001 // Test jack_transport_locate while rolling
2002 Log("Test jack_transport_locate while rolling\n");
2003 ts
= jack_transport_query(client2
, &pos
);
2004 Log("Transport current frame = %ld\n", pos
.frame
);
2005 jack_nframes_t cur_frame
= pos
.frame
;
2009 display_transport_state();
2010 jack_sleep(10); // 10 ms
2011 // locate at first...
2013 if (wait_count
== 1) {
2014 Log("Do jack_transport_locate\n");
2015 jack_transport_locate(client1
, cur_frame
/ 2);
2016 } else if (wait_count
== 100) {
2019 ts
= jack_transport_query(client2
, &pos
);
2020 Log("Locating.... frame = %ld\n", pos
.frame
);
2021 } while (pos
.frame
> cur_frame
);
2023 ts
= jack_transport_query(client2
, &pos
);
2024 Log("Transport current frame = %ld\n", pos
.frame
);
2025 if (wait_count
== 100) {
2026 printf("!!! ERROR !!! jack_transport_locate does not work correctly\n");
2029 // Test jack_transport_reposition while rolling
2030 Log("Test jack_transport_reposition while rolling\n");
2031 ts
= jack_transport_query(client2
, &pos
);
2032 Log("Transport current frame = %ld\n", pos
.frame
);
2033 cur_frame
= pos
.frame
;
2037 display_transport_state();
2038 jack_sleep(10); // 10 ms
2039 // locate at first...
2041 if (wait_count
== 1) {
2042 Log("Do jack_transport_reposition\n");
2043 request_pos
.frame
= cur_frame
/ 2;
2044 jack_transport_reposition(client1
, &request_pos
);
2045 } else if (wait_count
== 100) {
2048 ts
= jack_transport_query(client2
, &pos
);
2049 Log("Locating.... frame = %ld\n", pos
.frame
);
2050 } while (pos
.frame
> cur_frame
);
2052 ts
= jack_transport_query(client2
, &pos
);
2053 Log("Transport current frame = %ld\n", pos
.frame
);
2054 if (wait_count
== 100) {
2055 printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
2058 // Test jack_transport_reposition while stopped
2059 jack_transport_stop(client1
);
2060 ts
= jack_transport_query(client2
, &pos
);
2061 Log("Transport current frame = %ld\n", pos
.frame
);
2063 Log("Test jack_transport_reposition while stopped\n");
2065 request_pos
.frame
= 10000;
2066 jack_transport_reposition(client1
, &request_pos
);
2069 display_transport_state();
2070 jack_sleep(100); // 100 ms
2071 if (wait_count
++ == 10)
2073 ts
= jack_transport_query(client2
, &pos
);
2074 Log("Locating.... frame = %ld\n", pos
.frame
);
2075 } while (pos
.frame
!= 10000);
2077 ts
= jack_transport_query(client2
, &pos
);
2078 Log("Transport current frame = %ld\n", pos
.frame
);
2079 if (pos
.frame
!= 10000) {
2080 printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
2083 jack_transport_stop(client1
);
2085 /* Tell the JACK server that we are ready to roll. Our
2086 * process() callback will start running now. */
2089 printf("Transport check is disabled...\n");
2092 time_before_exit
= time_to_run
;
2093 while (time_before_exit
!= 0) {
2094 jack_sleep (1 * 1000);
2098 if (jack_deactivate(client2
) != 0) {
2099 printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
2101 if (jack_deactivate(client1
) != 0) {
2102 printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
2106 * Checking jack_frame_time.
2108 Log("Testing jack_frame_time...\n");
2109 jack_set_process_callback(client1
, process4
, client1
);
2110 jack_activate(client1
);
2111 jack_sleep(2 * 1000);
2114 * Checking jack_get_cycle_times.
2116 Log("Testing jack_get_cycle_times...\n");
2117 jack_deactivate(client1
);
2118 jack_set_process_callback(client1
, process5
, client1
);
2119 jack_activate(client1
);
2120 jack_sleep(3 * 1000);
2123 * Checking alternate thread model
2125 Log("Testing alternate thread model...\n");
2126 jack_deactivate(client1
);
2127 jack_set_process_callback(client1
, NULL
, NULL
); // remove callback
2128 jack_set_process_thread(client1
, jack_thread
, client1
);
2129 jack_activate(client1
);
2130 jack_sleep(2 * 1000);
2133 * Checking callback exiting : when the return code is != 0, the client is deactivated.
2135 Log("Testing callback exiting...\n");
2136 jack_deactivate(client1
);
2137 jack_set_process_thread(client1
, NULL
, NULL
); // remove thread callback
2138 jack_set_process_callback(client1
, process3
, 0);
2139 jack_activate(client1
);
2140 jack_sleep(3 * 1000);
2143 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2144 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2145 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2147 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2148 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2149 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2152 if (jack_deactivate(client2
) != 0) {
2153 printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
2155 if (jack_deactivate(client1
) != 0) {
2156 printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
2158 if (jack_client_close(client2
) != 0) {
2159 printf("!!! ERROR !!! jack_client_close does not return 0 for client2 !\n");
2161 if (jack_client_close(client1
) != 0) {
2162 printf("!!! ERROR !!! jack_client_close does not return 0 for client1 !\n");
2166 Log("No Xrun have been detected during this test... cool !\n");
2168 printf("%i Xrun have been detected during this session (seen callback messages to see where are the problems).\n", xrun
);
2173 Log("Exiting jack_test...\n");
2175 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
2176 sprintf (filename
, "framegraph-%i.gnu", cur_buffer_size
);
2177 file
= fopen(filename
, "w");
2179 fprintf(stderr
, "Error while opening file");
2182 fprintf(file
, "reset\n");
2183 fprintf(file
, "set terminal png transparent nocrop enhanced\n");
2184 fprintf(file
, "set output 'framegraph-%i-1.png'\n", cur_buffer_size
);
2185 fprintf(file
, "set title \"Frame time evolution during jack_test run\"\n");
2186 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));
2187 fprintf(file
, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount
- 1);
2188 fprintf(file
, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
2189 fprintf(file
, "set xlabel \"FrameTime\"\n");
2190 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
);
2191 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
);
2193 fprintf(file
, "set output 'framegraph-%i-2.png'\n", cur_buffer_size
);
2194 fprintf(file
, "set title \"Frame time evolution during jack_test run\"\n");
2195 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)));
2196 fprintf(file
, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount
- 1);
2197 fprintf(file
, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
2198 fprintf(file
, "set xlabel \"FrameTime\"\n");
2199 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
);
2200 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
);