jack1 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

699 lines
21KB

  1. /*
  2. NetJack Client
  3. Copyright (C) 2008 Marc-Olivier Barre <marco@marcochapeau.org>
  4. Copyright (C) 2008 Pieter Palmers <pieterpalmers@users.sourceforge.net>
  5. Copyright (C) 2006 Torben Hohn <torbenh@gmx.de>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. 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.
  17. */
  18. /** @file netsource.c
  19. *
  20. * @brief This client connects a remote slave JACK to a local JACK server assumed to be the master
  21. */
  22. #include "config.h"
  23. #include <stdio.h>
  24. #include <errno.h>
  25. #include <unistd.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <netinet/in.h>
  29. #include <netdb.h>
  30. /* These two required by FreeBSD. */
  31. #include <sys/types.h>
  32. #include <sys/socket.h>
  33. #if HAVE_ALLOCA_H
  34. #include <alloca.h>
  35. #endif
  36. #include <jack/jack.h>
  37. #include <net_driver.h>
  38. #include <netjack_packet.h>
  39. #if HAVE_SAMPLERATE
  40. #include <samplerate.h>
  41. #endif
  42. #if HAVE_CELT
  43. #include <celt/celt.h>
  44. #endif
  45. #include <math.h>
  46. JSList *capture_ports = NULL;
  47. JSList *capture_srcs = NULL;
  48. int capture_channels = 0;
  49. int capture_channels_audio = 2;
  50. int capture_channels_midi = 1;
  51. JSList *playback_ports = NULL;
  52. JSList *playback_srcs = NULL;
  53. int playback_channels = 0;
  54. int playback_channels_audio = 2;
  55. int playback_channels_midi = 1;
  56. int dont_htonl_floats = 0;
  57. int latency = 5;
  58. jack_nframes_t factor = 1;
  59. int bitdepth = 0;
  60. int mtu = 1400;
  61. int reply_port = 0;
  62. int redundancy = 1;
  63. jack_client_t *client;
  64. int state_connected = 0;
  65. int state_latency = 0;
  66. int state_netxruns = 0;
  67. int state_currentframe = 0;
  68. int state_recv_packet_queue_time = 0;
  69. int outsockfd;
  70. int insockfd;
  71. struct sockaddr destaddr;
  72. struct sockaddr bindaddr;
  73. int sync_state;
  74. jack_transport_state_t last_transport_state;
  75. int framecnt = 0;
  76. int cont_miss = 0;
  77. /**
  78. * This Function allocates all the I/O Ports which are added the lists.
  79. */
  80. void
  81. alloc_ports (int n_capture_audio, int n_playback_audio, int n_capture_midi, int n_playback_midi)
  82. {
  83. int port_flags = JackPortIsOutput;
  84. int chn;
  85. jack_port_t *port;
  86. char buf[32];
  87. capture_ports = NULL;
  88. /* Allocate audio capture channels */
  89. for (chn = 0; chn < n_capture_audio; chn++)
  90. {
  91. snprintf (buf, sizeof (buf) - 1, "capture_%u", chn + 1);
  92. port = jack_port_register (client, buf, JACK_DEFAULT_AUDIO_TYPE, port_flags, 0);
  93. if (!port)
  94. {
  95. printf( "jack_netsource: cannot register %s port\n", buf);
  96. break;
  97. }
  98. if( bitdepth == 1000 ) {
  99. #if HAVE_CELT
  100. // XXX: memory leak
  101. CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate( client ), 1, jack_get_buffer_size(client), NULL );
  102. capture_srcs = jack_slist_append(capture_srcs, celt_decoder_create( celt_mode ) );
  103. #endif
  104. } else {
  105. #if HAVE_SAMPLERATE
  106. capture_srcs = jack_slist_append (capture_srcs, src_new (SRC_LINEAR, 1, NULL));
  107. #endif
  108. }
  109. capture_ports = jack_slist_append (capture_ports, port);
  110. }
  111. /* Allocate midi capture channels */
  112. for (chn = n_capture_audio; chn < n_capture_midi + n_capture_audio; chn++)
  113. {
  114. snprintf (buf, sizeof (buf) - 1, "capture_%u", chn + 1);
  115. port = jack_port_register (client, buf, JACK_DEFAULT_MIDI_TYPE, port_flags, 0);
  116. if (!port)
  117. {
  118. printf ("jack_netsource: cannot register %s port\n", buf);
  119. break;
  120. }
  121. capture_ports = jack_slist_append(capture_ports, port);
  122. }
  123. /* Allocate audio playback channels */
  124. port_flags = JackPortIsInput;
  125. playback_ports = NULL;
  126. for (chn = 0; chn < n_playback_audio; chn++)
  127. {
  128. snprintf (buf, sizeof (buf) - 1, "playback_%u", chn + 1);
  129. port = jack_port_register (client, buf, JACK_DEFAULT_AUDIO_TYPE, port_flags, 0);
  130. if (!port)
  131. {
  132. printf ("jack_netsource: cannot register %s port\n", buf);
  133. break;
  134. }
  135. if( bitdepth == 1000 ) {
  136. #if HAVE_CELT
  137. // XXX: memory leak
  138. CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate (client), 1, jack_get_buffer_size(client), NULL );
  139. playback_srcs = jack_slist_append(playback_srcs, celt_encoder_create( celt_mode ) );
  140. #endif
  141. } else {
  142. #if HAVE_SAMPLERATE
  143. playback_srcs = jack_slist_append (playback_srcs, src_new (SRC_LINEAR, 1, NULL));
  144. #endif
  145. }
  146. playback_ports = jack_slist_append (playback_ports, port);
  147. }
  148. /* Allocate midi playback channels */
  149. for (chn = n_playback_audio; chn < n_playback_midi + n_playback_audio; chn++)
  150. {
  151. snprintf (buf, sizeof (buf) - 1, "playback_%u", chn + 1);
  152. port = jack_port_register (client, buf, JACK_DEFAULT_MIDI_TYPE, port_flags, 0);
  153. if (!port)
  154. {
  155. printf ("jack_netsource: cannot register %s port\n", buf);
  156. break;
  157. }
  158. playback_ports = jack_slist_append (playback_ports, port);
  159. }
  160. }
  161. /**
  162. * The Sync callback... sync state is set elsewhere...
  163. * we will see if this is working correctly.
  164. * i dont really believe in it yet.
  165. */
  166. int
  167. sync_cb (jack_transport_state_t state, jack_position_t *pos, void *arg)
  168. {
  169. static int latency_count = 0;
  170. int retval = sync_state;
  171. if (latency_count) {
  172. latency_count--;
  173. retval = 0;
  174. }
  175. else if (state == JackTransportStarting && last_transport_state != JackTransportStarting)
  176. {
  177. retval = 0;
  178. latency_count = latency - 1;
  179. }
  180. last_transport_state = state;
  181. return retval;
  182. }
  183. int deadline_goodness=0;
  184. /**
  185. * The process callback for this JACK application.
  186. * It is called by JACK at the appropriate times.
  187. */
  188. int
  189. process (jack_nframes_t nframes, void *arg)
  190. {
  191. jack_nframes_t net_period;
  192. int rx_bufsize, tx_bufsize;
  193. jack_default_audio_sample_t *buf;
  194. jack_port_t *port;
  195. JSList *node;
  196. channel_t chn;
  197. int size, i;
  198. const char *porttype;
  199. int input_fd;
  200. jack_position_t local_trans_pos;
  201. uint32_t *packet_buf, *packet_bufX;
  202. jack_time_t packet_recv_timestamp;
  203. if( bitdepth == 1000 )
  204. net_period = factor;
  205. else
  206. net_period = (float) nframes / (float) factor;
  207. rx_bufsize = get_sample_size (bitdepth) * capture_channels * net_period + sizeof (jacknet_packet_header);
  208. tx_bufsize = get_sample_size (bitdepth) * playback_channels * net_period + sizeof (jacknet_packet_header);
  209. /* Allocate a buffer where both In and Out Buffer will fit */
  210. packet_buf = alloca ((rx_bufsize > tx_bufsize) ? rx_bufsize : tx_bufsize);
  211. jacknet_packet_header *pkthdr = (jacknet_packet_header *) packet_buf;
  212. /*
  213. * for latency==0 we need to send out the packet before we wait on the reply.
  214. * but this introduces a cycle of latency, when netsource is connected to itself.
  215. * so we send out before read only in zero latency mode.
  216. *
  217. */
  218. if( latency == 0 ) {
  219. /* reset packet_bufX... */
  220. packet_bufX = packet_buf + sizeof (jacknet_packet_header) / sizeof (jack_default_audio_sample_t);
  221. /* ---------- Send ---------- */
  222. render_jack_ports_to_payload (bitdepth, playback_ports, playback_srcs, nframes,
  223. packet_bufX, net_period, dont_htonl_floats);
  224. /* fill in packet hdr */
  225. pkthdr->transport_state = jack_transport_query (client, &local_trans_pos);
  226. pkthdr->transport_frame = local_trans_pos.frame;
  227. pkthdr->framecnt = framecnt;
  228. pkthdr->latency = latency;
  229. pkthdr->reply_port = reply_port;
  230. pkthdr->sample_rate = jack_get_sample_rate (client);
  231. pkthdr->period_size = nframes;
  232. /* playback for us is capture on the other side */
  233. pkthdr->capture_channels_audio = playback_channels_audio;
  234. pkthdr->playback_channels_audio = capture_channels_audio;
  235. pkthdr->capture_channels_midi = playback_channels_midi;
  236. pkthdr->playback_channels_midi = capture_channels_midi;
  237. pkthdr->mtu = mtu;
  238. pkthdr->sync_state = (jack_nframes_t)deadline_goodness;
  239. //printf("goodness=%d\n", deadline_goodness );
  240. packet_header_hton (pkthdr);
  241. if (cont_miss < 3*latency+5) {
  242. int r;
  243. for( r=0; r<redundancy; r++ )
  244. netjack_sendto (outsockfd, (char *) packet_buf, tx_bufsize, 0, &destaddr, sizeof (destaddr), mtu);
  245. }
  246. else if (cont_miss > 50+5*latency)
  247. {
  248. state_connected = 0;
  249. packet_cache_reset_master_address( global_packcache );
  250. //printf ("Frame %d \tRealy too many packets missed (%d). Let's reset the counter\n", framecnt, cont_miss);
  251. cont_miss = 0;
  252. }
  253. }
  254. /*
  255. * ok... now the RECEIVE code.
  256. *
  257. */
  258. /* reset packet_bufX... */
  259. packet_bufX = packet_buf + sizeof (jacknet_packet_header) / sizeof (jack_default_audio_sample_t);
  260. if( reply_port )
  261. input_fd = insockfd;
  262. else
  263. input_fd = outsockfd;
  264. // for latency == 0 we can poll.
  265. if( latency == 0 ) {
  266. jack_time_t deadline = jack_get_time() + 1000000 * jack_get_buffer_size(client)/jack_get_sample_rate(client);
  267. // Now loop until we get the right packet.
  268. while(1) {
  269. if ( ! netjack_poll_deadline( input_fd, deadline ) )
  270. break;
  271. packet_cache_drain_socket(global_packcache, input_fd);
  272. if (packet_cache_get_next_available_framecnt( global_packcache, framecnt - latency, NULL ))
  273. break;
  274. }
  275. } else {
  276. // normally:
  277. // only drain socket.
  278. packet_cache_drain_socket(global_packcache, input_fd);
  279. }
  280. size = packet_cache_retreive_packet( global_packcache, framecnt - latency, (char *)packet_buf, rx_bufsize, &packet_recv_timestamp );
  281. /* First alternative : we received what we expected. Render the data
  282. * to the JACK ports so it can be played. */
  283. if (size == rx_bufsize)
  284. {
  285. // calculate how much time there would have been, if this packet was sent at the deadline.
  286. int recv_time_offset = (int) (jack_get_time() - packet_recv_timestamp);
  287. packet_header_ntoh (pkthdr);
  288. deadline_goodness = recv_time_offset - (int)pkthdr->latency;
  289. //printf( "deadline goodness = %d ---> off: %d\n", deadline_goodness, recv_time_offset );
  290. if (cont_miss)
  291. {
  292. //printf("Frame %d \tRecovered from dropouts\n", framecnt);
  293. cont_miss = 0;
  294. }
  295. render_payload_to_jack_ports (bitdepth, packet_bufX, net_period,
  296. capture_ports, capture_srcs, nframes, dont_htonl_floats);
  297. state_currentframe = framecnt;
  298. state_recv_packet_queue_time = recv_time_offset;
  299. state_connected = 1;
  300. sync_state = pkthdr->sync_state;
  301. }
  302. /* Second alternative : we've received something that's not
  303. * as big as expected or we missed a packet. We render silence
  304. * to the ouput ports */
  305. else
  306. {
  307. jack_nframes_t latency_estimate;
  308. if( packet_cache_find_latency( global_packcache, framecnt, &latency_estimate ) )
  309. //if( (state_latency == 0) || (latency_estimate < state_latency) )
  310. state_latency = latency_estimate;
  311. // Set the counters up.
  312. state_currentframe = framecnt;
  313. //state_latency = framecnt - pkthdr->framecnt;
  314. state_netxruns += 1;
  315. //printf ("Frame %d \tPacket missed or incomplete (expected: %d bytes, got: %d bytes)\n", framecnt, rx_bufsize, size);
  316. //printf ("Frame %d \tPacket missed or incomplete\n", framecnt);
  317. cont_miss += 1;
  318. chn = 0;
  319. node = capture_ports;
  320. while (node != NULL)
  321. {
  322. port = (jack_port_t *) node->data;
  323. buf = jack_port_get_buffer (port, nframes);
  324. porttype = jack_port_type (port);
  325. if (strncmp (porttype, JACK_DEFAULT_AUDIO_TYPE, jack_port_type_size ()) == 0)
  326. for (i = 0; i < nframes; i++)
  327. buf[i] = 0.0;
  328. else if (strncmp (porttype, JACK_DEFAULT_MIDI_TYPE, jack_port_type_size ()) == 0)
  329. jack_midi_clear_buffer (buf);
  330. node = jack_slist_next (node);
  331. chn++;
  332. }
  333. }
  334. if( latency != 0 ) {
  335. /* reset packet_bufX... */
  336. packet_bufX = packet_buf + sizeof (jacknet_packet_header) / sizeof (jack_default_audio_sample_t);
  337. /* ---------- Send ---------- */
  338. render_jack_ports_to_payload (bitdepth, playback_ports, playback_srcs, nframes,
  339. packet_bufX, net_period, dont_htonl_floats);
  340. /* fill in packet hdr */
  341. pkthdr->transport_state = jack_transport_query (client, &local_trans_pos);
  342. pkthdr->transport_frame = local_trans_pos.frame;
  343. pkthdr->framecnt = framecnt;
  344. pkthdr->latency = latency;
  345. pkthdr->reply_port = reply_port;
  346. pkthdr->sample_rate = jack_get_sample_rate (client);
  347. pkthdr->period_size = nframes;
  348. /* playback for us is capture on the other side */
  349. pkthdr->capture_channels_audio = playback_channels_audio;
  350. pkthdr->playback_channels_audio = capture_channels_audio;
  351. pkthdr->capture_channels_midi = playback_channels_midi;
  352. pkthdr->playback_channels_midi = capture_channels_midi;
  353. pkthdr->mtu = mtu;
  354. pkthdr->sync_state = (jack_nframes_t)deadline_goodness;
  355. //printf("goodness=%d\n", deadline_goodness );
  356. packet_header_hton (pkthdr);
  357. if (cont_miss < 3*latency+5) {
  358. int r;
  359. for( r=0; r<redundancy; r++ )
  360. netjack_sendto (outsockfd, (char *) packet_buf, tx_bufsize, 0, &destaddr, sizeof (destaddr), mtu);
  361. }
  362. else if (cont_miss > 50+5*latency)
  363. {
  364. state_connected = 0;
  365. packet_cache_reset_master_address( global_packcache );
  366. //printf ("Frame %d \tRealy too many packets missed (%d). Let's reset the counter\n", framecnt, cont_miss);
  367. cont_miss = 0;
  368. }
  369. }
  370. framecnt++;
  371. return 0;
  372. }
  373. /**
  374. * This is the shutdown callback for this JACK application.
  375. * It is called by JACK if the server ever shuts down or
  376. * decides to disconnect the client.
  377. */
  378. void
  379. jack_shutdown (void *arg)
  380. {
  381. exit (1);
  382. }
  383. void
  384. init_sockaddr_in (struct sockaddr_in *name , const char *hostname , uint16_t port)
  385. {
  386. name->sin_family = AF_INET ;
  387. name->sin_port = htons (port);
  388. if (hostname)
  389. {
  390. struct hostent *hostinfo = gethostbyname (hostname);
  391. if (hostinfo == NULL) {
  392. fprintf (stderr, "init_sockaddr_in: unknown host: %s.\n", hostname);
  393. fflush( stderr );
  394. }
  395. name->sin_addr = *(struct in_addr *) hostinfo->h_addr ;
  396. }
  397. else
  398. name->sin_addr.s_addr = htonl (INADDR_ANY) ;
  399. }
  400. void
  401. printUsage ()
  402. {
  403. fprintf (stderr, "usage: jack_netsource -h <host peer> [options]\n"
  404. "\n"
  405. " -n <jack name> - Reports a different name to jack\n"
  406. " -s <server name> - The name of the local jack server\n"
  407. " -h <host_peer> - Host name of the slave JACK\n"
  408. " -p <port> - UDP port used by the slave JACK\n"
  409. " -P <num channels> - Number of audio playback channels\n"
  410. " -C <num channels> - Number of audio capture channels\n"
  411. " -o <num channels> - Number of midi playback channels\n"
  412. " -i <num channels> - Number of midi capture channels\n"
  413. " -l <latency> - Network latency in number of NetJack frames\n"
  414. " -r <reply port> - Local UDP port to use\n"
  415. " -f <downsample ratio> - Downsample data in the wire by this factor\n"
  416. " -b <bitdepth> - Set transport to use 16bit or 8bit\n"
  417. " -m <mtu> - Assume this mtu for the link\n"
  418. " -c <bytes> - Use Celt and encode <bytes> per channel and packet.\n"
  419. " -R <N> - Send out packets N times.\n"
  420. "\n");
  421. }
  422. int
  423. main (int argc, char *argv[])
  424. {
  425. /* Some startup related basics */
  426. char *client_name, *server_name = NULL, *peer_ip;
  427. int peer_port = 3000;
  428. jack_options_t options = JackNullOption;
  429. jack_status_t status;
  430. /* Torben's famous state variables, aka "the reporting API" ! */
  431. /* heh ? these are only the copies of them ;) */
  432. int statecopy_connected, statecopy_latency, statecopy_netxruns;
  433. jack_nframes_t net_period;
  434. /* Argument parsing stuff */
  435. extern char *optarg;
  436. extern int optind, optopt;
  437. int errflg=0, c;
  438. if (argc < 3)
  439. {
  440. printUsage ();
  441. return 1;
  442. }
  443. client_name = (char *) malloc (sizeof (char) * 10);
  444. peer_ip = (char *) malloc (sizeof (char) * 10);
  445. sprintf(client_name, "netsource");
  446. sprintf(peer_ip, "localhost");
  447. while ((c = getopt (argc, argv, ":H:R:n:s:h:p:C:P:i:o:l:r:f:b:m:c:")) != -1)
  448. {
  449. switch (c)
  450. {
  451. case 'n':
  452. free(client_name);
  453. client_name = (char *) malloc (sizeof (char) * strlen (optarg)+1);
  454. strcpy (client_name, optarg);
  455. break;
  456. case 's':
  457. server_name = (char *) malloc (sizeof (char) * strlen (optarg)+1);
  458. strcpy (server_name, optarg);
  459. options |= JackServerName;
  460. break;
  461. case 'h':
  462. free(peer_ip);
  463. peer_ip = (char *) malloc (sizeof (char) * strlen (optarg)+1);
  464. strcpy (peer_ip, optarg);
  465. break;
  466. case 'p':
  467. peer_port = atoi (optarg);
  468. break;
  469. case 'P':
  470. playback_channels_audio = atoi (optarg);
  471. break;
  472. case 'C':
  473. capture_channels_audio = atoi (optarg);
  474. break;
  475. case 'o':
  476. playback_channels_midi = atoi (optarg);
  477. break;
  478. case 'i':
  479. capture_channels_midi = atoi (optarg);
  480. break;
  481. case 'l':
  482. latency = atoi (optarg);
  483. break;
  484. case 'r':
  485. reply_port = atoi (optarg);
  486. break;
  487. case 'f':
  488. factor = atoi (optarg);
  489. break;
  490. case 'b':
  491. bitdepth = atoi (optarg);
  492. break;
  493. case 'c':
  494. #if HAVE_CELT
  495. bitdepth = 1000;
  496. factor = atoi (optarg);
  497. #else
  498. printf( "not built with celt supprt\n" );
  499. exit(10);
  500. #endif
  501. break;
  502. case 'm':
  503. mtu = atoi (optarg);
  504. break;
  505. case 'R':
  506. redundancy = atoi (optarg);
  507. break;
  508. case 'H':
  509. dont_htonl_floats = atoi (optarg);
  510. break;
  511. case ':':
  512. fprintf (stderr, "Option -%c requires an operand\n", optopt);
  513. errflg++;
  514. break;
  515. case '?':
  516. fprintf (stderr, "Unrecognized option: -%c\n", optopt);
  517. errflg++;
  518. }
  519. }
  520. if (errflg)
  521. {
  522. printUsage ();
  523. exit (2);
  524. }
  525. capture_channels = capture_channels_audio + capture_channels_midi;
  526. playback_channels = playback_channels_audio + playback_channels_midi;
  527. outsockfd = socket (PF_INET, SOCK_DGRAM, 0);
  528. insockfd = socket (PF_INET, SOCK_DGRAM, 0);
  529. init_sockaddr_in ((struct sockaddr_in *) &destaddr, peer_ip, peer_port);
  530. if(reply_port)
  531. {
  532. init_sockaddr_in ((struct sockaddr_in *) &bindaddr, NULL, reply_port);
  533. if( bind (insockfd, &bindaddr, sizeof (bindaddr)) ) {
  534. fprintf (stderr, "bind failure\n" );
  535. }
  536. }
  537. /* try to become a client of the JACK server */
  538. client = jack_client_open (client_name, options, &status, server_name);
  539. if (client == NULL)
  540. {
  541. fprintf (stderr, "jack_client_open() failed, status = 0x%2.0x\n"
  542. "Is the JACK server running ?\n", status);
  543. return 1;
  544. }
  545. /* Set up jack callbacks */
  546. jack_set_process_callback (client, process, 0);
  547. jack_set_sync_callback (client, sync_cb, 0);
  548. jack_on_shutdown (client, jack_shutdown, 0);
  549. alloc_ports (capture_channels_audio, playback_channels_audio, capture_channels_midi, playback_channels_midi);
  550. if( bitdepth == 1000 )
  551. net_period = factor;
  552. else
  553. net_period = ceilf((float) jack_get_buffer_size (client) / (float) factor);
  554. int rx_bufsize = get_sample_size (bitdepth) * capture_channels * net_period + sizeof (jacknet_packet_header);
  555. global_packcache = packet_cache_new (latency + 50, rx_bufsize, mtu);
  556. /* tell the JACK server that we are ready to roll */
  557. if (jack_activate (client))
  558. {
  559. fprintf (stderr, "Cannot activate client");
  560. return 1;
  561. }
  562. /* Now sleep forever... and evaluate the state_ vars */
  563. statecopy_connected = 2; // make it report unconnected on start.
  564. statecopy_latency = state_latency;
  565. statecopy_netxruns = state_netxruns;
  566. while (1)
  567. {
  568. sleep (1);
  569. if (statecopy_connected != state_connected)
  570. {
  571. statecopy_connected = state_connected;
  572. if (statecopy_connected)
  573. {
  574. state_netxruns = 1; // We want to reset the netxrun count on each new connection
  575. printf ("Connected :-)\n");
  576. }
  577. else
  578. printf ("Not Connected\n");
  579. fflush(stdout);
  580. }
  581. if (statecopy_connected)
  582. {
  583. if (statecopy_netxruns != state_netxruns) {
  584. statecopy_netxruns = state_netxruns;
  585. printf ("%s: at frame %06d -> total netxruns %d (%d%%) queue time= %d\n",
  586. client_name,
  587. state_currentframe,
  588. statecopy_netxruns,
  589. 100*statecopy_netxruns/state_currentframe,
  590. state_recv_packet_queue_time);
  591. fflush(stdout);
  592. }
  593. }
  594. else
  595. {
  596. if (statecopy_latency != state_latency)
  597. {
  598. statecopy_latency = state_latency;
  599. if (statecopy_latency > 1)
  600. printf ("current latency %d\n", statecopy_latency);
  601. fflush(stdout);
  602. }
  603. }
  604. }
  605. /* Never reached. Well we will be a GtkApp someday... */
  606. packet_cache_free (global_packcache);
  607. jack_client_close (client);
  608. exit (0);
  609. }