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.

692 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. name->sin_addr = *(struct in_addr *) hostinfo->h_addr ;
  394. }
  395. else
  396. name->sin_addr.s_addr = htonl (INADDR_ANY) ;
  397. }
  398. void
  399. printUsage ()
  400. {
  401. fprintf (stderr, "usage: jack_netsource -h <host peer> [options]\n"
  402. "\n"
  403. " -n <jack name> - Reports a different name to jack\n"
  404. " -s <server name> - The name of the local jack server\n"
  405. " -h <host_peer> - Host name of the slave JACK\n"
  406. " -p <port> - UDP port used by the slave JACK\n"
  407. " -P <num channels> - Number of audio playback channels\n"
  408. " -C <num channels> - Number of audio capture channels\n"
  409. " -o <num channels> - Number of midi playback channels\n"
  410. " -i <num channels> - Number of midi capture channels\n"
  411. " -l <latency> - Network latency in number of NetJack frames\n"
  412. " -r <reply port> - Local UDP port to use\n"
  413. " -f <downsample ratio> - Downsample data in the wire by this factor\n"
  414. " -b <bitdepth> - Set transport to use 16bit or 8bit\n"
  415. " -m <mtu> - Assume this mtu for the link\n"
  416. " -c <bytes> - Use Celt and encode <bytes> per channel and packet.\n"
  417. " -R <N> - Send out packets N times.\n"
  418. "\n");
  419. }
  420. int
  421. main (int argc, char *argv[])
  422. {
  423. /* Some startup related basics */
  424. char *client_name, *server_name = NULL, *peer_ip;
  425. int peer_port = 3000;
  426. jack_options_t options = JackNullOption;
  427. jack_status_t status;
  428. /* Torben's famous state variables, aka "the reporting API" ! */
  429. /* heh ? these are only the copies of them ;) */
  430. int statecopy_connected, statecopy_latency, statecopy_netxruns;
  431. jack_nframes_t net_period;
  432. /* Argument parsing stuff */
  433. extern char *optarg;
  434. extern int optind, optopt;
  435. int errflg=0, c;
  436. if (argc < 3)
  437. {
  438. printUsage ();
  439. return 1;
  440. }
  441. client_name = (char *) malloc (sizeof (char) * 10);
  442. peer_ip = (char *) malloc (sizeof (char) * 10);
  443. sprintf(client_name, "netsource");
  444. sprintf(peer_ip, "localhost");
  445. while ((c = getopt (argc, argv, ":H:R:n:s:h:p:C:P:i:o:l:r:f:b:m:c:")) != -1)
  446. {
  447. switch (c)
  448. {
  449. case 'n':
  450. free(client_name);
  451. client_name = (char *) malloc (sizeof (char) * strlen (optarg)+1);
  452. strcpy (client_name, optarg);
  453. break;
  454. case 's':
  455. server_name = (char *) malloc (sizeof (char) * strlen (optarg)+1);
  456. strcpy (server_name, optarg);
  457. options |= JackServerName;
  458. break;
  459. case 'h':
  460. free(peer_ip);
  461. peer_ip = (char *) malloc (sizeof (char) * strlen (optarg)+1);
  462. strcpy (peer_ip, optarg);
  463. break;
  464. case 'p':
  465. peer_port = atoi (optarg);
  466. break;
  467. case 'P':
  468. playback_channels_audio = atoi (optarg);
  469. break;
  470. case 'C':
  471. capture_channels_audio = atoi (optarg);
  472. break;
  473. case 'o':
  474. playback_channels_midi = atoi (optarg);
  475. break;
  476. case 'i':
  477. capture_channels_midi = atoi (optarg);
  478. break;
  479. case 'l':
  480. latency = atoi (optarg);
  481. break;
  482. case 'r':
  483. reply_port = atoi (optarg);
  484. break;
  485. case 'f':
  486. factor = atoi (optarg);
  487. break;
  488. case 'b':
  489. bitdepth = atoi (optarg);
  490. break;
  491. case 'c':
  492. #if HAVE_CELT
  493. bitdepth = 1000;
  494. factor = atoi (optarg);
  495. #else
  496. printf( "not built with celt supprt\n" );
  497. exit(10);
  498. #endif
  499. break;
  500. case 'm':
  501. mtu = atoi (optarg);
  502. break;
  503. case 'R':
  504. redundancy = atoi (optarg);
  505. break;
  506. case 'H':
  507. dont_htonl_floats = atoi (optarg);
  508. break;
  509. case ':':
  510. fprintf (stderr, "Option -%c requires an operand\n", optopt);
  511. errflg++;
  512. break;
  513. case '?':
  514. fprintf (stderr, "Unrecognized option: -%c\n", optopt);
  515. errflg++;
  516. }
  517. }
  518. if (errflg)
  519. {
  520. printUsage ();
  521. exit (2);
  522. }
  523. capture_channels = capture_channels_audio + capture_channels_midi;
  524. playback_channels = playback_channels_audio + playback_channels_midi;
  525. outsockfd = socket (PF_INET, SOCK_DGRAM, 0);
  526. insockfd = socket (PF_INET, SOCK_DGRAM, 0);
  527. init_sockaddr_in ((struct sockaddr_in *) &destaddr, peer_ip, peer_port);
  528. if(reply_port)
  529. {
  530. init_sockaddr_in ((struct sockaddr_in *) &bindaddr, NULL, reply_port);
  531. bind (insockfd, &bindaddr, sizeof (bindaddr));
  532. }
  533. /* try to become a client of the JACK server */
  534. client = jack_client_open (client_name, options, &status, server_name);
  535. if (client == NULL)
  536. {
  537. fprintf (stderr, "jack_client_open() failed, status = 0x%2.0x\n"
  538. "Is the JACK server running ?\n", status);
  539. return 1;
  540. }
  541. /* Set up jack callbacks */
  542. jack_set_process_callback (client, process, 0);
  543. jack_set_sync_callback (client, sync_cb, 0);
  544. jack_on_shutdown (client, jack_shutdown, 0);
  545. alloc_ports (capture_channels_audio, playback_channels_audio, capture_channels_midi, playback_channels_midi);
  546. if( bitdepth == 1000 )
  547. net_period = factor;
  548. else
  549. net_period = ceilf((float) jack_get_buffer_size (client) / (float) factor);
  550. int rx_bufsize = get_sample_size (bitdepth) * capture_channels * net_period + sizeof (jacknet_packet_header);
  551. global_packcache = packet_cache_new (latency + 50, rx_bufsize, mtu);
  552. /* tell the JACK server that we are ready to roll */
  553. if (jack_activate (client))
  554. {
  555. fprintf (stderr, "Cannot activate client");
  556. return 1;
  557. }
  558. /* Now sleep forever... and evaluate the state_ vars */
  559. statecopy_connected = 2; // make it report unconnected on start.
  560. statecopy_latency = state_latency;
  561. statecopy_netxruns = state_netxruns;
  562. while (1)
  563. {
  564. sleep (1);
  565. if (statecopy_connected != state_connected)
  566. {
  567. statecopy_connected = state_connected;
  568. if (statecopy_connected)
  569. {
  570. state_netxruns = 1; // We want to reset the netxrun count on each new connection
  571. printf ("Connected :-)\n");
  572. }
  573. else
  574. printf ("Not Connected\n");
  575. fflush(stdout);
  576. }
  577. if (statecopy_connected)
  578. {
  579. if (statecopy_netxruns != state_netxruns) {
  580. statecopy_netxruns = state_netxruns;
  581. printf ("at frame %06d -> total netxruns %d (%d%%) queue time= %d\n", state_currentframe,
  582. statecopy_netxruns,
  583. 100*statecopy_netxruns/state_currentframe,
  584. state_recv_packet_queue_time);
  585. fflush(stdout);
  586. }
  587. }
  588. else
  589. {
  590. if (statecopy_latency != state_latency)
  591. {
  592. statecopy_latency = state_latency;
  593. if (statecopy_latency > 1)
  594. printf ("current latency %d\n", statecopy_latency);
  595. fflush(stdout);
  596. }
  597. }
  598. }
  599. /* Never reached. Well we will be a GtkApp someday... */
  600. packet_cache_free (global_packcache);
  601. jack_client_close (client);
  602. exit (0);
  603. }