From 47b65e76f5ed7e02f9a137a3dd8cc3eba6009039 Mon Sep 17 00:00:00 2001 From: marco Date: Tue, 15 Apr 2008 21:56:39 +0000 Subject: [PATCH] * Code cleanup * Help text improvements * Output messages improvements/fixes * Latency now defaults to 5 which is a much more realistic/sensible default for most networks (I'm thinking about first user experience there git-svn-id: svn+ssh://jackaudio.org/trunk/jack@1160 0c269be4-1314-0410-8aa9-9f06e86f4224 --- tools/net_source.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/tools/net_source.c b/tools/net_source.c index be8b2ab..b52e45a 100644 --- a/tools/net_source.c +++ b/tools/net_source.c @@ -21,9 +21,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/** @file net_source.c +/** @file netsource.c * - * @brief This client connects a remote netjack slave to a local jackd master server + * @brief This client connects a remote slave JACK to a local JACK server assumed to be the master */ #include #include @@ -53,7 +53,7 @@ int playback_channels = 0; int playback_channels_audio = 2; int playback_channels_midi = 1; -int latency = 1; +int latency = 5; jack_nframes_t factor = 1; int bitdepth = 0; int reply_port = 0; @@ -64,9 +64,6 @@ int insockfd; struct sockaddr destaddr; struct sockaddr bindaddr; -int recv_channels; -int recv_smaple_format; - int sync_state; jack_transport_state_t last_transport_state; @@ -94,7 +91,7 @@ alloc_ports (int n_capture_audio, int n_playback_audio, int n_capture_midi, int port = jack_port_register (client, buf, JACK_DEFAULT_AUDIO_TYPE, port_flags, 0); if (!port) { - printf( "jacknet_client: cannot register port for %s", buf); + printf( "jack_netsource: cannot register port for %s", buf); break; } capture_srcs = jack_slist_append (capture_srcs, src_new (SRC_LINEAR, 1, NULL)); @@ -108,7 +105,7 @@ alloc_ports (int n_capture_audio, int n_playback_audio, int n_capture_midi, int port = jack_port_register (client, buf, JACK_DEFAULT_MIDI_TYPE, port_flags, 0); if (!port) { - printf ("jacknet_client: cannot register port for %s", buf); + printf ("jack_netsource: cannot register port for %s", buf); break; } capture_ports = jack_slist_append(capture_ports, port); @@ -123,7 +120,7 @@ alloc_ports (int n_capture_audio, int n_playback_audio, int n_capture_midi, int port = jack_port_register (client, buf, JACK_DEFAULT_AUDIO_TYPE, port_flags, 0); if (!port) { - printf ("jacknet_client: cannot register port for %s", buf); + printf ("jack_netsource: cannot register port for %s", buf); break; } playback_srcs = jack_slist_append (playback_srcs, src_new (SRC_LINEAR, 1, NULL)); @@ -137,7 +134,7 @@ alloc_ports (int n_capture_audio, int n_playback_audio, int n_capture_midi, int port = jack_port_register (client, buf, JACK_DEFAULT_MIDI_TYPE, port_flags, 0); if (!port) { - printf ("jacknet_client: cannot register port for %s", buf); + printf ("jack_netsource: cannot register port for %s", buf); break; } playback_ports = jack_slist_append (playback_ports, port); @@ -209,7 +206,8 @@ process (jack_nframes_t nframes, void *arg) /* Loop till we get the right packet at the right momment */ while (size == rx_bufsize && (framecnt - pkthdr->framecnt) > latency) { - printf ("Frame %d \tLate packet (expected frame %d, got frame %d). Packet received with a latency of %d frames\n", framecnt, framecnt - latency, pkthdr->framecnt, framecnt - pkthdr->framecnt); + //printf ("Frame %d \tLate packet received with a latency of %d frames (expected frame %d, got frame %d)\n", framecnt, framecnt - pkthdr->framecnt, framecnt - latency, pkthdr->framecnt); + printf ("Frame %d \tLate packet received with a latency of %d frames\n", framecnt, framecnt - pkthdr->framecnt); if (reply_port) size = netjack_recv (insockfd, (char *) packet_buf, rx_bufsize, MSG_DONTWAIT, 1400); else @@ -221,7 +219,11 @@ process (jack_nframes_t nframes, void *arg) * to the JACK ports so it can be played. */ if (size == rx_bufsize) { - cont_miss = 0; + if (cont_miss) + { + //printf("Frame %d \tRecovered from dropouts\n", framecnt); + cont_miss = 0; + } render_payload_to_jack_ports (bitdepth, packet_bufX, net_period, capture_ports, capture_srcs, nframes); /* Now evaluate packet header */ if (sync_state != pkthdr->sync_state) @@ -233,7 +235,8 @@ process (jack_nframes_t nframes, void *arg) * to the ouput ports */ else { - printf ("Frame %d \tPacket missed or incomplete (expected: %d bytes, got: %d bytes)\n", framecnt, rx_bufsize, size); + //printf ("Frame %d \tPacket missed or incomplete (expected: %d bytes, got: %d bytes)\n", framecnt, rx_bufsize, size); + printf ("Frame %d \tPacket missed or incomplete\n", framecnt); cont_miss += 1; chn = 0; node = capture_ports; @@ -275,8 +278,13 @@ process (jack_nframes_t nframes, void *arg) packet_header_hton (pkthdr); if (cont_miss < 10) netjack_sendto (outsockfd, (char *) packet_buf, tx_bufsize, 0, &destaddr, sizeof (destaddr), 1400); +// else if (cont_miss >= 10 && cont_miss <= 50) +// printf ("Frame %d \tToo many packets missed (%d). We have stopped sending data\n", framecnt, cont_miss); else if (cont_miss > 50) + { + //printf ("Frame %d \tRealy too many packets missed (%d). Let's reset the counter\n", framecnt, cont_miss); cont_miss = 5; + } framecnt++; return 0; @@ -312,18 +320,18 @@ init_sockaddr_in (struct sockaddr_in *name , const char *hostname , uint16_t por void printUsage () { -fprintf (stderr, "usage: jack_netsource [options] -h \n" +fprintf (stderr, "usage: jack_netsource -h [options]\n" "\n" " -n - Reports a different name to jack\n" - " -s - The name of the jack server to connect to\n" - " -h - The hostname/IP of the \"other\" machine running the jack-slave\n" - " -p - Select another socket than the default (3000)\n" + " -s - The name of the local jack server\n" + " -h - Host name of the slave JACK\n" + " -p - UDP port used by the slave JACK\n" " -P - Number of audio playback channels\n" " -C - Number of audio capture channels\n" " -o - Number of midi playback channels\n" " -i - Number of midi capture channels\n" - " -l - Number of packets on the wire to approach\n" - " -r - When using a firewall use this port for incoming packets\n" + " -l - Network latency in number of NetJack frames\n" + " -r - Local UDP port to use\n" " -f - Downsample data in the wire by this factor\n" " -b - Set transport to use 16bit or 8bit\n" "\n");