oops, paul should remember to try an OSX build before releasing a tarball; fixed...
[jack.git] / drivers / netjack / netjack_packet.h
blobc9ef00b8a21c335422aa2ed3dd67ee032f2ecccc
2 /*
3 * NetJack - Packet Handling functions
5 * used by the driver and the jacknet_client
7 * Copyright (C) 2006 Torben Hohn <torbenh@gmx.de>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * $Id: net_driver.c,v 1.16 2006/03/20 19:41:37 torbenh Exp $
27 #ifndef __JACK_NET_PACKET_H__
28 #define __JACK_NET_PACKET_H__
30 #include <jack/jack.h>
31 #include <jack/types.h>
32 #include <jack/engine.h>
34 #include <jack/midiport.h>
36 #include <netinet/in.h>
37 // The Packet Header.
39 typedef struct _jacknet_packet_header jacknet_packet_header;
41 struct _jacknet_packet_header
43 // General AutoConf Data
44 jack_nframes_t capture_channels_audio;
45 jack_nframes_t playback_channels_audio;
46 jack_nframes_t capture_channels_midi;
47 jack_nframes_t playback_channels_midi;
48 jack_nframes_t period_size;
49 jack_nframes_t sample_rate;
51 // Transport Sync
52 jack_nframes_t sync_state;
53 jack_nframes_t transport_frame;
54 jack_nframes_t transport_state;
56 // Packet loss Detection, and latency reduction
57 jack_nframes_t framecnt;
58 jack_nframes_t latency;
59 jack_nframes_t reply_port;
61 jack_nframes_t mtu;
62 jack_nframes_t fragment_nr;
65 typedef union _int_float int_float_t;
67 union _int_float
69 uint32_t i;
70 float f;
73 // fragment reorder cache.
74 typedef struct _cache_packet cache_packet;
76 struct _cache_packet
78 int valid;
79 int num_fragments;
80 int packet_size;
81 int mtu;
82 jack_nframes_t framecnt;
83 char * fragment_array;
84 char * packet_buf;
87 typedef struct _packet_cache packet_cache;
89 struct _packet_cache
91 int size;
92 cache_packet *packets;
95 extern packet_cache *global_packcache;
97 // fragment cache function prototypes
98 packet_cache *packet_cache_new(int num_packets, int pkt_size, int mtu);
99 void packet_cache_free(packet_cache *pkt_cache);
101 cache_packet *packet_cache_get_packet(packet_cache *pkt_cache, jack_nframes_t framecnt);
102 cache_packet *packet_cache_get_oldest_packet(packet_cache *pkt_cache);
103 cache_packet *packet_cache_get_free_packet(packet_cache *pkt_cache);
105 void cache_packet_reset(cache_packet *pack);
106 void cache_packet_set_framecnt(cache_packet *pack, jack_nframes_t framecnt);
107 void cache_packet_add_fragment(cache_packet *pack, char *packet_buf, int rcv_len);
108 int cache_packet_is_complete(cache_packet *pack);
110 // Function Prototypes
111 int netjack_poll(int sockfd, int timeout);
112 void netjack_sendto(int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, int addr_size, int mtu);
113 int netjack_recvfrom(int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, socklen_t *addr_size, int mtu);
114 int netjack_recv(int sockfd, char *packet_buf, int pkt_size, int flags, int mtu);
116 int get_sample_size(int bitdepth);
117 void packet_header_hton(jacknet_packet_header *pkthdr);
119 void packet_header_ntoh(jacknet_packet_header *pkthdr);
121 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);
123 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);
125 #endif