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>
42 #if defined(WIN32) && !defined(M_PI)
43 #define M_PI 3.151592653
47 #define jack_sleep(val) Sleep((val))
49 #define jack_sleep(val) usleep((val) * 1000)
54 jack_nframes_t ft
; // running counter frame time
55 jack_nframes_t fcs
; // from sycle start...
56 jack_nframes_t lft
; // last frame time...
61 FrameTimeCollector
* framecollect
;
62 FrameTimeCollector perpetualcollect
;
63 FrameTimeCollector lastperpetualcollect
;
64 int frames_collected
= 0;
67 jack_port_t
*output_port1
;
68 jack_port_t
*output_port1b
;
69 jack_port_t
*input_port2
;
70 jack_port_t
*output_port2
;
71 jack_port_t
*input_port1
;
74 jack_client_t
*client1
;
75 jack_client_t
*client2
;
76 const char *client_name1
;
77 const char *client_name2
;
79 unsigned long sr
; // sample rate
82 int time_before_exit
= 1;
83 // standard error count
85 int reorder
= 0; // graph reorder callback
86 int RT
= 0; // is real time or not...
87 int FW
= 0; // freewheel mode
88 int init_clbk
= 0; // init callback
89 int port_rename_clbk
= 0; // portrename callback
91 int port_callback_reg
= 0;
92 jack_nframes_t cur_buffer_size
, old_buffer_size
, cur_pos
;
94 int count1
, count2
= 0; // for freewheel
96 int have_xrun
= 0; // msg to tell the process1 function to write a special thing in the frametime file.
97 int process1_activated
= -1; // to control processing...
98 int process2_activated
= -1; // to control processing...
99 unsigned long int index1
= 0;
100 unsigned long int index2
= 0;
101 jack_default_audio_sample_t
*signal1
; // signal source d'emission
102 jack_default_audio_sample_t
*signal2
; // tableau de reception
103 jack_transport_state_t ts
;
105 jack_position_t request_pos
;
106 int silent_error
= 0; // jack silent mode
107 int verbose_mode
= 0;
108 int transport_mode
= 1;
109 jack_nframes_t input_ext_latency
= 0; // test latency for PHY devices
110 jack_nframes_t output_ext_latency
= 0; // test latency for PHY devices
113 int starting_state
= 1;
115 int linecount
= 0; // line counter for log file of sampleframe counter --> for graph function.
116 int linebuf
= 0; // reminders for graph analysis
117 int linetransport
= 0;
122 int client_register
= 0;
125 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
126 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
128 Callbacks & basics functions
130 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
131 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
136 fprintf (stderr
, "\n\n"
137 "usage: jack_test \n"
138 " [ --time OR -t time_to_run (in seconds) ]\n"
139 " [ --quiet OR -q (quiet mode : without jack server errors) ]\n"
140 " [ --verbose OR -v (verbose mode : no details on tests done. Only main results & errors) ]\n"
141 " [ --transport OR -k (Do not test transport functions.) ]\n"
142 " --realtime OR -R (jack is in rt mode)\n\n\n"
147 void Log(const char *fmt
, ...)
152 vfprintf(stderr
, fmt
, ap
);
157 void Collect(FrameTimeCollector
* TheFrame
)
159 TheFrame
->lft
= jack_last_frame_time(client1
);
160 TheFrame
->ft
= jack_frame_time(client1
);
161 TheFrame
->fcs
= jack_frames_since_cycle_start(client1
);
164 void Jack_Thread_Init_Callback(void *arg
)
167 Log("Init callback has been successfully called from thread = %x. (msg from callback)\n", GetCurrentThread());
169 Log("Init callback has been successfully called from thread = %x. (msg from callback)\n", pthread_self());
174 void Jack_Freewheel_Callback(int starting
, void *arg
)
176 Log("Freewheel callback has been successfully called with value %i. (msg from callback)\n", starting
);
180 void Jack_Client_Registration_Callback(const char* name
, int val
, void *arg
)
182 Log("Client registration callback name = %s has been successfully called with value %i. (msg from callback)\n", name
, val
);
189 int Jack_Port_Rename_Callback(jack_port_id_t port
, const char* old_name
, const char* new_name
, void *arg
)
191 Log("Rename callback has been successfully called with old_name '%s' and new_name '%s'. (msg from callback)\n", old_name
, new_name
);
192 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
);
437 sizeof (jack_default_audio_sample_t
) * nframes
);
441 static void* jack_thread(void *arg
)
443 jack_client_t
* client
= (jack_client_t
*) arg
;
444 jack_nframes_t last_thread_time
= jack_frame_time(client
);
447 jack_nframes_t frames
= jack_cycle_wait(client
);
448 jack_nframes_t current_thread_time
= jack_frame_time(client
);
449 jack_nframes_t delta_time
= current_thread_time
- last_thread_time
;
450 Log("jack_thread : delta_time = %ld\n", delta_time
);
451 int status
= _process(frames
);
452 last_thread_time
= current_thread_time
;
453 jack_cycle_signal (client
, status
);
459 // To test callback exiting
460 int process3(jack_nframes_t nframes
, void *arg
)
462 static int process3_call
= 0;
464 if (process3_call
++ > 10) {
465 Log("process3 callback : exiting...\n");
468 Log("calling process3 callback : process3_call = %ld\n", process3_call
);
473 int process4(jack_nframes_t nframes
, void *arg
)
475 jack_client_t
* client
= (jack_client_t
*) arg
;
477 static jack_nframes_t last_time
= jack_frame_time(client
);
478 static jack_nframes_t tolerance
= (jack_nframes_t
)(cur_buffer_size
* 0.1f
);
480 jack_nframes_t cur_time
= jack_frame_time(client
);
481 jack_nframes_t delta_time
= cur_time
- last_time
;
483 Log("calling process4 callback : jack_frame_time = %ld delta_time = %ld\n", cur_time
, delta_time
);
484 if (delta_time
> 0 && (jack_nframes_t
)abs(delta_time
- cur_buffer_size
) > tolerance
) {
485 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
);
488 last_time
= cur_time
;
492 int process5(jack_nframes_t nframes
, void *arg
)
494 jack_client_t
* client
= (jack_client_t
*) arg
;
496 static jack_nframes_t first_current_frames
;
497 static jack_time_t first_current_usecs
;
498 static jack_time_t first_next_usecs
;
499 static float first_period_usecs
;
500 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
);
724 * try to register another one with the same name...
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
);
737 * try to register another one with the same name using jack_client_open ==> since JackUseExactName is not used, an new client should be opened...
740 Log("trying to register a new jackd client with name %s using jack_client_open()...\n", client_name1
);
741 client2
= jack_client_open(client_name1
, jack_options
, &status
, server_name
);
742 if (client2
!= NULL
) {
743 Log ("valid : a second client with the same name can be registered (client automatic renaming)\n");
744 jack_client_close(client2
);
746 printf("!!! ERROR !!! Jackd server automatic renaming feature does not work!\n");
750 * testing client name...
751 * Verify that the name sended at registration and the one returned by jack server is the same...
754 Log("Testing name...");
755 client_name2
= jack_get_client_name(client1
);
756 if (strcmp(client_name1
, client_name2
) == 0)
759 printf("\n!!! ERROR !!! name returned different from the one given : %s\n", client_name2
);
763 * verify if the real time mode returned by jack match the optional argument defined when launching jack_test*/
764 if (jack_is_realtime(client1
) == RT
)
765 Log("Jackd is in realtime mode (RT = %i).\n", RT
);
767 printf("!!! ERROR !!! Jackd is in a non-expected realtime mode (RT = %i).\n", RT
);
770 * Register all callbacks...
773 if (jack_set_thread_init_callback(client1
, Jack_Thread_Init_Callback
, 0) != 0)
774 printf("!!! ERROR !!! while calling jack_set_thread_init_callback()...\n");
775 if (jack_set_freewheel_callback(client1
, Jack_Freewheel_Callback
, 0) != 0 )
776 printf("\n!!! ERROR !!! while calling jack_set_freewheel_callback()...\n");
779 if (jack_set_process_callback(client1
, process1
, 0) != 0) {
780 printf("Error when calling jack_set_process_callback() !\n");
783 jack_on_shutdown(client1
, jack_shutdown
, 0);
785 if (jack_on_info_shutdown
)
786 jack_on_info_shutdown(client1
, jack_info_shutdown
, 0);
788 if (jack_set_buffer_size_callback(client1
, Jack_Update_Buffer_Size
, 0) != 0) {
789 printf("Error when calling buffer_size_callback !\n");
792 if (jack_set_graph_order_callback(client1
, Jack_Graph_Order_Callback
, 0) != 0) {
793 printf("Error when calling Jack_Graph_Order_Callback() !\n");
796 if (jack_set_port_rename_callback(client1
, Jack_Port_Rename_Callback
, 0) != 0 )
797 printf("\n!!! ERROR !!! while calling jack_set_rename_callback()...\n");
799 if (jack_set_xrun_callback(client1
, Jack_XRun_Callback
, 0 ) != 0) {
800 printf("Error when calling jack_set_xrun_callback() !\n");
803 if (jack_set_sample_rate_callback(client1
, Jack_Sample_Rate_Callback
, 0 ) != 0) {
804 printf("Error when calling Jack_Sample_Rate_Callback() !\n");
807 if (jack_set_port_registration_callback(client1
, Jack_Port_Register
, 0) != 0) {
808 printf("Error when calling jack_set_port_registration_callback() !\n");
811 if (jack_set_port_connect_callback(client1
, Jack_Port_Connect
, 0) != 0) {
812 printf("Error when calling jack_set_port_connect_callback() !\n");
815 if (jack_set_client_registration_callback(client1
, Jack_Client_Registration_Callback
, 0) != 0) {
816 printf("Error when calling jack_set_client_registration_callback() !\n");
819 jack_set_error_function(Jack_Error_Callback
);
822 * Create file for clock "frame time" analysis
825 cur_buffer_size
= jack_get_buffer_size(client1
);
826 sprintf (filename
, "framefile-%i.dat", cur_buffer_size
);
827 file
= fopen(filename
, "w");
829 fprintf(stderr
, "Erreur dans l'ouverture du fichier log framefile.dat");
834 * Try to register a client with a NULL name/zero length name...
837 output_port1
= jack_port_register(client1
, nullportname
,
838 JACK_DEFAULT_AUDIO_TYPE
,
839 JackPortIsOutput
, 0);
840 if (output_port1
== NULL
) {
841 Log("Can't register a port with a NULL portname... ok.\n");
843 printf("!!! ERROR !!! Can register a port with a NULL portname !\n");
844 jack_port_unregister(client1
, output_port1
);
848 * Register 1 port in order to stress other functions.
851 output_port1
= jack_port_register(client1
, portname
,
852 JACK_DEFAULT_AUDIO_TYPE
,
853 JackPortIsOutput
, 0);
854 if (output_port1
== NULL
) {
855 printf("!!! ERROR !!! Can't register any port for the client !\n");
860 * Test port type of the just registered port.
863 if (strcmp(jack_port_type(output_port1
), JACK_DEFAULT_AUDIO_TYPE
) != 0) {
864 printf("!!! ERROR !!! jack_port_type returns an incorrect value!\n");
866 Log("Checking jack_port_type()... ok.\n");
870 * Try to register another port with the same name...
873 output_port2
= jack_port_register(client1
, portname
,
874 JACK_DEFAULT_AUDIO_TYPE
,
875 JackPortIsOutput
, 0);
876 if (output_port2
== NULL
) {
877 Log("Can't register two ports with the same name... ok\n");
879 if (strcmp (jack_port_name(output_port1
), jack_port_name(output_port2
)) == 0) {
880 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
));
881 jack_port_unregister(client1
, output_port2
);
883 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
));
884 jack_port_unregister(client1
, output_port2
);
889 * Verify that both port_name and port_short_name return correct results...
892 sprintf (portname
, "%s:%s", jack_get_client_name(client1
), jack_port_short_name(output_port1
));
893 if (strcmp(jack_port_name(output_port1
), portname
) != 0) {
894 printf("!!! ERROR !!! functions jack_port_name and/or jack_short_port_name seems to be invalid !\n");
895 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
));
899 * Verify the function port_set_name
902 if (jack_port_set_name (output_port1
, "renamed-port#") == 0 ) {
903 if (strcmp(jack_port_name(output_port1
), "renamed-port#") == 0) {
904 printf("!!! ERROR !!! functions jack_port_set_name seems to be invalid !\n");
905 printf("jack_port_name return '%s' whereas 'renamed-port#' was expected...\n", jack_port_name(output_port1
));
907 Log("Checking jack_port_set_name()... ok\n");
908 jack_port_set_name (output_port1
, "port");
911 printf("error : port_set_name function can't be tested...\n");
914 port_callback_reg
= 0; // number of port registration received by the callback
917 * Activate the client
920 if (jack_activate(client1
) < 0) {
921 printf ("Fatal error : cannot activate client1\n");
926 * Test if portrename callback have been called.
929 jack_port_set_name (output_port1
, "renamed-port#");
930 jack_sleep(1 * 1000);
932 if (port_rename_clbk
== 0)
933 printf("!!! ERROR !!! Jack_Port_Rename_Callback was not called !!.\n");
937 * Test if portregistration callback have been called.
941 jack_sleep(1 * 1000);
943 if (1 == port_callback_reg
) {
944 Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", 1, port_callback_reg
);
946 printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", 1, port_callback_reg
);
950 * Test if init callback initThread have been called.
954 printf("!!! ERROR !!! Jack_Thread_Init_Callback was not called !!.\n");
956 jack_sleep(10 * 1000); // test see the clock in the graph at the begining...
959 * Stress Freewheel mode...
960 * Try to enter freewheel mode. Check the realtime mode de-activation.
961 * Check that the number of call of the process callback is greater than in non-freewheel mode.
962 * Give an approximated speed ratio (number of process call) between the two modes.
963 * Then return in normal mode.
967 jack_sleep(1 * 1000);
969 Log("Testing activation freewheel mode...\n");
970 linefw
= linecount
; // count for better graph reading with gnuplot
971 jack_set_freewheel(client1
, 1);
973 jack_sleep(1 * 1000);
975 if (jack_is_realtime(client1
) == 0) {
978 printf("\n!!! ERROR !!! RT mode is always activated while freewheel mode is applied !\n");
982 printf("!!! ERROR !!! Freewheel mode doesn't activate audio callback !!\n");
984 jack_set_freewheel(client1
, 0);
985 jack_sleep(7 * 1000);
987 if (jack_is_realtime(client1
) == 1) {}
989 printf("\n!!! ERROR !!! freewheel mode fail to reactivate RT mode when exiting !\n");
993 Log("Freewheel mode appears to work well...\n");
996 Log("Audio Callback in 'standard' (non-freewheel) mode seems not to be called...\n");
997 Log("Ratio speed would be unavailable...\n");
999 ratio
= (float) ((count2
- count1
) / count1
);
1000 Log("Approximative speed ratio of freewheel mode = %f : 1.00\n", ratio
);
1004 * Stress buffer function...
1005 * get current buffer size.
1006 * Try to apply a new buffer size value ( 2 x the precedent buffer size value)
1007 * Then return in previous buffer size mode.
1011 float factor
= 0.5f
;
1012 old_buffer_size
= jack_get_buffer_size(client1
);
1013 Log("Testing BufferSize change & Callback...\n--> Current buffer size : %d.\n", old_buffer_size
);
1014 linebuf
= linecount
;
1015 if (jack_set_buffer_size(client1
, (jack_nframes_t
)(old_buffer_size
* factor
)) < 0) {
1016 printf("!!! ERROR !!! jack_set_buffer_size fails !\n");
1018 jack_sleep(1 * 1000);
1019 cur_buffer_size
= jack_get_buffer_size(client1
);
1020 if (abs((old_buffer_size
* factor
) - cur_buffer_size
) > 5) { // Tolerance needed for dummy driver...
1021 printf("!!! ERROR !!! Buffer size has not been changed !\n");
1022 printf("!!! Maybe jack was compiled without the '--enable-resize' flag...\n");
1024 Log("jack_set_buffer_size() command successfully applied...\n");
1026 jack_sleep(3 * 1000);
1027 jack_set_buffer_size(client1
, old_buffer_size
);
1028 cur_buffer_size
= jack_get_buffer_size(client1
);
1031 * Test the last regestered port to see if port_is_mine function the right value.
1032 * A second test will be performed later.
1033 * The result will be printed at the end.
1036 if (jack_port_is_mine(client1
, output_port1
)) {
1043 * Check that the ID returned by the port_by_name is right.
1044 * (it seems there is a problem here in some jack versions).
1047 if (output_port1
!= jack_port_by_name(client1
, jack_port_name(output_port1
))) {
1048 printf("!!! ERROR !!! function jack_port_by_name() return bad value !\n");
1049 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
);
1051 Log("Checking jack_port_by_name() return value... ok\n");
1053 if (NULL
!= jack_port_by_name(client1
, jack_port_short_name(output_port1
))) {
1054 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
)));
1056 Log("Checking jack_port_by_name() with bad argument... ok (returned id 0)\n");
1060 * remove the output port previously created
1061 * no more ports should subsist here for our client.
1064 if (jack_port_unregister(client1
, output_port1
) != 0) {
1065 printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1
));
1072 inports
= jack_get_ports(client1
, NULL
, NULL
, 0);
1075 * Test the first PHY (physical) connection to see if it's "mine".
1076 * and report the result in the test that began before.
1077 * The result is printed later.
1080 if (jack_port_is_mine(client1
, jack_port_by_name(client1
, inports
[0]))) {
1085 * List all devices' flags and print them...
1088 Log("\nTry functions jack_get_ports, jack_port_flag & jack_port_by_name to list PHY devices...\n");
1089 Log("-----------------------------------------------------------\n");
1090 Log("---------------------------DEVICES-------------------------\n");
1091 Log("-----------------------------------------------------------\n");
1093 while (inports
[a
] != NULL
) {
1094 flag
= jack_port_flags(jack_port_by_name(client1
, inports
[a
]) );
1095 Log(" * %s (id : %i)\n", inports
[a
], jack_port_by_name(client1
, inports
[a
]));
1097 if (flag
& JackPortIsInput
)
1098 Log("JackPortIsInput ");
1099 if (flag
& JackPortIsOutput
)
1100 Log("JackPortIsOutput ");
1101 if (flag
& JackPortIsPhysical
)
1102 Log("JackPortIsPhysical ");
1103 if (flag
& JackPortCanMonitor
)
1104 Log("JackPortCanMonitor ");
1105 if (flag
& JackPortIsTerminal
)
1106 Log("JackPortIsTerminal ");
1110 Log("-----------------------------------------------------------\n\n");
1113 * list all PHY in/out ports...
1114 * This list will be used later many times.
1117 outports
= jack_get_ports(client1
, NULL
, NULL
, JackPortIsPhysical
| JackPortIsOutput
);
1118 inports
= jack_get_ports(client1
, NULL
, NULL
, JackPortIsPhysical
| JackPortIsInput
);
1120 if (outports
== NULL
) {
1121 printf("!!! WARNING !!! no physical capture ports founded !\n");
1123 if (inports
== NULL
) {
1124 printf("!!! WARNING !!! no physical output ports founded !\n");
1128 * Brute test : try to create as many ports as possible.
1129 * It stops when jack returns an error.
1130 * Then try to connect each port to physical entry...
1131 * Check also that graph reorder callback is called.
1134 Log("Registering as many ports as possible and connect them to physical entries...\n");
1135 lineports
= linecount
;
1138 i
= 0; // number of couple 'input-ouput'
1139 j
= 0; // number of ports created
1140 port_callback_reg
= 0; // number of port registration received by the callback
1141 reorder
= 0; // number of graph reorder callback activation
1142 test_link
= 0 ; // Test the "overconnect" function only one time
1143 while (t_error
== 0) {
1144 sprintf (portname
, "input_%d", i
);
1145 input_port1
= jack_port_register(client1
, portname
,
1146 JACK_DEFAULT_AUDIO_TYPE
,
1147 JackPortIsInput
, 0);
1149 if (input_port1
== NULL
) {
1153 // Connect created input to PHY output
1155 while (outports
[a
] != NULL
) {
1156 if (jack_connect(client1
, outports
[a
], jack_port_name(input_port1
))) {
1157 printf ("error : cannot connect input PHY port to client port %s\n", jack_port_name(input_port1
));
1159 // printf ("input PHY port %s connected to client port %s\n", outports[a], jack_port_name(input_port1));
1163 // Try one time to "overconnect" 2 ports (the latest created)...
1164 if (test_link
== 0) {
1165 if (jack_connect(client1
, outports
[a
- 1], jack_port_name(input_port1
)) == EEXIST
) {
1166 // cannot over-connect input PHY port to client port. ok.
1172 sprintf(portname
, "output_%d", i
);
1173 output_port1
= jack_port_register(client1
, portname
,
1174 JACK_DEFAULT_AUDIO_TYPE
,
1175 JackPortIsOutput
, 0);
1177 if (output_port1
== NULL
) {
1181 // Connect created input to PHY output
1183 while (inports
[a
] != NULL
) {
1184 if (jack_connect(client1
, jack_port_name(output_port1
), inports
[a
])) {
1185 printf ("error : cannot connect input PHY port %s to client port %s\n", inports
[a
], jack_port_name(output_port1
));
1187 // output PHY port %s connected to client port. ok.
1191 // Try one time to "overconnect" 2 ports (the latest created)...
1192 if (test_link
== 0) {
1193 if (jack_connect(client1
, jack_port_name(output_port1
), inports
[a
- 1]) == EEXIST
) {
1194 // cannot over-connect output PHY port to client port. ok.
1202 jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
1204 // Check port registration callback
1205 if (j
== port_callback_reg
) {
1206 Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j
, port_callback_reg
);
1208 printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j
, port_callback_reg
);
1211 if (reorder
== (2 * j
)) {
1212 Log("%i graph reorder callback have been received... ok\n", reorder
);
1214 printf("!!! ERROR !!! %i graph reorder callback have been received (maybe non-valid value)...\n", reorder
);
1217 * print basic test connection functions result ...
1218 * over-connected means here that we try to connect 2 ports that are already connected.
1222 Log("Jack links can't be 'over-connected'... ok\n");
1224 printf("!!! ERROR !!! Jack links can be 'over-connected'...\n");
1227 * Print the result of the two jack_is_mine test.
1231 Log("Checking jack_port_is_mine()... ok\n");
1233 printf("!!! ERROR !!! jack_port_is_mine() function seems to send non-valid datas !\n");
1236 * Free the array of the physical input and ouput ports.
1237 * (as mentionned in the doc of jack_get_ports)
1241 jack_free(outports
);
1244 * Try to "reactivate" the client whereas it's already activated...
1247 if (jack_activate(client1
) < 0) {
1248 printf("!!! ERROR !!! Cannot activate client1 a second time...\n");
1251 Log("jackd server accept client.jack_activate() re-activation (while client was already activated).\n");
1255 * Deregister all ports previously created.
1258 port_callback_reg
= 0; // to check registration callback
1259 Log("Deregistering all ports of the client...\n");
1260 inports
= jack_get_ports(client1
, NULL
, NULL
, 0);
1262 while (inports
[a
] != NULL
) {
1263 flag
= jack_port_flags(jack_port_by_name(client1
, inports
[a
]));
1264 input_port1
= jack_port_by_name(client1
, inports
[a
]);
1265 if (jack_port_is_mine(client1
, input_port1
)) {
1266 if (jack_port_unregister(client1
, input_port1
) != 0) {
1267 printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1
));
1273 // Check port registration callback again
1274 if (j
== port_callback_reg
) {
1275 Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j
, port_callback_reg
);
1277 printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j
, port_callback_reg
);
1280 jack_free(inports
); // free array of ports (as mentionned in the doc of jack_get_ports)
1283 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1284 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1285 Open a new client (second one) to test some other things...
1286 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1287 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1290 Log("\n\n----------------------------------------------------------------------\n");
1291 Log("Starting second new client 'jack_test_#2'...\n");
1292 /* open a client connection to the JACK server */
1293 client_name2
= "jack_test_#2";
1294 linecl2
= linecount
; // reminders for graph analysis
1295 client2
= jack_client_new(client_name2
);
1297 if (client2
== NULL
) {
1298 fprintf(stderr
, "jack_client_new() failed for %s.\n"
1299 "status = 0x%2.0x\n", client_name2
, status
);
1300 if (status
& JackServerFailed
) {
1301 fprintf(stderr
, "Unable to connect client2 to JACK server\n");
1306 // Check client registration callback
1308 if (client_register
== 0)
1309 printf("!!! ERROR !!! Client registration callback not called!\n");
1312 * Register callback for this client.
1313 * Callbacks are the same as the first client for most of them, excepted for process audio callback.
1316 jack_set_port_registration_callback(client2
, Jack_Port_Register
, 0);
1318 jack_set_process_callback(client2
, process2
, 0);
1320 jack_on_shutdown(client2
, jack_shutdown
, 0);
1323 * Register one input and one output for each client.
1326 Log("registering 1 input/output ports for each client...\n");
1328 output_port1
= jack_port_register(client1
, "out1",
1329 JACK_DEFAULT_AUDIO_TYPE
,
1330 JackPortIsOutput
, 0);
1331 output_port2
= jack_port_register(client2
, "out2",
1332 JACK_DEFAULT_AUDIO_TYPE
,
1333 JackPortIsOutput
, 0);
1334 input_port1
= jack_port_register(client1
, "in1",
1335 JACK_DEFAULT_AUDIO_TYPE
,
1336 JackPortIsInput
, 0);
1337 input_port2
= jack_port_register(client2
, "in2",
1338 JACK_DEFAULT_AUDIO_TYPE
,
1339 JackPortIsInput
, 0);
1340 if ((output_port1
== NULL
) || (output_port2
== NULL
) || (input_port1
== NULL
) || (input_port2
== NULL
)) {
1341 printf("!!! ERROR !!! Unable to register ports...\n");
1345 * Set each process mode to idle and activate client2
1348 process2_activated
= -1;
1349 process1_activated
= -1;
1350 if (jack_activate(client2
) < 0) {
1351 printf ("Fatal error : cannot activate client2\n");
1356 * Connect the two clients and check that all connections are well-done.
1359 Log("Testing connections functions between clients...\n");
1360 if (jack_connect(client1
, jack_port_name(output_port1
), jack_port_name(input_port2
)) != 0) {
1361 printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
1363 if (jack_connect(client2
, jack_port_name(output_port2
), jack_port_name(input_port1
)) != 0) {
1364 printf("!!! ERROR !!! while client2 intenting to connect ports...\n");
1366 if (jack_connect(client1
, jack_port_name(output_port1
), jack_port_name(input_port1
)) != 0) {
1367 printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
1371 * Test the port_connected function...
1374 if ((jack_port_connected(output_port1
) == jack_port_connected(input_port1
)) &&
1375 (jack_port_connected(output_port2
) == jack_port_connected(input_port2
)) &&
1376 (jack_port_connected(output_port2
) == 1) &&
1377 (jack_port_connected(output_port1
) == 2)
1379 Log("Checking jack_port_connected()... ok.\n");
1381 printf("!!! ERROR !!! function jack_port_connected() return a bad value !\n");
1382 printf("jack_port_connected(output_port1) %d\n", jack_port_connected(output_port1
));
1383 printf("jack_port_connected(output_port2) %d\n", jack_port_connected(output_port2
));
1384 printf("jack_port_connected(input_port1) %d\n", jack_port_connected(input_port1
));
1385 printf("jack_port_connected(input_port2) %d\n", jack_port_connected(input_port2
));
1389 * Test a new time the port_by_name function...(now we are in multi-client mode)
1392 Log("Testing again jack_port_by_name...\n");
1393 if (output_port1
!= jack_port_by_name(client1
, jack_port_name(output_port1
))) {
1394 printf("!!! ERROR !!! function jack_port_by_name() return bad value in a multi-client application!\n");
1395 printf("!!! jack_port_by_name(jack_port_name(_ID_) ) != _ID_ in multiclient application.\n");
1397 Log("Checking jack_port_by_name() function with a multi-client application... ok\n");
1401 * Test the port_connected_to function...
1404 if ((jack_port_connected_to (output_port1
, jack_port_name(input_port2
))) &&
1405 (!(jack_port_connected_to (output_port2
, jack_port_name(input_port2
))))) {
1406 Log("checking jack_port_connected_to()... ok\n");
1408 printf("!!! ERROR !!! jack_port_connected_to() return bad value !\n");
1412 * Test the port_get_connections & port_get_all_connections functions...
1415 Log("Testing jack_port_get_connections and jack_port_get_all_connections...\n");
1418 connexions1
= jack_port_get_connections (output_port1
);
1419 connexions2
= jack_port_get_all_connections(client1
, output_port1
);
1420 if ((connexions1
== NULL
) || (connexions2
== NULL
)) {
1421 printf("!!! ERROR !!! port_get_connexions or port_get_all_connexions return a NULL pointer !\n");
1423 while ((connexions1
[a
] != NULL
) && (connexions2
[a
] != NULL
) && (t_error
== 0)) {
1424 t_error
= strcmp(connexions1
[a
], connexions2
[a
]);
1429 Log("Checking jack_port_get_connections Vs jack_port_get_all_connections... ok\n");
1431 printf("!!! ERROR !!! while checking jack_port_get_connections Vs jack_port_get_all_connections...\n");
1436 inports
= jack_get_ports(client1
, NULL
, NULL
, JackPortIsPhysical
| JackPortIsInput
);
1438 assert(inports
!= NULL
);
1439 if (inports
[0] != NULL
) {
1440 connexions1
= jack_port_get_connections (jack_port_by_name(client1
, inports
[0]));
1441 connexions2
= jack_port_get_all_connections(client1
, jack_port_by_name(client1
, inports
[0]));
1444 jack_free (inports
);
1445 if (connexions1
== NULL
) {
1446 Log("checking jack_port_get_connections() for external client... ok\n");
1448 while ((connexions1
[a
] != NULL
) && (connexions2
[a
] != NULL
) && (t_error
== 0)) {
1449 t_error
= strcmp(connexions1
[a
], connexions2
[a
]);
1454 Log("Checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port... ok\n");
1456 printf("!!! ERROR !!! while checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port...\n");
1459 if (jack_disconnect(client1
, jack_port_name(output_port1
), jack_port_name(input_port1
)) != 0) {
1460 printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
1462 if (jack_disconnect(client1
, jack_port_name(output_port2
), jack_port_name(input_port1
)) != 0) {
1463 printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
1465 // No links should subsist now...
1468 * Checking data connexion
1469 * establishing a link between client1.out1 --> client2.in2
1470 * Send the signal1 test on out1. Record the result into signal2. (see process functions).
1471 ---------------------------------------------------------------------------*/
1472 Log("Testing connections datas between clients...\n");
1473 jack_connect(client2
, jack_port_name(output_port1
), jack_port_name(input_port2
) );
1474 process2_activated
= -1;
1475 process1_activated
= -1;
1476 Log("process 2 : idle mode...\n");
1477 Log("Sending datas...");
1480 process1_activated
= 1; // We start emitting first.
1481 process2_activated
= 1; // So record begin at least when we just begin to emitt the signal, else at next call of process with
1482 // nframe = jack buffersize shifting.
1484 while (process2_activated
== 1) {
1485 jack_sleep(1 * 1000);
1489 Log("\nAnalysing datas...\n"); // search the first occurence of the first element of the reference signal in the recorded signal
1490 while (signal2
[index2
] != signal1
[1] ) {
1492 if (index2
== 95999) {
1493 printf("!!! ERROR !!! Data not found in first connexion data check!\n");
1498 Log("Data founded at offset %i.\n", index2
);
1499 // And now we founded were the recorded data are, we can see if the two signals matches...
1500 while ( (signal2
[index2
] == signal1
[index2
- index1
+ 1]) || (index2
== 95999) || ((index2
- index1
+ 1) == 47999) ) {
1503 Log("Checking difference between datas... %i have the same value...\n", index2
- index1
);
1504 if ((index2
- index1
) == 48000) {
1505 Log("Data received are valid...\n");
1507 printf("!!! ERROR !!! data transmission seems not to be valid in first connexion data check!\n");
1509 if (jack_disconnect(client1
, jack_port_name(output_port1
), jack_port_name(input_port2
) ) != 0)
1510 // no more connection between ports exist now...
1512 printf("Error while establishing new connexion (disconnect).\n");
1517 * (This mode seems to be problematic in standard jack version 0.100. It seems that nobody
1518 * is used to apply this mode because the tie mode doesn't work at all. A patch seems difficult to produce
1519 * in this version of jack. Tie mode work well in MP version.)
1520 * Test some basic thinks (tie with 2 differents client, tie non-owned ports...)
1521 * Tie client1.in1 and client1.out1 ports, and make some data test to check the validity of the tie.
1524 Log("Testing tie mode...\n");
1525 if (jack_port_tie(input_port1
, output_port2
) != 0) {
1526 Log("not possible to tie two ports from two differents clients... ok\n");
1528 printf("!!! ERROR !!! port_tie has allowed a connexion between two differents clients !\n");
1529 jack_port_untie(output_port2
);
1531 Log("Testing connections datas in tie mode...\n");
1533 for (g
= 0; g
< 96000; g
++)
1535 // Create a loop (emit test) client2.out2----client.in1--tie--client1.out1-----client2.in1 (receive test)
1536 if (jack_port_tie(input_port1
, output_port1
) != 0) {
1537 printf("Unable to tie... fatal error : data test will not be performed on tie mode !!\n");
1538 } else { // begin of tie
1539 if (jack_connect(client1
, jack_port_name(output_port1
), jack_port_name(input_port2
)) != 0) {
1540 printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
1542 if (jack_connect(client1
, jack_port_name(output_port2
), jack_port_name(input_port1
)) != 0) {
1543 printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
1546 process1_activated
= -1;
1547 process2_activated
= -1;
1549 // We can manualy check here that the tie is effective.
1550 // ie : playing a wav with a client, connecting ports manualy with qjackctl, and listen...
1551 // printf("manual test\n");
1553 // printf("end of manual test\n");
1557 process1_activated
= -1;
1558 process2_activated
= 2;
1560 Log("Sending datas...");
1562 while (process2_activated
== 2) {
1563 jack_sleep(1 * 1000);
1566 process1_activated
= -1;
1567 process2_activated
= -1;
1569 Log("\nAnalysing datas...\n");
1570 // We must find at least 2 identical values to ensure we are at the right place in the siusoidal array...
1571 while (!((signal2
[index2
] == signal1
[1]) && (signal2
[index2
+ 1] == signal1
[2]))) {
1573 if (index2
== 95999) {
1574 printf("!!! ERROR !!! Data not found in connexion check of tie mode!\n");
1579 Log("Tie mode : Data founded at offset %i.\n", index2
);
1580 while (signal2
[index2
] == signal1
[index2
- index1
+ 1]) {
1582 if ((index2
== 95999) || ((index2
- index1
+ 1) == 47999)) {
1586 Log("Checking difference between datas... %i have the same value...\n", index2
- index1
);
1587 if ((index2
- index1
) > 47995) {
1588 Log("Data received in tie mode are valid...\n");
1590 // in tie mode, the buffers adress should be the same for the two tied ports.
1591 printf("!!! ERROR !!! data transmission seems not to be valid !\n");
1592 printf("Links topology : (emitt) client2.out2 ----> client1.in1--(tie)--client1.out1----->client2.in2 (recive)\n");
1593 printf(" port_name : Port_adress \n");
1594 printf(" output_port1 : %px\n", jack_port_get_buffer(output_port1
, cur_buffer_size
));
1595 printf(" input_port2 : %px\n", jack_port_get_buffer(input_port2
, cur_buffer_size
));
1596 printf(" output_port2 : %px\n", jack_port_get_buffer(output_port2
, cur_buffer_size
));
1597 printf(" input_port1 : %px\n", jack_port_get_buffer(input_port1
, cur_buffer_size
));
1600 jack_port_untie(output_port1
);
1601 jack_port_disconnect(client1
, output_port2
);
1602 jack_port_disconnect(client1
, output_port1
);
1608 * Testing SUMMATION CAPABILITIES OF JACK CONNECTIONS
1610 * In a short test, we just check a simple summation in jack.
1611 * A first client(client1) send two signal in phase opposition
1612 * A second client(client2) record the summation at one of his port
1613 * So, the result must be zero...
1614 * See process1 for details about steps of this test
1617 // fprintf(file, "Sum test\n");
1618 Log("Checking summation capabilities of patching...\n");
1619 output_port1b
= jack_port_register(client1
, "out1b",
1620 JACK_DEFAULT_AUDIO_TYPE
,
1621 JackPortIsOutput
, 0);
1622 jack_connect(client2
, jack_port_name(output_port1
), jack_port_name(input_port2
));
1623 jack_connect(client2
, jack_port_name(output_port1b
), jack_port_name(input_port2
));
1625 process1_activated
= 3;
1626 process2_activated
= -1;
1627 for (g
= 0; g
< 96000; g
++)
1632 Log("Sending datas...");
1633 process2_activated
= 3;
1635 while (process2_activated
== 3) {
1636 jack_sleep(1 * 1000);
1639 process1_activated
= -1;
1640 process2_activated
= -1;
1642 Log("\nAnalysing datas...\n"); // same idea as above, with first data check...
1643 while (!((signal2
[index2
] == 0.0 ) && (signal2
[(index2
+ 1)] == 0.0 ))) {
1645 if (index2
== 95999) {
1646 printf("!!! ERROR !!! Data not found in summation check!\n");
1651 Log("Data founded at offset %i.\n", index2
);
1653 while ( signal2
[index2
] == 0.0 ) {
1655 if ((index2
> 95998) || ((index2
- index1
+ 1) > 47998)) {
1659 Log("Checking difference between datas...\n");
1660 if ((index2
- index1
) > 47996) {
1661 Log("Data mixed received are valid...\nSummation is well done.\n");
1663 printf("!!! ERROR !!! data transmission / summation seems not to be valid !\n");
1665 jack_port_disconnect(client1
, output_port1
);
1666 jack_port_disconnect(client1
, output_port1b
);
1667 jack_port_unregister(client1
, output_port1b
);
1669 if (jack_port_name(output_port1b
) != NULL
) {
1670 printf("!!! WARNING !!! port_name return something while the port have been unregistered !\n");
1671 printf("!!! Name of unregistered port : %s !\n", jack_port_name(output_port1b
));
1673 Log("Checking jack_port_name() with a non valid port... ok\n");
1676 if (jack_port_set_name(output_port1b
, "new_name") == 0 ) {
1677 printf("!!! WARNING !!! An unregistered port can be renamed successfully !\n");
1679 Log("Checking renaming of an unregistered port... ok\n");
1681 inports
= jack_get_ports(client1
, NULL
, NULL
, JackPortIsPhysical
| JackPortIsInput
);
1682 if (jack_port_set_name(jack_port_by_name(client1
, inports
[0]), "new_name") == 0 ) {
1683 printf("!!! WARNING !!! A PHYSICAL port can be renamed successfully !\n");
1685 Log("Checking renaming of an unregistered port... ok\n");
1687 jack_free (inports
);
1691 * Checking latency issues
1692 * here are simple latency check
1693 * We simply check that the value returned by jack seems ok
1694 * Latency compensation is a difficult point.
1695 * Actually, jack is not able to see "thru" client to build a full latency chain.
1696 * Ardour use theses informations to do internally his compensations.
1698 * 3 test are done : one with no connections between client, one with a serial connection, and one with parallel connection
1700 Log("Checking about latency functions...\n");
1702 jack_recompute_total_latencies(client1
);
1703 Log("jack_recompute_total_latencies...\n");
1704 if ((jack_port_get_latency (output_port1
) != 0) ||
1705 (jack_port_get_total_latency(client1
, output_port1
) != 0) ) {
1707 printf("!!! ERROR !!! default latency of a non-PHY device is not set to zero !\n");
1710 inports
= jack_get_ports(client1
, NULL
, NULL
, JackPortIsPhysical
| JackPortIsInput
);
1711 outports
= jack_get_ports(client1
, NULL
, NULL
, JackPortIsPhysical
| JackPortIsOutput
);
1712 if (inports
[0] != NULL
) {
1713 output_ext_latency
= jack_port_get_latency (jack_port_by_name(client1
, inports
[0])); // from client to out driver (which has "inputs" ports..)
1714 input_ext_latency
= jack_port_get_latency (jack_port_by_name(client1
, outports
[0])); // from in driver (which has "output" ports..) to client
1715 if (output_ext_latency
!= jack_port_get_total_latency(client1
, jack_port_by_name(client1
, inports
[0]))) {
1717 printf("!!! ERROR !!! get_latency & get_all_latency for a PHY device (unconnected) didn't return the same value !\n");
1719 Log("Checking a serial model with 2 clients...\n");
1721 jack_connect(client1
, jack_port_name(output_port1
), jack_port_name(input_port2
));
1722 jack_connect(client1
, outports
[0], jack_port_name(input_port1
));
1723 jack_connect(client2
, jack_port_name(output_port2
), inports
[0]);
1724 jack_port_set_latency(output_port2
, 256);
1725 jack_recompute_total_latencies(client1
);
1727 if ((jack_port_get_latency (output_port1
) != 0) ||
1728 (jack_port_get_total_latency(client1
, output_port1
) != 0) ||
1729 (jack_port_get_latency (jack_port_by_name(client1
, inports
[0])) != (output_ext_latency
)) ||
1730 (jack_port_get_total_latency(client1
, jack_port_by_name(client1
, inports
[0])) != (output_ext_latency
+ 256)) ||
1731 (jack_port_get_total_latency(client1
, output_port2
) != (output_ext_latency
+ 256)) ||
1732 (jack_port_get_total_latency(client1
, input_port2
) != 0) ||
1733 (jack_port_get_total_latency(client1
, input_port1
) != input_ext_latency
) ||
1734 (jack_port_get_latency (jack_port_by_name(client1
, outports
[0])) != input_ext_latency
) ||
1735 (jack_port_get_total_latency(client1
, jack_port_by_name(client1
, outports
[0])) != input_ext_latency
)
1737 printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
1738 printf("!!! get_latency(output_port1) : %i (must be 0)\n", jack_port_get_latency(output_port1
));
1739 printf("!!! get_total_latency(output_port1) : %i (must be 0)\n", jack_port_get_total_latency(client1
, output_port1
));
1740 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
);
1741 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));
1742 printf("!!! get_total_latency(output_port2) : %i (must be %i)\n", jack_port_get_total_latency(client1
, output_port2
), (output_ext_latency
+ 256));
1743 printf("!!! get_total_latency(input_port2) : %i (must be 0)\n", jack_port_get_total_latency(client1
, input_port2
));
1744 printf("!!! get_total_latency(input_port1) : %i (must be %i)\n", jack_port_get_total_latency(client1
, input_port1
), input_ext_latency
);
1745 printf("!!! get_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_latency(jack_port_by_name(client1
, outports
[0])), input_ext_latency
);
1746 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
);
1749 Log("get_latency & get_total_latency seems quite ok...\n");
1752 jack_port_disconnect(client1
, output_port1
);
1753 jack_port_disconnect(client1
, output_port2
);
1754 jack_port_disconnect(client1
, input_port1
);
1755 jack_port_disconnect(client1
, input_port2
);
1756 Log("Checking a parallel model with 2 clients...\n");
1757 jack_connect(client2
, outports
[0], jack_port_name(input_port1
));
1758 jack_connect(client2
, outports
[0], jack_port_name(input_port2
));
1759 jack_connect(client2
, jack_port_name(output_port1
), inports
[0]);
1760 jack_connect(client2
, jack_port_name(output_port2
), inports
[0]);
1761 jack_port_set_latency(output_port1
, 256);
1762 jack_port_set_latency(output_port2
, 512);
1763 jack_recompute_total_latencies(client1
);
1765 if ((jack_port_get_latency(output_port1
) != 256 ) ||
1766 (jack_port_get_total_latency(client1
, output_port1
) != (256 + output_ext_latency
)) ||
1767 (jack_port_get_latency(output_port2
) != 512) ||
1768 (jack_port_get_total_latency(client1
, output_port2
) != (512 + output_ext_latency
)) ||
1769 (jack_port_get_latency(jack_port_by_name(client1
, inports
[0])) != output_ext_latency
) ||
1770 (jack_port_get_total_latency(client1
, jack_port_by_name(client1
, inports
[0])) != (512 + output_ext_latency
))
1772 printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
1773 printf("!!! get_latency(output_port1) : %i (must be 256)\n", jack_port_get_latency(output_port1
));
1774 printf("!!! get_total_latency(output_port1) : %i (must be 256 + output_ext_latency)\n", jack_port_get_total_latency(client1
, output_port1
));
1775 printf("!!! get_latency(output_port2) : %i (must 512)\n", jack_port_get_latency(output_port2
));
1776 printf("!!! get_total_latency(output_port2) : %i (must 512 + output_ext_latency)\n", jack_port_get_total_latency(client1
, output_port2
));
1777 printf("!!! get_latency(inports[0])) : %i (must output_ext_latency)\n", jack_port_get_latency(jack_port_by_name(client1
, inports
[0])));
1778 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])));
1780 Log("get_latency & get_total_latency seems quite ok...\n");
1783 printf("No physical port founded : not able to test latency functions...");
1786 jack_port_disconnect(client1
, input_port1
);
1787 jack_port_disconnect(client1
, input_port2
);
1788 jack_port_disconnect(client1
, output_port1
);
1789 jack_port_disconnect(client1
, output_port2
);
1794 jack_free(outports
);
1797 * Checking transport API.
1798 * Simple transport test.
1799 * Check a transport start with a "slow" client, simulating a delay around 1 sec before becoming ready.
1802 Log("-----------------------------------------------------------\n");
1803 Log("---------------------------TRANSPORT-----------------------\n");
1804 Log("-----------------------------------------------------------\n");
1806 lineports
= linecount
;
1808 if (transport_mode
) {
1810 ts
= jack_transport_query(client1
, &pos
);
1811 if (ts
== JackTransportStopped
) {
1812 Log("Transport is stopped...\n");
1814 jack_transport_stop(client1
);
1815 Log("Transport state : %i\n", ts
);
1817 if (jack_set_sync_callback(client2
, Jack_Sync_Callback
, 0) != 0)
1818 printf("error while calling set_sync_callback...\n");
1820 Log("starting transport...\n");
1822 starting_state
= 1; // Simulate starting state
1823 jack_transport_start(client1
);
1825 // Wait until sync callback is called
1826 while (!(sync_called
)) {
1827 jack_sleep(1 * 1000);
1830 // Wait untill rolling : simulate sync time out
1831 Log("Simulate a slow-sync client exceeding the time-out\n");
1835 jack_sleep(100); // Wait 100 ms each cycle
1837 if (wait_count
== 100) {
1838 Log("!!! ERROR !!! max time-out exceedeed : sync time-out does not work correctly\n");
1841 ts
= jack_transport_query(client2
, &pos
);
1842 Log("Waiting....pos = %ld\n", pos
.frame
);
1843 display_transport_state();
1845 } while (ts
!= JackTransportRolling
);
1847 Log("Sync callback have been called %i times.\n", sync_called
);
1848 jack_transport_stop(client1
);
1850 // Wait until stopped
1851 ts
= jack_transport_query(client2
, &pos
);
1852 while (ts
!= JackTransportStopped
) {
1853 jack_sleep(1 * 1000);
1854 ts
= jack_transport_query(client2
, &pos
);
1857 // Simulate starting a slow-sync client that rolls after 0.5 sec
1858 Log("Simulate a slow-sync client that needs 0.5 sec to start\n");
1861 starting_state
= 1; // Simulate starting state
1863 Log("Starting transport...\n");
1864 jack_transport_start(client1
);
1865 display_transport_state();
1867 Log("Waiting 0.5 sec...\n");
1869 starting_state
= 0; // Simulate end of starting state after 0.5 sec
1871 // Wait untill rolling
1872 ts
= jack_transport_query(client2
, &pos
);
1873 while (ts
!= JackTransportRolling
) {
1874 jack_sleep(100); // Wait 100 ms each cycle
1876 if (wait_count
== 10) {
1877 Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
1880 ts
= jack_transport_query(client2
, &pos
);
1883 if (sync_called
== 0)
1884 Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
1886 Log("Sync callback have been called %i times.\n", sync_called
);
1887 display_transport_state();
1889 // Test jack_transport_locate while rolling
1890 Log("Test jack_transport_locate while rolling\n");
1891 ts
= jack_transport_query(client2
, &pos
);
1892 Log("Transport current frame = %ld\n", pos
.frame
);
1893 jack_nframes_t cur_frame
= pos
.frame
;
1897 display_transport_state();
1898 jack_sleep(10); // 10 ms
1899 // locate at first...
1901 if (wait_count
== 1) {
1902 Log("Do jack_transport_locate\n");
1903 jack_transport_locate(client1
, cur_frame
/ 2);
1904 } else if (wait_count
== 100) {
1907 ts
= jack_transport_query(client2
, &pos
);
1908 Log("Locating.... frame = %ld\n", pos
.frame
);
1909 } while (pos
.frame
> cur_frame
);
1911 ts
= jack_transport_query(client2
, &pos
);
1912 Log("Transport current frame = %ld\n", pos
.frame
);
1913 if (wait_count
== 100) {
1914 printf("!!! ERROR !!! jack_transport_locate does not work correctly\n");
1917 // Test jack_transport_reposition while rolling
1918 Log("Test jack_transport_reposition while rolling\n");
1919 ts
= jack_transport_query(client2
, &pos
);
1920 Log("Transport current frame = %ld\n", pos
.frame
);
1921 cur_frame
= pos
.frame
;
1925 display_transport_state();
1926 jack_sleep(10); // 10 ms
1927 // locate at first...
1929 if (wait_count
== 1) {
1930 Log("Do jack_transport_reposition\n");
1931 request_pos
.frame
= cur_frame
/ 2;
1932 jack_transport_reposition(client1
, &request_pos
);
1933 } else if (wait_count
== 100) {
1936 ts
= jack_transport_query(client2
, &pos
);
1937 Log("Locating.... frame = %ld\n", pos
.frame
);
1938 } while (pos
.frame
> cur_frame
);
1940 ts
= jack_transport_query(client2
, &pos
);
1941 Log("Transport current frame = %ld\n", pos
.frame
);
1942 if (wait_count
== 100) {
1943 printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
1946 // Test jack_transport_reposition while stopped
1947 jack_transport_stop(client1
);
1948 ts
= jack_transport_query(client2
, &pos
);
1949 Log("Transport current frame = %ld\n", pos
.frame
);
1951 Log("Test jack_transport_reposition while stopped\n");
1953 request_pos
.frame
= 10000;
1954 jack_transport_reposition(client1
, &request_pos
);
1957 display_transport_state();
1958 jack_sleep(100); // 100 ms
1959 if (wait_count
++ == 10)
1961 ts
= jack_transport_query(client2
, &pos
);
1962 Log("Locating.... frame = %ld\n", pos
.frame
);
1963 } while (pos
.frame
!= 10000);
1965 ts
= jack_transport_query(client2
, &pos
);
1966 Log("Transport current frame = %ld\n", pos
.frame
);
1967 if (pos
.frame
!= 10000) {
1968 printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
1971 jack_transport_stop(client1
);
1973 /* Tell the JACK server that we are ready to roll. Our
1974 * process() callback will start running now. */
1977 printf("Transport check is disabled...\n");
1980 time_before_exit
= time_to_run
;
1981 while (time_before_exit
!= 0) {
1982 jack_sleep (1 * 1000);
1986 if (jack_deactivate(client2
) != 0) {
1987 printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
1989 if (jack_deactivate(client1
) != 0) {
1990 printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
1994 * Checking jack_frame_time.
1996 Log("Testing jack_frame_time...\n");
1997 jack_set_process_callback(client1
, process4
, client1
);
1998 jack_activate(client1
);
1999 jack_sleep(2 * 1000);
2002 * Checking jack_get_cycle_times.
2004 Log("Testing jack_get_cycle_times...\n");
2005 jack_deactivate(client1
);
2006 jack_set_process_callback(client1
, process5
, client1
);
2007 jack_activate(client1
);
2008 jack_sleep(3 * 1000);
2012 * Checking alternate thread model
2014 Log("Testing alternate thread model...\n");
2015 jack_deactivate(client1
);
2016 jack_set_process_callback(client1
, NULL
, NULL
); // remove callback
2017 jack_set_process_thread(client1
, jack_thread
, client1
);
2018 jack_activate(client1
);
2019 jack_sleep(2 * 1000);
2022 * Checking callback exiting : when the return code is != 0, the client is desactivated.
2024 Log("Testing callback exiting...\n");
2025 jack_deactivate(client1
);
2026 jack_set_process_thread(client1
, NULL
, NULL
); // remove thread callback
2027 jack_set_process_callback(client1
, process3
, 0);
2028 jack_activate(client1
);
2029 jack_sleep(3 * 1000);
2032 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2033 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2034 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2036 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2037 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2038 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2041 if (jack_deactivate(client2
) != 0) {
2042 printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
2044 if (jack_deactivate(client1
) != 0) {
2045 printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
2047 if (jack_client_close(client2
) != 0) {
2048 printf("!!! ERROR !!! jack_client_close does not return 0 for client2 !\n");
2050 if (jack_client_close(client1
) != 0) {
2051 printf("!!! ERROR !!! jack_client_close does not return 0 for client1 !\n");
2055 Log("No Xrun have been detected during this test... cool !\n");
2057 printf("%i Xrun have been detected during this session (seen callback messages to see where are the problems).\n", xrun
);
2062 Log("Exiting jack_test...\n");
2064 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
2065 sprintf (filename
, "framegraph-%i.gnu", cur_buffer_size
);
2066 file
= fopen(filename
, "w");
2068 fprintf(stderr
, "Erreur dans l'ouverture du fichier");
2071 fprintf(file
, "reset\n");
2072 fprintf(file
, "set terminal png transparent nocrop enhanced\n");
2073 fprintf(file
, "set output 'framegraph-%i-1.png'\n", cur_buffer_size
);
2074 fprintf(file
, "set title \"Frame time evolution during jack_test run\"\n");
2075 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));
2076 fprintf(file
, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount
- 1);
2077 fprintf(file
, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
2078 fprintf(file
, "set xlabel \"FrameTime\"\n");
2079 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
);
2080 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
);
2082 fprintf(file
, "set output 'framegraph-%i-2.png'\n", cur_buffer_size
);
2083 fprintf(file
, "set title \"Frame time evolution during jack_test run\"\n");
2084 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)));
2085 fprintf(file
, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount
- 1);
2086 fprintf(file
, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
2087 fprintf(file
, "set xlabel \"FrameTime\"\n");
2088 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
);
2089 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
);