4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jonghyuk Choi <jhchoi.choi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #ifndef __AVSYS_AUDIO_H__
23 #define __AVSYS_AUDIO_H__
25 #include "avsys-types.h"
26 #include "avsys-error.h"
37 This part describes the interface with audio input/output.
40 #define AVSYS_AUDIO_VOLUME_MAX_MULTIMEDIA 16
41 #define AVSYS_AUDIO_VOLUME_MAX_BASIC 8
42 #define AVSYS_AUDIO_VOLUME_MAX_SINGLE 1
45 * Enumerations for audio mode
47 enum avsys_audio_mode_t {
48 AVSYS_AUDIO_MODE_OUTPUT, /**< Output mode of handle */
49 AVSYS_AUDIO_MODE_OUTPUT_CLOCK, /**< Output mode of gst audio only mode */
50 AVSYS_AUDIO_MODE_OUTPUT_VIDEO, /**< Output mode of gst video mode */
51 AVSYS_AUDIO_MODE_OUTPUT_LOW_LATENCY, /**< Output mode for low latency play mode. typically for game */
52 AVSYS_AUDIO_MODE_INPUT, /**< Input mode of handle */
53 AVSYS_AUDIO_MODE_INPUT_HIGH_LATENCY, /**< Input mode for high latency capture mode. */
54 AVSYS_AUDIO_MODE_INPUT_LOW_LATENCY, /**< Input mode for low latency capture mode. typically for VoIP */
55 AVSYS_AUDIO_MODE_CALL_OUT, /**< for voice call establish */
56 AVSYS_AUDIO_MODE_CALL_IN, /**< for voice call establish */
57 AVSYS_AUDIO_MODE_OUTPUT_AP_CALL, /**< for VT call on thin modem */
58 AVSYS_AUDIO_MODE_INPUT_AP_CALL, /**< for VT call on thin modem */
59 AVSYS_AUDIO_MODE_NUM, /**< Number of mode */
63 * Enumerations for audio format
65 enum avsys_audio_format_t {
66 AVSYS_AUDIO_FORMAT_UNKNOWN = -1, /**< Invalid audio format */
67 AVSYS_AUDIO_FORMAT_8BIT, /**< Unsigned 8Bit */
68 AVSYS_AUDIO_FORMAT_16BIT, /**< Signed 16bit Little Endian */
69 AVSYS_AUDIO_FORMAT_MIN = AVSYS_AUDIO_FORMAT_8BIT, /**< Minimum value 8-bit integer per sample */
70 AVSYS_AUDIO_FORMAT_MAX = AVSYS_AUDIO_FORMAT_16BIT, /**< Maximum value 16-bit integer per sample */
75 * Enums for volume types
77 enum avsys_audio_volume_type_t {
78 AVSYS_AUDIO_VOLUME_TYPE_SYSTEM,
79 AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION,
80 AVSYS_AUDIO_VOLUME_TYPE_ALARM,
81 AVSYS_AUDIO_VOLUME_TYPE_RINGTONE,
82 AVSYS_AUDIO_VOLUME_TYPE_MEDIA,
83 AVSYS_AUDIO_VOLUME_TYPE_CALL,
84 AVSYS_AUDIO_VOLUME_TYPE_FIXED,
85 AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_JAVA,
86 AVSYS_AUDIO_VOLUME_TYPE_MEDIA_HL,
87 AVSYS_AUDIO_VOLUME_TYPE_NUM,
88 AVSYS_AUDIO_VOLUME_TYPE_MAX = AVSYS_AUDIO_VOLUME_TYPE_NUM,
89 AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_ANDROID = AVSYS_AUDIO_VOLUME_TYPE_FIXED,
92 enum avsys_audio_priority_t {
93 AVSYS_AUDIO_PRIORITY_0 = 0, /*< deprecated. use AVSYS_AUDIO_PRIORITY_NORMAL or AVSYS_AUDIO_PRIORITY_SOLO instead */
94 AVSYS_AUDIO_PRIORITY_NORMAL = AVSYS_AUDIO_PRIORITY_0,
95 AVSYS_AUDIO_PRIORITY_SOLO,
96 AVSYS_AUDIO_PRIORITY_SOLO_WITH_TRANSITION_EFFECT,
97 AVSYS_AUDIO_PRIORITY_MAX,
100 enum avsys_audio_device_t {
101 AVSYS_AUDIO_DEVICE_TYPE_SPK = 0,
102 AVSYS_AUDIO_DEVICE_TYPE_RECV,
103 AVSYS_AUDIO_DEVICE_TYPE_HEADSET,
104 AVSYS_AUDIO_DEVICE_TYPE_HANDSFREE,
105 AVSYS_AUDIO_DEVICE_TYPE_BT,
106 AVSYS_AUDIO_DEVICE_TYPE_NUM,
107 AVSYS_AUDIO_DEVICE_TYPE_MAX = AVSYS_AUDIO_DEVICE_TYPE_NUM,
111 * Enumerations for audio channel
113 enum avsys_audio_channel_t {
114 AVSYS_AUDIO_CHANNEL_LEFT, /**< front-left channel */
115 AVSYS_AUDIO_CHANNEL_RIGHT, /**< front-righth channel */
116 AVSYS_AUDIO_CHANNEL_NUM, /**< Number of channels */
120 * Enumerations for audio mute condition
122 enum avsys_audio_mute_t {
123 AVSYS_AUDIO_UNMUTE = 0, /**< Unmute state */
124 AVSYS_AUDIO_MUTE, /**< Mute state */
125 AVSYS_AUDIO_UNMUTE_NOLOCK, /** < Unmute without lock */
126 AVSYS_AUDIO_MUTE_NOLOCK, /** < Mute without lock */
130 * Enumerations for priority command
132 enum avsys_audio_priority_cmd_t {
133 AVSYS_AUDIO_SET_PRIORITY = 0, /**< Command set priority */
134 AVSYS_AUDIO_UNSET_PRIORITY, /**< Command unset priority */
138 * Structure for sound device parameters.
141 int mode; /**< Open mode (In/Out) */
142 int priority; /**< Priority of sound handle */
143 int channels; /**< Number of channels */
144 int samplerate; /**< Sampling rate */
145 int format; /**< Sampling format */
146 int bluetooth; /**< Handle route information. refer. avsys_audio_handle_route_t */
147 int vol_type; /**< volume type */
149 } avsys_audio_param_t;
153 * Structure for volume information.
156 int level[AVSYS_AUDIO_CHANNEL_NUM]; /**< Array of volume level for each channel */
157 } avsys_audio_volume_t;
159 /* NEW PATH DEFINE */
163 enum avsys_audio_path_ex {
164 AVSYS_AUDIO_PATH_EX_NONE = 0,
165 AVSYS_AUDIO_PATH_EX_SPK,
166 AVSYS_AUDIO_PATH_EX_RECV,
167 AVSYS_AUDIO_PATH_EX_HEADSET,
168 AVSYS_AUDIO_PATH_EX_BTHEADSET,
169 AVSYS_AUDIO_PATH_EX_A2DP,
170 AVSYS_AUDIO_PATH_EX_HANDSFREE,
171 AVSYS_AUDIO_PATH_EX_HDMI,
172 AVSYS_AUDIO_PATH_EX_OUTMAX,
173 AVSYS_AUDIO_PATH_EX_MIC = 1,
174 AVSYS_AUDIO_PATH_EX_HEADSETMIC,
175 AVSYS_AUDIO_PATH_EX_BTMIC,
176 AVSYS_AUDIO_PATH_EX_FMINPUT,
177 AVSYS_AUDIO_PATH_EX_HANDSFREEMIC,
178 AVSYS_AUDIO_PATH_EX_INMAX,
181 enum avsys_audio_gain_ex {
182 AVSYS_AUDIO_GAIN_EX_KEYTONE = 0,
183 AVSYS_AUDIO_GAIN_EX_RINGTONE,
184 AVSYS_AUDIO_GAIN_EX_ALARMTONE,
185 AVSYS_AUDIO_GAIN_EX_CALLTONE,
186 AVSYS_AUDIO_GAIN_EX_AUDIOPLAYER,
187 AVSYS_AUDIO_GAIN_EX_VIDEOPLAYER,
188 AVSYS_AUDIO_GAIN_EX_VOICECALL,
189 AVSYS_AUDIO_GAIN_EX_VIDEOCALL,
190 AVSYS_AUDIO_GAIN_EX_FMRADIO,
191 AVSYS_AUDIO_GAIN_EX_VOICEREC,
192 AVSYS_AUDIO_GAIN_EX_CAMCORDER,
193 AVSYS_AUDIO_GAIN_EX_CAMERA,
194 AVSYS_AUDIO_GAIN_EX_GAME,
195 AVSYS_AUDIO_GAIN_EX_MAX,
196 AVSYS_AUDIO_GAIN_EX_PDA_PLAYBACK = AVSYS_AUDIO_GAIN_EX_KEYTONE,
200 AVSYS_AUDIO_EXT_DEVICE_FMRADIO = 0,
201 AVSYS_AUDIO_EXT_DEVICE_NUM
202 }avsysaudio_ext_device_t;
206 AVSYS_AUDIO_ROUTE_POLICY_DEFAULT,
207 AVSYS_AUDIO_ROUTE_POLICY_IGNORE_A2DP,
208 AVSYS_AUDIO_ROUTE_POLICY_HANDSET_ONLY,
209 AVSYS_AUDIO_ROUTE_POLICY_MAX,
210 }avsys_audio_route_policy_t; /* system global configuration */
212 enum avsys_audio_handle_route_t{
213 AVSYS_AUDIO_HANDLE_ROUTE_FOLLOWING_POLICY,
214 AVSYS_AUDIO_HANDLE_ROUTE_HANDSET_ONLY,
215 }; /* custom routing per handle */
218 AVSYS_AUDIO_ROUTE_DEVICE_UNKNOWN = -1,
219 AVSYS_AUDIO_ROUTE_DEVICE_HANDSET,
220 AVSYS_AUDIO_ROUTE_DEVICE_BLUETOOTH,
221 AVSYS_AUDIO_ROUTE_DEVICE_EARPHONE,
222 AVSYS_AUDIO_ROUTE_DEVICE_NUM,
223 }avsys_audio_playing_devcie_t;/* routing device */
226 #define AVSYS_AUDIO_PATH_OPTION_NONE 0x00000000 /*!< Sound path option none */
227 #define AVSYS_AUDIO_PATH_OPTION_JACK_AUTO 0x00000001 /*!< Sound path auto change between SPK/Recv and headset */
228 #define AVSYS_AUDIO_PATH_OPTION_DUAL_OUT 0x00000002 /*!< SPK or Recv with headset sound path. used for Ringtone or Alarm */
229 #define AVSYS_AUDIO_PATH_OPTION_LEFT_SPK_ONLY 0x00000004 /*!< AP playback left speaker only */
230 #define AVSYS_AUDIO_PATH_OPTION_RIGHT_SPK_ONLY 0x00000008 /*!< AP playback right speaker only */
231 #define AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC 0x00000010 /*!< Voice call recording path option */
232 #define AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC 0x00000020 /*!< Use sub-mic when call or recording */
233 #define AVSYS_AUDIO_PATH_OPTION_USE_STEREOMIC 0x00000040 /*!< Use stereo mic when recording */
234 #define AVSYS_AUDIO_PATH_OPTION_FORCED 0x01000000 /*!< Forced sound path setting. only for booting animation */
235 #define AVSYS_AUDIO_PATH_OPTION_LEGACY_MODE 0x10000000 /*!< Now Plus Style */
239 * This function make instance for audio system, and retreives handle.
241 * @param param [in] Parameters of audio system.
242 * @param phandle [out] Handle of audio system.
243 * @param size [out] Recomended buffer size.
245 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
246 * value with error code.
251 int avsys_audio_open(avsys_audio_param_t *param, avsys_handle_t *phandle, int *size);
254 * This function is to close sound handle and release allocated resources.
256 * @param handle [in] Handle of audio system
258 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
259 * value with error code.
263 int avsys_audio_close(avsys_handle_t handle);
266 * This function is to stop playback stream immediately. this drops all buffer remaining data.
268 * @param handle [in] Playback handle of audio system
270 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
271 * value with error code.
275 int avsys_audio_flush(avsys_handle_t handle);
278 * This function is to stop playback stream after all remaining buffer data played.
280 * @param handle [in] Playback handle of audio system
282 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
283 * value with error code.
287 int avsys_audio_drain(avsys_handle_t handle);
290 * This function is turn on speaker amp.
293 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
294 * value with error code.
298 int avsys_audio_ampon(void) __attribute__((deprecated));
301 * This function is turn off speaker amp.
303 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
304 * value with error code.
308 int avsys_audio_ampoff(void) __attribute__((deprecated));
311 * This function is to read pcm data from sound handle.
313 * @param handle [in] Handle of audio system
314 * @param buf [in] Buffer of audio data to read
315 * @param size [in] Size of buffer
317 * @return This function returns number of bytes read, or negative value with
318 * error code on failure.
322 int avsys_audio_read(avsys_handle_t handle, void *buf, int size);
325 * This function is to write audio data to sound handle.
327 * @param handle [in] Handle of audio system
328 * @param buf [in] Buffer of audio data to write
329 * @param size [in] Size of buffer
331 * @return This function returns number of bytes written, or negative value
332 * with error code on failure.
336 int avsys_audio_write(avsys_handle_t handle, void *buf, int size);
338 int avsys_audio_set_volume_table(int gain_type, int dev_type, int step, int lv, int rv);
339 int avsys_audio_get_volume_table(int gain_type, int dev_type, int step, int *lv, int *rv);
341 int avsys_audio_set_volume_fadeup(avsys_handle_t handle);
344 * This function is to get volume max.
346 * @param vol_type [in] Type of volume table
347 * @param max [out] number of volume steps
349 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
350 * value with error code.
354 int avsys_audio_get_volume_max_ex(int volume_table, int *max_step);
357 * This function is to set relative mute of sound handle.
359 * @param handle [in] Handle of audio system
360 * @param mute [in] Mute information to set
362 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
363 * value with error code.
365 * mute is AVSYS_AUDIO_MUTE : mute
366 * mute is AVSYS_AUDIO_UNMUTE : unmute
369 int avsys_audio_set_mute(avsys_handle_t handle, int mute);
373 * This function is to set mute of sound handle with fade out effect.
375 * @param handle [in] Handle of audio system
377 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
378 * value with error code.
382 int avsys_audio_set_mute_fadedown(avsys_handle_t handle);
385 * This function is to get relative mute of sound handle.
387 * @param handle [in] Handle of audio system
388 * @param pmute [out] Pointer to mute information to retrieve
390 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
391 * value with error code.
393 * pmute is AVSYS_AUDIO_MUTE : mute
394 * pmute is AVSYS_AUDIO_UNMUTE : unmute
395 * @see avsys_audio_mute_t
397 int avsys_audio_get_mute(avsys_handle_t handle, int* pmute);
401 * This function is to set amp on external device
403 * @param device [in] External audio device type
405 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
406 * value with error code.
408 * mute is AVSYS_AUDIO_MUTE : mute
409 * mute is AVSYS_AUDIO_UNMUTE : unmute
410 * @see avsysaudio_ext_device_t
412 int avsys_audio_ext_device_ampon(avsysaudio_ext_device_t device);
415 * This function is to set amp off external device
417 * @param device [in] External audio device type
419 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
420 * value with error code.
422 * pmute is AVSYS_AUDIO_MUTE : mute
423 * pmute is AVSYS_AUDIO_UNMUTE : unmute
424 * @see avsysaudio_ext_device_t
426 int avsys_audio_ext_device_ampoff(avsysaudio_ext_device_t device);
429 * This function is to set status of external device
431 * @param device [in] External audio device type
432 * @param onoff [in] 1 for on , 0 for off
434 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
435 * value with error code.
437 * @see avsysaudio_ext_device_t
439 int avsys_audio_set_ext_device_status(avsysaudio_ext_device_t device_type, int onoff);
442 * This function is to get status of external device
444 * @param device [in] External audio device type
445 * @param onoff [out] 1 for on , 0 for off
447 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
448 * value with error code.
450 * @see avsys_audio_set_ext_device_status
452 int avsys_audio_get_ext_device_status(avsysaudio_ext_device_t device_type, int *onoff);
454 * This function is to set sound path of sound device.
456 * @param path [in] value of sound gain
457 * @param output [in] value of output device
458 * @param input [in] value of input device
459 * @param option [in] value of sound path option
461 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
462 * value with error code.
463 * AVSYS_STATE_ERR_RANGE_OVER : input path value is invalid range
464 * AVSYS_STATE_ERR_INTERNAL : internal device error
468 int avsys_audio_set_path_ex(int gain, int out, int in, int option);
471 * This function is to get sound path of sound device.
473 * @param path [out] value of sound gain
474 * @param output [out] value of output device
475 * @param input [out] value of input device
476 * @param option [out] value of sound path option
478 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
479 * value with error code.
480 * AVSYS_STATE_ERR_INTERNAL : internal device error
484 int avsys_audio_get_path_ex(int *gain, int *out, int *in, int *option);
487 * This function is to set relative global mute of sound device.
489 * @param mute [in] Global mute information to retreive
491 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
492 * value with error code.
494 * mute is avsys_audio_mute_disable : unmute
495 * mute is avsys_audio_mute_enable : mute
497 * @see avsys_audio_mute_t
499 int avsys_audio_set_global_mute(int mute);
502 * This function is to get relative global mute of sound device.
504 * @param pmute [out] Pointer to global mute information to retreive
506 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
507 * value with error code.
509 * *pbmute is avsys_audio_mute_disable or avsys_audio_mute_enable
512 int avsys_audio_get_global_mute(int* pmute);
515 * This function is to get number of remaining audio frames in hw buffer.
517 * @param handle [in] handle to get delay frames
518 * @param frame_delay [out] value of number of remaining audio frames
520 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
521 * value with error code.
525 int avsys_audio_delay(avsys_handle_t handle, int *frame_delay);
528 * This function is to reset audio stream. (drops all remaining audio frames in device buffer)
530 * @param handle [in] handle to reset
532 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
533 * value with error code.
537 int avsys_audio_reset(avsys_handle_t handle);
540 * This function is to get period time and buffer time of audio stream.
542 * @param handle [in] handle to get period & buffer time
543 * @param period_time [out] value of period time in microsecond.
544 * @param buffer_time [out] value of buffer time in microsecond.
546 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
547 * value with error code.
551 int avsys_audio_get_period_buffer_time(avsys_handle_t handle, unsigned int *period_time, unsigned int *buffer_time);
554 * This function is to get playback audio device information of system.
556 * @param dev [out] current playback device type
558 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
559 * value with error code.
561 * @see avsys_audio_playing_devcie_t
563 int avsys_audio_get_playing_device_info(avsys_audio_playing_devcie_t *dev);
566 * This function is to get audio capturing status of system.
568 * @param on_capture [out] capture status.
569 * zero if there is no capture instance.
570 * positive value if there is capture instance
572 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
573 * value with error code.
577 int avsys_audio_get_capture_status(int *on_capture);
579 int avsys_audio_earjack_manager_init(int *earjack_type, int *waitfd);
580 int avsys_audio_earjack_manager_wait(int waitfd, int *current_earjack_type, int *new_earjack_type, int *need_mute);
581 int avsys_audio_earjack_manager_process(int new_earjack_type);
582 int avsys_audio_earjack_manager_deinit(int waitfd);
583 int avsys_audio_earjack_manager_unlock(void);
585 int avsys_audio_set_route_policy(avsys_audio_route_policy_t route);
586 int avsys_audio_get_route_policy(avsys_audio_route_policy_t *route);
587 int avsys_audio_get_current_playing_volume_type(int *volume_type);
588 int avsys_audio_set_volume_by_type(const int volume_type, const int volume_value);
589 int avsys_audio_set_primary_volume(const int pid, const int type);
590 int avsys_audio_clear_primary_volume(const int pid);
591 int avsys_audio_hibernation_reset(int *vol);
600 #endif /* __AVSYS_AUDIO_H__ */