summaryrefslogtreecommitdiff
path: root/common/netjack.h
blob: 91c81be5dc1f0d1156a6cd177f04c8a846e5bea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

/*
    Copyright (C) 2003 Robert Ham <rah@bash.sh>
    Copyright (C) 2005 Torben Hohn <torbenh@gmx.de>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef __NETJACK_H__
#define __NETJACK_H__

#include <unistd.h>

#include <jack/types.h>
//#include <jack/driver.h>
#include <jack/jack.h>
#include <jack/transport.h>

#include "jack/jslist.h"

//#include <netinet/in.h>

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct _netjack_driver_state netjack_driver_state_t;

struct _netjack_driver_state {
    jack_nframes_t  net_period_up;
    jack_nframes_t  net_period_down;

    jack_nframes_t  sample_rate;
    jack_nframes_t  bitdepth;
    jack_nframes_t  period_size;
    jack_time_t	    period_usecs;
    int		    dont_htonl_floats;
    int		    always_deadline;

    jack_nframes_t  codec_latency;

    unsigned int    listen_port;

    unsigned int    capture_channels;
    unsigned int    playback_channels;
    unsigned int    capture_channels_audio;
    unsigned int    playback_channels_audio;
    unsigned int    capture_channels_midi;
    unsigned int    playback_channels_midi;

    JSList	    *capture_ports;
    JSList	    *playback_ports;
    JSList	    *playback_srcs;
    JSList	    *capture_srcs;

    jack_client_t   *client;

#ifdef WIN32
    SOCKET	    sockfd;
    SOCKET	    outsockfd;
#else
    int		    sockfd;
    int		    outsockfd;
#endif

    struct sockaddr_in syncsource_address;

    int		    reply_port;
    int		    srcaddress_valid;

    int sync_state;
    unsigned int handle_transport_sync;

    unsigned int *rx_buf;
    unsigned int *pkt_buf;
    unsigned int rx_bufsize;
    //unsigned int tx_bufsize;
    unsigned int mtu;
    unsigned int latency;
    unsigned int redundancy;

    jack_nframes_t expected_framecnt;
    int		   expected_framecnt_valid;
    unsigned int   num_lost_packets;
    jack_time_t	   next_deadline;
    jack_time_t	   deadline_offset;
    int		   next_deadline_valid;
    int		   packet_data_valid;
    int		   resync_threshold;
    int		   running_free;
    int		   deadline_goodness;
    jack_time_t	   time_to_deadline;
    unsigned int   use_autoconfig;
    unsigned int   resample_factor;
    unsigned int   resample_factor_up;
    int		   jitter_val;
};

int netjack_wait( netjack_driver_state_t *netj );
void netjack_send_silence( netjack_driver_state_t *netj, int syncstate );
void netjack_read( netjack_driver_state_t *netj, jack_nframes_t nframes ) ;
void netjack_write( netjack_driver_state_t *netj, jack_nframes_t nframes, int syncstate );
void netjack_attach( netjack_driver_state_t *netj );
void netjack_detach( netjack_driver_state_t *netj );

netjack_driver_state_t *netjack_init (netjack_driver_state_t *netj,
		jack_client_t * client,
                const char *name,
                unsigned int capture_ports,
                unsigned int playback_ports,
                unsigned int capture_ports_midi,
                unsigned int playback_ports_midi,
                jack_nframes_t sample_rate,
                jack_nframes_t period_size,
                unsigned int listen_port,
                unsigned int transport_sync,
                unsigned int resample_factor,
                unsigned int resample_factor_up,
                unsigned int bitdepth,
		unsigned int use_autoconfig,
		unsigned int latency,
		unsigned int redundancy,
		int dont_htonl_floats,
		int always_deadline,
		int jitter_val );

void netjack_release( netjack_driver_state_t *netj );
int netjack_startup( netjack_driver_state_t *netj );

#ifdef __cplusplus
}
#endif

#endif