git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4171 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.9.7
| @@ -38,6 +38,8 @@ Valerio Pilo | |||
| * Latency callback must always be activated. | |||
| * Correct TopologicalSort. | |||
| * Add jack_midi_dump client. | |||
| * Synchronize netjack1 with JACK1 version. | |||
| 2011-03-09 Stephane Letz <letz@grame.fr> | |||
| @@ -260,8 +260,8 @@ extern "C" | |||
| EXPORT jack_session_command_t *jack_session_notify(jack_client_t* ext_client, const char* target, jack_session_event_type_t ev_type, const char* path); | |||
| EXPORT int jack_session_reply(jack_client_t* ext_client, jack_session_event_t *event); | |||
| EXPORT void jack_session_event_free(jack_session_event_t* ev); | |||
| EXPORT char *jack_get_uuid_for_client_name(jack_client_t* ext_client, const char* client_name); | |||
| EXPORT char *jack_get_client_name_by_uuid(jack_client_t* ext_client, const char* client_uuid); | |||
| EXPORT char* jack_get_uuid_for_client_name(jack_client_t* ext_client, const char* client_name); | |||
| EXPORT char* jack_get_client_name_by_uuid(jack_client_t* ext_client, const char* client_uuid); | |||
| EXPORT int jack_reserve_client_name(jack_client_t* ext_client, const char* name, const char* uuid); | |||
| EXPORT void jack_session_commands_free(jack_session_command_t *cmds); | |||
| EXPORT int jack_client_has_session_callback(jack_client_t *client, const char* client_name); | |||
| @@ -243,10 +243,12 @@ namespace Jack | |||
| { | |||
| jack_log ( "JackNetOneDriver::Init()" ); | |||
| /* SL: no more needed | |||
| if( global_packcache != NULL ) { | |||
| FreePorts(); | |||
| netjack_release( &netj ); | |||
| } | |||
| */ | |||
| //display some additional infos | |||
| jack_info ( "NetOne driver started" ); | |||
| @@ -386,7 +388,7 @@ namespace Jack | |||
| } | |||
| render_payload_to_jack_ports (netj.bitdepth, packet_bufX, netj.net_period_down, netj.capture_ports, netj.capture_srcs, netj.period_size, netj.dont_htonl_floats ); | |||
| packet_cache_release_packet(global_packcache, netj.expected_framecnt ); | |||
| packet_cache_release_packet(netj.packcache, netj.expected_framecnt ); | |||
| return 0; | |||
| } | |||
| @@ -989,7 +991,9 @@ JackNetOneDriver::render_jack_ports_to_payload (int bitdepth, JSList *playback_p | |||
| unsigned int latency = 5; | |||
| unsigned int redundancy = 1; | |||
| unsigned int mtu = 1400; | |||
| #if HAVE_SAMPLERATE | |||
| unsigned int resample_factor_up = 1; | |||
| #endif | |||
| int dont_htonl_floats = 0; | |||
| int always_deadline = 0; | |||
| int jitter_val = 0; | |||
| @@ -1098,7 +1102,7 @@ JackNetOneDriver::render_jack_ports_to_payload (int bitdepth, JSList *playback_p | |||
| new Jack::JackNetOneDriver ( "system", "net_pcm", engine, table, listen_port, mtu, | |||
| capture_ports_midi, playback_ports_midi, capture_ports, playback_ports, | |||
| sample_rate, period_size, resample_factor, | |||
| "net_pcm", handle_transport_sync, bitdepth, use_autoconfig, latency, redundancy, | |||
| "net_pcm", handle_transport_sync, bitdepth, use_autoconfig, latency, redundancy, | |||
| dont_htonl_floats, always_deadline, jitter_val ) ); | |||
| if ( driver->Open ( period_size, sample_rate, 1, 1, capture_ports, playback_ports, | |||
| @@ -66,7 +66,7 @@ $Id: net_driver.c,v 1.17 2006/04/16 20:16:10 torbenh Exp $ | |||
| #include "netjack_packet.h" | |||
| // JACK2 | |||
| #include "jack/control.h" | |||
| #include "control.h" | |||
| #define MIN(x,y) ((x)<(y) ? (x) : (y)) | |||
| @@ -105,8 +105,8 @@ int netjack_wait( netjack_driver_state_t *netj ) | |||
| netj->expected_framecnt += 1; | |||
| } else { | |||
| // starting up.... lets look into the packetcache, and fetch the highest packet. | |||
| packet_cache_drain_socket( global_packcache, netj->sockfd ); | |||
| if( packet_cache_get_highest_available_framecnt( global_packcache, &next_frame_avail ) ) { | |||
| packet_cache_drain_socket( netj->packcache, netj->sockfd ); | |||
| if( packet_cache_get_highest_available_framecnt( netj->packcache, &next_frame_avail ) ) { | |||
| netj->expected_framecnt = next_frame_avail; | |||
| netj->expected_framecnt_valid = 1; | |||
| } else { | |||
| @@ -122,7 +122,7 @@ int netjack_wait( netjack_driver_state_t *netj ) | |||
| // then poll (have deadline calculated) | |||
| // then drain socket, rinse and repeat. | |||
| while(1) { | |||
| if( packet_cache_get_next_available_framecnt( global_packcache, netj->expected_framecnt, &next_frame_avail) ) { | |||
| if( packet_cache_get_next_available_framecnt( netj->packcache, netj->expected_framecnt, &next_frame_avail) ) { | |||
| if( next_frame_avail == netj->expected_framecnt ) { | |||
| we_have_the_expected_frame = 1; | |||
| if( !netj->always_deadline ) | |||
| @@ -133,13 +133,13 @@ int netjack_wait( netjack_driver_state_t *netj ) | |||
| break; | |||
| } | |||
| packet_cache_drain_socket( global_packcache, netj->sockfd ); | |||
| packet_cache_drain_socket( netj->packcache, netj->sockfd ); | |||
| } | |||
| // check if we know who to send our packets too. | |||
| if (!netj->srcaddress_valid) | |||
| if( global_packcache->master_address_valid ) { | |||
| memcpy (&(netj->syncsource_address), &(global_packcache->master_address), sizeof( struct sockaddr_in ) ); | |||
| if( netj->packcache->master_address_valid ) { | |||
| memcpy (&(netj->syncsource_address), &(netj->packcache->master_address), sizeof( struct sockaddr_in ) ); | |||
| netj->srcaddress_valid = 1; | |||
| } | |||
| @@ -161,7 +161,7 @@ int netjack_wait( netjack_driver_state_t *netj ) | |||
| else | |||
| netj->time_to_deadline = 0; | |||
| packet_cache_retreive_packet_pointer( global_packcache, netj->expected_framecnt, (char **) &(netj->rx_buf), netj->rx_bufsize , &packet_recv_time_stamp); | |||
| packet_cache_retreive_packet_pointer( netj->packcache, netj->expected_framecnt, (char **) &(netj->rx_buf), netj->rx_bufsize , &packet_recv_time_stamp); | |||
| pkthdr = (jacknet_packet_header *) netj->rx_buf; | |||
| packet_header_ntoh(pkthdr); | |||
| netj->deadline_goodness = (int)pkthdr->sync_state; | |||
| @@ -203,7 +203,7 @@ int netjack_wait( netjack_driver_state_t *netj ) | |||
| // lets check if we have the next packets, we will just run a cycle without data. | |||
| // in that case. | |||
| if( packet_cache_get_next_available_framecnt( global_packcache, netj->expected_framecnt, &next_frame_avail) ) | |||
| if( packet_cache_get_next_available_framecnt( netj->packcache, netj->expected_framecnt, &next_frame_avail) ) | |||
| { | |||
| jack_nframes_t offset = next_frame_avail - netj->expected_framecnt; | |||
| @@ -221,7 +221,7 @@ int netjack_wait( netjack_driver_state_t *netj ) | |||
| // I also found this happening, when the packet queue, is too full. | |||
| // but wtf ? use a smaller latency. this link can handle that ;S | |||
| if( packet_cache_get_fill( global_packcache, netj->expected_framecnt ) > 80.0 ) | |||
| if( packet_cache_get_fill( netj->packcache, netj->expected_framecnt ) > 80.0 ) | |||
| netj->next_deadline -= netj->period_usecs/2; | |||
| @@ -229,7 +229,7 @@ int netjack_wait( netjack_driver_state_t *netj ) | |||
| // the diff is too high. but we have a packet in the future. | |||
| // lets resync. | |||
| netj->expected_framecnt = next_frame_avail; | |||
| packet_cache_retreive_packet_pointer( global_packcache, netj->expected_framecnt, (char **) &(netj->rx_buf), netj->rx_bufsize, NULL ); | |||
| packet_cache_retreive_packet_pointer( netj->packcache, netj->expected_framecnt, (char **) &(netj->rx_buf), netj->rx_bufsize, NULL ); | |||
| pkthdr = (jacknet_packet_header *) netj->rx_buf; | |||
| packet_header_ntoh(pkthdr); | |||
| //netj->deadline_goodness = 0; | |||
| @@ -257,7 +257,7 @@ int netjack_wait( netjack_driver_state_t *netj ) | |||
| // i will make the packet cache drop redundant packets, | |||
| // that have already been retreived. | |||
| // | |||
| if( packet_cache_get_highest_available_framecnt( global_packcache, &next_frame_avail) ) { | |||
| if( packet_cache_get_highest_available_framecnt( netj->packcache, &next_frame_avail) ) { | |||
| if( next_frame_avail == (netj->expected_framecnt - 1) ) { | |||
| // Ok. the last packet is there now. | |||
| // and it had not been retrieved. | |||
| @@ -277,9 +277,9 @@ int netjack_wait( netjack_driver_state_t *netj ) | |||
| // But now we can check for any new frame available. | |||
| // | |||
| if( packet_cache_get_highest_available_framecnt( global_packcache, &next_frame_avail) ) { | |||
| if( packet_cache_get_highest_available_framecnt( netj->packcache, &next_frame_avail) ) { | |||
| netj->expected_framecnt = next_frame_avail; | |||
| packet_cache_retreive_packet_pointer( global_packcache, netj->expected_framecnt, (char **) &(netj->rx_buf), netj->rx_bufsize, NULL ); | |||
| packet_cache_retreive_packet_pointer( netj->packcache, netj->expected_framecnt, (char **) &(netj->rx_buf), netj->rx_bufsize, NULL ); | |||
| pkthdr = (jacknet_packet_header *) netj->rx_buf; | |||
| packet_header_ntoh(pkthdr); | |||
| netj->deadline_goodness = pkthdr->sync_state; | |||
| @@ -300,7 +300,7 @@ int netjack_wait( netjack_driver_state_t *netj ) | |||
| // reply address changes port. | |||
| if (netj->num_lost_packets > 200 ) { | |||
| netj->srcaddress_valid = 0; | |||
| packet_cache_reset_master_address( global_packcache ); | |||
| packet_cache_reset_master_address( netj->packcache ); | |||
| } | |||
| } | |||
| } | |||
| @@ -369,6 +369,21 @@ void netjack_attach( netjack_driver_state_t *netj ) | |||
| int port_flags; | |||
| if( netj->bitdepth == CELT_MODE ) | |||
| { | |||
| #if HAVE_CELT | |||
| #if HAVE_CELT_API_0_7 || HAVE_CELT_API_0_8 | |||
| celt_int32 lookahead; | |||
| netj->celt_mode = celt_mode_create( netj->sample_rate, netj->period_size, NULL ); | |||
| #else | |||
| celt_int32_t lookahead; | |||
| netj->celt_mode = celt_mode_create( netj->sample_rate, 1, netj->period_size, NULL ); | |||
| #endif | |||
| celt_mode_info( netj->celt_mode, CELT_GET_LOOKAHEAD, &lookahead ); | |||
| netj->codec_latency = 2*lookahead; | |||
| #endif | |||
| } | |||
| if (netj->handle_transport_sync) | |||
| jack_set_sync_callback(netj->client, (JackSyncCallback) net_driver_sync_cb, NULL); | |||
| @@ -390,17 +405,11 @@ void netjack_attach( netjack_driver_state_t *netj ) | |||
| if( netj->bitdepth == CELT_MODE ) { | |||
| #if HAVE_CELT | |||
| #if HAVE_CELT_API_0_7 | |||
| celt_int32 lookahead; | |||
| CELTMode *celt_mode = celt_mode_create( netj->sample_rate, netj->period_size, NULL ); | |||
| netj->capture_srcs = jack_slist_append(netj->capture_srcs, celt_decoder_create( celt_mode, 1, NULL ) ); | |||
| #if HAVE_CELT_API_0_7 || HAVE_CELT_API_0_8 | |||
| netj->capture_srcs = jack_slist_append(netj->capture_srcs, celt_decoder_create( netj->celt_mode, 1, NULL ) ); | |||
| #else | |||
| celt_int32_t lookahead; | |||
| CELTMode *celt_mode = celt_mode_create( netj->sample_rate, 1, netj->period_size, NULL ); | |||
| netj->capture_srcs = jack_slist_append(netj->capture_srcs, celt_decoder_create( celt_mode ) ); | |||
| netj->capture_srcs = jack_slist_append(netj->capture_srcs, celt_decoder_create( netj->celt_mode ) ); | |||
| #endif | |||
| celt_mode_info( celt_mode, CELT_GET_LOOKAHEAD, &lookahead ); | |||
| netj->codec_latency = 2*lookahead; | |||
| #endif | |||
| } else { | |||
| #if HAVE_SAMPLERATE | |||
| @@ -408,6 +417,7 @@ void netjack_attach( netjack_driver_state_t *netj ) | |||
| #endif | |||
| } | |||
| } | |||
| for (chn = netj->capture_channels_audio; chn < netj->capture_channels; chn++) { | |||
| snprintf (buf, sizeof(buf) - 1, "capture_%u", chn + 1); | |||
| @@ -441,7 +451,7 @@ void netjack_attach( netjack_driver_state_t *netj ) | |||
| jack_slist_append (netj->playback_ports, port); | |||
| if( netj->bitdepth == CELT_MODE ) { | |||
| #if HAVE_CELT | |||
| #if HAVE_CELT_API_0_7 | |||
| #if HAVE_CELT_API_0_7 || HAVE_CELT_API_0_8 | |||
| CELTMode *celt_mode = celt_mode_create( netj->sample_rate, netj->period_size, NULL ); | |||
| netj->playback_srcs = jack_slist_append(netj->playback_srcs, celt_encoder_create( celt_mode, 1, NULL ) ); | |||
| #else | |||
| @@ -479,7 +489,6 @@ void netjack_detach( netjack_driver_state_t *netj ) | |||
| { | |||
| JSList * node; | |||
| for (node = netj->capture_ports; node; node = jack_slist_next (node)) | |||
| jack_port_unregister (netj->client, | |||
| ((jack_port_t *) node->data)); | |||
| @@ -487,12 +496,57 @@ void netjack_detach( netjack_driver_state_t *netj ) | |||
| jack_slist_free (netj->capture_ports); | |||
| netj->capture_ports = NULL; | |||
| for (node = netj->capture_srcs; node; node = jack_slist_next (node)) | |||
| { | |||
| #if HAVE_CELT | |||
| if( netj->bitdepth == CELT_MODE ) | |||
| { | |||
| CELTDecoder * decoder = node->data; | |||
| celt_decoder_destroy(decoder); | |||
| } | |||
| else | |||
| #endif | |||
| { | |||
| #if HAVE_SAMPLERATE | |||
| SRC_STATE * src = node->data; | |||
| src_delete(src); | |||
| #endif | |||
| } | |||
| } | |||
| jack_slist_free (netj->capture_srcs); | |||
| netj->playback_srcs = NULL; | |||
| for (node = netj->playback_ports; node; node = jack_slist_next (node)) | |||
| jack_port_unregister (netj->client, | |||
| ((jack_port_t *) node->data)); | |||
| jack_slist_free (netj->playback_ports); | |||
| netj->playback_ports = NULL; | |||
| for (node = netj->playback_srcs; node; node = jack_slist_next (node)) | |||
| { | |||
| #if HAVE_CELT | |||
| if( netj->bitdepth == CELT_MODE ) | |||
| { | |||
| CELTEncoder * encoder = node->data; | |||
| celt_encoder_destroy(encoder); | |||
| } | |||
| else | |||
| #endif | |||
| { | |||
| #if HAVE_SAMPLERATE | |||
| SRC_STATE * src = node->data; | |||
| src_delete(src); | |||
| #endif | |||
| } | |||
| } | |||
| jack_slist_free (netj->playback_srcs); | |||
| netj->playback_srcs = NULL; | |||
| #if HAVE_CELT | |||
| if( netj->bitdepth == CELT_MODE ) | |||
| celt_mode_destroy(netj->celt_mode); | |||
| #endif | |||
| } | |||
| @@ -574,8 +628,8 @@ void netjack_release( netjack_driver_state_t *netj ) | |||
| close( netj->sockfd ); | |||
| close( netj->outsockfd ); | |||
| packet_cache_free( global_packcache ); | |||
| global_packcache = NULL; | |||
| packet_cache_free( netj->packcache ); | |||
| netj->packcache = NULL; | |||
| } | |||
| int | |||
| @@ -585,13 +639,7 @@ netjack_startup( netjack_driver_state_t *netj ) | |||
| struct sockaddr_in address; | |||
| // Now open the socket, and wait for the first packet to arrive... | |||
| netj->sockfd = socket (AF_INET, SOCK_DGRAM, 0); | |||
| #ifdef WIN32 | |||
| u_long parm = 1; | |||
| DWORD bufsize = 262144; | |||
| //ioctlsocket( netj->sockfd, FIONBIO, &parm ); | |||
| setsockopt( netj->sockfd, SOL_SOCKET, SO_RCVBUF, (char *)&bufsize, sizeof(bufsize) ); | |||
| setsockopt( netj->sockfd, SOL_SOCKET, SO_SNDBUF, (char *)&bufsize, sizeof(bufsize) ); | |||
| if (netj->sockfd == INVALID_SOCKET) | |||
| #else | |||
| if (netj->sockfd == -1) | |||
| @@ -632,6 +680,10 @@ netjack_startup( netjack_driver_state_t *netj ) | |||
| //jack_info ("*** IMPORTANT *** Dont connect a client to jackd until the driver is attached to a clock source !!!"); | |||
| while(1) { | |||
| if( ! netjack_poll( netj->sockfd, 1000 ) ) { | |||
| jack_info ("Waiting aborted"); | |||
| return -1; | |||
| } | |||
| first_pack_len = recvfrom (netj->sockfd, (char *)first_packet, sizeof (jacknet_packet_header), 0, (struct sockaddr*) & netj->syncsource_address, &address_size); | |||
| #ifdef WIN32 | |||
| if( first_pack_len == -1 ) { | |||
| @@ -735,7 +787,7 @@ netjack_startup( netjack_driver_state_t *netj ) | |||
| } | |||
| netj->rx_bufsize = sizeof (jacknet_packet_header) + netj->net_period_down * netj->capture_channels * get_sample_size (netj->bitdepth); | |||
| global_packcache = packet_cache_new (netj->latency + 50, netj->rx_bufsize, netj->mtu); | |||
| netj->packcache = packet_cache_new (netj->latency + 50, netj->rx_bufsize, netj->mtu); | |||
| netj->expected_framecnt_valid = 0; | |||
| netj->num_lost_packets = 0; | |||
| @@ -30,6 +30,10 @@ | |||
| #include "jack/jslist.h" | |||
| #if HAVE_CELT | |||
| #include <celt/celt.h> | |||
| #endif | |||
| //#include <netinet/in.h> | |||
| #ifdef __cplusplus | |||
| @@ -37,6 +41,8 @@ extern "C" | |||
| { | |||
| #endif | |||
| struct _packet_cache; | |||
| typedef struct _netjack_driver_state netjack_driver_state_t; | |||
| struct _netjack_driver_state { | |||
| @@ -106,6 +112,10 @@ struct _netjack_driver_state { | |||
| unsigned int resample_factor; | |||
| unsigned int resample_factor_up; | |||
| int jitter_val; | |||
| struct _packet_cache * packcache; | |||
| #if HAVE_CELT | |||
| CELTMode *celt_mode; | |||
| #endif | |||
| }; | |||
| int netjack_wait( netjack_driver_state_t *netj ); | |||
| @@ -75,7 +75,7 @@ | |||
| #include "netjack_packet.h" | |||
| // JACK2 specific. | |||
| #include "jack/control.h" | |||
| #include "control.h" | |||
| #ifdef NO_JACK_ERROR | |||
| #define jack_error printf | |||
| @@ -83,8 +83,6 @@ | |||
| int fraggo = 0; | |||
| packet_cache *global_packcache = NULL; | |||
| void | |||
| packet_header_hton (jacknet_packet_header *pkthdr) | |||
| { | |||
| @@ -388,7 +386,7 @@ netjack_poll_deadline (int sockfd, jack_time_t deadline) | |||
| #if HAVE_PPOLL | |||
| timeout_spec.tv_nsec = (deadline - now) * 1000; | |||
| #else | |||
| timeout = (deadline - now + 500) / 1000; | |||
| timeout = lrintf( (float)(deadline - now) / 1000.0 ); | |||
| #endif | |||
| @@ -565,7 +563,7 @@ packet_cache_drain_socket( packet_cache *pcache, int sockfd ) | |||
| if( pcache->last_framecnt_retreived_valid && (framecnt <= pcache->last_framecnt_retreived )) | |||
| continue; | |||
| cpack = packet_cache_get_packet (global_packcache, framecnt); | |||
| cpack = packet_cache_get_packet (pcache, framecnt); | |||
| cache_packet_add_fragment (cpack, rx_packet, rcv_len); | |||
| cpack->recv_timestamp = jack_get_time(); | |||
| } | |||
| @@ -774,61 +772,6 @@ packet_cache_find_latency( packet_cache *pcache, jack_nframes_t expected_framecn | |||
| return retval; | |||
| } | |||
| // fragmented packet IO | |||
| int | |||
| netjack_recvfrom (int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, size_t *addr_size, int mtu) | |||
| { | |||
| int retval; | |||
| socklen_t from_len = *addr_size; | |||
| if (pkt_size <= mtu) { | |||
| retval = recvfrom (sockfd, packet_buf, pkt_size, flags, addr, &from_len); | |||
| *addr_size = from_len; | |||
| return retval; | |||
| } | |||
| char *rx_packet = alloca (mtu); | |||
| jacknet_packet_header *pkthdr = (jacknet_packet_header *) rx_packet; | |||
| int rcv_len; | |||
| jack_nframes_t framecnt; | |||
| cache_packet *cpack; | |||
| do | |||
| { | |||
| rcv_len = recvfrom (sockfd, rx_packet, mtu, 0, addr, &from_len); | |||
| if (rcv_len < 0) | |||
| return rcv_len; | |||
| framecnt = ntohl (pkthdr->framecnt); | |||
| cpack = packet_cache_get_packet (global_packcache, framecnt); | |||
| cache_packet_add_fragment (cpack, rx_packet, rcv_len); | |||
| } while (!cache_packet_is_complete (cpack)); | |||
| memcpy (packet_buf, cpack->packet_buf, pkt_size); | |||
| cache_packet_reset (cpack); | |||
| *addr_size = from_len; | |||
| return pkt_size; | |||
| } | |||
| int | |||
| netjack_recv (int sockfd, char *packet_buf, int pkt_size, int flags, int mtu) | |||
| { | |||
| if (pkt_size <= mtu) | |||
| return recv (sockfd, packet_buf, pkt_size, flags); | |||
| char *rx_packet = alloca (mtu); | |||
| jacknet_packet_header *pkthdr = (jacknet_packet_header *) rx_packet; | |||
| int rcv_len; | |||
| jack_nframes_t framecnt; | |||
| cache_packet *cpack; | |||
| do | |||
| { | |||
| rcv_len = recv (sockfd, rx_packet, mtu, flags); | |||
| if (rcv_len < 0) | |||
| return rcv_len; | |||
| framecnt = ntohl (pkthdr->framecnt); | |||
| cpack = packet_cache_get_packet (global_packcache, framecnt); | |||
| cache_packet_add_fragment (cpack, rx_packet, rcv_len); | |||
| } while (!cache_packet_is_complete (cpack)); | |||
| memcpy (packet_buf, cpack->packet_buf, pkt_size); | |||
| cache_packet_reset (cpack); | |||
| return pkt_size; | |||
| } | |||
| void | |||
| netjack_sendto (int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, int addr_size, int mtu) | |||
| { | |||
| @@ -1427,10 +1370,17 @@ render_payload_to_jack_ports_celt (void *packet_payload, jack_nframes_t net_peri | |||
| // audio port, decode celt data. | |||
| CELTDecoder *decoder = src_node->data; | |||
| #if HAVE_CELT_API_0_8 | |||
| if( !packet_payload ) | |||
| celt_decode_float( decoder, NULL, net_period_down, buf, nframes ); | |||
| else | |||
| celt_decode_float( decoder, packet_bufX, net_period_down, buf, nframes ); | |||
| #else | |||
| if( !packet_payload ) | |||
| celt_decode_float( decoder, NULL, net_period_down, buf ); | |||
| else | |||
| celt_decode_float( decoder, packet_bufX, net_period_down, buf ); | |||
| #endif | |||
| src_node = jack_slist_next (src_node); | |||
| } | |||
| @@ -1472,7 +1422,11 @@ render_jack_ports_to_payload_celt (JSList *playback_ports, JSList *playback_srcs | |||
| float *floatbuf = alloca (sizeof(float) * nframes ); | |||
| memcpy( floatbuf, buf, nframes*sizeof(float) ); | |||
| CELTEncoder *encoder = src_node->data; | |||
| #if HAVE_CELT_API_0_8 | |||
| encoded_bytes = celt_encode_float( encoder, floatbuf, nframes, packet_bufX, net_period_up ); | |||
| #else | |||
| encoded_bytes = celt_encode_float( encoder, floatbuf, NULL, packet_bufX, net_period_up ); | |||
| #endif | |||
| if( encoded_bytes != net_period_up ) | |||
| printf( "something in celt changed. netjack needs to be changed to handle this.\n" ); | |||
| src_node = jack_slist_next( src_node ); | |||
| @@ -107,8 +107,6 @@ struct _packet_cache | |||
| int last_framecnt_retreived_valid; | |||
| }; | |||
| extern packet_cache *global_packcache; | |||
| // fragment cache function prototypes | |||
| // XXX: Some of these are private. | |||
| packet_cache *packet_cache_new(int num_packets, int pkt_size, int mtu); | |||
| @@ -152,10 +150,6 @@ void render_jack_ports_to_payload(int bitdepth, JSList *playback_ports, JSList * | |||
| // This one waits forever. an is not using ppoll | |||
| int netjack_poll(int sockfd, int timeout); | |||
| // TODO: these are deprecated. | |||
| //int netjack_recvfrom(int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, socklen_t *addr_size, int mtu); | |||
| //int netjack_recv(int sockfd, char *packet_buf, int pkt_size, int flags, int mtu); | |||
| void decode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf); | |||
| void encode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf); | |||
| #ifdef __cplusplus | |||
| @@ -86,6 +86,7 @@ int reply_port = 0; | |||
| int bind_port = 0; | |||
| int redundancy = 1; | |||
| jack_client_t *client; | |||
| packet_cache * packcache = 0; | |||
| int state_connected = 0; | |||
| int state_latency = 0; | |||
| @@ -140,7 +141,7 @@ alloc_ports (int n_capture_audio, int n_playback_audio, int n_capture_midi, int | |||
| } | |||
| if( bitdepth == 1000 ) { | |||
| #if HAVE_CELT | |||
| #if HAVE_CELT_API_0_7 | |||
| #if 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 | |||
| @@ -183,7 +184,7 @@ alloc_ports (int n_capture_audio, int n_playback_audio, int n_capture_midi, int | |||
| } | |||
| if( bitdepth == 1000 ) { | |||
| #if HAVE_CELT | |||
| #if HAVE_CELT_API_0_7 | |||
| #if 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 | |||
| @@ -224,6 +225,9 @@ sync_cb (jack_transport_state_t state, jack_position_t *pos, void *arg) | |||
| static int latency_count = 0; | |||
| int retval = sync_state; | |||
| if (! state_connected) { | |||
| return 1; | |||
| } | |||
| if (latency_count) { | |||
| latency_count--; | |||
| retval = 0; | |||
| @@ -329,7 +333,7 @@ process (jack_nframes_t nframes, void *arg) | |||
| else if (cont_miss > 50+5*latency) | |||
| { | |||
| state_connected = 0; | |||
| packet_cache_reset_master_address( global_packcache ); | |||
| packet_cache_reset_master_address( packcache ); | |||
| //printf ("Frame %d \tRealy too many packets missed (%d). Let's reset the counter\n", framecnt, cont_miss); | |||
| cont_miss = 0; | |||
| } | |||
| @@ -355,19 +359,19 @@ process (jack_nframes_t nframes, void *arg) | |||
| if ( ! netjack_poll_deadline( input_fd, deadline ) ) | |||
| break; | |||
| packet_cache_drain_socket(global_packcache, input_fd); | |||
| packet_cache_drain_socket(packcache, input_fd); | |||
| if (packet_cache_get_next_available_framecnt( global_packcache, framecnt - latency, &got_frame )) | |||
| if (packet_cache_get_next_available_framecnt( packcache, framecnt - latency, &got_frame )) | |||
| if( got_frame == (framecnt - latency) ) | |||
| break; | |||
| } | |||
| } else { | |||
| // normally: | |||
| // only drain socket. | |||
| packet_cache_drain_socket(global_packcache, input_fd); | |||
| packet_cache_drain_socket(packcache, input_fd); | |||
| } | |||
| size = packet_cache_retreive_packet_pointer( global_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 ); | |||
| /* First alternative : we received what we expected. Render the data | |||
| * to the JACK ports so it can be played. */ | |||
| if (size == rx_bufsize) | |||
| @@ -394,7 +398,7 @@ process (jack_nframes_t nframes, void *arg) | |||
| state_recv_packet_queue_time = recv_time_offset; | |||
| state_connected = 1; | |||
| sync_state = pkthdr_rx->sync_state; | |||
| packet_cache_release_packet( global_packcache, framecnt - latency ); | |||
| packet_cache_release_packet( packcache, framecnt - latency ); | |||
| } | |||
| /* Second alternative : we've received something that's not | |||
| * as big as expected or we missed a packet. We render silence | |||
| @@ -402,7 +406,7 @@ process (jack_nframes_t nframes, void *arg) | |||
| else | |||
| { | |||
| jack_nframes_t latency_estimate; | |||
| if( packet_cache_find_latency( global_packcache, framecnt, &latency_estimate ) ) | |||
| if( packet_cache_find_latency( packcache, framecnt, &latency_estimate ) ) | |||
| //if( (state_latency == 0) || (latency_estimate < state_latency) ) | |||
| state_latency = latency_estimate; | |||
| @@ -468,7 +472,7 @@ process (jack_nframes_t nframes, void *arg) | |||
| else if (cont_miss > 50+5*latency) | |||
| { | |||
| state_connected = 0; | |||
| packet_cache_reset_master_address( global_packcache ); | |||
| packet_cache_reset_master_address( packcache ); | |||
| //printf ("Frame %d \tRealy too many packets missed (%d). Let's reset the counter\n", framecnt, cont_miss); | |||
| cont_miss = 0; | |||
| } | |||
| @@ -501,12 +505,11 @@ init_sockaddr_in (struct sockaddr_in *name , const char *hostname , uint16_t por | |||
| if (hostinfo == NULL) { | |||
| fprintf (stderr, "init_sockaddr_in: unknown host: %s.\n", hostname); | |||
| fflush( stderr ); | |||
| return; | |||
| } | |||
| #ifdef WIN32 | |||
| name->sin_addr.s_addr = inet_addr( hostname ); | |||
| name->sin_addr.s_addr = inet_addr( hostname ); | |||
| #else | |||
| name->sin_addr = *(struct in_addr *) hostinfo->h_addr ; | |||
| name->sin_addr = *(struct in_addr *) hostinfo->h_addr ; | |||
| #endif | |||
| } | |||
| else | |||
| @@ -621,15 +624,15 @@ main (int argc, char *argv[]) | |||
| case 'b': | |||
| bitdepth = atoi (optarg); | |||
| break; | |||
| case 'c': | |||
| #if HAVE_CELT | |||
| bitdepth = 1000; | |||
| case 'c': | |||
| #if HAVE_CELT | |||
| bitdepth = 1000; | |||
| factor = atoi (optarg); | |||
| #else | |||
| #else | |||
| printf( "not built with celt supprt\n" ); | |||
| exit(10); | |||
| #endif | |||
| break; | |||
| #endif | |||
| break; | |||
| case 'm': | |||
| mtu = atoi (optarg); | |||
| break; | |||
| @@ -676,17 +679,18 @@ main (int argc, char *argv[]) | |||
| } | |||
| 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); | |||
| 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); | |||
| 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 */ | |||
| @@ -712,7 +716,7 @@ main (int argc, char *argv[]) | |||
| 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); | |||
| global_packcache = packet_cache_new (latency + 50, rx_bufsize, mtu); | |||
| packcache = packet_cache_new (latency + 50, rx_bufsize, mtu); | |||
| /* tell the JACK server that we are ready to roll */ | |||
| if (jack_activate (client)) | |||
| @@ -778,6 +782,6 @@ main (int argc, char *argv[]) | |||
| } | |||
| jack_client_close (client); | |||
| packet_cache_free (global_packcache); | |||
| packet_cache_free (packcache); | |||
| exit (0); | |||
| } | |||
| @@ -125,12 +125,6 @@ def build(bld): | |||
| prog.includes = os_incdir + ['../common/jack', '../common'] | |||
| prog.source = ['netsource.c', '../common/netjack_packet.c'] | |||
| prog.env.append_value("CCFLAGS", "-DNO_JACK_ERROR") | |||
| # Seems uneeded here... | |||
| #if bld.env['HAVE_CELT']: | |||
| #if bld.env['HAVE_CELT_API_0_5']: | |||
| # prog.defines = ['HAVE_CELT', 'HAVE_CELT_API_0_5'] | |||
| #elif bld.env['HAVE_CELT_API_0_7']: | |||
| # prog.defines = ['HAVE_CELT', 'HAVE_CELT_API_0_7'] | |||
| prog.uselib = 'CELT SAMPLERATE' | |||
| prog.uselib_local = 'clientlib' | |||
| prog.target = 'jack_netsource' | |||
| @@ -1203,14 +1203,14 @@ | |||
| isa = PBXContainerItemProxy; | |||
| containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */; | |||
| proxyType = 1; | |||
| remoteGlobalIDString = 4B8F16DB13290DC80002AD73 /* jack_midi_dump Universal */; | |||
| remoteGlobalIDString = 4B8F16DB13290DC80002AD73; | |||
| remoteInfo = "jack_midi_dump Universal"; | |||
| }; | |||
| 4B8F16FB1329169F0002AD73 /* PBXContainerItemProxy */ = { | |||
| isa = PBXContainerItemProxy; | |||
| containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */; | |||
| proxyType = 1; | |||
| remoteGlobalIDString = 4B8F16E813290E0E0002AD73 /* jack_midi_dump 64 bits */; | |||
| remoteGlobalIDString = 4B8F16E813290E0E0002AD73; | |||
| remoteInfo = "jack_midi_dump 64 bits"; | |||
| }; | |||
| 4BA693E80CBE5BBA00EAD520 /* PBXContainerItemProxy */ = { | |||
| @@ -6,12 +6,6 @@ def create_jack_driver_obj(bld, target, sources, uselib = None): | |||
| driver.features.append('cc') | |||
| driver.env['shlib_PATTERN'] = 'jack_%s.so' | |||
| driver.defines = ['HAVE_CONFIG_H','SERVER_SIDE'] | |||
| # Seems uneeded here... | |||
| #if bld.env['HAVE_CELT']: | |||
| #if bld.env['HAVE_CELT_API_0_5']: | |||
| # driver.defines += ['HAVE_CELT', 'HAVE_CELT_API_0_5'] | |||
| #elif bld.env['HAVE_CELT_API_0_7']: | |||
| # driver.defines += ['HAVE_CELT', 'HAVE_CELT_API_0_7'] | |||
| driver.includes = ['.', '../macosx', '../posix', '../common', '../common/jack'] | |||
| driver.target = target | |||
| driver.source = sources | |||
| @@ -129,18 +129,26 @@ def configure(conf): | |||
| conf.fatal('jackdbus was explicitly requested but cannot be built') | |||
| conf.sub_config('example-clients') | |||
| if conf.check_cfg(package='celt', atleast_version='0.7.0', args='--cflags --libs'): | |||
| if conf.check_cfg(package='celt', atleast_version='0.8.0', args='--cflags --libs'): | |||
| conf.define('HAVE_CELT', 1) | |||
| conf.define('HAVE_CELT_API_0_8', 1) | |||
| conf.define('HAVE_CELT_API_0_7', 0) | |||
| conf.define('HAVE_CELT_API_0_5', 0) | |||
| elif conf.check_cfg(package='celt', atleast_version='0.7.0', args='--cflags --libs'): | |||
| conf.define('HAVE_CELT', 1) | |||
| conf.define('HAVE_CELT_API_0_8', 0) | |||
| conf.define('HAVE_CELT_API_0_7', 1) | |||
| conf.define('HAVE_CELT_API_0_5', 0) | |||
| elif conf.check_cfg(package='celt', atleast_version='0.5.0', args='--cflags --libs', required=True): | |||
| conf.define('HAVE_CELT', 1) | |||
| conf.define('HAVE_CELT_API_0_5', 1) | |||
| conf.define('HAVE_CELT_API_0_8', 0) | |||
| conf.define('HAVE_CELT_API_0_7', 0) | |||
| conf.define('HAVE_CELT_API_0_5', 1) | |||
| else: | |||
| conf.define('HAVE_CELT', 0) | |||
| conf.define('HAVE_CELT_API_0_5', 0) | |||
| conf.define('HAVE_CELT_API_0_8', 0) | |||
| conf.define('HAVE_CELT_API_0_7', 0) | |||
| conf.define('HAVE_CELT_API_0_5', 0) | |||
| conf.env['LIB_PTHREAD'] = ['pthread'] | |||
| conf.env['LIB_DL'] = ['dl'] | |||