Browse Source

Beautifull code.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4230 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/1.9.7
sletz 14 years ago
parent
commit
ed52540600
2 changed files with 186 additions and 191 deletions
  1. +82
    -86
      common/netjack_packet.c
  2. +104
    -105
      example-clients/netsource.c

+ 82
- 86
common/netjack_packet.c View File

@@ -130,7 +130,7 @@ int get_sample_size (int bitdepth)
//JN: why? is this for buffer sizes before or after encoding? //JN: why? is this for buffer sizes before or after encoding?
//JN: if the former, why not int16_t, if the latter, shouldn't it depend on -c N? //JN: if the former, why not int16_t, if the latter, shouldn't it depend on -c N?
if( bitdepth == CELT_MODE ) if( bitdepth == CELT_MODE )
return sizeof( unsigned char );
return sizeof( unsigned char );
return sizeof (int32_t); return sizeof (int32_t);
} }


@@ -328,7 +328,6 @@ cache_packet_add_fragment (cache_packet *pack, char *packet_buf, int rcv_len)
return; return;
} }



if (fragment_nr == 0) if (fragment_nr == 0)
{ {
memcpy (pack->packet_buf, packet_buf, rcv_len); memcpy (pack->packet_buf, packet_buf, rcv_len);
@@ -374,7 +373,6 @@ netjack_poll_deadline (int sockfd, jack_time_t deadline)
int timeout; int timeout;
#endif #endif



jack_time_t now = jack_get_time(); jack_time_t now = jack_get_time();
if( now >= deadline ) if( now >= deadline )
return 0; return 0;
@@ -389,7 +387,6 @@ netjack_poll_deadline (int sockfd, jack_time_t deadline)
timeout = lrintf( (float)(deadline - now) / 1000.0 ); timeout = lrintf( (float)(deadline - now) / 1000.0 );
#endif #endif



fds.fd = sockfd; fds.fd = sockfd;
fds.events = POLLIN; fds.events = POLLIN;


@@ -600,24 +597,24 @@ packet_cache_retreive_packet_pointer( packet_cache *pcache, jack_nframes_t frame


for (i = 0; i < pcache->size; i++) { for (i = 0; i < pcache->size; i++) {
if (pcache->packets[i].valid && (pcache->packets[i].framecnt == framecnt)) { if (pcache->packets[i].valid && (pcache->packets[i].framecnt == framecnt)) {
cpack = &(pcache->packets[i]);
cpack = &(pcache->packets[i]);
break; break;
}
}
} }


if( cpack == NULL ) { if( cpack == NULL ) {
//printf( "retreive packet: %d....not found\n", framecnt );
return -1;
//printf( "retreive packet: %d....not found\n", framecnt );
return -1;
} }


if( !cache_packet_is_complete( cpack ) ) { if( !cache_packet_is_complete( cpack ) ) {
return -1;
return -1;
} }


// ok. cpack is the one we want and its complete. // ok. cpack is the one we want and its complete.
*packet_buf = cpack->packet_buf; *packet_buf = cpack->packet_buf;
if( timestamp ) if( timestamp )
*timestamp = cpack->recv_timestamp;
*timestamp = cpack->recv_timestamp;


pcache->last_framecnt_retreived_valid = 1; pcache->last_framecnt_retreived_valid = 1;
pcache->last_framecnt_retreived = framecnt; pcache->last_framecnt_retreived = framecnt;
@@ -634,18 +631,18 @@ packet_cache_release_packet( packet_cache *pcache, jack_nframes_t framecnt )


for (i = 0; i < pcache->size; i++) { for (i = 0; i < pcache->size; i++) {
if (pcache->packets[i].valid && (pcache->packets[i].framecnt == framecnt)) { if (pcache->packets[i].valid && (pcache->packets[i].framecnt == framecnt)) {
cpack = &(pcache->packets[i]);
cpack = &(pcache->packets[i]);
break; break;
}
}
} }


if( cpack == NULL ) { if( cpack == NULL ) {
//printf( "retreive packet: %d....not found\n", framecnt );
return -1;
//printf( "retreive packet: %d....not found\n", framecnt );
return -1;
} }


if( !cache_packet_is_complete( cpack ) ) { if( !cache_packet_is_complete( cpack ) ) {
return -1;
return -1;
} }


cache_packet_reset (cpack); cache_packet_reset (cpack);
@@ -661,13 +658,13 @@ packet_cache_get_fill( packet_cache *pcache, jack_nframes_t expected_framecnt )


for (i = 0; i < pcache->size; i++) for (i = 0; i < pcache->size; i++)
{ {
cache_packet *cpack = &(pcache->packets[i]);
cache_packet *cpack = &(pcache->packets[i]);
if (cpack->valid && cache_packet_is_complete( cpack )) if (cpack->valid && cache_packet_is_complete( cpack ))
if( cpack->framecnt >= expected_framecnt )
num_packets_before_us += 1;
if( cpack->framecnt >= expected_framecnt )
num_packets_before_us += 1;
} }


return 100.0 * (float)num_packets_before_us / (float)( pcache->size ) ;
return 100.0 * (float)num_packets_before_us / (float)( pcache->size );
} }


// Returns 0 when no valid packet is inside the cache. // Returns 0 when no valid packet is inside the cache.
@@ -680,29 +677,29 @@ packet_cache_get_next_available_framecnt( packet_cache *pcache, jack_nframes_t e


for (i = 0; i < pcache->size; i++) for (i = 0; i < pcache->size; i++)
{ {
cache_packet *cpack = &(pcache->packets[i]);
//printf( "p%d: valid=%d, frame %d\n", i, cpack->valid, cpack->framecnt );
cache_packet *cpack = &(pcache->packets[i]);
//printf( "p%d: valid=%d, frame %d\n", i, cpack->valid, cpack->framecnt );


if (!cpack->valid || !cache_packet_is_complete( cpack )) { if (!cpack->valid || !cache_packet_is_complete( cpack )) {
//printf( "invalid\n" );
continue;
}
//printf( "invalid\n" );
continue;
}


if( cpack->framecnt < expected_framecnt )
continue;
if( cpack->framecnt < expected_framecnt )
continue;


if( (cpack->framecnt - expected_framecnt) > best_offset ) {
continue;
if( (cpack->framecnt - expected_framecnt) > best_offset ) {
continue;
} }


best_offset = cpack->framecnt - expected_framecnt; best_offset = cpack->framecnt - expected_framecnt;
retval = 1; retval = 1;


if( best_offset == 0 )
if (best_offset == 0)
break; break;
} }
if( retval && framecnt )
*framecnt = expected_framecnt + best_offset;
if (retval && framecnt)
*framecnt = expected_framecnt + best_offset;


return retval; return retval;
} }
@@ -716,12 +713,12 @@ packet_cache_get_highest_available_framecnt( packet_cache *pcache, jack_nframes_


for (i = 0; i < pcache->size; i++) for (i = 0; i < pcache->size; i++)
{ {
cache_packet *cpack = &(pcache->packets[i]);
//printf( "p%d: valid=%d, frame %d\n", i, cpack->valid, cpack->framecnt );
cache_packet *cpack = &(pcache->packets[i]);
//printf( "p%d: valid=%d, frame %d\n", i, cpack->valid, cpack->framecnt );


if (!cpack->valid || !cache_packet_is_complete( cpack )) { if (!cpack->valid || !cache_packet_is_complete( cpack )) {
//printf( "invalid\n" );
continue;
//printf( "invalid\n" );
continue;
} }


if (cpack->framecnt < best_value) { if (cpack->framecnt < best_value) {
@@ -732,8 +729,8 @@ packet_cache_get_highest_available_framecnt( packet_cache *pcache, jack_nframes_
retval = 1; retval = 1;


} }
if( retval && framecnt )
*framecnt = best_value;
if (retval && framecnt)
*framecnt = best_value;


return retval; return retval;
} }
@@ -748,15 +745,15 @@ packet_cache_find_latency( packet_cache *pcache, jack_nframes_t expected_framecn


for (i = 0; i < pcache->size; i++) for (i = 0; i < pcache->size; i++)
{ {
cache_packet *cpack = &(pcache->packets[i]);
//printf( "p%d: valid=%d, frame %d\n", i, cpack->valid, cpack->framecnt );
cache_packet *cpack = &(pcache->packets[i]);
//printf( "p%d: valid=%d, frame %d\n", i, cpack->valid, cpack->framecnt );


if (!cpack->valid || !cache_packet_is_complete( cpack )) { if (!cpack->valid || !cache_packet_is_complete( cpack )) {
//printf( "invalid\n" );
continue;
//printf( "invalid\n" );
continue;
} }


if( (cpack->framecnt - expected_framecnt) < best_offset ) {
if ((cpack->framecnt - expected_framecnt) < best_offset) {
continue; continue;
} }


@@ -766,8 +763,8 @@ packet_cache_find_latency( packet_cache *pcache, jack_nframes_t expected_framecn
if( best_offset == 0 ) if( best_offset == 0 )
break; break;
} }
if( retval && framecnt )
*framecnt = JACK_MAX_FRAMES - best_offset;
if (retval && framecnt)
*framecnt = JACK_MAX_FRAMES - best_offset;


return retval; return retval;
} }
@@ -786,18 +783,18 @@ netjack_sendto (int sockfd, char *packet_buf, int pkt_size, int flags, struct so
int fragment_payload_size = mtu - sizeof (jacknet_packet_header); int fragment_payload_size = mtu - sizeof (jacknet_packet_header);


if (pkt_size <= mtu) { if (pkt_size <= mtu) {
int err;
pkthdr = (jacknet_packet_header *) packet_buf;
int err;
pkthdr = (jacknet_packet_header *) packet_buf;
pkthdr->fragment_nr = htonl (0); pkthdr->fragment_nr = htonl (0);
err = sendto(sockfd, packet_buf, pkt_size, flags, addr, addr_size); err = sendto(sockfd, packet_buf, pkt_size, flags, addr, addr_size);
if( err<0 ) {
//printf( "error in send\n" );
perror( "send" );
}
if( err<0 ) {
//printf( "error in send\n" );
perror( "send" );
}
} }
else else
{ {
int err;
int err;
// Copy the packet header to the tx pack first. // Copy the packet header to the tx pack first.
memcpy(tx_packet, packet_buf, sizeof (jacknet_packet_header)); memcpy(tx_packet, packet_buf, sizeof (jacknet_packet_header));


@@ -819,14 +816,13 @@ netjack_sendto (int sockfd, char *packet_buf, int pkt_size, int flags, struct so


// sendto(last_pack_size); // sendto(last_pack_size);
err = sendto(sockfd, tx_packet, last_payload_size + sizeof(jacknet_packet_header), flags, addr, addr_size); err = sendto(sockfd, tx_packet, last_payload_size + sizeof(jacknet_packet_header), flags, addr, addr_size);
if( err<0 ) {
//printf( "error in send\n" );
perror( "send" );
}
if( err<0 ) {
//printf( "error in send\n" );
perror( "send" );
}
} }
} }



void void
decode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf) decode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf)
{ {
@@ -907,8 +903,8 @@ render_payload_to_jack_ports_float ( void *packet_payload, jack_nframes_t net_pe


uint32_t *packet_bufX = (uint32_t *)packet_payload; uint32_t *packet_bufX = (uint32_t *)packet_payload;


if( !packet_payload )
return;
if (!packet_payload)
return;


while (node != NULL) while (node != NULL)
{ {
@@ -951,19 +947,19 @@ render_payload_to_jack_ports_float ( void *packet_payload, jack_nframes_t net_pe
else else
#endif #endif
{ {
if( dont_htonl_floats )
{
memcpy( buf, packet_bufX, net_period_down*sizeof(jack_default_audio_sample_t));
}
else
{
for (i = 0; i < net_period_down; i++)
{
val.i = packet_bufX[i];
val.i = ntohl (val.i);
buf[i] = val.f;
}
}
if( dont_htonl_floats )
{
memcpy( buf, packet_bufX, net_period_down*sizeof(jack_default_audio_sample_t));
}
else
{
for (i = 0; i < net_period_down; i++)
{
val.i = packet_bufX[i];
val.i = ntohl (val.i);
buf[i] = val.f;
}
}
} }
} }
else if (jack_port_is_midi (porttype)) else if (jack_port_is_midi (porttype))
@@ -1031,19 +1027,19 @@ render_jack_ports_to_payload_float (JSList *playback_ports, JSList *playback_src
else else
#endif #endif
{ {
if( dont_htonl_floats )
{
memcpy( packet_bufX, buf, net_period_up*sizeof(jack_default_audio_sample_t) );
}
else
{
for (i = 0; i < net_period_up; i++)
{
val.f = buf[i];
val.i = htonl (val.i);
packet_bufX[i] = val.i;
}
}
if( dont_htonl_floats )
{
memcpy( packet_bufX, buf, net_period_up*sizeof(jack_default_audio_sample_t) );
}
else
{
for (i = 0; i < net_period_up; i++)
{
val.f = buf[i];
val.i = htonl (val.i);
packet_bufX[i] = val.i;
}
}
} }
} }
else if (jack_port_is_midi (porttype)) else if (jack_port_is_midi (porttype))
@@ -1218,8 +1214,8 @@ render_payload_to_jack_ports_8bit (void *packet_payload, jack_nframes_t net_peri


int8_t *packet_bufX = (int8_t *)packet_payload; int8_t *packet_bufX = (int8_t *)packet_payload;


if( !packet_payload )
return;
if (!packet_payload)
return;


while (node != NULL) while (node != NULL)
{ {


+ 104
- 105
example-clients/netsource.c View File

@@ -139,24 +139,24 @@ alloc_ports (int n_capture_audio, int n_playback_audio, int n_capture_midi, int
printf( "jack_netsource: cannot register %s port\n", buf); printf( "jack_netsource: cannot register %s port\n", buf);
break; break;
} }
if( bitdepth == 1000 ) {
#if HAVE_CELT
#if HAVE_CELT_API_0_11
CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate( client ), jack_get_buffer_size(client), NULL );
capture_srcs = jack_slist_append(capture_srcs, celt_decoder_create_custom( celt_mode, 1, NULL ) );
#elif HAVE_CELT_API_0_7 || HAVE_CELT_API_0_8
CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate( client ), jack_get_buffer_size(client), NULL );
capture_srcs = jack_slist_append(capture_srcs, celt_decoder_create( celt_mode, 1, NULL ) );
#else
CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate( client ), 1, jack_get_buffer_size(client), NULL );
capture_srcs = jack_slist_append(capture_srcs, celt_decoder_create( celt_mode ) );
#endif
#endif
} else {
#if HAVE_SAMPLERATE
capture_srcs = jack_slist_append (capture_srcs, src_new (SRC_LINEAR, 1, NULL));
#endif
}
if (bitdepth == 1000) {
#if HAVE_CELT
#if HAVE_CELT_API_0_11
CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate( client ), jack_get_buffer_size(client), NULL );
capture_srcs = jack_slist_append(capture_srcs, celt_decoder_create_custom( celt_mode, 1, NULL ) );
#elif HAVE_CELT_API_0_7 || HAVE_CELT_API_0_8
CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate( client ), jack_get_buffer_size(client), NULL );
capture_srcs = jack_slist_append(capture_srcs, celt_decoder_create( celt_mode, 1, NULL ) );
#else
CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate( client ), 1, jack_get_buffer_size(client), NULL );
capture_srcs = jack_slist_append(capture_srcs, celt_decoder_create( celt_mode ) );
#endif
#endif
} else {
#if HAVE_SAMPLERATE
capture_srcs = jack_slist_append (capture_srcs, src_new (SRC_LINEAR, 1, NULL));
#endif
}
capture_ports = jack_slist_append (capture_ports, port); capture_ports = jack_slist_append (capture_ports, port);
} }


@@ -185,25 +185,25 @@ alloc_ports (int n_capture_audio, int n_playback_audio, int n_capture_midi, int
printf ("jack_netsource: cannot register %s port\n", buf); printf ("jack_netsource: cannot register %s port\n", buf);
break; break;
} }
if( bitdepth == 1000 ) {
#if HAVE_CELT
#if HAVE_CELT_API_0_11
CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate (client), jack_get_buffer_size(client), NULL );
playback_srcs = jack_slist_append(playback_srcs, celt_encoder_create_custom( celt_mode, 1, NULL ) );
#elif HAVE_CELT_API_0_7 || HAVE_CELT_API_0_8
CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate (client), jack_get_buffer_size(client), NULL );
playback_srcs = jack_slist_append(playback_srcs, celt_encoder_create( celt_mode, 1, NULL ) );
#else
CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate (client), 1, jack_get_buffer_size(client), NULL );
playback_srcs = jack_slist_append(playback_srcs, celt_encoder_create( celt_mode ) );
#endif
#endif
} else {
#if HAVE_SAMPLERATE
playback_srcs = jack_slist_append (playback_srcs, src_new (SRC_LINEAR, 1, NULL));
#endif
}
playback_ports = jack_slist_append (playback_ports, port);
if( bitdepth == 1000 ) {
#if HAVE_CELT
#if HAVE_CELT_API_0_11
CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate (client), jack_get_buffer_size(client), NULL );
playback_srcs = jack_slist_append(playback_srcs, celt_encoder_create_custom( celt_mode, 1, NULL ) );
#elif HAVE_CELT_API_0_7 || HAVE_CELT_API_0_8
CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate (client), jack_get_buffer_size(client), NULL );
playback_srcs = jack_slist_append(playback_srcs, celt_encoder_create( celt_mode, 1, NULL ) );
#else
CELTMode *celt_mode = celt_mode_create( jack_get_sample_rate (client), 1, jack_get_buffer_size(client), NULL );
playback_srcs = jack_slist_append(playback_srcs, celt_encoder_create( celt_mode ) );
#endif
#endif
} else {
#if HAVE_SAMPLERATE
playback_srcs = jack_slist_append (playback_srcs, src_new (SRC_LINEAR, 1, NULL));
#endif
}
playback_ports = jack_slist_append (playback_ports, port);
} }


/* Allocate midi playback channels */ /* Allocate midi playback channels */
@@ -232,7 +232,7 @@ sync_cb (jack_transport_state_t state, jack_position_t *pos, void *arg)
int retval = sync_state; int retval = sync_state;


if (! state_connected) { if (! state_connected) {
return 1;
return 1;
} }
if (latency_count) { if (latency_count) {
latency_count--; latency_count--;
@@ -281,14 +281,13 @@ process (jack_nframes_t nframes, void *arg)
jack_time_t packet_recv_timestamp; jack_time_t packet_recv_timestamp;


if( bitdepth == 1000 ) if( bitdepth == 1000 )
net_period = (factor * jack_get_buffer_size(client) * 1024 / jack_get_sample_rate(client) / 8)&(~1) ;
net_period = (factor * jack_get_buffer_size(client) * 1024 / jack_get_sample_rate(client) / 8)&(~1) ;
else else
net_period = (float) nframes / (float) factor;
net_period = (float) nframes / (float) factor;


rx_bufsize = get_sample_size (bitdepth) * capture_channels * net_period + sizeof (jacknet_packet_header); rx_bufsize = get_sample_size (bitdepth) * capture_channels * net_period + sizeof (jacknet_packet_header);
tx_bufsize = get_sample_size (bitdepth) * playback_channels * net_period + sizeof (jacknet_packet_header); tx_bufsize = get_sample_size (bitdepth) * playback_channels * net_period + sizeof (jacknet_packet_header);



/* Allocate a buffer where both In and Out Buffer will fit */ /* Allocate a buffer where both In and Out Buffer will fit */
packet_buf_tx = alloca (tx_bufsize); packet_buf_tx = alloca (tx_bufsize);


@@ -352,29 +351,29 @@ process (jack_nframes_t nframes, void *arg)




if( reply_port ) if( reply_port )
input_fd = insockfd;
input_fd = insockfd;
else else
input_fd = outsockfd;
input_fd = outsockfd;


// for latency == 0 we can poll. // for latency == 0 we can poll.
if( (latency == 0) || (freewheeling!=0) ) { if( (latency == 0) || (freewheeling!=0) ) {
jack_time_t deadline = jack_get_time() + 1000000 * jack_get_buffer_size(client)/jack_get_sample_rate(client);
// Now loop until we get the right packet.
while(1) {
jack_nframes_t got_frame;
if ( ! netjack_poll_deadline( input_fd, deadline ) )
break;
packet_cache_drain_socket(packcache, input_fd);
if (packet_cache_get_next_available_framecnt( packcache, framecnt - latency, &got_frame ))
if( got_frame == (framecnt - latency) )
break;
}
jack_time_t deadline = jack_get_time() + 1000000 * jack_get_buffer_size(client)/jack_get_sample_rate(client);
// Now loop until we get the right packet.
while(1) {
jack_nframes_t got_frame;
if ( ! netjack_poll_deadline( input_fd, deadline ) )
break;
packet_cache_drain_socket(packcache, input_fd);
if (packet_cache_get_next_available_framecnt( packcache, framecnt - latency, &got_frame ))
if( got_frame == (framecnt - latency) )
break;
}
} else { } else {
// normally:
// only drain socket.
packet_cache_drain_socket(packcache, input_fd);
// normally:
// only drain socket.
packet_cache_drain_socket(packcache, input_fd);
} }


size = packet_cache_retreive_packet_pointer( packcache, framecnt - latency, (char**)&rx_packet_ptr, rx_bufsize, &packet_recv_timestamp ); size = packet_cache_retreive_packet_pointer( packcache, framecnt - latency, (char**)&rx_packet_ptr, rx_bufsize, &packet_recv_timestamp );
@@ -382,15 +381,15 @@ process (jack_nframes_t nframes, void *arg)
* to the JACK ports so it can be played. */ * to the JACK ports so it can be played. */
if (size == rx_bufsize) if (size == rx_bufsize)
{ {
uint32_t *packet_buf_rx = rx_packet_ptr;
jacknet_packet_header *pkthdr_rx = (jacknet_packet_header *) packet_buf_rx;
packet_bufX = packet_buf_rx + sizeof (jacknet_packet_header) / sizeof (jack_default_audio_sample_t);
// calculate how much time there would have been, if this packet was sent at the deadline.
uint32_t *packet_buf_rx = rx_packet_ptr;
jacknet_packet_header *pkthdr_rx = (jacknet_packet_header *) packet_buf_rx;
packet_bufX = packet_buf_rx + sizeof (jacknet_packet_header) / sizeof (jack_default_audio_sample_t);
// calculate how much time there would have been, if this packet was sent at the deadline.


int recv_time_offset = (int) (jack_get_time() - packet_recv_timestamp);
packet_header_ntoh (pkthdr_rx);
deadline_goodness = recv_time_offset - (int)pkthdr_rx->latency;
//printf( "deadline goodness = %d ---> off: %d\n", deadline_goodness, recv_time_offset );
int recv_time_offset = (int) (jack_get_time() - packet_recv_timestamp);
packet_header_ntoh (pkthdr_rx);
deadline_goodness = recv_time_offset - (int)pkthdr_rx->latency;
//printf( "deadline goodness = %d ---> off: %d\n", deadline_goodness, recv_time_offset );


if (cont_miss) if (cont_miss)
{ {
@@ -400,26 +399,26 @@ process (jack_nframes_t nframes, void *arg)
render_payload_to_jack_ports (bitdepth, packet_bufX, net_period, render_payload_to_jack_ports (bitdepth, packet_bufX, net_period,
capture_ports, capture_srcs, nframes, dont_htonl_floats); capture_ports, capture_srcs, nframes, dont_htonl_floats);


state_currentframe = framecnt;
state_recv_packet_queue_time = recv_time_offset;
state_connected = 1;
state_currentframe = framecnt;
state_recv_packet_queue_time = recv_time_offset;
state_connected = 1;
sync_state = pkthdr_rx->sync_state; sync_state = pkthdr_rx->sync_state;
packet_cache_release_packet( packcache, framecnt - latency );
packet_cache_release_packet( packcache, framecnt - latency );
} }
/* Second alternative : we've received something that's not /* Second alternative : we've received something that's not
* as big as expected or we missed a packet. We render silence * as big as expected or we missed a packet. We render silence
* to the ouput ports */ * to the ouput ports */
else else
{ {
jack_nframes_t latency_estimate;
if( packet_cache_find_latency( packcache, framecnt, &latency_estimate ) )
//if( (state_latency == 0) || (latency_estimate < state_latency) )
state_latency = latency_estimate;
jack_nframes_t latency_estimate;
if( packet_cache_find_latency( packcache, framecnt, &latency_estimate ) )
//if( (state_latency == 0) || (latency_estimate < state_latency) )
state_latency = latency_estimate;


// Set the counters up.
state_currentframe = framecnt;
//state_latency = framecnt - pkthdr->framecnt;
state_netxruns += 1;
// Set the counters up.
state_currentframe = framecnt;
//state_latency = framecnt - pkthdr->framecnt;
state_netxruns += 1;


//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); //printf ("Frame %d \tPacket missed or incomplete\n", framecnt);
@@ -440,7 +439,7 @@ process (jack_nframes_t nframes, void *arg)
chn++; chn++;
} }
} }
if( latency != 0 ) {
if (latency != 0) {
/* reset packet_bufX... */ /* reset packet_bufX... */
packet_bufX = packet_buf_tx + sizeof (jacknet_packet_header) / sizeof (jack_default_audio_sample_t); packet_bufX = packet_buf_tx + sizeof (jacknet_packet_header) / sizeof (jack_default_audio_sample_t);


@@ -630,15 +629,15 @@ main (int argc, char *argv[])
case 'b': case 'b':
bitdepth = atoi (optarg); bitdepth = atoi (optarg);
break; break;
case 'c':
case 'c':
#if HAVE_CELT #if HAVE_CELT
bitdepth = 1000;
bitdepth = 1000;
factor = atoi (optarg); factor = atoi (optarg);
#else #else
printf( "not built with celt supprt\n" );
printf( "not built with celt support\n" );
exit(10); exit(10);
#endif #endif
break;
break;
case 'm': case 'm':
mtu = atoi (optarg); mtu = atoi (optarg);
break; break;
@@ -679,24 +678,24 @@ main (int argc, char *argv[])
outsockfd = socket (AF_INET, SOCK_DGRAM, 0); outsockfd = socket (AF_INET, SOCK_DGRAM, 0);
insockfd = socket (AF_INET, SOCK_DGRAM, 0); insockfd = socket (AF_INET, SOCK_DGRAM, 0);


if( (outsockfd == -1) || (insockfd == -1) ) {
if ((outsockfd == -1) || (insockfd == -1)) {
fprintf (stderr, "cant open sockets\n" ); fprintf (stderr, "cant open sockets\n" );
return 1; return 1;
} }


init_sockaddr_in ((struct sockaddr_in *) &destaddr, peer_ip, peer_port); init_sockaddr_in ((struct sockaddr_in *) &destaddr, peer_ip, peer_port);
if(bind_port) {
if (bind_port) {
init_sockaddr_in ((struct sockaddr_in *) &bindaddr, NULL, bind_port); init_sockaddr_in ((struct sockaddr_in *) &bindaddr, NULL, bind_port);
if( bind (outsockfd, &bindaddr, sizeof (bindaddr)) ) { if( bind (outsockfd, &bindaddr, sizeof (bindaddr)) ) {
fprintf (stderr, "bind failure\n" );
}
fprintf (stderr, "bind failure\n" );
}
} }
if(reply_port)
if (reply_port)
{ {
init_sockaddr_in ((struct sockaddr_in *) &bindaddr, NULL, reply_port); init_sockaddr_in ((struct sockaddr_in *) &bindaddr, NULL, reply_port);
if( bind (insockfd, &bindaddr, sizeof (bindaddr)) ) { if( bind (insockfd, &bindaddr, sizeof (bindaddr)) ) {
fprintf (stderr, "bind failure\n" );
}
fprintf (stderr, "bind failure\n" );
}
} }


/* try to become a client of the JACK server */ /* try to become a client of the JACK server */
@@ -717,9 +716,9 @@ main (int argc, char *argv[])
alloc_ports (capture_channels_audio, playback_channels_audio, capture_channels_midi, playback_channels_midi); alloc_ports (capture_channels_audio, playback_channels_audio, capture_channels_midi, playback_channels_midi);


if( bitdepth == 1000 ) if( bitdepth == 1000 )
net_period = (factor * jack_get_buffer_size(client) * 1024 / jack_get_sample_rate(client) / 8)&(~1) ;
net_period = (factor * jack_get_buffer_size(client) * 1024 / jack_get_sample_rate(client) / 8)&(~1) ;
else else
net_period = ceilf((float) jack_get_buffer_size (client) / (float) factor);
net_period = ceilf((float) jack_get_buffer_size (client) / (float) factor);


int rx_bufsize = get_sample_size (bitdepth) * capture_channels * net_period + sizeof (jacknet_packet_header); int rx_bufsize = get_sample_size (bitdepth) * capture_channels * net_period + sizeof (jacknet_packet_header);
packcache = packet_cache_new (latency + 50, rx_bufsize, mtu); packcache = packet_cache_new (latency + 50, rx_bufsize, mtu);
@@ -763,26 +762,26 @@ main (int argc, char *argv[])


if (statecopy_connected) if (statecopy_connected)
{ {
if (statecopy_netxruns != state_netxruns) {
statecopy_netxruns = state_netxruns;
printf ("%s: at frame %06d -> total netxruns %d (%d%%) queue time= %d\n",
if (statecopy_netxruns != state_netxruns) {
statecopy_netxruns = state_netxruns;
printf ("%s: at frame %06d -> total netxruns %d (%d%%) queue time= %d\n",
client_name, client_name,
state_currentframe, state_currentframe,
statecopy_netxruns, statecopy_netxruns,
100*statecopy_netxruns/state_currentframe, 100*statecopy_netxruns/state_currentframe,
state_recv_packet_queue_time); state_recv_packet_queue_time);


fflush(stdout);
fflush(stdout);
} }
}
else
}
else
{
if (statecopy_latency != state_latency)
{ {
if (statecopy_latency != state_latency)
{
statecopy_latency = state_latency;
if (statecopy_latency > 1)
printf ("current latency %d\n", statecopy_latency);
fflush(stdout);
statecopy_latency = state_latency;
if (statecopy_latency > 1)
printf ("current latency %d\n", statecopy_latency);
fflush(stdout);
} }
} }
} }


Loading…
Cancel
Save