Jack2
1.9.8
|
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/jslist.h> 00038 #include <jack/midiport.h> 00039 00040 // The Packet Header. 00041 00042 #define CELT_MODE 1000 // Magic bitdepth value that indicates CELT compression 00043 #define MASTER_FREEWHEELS 0x80000000 00044 00045 typedef struct _jacknet_packet_header jacknet_packet_header; 00046 00047 struct _jacknet_packet_header { 00048 // General AutoConf Data 00049 jack_nframes_t capture_channels_audio; 00050 jack_nframes_t playback_channels_audio; 00051 jack_nframes_t capture_channels_midi; 00052 jack_nframes_t playback_channels_midi; 00053 jack_nframes_t period_size; 00054 jack_nframes_t sample_rate; 00055 00056 // Transport Sync 00057 jack_nframes_t sync_state; 00058 jack_nframes_t transport_frame; 00059 jack_nframes_t transport_state; 00060 00061 // Packet loss Detection, and latency reduction 00062 jack_nframes_t framecnt; 00063 jack_nframes_t latency; 00064 00065 jack_nframes_t reply_port; 00066 jack_nframes_t mtu; 00067 jack_nframes_t fragment_nr; 00068 }; 00069 00070 typedef union _int_float int_float_t; 00071 00072 union _int_float { 00073 uint32_t i; 00074 float f; 00075 }; 00076 00077 // fragment reorder cache. 00078 typedef struct _cache_packet cache_packet; 00079 00080 struct _cache_packet { 00081 int valid; 00082 int num_fragments; 00083 int packet_size; 00084 int mtu; 00085 jack_time_t recv_timestamp; 00086 jack_nframes_t framecnt; 00087 char * fragment_array; 00088 char * packet_buf; 00089 }; 00090 00091 typedef struct _packet_cache packet_cache; 00092 00093 struct _packet_cache { 00094 int size; 00095 cache_packet *packets; 00096 int mtu; 00097 struct sockaddr_in master_address; 00098 int master_address_valid; 00099 jack_nframes_t last_framecnt_retreived; 00100 int last_framecnt_retreived_valid; 00101 }; 00102 00103 // fragment cache function prototypes 00104 // XXX: Some of these are private. 00105 packet_cache *packet_cache_new(int num_packets, int pkt_size, int mtu); 00106 void packet_cache_free(packet_cache *pkt_cache); 00107 00108 cache_packet *packet_cache_get_packet(packet_cache *pkt_cache, jack_nframes_t framecnt); 00109 cache_packet *packet_cache_get_oldest_packet(packet_cache *pkt_cache); 00110 cache_packet *packet_cache_get_free_packet(packet_cache *pkt_cache); 00111 00112 void cache_packet_reset(cache_packet *pack); 00113 void cache_packet_set_framecnt(cache_packet *pack, jack_nframes_t framecnt); 00114 void cache_packet_add_fragment(cache_packet *pack, char *packet_buf, int rcv_len); 00115 int cache_packet_is_complete(cache_packet *pack); 00116 00117 void packet_cache_drain_socket( packet_cache *pcache, int sockfd ); 00118 void packet_cache_reset_master_address( packet_cache *pcache ); 00119 float packet_cache_get_fill( packet_cache *pcache, jack_nframes_t expected_framecnt ); 00120 int packet_cache_retreive_packet_pointer( packet_cache *pcache, jack_nframes_t framecnt, char **packet_buf, int pkt_size, jack_time_t *timestamp ); 00121 int packet_cache_release_packet( packet_cache *pcache, jack_nframes_t framecnt ); 00122 int packet_cache_get_next_available_framecnt( packet_cache *pcache, jack_nframes_t expected_framecnt, jack_nframes_t *framecnt ); 00123 int packet_cache_get_highest_available_framecnt( packet_cache *pcache, jack_nframes_t *framecnt ); 00124 int packet_cache_find_latency( packet_cache *pcache, jack_nframes_t expected_framecnt, jack_nframes_t *framecnt ); 00125 00126 // Function Prototypes 00127 00128 int netjack_poll_deadline (int sockfd, jack_time_t deadline); 00129 void netjack_sendto(int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, int addr_size, int mtu); 00130 int get_sample_size(int bitdepth); 00131 void packet_header_hton(jacknet_packet_header *pkthdr); 00132 void packet_header_ntoh(jacknet_packet_header *pkthdr); 00133 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 ); 00134 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 ); 00135 00136 // XXX: This is sort of deprecated: 00137 // This one waits forever. an is not using ppoll 00138 int netjack_poll(int sockfd, int timeout); 00139 00140 void decode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf); 00141 void encode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf); 00142 00143 #ifdef __cplusplus 00144 } 00145 #endif 00146 #endif 00147