4
* Purpose: Internal definitions for the OS audio core
8
* This file contains internal structures used by Open Sound Systems.
9
* They will change without any notice between OSS versions. Care must be taken
10
* to make sure any software using this header gets properly re-compiled before
13
* 4Front Technologies (or anybody else) takes no responsibility of damages
14
* caused by use of this file.
19
* This file is part of Open Sound System.
21
* Copyright (C) 4Front Technologies 1996-2008.
23
* This this source file is released under GPL v2 license (no other versions).
24
* See the COPYING file included in the main directory of this source
25
* distribution for the license terms and conditions.
30
* Max number of audio channels currently supported by the sample format converter.
32
#define OSS_MAX_CONVERT_CHANNELS 64
35
* Size of the temporary buffer used for audio conversions.
37
* TMP_CONVERT_MAX defines how many bytes can be fed to the converter in
40
* TMP_CONVERT_BUF_SIZE defines how many bytes of buffer will be allocated.
41
* This is larger than TMP_CONVERT_MAX because amount of data may get expanded
42
* during the conversion (for example if the output sampling rate or #channels
43
* is larger than in the input side).
45
#define TMP_CONVERT_MAX (16*1024)
46
#define TMP_CONVERT_BUF_SIZE (8*TMP_CONVERT_MAX)
49
* open_flags (for opening audio devices)
51
#define OF_MMAP 0x00000001 /* Opening application is known to use mmap() */
52
#define OF_BLOCK 0x00000002 /* Disable O_NONBLOCK */
53
#define OF_NOCONV 0x00000010 /* Disable all fmt/src conversions */
54
#define OF_DEVAUDIO 0x00000020 /* Solaris /dev/audio emulator */
55
#define OF_SMALLFRAGS 0x00000040 /* Use smaller fragments than requested */
56
#define OF_SMALLBUF 0x00000080 /* Allocate small (4k) buffer this time */
57
#define OF_MEDIUMBUF 0x00000100 /* Allocate moderate (16k) buffer */
59
#define CONVERTABLE_FORMATS \
60
(AFMT_U8|AFMT_S8|AFMT_MU_LAW|AFMT_S16_LE|AFMT_S16_BE|\
61
AFMT_S24_LE|AFMT_S24_BE|AFMT_S32_LE|AFMT_S32_BE|AFMT_S24_PACKED)
64
typedef struct _audiodrv_t audiodrv_t;
71
unsigned char neutral_byte;
76
#define ENDIAN_LITTLE 1
79
# define ENDIAN_NATIVE ENDIAN_BIG
81
# define ENDIAN_NATIVE ENDIAN_LITTLE
90
audio_format_info_t, *audio_format_info_p;
94
int fmt, rate, channels;
99
typedef struct _adev_t adev_t, *adev_p;
100
typedef struct _dmap_t *dmap_p;
101
typedef int (*cnv_func_t) (adev_p adev, dmap_p dmap, unsigned char **srcp, int *srcl,
102
unsigned char **tgtp, sample_parms * source,
103
sample_parms * target);
108
* Static fields (not to be cleared during open)
114
oss_device_t *master_osdev; /* The osdev pointer of the master (for virtual drivers) */
116
unsigned char *dmabuf;
117
oss_native_word dmabuf_phys;
118
oss_dma_handle_t dmabuf_dma_handle;
120
int buffer_protected; /* Buffer is shared - don't modify/clear */
121
unsigned char *tmpbuf1, *tmpbuf2;
122
void *driver_use_ptr;
123
long driver_use_value;
124
/* Interrupt callback stuff */
125
void (*audio_callback) (int dev, int parm);
132
* Dynamic fields (will be zeroed during open)
133
* Don't add anything before flags.
135
void *srcstate[OSS_MAX_CONVERT_CHANNELS];
136
oss_native_word flags;
137
#define DMAP_NOTIMEOUT 0x00000001
138
#define DMAP_POST 0x00000002
139
#define DMAP_PREPARED 0x00000004
140
#define DMAP_FRAGFIXED 0x00000008 /* Fragment size fixed */
141
#define DMAP_STARTED 0x00000010
142
#define DMAP_COOKED 0x00000020
143
#define DMAP_SMALLBUF 0x00000040 /* Allocate small buffers */
144
#define DMAP_MEDIUMBUF 0x00000040 /* Allocate 16k buffers */
145
int dma_mode; /* PCM_ENABLE_INPUT, PCM_ENABLE_OUTPUT or 0 */
153
int data_rate; /* Bytes/second */
154
int frame_size; /* Device frame size */
155
int user_frame_size; /* Application frame size */
157
int low_water, low_water_rq;
158
volatile oss_uint64_t byte_counter;
159
volatile oss_uint64_t user_counter;
161
int fragment_counter;
165
#define DMA_MAP_MAPPED 0x00000001
169
int play_underruns, rec_overruns;
172
#define MAX_AUDIO_ERRORS 5
173
int errors[MAX_AUDIO_ERRORS];
174
int error_parms[MAX_AUDIO_ERRORS];
176
unsigned char *leftover_buf;
178
int tmpbuf_len, tmpbuf_ptr;
179
cnv_func_t convert_func;
180
unsigned int convert_mode;
181
struct audio_buffer *(*user_import) (adev_t * adev,
183
sample_parms * parms,
184
unsigned char *cbuf, int len);
185
int (*user_export) (adev_t * adev,
186
dmap_t * dmap, sample_parms * parms,
187
struct audio_buffer * buf, unsigned char *cbuf,
189
struct audio_buffer *(*device_read) (adev_t * adev,
191
sample_parms * parms,
192
unsigned char *cbuf, int len);
193
int (*device_write) (adev_t * adev,
195
void *frombuf, void *tobuf,
196
int maxspace, int *fromlen, int *tolen);
198
extern int dmap_get_qlen (dmap_t * dmap);
199
extern int dmap_get_qhead (dmap_t * dmap);
200
extern int dmap_get_qtail (dmap_t * dmap);
206
int engine_num; /* Audio engine number */
207
int audio_devfile; /* Audio device file number */
210
struct _adev_t *next_in, *next_out; /* Links to the next "shadow" devices */
215
int magic; /* Secret low level driver ID */
216
int latency; /* In usecs, -1=unknown */
220
* Sampling parameters
223
sample_parms user_parms, hw_parms;
224
int iformat_mask, oformat_mask; /* Bitmasks for supported audio formats */
225
int min_rate, max_rate; /* Sampling rate limits */
226
int min_channels, max_channels;
227
char *inch_names, *outch_names;
228
int xformat_mask; /* Format mask for current open mode */
230
void *devc; /* Driver specific info */
232
void *portc, *portc_play, *portc_record; /* Driver specific info */
233
dmap_t *dmap_in, *dmap_out;
238
int parent_dev; /* 0 -> no parent, 1 to n -> parent=parent_dev+1 */
239
int max_block; /* Maximum fragment size to be accepted */
240
int min_block; /* Minimum fragment size */
241
int min_fragments; /* Minimum number of fragments */
242
int max_fragments; /* Maximum number of fragments */
243
int max_intrate; /* Another form of min_block */
244
int dmabuf_alloc_flags;
245
oss_uint64_t dmabuf_maxaddr;
247
int vmix_flags; /* special flags sent to virtual mixer */
248
#define VMIX_MULTIFRAG 0x00000001 /* More than 2 fragments required (causes longer latencies) */
249
#define VMIX_DISABLED 0x00000002 /* Not compatible with vmix */
250
#define VMIX_NOINPUT 0x00000004 /* Disable input capability */
251
#define VMIX_NOMAINVOL 0x00000008 /* No main volume sliders/meters please */
255
oss_device_t *master_osdev; /* The osdev pointer of the master (for virtual drivers) */
256
int setfragment_warned;
257
int getispace_error_count;
258
int redirect_in, redirect_out;
259
int dmask; /* Open dmaps */
260
#define DMASK_OUT 0x01
261
#define DMASK_IN 0x02
266
#define SYNC_MASTER 0x01
267
#define SYNC_SLAVE 0x02
270
adev_t *sync_next; /* Next device in sync group */
273
unsigned int nrates, rates[OSS_MAX_SAMPLE_RATES + 1];
277
oss_wait_queue_t *out_wq, *in_wq;
285
* By default OSS will let applications to use sampling rates and formats
286
* that are not supported by the hardware. Instead OSS performs the necessary
287
* format conversions in software. Applications that don't tolerate this kind
288
* of conversions usually disable them by using features of the OSS API
289
* (SNDCTL_DSP_COOKEDMODE). If this option is set to 0 then the format
290
* conversions will be disabled for all applications and devices unless the
291
* application explicitly enables them.
293
* cooked_enable is a global variable (int) defined in oss_core_options.c. The current
294
* value of this global variable will be copied to adev->cooked_enable when
295
* an audio engine is opened.
300
void (*outputintr) (int dev, int intr_flags);
301
void (*inputintr) (int dev, int intr_flags);
304
void *os_id; /* The device ID (dip) given by the system. */
305
oss_longname_t song_name;
307
oss_devnode_t devnode;
308
void *vmix_mixer; /* Pointer to the vmix_mixer_t structure for this device */
309
void *prev_vmix_mixer; /* Reserved for vmix_core */
312
#define UNIT_EXPAND 1024
315
* The audio_devfiles and audio_engines tables contain pointers to
316
* the (same) adev_t structures. The difference is that
317
* audio_engines contains an entry for all audio devices/engines in the system
318
* (including hidden and shadow devices). The 'dev' parameter of most audio
319
* core routines and audio driver methods are indexes to this array.
321
* The audio_devfiles array is a "parallel" structure that contains only
322
* the audio engines that have a device file in /dev/oss (and usually also
323
* an legacy /dev/dsp# device file). This audio_devfiles array doesn't contain
324
* "hidden" audio engines.
326
* Each audio operations structure in audio_devfiles will also be in
327
* audio_engines but the indexes are different. Both arrays contain pointer to
328
* the same structure in memory (not a copy).
330
* For example the 6th audio device file (usually but not always /dev/dsp5) is
331
* audio_devfiles[5]. However it may be (say) audio_engines[11] if there are
332
* hidden devices created before it.
334
* /dev/dsp5 -> audio_devfile[5] == audio_engines[11]
336
* The next field of the adev_t structure contains a pointer
337
* to the next "identical" device. Most OSS implementations will
338
* try to open one of the subsequent devices in the next chain if
339
* the original device was busy. "Identical" means that the device suports
340
* multiple identical (hw mixing) engines or the vmix driver is used to
341
* add software mixing capability to the device.
344
extern adev_t **audio_engines;
345
extern int num_audio_engines;
346
extern adev_t **audio_devfiles;
347
extern int num_audio_devfiles;
353
unsigned short devices[MAX_AUDIO_DEVFILES];
357
extern oss_devlist_t dspoutlist, dspoutlist2, dspinlist, dspinoutlist;
360
int oss_install_audiodev (int vers,
361
oss_device_t * osdev,
362
oss_device_t * master_osdev,
364
const audiodrv_t * driver,
366
unsigned long long flags,
367
unsigned int format_mask, void *devc, int parent);
369
int oss_install_audiodev_with_devname (int vers,
370
oss_device_t * osdev,
371
oss_device_t * master_osdev,
373
const audiodrv_t * driver,
376
unsigned int format_mask, void *devc, int parent,
377
const char *devfile_name);
378
extern void install_vdsp (oss_device_t * osdev);
379
extern int *load_mixer_volumes (char *name, int *levels, int present);
382
int oss_audio_read (int dev, struct fileinfo *file, uio_t * buf, int count);
383
int oss_audio_write (int dev, struct fileinfo *file, uio_t * buf, int count);
384
int oss_audio_open_engine (int dev, int dev_class, struct fileinfo *file,
385
int recursive, int open_flags, int *newdev);
386
int oss_audio_open_devfile (int dev, int dev_class, struct fileinfo *file,
387
int recursive, int open_flags, int *newdev);
388
int oss_open_vdsp (int dev, int dev_type, struct fileinfo *file,
389
int recursive, int open_flags, int *newdev);
390
void oss_audio_release (int dev, struct fileinfo *file);
391
int oss_audio_ioctl (int dev, struct fileinfo *file,
392
unsigned int cmd, ioctl_arg arg);
393
int oss_audio_set_format (int dev, int fmt, int format_mask);
394
int oss_audio_set_channels (int dev, int ch);
395
int oss_audio_set_rate (int dev, int val);
396
void audio_uninit_device (int dev);
397
int oss_audio_mmap (int dev, int direction);
400
/* From audiofmt.c */
401
int setup_format_conversions (adev_p adev, dmap_p dmap, sample_parms * source,
402
sample_parms * target,
404
sample_parms * device, int format_mask);
405
audio_format_info_p oss_find_format (unsigned int fmt);
408
#define oss_audio_outputintr(dev, flags) audio_engines[dev]->outputintr(dev, flags)
409
#define oss_audio_inputintr(dev, flags) audio_engines[dev]->inputintr(dev, flags)
410
void oss_audio_reset (int dev);
411
void oss_audio_start_syncgroup (unsigned int syncgroup);
412
typedef int (*oss_audio_startup_func) (void *devc);
413
extern void oss_audio_register_client (oss_audio_startup_func func,
414
void *devc, oss_device_t * osdev);
416
extern int oss_encode_enum (oss_mixer_enuminfo * ei, const char *s,
418
extern char *audio_show_latency (int dev);
419
extern void oss_audio_inc_byte_counter (dmap_t * dmap, int increment);
420
extern void oss_add_audio_devlist (int list, int devfile);
422
#ifndef SMALL_DMABUF_SIZE
423
#define SMALL_DMABUF_SIZE (4*1024)
426
#define MEDIUM_DMABUF_SIZE (16*1024)