Jack2 1.9.12

netjack_packet.h
1
2 /*
3 * NetJack - Packet Handling functions
4 *
5 * used by the driver and the jacknet_client
6 *
7 * Copyright (C) 2006 Torben Hohn <torbenh@gmx.de>
8 *
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.
13 *
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.
18 *
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.
22 *
23 * $Id: net_driver.c,v 1.16 2006/03/20 19:41:37 torbenh Exp $
24 *
25 */
26
27 #ifndef __JACK_NET_PACKET_H__
28 #define __JACK_NET_PACKET_H__
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34
35 #include <jack/jack.h>
36 #include <jack/types.h>
37 #include <jack/jslist.h>
38 #include <jack/midiport.h>
39
40 // The Packet Header.
41
42 #define CELT_MODE 1000 // Magic bitdepth value that indicates CELT compression
43 #define OPUS_MODE 999 // Magic bitdepth value that indicates OPUS compression
44 #define MASTER_FREEWHEELS 0x80000000
45
46 typedef struct _jacknet_packet_header jacknet_packet_header;
47
48 struct _jacknet_packet_header {
49 // General AutoConf Data
50 jack_nframes_t capture_channels_audio;
51 jack_nframes_t playback_channels_audio;
52 jack_nframes_t capture_channels_midi;
53 jack_nframes_t playback_channels_midi;
54 jack_nframes_t period_size;
55 jack_nframes_t sample_rate;
56
57 // Transport Sync
58 jack_nframes_t sync_state;
59 jack_nframes_t transport_frame;
60 jack_nframes_t transport_state;
61
62 // Packet loss Detection, and latency reduction
63 jack_nframes_t framecnt;
64 jack_nframes_t latency;
65
66 jack_nframes_t reply_port;
67 jack_nframes_t mtu;
68 jack_nframes_t fragment_nr;
69 };
70
71 typedef union _int_float int_float_t;
72
73 union _int_float {
74 uint32_t i;
75 float f;
76 };
77
78 // fragment reorder cache.
79 typedef struct _cache_packet cache_packet;
80
81 struct _cache_packet {
82 int valid;
83 int num_fragments;
84 int packet_size;
85 int mtu;
86 jack_time_t recv_timestamp;
87 jack_nframes_t framecnt;
88 char * fragment_array;
89 char * packet_buf;
90 };
91
92 typedef struct _packet_cache packet_cache;
93
94 struct _packet_cache {
95 int size;
96 cache_packet *packets;
97 int mtu;
98 struct sockaddr_in master_address;
99 int master_address_valid;
100 jack_nframes_t last_framecnt_retreived;
101 int last_framecnt_retreived_valid;
102 };
103
104 // fragment cache function prototypes
105 // XXX: Some of these are private.
106 packet_cache *packet_cache_new(int num_packets, int pkt_size, int mtu);
107 void packet_cache_free(packet_cache *pkt_cache);
108
109 cache_packet *packet_cache_get_packet(packet_cache *pkt_cache, jack_nframes_t framecnt);
110 cache_packet *packet_cache_get_oldest_packet(packet_cache *pkt_cache);
111 cache_packet *packet_cache_get_free_packet(packet_cache *pkt_cache);
112
113 void cache_packet_reset(cache_packet *pack);
114 void cache_packet_set_framecnt(cache_packet *pack, jack_nframes_t framecnt);
115 void cache_packet_add_fragment(cache_packet *pack, char *packet_buf, int rcv_len);
116 int cache_packet_is_complete(cache_packet *pack);
117
118 void packet_cache_drain_socket( packet_cache *pcache, int sockfd );
119 void packet_cache_reset_master_address( packet_cache *pcache );
120 float packet_cache_get_fill( packet_cache *pcache, jack_nframes_t expected_framecnt );
121 int packet_cache_retreive_packet_pointer( packet_cache *pcache, jack_nframes_t framecnt, char **packet_buf, int pkt_size, jack_time_t *timestamp );
122 int packet_cache_release_packet( packet_cache *pcache, jack_nframes_t framecnt );
123 int packet_cache_get_next_available_framecnt( packet_cache *pcache, jack_nframes_t expected_framecnt, jack_nframes_t *framecnt );
124 int packet_cache_get_highest_available_framecnt( packet_cache *pcache, jack_nframes_t *framecnt );
125 int packet_cache_find_latency( packet_cache *pcache, jack_nframes_t expected_framecnt, jack_nframes_t *framecnt );
126
127 // Function Prototypes
128
129 int netjack_poll_deadline (int sockfd, jack_time_t deadline);
130 void netjack_sendto(int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, int addr_size, int mtu);
131 int get_sample_size(int bitdepth);
132 void packet_header_hton(jacknet_packet_header *pkthdr);
133 void packet_header_ntoh(jacknet_packet_header *pkthdr);
134 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 );
135 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 );
136
137 // XXX: This is sort of deprecated:
138 // This one waits forever. an is not using ppoll
139 int netjack_poll(int sockfd, int timeout);
140
141 void decode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf);
142 void encode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf);
143
144 #ifdef __cplusplus
145 }
146 #endif
147 #endif
148
_packet_cache
Definition: netjack_packet.h:94
_cache_packet
Definition: netjack_packet.h:81
_int_float
Definition: netjack_packet.h:73
_jacknet_packet_header
Definition: netjack_packet.h:48
_JSList
Definition: linux/alsa/jslist.h:35