~ubuntu-branches/ubuntu/oneiric/oss4/oneiric-proposed

« back to all changes in this revision

Viewing changes to kernel/framework/include/audio_core.h

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Rivera
  • Date: 2011-06-16 20:37:48 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110616203748-jbrxik6ql33z54co
Tags: 4.2-build2004-1ubuntu1
* Merge from Debian unstable.
  - Supports our current kernel (LP: #746048)
  Remaining changes:
  - debian/oss4-dkms.dkms.in: s/source/build/ in Kernel headers paths.
* ld-as-needed.patch: Re-order CC arguments to enable building with ld
  --as-needed (LP: #770972)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef AUDIO_CORE_H
 
2
#define AUDIO_CORE_H
 
3
/*
 
4
 * Purpose: Internal definitions for the OS audio core
 
5
 *
 
6
 * IMPORTANT NOTICE!
 
7
 *
 
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
 
11
 * use.
 
12
 *
 
13
 * 4Front Technologies (or anybody else) takes no responsibility of damages
 
14
 * caused by use of this file.
 
15
 */
 
16
 
 
17
/*
 
18
 *
 
19
 * This file is part of Open Sound System.
 
20
 *
 
21
 * Copyright (C) 4Front Technologies 1996-2008.
 
22
 *
 
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.
 
26
 *
 
27
 */
 
28
 
 
29
/*
 
30
 * Max number of audio channels currently supported by the sample format converter.
 
31
 */
 
32
#define OSS_MAX_CONVERT_CHANNELS        64
 
33
 
 
34
/*
 
35
 * Size of the temporary buffer used for audio conversions.
 
36
 *
 
37
 * TMP_CONVERT_MAX defines how many bytes can be fed to the converter in
 
38
 * one call.
 
39
 *
 
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).
 
44
 */
 
45
#define TMP_CONVERT_MAX         (16*1024)
 
46
#define TMP_CONVERT_BUF_SIZE    (8*TMP_CONVERT_MAX)
 
47
 
 
48
/*
 
49
 * open_flags (for opening audio devices)
 
50
 */
 
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 */
 
58
 
 
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)
 
62
 
 
63
#ifndef _KERNEL
 
64
typedef struct _audiodrv_t audiodrv_t;
 
65
#endif
 
66
 
 
67
typedef struct
 
68
{
 
69
  char *name;
 
70
  int fmt;
 
71
  unsigned char neutral_byte;
 
72
  char bits;
 
73
  char is_linear;
 
74
  char endianess;
 
75
#define ENDIAN_NONE             0
 
76
#define ENDIAN_LITTLE   1
 
77
#define ENDIAN_BIG              2
 
78
#ifdef OSS_BIG_ENDIAN
 
79
# define ENDIAN_NATIVE ENDIAN_BIG
 
80
#else
 
81
# define ENDIAN_NATIVE ENDIAN_LITTLE
 
82
#endif
 
83
 
 
84
  char is_signed;
 
85
  char alignment;
 
86
#define ALIGN_MSB               0
 
87
#define ALIGN_LSB               1
 
88
  int no_convert;
 
89
}
 
90
audio_format_info_t, *audio_format_info_p;
 
91
 
 
92
typedef struct
 
93
{
 
94
  int fmt, rate, channels;
 
95
  int convert;
 
96
}
 
97
sample_parms;
 
98
 
 
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);
 
104
 
 
105
struct _dmap_t
 
106
{
 
107
/*
 
108
 * Static fields (not to be cleared during open)
 
109
 */
 
110
#ifdef _KERNEL
 
111
  oss_mutex_t mutex;
 
112
#endif
 
113
  oss_device_t *osdev;
 
114
  oss_device_t *master_osdev;   /* The osdev pointer of the master (for virtual drivers) */
 
115
  adev_t *adev;
 
116
  unsigned char *dmabuf;
 
117
  oss_native_word dmabuf_phys;
 
118
  oss_dma_handle_t dmabuf_dma_handle;
 
119
  int buffsize;
 
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);
 
126
  int callback_parm;
 
127
 
 
128
#ifdef OS_DMA_PARMS
 
129
    OS_DMA_PARMS
 
130
#endif
 
131
/*
 
132
 * Dynamic fields (will be zeroed during open)
 
133
 * Don't add anything before flags.
 
134
 */
 
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 */
 
146
 
 
147
  /*
 
148
   * Queue parameters.
 
149
   */
 
150
  int nfrags;
 
151
  int fragment_size;
 
152
  int bytes_in_use;
 
153
  int data_rate;                /* Bytes/second */
 
154
  int frame_size;               /* Device frame size */
 
155
  int user_frame_size;          /* Application frame size */
 
156
  int fragsize_rq;
 
157
  int low_water, low_water_rq;
 
158
  volatile oss_uint64_t byte_counter;
 
159
  volatile oss_uint64_t user_counter;
 
160
  int interrupt_count;
 
161
  int fragment_counter;
 
162
  int expand_factor;
 
163
 
 
164
  int mapping_flags;
 
165
#define                 DMA_MAP_MAPPED          0x00000001
 
166
  char neutral_byte;
 
167
 
 
168
  int error;
 
169
  int play_underruns, rec_overruns;
 
170
  int underrun_flag;
 
171
  int num_errors;
 
172
#define MAX_AUDIO_ERRORS        5
 
173
  int errors[MAX_AUDIO_ERRORS];
 
174
  int error_parms[MAX_AUDIO_ERRORS];
 
175
 
 
176
  unsigned char *leftover_buf;
 
177
  int leftover_bytes;
 
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,
 
182
                                       dmap_t * dmap,
 
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,
 
188
                      int maxbytes);
 
189
  struct audio_buffer *(*device_read) (adev_t * adev,
 
190
                                       dmap_t * dmap,
 
191
                                       sample_parms * parms,
 
192
                                       unsigned char *cbuf, int len);
 
193
  int (*device_write) (adev_t * adev,
 
194
                       dmap_t * dmap,
 
195
                       void *frombuf, void *tobuf,
 
196
                       int maxspace, int *fromlen, int *tolen);
 
197
};
 
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);
 
201
 
 
202
struct _adev_t
 
203
{
 
204
  char name[64];
 
205
  char handle[32];
 
206
  int engine_num;               /* Audio engine number */
 
207
  int audio_devfile;            /* Audio device file number */
 
208
  int enabled;
 
209
  int unloaded;
 
210
  struct _adev_t *next_in, *next_out;   /* Links to the next "shadow" devices */
 
211
  long long flags;
 
212
  int open_flags;
 
213
  int src_quality;
 
214
  int caps;
 
215
  int magic;                    /* Secret low level driver ID */
 
216
  int latency;                  /* In usecs, -1=unknown */
 
217
 
 
218
 
 
219
  /*
 
220
   * Sampling parameters
 
221
   */
 
222
 
 
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 */
 
229
  int binding;
 
230
  void *devc;                   /* Driver specific info */
 
231
  audiodrv_t *d;
 
232
  void *portc, *portc_play, *portc_record;      /* Driver specific info */
 
233
  dmap_t *dmap_in, *dmap_out;
 
234
  int mixer_dev;
 
235
  int open_mode;
 
236
  int go;
 
237
  int enable_bits;
 
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;
 
246
  int fixed_rate;
 
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 */
 
252
  pid_t pid;
 
253
  char cmd[16];
 
254
  oss_device_t *osdev;
 
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
 
262
  int nonblock;
 
263
  int forced_nonblock;
 
264
  int ossd_registered;
 
265
  int sync_flags;
 
266
#define SYNC_MASTER             0x01
 
267
#define SYNC_SLAVE              0x02
 
268
  int sync_group;
 
269
  int sync_mode;
 
270
  adev_t *sync_next;            /* Next device in sync group */
 
271
 
 
272
  int rate_source;
 
273
  unsigned int nrates, rates[OSS_MAX_SAMPLE_RATES + 1];
 
274
 
 
275
#ifdef _KERNEL
 
276
  oss_mutex_t mutex;
 
277
  oss_wait_queue_t *out_wq, *in_wq;
 
278
#endif
 
279
 
 
280
  int card_number;
 
281
  int port_number;
 
282
  int real_dev;
 
283
 
 
284
/*
 
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.
 
292
 *
 
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.
 
296
 */
 
297
  int cooked_enable;
 
298
  int timeout_count;
 
299
 
 
300
  void (*outputintr) (int dev, int intr_flags);
 
301
  void (*inputintr) (int dev, int intr_flags);
 
302
 
 
303
  int policy;
 
304
  void *os_id;                  /* The device ID (dip) given by the system. */
 
305
  oss_longname_t song_name;
 
306
  oss_label_t label;
 
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 */
 
310
};
 
311
 
 
312
#define UNIT_EXPAND             1024
 
313
 
 
314
/*
 
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.
 
320
 *
 
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.
 
325
 *
 
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).
 
329
 *
 
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.
 
333
 *
 
334
 *  /dev/dsp5 -> audio_devfile[5] == audio_engines[11]
 
335
 *
 
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.
 
342
 */
 
343
 
 
344
extern adev_t **audio_engines;
 
345
extern int num_audio_engines;
 
346
extern adev_t **audio_devfiles;
 
347
extern int num_audio_devfiles;
 
348
 
 
349
#if 0
 
350
typedef struct
 
351
{
 
352
  int ndevs;
 
353
  unsigned short devices[MAX_AUDIO_DEVFILES];
 
354
}
 
355
oss_devlist_t;
 
356
 
 
357
extern oss_devlist_t dspoutlist, dspoutlist2, dspinlist, dspinoutlist;
 
358
#endif
 
359
 
 
360
int oss_install_audiodev (int vers,
 
361
                          oss_device_t * osdev,
 
362
                          oss_device_t * master_osdev,
 
363
                          char *name,
 
364
                          const audiodrv_t * driver,
 
365
                          int driver_size,
 
366
                          unsigned long long flags,
 
367
                          unsigned int format_mask, void *devc, int parent);
 
368
 
 
369
int oss_install_audiodev_with_devname (int vers,
 
370
                          oss_device_t * osdev,
 
371
                          oss_device_t * master_osdev,
 
372
                          char *name,
 
373
                          const audiodrv_t * driver,
 
374
                          int driver_size,
 
375
                          int flags,
 
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);
 
380
 
 
381
#ifdef _KERNEL
 
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);
 
398
#endif
 
399
 
 
400
/* From audiofmt.c */
 
401
int setup_format_conversions (adev_p adev, dmap_p dmap, sample_parms * source,
 
402
                              sample_parms * target,
 
403
                              sample_parms * user,
 
404
                              sample_parms * device, int format_mask);
 
405
audio_format_info_p oss_find_format (unsigned int fmt);
 
406
 
 
407
 
 
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);
 
415
 
 
416
extern int oss_encode_enum (oss_mixer_enuminfo * ei, const char *s,
 
417
                            int version);
 
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);
 
421
 
 
422
#ifndef SMALL_DMABUF_SIZE
 
423
#define SMALL_DMABUF_SIZE (4*1024)
 
424
#endif
 
425
 
 
426
#define MEDIUM_DMABUF_SIZE (16*1024)
 
427
#endif