Jack2 1.9.6
|
00001 00002 /* 00003 * NetJack - Packet Handling functions 00004 * 00005 * used by the driver and the jacknet_client 00006 * 00007 * Copyright (C) 2006 Torben Hohn <torbenh@gmx.de> 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00022 * 00023 * $Id: net_driver.c,v 1.16 2006/03/20 19:41:37 torbenh Exp $ 00024 * 00025 */ 00026 00027 #ifndef __JACK_NET_PACKET_H__ 00028 #define __JACK_NET_PACKET_H__ 00029 00030 #ifdef __cplusplus 00031 extern "C" 00032 { 00033 #endif 00034 00035 #include <jack/jack.h> 00036 #include <jack/types.h> 00037 //#include <jack/engine.h> 00038 #include <jack/jslist.h> 00039 00040 #include <jack/midiport.h> 00041 00042 //#include <netinet/in.h> 00043 // The Packet Header. 00044 00045 #define CELT_MODE 1000 // Magic bitdepth value that indicates CELT compression 00046 #define MASTER_FREEWHEELS 0x80000000 00047 00048 typedef struct _jacknet_packet_header jacknet_packet_header; 00049 00050 struct _jacknet_packet_header 00051 { 00052 // General AutoConf Data 00053 jack_nframes_t capture_channels_audio; 00054 jack_nframes_t playback_channels_audio; 00055 jack_nframes_t capture_channels_midi; 00056 jack_nframes_t playback_channels_midi; 00057 jack_nframes_t period_size; 00058 jack_nframes_t sample_rate; 00059 00060 // Transport Sync 00061 jack_nframes_t sync_state; 00062 jack_nframes_t transport_frame; 00063 jack_nframes_t transport_state; 00064 00065 // Packet loss Detection, and latency reduction 00066 jack_nframes_t framecnt; 00067 jack_nframes_t latency; 00068 00069 jack_nframes_t reply_port; 00070 jack_nframes_t mtu; 00071 jack_nframes_t fragment_nr; 00072 }; 00073 00074 typedef union _int_float int_float_t; 00075 00076 union _int_float 00077 { 00078 uint32_t i; 00079 float f; 00080 }; 00081 00082 // fragment reorder cache. 00083 typedef struct _cache_packet cache_packet; 00084 00085 struct _cache_packet 00086 { 00087 int valid; 00088 int num_fragments; 00089 int packet_size; 00090 int mtu; 00091 jack_time_t recv_timestamp; 00092 jack_nframes_t framecnt; 00093 char * fragment_array; 00094 char * packet_buf; 00095 }; 00096 00097 typedef struct _packet_cache packet_cache; 00098 00099 struct _packet_cache 00100 { 00101 int size; 00102 cache_packet *packets; 00103 int mtu; 00104 struct sockaddr_in master_address; 00105 int master_address_valid; 00106 jack_nframes_t last_framecnt_retreived; 00107 int last_framecnt_retreived_valid; 00108 }; 00109 00110 extern packet_cache *global_packcache; 00111 00112 // fragment cache function prototypes 00113 // XXX: Some of these are private. 00114 packet_cache *packet_cache_new(int num_packets, int pkt_size, int mtu); 00115 void packet_cache_free(packet_cache *pkt_cache); 00116 00117 cache_packet *packet_cache_get_packet(packet_cache *pkt_cache, jack_nframes_t framecnt); 00118 cache_packet *packet_cache_get_oldest_packet(packet_cache *pkt_cache); 00119 cache_packet *packet_cache_get_free_packet(packet_cache *pkt_cache); 00120 00121 void cache_packet_reset(cache_packet *pack); 00122 void cache_packet_set_framecnt(cache_packet *pack, jack_nframes_t framecnt); 00123 void cache_packet_add_fragment(cache_packet *pack, char *packet_buf, int rcv_len); 00124 int cache_packet_is_complete(cache_packet *pack); 00125 00126 void packet_cache_drain_socket( packet_cache *pcache, int sockfd ); 00127 void packet_cache_reset_master_address( packet_cache *pcache ); 00128 float packet_cache_get_fill( packet_cache *pcache, jack_nframes_t expected_framecnt ); 00129 int packet_cache_retreive_packet_pointer( packet_cache *pcache, jack_nframes_t framecnt, char **packet_buf, int pkt_size, jack_time_t *timestamp ); 00130 int packet_cache_release_packet( packet_cache *pcache, jack_nframes_t framecnt ); 00131 int packet_cache_get_next_available_framecnt( packet_cache *pcache, jack_nframes_t expected_framecnt, jack_nframes_t *framecnt ); 00132 int packet_cache_get_highest_available_framecnt( packet_cache *pcache, jack_nframes_t *framecnt ); 00133 int packet_cache_find_latency( packet_cache *pcache, jack_nframes_t expected_framecnt, jack_nframes_t *framecnt ); 00134 // Function Prototypes 00135 00136 int netjack_poll_deadline (int sockfd, jack_time_t deadline); 00137 00138 void netjack_sendto(int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, int addr_size, int mtu); 00139 00140 00141 int get_sample_size(int bitdepth); 00142 void packet_header_hton(jacknet_packet_header *pkthdr); 00143 00144 void packet_header_ntoh(jacknet_packet_header *pkthdr); 00145 00146 void render_payload_to_jack_ports(int bitdepth, void *packet_payload, jack_nframes_t net_period_down, JSList *capture_ports, JSList *capture_srcs, jack_nframes_t nframes, int dont_htonl_floats ); 00147 00148 void render_jack_ports_to_payload(int bitdepth, JSList *playback_ports, JSList *playback_srcs, jack_nframes_t nframes, void *packet_payload, jack_nframes_t net_period_up, int dont_htonl_floats ); 00149 00150 00151 // XXX: This is sort of deprecated: 00152 // This one waits forever. an is not using ppoll 00153 int netjack_poll(int sockfd, int timeout); 00154 00155 // TODO: these are deprecated. 00156 //int netjack_recvfrom(int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, socklen_t *addr_size, int mtu); 00157 //int netjack_recv(int sockfd, char *packet_buf, int pkt_size, int flags, int mtu); 00158 00159 void decode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf); 00160 void encode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf); 00161 #ifdef __cplusplus 00162 } 00163 #endif 00164 #endif 00165