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
44 #define AVSYS_AUDIO_VOLUME_CONFIG_TYPE(vol) (vol & 0x00FF)
45 #define AVSYS_AUDIO_VOLUME_CONFIG_GAIN(vol) (vol & 0xFF00)
46 #define AVSYS_AUDIO_VOLUME_GAIN_IDX(gain) ((gain >> 8) - 1)
48 #define AVSYS_CHANNEL_MIN 1
49 #define AVSYS_CHANNEL_MAX 6
52 * Enumerations for audio mode
54 enum avsys_audio_mode_t {
55 AVSYS_AUDIO_MODE_OUTPUT, /**< Output mode of handle */
56 AVSYS_AUDIO_MODE_OUTPUT_CLOCK, /**< Output mode of gst audio only mode */
57 AVSYS_AUDIO_MODE_OUTPUT_VIDEO, /**< Output mode of gst video mode */
58 AVSYS_AUDIO_MODE_OUTPUT_LOW_LATENCY, /**< Output mode for low latency play mode. typically for game */
59 AVSYS_AUDIO_MODE_INPUT, /**< Input mode of handle */
60 AVSYS_AUDIO_MODE_INPUT_HIGH_LATENCY, /**< Input mode for high latency capture mode. */
61 AVSYS_AUDIO_MODE_INPUT_LOW_LATENCY, /**< Input mode for low latency capture mode. typically for VoIP */
62 AVSYS_AUDIO_MODE_CALL_OUT, /**< for voice call establish */
63 AVSYS_AUDIO_MODE_CALL_IN, /**< for voice call establish */
64 AVSYS_AUDIO_MODE_OUTPUT_AP_CALL, /**< for VT call on thin modem */
65 AVSYS_AUDIO_MODE_INPUT_AP_CALL, /**< for VT call on thin modem */
66 AVSYS_AUDIO_MODE_NUM, /**< Number of mode */
70 * Enumerations for audio format
72 enum avsys_audio_format_t {
73 AVSYS_AUDIO_FORMAT_UNKNOWN = -1, /**< Invalid audio format */
74 AVSYS_AUDIO_FORMAT_8BIT, /**< Unsigned 8Bit */
75 AVSYS_AUDIO_FORMAT_16BIT, /**< Signed 16bit Little Endian */
76 AVSYS_AUDIO_FORMAT_MIN = AVSYS_AUDIO_FORMAT_8BIT, /**< Minimum value 8-bit integer per sample */
77 AVSYS_AUDIO_FORMAT_MAX = AVSYS_AUDIO_FORMAT_16BIT, /**< Maximum value 16-bit integer per sample */
82 * Enums for volume types
84 enum avsys_audio_volume_type_t {
85 AVSYS_AUDIO_VOLUME_TYPE_SYSTEM,
86 AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION,
87 AVSYS_AUDIO_VOLUME_TYPE_ALARM,
88 AVSYS_AUDIO_VOLUME_TYPE_RINGTONE,
89 AVSYS_AUDIO_VOLUME_TYPE_MEDIA,
90 AVSYS_AUDIO_VOLUME_TYPE_CALL,
91 AVSYS_AUDIO_VOLUME_TYPE_VOIP,
92 AVSYS_AUDIO_VOLUME_TYPE_FIXED,
93 AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_JAVA,
94 AVSYS_AUDIO_VOLUME_TYPE_NUM,
95 AVSYS_AUDIO_VOLUME_TYPE_MAX = AVSYS_AUDIO_VOLUME_TYPE_NUM,
96 AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_ANDROID = AVSYS_AUDIO_VOLUME_TYPE_FIXED,
99 enum avsys_audio_volume_gain_t {
100 AVSYS_AUDIO_VOLUME_GAIN_DIALER = 1<<8,
101 AVSYS_AUDIO_VOLUME_GAIN_TOUCH = 2<<8,
102 AVSYS_AUDIO_VOLUME_GAIN_AF = 3<<8,
103 AVSYS_AUDIO_VOLUME_GAIN_SHUTTER1 = 4<<8,
104 AVSYS_AUDIO_VOLUME_GAIN_SHUTTER2 = 5<<8,
105 AVSYS_AUDIO_VOLUME_GAIN_CAMCORDING = 6<<8,
106 AVSYS_AUDIO_VOLUME_GAIN_MIDI = 7<<8,
107 AVSYS_AUDIO_VOLUME_GAIN_BOOTING = 8<<8,
108 AVSYS_AUDIO_VOLUME_GAIN_VIDEO = 9<<8,
109 AVSYS_AUDIO_VOLUME_GAIN_VIDEO_HDMI = 10<<8,
110 AVSYS_AUDIO_VOLUME_GAIN_TYPE_MAX,
113 enum avsys_audio_priority_t {
114 AVSYS_AUDIO_PRIORITY_0 = 0, /*< deprecated. use AVSYS_AUDIO_PRIORITY_NORMAL or AVSYS_AUDIO_PRIORITY_SOLO instead */
115 AVSYS_AUDIO_PRIORITY_NORMAL = AVSYS_AUDIO_PRIORITY_0,
116 AVSYS_AUDIO_PRIORITY_SOLO,
117 AVSYS_AUDIO_PRIORITY_SOLO_WITH_TRANSITION_EFFECT,
118 AVSYS_AUDIO_PRIORITY_MAX,
121 enum avsys_audio_device_t {
122 AVSYS_AUDIO_DEVICE_TYPE_SPK = 0,
123 AVSYS_AUDIO_DEVICE_TYPE_RECV,
124 AVSYS_AUDIO_DEVICE_TYPE_HEADSET,
125 AVSYS_AUDIO_DEVICE_TYPE_HANDSFREE,
126 AVSYS_AUDIO_DEVICE_TYPE_BT,
127 AVSYS_AUDIO_DEVICE_TYPE_NUM,
128 AVSYS_AUDIO_DEVICE_TYPE_MAX = AVSYS_AUDIO_DEVICE_TYPE_NUM,
132 * Enumerations for audio channel
134 enum avsys_audio_channel_t {
135 AVSYS_AUDIO_CHANNEL_LEFT, /**< front-left channel */
136 AVSYS_AUDIO_CHANNEL_RIGHT, /**< front-righth channel */
137 AVSYS_AUDIO_CHANNEL_NUM, /**< Number of channels */
141 * Enumerations for audio mute condition
143 enum avsys_audio_mute_t {
144 AVSYS_AUDIO_UNMUTE = 0, /**< Unmute state */
145 AVSYS_AUDIO_MUTE, /**< Mute state */
146 AVSYS_AUDIO_UNMUTE_NOLOCK, /** < Unmute without lock */
147 AVSYS_AUDIO_MUTE_NOLOCK, /** < Mute without lock */
151 * Enumerations for priority command
153 enum avsys_audio_priority_cmd_t {
154 AVSYS_AUDIO_SET_PRIORITY = 0, /**< Command set priority */
155 AVSYS_AUDIO_UNSET_PRIORITY, /**< Command unset priority */
159 * Structure for sound device parameters.
162 int mode; /**< Open mode (In/Out) */
163 int priority; /**< Priority of sound handle */
164 int channels; /**< Number of channels */
165 int samplerate; /**< Sampling rate */
166 int format; /**< Sampling format */
167 int handle_route; /**< Handle route information. refer. avsys_audio_handle_route_t */
168 int vol_type; /**< volume type */
170 } avsys_audio_param_t;
174 * Structure for volume information.
177 int level[AVSYS_AUDIO_CHANNEL_NUM]; /**< Array of volume level for each channel */
178 } avsys_audio_volume_t;
180 /* NEW PATH DEFINE */
184 enum avsys_audio_path_ex {
185 AVSYS_AUDIO_PATH_EX_NONE = 0,
186 AVSYS_AUDIO_PATH_EX_SPK,
187 AVSYS_AUDIO_PATH_EX_RECV,
188 AVSYS_AUDIO_PATH_EX_HEADSET,
189 AVSYS_AUDIO_PATH_EX_BTHEADSET,
190 AVSYS_AUDIO_PATH_EX_A2DP,
191 AVSYS_AUDIO_PATH_EX_HANDSFREE,
192 AVSYS_AUDIO_PATH_EX_HDMI,
193 AVSYS_AUDIO_PATH_EX_DOCK,
194 AVSYS_AUDIO_PATH_EX_USBAUDIO,
195 AVSYS_AUDIO_PATH_EX_OUTMAX,
196 AVSYS_AUDIO_PATH_EX_MIC = 1,
197 AVSYS_AUDIO_PATH_EX_HEADSETMIC,
198 AVSYS_AUDIO_PATH_EX_BTMIC,
199 AVSYS_AUDIO_PATH_EX_FMINPUT,
200 AVSYS_AUDIO_PATH_EX_HANDSFREEMIC,
201 AVSYS_AUDIO_PATH_EX_INMAX,
204 enum avsys_audio_gain_ex {
205 AVSYS_AUDIO_GAIN_EX_KEYTONE = 0,
206 AVSYS_AUDIO_GAIN_EX_RINGTONE,
207 AVSYS_AUDIO_GAIN_EX_ALARMTONE,
208 AVSYS_AUDIO_GAIN_EX_CALLTONE,
209 AVSYS_AUDIO_GAIN_EX_AUDIOPLAYER,
210 AVSYS_AUDIO_GAIN_EX_VIDEOPLAYER,
211 AVSYS_AUDIO_GAIN_EX_VOICECALL,
212 AVSYS_AUDIO_GAIN_EX_VIDEOCALL,
213 AVSYS_AUDIO_GAIN_EX_FMRADIO,
214 AVSYS_AUDIO_GAIN_EX_VOICEREC,
215 AVSYS_AUDIO_GAIN_EX_CAMCORDER,
216 AVSYS_AUDIO_GAIN_EX_CAMERA,
217 AVSYS_AUDIO_GAIN_EX_GAME,
218 AVSYS_AUDIO_GAIN_EX_MAX,
219 AVSYS_AUDIO_GAIN_EX_PDA_PLAYBACK = AVSYS_AUDIO_GAIN_EX_KEYTONE,
223 AVSYS_AUDIO_EXT_DEVICE_FMRADIO = 0,
224 AVSYS_AUDIO_EXT_DEVICE_NUM
225 }avsysaudio_ext_device_t;
229 AVSYS_AUDIO_ROUTE_POLICY_DEFAULT,
230 AVSYS_AUDIO_ROUTE_POLICY_IGNORE_A2DP,
231 AVSYS_AUDIO_ROUTE_POLICY_HANDSET_ONLY,
232 AVSYS_AUDIO_ROUTE_POLICY_MAX,
233 }avsys_audio_route_policy_t; /* system global configuration */
235 enum avsys_audio_handle_route_t{
236 AVSYS_AUDIO_HANDLE_ROUTE_FOLLOWING_POLICY,
237 AVSYS_AUDIO_HANDLE_ROUTE_HANDSET_ONLY,
238 }; /* custom routing per handle */
241 AVSYS_AUDIO_ROUTE_DEVICE_UNKNOWN = -1,
242 AVSYS_AUDIO_ROUTE_DEVICE_HANDSET,
243 AVSYS_AUDIO_ROUTE_DEVICE_BLUETOOTH,
244 AVSYS_AUDIO_ROUTE_DEVICE_EARPHONE,
245 AVSYS_AUDIO_ROUTE_DEVICE_NUM,
246 }avsys_audio_playing_devcie_t;/* routing device */
249 #define AVSYS_AUDIO_PATH_OPTION_NONE 0x00000000 /*!< Sound path option none */
250 #define AVSYS_AUDIO_PATH_OPTION_DUAL_OUT 0x00000002 /*!< SPK or Recv with headset sound path. used for Ringtone or Alarm */
251 #define AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC 0x00000010 /*!< Voice call recording path option */
252 #define AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC 0x00000020 /*!< Use sub-mic when call or recording */
253 #define AVSYS_AUDIO_PATH_OPTION_USE_STEREOMIC 0x00000040 /*!< Use stereo mic when recording */
254 #define AVSYS_AUDIO_PATH_OPTION_FORCED 0x01000000 /*!< Forced sound path setting. only for booting animation */
258 * This function make instance for audio system, and retreives handle.
260 * @param param [in] Parameters of audio system.
261 * @param phandle [out] Handle of audio system.
262 * @param size [out] Recomended buffer size.
264 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
265 * value with error code.
270 int avsys_audio_open(avsys_audio_param_t *param, avsys_handle_t *phandle, int *size);
273 * This function is to close sound handle and release allocated resources.
275 * @param handle [in] Handle of audio system
277 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
278 * value with error code.
282 int avsys_audio_close(avsys_handle_t handle);
285 * This function is to update volume type & volume gain.
287 * @param handle [in] Handle of audio system
289 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
290 * value with error code.
294 int avsys_audio_update_volume_config(avsys_handle_t handle, int volume_config);
297 * This function is to stop playback stream immediately. this drops all buffer remaining data.
299 * @param handle [in] Playback handle of audio system
301 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
302 * value with error code.
306 int avsys_audio_flush(avsys_handle_t handle);
309 * This function is to stop playback stream after all remaining buffer data played.
311 * @param handle [in] Playback handle of audio system
313 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
314 * value with error code.
318 int avsys_audio_drain(avsys_handle_t handle);
321 * This function is turn on speaker amp.
324 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
325 * value with error code.
329 int avsys_audio_ampon(void) __attribute__((deprecated));
332 * This function is turn off speaker amp.
334 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
335 * value with error code.
339 int avsys_audio_ampoff(void) __attribute__((deprecated));
342 * This function is to read pcm data from sound handle.
344 * @param handle [in] Handle of audio system
345 * @param buf [in] Buffer of audio data to read
346 * @param size [in] Size of buffer
348 * @return This function returns number of bytes read, or negative value with
349 * error code on failure.
353 int avsys_audio_read(avsys_handle_t handle, void *buf, int size);
356 * This function is to write audio data to sound handle.
358 * @param handle [in] Handle of audio system
359 * @param buf [in] Buffer of audio data to write
360 * @param size [in] Size of buffer
362 * @return This function returns number of bytes written, or negative value
363 * with error code on failure.
367 int avsys_audio_write(avsys_handle_t handle, void *buf, int size);
369 int avsys_audio_set_volume_table(int volume_type, int dev_type, int step, int lv, int rv);
370 int avsys_audio_get_volume_table(int volume_type, int dev_type, int step, int *lv, int *rv);
371 int avsys_audio_set_volume_gain_table(int volume_gain_idx, int dev_type, float lv, float rv);
372 int avsys_audio_get_volume_gain_table(int volume_gain_idx, int dev_type, float *lv, float *rv);
374 int avsys_audio_set_volume_fadeup(avsys_handle_t handle);
377 * This function is to get volume max.
379 * @param vol_type [in] Type of volume table
380 * @param max [out] number of volume steps
382 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
383 * value with error code.
387 int avsys_audio_get_volume_max_ex(int volume_table, int *max_step);
390 * This function is to set relative mute of sound handle.
392 * @param handle [in] Handle of audio system
393 * @param mute [in] Mute information to set
395 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
396 * value with error code.
398 * mute is AVSYS_AUDIO_MUTE : mute
399 * mute is AVSYS_AUDIO_UNMUTE : unmute
402 int avsys_audio_set_mute(avsys_handle_t handle, int mute);
406 * This function is to set mute of sound handle with fade out effect.
408 * @param handle [in] Handle of audio system
410 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
411 * value with error code.
415 int avsys_audio_set_mute_fadedown(avsys_handle_t handle);
418 * This function is to get relative mute of sound handle.
420 * @param handle [in] Handle of audio system
421 * @param pmute [out] Pointer to mute information to retrieve
423 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
424 * value with error code.
426 * pmute is AVSYS_AUDIO_MUTE : mute
427 * pmute is AVSYS_AUDIO_UNMUTE : unmute
428 * @see avsys_audio_mute_t
430 int avsys_audio_get_mute(avsys_handle_t handle, int* pmute);
434 * This function is to set amp on external device
436 * @param device [in] External audio device type
438 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
439 * value with error code.
441 * mute is AVSYS_AUDIO_MUTE : mute
442 * mute is AVSYS_AUDIO_UNMUTE : unmute
443 * @see avsysaudio_ext_device_t
445 int avsys_audio_ext_device_ampon(avsysaudio_ext_device_t device);
448 * This function is to set amp off external device
450 * @param device [in] External audio device type
452 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
453 * value with error code.
455 * pmute is AVSYS_AUDIO_MUTE : mute
456 * pmute is AVSYS_AUDIO_UNMUTE : unmute
457 * @see avsysaudio_ext_device_t
459 int avsys_audio_ext_device_ampoff(avsysaudio_ext_device_t device);
462 * This function is to set status of external device
464 * @param device [in] External audio device type
465 * @param onoff [in] 1 for on , 0 for off
467 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
468 * value with error code.
470 * @see avsysaudio_ext_device_t
472 int avsys_audio_set_ext_device_status(avsysaudio_ext_device_t device_type, int onoff);
475 * This function is to get status of external device
477 * @param device [in] External audio device type
478 * @param onoff [out] 1 for on , 0 for off
480 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
481 * value with error code.
483 * @see avsys_audio_set_ext_device_status
485 int avsys_audio_get_ext_device_status(avsysaudio_ext_device_t device_type, int *onoff);
487 * This function is to set sound path of sound device.
489 * @param path [in] value of sound gain
490 * @param output [in] value of output device
491 * @param input [in] value of input device
492 * @param option [in] value of sound path option
494 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
495 * value with error code.
496 * AVSYS_STATE_ERR_RANGE_OVER : input path value is invalid range
497 * AVSYS_STATE_ERR_INTERNAL : internal device error
501 int avsys_audio_set_path_ex(int gain, int out, int in, int option);
504 * This function is to get sound path of sound device.
506 * @param path [out] value of sound gain
507 * @param output [out] value of output device
508 * @param input [out] value of input device
509 * @param option [out] value of sound path option
511 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
512 * value with error code.
513 * AVSYS_STATE_ERR_INTERNAL : internal device error
517 int avsys_audio_get_path_ex(int *gain, int *out, int *in, int *option);
520 * This function is to set relative global mute of sound device.
522 * @param mute [in] Global mute information to retreive
524 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
525 * value with error code.
527 * mute is avsys_audio_mute_disable : unmute
528 * mute is avsys_audio_mute_enable : mute
530 * @see avsys_audio_mute_t
532 int avsys_audio_set_global_mute(int mute);
535 * This function is to get relative global mute of sound device.
537 * @param pmute [out] Pointer to global mute information to retreive
539 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
540 * value with error code.
542 * *pbmute is avsys_audio_mute_disable or avsys_audio_mute_enable
545 int avsys_audio_get_global_mute(int* pmute);
548 * This function is to get number of remaining audio frames in hw buffer.
550 * @param handle [in] handle to get delay frames
551 * @param frame_delay [out] value of number of remaining audio frames
553 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
554 * value with error code.
558 int avsys_audio_delay(avsys_handle_t handle, int *frame_delay);
561 * This function is to reset audio stream. (drops all remaining audio frames in device buffer)
563 * @param handle [in] handle to reset
565 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
566 * value with error code.
570 int avsys_audio_reset(avsys_handle_t handle);
573 * This function is to get period time and buffer time of audio stream.
575 * @param handle [in] handle to get period & buffer time
576 * @param period_time [out] value of period time in microsecond.
577 * @param buffer_time [out] value of buffer time in microsecond.
579 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
580 * value with error code.
584 int avsys_audio_get_period_buffer_time(avsys_handle_t handle, unsigned int *period_time, unsigned int *buffer_time);
587 * This function is to cork stream.
589 * @param handle [in] handle to cork
590 * @param cork [in] cork=1, uncork=0
592 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
593 * value with error code.
597 int avsys_audio_cork (avsys_handle_t handle, int cork);
600 * This function is to check whether stream is corked or not.
602 * @param handle [in] handle to cork
603 * @param is_corked [out] corked is 1, otherwise 0
605 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
606 * value with error code.
610 int avsys_audio_is_corked (avsys_handle_t handle, int *is_corked);
613 * This function is to get audio capturing status of system.
615 * @param on_capture [out] capture status.
616 * zero if there is no capture instance.
617 * positive value if there is capture instance
619 * @return This function returns AVSYS_STATE_SUCCESS on success, or negative
620 * value with error code.
624 int avsys_audio_get_capture_status(int *on_capture);
626 int avsys_audio_earjack_manager_init(int *earjack_type, int *waitfd);
627 int avsys_audio_earjack_manager_wait(int waitfd, int *current_earjack_type, int *new_earjack_type, int *need_mute);
628 int avsys_audio_earjack_manager_process(int new_earjack_type);
629 int avsys_audio_earjack_manager_deinit(int waitfd);
630 int avsys_audio_earjack_manager_get_type(void);
631 int avsys_audio_earjack_manager_unlock(void);
633 int avsys_audio_set_route_policy(avsys_audio_route_policy_t route);
634 int avsys_audio_get_route_policy(avsys_audio_route_policy_t *route);
635 int avsys_audio_get_current_playing_volume_type(int *volume_type);
636 int avsys_audio_set_volume_by_type(const int volume_type, const int volume_value);
637 int avsys_audio_set_primary_volume(const int pid, const int type);
638 int avsys_audio_clear_primary_volume(const int pid);
639 int avsys_audio_hibernation_reset(int *vol);
648 #endif /* __AVSYS_AUDIO_H__ */