blob: f538f0043bfe58a3df42791e0ce38e0d25210bb8 [file] [log] [blame]
Iliyan Malchev4765c432012-06-11 14:36:16 -07001/*
2** Copyright 2010, The Android Open-Source Project
Subhash Chandra Bose Naripeddy6000eb52013-01-05 18:02:44 -08003** Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Iliyan Malchev4765c432012-06-11 14:36:16 -07004**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef _AUDIO_H_
19#define _AUDIO_H_
20
21#include <sound/asound.h>
22#define PCM_ERROR_MAX 128
23
24struct pcm {
25 int fd;
26 int timer_fd;
27 unsigned rate;
28 unsigned channels;
29 unsigned flags;
30 unsigned format;
31 unsigned running:1;
32 int underruns;
33 unsigned buffer_size;
34 unsigned period_size;
35 unsigned period_cnt;
36 char error[PCM_ERROR_MAX];
37 struct snd_pcm_hw_params *hw_p;
38 struct snd_pcm_sw_params *sw_p;
39 struct snd_pcm_sync_ptr *sync_ptr;
40 struct snd_pcm_channel_info ch[2];
41 void *addr;
42 int card_no;
43 int device_no;
44 int start;
45};
Iliyan Malchev4765c432012-06-11 14:36:16 -070046#define FORMAT(v) SNDRV_PCM_FORMAT_##v
47
48#define PCM_OUT 0x00000000
49#define PCM_IN 0x10000000
50
51#define PCM_STEREO 0x00000000
52#define PCM_MONO 0x01000000
53#define PCM_QUAD 0x02000000
54#define PCM_5POINT1 0x04000000
Mingming Yinbbd94ad2012-11-29 20:04:36 -080055#define PCM_7POINT1 0x08000000
Iliyan Malchev4765c432012-06-11 14:36:16 -070056
57#define PCM_44100HZ 0x00000000
58#define PCM_48000HZ 0x00100000
59#define PCM_8000HZ 0x00200000
60#define PCM_RATE_MASK 0x00F00000
61
62#define PCM_MMAP 0x00010000
63#define PCM_NMMAP 0x00000000
64
65#define DEBUG_ON 0x00000001
66#define DEBUG_OFF 0x00000000
67
68#define PCM_PERIOD_CNT_MIN 2
69#define PCM_PERIOD_CNT_SHIFT 16
70#define PCM_PERIOD_CNT_MASK (0xF << PCM_PERIOD_CNT_SHIFT)
71#define PCM_PERIOD_SZ_MIN 128
72#define PCM_PERIOD_SZ_SHIFT 12
73#define PCM_PERIOD_SZ_MASK (0xF << PCM_PERIOD_SZ_SHIFT)
74
75#define TIMEOUT_INFINITE -1
76
77/* Acquire/release a pcm channel.
78 * Returns non-zero on error
79 */
80
81struct mixer_ctl {
82 struct mixer *mixer;
83 struct snd_ctl_elem_info *info;
84 char **ename;
85};
86
87#define __snd_alloca(ptr,type) do { *ptr = (type *) alloca(sizeof(type)); memset(*ptr, 0, sizeof(type)); } while (0)
88#define snd_ctl_elem_id_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_id)
89#define snd_ctl_card_info_alloca(ptr) __snd_alloca(ptr, snd_ctl_card_info)
90#define snd_ctl_event_alloca(ptr) __snd_alloca(ptr, snd_ctl_event)
91#define snd_ctl_elem_list_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_list)
92#define snd_ctl_elem_info_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_info)
93#define snd_ctl_elem_value_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_value)
94
95
96enum snd_pcm_stream_t {
97 /** Playback stream */
98 SND_PCM_STREAM_PLAYBACK = 0,
99 /** Capture stream */
100 SND_PCM_STREAM_CAPTURE,
101 SND_PCM_STREAM_LAST = SND_PCM_STREAM_CAPTURE
102};
103
104enum _snd_ctl_elem_iface {
105 /** Card level */
106 SND_CTL_ELEM_IFACE_CARD = 0,
107 /** Hardware dependent device */
108 SND_CTL_ELEM_IFACE_HWDEP,
109 /** Mixer */
110 SND_CTL_ELEM_IFACE_MIXER,
111 /** PCM */
112 SND_CTL_ELEM_IFACE_PCM,
113 /** RawMidi */
114 SND_CTL_ELEM_IFACE_RAWMIDI,
115 /** Timer */
116 SND_CTL_ELEM_IFACE_TIMER,
117 /** Sequencer */
118 SND_CTL_ELEM_IFACE_SEQUENCER,
119 SND_CTL_ELEM_IFACE_LAST = SND_CTL_ELEM_IFACE_SEQUENCER
120};
121
122struct mixer {
123 int fd;
124 struct snd_ctl_elem_info *info;
125 struct mixer_ctl *ctl;
126 unsigned count;
127};
128
129int get_format(const char* name);
130const char *get_format_name(int format);
131const char *get_format_desc(int format);
132struct pcm *pcm_open(unsigned flags, char *device);
133int pcm_close(struct pcm *pcm);
134int pcm_ready(struct pcm *pcm);
135int mmap_buffer(struct pcm *pcm);
136u_int8_t *dst_address(struct pcm *pcm);
137int sync_ptr(struct pcm *pcm);
138
139void param_init(struct snd_pcm_hw_params *p);
140void param_set_mask(struct snd_pcm_hw_params *p, int n, unsigned bit);
141void param_set_min(struct snd_pcm_hw_params *p, int n, unsigned val);
142void param_set_int(struct snd_pcm_hw_params *p, int n, unsigned val);
143void param_set_max(struct snd_pcm_hw_params *p, int n, unsigned val);
144int param_set_hw_refine(struct pcm *pcm, struct snd_pcm_hw_params *params);
145int param_set_hw_params(struct pcm *pcm, struct snd_pcm_hw_params *params);
146int param_set_sw_params(struct pcm *pcm, struct snd_pcm_sw_params *sparams);
Mingming Yinbbd94ad2012-11-29 20:04:36 -0800147int get_compressed_format(const char *format);
Iliyan Malchev4765c432012-06-11 14:36:16 -0700148void param_dump(struct snd_pcm_hw_params *p);
149int pcm_prepare(struct pcm *pcm);
150long pcm_avail(struct pcm *pcm);
Mingming Yinbbd94ad2012-11-29 20:04:36 -0800151int pcm_set_channel_map(struct pcm *pcm, struct mixer *mixer,
152 int max_channels, char *chmap);
Iliyan Malchev4765c432012-06-11 14:36:16 -0700153
154/* Returns a human readable reason for the last error. */
155const char *pcm_error(struct pcm *pcm);
156
157/* Returns the buffer size (int bytes) that should be used for pcm_write.
158 * This will be 1/2 of the actual fifo size.
159 */
160int pcm_buffer_size(struct snd_pcm_hw_params *params);
161int pcm_period_size(struct snd_pcm_hw_params *params);
162
163/* Write data to the fifo.
164 * Will start playback on the first write or on a write that
165 * occurs after a fifo underrun.
166 */
167int pcm_write(struct pcm *pcm, void *data, unsigned count);
168int pcm_read(struct pcm *pcm, void *data, unsigned count);
169
170struct mixer;
171struct mixer_ctl;
172
173struct mixer *mixer_open(const char *device);
174void mixer_close(struct mixer *mixer);
175void mixer_dump(struct mixer *mixer);
176
177struct mixer_ctl *mixer_get_control(struct mixer *mixer,
178 const char *name, unsigned index);
179struct mixer_ctl *mixer_get_nth_control(struct mixer *mixer, unsigned n);
180
181int mixer_ctl_set(struct mixer_ctl *ctl, unsigned percent);
182int mixer_ctl_select(struct mixer_ctl *ctl, const char *value);
183void mixer_ctl_get(struct mixer_ctl *ctl, unsigned *value);
Subhash Chandra Bose Naripeddy6000eb52013-01-05 18:02:44 -0800184void mixer_ctl_get_mulvalues(struct mixer_ctl *ctl, unsigned **value, unsigned *count);
Iliyan Malchev4765c432012-06-11 14:36:16 -0700185int mixer_ctl_set_value(struct mixer_ctl *ctl, int count, char ** argv);
186
187
188#define MAX_NUM_CODECS 32
189
dhacker2994db5552013-04-26 21:32:42 -0500190#ifndef QCOM_COMPRESSED_AUDIO_ENABLED
191/* compressed audio support */
192
193/* AUDIO CODECS SUPPORTED */
194#define MAX_NUM_CODECS 32
195#define MAX_NUM_CODEC_DESCRIPTORS 32
196#define MAX_NUM_BITRATES 32
197
198/* compressed TX */
199#define MAX_NUM_FRAMES_PER_BUFFER 1
200#define COMPRESSED_META_DATA_MODE 0x10
201#define META_DATA_LEN_BYTES 36
202#define Q6_AC3_DECODER 0x00010BF6
203#define Q6_EAC3_DECODER 0x00010C3C
204#define Q6_DTS 0x00010D88
205#define Q6_DTS_LBR 0x00010DBB
206
207/* Codecs are listed linearly to allow for extensibility */
208#define SND_AUDIOCODEC_PCM ((__u32) 0x00000001)
209#define SND_AUDIOCODEC_MP3 ((__u32) 0x00000002)
210#define SND_AUDIOCODEC_AMR ((__u32) 0x00000003)
211#define SND_AUDIOCODEC_AMRWB ((__u32) 0x00000004)
212#define SND_AUDIOCODEC_AMRWBPLUS ((__u32) 0x00000005)
213#define SND_AUDIOCODEC_AAC ((__u32) 0x00000006)
214#define SND_AUDIOCODEC_WMA ((__u32) 0x00000007)
215#define SND_AUDIOCODEC_REAL ((__u32) 0x00000008)
216#define SND_AUDIOCODEC_VORBIS ((__u32) 0x00000009)
217#define SND_AUDIOCODEC_FLAC ((__u32) 0x0000000A)
218#define SND_AUDIOCODEC_IEC61937 ((__u32) 0x0000000B)
219#define SND_AUDIOCODEC_G723_1 ((__u32) 0x0000000C)
220#define SND_AUDIOCODEC_G729 ((__u32) 0x0000000D)
221#define SND_AUDIOCODEC_AC3 ((__u32) 0x0000000E)
222#define SND_AUDIOCODEC_DTS ((__u32) 0x0000000F)
223#define SND_AUDIOCODEC_AC3_PASS_THROUGH ((__u32) 0x00000010)
224#define SND_AUDIOCODEC_WMA_PRO ((__u32) 0x00000011)
225#define SND_AUDIOCODEC_DTS_PASS_THROUGH ((__u32) 0x00000012)
226#define SND_AUDIOCODEC_DTS_LBR ((__u32) 0x00000013)
227#define SND_AUDIOCODEC_DTS_TRANSCODE_LOOPBACK ((__u32) 0x00000014)
228#define SND_AUDIOCODEC_PASS_THROUGH ((__u32) 0x00000015)
229#define SND_AUDIOCODEC_MP2 ((__u32) 0x00000016)
230#define SND_AUDIOCODEC_DTS_LBR_PASS_THROUGH ((__u32) 0x00000017)
231/*
232 * Profile and modes are listed with bit masks. This allows for a
233 * more compact representation of fields that will not evolve
234 * (in contrast to the list of codecs)
235 */
236
237#define SND_AUDIOPROFILE_PCM ((__u32) 0x00000001)
238
239/* MP3 modes are only useful for encoders */
240#define SND_AUDIOCHANMODE_MP3_MONO ((__u32) 0x00000001)
241#define SND_AUDIOCHANMODE_MP3_STEREO ((__u32) 0x00000002)
242#define SND_AUDIOCHANMODE_MP3_JOINTSTEREO ((__u32) 0x00000004)
243#define SND_AUDIOCHANMODE_MP3_DUAL ((__u32) 0x00000008)
244
245#define SND_AUDIOPROFILE_AMR ((__u32) 0x00000001)
246
247/* AMR modes are only useful for encoders */
248#define SND_AUDIOMODE_AMR_DTX_OFF ((__u32) 0x00000001)
249#define SND_AUDIOMODE_AMR_VAD1 ((__u32) 0x00000002)
250#define SND_AUDIOMODE_AMR_VAD2 ((__u32) 0x00000004)
251
252#define SND_AUDIOSTREAMFORMAT_UNDEFINED ((__u32) 0x00000000)
253#define SND_AUDIOSTREAMFORMAT_CONFORMANCE ((__u32) 0x00000001)
254#define SND_AUDIOSTREAMFORMAT_IF1 ((__u32) 0x00000002)
255#define SND_AUDIOSTREAMFORMAT_IF2 ((__u32) 0x00000004)
256#define SND_AUDIOSTREAMFORMAT_FSF ((__u32) 0x00000008)
257#define SND_AUDIOSTREAMFORMAT_RTPPAYLOAD ((__u32) 0x00000010)
258#define SND_AUDIOSTREAMFORMAT_ITU ((__u32) 0x00000020)
259
260#define SND_AUDIOPROFILE_AMRWB ((__u32) 0x00000001)
261
262/* AMRWB modes are only useful for encoders */
263#define SND_AUDIOMODE_AMRWB_DTX_OFF ((__u32) 0x00000001)
264#define SND_AUDIOMODE_AMRWB_VAD1 ((__u32) 0x00000002)
265#define SND_AUDIOMODE_AMRWB_VAD2 ((__u32) 0x00000004)
266
267#define SND_AUDIOPROFILE_AMRWBPLUS ((__u32) 0x00000001)
268
269#define SND_AUDIOPROFILE_AAC ((__u32) 0x00000001)
270
271/* AAC modes are required for encoders and decoders */
272#define SND_AUDIOMODE_AAC_MAIN ((__u32) 0x00000001)
273#define SND_AUDIOMODE_AAC_LC ((__u32) 0x00000002)
274#define SND_AUDIOMODE_AAC_SSR ((__u32) 0x00000004)
275#define SND_AUDIOMODE_AAC_LTP ((__u32) 0x00000008)
276#define SND_AUDIOMODE_AAC_HE ((__u32) 0x00000010)
277#define SND_AUDIOMODE_AAC_SCALABLE ((__u32) 0x00000020)
278#define SND_AUDIOMODE_AAC_ERLC ((__u32) 0x00000040)
279#define SND_AUDIOMODE_AAC_LD ((__u32) 0x00000080)
280#define SND_AUDIOMODE_AAC_HE_PS ((__u32) 0x00000100)
281#define SND_AUDIOMODE_AAC_HE_MPS ((__u32) 0x00000200)
282
283/* AAC formats are required for encoders and decoders */
284#define SND_AUDIOSTREAMFORMAT_MP2ADTS ((__u32) 0x00000001)
285#define SND_AUDIOSTREAMFORMAT_MP4ADTS ((__u32) 0x00000002)
286#define SND_AUDIOSTREAMFORMAT_MP4LOAS ((__u32) 0x00000004)
287#define SND_AUDIOSTREAMFORMAT_MP4LATM ((__u32) 0x00000008)
288#define SND_AUDIOSTREAMFORMAT_ADIF ((__u32) 0x00000010)
289#define SND_AUDIOSTREAMFORMAT_MP4FF ((__u32) 0x00000020)
290#define SND_AUDIOSTREAMFORMAT_RAW ((__u32) 0x00000040)
291
292#define SND_AUDIOPROFILE_WMA7 ((__u32) 0x00000001)
293#define SND_AUDIOPROFILE_WMA8 ((__u32) 0x00000002)
294#define SND_AUDIOPROFILE_WMA9 ((__u32) 0x00000004)
295#define SND_AUDIOPROFILE_WMA10 ((__u32) 0x00000008)
296
297#define SND_AUDIOMODE_WMA_LEVEL1 ((__u32) 0x00000001)
298#define SND_AUDIOMODE_WMA_LEVEL2 ((__u32) 0x00000002)
299#define SND_AUDIOMODE_WMA_LEVEL3 ((__u32) 0x00000004)
300#define SND_AUDIOMODE_WMA_LEVEL4 ((__u32) 0x00000008)
301#define SND_AUDIOMODE_WMAPRO_LEVELM0 ((__u32) 0x00000010)
302#define SND_AUDIOMODE_WMAPRO_LEVELM1 ((__u32) 0x00000020)
303#define SND_AUDIOMODE_WMAPRO_LEVELM2 ((__u32) 0x00000040)
304#define SND_AUDIOMODE_WMAPRO_LEVELM3 ((__u32) 0x00000080)
305
306#define SND_AUDIOSTREAMFORMAT_WMA_ASF ((__u32) 0x00000001)
307/*
308 * Some implementations strip the ASF header and only send ASF packets
309 * to the DSP
310 */
311#define SND_AUDIOSTREAMFORMAT_WMA_NOASF_HDR ((__u32) 0x00000002)
312
313#define SND_AUDIOPROFILE_REALAUDIO ((__u32) 0x00000001)
314
315#define SND_AUDIOMODE_REALAUDIO_G2 ((__u32) 0x00000001)
316#define SND_AUDIOMODE_REALAUDIO_8 ((__u32) 0x00000002)
317#define SND_AUDIOMODE_REALAUDIO_10 ((__u32) 0x00000004)
318#define SND_AUDIOMODE_REALAUDIO_SURROUND ((__u32) 0x00000008)
319
320#define SND_AUDIOPROFILE_VORBIS ((__u32) 0x00000001)
321
322#define SND_AUDIOMODE_VORBIS ((__u32) 0x00000001)
323
324#define SND_AUDIOPROFILE_FLAC ((__u32) 0x00000001)
325
326/*
327 * Define quality levels for FLAC encoders, from LEVEL0 (fast)
328 * to LEVEL8 (best)
329 */
330#define SND_AUDIOMODE_FLAC_LEVEL0 ((__u32) 0x00000001)
331#define SND_AUDIOMODE_FLAC_LEVEL1 ((__u32) 0x00000002)
332#define SND_AUDIOMODE_FLAC_LEVEL2 ((__u32) 0x00000004)
333#define SND_AUDIOMODE_FLAC_LEVEL3 ((__u32) 0x00000008)
334#define SND_AUDIOMODE_FLAC_LEVEL4 ((__u32) 0x00000010)
335#define SND_AUDIOMODE_FLAC_LEVEL5 ((__u32) 0x00000020)
336#define SND_AUDIOMODE_FLAC_LEVEL6 ((__u32) 0x00000040)
337#define SND_AUDIOMODE_FLAC_LEVEL7 ((__u32) 0x00000080)
338#define SND_AUDIOMODE_FLAC_LEVEL8 ((__u32) 0x00000100)
339
340#define SND_AUDIOSTREAMFORMAT_FLAC ((__u32) 0x00000001)
341#define SND_AUDIOSTREAMFORMAT_FLAC_OGG ((__u32) 0x00000002)
342
343/* IEC61937 payloads without CUVP and preambles */
344#define SND_AUDIOPROFILE_IEC61937 ((__u32) 0x00000001)
345/* IEC61937 with S/PDIF preambles+CUVP bits in 32-bit containers */
346#define SND_AUDIOPROFILE_IEC61937_SPDIF ((__u32) 0x00000002)
347
348/*
349 * IEC modes are mandatory for decoders. Format autodetection
350 * will only happen on the DSP side with mode 0. The PCM mode should
351 * not be used, the PCM codec should be used instead.
352 */
353#define SND_AUDIOMODE_IEC_REF_STREAM_HEADER ((__u32) 0x00000000)
354#define SND_AUDIOMODE_IEC_LPCM ((__u32) 0x00000001)
355#define SND_AUDIOMODE_IEC_AC3 ((__u32) 0x00000002)
356#define SND_AUDIOMODE_IEC_MPEG1 ((__u32) 0x00000004)
357#define SND_AUDIOMODE_IEC_MP3 ((__u32) 0x00000008)
358#define SND_AUDIOMODE_IEC_MPEG2 ((__u32) 0x00000010)
359#define SND_AUDIOMODE_IEC_AACLC ((__u32) 0x00000020)
360#define SND_AUDIOMODE_IEC_DTS ((__u32) 0x00000040)
361#define SND_AUDIOMODE_IEC_ATRAC ((__u32) 0x00000080)
362#define SND_AUDIOMODE_IEC_SACD ((__u32) 0x00000100)
363#define SND_AUDIOMODE_IEC_EAC3 ((__u32) 0x00000200)
364#define SND_AUDIOMODE_IEC_DTS_HD ((__u32) 0x00000400)
365#define SND_AUDIOMODE_IEC_MLP ((__u32) 0x00000800)
366#define SND_AUDIOMODE_IEC_DST ((__u32) 0x00001000)
367#define SND_AUDIOMODE_IEC_WMAPRO ((__u32) 0x00002000)
368#define SND_AUDIOMODE_IEC_REF_CXT ((__u32) 0x00004000)
369#define SND_AUDIOMODE_IEC_HE_AAC ((__u32) 0x00008000)
370#define SND_AUDIOMODE_IEC_HE_AAC2 ((__u32) 0x00010000)
371#define SND_AUDIOMODE_IEC_MPEG_SURROUND ((__u32) 0x00020000)
372
373#define SND_AUDIOPROFILE_G723_1 ((__u32) 0x00000001)
374
375#define SND_AUDIOMODE_G723_1_ANNEX_A ((__u32) 0x00000001)
376#define SND_AUDIOMODE_G723_1_ANNEX_B ((__u32) 0x00000002)
377#define SND_AUDIOMODE_G723_1_ANNEX_C ((__u32) 0x00000004)
378
379#define SND_AUDIOPROFILE_G729 ((__u32) 0x00000001)
380
381#define SND_AUDIOMODE_G729_ANNEX_A ((__u32) 0x00000001)
382#define SND_AUDIOMODE_G729_ANNEX_B ((__u32) 0x00000002)
383
384/* <FIXME: multichannel encoders aren't supported for now. Would need
385 an additional definition of channel arrangement> */
386
387/* VBR/CBR definitions */
388#define SND_RATECONTROLMODE_CONSTANTBITRATE ((__u32) 0x00000001)
389#define SND_RATECONTROLMODE_VARIABLEBITRATE ((__u32) 0x00000002)
390
391/* Encoder options */
392
393struct snd_enc_wma {
394 __u32 super_block_align; /* WMA Type-specific data */
395 __u32 bits_per_sample;
396 __u32 channelmask;
397 __u32 encodeopt;
398 __u32 encodeopt1;
399 __u32 encodeopt2;
400};
401
402
403/**
404 * struct snd_enc_vorbis
405 * @quality: Sets encoding quality to n, between -1 (low) and 10 (high).
406 * In the default mode of operation, the quality level is 3.
407 * Normal quality range is 0 - 10.
408 * @managed: Boolean. Set bitrate management mode. This turns off the
409 * normal VBR encoding, but allows hard or soft bitrate constraints to be
410 * enforced by the encoder. This mode can be slower, and may also be
411 * lower quality. It is primarily useful for streaming.
412 * @max_bit_rate: Enabled only if managed is TRUE
413 * @min_bit_rate: Enabled only if managed is TRUE
414 * @downmix: Boolean. Downmix input from stereo to mono (has no effect on
415 * non-stereo streams). Useful for lower-bitrate encoding.
416 *
417 * These options were extracted from the OpenMAX IL spec and Gstreamer vorbisenc
418 * properties
419 *
420 * For best quality users should specify VBR mode and set quality levels.
421 */
422
423struct snd_enc_vorbis {
424 __s32 quality;
425 __u32 managed;
426 __u32 max_bit_rate;
427 __u32 min_bit_rate;
428 __u32 downmix;
429};
430
431
432/**
433 * struct snd_enc_real
434 * @quant_bits: number of coupling quantization bits in the stream
435 * @start_region: coupling start region in the stream
436 * @num_regions: number of regions value
437 *
438 * These options were extracted from the OpenMAX IL spec
439 */
440
441struct snd_enc_real {
442 __u32 quant_bits;
443 __u32 start_region;
444 __u32 num_regions;
445};
446
447/**
448 * struct snd_enc_flac
449 * @num: serial number, valid only for OGG formats
450 * needs to be set by application
451 * @gain: Add replay gain tags
452 *
453 * These options were extracted from the FLAC online documentation
454 * at http://flac.sourceforge.net/documentation_tools_flac.html
455 *
456 * To make the API simpler, it is assumed that the user will select quality
457 * profiles. Additional options that affect encoding quality and speed can
458 * be added at a later stage if needed.
459 *
460 * By default the Subset format is used by encoders.
461 *
462 * TAGS such as pictures, etc, cannot be handled by an offloaded encoder and are
463 * not supported in this API.
464 */
465
466struct snd_enc_flac {
467 __u32 num;
468 __u32 gain;
469};
470
471struct snd_enc_generic {
472 __u32 bw; /* encoder bandwidth */
473 __s32 reserved[15];
474};
475struct snd_dec_dts {
476 __u32 modelIdLength;
477 __u8 *modelId;
478};
479
480union snd_codec_options {
481 struct snd_enc_wma wma;
482 struct snd_enc_vorbis vorbis;
483 struct snd_enc_real real;
484 struct snd_enc_flac flac;
485 struct snd_enc_generic generic;
486 struct snd_dec_dts dts;
487};
488
489/** struct snd_codec_desc - description of codec capabilities
490 * @max_ch: Maximum number of audio channels
491 * @sample_rates: Sampling rates in Hz, use SNDRV_PCM_RATE_xxx for this
492 * @bit_rate: Indexed array containing supported bit rates
493 * @num_bitrates: Number of valid values in bit_rate array
494 * @rate_control: value is specified by SND_RATECONTROLMODE defines.
495 * @profiles: Supported profiles. See SND_AUDIOPROFILE defines.
496 * @modes: Supported modes. See SND_AUDIOMODE defines
497 * @formats: Supported formats. See SND_AUDIOSTREAMFORMAT defines
498 * @min_buffer: Minimum buffer size handled by codec implementation
499 * @reserved: reserved for future use
500 *
501 * This structure provides a scalar value for profiles, modes and stream
502 * format fields.
503 * If an implementation supports multiple combinations, they will be listed as
504 * codecs with different descriptors, for example there would be 2 descriptors
505 * for AAC-RAW and AAC-ADTS.
506 * This entails some redundancy but makes it easier to avoid invalid
507 * configurations.
508 *
509 */
510
511struct snd_codec_desc {
512 __u32 max_ch;
513 __u32 sample_rates;
514 __u32 bit_rate[MAX_NUM_BITRATES];
515 __u32 num_bitrates;
516 __u32 rate_control;
517 __u32 profiles;
518 __u32 modes;
519 __u32 formats;
520 __u32 min_buffer;
521 __u32 reserved[15];
522};
523
524/** struct snd_codec
525 * @id: Identifies the supported audio encoder/decoder.
526 * See SND_AUDIOCODEC macros.
527 * @ch_in: Number of input audio channels
528 * @ch_out: Number of output channels. In case of contradiction between
529 * this field and the channelMode field, the channelMode field
530 * overrides.
531 * @sample_rate: Audio sample rate of input data
532 * @bit_rate: Bitrate of encoded data. May be ignored by decoders
533 * @rate_control: Encoding rate control. See SND_RATECONTROLMODE defines.
534 * Encoders may rely on profiles for quality levels.
535 * May be ignored by decoders.
536 * @profile: Mandatory for encoders, can be mandatory for specific
537 * decoders as well. See SND_AUDIOPROFILE defines.
538 * @level: Supported level (Only used by WMA at the moment)
539 * @ch_mode: Channel mode for encoder. See SND_AUDIOCHANMODE defines
540 * @format: Format of encoded bistream. Mandatory when defined.
541 * See SND_AUDIOSTREAMFORMAT defines.
542 * @align: Block alignment in bytes of an audio sample.
543 * Only required for PCM or IEC formats.
544 * @options: encoder-specific settings
545 * @reserved: reserved for future use
546 */
547
548struct snd_codec {
549 __u32 id;
550 __u32 ch_in;
551 __u32 ch_out;
552 __u32 sample_rate;
553 __u32 bit_rate;
554 __u32 rate_control;
555 __u32 profile;
556 __u32 level;
557 __u32 ch_mode;
558 __u32 format;
559 __u32 align;
560 __u32 transcode_dts;
561 struct snd_dec_dts dts;
562 union snd_codec_options options;
563 __u32 reserved[3];
564};
565
566
567
568#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 1, 0)
569/**
570 * struct snd_compressed_buffer: compressed buffer
571 * @fragment_size: size of buffer fragment in bytes
572 * @fragments: number of such fragments
573 */
574struct snd_compressed_buffer {
575 __u32 fragment_size;
576 __u32 fragments;
577};
578
579/**
580 * struct snd_compr_params: compressed stream params
581 * @buffer: buffer description
582 * @codec: codec parameters
583 * @no_wake_mode: dont wake on fragment elapsed
584 */
585struct snd_compr_params {
586 struct snd_compressed_buffer buffer;
587 struct snd_codec codec;
588 __u8 no_wake_mode;
589};
590
591/**
592 * struct snd_compr_tstamp: timestamp descriptor
593 * @byte_offset: Byte offset in ring buffer to DSP
594 * @copied_total: Total number of bytes copied from/to ring buffer to/by DSP
595 * @pcm_frames: Frames decoded or encoded by DSP. This field will evolve by
596 * large steps and should only be used to monitor encoding/decoding
597 * progress. It shall not be used for timing estimates.
598 * @pcm_io_frames: Frames rendered or received by DSP into a mixer or an audio
599 * output/input. This field should be used for A/V sync or time estimates.
600 * @sampling_rate: sampling rate of audio
601 */
602struct snd_compr_tstamp {
603 __u32 byte_offset;
604 __u32 copied_total;
605 snd_pcm_uframes_t pcm_frames;
606 snd_pcm_uframes_t pcm_io_frames;
607 __u32 sampling_rate;
608 uint64_t timestamp;
609};
610
611/**
612 * struct snd_compr_avail: avail descriptor
613 * @avail: Number of bytes available in ring buffer for writing/reading
614 * @tstamp: timestamp infomation
615 */
616struct snd_compr_avail {
617 __u64 avail;
618 struct snd_compr_tstamp tstamp;
619};
620
621enum snd_compr_direction {
622 SND_COMPRESS_PLAYBACK = 0,
623 SND_COMPRESS_CAPTURE
624};
625
626/**
627 * struct snd_compr_caps: caps descriptor
628 * @codecs: pointer to array of codecs
629 * @direction: direction supported. Of type snd_compr_direction
630 * @min_fragment_size: minimum fragment supported by DSP
631 * @max_fragment_size: maximum fragment supported by DSP
632 * @min_fragments: min fragments supported by DSP
633 * @max_fragments: max fragments supported by DSP
634 * @num_codecs: number of codecs supported
635 * @reserved: reserved field
636 */
637struct snd_compr_caps {
638 __u32 num_codecs;
639 __u32 direction;
640 __u32 min_fragment_size;
641 __u32 max_fragment_size;
642 __u32 min_fragments;
643 __u32 max_fragments;
644 __u32 codecs[MAX_NUM_CODECS];
645 __u32 reserved[11];
646};
647
648/**
649 * struct snd_compr_codec_caps: query capability of codec
650 * @codec: codec for which capability is queried
651 * @num_descriptors: number of codec descriptors
652 * @descriptor: array of codec capability descriptor
653 */
654struct snd_compr_codec_caps {
655 __u32 codec;
656 __u32 num_descriptors;
657 struct snd_codec_desc descriptor[MAX_NUM_CODEC_DESCRIPTORS];
658};
659
660/**
661 * struct snd_compr_audio_info: compressed input audio information
662 * @frame_size: legth of the encoded frame with valid data
663 * @reserved: reserved for furture use
664 */
665struct snd_compr_audio_info {
666 uint32_t frame_size;
667 uint32_t reserved[15];
668};
669
670/**
671 * compress path ioctl definitions
672 * SNDRV_COMPRESS_GET_CAPS: Query capability of DSP
673 * SNDRV_COMPRESS_GET_CODEC_CAPS: Query capability of a codec
674 * SNDRV_COMPRESS_SET_PARAMS: Set codec and stream parameters
675 * Note: only codec params can be changed runtime and stream params cant be
676 * SNDRV_COMPRESS_GET_PARAMS: Query codec params
677 * SNDRV_COMPRESS_TSTAMP: get the current timestamp value
678 * SNDRV_COMPRESS_AVAIL: get the current buffer avail value.
679 * This also queries the tstamp properties
680 * SNDRV_COMPRESS_PAUSE: Pause the running stream
681 * SNDRV_COMPRESS_RESUME: resume a paused stream
682 * SNDRV_COMPRESS_START: Start a stream
683 * SNDRV_COMPRESS_STOP: stop a running stream, discarding ring buffer content
684 * and the buffers currently with DSP
685 * SNDRV_COMPRESS_DRAIN: Play till end of buffers and stop after that
686 * SNDRV_COMPRESS_IOCTL_VERSION: Query the API version
687 */
688#define SNDRV_COMPRESS_GET_CAPS _IOWR('C', 0x00, struct snd_compr_caps *)
689#define SNDRV_COMPRESS_GET_CODEC_CAPS _IOWR('C', 0x01, struct snd_compr_codec_caps *)
690#define SNDRV_COMPRESS_SET_PARAMS _IOW('C', 0x02, struct snd_compr_params *)
691#define SNDRV_COMPRESS_GET_PARAMS _IOR('C', 0x03, struct snd_compr_params *)
692#define SNDRV_COMPRESS_TSTAMP _IOR('C', 0x10, struct snd_compr_tstamp *)
693#define SNDRV_COMPRESS_AVAIL _IOR('C', 0x11, struct snd_compr_avail *)
694#define SNDRV_COMPRESS_PAUSE _IO('C', 0x20)
695#define SNDRV_COMPRESS_RESUME _IO('C', 0x21)
696#define SNDRV_COMPRESS_START _IO('C', 0x22)
697#define SNDRV_COMPRESS_STOP _IO('C', 0x23)
698#define SNDRV_COMPRESS_DRAIN _IO('C', 0x24)
699/*
700 * TODO
701 * 1. add mmap support
702 *
703 */
704#define SND_COMPR_TRIGGER_DRAIN 7 /*FIXME move this to pcm.h */
705
706#endif
707
Iliyan Malchev4765c432012-06-11 14:36:16 -0700708#endif