master
  1/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) AND MIT) */
  2/*
  3 *  compress_params.h - codec types and parameters for compressed data
  4 *  streaming interface
  5 *
  6 *  Copyright (C) 2011 Intel Corporation
  7 *  Authors:	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
  8 *              Vinod Koul <vinod.koul@linux.intel.com>
  9 *
 10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 11 *
 12 * The definitions in this file are derived from the OpenMAX AL version 1.1
 13 * and OpenMAX IL v 1.1.2 header files which contain the copyright notice below
 14 * and are licensed under the MIT license.
 15 *
 16 * Copyright (c) 2007-2010 The Khronos Group Inc.
 17 */
 18#ifndef __SND_COMPRESS_PARAMS_H
 19#define __SND_COMPRESS_PARAMS_H
 20
 21#include <linux/types.h>
 22
 23/* AUDIO CODECS SUPPORTED */
 24#define MAX_NUM_CODECS 32
 25#define MAX_NUM_CODEC_DESCRIPTORS 32
 26#define MAX_NUM_BITRATES 32
 27#define MAX_NUM_SAMPLE_RATES 32
 28
 29/* Codecs are listed linearly to allow for extensibility */
 30#define SND_AUDIOCODEC_PCM                   ((__u32) 0x00000001)
 31#define SND_AUDIOCODEC_MP3                   ((__u32) 0x00000002)
 32#define SND_AUDIOCODEC_AMR                   ((__u32) 0x00000003)
 33#define SND_AUDIOCODEC_AMRWB                 ((__u32) 0x00000004)
 34#define SND_AUDIOCODEC_AMRWBPLUS             ((__u32) 0x00000005)
 35#define SND_AUDIOCODEC_AAC                   ((__u32) 0x00000006)
 36#define SND_AUDIOCODEC_WMA                   ((__u32) 0x00000007)
 37#define SND_AUDIOCODEC_REAL                  ((__u32) 0x00000008)
 38#define SND_AUDIOCODEC_VORBIS                ((__u32) 0x00000009)
 39#define SND_AUDIOCODEC_FLAC                  ((__u32) 0x0000000A)
 40#define SND_AUDIOCODEC_IEC61937              ((__u32) 0x0000000B)
 41#define SND_AUDIOCODEC_G723_1                ((__u32) 0x0000000C)
 42#define SND_AUDIOCODEC_G729                  ((__u32) 0x0000000D)
 43#define SND_AUDIOCODEC_BESPOKE               ((__u32) 0x0000000E)
 44#define SND_AUDIOCODEC_ALAC                  ((__u32) 0x0000000F)
 45#define SND_AUDIOCODEC_APE                   ((__u32) 0x00000010)
 46#define SND_AUDIOCODEC_MAX                   SND_AUDIOCODEC_APE
 47
 48/*
 49 * Profile and modes are listed with bit masks. This allows for a
 50 * more compact representation of fields that will not evolve
 51 * (in contrast to the list of codecs)
 52 */
 53
 54#define SND_AUDIOPROFILE_PCM                 ((__u32) 0x00000001)
 55
 56/* MP3 modes are only useful for encoders */
 57#define SND_AUDIOCHANMODE_MP3_MONO           ((__u32) 0x00000001)
 58#define SND_AUDIOCHANMODE_MP3_STEREO         ((__u32) 0x00000002)
 59#define SND_AUDIOCHANMODE_MP3_JOINTSTEREO    ((__u32) 0x00000004)
 60#define SND_AUDIOCHANMODE_MP3_DUAL           ((__u32) 0x00000008)
 61
 62#define SND_AUDIOPROFILE_AMR                 ((__u32) 0x00000001)
 63
 64/* AMR modes are only useful for encoders */
 65#define SND_AUDIOMODE_AMR_DTX_OFF            ((__u32) 0x00000001)
 66#define SND_AUDIOMODE_AMR_VAD1               ((__u32) 0x00000002)
 67#define SND_AUDIOMODE_AMR_VAD2               ((__u32) 0x00000004)
 68
 69#define SND_AUDIOSTREAMFORMAT_UNDEFINED	     ((__u32) 0x00000000)
 70#define SND_AUDIOSTREAMFORMAT_CONFORMANCE    ((__u32) 0x00000001)
 71#define SND_AUDIOSTREAMFORMAT_IF1            ((__u32) 0x00000002)
 72#define SND_AUDIOSTREAMFORMAT_IF2            ((__u32) 0x00000004)
 73#define SND_AUDIOSTREAMFORMAT_FSF            ((__u32) 0x00000008)
 74#define SND_AUDIOSTREAMFORMAT_RTPPAYLOAD     ((__u32) 0x00000010)
 75#define SND_AUDIOSTREAMFORMAT_ITU            ((__u32) 0x00000020)
 76
 77#define SND_AUDIOPROFILE_AMRWB               ((__u32) 0x00000001)
 78
 79/* AMRWB modes are only useful for encoders */
 80#define SND_AUDIOMODE_AMRWB_DTX_OFF          ((__u32) 0x00000001)
 81#define SND_AUDIOMODE_AMRWB_VAD1             ((__u32) 0x00000002)
 82#define SND_AUDIOMODE_AMRWB_VAD2             ((__u32) 0x00000004)
 83
 84#define SND_AUDIOPROFILE_AMRWBPLUS           ((__u32) 0x00000001)
 85
 86#define SND_AUDIOPROFILE_AAC                 ((__u32) 0x00000001)
 87
 88/* AAC modes are required for encoders and decoders */
 89#define SND_AUDIOMODE_AAC_MAIN               ((__u32) 0x00000001)
 90#define SND_AUDIOMODE_AAC_LC                 ((__u32) 0x00000002)
 91#define SND_AUDIOMODE_AAC_SSR                ((__u32) 0x00000004)
 92#define SND_AUDIOMODE_AAC_LTP                ((__u32) 0x00000008)
 93#define SND_AUDIOMODE_AAC_HE                 ((__u32) 0x00000010)
 94#define SND_AUDIOMODE_AAC_SCALABLE           ((__u32) 0x00000020)
 95#define SND_AUDIOMODE_AAC_ERLC               ((__u32) 0x00000040)
 96#define SND_AUDIOMODE_AAC_LD                 ((__u32) 0x00000080)
 97#define SND_AUDIOMODE_AAC_HE_PS              ((__u32) 0x00000100)
 98#define SND_AUDIOMODE_AAC_HE_MPS             ((__u32) 0x00000200)
 99
100/* AAC formats are required for encoders and decoders */
101#define SND_AUDIOSTREAMFORMAT_MP2ADTS        ((__u32) 0x00000001)
102#define SND_AUDIOSTREAMFORMAT_MP4ADTS        ((__u32) 0x00000002)
103#define SND_AUDIOSTREAMFORMAT_MP4LOAS        ((__u32) 0x00000004)
104#define SND_AUDIOSTREAMFORMAT_MP4LATM        ((__u32) 0x00000008)
105#define SND_AUDIOSTREAMFORMAT_ADIF           ((__u32) 0x00000010)
106#define SND_AUDIOSTREAMFORMAT_MP4FF          ((__u32) 0x00000020)
107#define SND_AUDIOSTREAMFORMAT_RAW            ((__u32) 0x00000040)
108
109#define SND_AUDIOPROFILE_WMA7                ((__u32) 0x00000001)
110#define SND_AUDIOPROFILE_WMA8                ((__u32) 0x00000002)
111#define SND_AUDIOPROFILE_WMA9                ((__u32) 0x00000004)
112#define SND_AUDIOPROFILE_WMA10               ((__u32) 0x00000008)
113#define SND_AUDIOPROFILE_WMA9_PRO            ((__u32) 0x00000010)
114#define SND_AUDIOPROFILE_WMA9_LOSSLESS       ((__u32) 0x00000020)
115#define SND_AUDIOPROFILE_WMA10_LOSSLESS      ((__u32) 0x00000040)
116
117#define SND_AUDIOMODE_WMA_LEVEL1             ((__u32) 0x00000001)
118#define SND_AUDIOMODE_WMA_LEVEL2             ((__u32) 0x00000002)
119#define SND_AUDIOMODE_WMA_LEVEL3             ((__u32) 0x00000004)
120#define SND_AUDIOMODE_WMA_LEVEL4             ((__u32) 0x00000008)
121#define SND_AUDIOMODE_WMAPRO_LEVELM0         ((__u32) 0x00000010)
122#define SND_AUDIOMODE_WMAPRO_LEVELM1         ((__u32) 0x00000020)
123#define SND_AUDIOMODE_WMAPRO_LEVELM2         ((__u32) 0x00000040)
124#define SND_AUDIOMODE_WMAPRO_LEVELM3         ((__u32) 0x00000080)
125
126#define SND_AUDIOSTREAMFORMAT_WMA_ASF        ((__u32) 0x00000001)
127/*
128 * Some implementations strip the ASF header and only send ASF packets
129 * to the DSP
130 */
131#define SND_AUDIOSTREAMFORMAT_WMA_NOASF_HDR  ((__u32) 0x00000002)
132
133#define SND_AUDIOPROFILE_REALAUDIO           ((__u32) 0x00000001)
134
135#define SND_AUDIOMODE_REALAUDIO_G2           ((__u32) 0x00000001)
136#define SND_AUDIOMODE_REALAUDIO_8            ((__u32) 0x00000002)
137#define SND_AUDIOMODE_REALAUDIO_10           ((__u32) 0x00000004)
138#define SND_AUDIOMODE_REALAUDIO_SURROUND     ((__u32) 0x00000008)
139
140#define SND_AUDIOPROFILE_VORBIS              ((__u32) 0x00000001)
141
142#define SND_AUDIOMODE_VORBIS                 ((__u32) 0x00000001)
143
144#define SND_AUDIOPROFILE_FLAC                ((__u32) 0x00000001)
145
146/*
147 * Define quality levels for FLAC encoders, from LEVEL0 (fast)
148 * to LEVEL8 (best)
149 */
150#define SND_AUDIOMODE_FLAC_LEVEL0            ((__u32) 0x00000001)
151#define SND_AUDIOMODE_FLAC_LEVEL1            ((__u32) 0x00000002)
152#define SND_AUDIOMODE_FLAC_LEVEL2            ((__u32) 0x00000004)
153#define SND_AUDIOMODE_FLAC_LEVEL3            ((__u32) 0x00000008)
154#define SND_AUDIOMODE_FLAC_LEVEL4            ((__u32) 0x00000010)
155#define SND_AUDIOMODE_FLAC_LEVEL5            ((__u32) 0x00000020)
156#define SND_AUDIOMODE_FLAC_LEVEL6            ((__u32) 0x00000040)
157#define SND_AUDIOMODE_FLAC_LEVEL7            ((__u32) 0x00000080)
158#define SND_AUDIOMODE_FLAC_LEVEL8            ((__u32) 0x00000100)
159
160#define SND_AUDIOSTREAMFORMAT_FLAC           ((__u32) 0x00000001)
161#define SND_AUDIOSTREAMFORMAT_FLAC_OGG       ((__u32) 0x00000002)
162
163/* IEC61937 payloads without CUVP and preambles */
164#define SND_AUDIOPROFILE_IEC61937            ((__u32) 0x00000001)
165/* IEC61937 with S/PDIF preambles+CUVP bits in 32-bit containers */
166#define SND_AUDIOPROFILE_IEC61937_SPDIF      ((__u32) 0x00000002)
167
168/*
169 * IEC modes are mandatory for decoders. Format autodetection
170 * will only happen on the DSP side with mode 0. The PCM mode should
171 * not be used, the PCM codec should be used instead.
172 */
173#define SND_AUDIOMODE_IEC_REF_STREAM_HEADER  ((__u32) 0x00000000)
174#define SND_AUDIOMODE_IEC_LPCM		     ((__u32) 0x00000001)
175#define SND_AUDIOMODE_IEC_AC3		     ((__u32) 0x00000002)
176#define SND_AUDIOMODE_IEC_MPEG1		     ((__u32) 0x00000004)
177#define SND_AUDIOMODE_IEC_MP3		     ((__u32) 0x00000008)
178#define SND_AUDIOMODE_IEC_MPEG2		     ((__u32) 0x00000010)
179#define SND_AUDIOMODE_IEC_AACLC		     ((__u32) 0x00000020)
180#define SND_AUDIOMODE_IEC_DTS		     ((__u32) 0x00000040)
181#define SND_AUDIOMODE_IEC_ATRAC		     ((__u32) 0x00000080)
182#define SND_AUDIOMODE_IEC_SACD		     ((__u32) 0x00000100)
183#define SND_AUDIOMODE_IEC_EAC3		     ((__u32) 0x00000200)
184#define SND_AUDIOMODE_IEC_DTS_HD	     ((__u32) 0x00000400)
185#define SND_AUDIOMODE_IEC_MLP		     ((__u32) 0x00000800)
186#define SND_AUDIOMODE_IEC_DST		     ((__u32) 0x00001000)
187#define SND_AUDIOMODE_IEC_WMAPRO	     ((__u32) 0x00002000)
188#define SND_AUDIOMODE_IEC_REF_CXT            ((__u32) 0x00004000)
189#define SND_AUDIOMODE_IEC_HE_AAC	     ((__u32) 0x00008000)
190#define SND_AUDIOMODE_IEC_HE_AAC2	     ((__u32) 0x00010000)
191#define SND_AUDIOMODE_IEC_MPEG_SURROUND	     ((__u32) 0x00020000)
192
193#define SND_AUDIOPROFILE_G723_1              ((__u32) 0x00000001)
194
195#define SND_AUDIOMODE_G723_1_ANNEX_A         ((__u32) 0x00000001)
196#define SND_AUDIOMODE_G723_1_ANNEX_B         ((__u32) 0x00000002)
197#define SND_AUDIOMODE_G723_1_ANNEX_C         ((__u32) 0x00000004)
198
199#define SND_AUDIOPROFILE_G729                ((__u32) 0x00000001)
200
201#define SND_AUDIOMODE_G729_ANNEX_A           ((__u32) 0x00000001)
202#define SND_AUDIOMODE_G729_ANNEX_B           ((__u32) 0x00000002)
203
204/* <FIXME: multichannel encoders aren't supported for now. Would need
205   an additional definition of channel arrangement> */
206
207/* VBR/CBR definitions */
208#define SND_RATECONTROLMODE_CONSTANTBITRATE  ((__u32) 0x00000001)
209#define SND_RATECONTROLMODE_VARIABLEBITRATE  ((__u32) 0x00000002)
210
211/* Encoder options */
212
213struct snd_enc_wma {
214	__u32 super_block_align; /* WMA Type-specific data */
215};
216
217
218/**
219 * struct snd_enc_vorbis - Vorbis encoder parameters
220 * @quality: Sets encoding quality to n, between -1 (low) and 10 (high).
221 * In the default mode of operation, the quality level is 3.
222 * Normal quality range is 0 - 10.
223 * @managed: Boolean. Set  bitrate  management  mode. This turns off the
224 * normal VBR encoding, but allows hard or soft bitrate constraints to be
225 * enforced by the encoder. This mode can be slower, and may also be
226 * lower quality. It is primarily useful for streaming.
227 * @max_bit_rate: Enabled only if managed is TRUE
228 * @min_bit_rate: Enabled only if managed is TRUE
229 * @downmix: Boolean. Downmix input from stereo to mono (has no effect on
230 * non-stereo streams). Useful for lower-bitrate encoding.
231 *
232 * These options were extracted from the OpenMAX IL spec and Gstreamer vorbisenc
233 * properties
234 *
235 * For best quality users should specify VBR mode and set quality levels.
236 */
237
238struct snd_enc_vorbis {
239	__s32 quality;
240	__u32 managed;
241	__u32 max_bit_rate;
242	__u32 min_bit_rate;
243	__u32 downmix;
244} __attribute__((packed, aligned(4)));
245
246
247/**
248 * struct snd_enc_real - RealAudio encoder parameters
249 * @quant_bits: number of coupling quantization bits in the stream
250 * @start_region: coupling start region in the stream
251 * @num_regions: number of regions value
252 *
253 * These options were extracted from the OpenMAX IL spec
254 */
255
256struct snd_enc_real {
257	__u32 quant_bits;
258	__u32 start_region;
259	__u32 num_regions;
260} __attribute__((packed, aligned(4)));
261
262/**
263 * struct snd_enc_flac - FLAC encoder parameters
264 * @num: serial number, valid only for OGG formats
265 *	needs to be set by application
266 * @gain: Add replay gain tags
267 *
268 * These options were extracted from the FLAC online documentation
269 * at http://flac.sourceforge.net/documentation_tools_flac.html
270 *
271 * To make the API simpler, it is assumed that the user will select quality
272 * profiles. Additional options that affect encoding quality and speed can
273 * be added at a later stage if needed.
274 *
275 * By default the Subset format is used by encoders.
276 *
277 * TAGS such as pictures, etc, cannot be handled by an offloaded encoder and are
278 * not supported in this API.
279 */
280
281struct snd_enc_flac {
282	__u32 num;
283	__u32 gain;
284} __attribute__((packed, aligned(4)));
285
286struct snd_enc_generic {
287	__u32 bw;	/* encoder bandwidth */
288	__s32 reserved[15];	/* Can be used for SND_AUDIOCODEC_BESPOKE */
289} __attribute__((packed, aligned(4)));
290
291struct snd_dec_flac {
292	__u16 sample_size;
293	__u16 min_blk_size;
294	__u16 max_blk_size;
295	__u16 min_frame_size;
296	__u16 max_frame_size;
297	__u16 reserved;
298} __attribute__((packed, aligned(4)));
299
300struct snd_dec_wma {
301	__u32 encoder_option;
302	__u32 adv_encoder_option;
303	__u32 adv_encoder_option2;
304	__u32 reserved;
305} __attribute__((packed, aligned(4)));
306
307struct snd_dec_alac {
308	__u32 frame_length;
309	__u8 compatible_version;
310	__u8 pb;
311	__u8 mb;
312	__u8 kb;
313	__u32 max_run;
314	__u32 max_frame_bytes;
315} __attribute__((packed, aligned(4)));
316
317struct snd_dec_ape {
318	__u16 compatible_version;
319	__u16 compression_level;
320	__u32 format_flags;
321	__u32 blocks_per_frame;
322	__u32 final_frame_blocks;
323	__u32 total_frames;
324	__u32 seek_table_present;
325} __attribute__((packed, aligned(4)));
326
327union snd_codec_options {
328	struct snd_enc_wma wma;
329	struct snd_enc_vorbis vorbis;
330	struct snd_enc_real real;
331	struct snd_enc_flac flac;
332	struct snd_enc_generic generic;
333	struct snd_dec_flac flac_d;
334	struct snd_dec_wma wma_d;
335	struct snd_dec_alac alac_d;
336	struct snd_dec_ape ape_d;
337	struct {
338		__u32 out_sample_rate;
339	} src_d;
340} __attribute__((packed, aligned(4)));
341
342struct snd_codec_desc_src {
343	__u32 out_sample_rate_min;
344	__u32 out_sample_rate_max;
345} __attribute__((packed, aligned(4)));
346
347/** struct snd_codec_desc - description of codec capabilities
348 * @max_ch: Maximum number of audio channels
349 * @sample_rates: Sampling rates in Hz, use values like 48000 for this
350 * @num_sample_rates: Number of valid values in sample_rates array
351 * @bit_rate: Indexed array containing supported bit rates
352 * @num_bitrates: Number of valid values in bit_rate array
353 * @rate_control: value is specified by SND_RATECONTROLMODE defines.
354 * @profiles: Supported profiles. See SND_AUDIOPROFILE defines.
355 * @modes: Supported modes. See SND_AUDIOMODE defines
356 * @formats: Supported formats. See SND_AUDIOSTREAMFORMAT defines
357 * @min_buffer: Minimum buffer size handled by codec implementation
358 * @pcm_formats: Output (for decoders) or input (for encoders)
359 *               PCM formats (required to accel mode, 0 for other modes)
360 * @u_space: union space (for codec dependent data)
361 * @reserved: reserved for future use
362 *
363 * This structure provides a scalar value for profiles, modes and stream
364 * format fields.
365 * If an implementation supports multiple combinations, they will be listed as
366 * codecs with different descriptors, for example there would be 2 descriptors
367 * for AAC-RAW and AAC-ADTS.
368 * This entails some redundancy but makes it easier to avoid invalid
369 * configurations.
370 *
371 */
372
373struct snd_codec_desc {
374	__u32 max_ch;
375	__u32 sample_rates[MAX_NUM_SAMPLE_RATES];
376	__u32 num_sample_rates;
377	__u32 bit_rate[MAX_NUM_BITRATES];
378	__u32 num_bitrates;
379	__u32 rate_control;
380	__u32 profiles;
381	__u32 modes;
382	__u32 formats;
383	__u32 min_buffer;
384	__u32 pcm_formats;
385	union {
386		__u32 u_space[6];
387		struct snd_codec_desc_src src;
388	} __attribute__((packed, aligned(4)));
389	__u32 reserved[8];
390} __attribute__((packed, aligned(4)));
391
392/** struct snd_codec
393 * @id: Identifies the supported audio encoder/decoder.
394 *		See SND_AUDIOCODEC macros.
395 * @ch_in: Number of input audio channels
396 * @ch_out: Number of output channels. In case of contradiction between
397 *		this field and the channelMode field, the channelMode field
398 *		overrides.
399 * @sample_rate: Audio sample rate of input data in Hz, use values like 48000
400 *		for this.
401 * @bit_rate: Bitrate of encoded data. May be ignored by decoders
402 * @rate_control: Encoding rate control. See SND_RATECONTROLMODE defines.
403 *               Encoders may rely on profiles for quality levels.
404 *		 May be ignored by decoders.
405 * @profile: Mandatory for encoders, can be mandatory for specific
406 *		decoders as well. See SND_AUDIOPROFILE defines.
407 * @level: Supported level (Only used by WMA at the moment)
408 * @ch_mode: Channel mode for encoder. See SND_AUDIOCHANMODE defines
409 * @format: Format of encoded bistream. Mandatory when defined.
410 *		See SND_AUDIOSTREAMFORMAT defines.
411 * @align: Block alignment in bytes of an audio sample.
412 *		Only required for PCM or IEC formats.
413 * @options: encoder-specific settings
414 * @pcm_format: Output (for decoders) or input (for encoders)
415 *               PCM formats (required to accel mode, 0 for other modes)
416 * @reserved: reserved for future use
417 */
418
419struct snd_codec {
420	__u32 id;
421	__u32 ch_in;
422	__u32 ch_out;
423	__u32 sample_rate;
424	__u32 bit_rate;
425	__u32 rate_control;
426	__u32 profile;
427	__u32 level;
428	__u32 ch_mode;
429	__u32 format;
430	__u32 align;
431	union snd_codec_options options;
432	__u32 pcm_format;
433	__u32 reserved[2];
434} __attribute__((packed, aligned(4)));
435
436#endif