root/trunk/libfreebob/src/libfreebobstreaming/freebob_connections.h

Revision 194, 6.0 kB (checked in by pieterpalmers, 18 years ago)

- code cleanup in the streaming part.
- calculate ISO connection parameters instead of user-supplying them
- SSE code improvement

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  *   FreeBob Streaming API
3  *   FreeBob = Firewire (pro-)audio for linux
4  *
5  *   http://freebob.sf.net
6  *
7  *   Copyright (C) 2005 Pieter Palmers <pieterpalmers@users.sourceforge.net>
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  *
24  *
25  */
26
27 /* freebob_connections.h
28  *
29  * Connection handling
30  *
31  */
32 #ifndef __FREEBOB_CONNECTIONS_H__
33 #define __FREEBOB_CONNECTIONS_H__
34
35 #include "cip.h"
36
37 #include "libfreebob/freebob.h"
38 #include "ringbuffer.h"
39 #include <errno.h>
40 #include <stdio.h>
41 #include <string.h>
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 #define TIMESTAMP_BUFFER_SIZE 512
48
49 /*
50  * ISO/AM824 packet structures
51  */
52 #if __BYTE_ORDER == __BIG_ENDIAN
53
54 struct iso_packet_header {
55         unsigned int data_length : 16;
56         unsigned int tag         : 2;
57         unsigned int channel     : 6;
58         unsigned int tcode       : 4;
59         unsigned int sy          : 4;
60 };
61
62
63 typedef struct packet_info packet_info_t;
64 struct packet_info {
65         /* The first part of this structure is a copy of the CIP header
66          * This can be memcpy'd from the packet itself.
67          */
68         /* First quadlet */
69         unsigned int dbs      : 8;
70         unsigned int eoh0     : 2;
71         unsigned int sid      : 6;
72
73         unsigned int dbc      : 8;
74         unsigned int fn       : 2;
75         unsigned int qpc      : 3;
76         unsigned int sph      : 1;
77         unsigned int reserved : 2;
78
79         /* Second quadlet */
80         unsigned int fdf      : 8;
81         unsigned int eoh1     : 2;
82         unsigned int fmt      : 6;
83
84         unsigned int syt      : 16;
85
86         /* the second part is some extra info */
87         unsigned int nevents;
88         unsigned int length;
89 };
90
91 #elif __BYTE_ORDER == __LITTLE_ENDIAN
92
93 struct iso_packet_header {
94         unsigned int data_length : 16;
95         unsigned int channel     : 6;
96         unsigned int tag         : 2;
97         unsigned int sy          : 4;
98         unsigned int tcode       : 4;
99 };
100
101 typedef struct packet_info packet_info_t;
102 struct packet_info {
103         /* The first part of this structure is a copy of the CIP header
104          * This can be memcpy'd from the packet itself.
105          */
106         /* First quadlet */
107         unsigned int sid      : 6;
108         unsigned int eoh0     : 2;
109         unsigned int dbs      : 8;
110
111         unsigned int reserved : 2;
112         unsigned int sph      : 1;
113         unsigned int qpc      : 3;
114         unsigned int fn       : 2;
115         unsigned int dbc      : 8;
116
117         /* Second quadlet */
118         unsigned int fmt      : 6;
119         unsigned int eoh1     : 2;
120         unsigned int fdf      : 8;
121
122         unsigned int syt      : 16;
123
124         /* the second part is some extra info */
125         unsigned int nevents;
126         unsigned int length;
127 };
128
129
130 #else
131
132 #error Unknown bitfield type
133
134 #endif
135 typedef struct _freebob_timestamp freebob_timestamp_t;
136
137 /**
138  * Timestamp structure
139  */
140 struct _freebob_timestamp {
141         unsigned int syt;
142         unsigned int cycle;
143 };
144
145 /*
146  * Connection definition
147  */
148
149 typedef struct _freebob_iso_status {
150         int buffers;
151         int prebuffers;
152         int irq_interval;
153         int startcycle;
154         enum raw1394_iso_dma_recv_mode receive_mode;
155
156         int iso_channel;
157         int do_disconnect;
158         int bandwidth;
159
160         int packets_per_period;
161         int max_packet_size; // tailored to result in optimal IRQ timing
162         int packet_size; // expected packet size
163        
164         int hostplug;
165        
166         enum raw1394_iso_speed speed;
167 } freebob_iso_status_t;
168
169 typedef struct _freebob_connection_status {
170         int packets;
171         int events;
172         int total_events;
173
174         int frames_left;
175
176         int iso_channel;
177        
178         int xruns;
179                
180         struct iec61883_cip cip;
181        
182         int dropped;
183        
184        
185 #ifdef DEBUG
186         int fdf;
187         int total_packets_prev;
188         int last_cycle;
189 #endif
190
191         int packet_info_table_size;
192         packet_info_t *packet_info_table;
193        
194         struct _freebob_connection_status *master;
195
196         freebob_timestamp_t last_timestamp;     
197        
198 } freebob_connection_status_t;
199
200 typedef struct _freebob_stream freebob_stream_t;
201 typedef struct _freebob_connection freebob_connection_t;
202
203 struct _freebob_connection {
204         freebob_device_t *parent;
205        
206         freebob_connection_spec_t spec;
207 //      freebob_stream_info_t stream_info;
208         freebob_connection_status_t status;
209         freebob_iso_status_t iso;
210        
211         /* pointer to the pollfd structure for this connection */
212         struct pollfd *pfd;
213        
214         /*
215          * The streams this connection is composed of
216          */
217         int nb_streams;
218         freebob_stream_t *streams;
219        
220         /*
221          * This is the buffer to decode/encode from samples from/to events
222          */
223         freebob_ringbuffer_t * event_buffer;
224         char * cluster_buffer;
225        
226         raw1394handle_t raw_handle;
227                
228        
229         /*
230          * This is the info needed for time stamp processing
231          */
232
233         unsigned int total_delay; // = transfer delay + processing delay
234         freebob_ringbuffer_t *timestamp_buffer;
235        
236 };
237
238 /**
239  * Stream definition
240  */
241
242 struct _freebob_stream {
243         freebob_stream_spec_t        spec;
244        
245         freebob_ringbuffer_t *buffer;
246         freebob_connection_t *parent;
247        
248         freebob_streaming_buffer_type buffer_type;
249         char *user_buffer;
250         unsigned int user_buffer_position;
251         int midi_counter;
252 };
253
254 /* Initializes a stream_t based upon an stream_info_t */
255 int freebob_streaming_init_stream(freebob_device_t* dev, freebob_stream_t *dst, freebob_stream_spec_t *src);
256
257 /* prefills a stream when the format needs it */
258 int freebob_streaming_prefill_stream(freebob_device_t* dev, freebob_stream_t *stream);
259
260 /* destroys a stream_t */
261 void freebob_streaming_cleanup_stream(freebob_device_t* dev, freebob_stream_t *dst);
262
263 /* put a stream into a known state */
264 int freebob_streaming_reset_stream(freebob_device_t* dev, freebob_stream_t *dst);
265
266 int freebob_streaming_init_connection(freebob_device_t * dev, freebob_connection_t *connection);
267 int freebob_streaming_cleanup_connection(freebob_device_t * dev, freebob_connection_t *connection);
268 int freebob_streaming_reset_connection(freebob_device_t * dev, freebob_connection_t *connection);
269
270
271
272 #ifdef __cplusplus
273 }
274 #endif
275
276 #endif
Note: See TracBrowser for help on using the browser.