diff options
author | Seungbae Shin <seungbae.shin@samsung.com> | 2016-03-23 20:19:47 +0900 |
---|---|---|
committer | Seungbae Shin <seungbae.shin@samsung.com> | 2016-03-23 20:19:47 +0900 |
commit | 3cdef9c950ee75607d56e2079d392d4533c0e981 (patch) | |
tree | 152d777ddba091a417b834c1a9af806a90249f64 | |
parent | e79006973e831643a884a6ca69c29a143207d554 (diff) | |
download | audio-hal-wm1831-3cdef9c950ee75607d56e2079d392d4533c0e981.tar.gz audio-hal-wm1831-3cdef9c950ee75607d56e2079d392d4533c0e981.tar.bz2 audio-hal-wm1831-3cdef9c950ee75607d56e2079d392d4533c0e981.zip |
Sync with latest reference HALsubmit/tizen/20160323.125029
[Version] 0.1.2
[Profile] Common
[Issue Type] Bug
Change-Id: I13ec8e89b48a46c27b9b2879be82580eec760845
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | packaging/audio-hal-wm1831.spec | 2 | ||||
-rw-r--r-- | tizen-audio-device.c | 92 | ||||
-rw-r--r-- | tizen-audio-internal.h | 48 | ||||
-rw-r--r-- | tizen-audio.c | 17 | ||||
-rw-r--r-- | tizen-audio.h | 13 |
6 files changed, 125 insertions, 48 deletions
diff --git a/Makefile.am b/Makefile.am index 1145f10..b5c6943 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,7 @@ libtizen_audio_la_SOURCES = tizen-audio.c \ tizen-audio-device.c \ tizen-audio-volume.c \ tizen-audio-ucm.c \ + tizen-audio-comm.c \ tizen-audio-util.c libtizen_audio_la_LDFLAGS = $(AM_LDFLAGS) -disable-static -avoid-version if USE_TINYALSA diff --git a/packaging/audio-hal-wm1831.spec b/packaging/audio-hal-wm1831.spec index 7ff7681..576e82a 100644 --- a/packaging/audio-hal-wm1831.spec +++ b/packaging/audio-hal-wm1831.spec @@ -1,6 +1,6 @@ Name: audio-hal-wm1831 Summary: TIZEN Audio HAL for WM1831 -Version: 0.1.1 +Version: 0.1.2 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-device.c b/tizen-audio-device.c index 2a22f81..e9c4d11 100644 --- a/tizen-audio-device.c +++ b/tizen-audio-device.c @@ -32,7 +32,6 @@ /* FIXME : To avoid build warning... */ int _snd_pcm_poll_descriptor(snd_pcm_t *pcm); #endif - /* #define DEBUG_TIMING */ static device_type_t outDeviceTypes[] = { @@ -51,6 +50,10 @@ static device_type_t inDeviceTypes[] = { { 0, 0 }, }; +static const char* mode_to_verb_str[] = { + AUDIO_USE_CASE_VERB_HIFI, +}; + static uint32_t convert_device_string_to_enum(const char* device_str, uint32_t direction) { uint32_t device = 0; @@ -89,6 +92,7 @@ static audio_return_t set_devices(audio_hal_t *ah, const char *verb, device_info AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(num_of_devices, AUDIO_ERR_PARAMETER); if (num_of_devices > MAX_DEVICES) { num_of_devices = MAX_DEVICES; @@ -96,23 +100,29 @@ static audio_return_t set_devices(audio_hal_t *ah, const char *verb, device_info return AUDIO_ERR_PARAMETER; } - if ((devices[0].direction == AUDIO_DIRECTION_OUT) && ah->device.active_in) { - /* check the active in devices */ - for (j = 0; j < inDeviceTypes[j].type; j++) { - if (((ah->device.active_in & (~0x80000000)) & inDeviceTypes[j].type)) - active_devices[dev_idx++] = inDeviceTypes[j].name; + if (devices[0].direction == AUDIO_DIRECTION_OUT) { + ah->device.active_out &= 0x0; + if (ah->device.active_in) { + /* check the active in devices */ + for (j = 0; j < inDeviceTypes[j].type; j++) { + if (((ah->device.active_in & (~AUDIO_DEVICE_IN)) & inDeviceTypes[j].type)) + active_devices[dev_idx++] = inDeviceTypes[j].name; + } } - } else if ((devices[0].direction == AUDIO_DIRECTION_IN) && ah->device.active_out) { - /* check the active out devices */ - for (j = 0; j < outDeviceTypes[j].type; j++) { - if (ah->device.active_out & outDeviceTypes[j].type) - active_devices[dev_idx++] = outDeviceTypes[j].name; + } else if (devices[0].direction == AUDIO_DIRECTION_IN) { + ah->device.active_in &= 0x0; + if (ah->device.active_out) { + /* check the active out devices */ + for (j = 0; j < outDeviceTypes[j].type; j++) { + if (ah->device.active_out & outDeviceTypes[j].type) + active_devices[dev_idx++] = outDeviceTypes[j].name; + } } } for (i = 0; i < num_of_devices; i++) { new_device = convert_device_string_to_enum(devices[i].type, devices[i].direction); - if (new_device & 0x80000000) { + if (new_device & AUDIO_DEVICE_IN) { for (j = 0; j < inDeviceTypes[j].type; j++) { if (new_device == inDeviceTypes[j].type) { active_devices[dev_idx++] = inDeviceTypes[j].name; @@ -135,12 +145,10 @@ static audio_return_t set_devices(audio_hal_t *ah, const char *verb, device_info } audio_ret = _audio_ucm_set_devices(ah, verb, active_devices); - if (audio_ret) { + if (audio_ret) AUDIO_LOG_ERROR("Failed to set device: error = %d", audio_ret); - return audio_ret; - } - return audio_ret; + return audio_ret; } audio_return_t _audio_device_init(audio_hal_t *ah) @@ -169,7 +177,7 @@ static audio_return_t _do_route_ap_playback_capture(audio_hal_t *ah, audio_route { audio_return_t audio_ret = AUDIO_RET_OK; device_info_t *devices = NULL; - const char *verb = NULL; + const char *verb = mode_to_verb_str[VERB_NORMAL]; AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(route_info, AUDIO_ERR_PARAMETER); @@ -180,7 +188,6 @@ static audio_return_t _do_route_ap_playback_capture(audio_hal_t *ah, audio_route /* int mod_idx = 0; */ /* const char *modifiers[MAX_MODIFIERS] = {NULL,}; */ - verb = AUDIO_USE_CASE_VERB_HIFI; AUDIO_LOG_INFO("do_route_ap_playback_capture++ "); audio_ret = set_devices(ah, verb, devices, route_info->num_of_devices); @@ -211,11 +218,10 @@ static audio_return_t _do_route_ap_playback_capture(audio_hal_t *ah, audio_route return audio_ret; } -audio_return_t _do_route_voip(audio_hal_t *ah, device_info_t *devices, int32_t num_of_devices) +static audio_return_t _do_route_voip(audio_hal_t *ah, device_info_t *devices, int32_t num_of_devices) { audio_return_t audio_ret = AUDIO_RET_OK; - const char *verb = NULL; - verb = AUDIO_USE_CASE_VERB_HIFI; + const char *verb = mode_to_verb_str[VERB_NORMAL]; AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER); @@ -234,9 +240,11 @@ audio_return_t _do_route_voip(audio_hal_t *ah, device_info_t *devices, int32_t n return audio_ret; } -audio_return_t _do_route_reset(audio_hal_t *ah, uint32_t direction) +static audio_return_t _do_route_reset(audio_hal_t *ah, uint32_t direction) { audio_return_t audio_ret = AUDIO_RET_OK; + const char *active_devices[MAX_DEVICES] = {NULL,}; + int i = 0, dev_idx = 0; /* FIXME: If you need to reset, set verb inactive */ /* const char *verb = NULL; */ @@ -244,18 +252,46 @@ audio_return_t _do_route_reset(audio_hal_t *ah, uint32_t direction) AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); - AUDIO_LOG_INFO("do_route_reset++, direction(%p)", direction); + AUDIO_LOG_INFO("do_route_reset++, direction(0x%x)", direction); if (direction == AUDIO_DIRECTION_OUT) { ah->device.active_out &= 0x0; + if (ah->device.active_in) { + /* check the active in devices */ + for (i = 0; i < inDeviceTypes[i].type; i++) { + if (((ah->device.active_in & (~AUDIO_DEVICE_IN)) & inDeviceTypes[i].type)) { + active_devices[dev_idx++] = inDeviceTypes[i].name; + AUDIO_LOG_INFO("added for in : %s", inDeviceTypes[i].name); + } + } + } } else { ah->device.active_in &= 0x0; + if (ah->device.active_out) { + /* check the active out devices */ + for (i = 0; i < outDeviceTypes[i].type; i++) { + if (ah->device.active_out & outDeviceTypes[i].type) { + active_devices[dev_idx++] = outDeviceTypes[i].name; + AUDIO_LOG_INFO("added for out : %s", outDeviceTypes[i].name); + } + } + } } - /* TO DO: Set Inactive */ + if (active_devices[0] == NULL) { + AUDIO_LOG_DEBUG("active device is NULL, no need to update."); + return AUDIO_RET_OK; + } + + audio_ret = _audio_ucm_set_devices(ah, mode_to_verb_str[ah->device.mode], active_devices); + if (audio_ret) + AUDIO_LOG_ERROR("Failed to set device: error = %d", audio_ret); + return audio_ret; } +#define LOOPBACK_ARG_LATENCY_MSEC 40 +#define LOOPBACK_ARG_ADJUST_TIME_SEC 3 audio_return_t audio_do_route(void *audio_handle, audio_route_info_t *info) { audio_return_t audio_ret = AUDIO_RET_OK; @@ -267,6 +303,8 @@ audio_return_t audio_do_route(void *audio_handle, audio_route_info_t *info) AUDIO_LOG_INFO("role:%s", info->role); + devices = info->device_infos; + if (!strncmp("voip", info->role, MAX_NAME_LEN)) { audio_ret = _do_route_voip(ah, devices, info->num_of_devices); if (AUDIO_IS_ERROR(audio_ret)) { @@ -278,9 +316,13 @@ audio_return_t audio_do_route(void *audio_handle, audio_route_info_t *info) AUDIO_LOG_WARN("set reset return 0x%x", audio_ret); } } else { + /* send latency and adjust time for loopback */ + if (!strncmp("loopback", info->role, MAX_NAME_LEN)) { + _audio_comm_send_message(ah, "loopback::latency", LOOPBACK_ARG_LATENCY_MSEC); + _audio_comm_send_message(ah, "loopback::adjust_time", LOOPBACK_ARG_ADJUST_TIME_SEC); + } /* need to prepare for "alarm","notification","emergency","voice-information","voice-recognition","ringtone" */ audio_ret = _do_route_ap_playback_capture(ah, info); - if (AUDIO_IS_ERROR(audio_ret)) { AUDIO_LOG_WARN("set playback route return 0x%x", audio_ret); } diff --git a/tizen-audio-internal.h b/tizen-audio-internal.h index cf4b1e8..f7b28cb 100644 --- a/tizen-audio-internal.h +++ b/tizen-audio-internal.h @@ -76,16 +76,18 @@ } while (0) /* Devices : Normal */ +#define AUDIO_DEVICE_OUT 0x00000000 +#define AUDIO_DEVICE_IN 0x80000000 enum audio_device_type { AUDIO_DEVICE_NONE = 0, /* output devices */ - AUDIO_DEVICE_OUT_SPEAKER = 0x00000001, - AUDIO_DEVICE_OUT_RECEIVER = 0x00000002, - AUDIO_DEVICE_OUT_JACK = 0x00000004, - AUDIO_DEVICE_OUT_BT_SCO = 0x00000008, - AUDIO_DEVICE_OUT_AUX = 0x00000010, - AUDIO_DEVICE_OUT_HDMI = 0x00000020, + AUDIO_DEVICE_OUT_SPEAKER = AUDIO_DEVICE_OUT | 0x00000001, + AUDIO_DEVICE_OUT_RECEIVER = AUDIO_DEVICE_OUT | 0x00000002, + AUDIO_DEVICE_OUT_JACK = AUDIO_DEVICE_OUT | 0x00000004, + AUDIO_DEVICE_OUT_BT_SCO = AUDIO_DEVICE_OUT | 0x00000008, + AUDIO_DEVICE_OUT_AUX = AUDIO_DEVICE_OUT | 0x00000010, + AUDIO_DEVICE_OUT_HDMI = AUDIO_DEVICE_OUT | 0x00000020, AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_RECEIVER | AUDIO_DEVICE_OUT_JACK | @@ -93,10 +95,10 @@ enum audio_device_type { AUDIO_DEVICE_OUT_AUX | AUDIO_DEVICE_OUT_HDMI), /* input devices */ - AUDIO_DEVICE_IN_MAIN_MIC = 0x80000001, - AUDIO_DEVICE_IN_SUB_MIC = 0x80000002, - AUDIO_DEVICE_IN_JACK = 0x80000004, - AUDIO_DEVICE_IN_BT_SCO = 0x80000008, + AUDIO_DEVICE_IN_MAIN_MIC = AUDIO_DEVICE_IN | 0x00000001, + AUDIO_DEVICE_IN_SUB_MIC = AUDIO_DEVICE_IN | 0x00000002, + AUDIO_DEVICE_IN_JACK = AUDIO_DEVICE_IN | 0x00000004, + AUDIO_DEVICE_IN_BT_SCO = AUDIO_DEVICE_IN | 0x00000008, AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_MAIN_MIC | AUDIO_DEVICE_IN_SUB_MIC | AUDIO_DEVICE_IN_JACK | @@ -178,12 +180,6 @@ typedef struct audio_device_info { typedef enum audio_route_mode { VERB_NORMAL, - -/* Add verb mode if you need */ - -/* VERB_CALL, */ -/* VERB_VOIP */ - } audio_route_mode_t; typedef struct audio_hal_device { @@ -196,7 +192,6 @@ typedef struct audio_hal_device { audio_route_mode_t mode; } audio_hal_device_t; - /* Stream */ #define AUDIO_VOLUME_LEVEL_MAX 16 @@ -276,12 +271,18 @@ typedef enum audio_sample_format { AUDIO_SAMPLE_INVALID = -1 } audio_sample_format_t; +typedef struct audio_hal_comm { + message_cb msg_cb; + void *user_data; +} audio_hal_comm_t; + /* Overall */ typedef struct audio_hal { audio_hal_device_t device; audio_hal_volume_t volume; audio_hal_ucm_t ucm; audio_hal_mixer_t mixer; + audio_hal_comm_t comm; } audio_hal_t; typedef struct { @@ -297,11 +298,15 @@ typedef struct samplerate_ctrl { audio_return_t _audio_volume_init(audio_hal_t *ah); audio_return_t _audio_volume_deinit(audio_hal_t *ah); - audio_return_t _audio_device_init(audio_hal_t *ah); -audio_return_t _audio_device_deinit(audio_hal_t * ah); +audio_return_t _audio_device_deinit(audio_hal_t *ah); audio_return_t _audio_ucm_init(audio_hal_t *ah); audio_return_t _audio_ucm_deinit(audio_hal_t *ah); +audio_return_t _audio_util_init(audio_hal_t *ah); +audio_return_t _audio_util_deinit(audio_hal_t *ah); +audio_return_t _audio_comm_init(audio_hal_t *ah); +audio_return_t _audio_comm_deinit(audio_hal_t *ah); + void _audio_ucm_get_device_name(audio_hal_t *ah, const char *use_case, audio_direction_t direction, const char **value); #define _audio_ucm_update_use_case _audio_ucm_set_use_case audio_return_t _audio_ucm_set_use_case(audio_hal_t *ah, const char *verb, const char *devices[], const char *modifiers[]); @@ -310,13 +315,14 @@ audio_return_t _audio_ucm_set_modifiers(audio_hal_t *ah, const char *verb, const int _audio_ucm_fill_device_info_list(audio_hal_t *ah, audio_device_info_t *device_info_list, const char *verb); audio_return_t _audio_ucm_get_verb(audio_hal_t *ah, const char **value); audio_return_t _audio_ucm_reset_use_case(audio_hal_t *ah); -audio_return_t _audio_util_init(audio_hal_t *ah); -audio_return_t _audio_util_deinit(audio_hal_t *ah); audio_return_t _audio_mixer_control_set_param(audio_hal_t *ah, const char* ctl_name, snd_ctl_elem_value_t* value, int size); audio_return_t _audio_mixer_control_set_value(audio_hal_t *ah, const char *ctl_name, int val); audio_return_t _audio_mixer_control_set_value_string(audio_hal_t *ah, const char* ctl_name, const char* value); audio_return_t _audio_mixer_control_get_value(audio_hal_t *ah, const char *ctl_name, int *val); audio_return_t _audio_mixer_control_get_element(audio_hal_t *ah, const char *ctl_name, snd_hctl_elem_t **elem); +audio_return_t _audio_comm_send_message(audio_hal_t *ah, const char *name, int value); +audio_return_t _audio_comm_set_message_callback(audio_hal_t *ah, message_cb callback, void *user_data); +audio_return_t _audio_comm_unset_message_callback(audio_hal_t *ah); audio_return_t _audio_pcm_set_sw_params(snd_pcm_t *pcm, snd_pcm_uframes_t avail_min, uint8_t period_event); audio_return_t _audio_pcm_set_hw_params(snd_pcm_t *pcm, audio_pcm_sample_spec_t *sample_spec, uint8_t *use_mmap, snd_pcm_uframes_t *period_size, snd_pcm_uframes_t *buffer_size); uint32_t _convert_format(audio_sample_format_t format); diff --git a/tizen-audio.c b/tizen-audio.c index 882a9b4..d8f7a70 100644 --- a/tizen-audio.c +++ b/tizen-audio.c @@ -29,6 +29,18 @@ static const char* AUDIO_LATENCY_MID = "mid"; static const char* AUDIO_LATENCY_HIGH = "high"; static const char* AUDIO_LATENCY_VOIP = "voip"; +audio_return_t audio_set_message_cb(void *audio_handle, message_cb callback, void *user_data) +{ + audio_return_t ret = AUDIO_RET_OK; + + AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(callback, AUDIO_ERR_PARAMETER); + + ret = _audio_comm_set_message_callback((audio_hal_t *)audio_handle, callback, user_data); + + return ret; +} + audio_return_t audio_init(void **audio_handle) { audio_hal_t *ah; @@ -56,6 +68,10 @@ audio_return_t audio_init(void **audio_handle) AUDIO_LOG_ERROR("mixer init failed"); goto error_exit; } + if (AUDIO_IS_ERROR((ret = _audio_comm_init(ah)))) { + AUDIO_LOG_ERROR("comm init failed"); + goto error_exit; + } *audio_handle = (void *)ah; return AUDIO_RET_OK; @@ -77,6 +93,7 @@ audio_return_t audio_deinit(void *audio_handle) _audio_volume_deinit(ah); _audio_ucm_deinit(ah); _audio_util_deinit(ah); + _audio_comm_deinit(ah); free(ah); ah = NULL; diff --git a/tizen-audio.h b/tizen-audio.h index 8dd3b44..794cdd7 100644 --- a/tizen-audio.h +++ b/tizen-audio.h @@ -30,7 +30,10 @@ typedef enum audio_return { AUDIO_ERR_RESOURCE = (int32_t)0x80001001, AUDIO_ERR_PARAMETER = (int32_t)0x80001002, AUDIO_ERR_IOCTL = (int32_t)0x80001003, - AUDIO_ERR_NOT_IMPLEMENTED = (int32_t)0x80001004, + AUDIO_ERR_INVALID_STATE = (int32_t)0x80001004, + AUDIO_ERR_INTERNAL = (int32_t)0x80001005, + + AUDIO_ERR_NOT_IMPLEMENTED = (int32_t)0x80001100, } audio_return_t ; typedef enum audio_direction { @@ -68,19 +71,24 @@ typedef struct audio_stream_info { uint32_t idx; } audio_stream_info_t ; +typedef void (*message_cb)(const char *name, int value, void *user_data); + /* Overall */ typedef struct audio_interface { audio_return_t (*init)(void **audio_handle); audio_return_t (*deinit)(void *audio_handle); + /* Volume */ audio_return_t (*get_volume_level_max)(void *audio_handle, audio_volume_info_t *info, uint32_t *level); audio_return_t (*get_volume_level)(void *audio_handle, audio_volume_info_t *info, uint32_t *level); audio_return_t (*set_volume_level)(void *audio_handle, audio_volume_info_t *info, uint32_t level); audio_return_t (*get_volume_value)(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value); audio_return_t (*get_volume_mute)(void *audio_handle, audio_volume_info_t *info, uint32_t *mute); audio_return_t (*set_volume_mute)(void *audio_handle, audio_volume_info_t *info, uint32_t mute); + /* Routing */ audio_return_t (*do_route)(void *audio_handle, audio_route_info_t *info); audio_return_t (*update_route_option)(void *audio_handle, audio_route_option_t *option); audio_return_t (*update_stream_connection_info) (void *audio_handle, audio_stream_info_t *info, uint32_t is_connected); + /* Buffer Attribute */ audio_return_t (*get_buffer_attr)(void *audio_handle, uint32_t direction, const char *latency, uint32_t samplerate, int format, uint32_t channels, uint32_t *maxlength, uint32_t *tlength, uint32_t *prebuf, uint32_t* minreq, uint32_t *fragsize); /* Interface of PCM device */ @@ -95,6 +103,8 @@ typedef struct audio_interface { audio_return_t (*pcm_recover)(void *audio_handle, void *pcm_handle, int revents); audio_return_t (*pcm_get_params)(void *audio_handle, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods); audio_return_t (*pcm_set_params)(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); + /* Message callback */ + audio_return_t (*set_message_cb)(void *audio_handle, message_cb callback, void *user_data); } audio_interface_t; audio_return_t audio_init(void **audio_handle); @@ -121,4 +131,5 @@ audio_return_t audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd); audio_return_t audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents); audio_return_t audio_pcm_get_params(void *audio_handle, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods); audio_return_t audio_pcm_set_params(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); +audio_return_t audio_set_message_cb(void *audio_handle, message_cb callback, void *user_data); #endif |