summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSangchul Lee <sc11.lee@samsung.com>2015-11-23 15:25:26 +0900
committerSangchul Lee <sc11.lee@samsung.com>2015-11-24 14:34:54 +0900
commitaf9737e49951c0f79cd96cb98936cec71f873310 (patch)
tree2cb36d399a08b93216bc4c46ec7eddad93ddd8ea
parentc66827ae38765e1eb5ac3fad1c06793e04e96ebc (diff)
downloadaudio-hal-max98090-af9737e49951c0f79cd96cb98936cec71f873310.tar.gz
audio-hal-max98090-af9737e49951c0f79cd96cb98936cec71f873310.tar.bz2
audio-hal-max98090-af9737e49951c0f79cd96cb98936cec71f873310.zip
Revise codes - add null checking codes, change variable names, remove unused codes, remove build warningssubmit/submit/tizen/20151124.083219/20151124.083307
[Version] 0.2.12 [Profile] Mobile [Issue Type] Code enhancement Change-Id: I265d6a59267febb2c338a186ffbd4dee2747edc9 Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
-rw-r--r--packaging/audio-hal-max98090.spec2
-rw-r--r--tizen-audio-device.c188
-rw-r--r--tizen-audio-internal.h152
-rw-r--r--tizen-audio-ucm.c142
-rw-r--r--tizen-audio-util.c64
-rw-r--r--tizen-audio-volume.c94
-rw-r--r--tizen-audio.c86
-rw-r--r--tizen-audio.h204
8 files changed, 482 insertions, 450 deletions
diff --git a/packaging/audio-hal-max98090.spec b/packaging/audio-hal-max98090.spec
index f87caae..1d52f14 100644
--- a/packaging/audio-hal-max98090.spec
+++ b/packaging/audio-hal-max98090.spec
@@ -1,6 +1,6 @@
Name: audio-hal-max98090
Summary: TIZEN Audio HAL for MAX98090
-Version: 0.2.11
+Version: 0.2.12
Release: 0
Group: System/Libraries
License: Apache-2.0
diff --git a/tizen-audio-device.c b/tizen-audio-device.c
index 3756295..8a522d7 100644
--- a/tizen-audio-device.c
+++ b/tizen-audio-device.c
@@ -75,29 +75,32 @@ static uint32_t convert_device_string_to_enum(const char* device_str, uint32_t d
return device;
}
-static audio_return_t set_devices(audio_mgr_t *am, const char *verb, device_info_t *devices, uint32_t num_of_devices)
+static audio_return_t set_devices(audio_hal_t *ah, const char *verb, device_info_t *devices, uint32_t num_of_devices)
{
audio_return_t audio_ret = AUDIO_RET_OK;
uint32_t new_device = 0;
const char *active_devices[MAX_DEVICES] = {NULL,};
int i = 0, j = 0, dev_idx = 0;
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);
+
if (num_of_devices > MAX_DEVICES) {
num_of_devices = MAX_DEVICES;
AUDIO_LOG_ERROR("error: num_of_devices");
return AUDIO_ERR_PARAMETER;
}
- if ((devices[0].direction == AUDIO_DIRECTION_OUT) && am->device.active_in) {
+ 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 (((am->device.active_in & (~0x80000000)) & inDeviceTypes[j].type))
+ if (((ah->device.active_in & (~0x80000000)) & inDeviceTypes[j].type))
active_devices[dev_idx++] = inDeviceTypes[j].name;
}
- } else if ((devices[0].direction == AUDIO_DIRECTION_IN) && am->device.active_out) {
+ } 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 (am->device.active_out & outDeviceTypes[j].type)
+ if (ah->device.active_out & outDeviceTypes[j].type)
active_devices[dev_idx++] = outDeviceTypes[j].name;
}
}
@@ -108,14 +111,14 @@ static audio_return_t set_devices(audio_mgr_t *am, const char *verb, device_info
for (j = 0; j < inDeviceTypes[j].type; j++) {
if (new_device == inDeviceTypes[j].type) {
active_devices[dev_idx++] = inDeviceTypes[j].name;
- am->device.active_in |= new_device;
+ ah->device.active_in |= new_device;
}
}
} else {
for (j = 0; j < outDeviceTypes[j].type; j++) {
if (new_device == outDeviceTypes[j].type) {
active_devices[dev_idx++] = outDeviceTypes[j].name;
- am->device.active_out |= new_device;
+ ah->device.active_out |= new_device;
}
}
}
@@ -126,7 +129,7 @@ static audio_return_t set_devices(audio_mgr_t *am, const char *verb, device_info
return AUDIO_ERR_PARAMETER;
}
- audio_ret = _audio_ucm_set_devices(am, verb, active_devices);
+ audio_ret = _audio_ucm_set_devices(ah, verb, active_devices);
if (audio_ret) {
AUDIO_LOG_ERROR("Failed to set device: error = %d", audio_ret);
return audio_ret;
@@ -135,86 +138,93 @@ static audio_return_t set_devices(audio_mgr_t *am, const char *verb, device_info
}
-audio_return_t _audio_device_init (audio_mgr_t *am)
+audio_return_t _audio_device_init(audio_hal_t *ah)
{
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
- am->device.active_in = 0x0;
- am->device.active_out = 0x0;
- am->device.pcm_in = NULL;
- am->device.pcm_out = NULL;
- am->device.mode = VERB_NORMAL;
- pthread_mutex_init(&am->device.pcm_lock, NULL);
- am->device.pcm_count = 0;
+ ah->device.active_in = 0x0;
+ ah->device.active_out = 0x0;
+ ah->device.pcm_in = NULL;
+ ah->device.pcm_out = NULL;
+ ah->device.mode = VERB_NORMAL;
+ pthread_mutex_init(&ah->device.pcm_lock, NULL);
+ ah->device.pcm_count = 0;
return AUDIO_RET_OK;
}
-audio_return_t _audio_device_deinit (audio_mgr_t *am)
+audio_return_t _audio_device_deinit(audio_hal_t *ah)
{
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
return AUDIO_RET_OK;
}
-static audio_return_t _do_route_ap_playback_capture (audio_mgr_t *am, audio_route_info_t *route_info)
+static audio_return_t _do_route_ap_playback_capture(audio_hal_t *ah, audio_route_info_t *route_info)
{
audio_return_t audio_ret = AUDIO_RET_OK;
- device_info_t *devices = route_info->device_infos;
+ device_info_t *devices = NULL;
const char *verb = NULL;
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(route_info, AUDIO_ERR_PARAMETER);
+
+ devices = route_info->device_infos;
+
/* To Do: Set modifiers */
/* 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_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
- audio_ret = set_devices(am, verb, devices, route_info->num_of_devices);
+ audio_ret = set_devices(ah, verb, devices, route_info->num_of_devices);
if (audio_ret) {
AUDIO_LOG_ERROR("Failed to set devices: error = 0x%x", audio_ret);
return audio_ret;
}
- am->device.mode = VERB_NORMAL;
+ ah->device.mode = VERB_NORMAL;
/* To Do: Set modifiers */
/*
if (!strncmp("voice_recognition", route_info->role, MAX_NAME_LEN)) {
modifiers[mod_idx++] = AUDIO_USE_CASE_MODIFIER_VOICESEARCH;
} else if ((!strncmp("alarm", route_info->role, MAX_NAME_LEN))||(!strncmp("notifiication", route_info->role, MAX_NAME_LEN))) {
- if (am->device.active_out &= AUDIO_DEVICE_OUT_JACK)
+ if (ah->device.active_out &= AUDIO_DEVICE_OUT_JACK)
modifiers[mod_idx++] = AUDIO_USE_CASE_MODIFIER_DUAL_MEDIA;
else
modifiers[mod_idx++] = AUDIO_USE_CASE_MODIFIER_MEDIA;
} else {
- if (am->device.active_in)
+ if (ah->device.active_in)
modifiers[mod_idx++] = AUDIO_USE_CASE_MODIFIER_CAMCORDING;
else
modifiers[mod_idx++] = AUDIO_USE_CASE_MODIFIER_MEDIA;
}
- audio_ret = _audio_ucm_set_modifiers (am, verb, modifiers);
+ audio_ret = _audio_ucm_set_modifiers (ah, verb, modifiers);
*/
return audio_ret;
}
-audio_return_t _do_route_voip (audio_mgr_t *am, device_info_t *devices, int32_t num_of_devices)
+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;
const char *active_devices[MAX_DEVICES] = {NULL,};
verb = AUDIO_USE_CASE_VERB_HIFI;
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);
+
AUDIO_LOG_INFO("do_route_voip++");
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
- audio_ret = set_devices(am, verb, devices, num_of_devices);
+
+ audio_ret = set_devices(ah, verb, devices, num_of_devices);
if (audio_ret) {
AUDIO_LOG_ERROR("Failed to set devices: error = 0x%x", audio_ret);
return audio_ret;
}
/* FIXME. If necessary, set VERB_VOIP */
- am->device.mode = VERB_NORMAL;
+ ah->device.mode = VERB_NORMAL;
if (active_devices == NULL) {
AUDIO_LOG_ERROR("Failed to set device: active device is NULL");
return AUDIO_ERR_PARAMETER;
@@ -224,7 +234,7 @@ audio_return_t _do_route_voip (audio_mgr_t *am, device_info_t *devices, int32_t
return audio_ret;
}
-audio_return_t _do_route_reset (audio_mgr_t *am, uint32_t direction)
+audio_return_t _do_route_reset(audio_hal_t *ah, uint32_t direction)
{
audio_return_t audio_ret = AUDIO_RET_OK;
@@ -232,42 +242,44 @@ audio_return_t _do_route_reset (audio_mgr_t *am, uint32_t direction)
/* const char *verb = NULL; */
/* verb = AUDIO_USE_CASE_VERB_INACTIVE; */
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+
AUDIO_LOG_INFO("do_route_reset++, direction(%p)", direction);
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
if (direction == AUDIO_DIRECTION_OUT) {
- am->device.active_out &= 0x0;
+ ah->device.active_out &= 0x0;
} else {
- am->device.active_in &= 0x0;
+ ah->device.active_in &= 0x0;
}
/* TO DO: Set Inactive */
return audio_ret;
}
-audio_return_t audio_do_route (void *userdata, audio_route_info_t *info)
+audio_return_t audio_do_route(void *audio_handle, audio_route_info_t *info)
{
audio_return_t audio_ret = AUDIO_RET_OK;
- audio_mgr_t *am = (audio_mgr_t *)userdata;
- device_info_t *devices = info->device_infos;
+ audio_hal_t *ah = (audio_hal_t *)audio_handle;
+ device_info_t *devices = NULL;
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(info, AUDIO_ERR_PARAMETER);
AUDIO_LOG_INFO("role:%s", info->role);
if (!strncmp("voip", info->role, MAX_NAME_LEN)) {
- audio_ret = _do_route_voip(am, devices, info->num_of_devices);
+ audio_ret = _do_route_voip(ah, devices, info->num_of_devices);
if (AUDIO_IS_ERROR(audio_ret)) {
AUDIO_LOG_WARN("set voip route return 0x%x", audio_ret);
}
} else if (!strncmp("reset", info->role, MAX_NAME_LEN)) {
- audio_ret = _do_route_reset(am, devices->direction);
+ audio_ret = _do_route_reset(ah, devices->direction);
if (AUDIO_IS_ERROR(audio_ret)) {
AUDIO_LOG_WARN("set reset return 0x%x", audio_ret);
}
} else {
/* need to prepare for "alarm","notification","emergency","voice-information","voice-recognition","ringtone" */
- audio_ret = _do_route_ap_playback_capture(am, info);
+ 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);
@@ -276,24 +288,26 @@ audio_return_t audio_do_route (void *userdata, audio_route_info_t *info)
return audio_ret;
}
-audio_return_t audio_update_stream_connection_info (void *userdata, audio_stream_info_t *info, uint32_t is_connected)
+audio_return_t audio_update_stream_connection_info(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected)
{
audio_return_t audio_ret = AUDIO_RET_OK;
- audio_mgr_t *am = (audio_mgr_t *)userdata;
+ audio_hal_t *ah = (audio_hal_t *)audio_handle;
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(info, AUDIO_ERR_PARAMETER);
AUDIO_LOG_INFO("role:%s, direction:%u, idx:%u, is_connected:%d", info->role, info->direction, info->idx, is_connected);
return audio_ret;
}
-audio_return_t audio_update_route_option (void *userdata, audio_route_option_t *option)
+audio_return_t audio_update_route_option(void *audio_handle, audio_route_option_t *option)
{
audio_return_t audio_ret = AUDIO_RET_OK;
- audio_mgr_t *am = (audio_mgr_t *)userdata;
+ audio_hal_t *ah = (audio_hal_t *)audio_handle;
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(option, AUDIO_ERR_PARAMETER);
AUDIO_LOG_INFO("role:%s, name:%s, value:%d", option->role, option->name, option->value);
@@ -301,11 +315,13 @@ audio_return_t audio_update_route_option (void *userdata, audio_route_option_t *
}
#ifdef __USE_TINYALSA__
-static struct pcm *__tinyalsa_open_device (audio_pcm_sample_spec_t *ss, size_t period_size, size_t period_count, uint32_t direction)
+static struct pcm *__tinyalsa_open_device(audio_pcm_sample_spec_t *ss, size_t period_size, size_t period_count, uint32_t direction)
{
struct pcm *pcm = NULL;
struct pcm_config config;
+ AUDIO_RETURN_NULL_IF_FAIL(ss);
+
config.channels = ss->channels;
config.rate = ss->rate;
config.period_size = period_size;
@@ -331,19 +347,20 @@ static struct pcm *__tinyalsa_open_device (audio_pcm_sample_spec_t *ss, size_t p
}
#endif
-audio_return_t audio_pcm_open (void *userdata, void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods)
+audio_return_t audio_pcm_open(void *audio_handle, void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods)
{
#ifdef __USE_TINYALSA__
- audio_mgr_t *am;
+ audio_hal_t *ah;
audio_pcm_sample_spec_t *ss;
int err;
- AUDIO_RETURN_VAL_IF_FAIL(userdata, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL((period_size > 0), AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL((periods > 0), AUDIO_ERR_PARAMETER);
- am = (audio_mgr_t *)userdata;
+ ah = (audio_hal_t *)audio_handle;
ss = (audio_pcm_sample_spec_t *)sample_spec;
ss->format = _convert_format((audio_sample_format_t)ss->format);
@@ -357,23 +374,21 @@ audio_return_t audio_pcm_open (void *userdata, void **pcm_handle, uint32_t direc
AUDIO_LOG_ERROR("Error prepare PCM device : %d", err);
}
- am->device.pcm_count++;
+ ah->device.pcm_count++;
AUDIO_LOG_INFO("Opening PCM handle 0x%x", *pcm_handle);
#else /* alsa-lib */
- audio_mgr_t *am;
+ audio_hal_t *ah;
int err, mode;
char *device_name = NULL;
- uint8_t use_mmap = 0;
- snd_pcm_uframes_t buffer_size;
- AUDIO_RETURN_VAL_IF_FAIL(userdata, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL((period_size > 0), AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL((periods > 0), AUDIO_ERR_PARAMETER);
- am = (audio_mgr_t *)userdata;
+ ah = (audio_hal_t *)audio_handle;
mode = SND_PCM_NONBLOCK | SND_PCM_NO_AUTO_RESAMPLE | SND_PCM_NO_AUTO_CHANNELS | SND_PCM_NO_AUTO_FORMAT;
- buffer_size = (snd_pcm_uframes_t)(period_size * periods);
if(direction == AUDIO_DIRECTION_OUT)
device_name = PLAYBACK_PCM_DEVICE;
@@ -389,22 +404,25 @@ audio_return_t audio_pcm_open (void *userdata, void **pcm_handle, uint32_t direc
return AUDIO_ERR_RESOURCE;
}
- if ((err = audio_pcm_set_params(userdata, *pcm_handle, direction, sample_spec, period_size, periods)) != AUDIO_RET_OK) {
+ if ((err = audio_pcm_set_params(audio_handle, *pcm_handle, direction, sample_spec, period_size, periods)) != AUDIO_RET_OK) {
AUDIO_LOG_ERROR("Failed to set pcm parameters : %d", err);
return err;
}
- am->device.pcm_count++;
+ ah->device.pcm_count++;
AUDIO_LOG_INFO("Opening PCM handle 0x%x, PCM device %s", *pcm_handle, device_name);
#endif
return AUDIO_RET_OK;
}
-audio_return_t audio_pcm_start (void *userdata, void *pcm_handle)
+audio_return_t audio_pcm_start(void *audio_handle, void *pcm_handle)
{
int err;
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
+
#ifdef __USE_TINYALSA__
if ((err = pcm_start(pcm_handle)) < 0) {
AUDIO_LOG_ERROR("Error starting PCM handle : %d", err);
@@ -421,10 +439,13 @@ audio_return_t audio_pcm_start (void *userdata, void *pcm_handle)
return AUDIO_RET_OK;
}
-audio_return_t audio_pcm_stop (void *userdata, void *pcm_handle)
+audio_return_t audio_pcm_stop(void *audio_handle, void *pcm_handle)
{
int err;
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
+
#ifdef __USE_TINYALSA__
if ((err = pcm_stop(pcm_handle)) < 0) {
AUDIO_LOG_ERROR("Error stopping PCM handle : %d", err);
@@ -441,11 +462,14 @@ audio_return_t audio_pcm_stop (void *userdata, void *pcm_handle)
return AUDIO_RET_OK;
}
-audio_return_t audio_pcm_close (void *userdata, void *pcm_handle)
+audio_return_t audio_pcm_close(void *audio_handle, void *pcm_handle)
{
- audio_mgr_t *am = (audio_mgr_t *)userdata;
+ audio_hal_t *ah = (audio_hal_t *)audio_handle;
int err;
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
+
AUDIO_LOG_INFO("Try to close PCM handle 0x%x", pcm_handle);
#ifdef __USE_TINYALSA__
@@ -461,19 +485,20 @@ audio_return_t audio_pcm_close (void *userdata, void *pcm_handle)
#endif
pcm_handle = NULL;
- am->device.pcm_count--;
- AUDIO_LOG_INFO("PCM handle close success (count:%d)", am->device.pcm_count);
+ ah->device.pcm_count--;
+ AUDIO_LOG_INFO("PCM handle close success (count:%d)", ah->device.pcm_count);
return AUDIO_RET_OK;
}
-audio_return_t audio_pcm_avail (void *userdata, void *pcm_handle, uint32_t *avail)
+audio_return_t audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *avail)
{
#ifdef __USE_TINYALSA__
struct timespec tspec;
unsigned int frames_avail = 0;
int err;
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(avail, AUDIO_ERR_PARAMETER);
@@ -491,6 +516,7 @@ audio_return_t audio_pcm_avail (void *userdata, void *pcm_handle, uint32_t *avai
#else /* alsa-lib */
snd_pcm_sframes_t frames_avail;
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(avail, AUDIO_ERR_PARAMETER);
@@ -509,11 +535,12 @@ audio_return_t audio_pcm_avail (void *userdata, void *pcm_handle, uint32_t *avai
return AUDIO_RET_OK;
}
-audio_return_t audio_pcm_write (void *userdata, void *pcm_handle, const void *buffer, uint32_t frames)
+audio_return_t audio_pcm_write(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames)
{
#ifdef __USE_TINYALSA__
int err;
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
err = pcm_write(pcm_handle, buffer, pcm_frames_to_bytes(pcm_handle, (unsigned int)frames));
@@ -544,11 +571,12 @@ audio_return_t audio_pcm_write (void *userdata, void *pcm_handle, const void *bu
return AUDIO_RET_OK;
}
-audio_return_t audio_pcm_read (void *userdata, void *pcm_handle, void *buffer, uint32_t frames)
+audio_return_t audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames)
{
#ifdef __USE_TINYALSA__
int err;
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
err = pcm_read(pcm_handle, buffer, pcm_frames_to_bytes(pcm_handle, (unsigned int)frames));
@@ -563,6 +591,7 @@ audio_return_t audio_pcm_read (void *userdata, void *pcm_handle, void *buffer, u
#else /* alsa-lib */
snd_pcm_sframes_t frames_read;
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
frames_read = snd_pcm_readi(pcm_handle, buffer, (snd_pcm_uframes_t)frames);
@@ -579,10 +608,12 @@ audio_return_t audio_pcm_read (void *userdata, void *pcm_handle, void *buffer, u
return AUDIO_RET_OK;
}
-audio_return_t audio_pcm_get_fd(void *userdata, void *pcm_handle, int *fd)
+audio_return_t audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd)
{
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(fd, AUDIO_ERR_PARAMETER);
+ /* we use an internal API of the (tiny)alsa library, so it causes warning message during compile */
#ifdef __USE_TINYALSA__
*fd = _pcm_poll_descriptor((struct pcm *)pcm_handle);
#else /* alsa-lib */
@@ -616,10 +647,11 @@ static int __tinyalsa_pcm_recover(struct pcm *pcm, int err)
}
#endif
-audio_return_t audio_pcm_recover(void *userdata, void *pcm_handle, int revents)
+audio_return_t audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents)
{
int state, err;
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
if (revents & POLLERR)
@@ -696,7 +728,7 @@ audio_return_t audio_pcm_recover(void *userdata, void *pcm_handle, int revents)
return AUDIO_RET_OK;
}
-audio_return_t audio_pcm_get_params(void *userdata, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods)
+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)
{
#ifdef __USE_TINYALSA__
audio_pcm_sample_spec_t *ss;
@@ -704,12 +736,14 @@ audio_return_t audio_pcm_get_params(void *userdata, void *pcm_handle, uint32_t d
unsigned int _start_threshold, _stop_threshold, _silence_threshold;
struct pcm_config *config;
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(period_size, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(periods, AUDIO_ERR_PARAMETER);
ss = (audio_pcm_sample_spec_t *)*sample_spec;
+ /* we use an internal API of the tiny alsa library, so it causes warning message during compile */
_pcm_config(pcm_handle, &config);
*period_size = config->period_size;
@@ -735,6 +769,7 @@ audio_return_t audio_pcm_get_params(void *userdata, void *pcm_handle, uint32_t d
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(period_size, AUDIO_ERR_PARAMETER);
@@ -783,7 +818,7 @@ audio_return_t audio_pcm_get_params(void *userdata, void *pcm_handle, uint32_t d
return AUDIO_RET_OK;
}
-audio_return_t audio_pcm_set_params(void *userdata, 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)
{
#ifdef __USE_TINYALSA__
/* Parameters are only acceptable in pcm_open() function */
@@ -795,6 +830,7 @@ audio_return_t audio_pcm_set_params(void *userdata, void *pcm_handle, uint32_t d
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(period_size, AUDIO_ERR_PARAMETER);
@@ -826,7 +862,7 @@ audio_return_t audio_pcm_set_params(void *userdata, void *pcm_handle, uint32_t d
return AUDIO_ERR_PARAMETER;
}
- if ((err = snd_pcm_hw_params_set_rate(pcm_handle, hwparams, ss.rate, NULL)) < 0) {
+ if ((err = snd_pcm_hw_params_set_rate(pcm_handle, hwparams, ss.rate, 0)) < 0) {
AUDIO_LOG_ERROR("snd_pcm_hw_params_set_rate() failed : %d", err);
return AUDIO_ERR_PARAMETER;
}
diff --git a/tizen-audio-internal.h b/tizen-audio-internal.h
index c129e80..d389e2d 100644
--- a/tizen-audio-internal.h
+++ b/tizen-audio-internal.h
@@ -68,6 +68,12 @@
return val; \
} \
} while (0)
+#define AUDIO_RETURN_NULL_IF_FAIL(expr) do { \
+ if (!expr) { \
+ AUDIO_LOG_ERROR("%s failed", #expr); \
+ return NULL; \
+ } \
+} while (0)
/* Devices : Normal */
enum audio_device_type {
@@ -142,7 +148,35 @@ typedef struct {
} audio_pcm_sample_spec_t;
/* Device */
-typedef enum audio_route_mode{
+typedef enum audio_device_api {
+ AUDIO_DEVICE_API_UNKNOWN,
+ AUDIO_DEVICE_API_ALSA,
+ AUDIO_DEVICE_API_BLUEZ,
+} audio_device_api_t;
+
+typedef struct audio_device_alsa_info {
+ char *card_name;
+ uint32_t card_idx;
+ uint32_t device_idx;
+} audio_device_alsa_info_t;
+
+typedef struct audio_device_bluz_info {
+ char *protocol;
+ uint32_t nrec;
+} audio_device_bluez_info_t;
+
+typedef struct audio_device_info {
+ audio_device_api_t api;
+ audio_direction_t direction;
+ char *name;
+ uint8_t is_default_device;
+ union {
+ audio_device_alsa_info_t alsa;
+ audio_device_bluez_info_t bluez;
+ };
+} audio_device_info_t;
+
+typedef enum audio_route_mode {
VERB_NORMAL,
/* Add verb mode if you need */
@@ -152,7 +186,7 @@ typedef enum audio_route_mode{
} audio_route_mode_t;
-typedef struct audio_device_mgr {
+typedef struct audio_hal_device {
uint32_t active_in;
uint32_t active_out;
snd_pcm_t *pcm_in;
@@ -160,13 +194,39 @@ typedef struct audio_device_mgr {
pthread_mutex_t pcm_lock;
uint32_t pcm_count;
audio_route_mode_t mode;
-} audio_device_mgr_t;
+} audio_hal_device_t;
/* Stream */
-
#define AUDIO_VOLUME_LEVEL_MAX 16
+typedef enum audio_volume {
+ AUDIO_VOLUME_TYPE_SYSTEM, /**< System volume type */
+ AUDIO_VOLUME_TYPE_NOTIFICATION, /**< Notification volume type */
+ AUDIO_VOLUME_TYPE_ALARM, /**< Alarm volume type */
+ AUDIO_VOLUME_TYPE_RINGTONE, /**< Ringtone volume type */
+ AUDIO_VOLUME_TYPE_MEDIA, /**< Media volume type */
+ AUDIO_VOLUME_TYPE_CALL, /**< Call volume type */
+ AUDIO_VOLUME_TYPE_VOIP, /**< VOIP volume type */
+ AUDIO_VOLUME_TYPE_VOICE, /**< Voice volume type */
+ AUDIO_VOLUME_TYPE_MAX, /**< Volume type count */
+} audio_volume_t;
+
+typedef enum audio_gain {
+ AUDIO_GAIN_TYPE_DEFAULT,
+ AUDIO_GAIN_TYPE_DIALER,
+ AUDIO_GAIN_TYPE_TOUCH,
+ AUDIO_GAIN_TYPE_AF,
+ AUDIO_GAIN_TYPE_SHUTTER1,
+ AUDIO_GAIN_TYPE_SHUTTER2,
+ AUDIO_GAIN_TYPE_CAMCODING,
+ AUDIO_GAIN_TYPE_MIDI,
+ AUDIO_GAIN_TYPE_BOOTING,
+ AUDIO_GAIN_TYPE_VIDEO,
+ AUDIO_GAIN_TYPE_TTS,
+ AUDIO_GAIN_TYPE_MAX,
+} audio_gain_t;
+
typedef struct audio_volume_value_table {
double volume[AUDIO_VOLUME_TYPE_MAX][AUDIO_VOLUME_LEVEL_MAX];
uint32_t volume_level_max[AUDIO_VOLUME_LEVEL_MAX];
@@ -178,16 +238,16 @@ enum {
AUDIO_VOLUME_DEVICE_MAX,
};
-typedef struct audio_volume_mgr {
+typedef struct audio_hal_volume {
uint32_t volume_level[AUDIO_VOLUME_TYPE_MAX];
audio_volume_value_table_t *volume_value_table;
-} audio_volume_mgr_t;
+} audio_hal_volume_t;
-typedef struct audio_ucm_mgr {
+typedef struct audio_hal_ucm {
snd_use_case_mgr_t* uc_mgr;
-} audio_ucm_mgr_t;
+} audio_hal_ucm_t;
-typedef struct audio_mixer_mgr {
+typedef struct audio_hal_mixer {
snd_mixer_t *mixer;
pthread_mutex_t mutex;
struct {
@@ -195,16 +255,34 @@ typedef struct audio_mixer_mgr {
snd_ctl_elem_id_t *id;
snd_ctl_elem_info_t *info;
} control;
-} audio_mixer_mgr_t;
+} audio_hal_mixer_t;
+
+/* Audio format */
+typedef enum audio_sample_format {
+ AUDIO_SAMPLE_U8,
+ AUDIO_SAMPLE_ALAW,
+ AUDIO_SAMPLE_ULAW,
+ AUDIO_SAMPLE_S16LE,
+ AUDIO_SAMPLE_S16BE,
+ AUDIO_SAMPLE_FLOAT32LE,
+ AUDIO_SAMPLE_FLOAT32BE,
+ AUDIO_SAMPLE_S32LE,
+ AUDIO_SAMPLE_S32BE,
+ AUDIO_SAMPLE_S24LE,
+ AUDIO_SAMPLE_S24BE,
+ AUDIO_SAMPLE_S24_32LE,
+ AUDIO_SAMPLE_S24_32BE,
+ AUDIO_SAMPLE_MAX,
+ AUDIO_SAMPLE_INVALID = -1
+} audio_sample_format_t;
/* Overall */
-
-typedef struct audio_mgr {
- audio_device_mgr_t device;
- audio_volume_mgr_t volume;
- audio_ucm_mgr_t ucm;
- audio_mixer_mgr_t mixer;
-} audio_mgr_t;
+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_t;
typedef struct {
unsigned short is_open; /* if is_open is true, open device; else close device.*/
@@ -217,28 +295,28 @@ typedef struct samplerate_ctrl {
unsigned int samplerate; /* change samplerate.*/
} set_samplerate_t;
-audio_return_t _audio_volume_init (audio_mgr_t *am);
-audio_return_t _audio_volume_deinit (audio_mgr_t *am);
+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_mgr_t *am);
-audio_return_t _audio_device_deinit (audio_mgr_t * am);
-audio_return_t _audio_ucm_init (audio_mgr_t *am);
-audio_return_t _audio_ucm_deinit (audio_mgr_t *am);
-void _audio_ucm_get_device_name (audio_mgr_t *am, const char *use_case, audio_direction_t direction, const char **value);
+audio_return_t _audio_device_init(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);
+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_mgr_t *am, const char *verb, const char *devices[], const char *modifiers[]);
-audio_return_t _audio_ucm_set_devices (audio_mgr_t *am, const char *verb, const char *devices[]);
-audio_return_t _audio_ucm_set_modifiers (audio_mgr_t *am, const char *verb, const char *modifiers[]);
-int _audio_ucm_fill_device_info_list (audio_mgr_t *am, audio_device_info_t *device_info_list, const char *verb);
-audio_return_t _audio_ucm_get_verb (audio_mgr_t *am, const char **value);
-audio_return_t _audio_ucm_reset_use_case (audio_mgr_t *am);
-audio_return_t _audio_util_init (audio_mgr_t *am);
-audio_return_t _audio_util_deinit (audio_mgr_t *am);
-audio_return_t _audio_mixer_control_set_param(audio_mgr_t *am, const char* ctl_name, snd_ctl_elem_value_t* value, int size);
-audio_return_t _audio_mixer_control_set_value(audio_mgr_t *am, const char *ctl_name, int val);
-audio_return_t _audio_mixer_control_set_value_string(audio_mgr_t *am, const char* ctl_name, const char* value);
-audio_return_t _audio_mixer_control_get_value(audio_mgr_t *am, const char *ctl_name, int *val);
-audio_return_t _audio_mixer_control_get_element(audio_mgr_t *am, const char *ctl_name, snd_hctl_elem_t **elem);
+audio_return_t _audio_ucm_set_use_case(audio_hal_t *ah, const char *verb, const char *devices[], const char *modifiers[]);
+audio_return_t _audio_ucm_set_devices(audio_hal_t *ah, const char *verb, const char *devices[]);
+audio_return_t _audio_ucm_set_modifiers(audio_hal_t *ah, const char *verb, const char *modifiers[]);
+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_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-ucm.c b/tizen-audio-ucm.c
index 482e7a0..6f9faaf 100644
--- a/tizen-audio-ucm.c
+++ b/tizen-audio-ucm.c
@@ -37,46 +37,57 @@
#define SND_USE_CASE_SET snd_use_case_set
#endif
-audio_return_t _audio_ucm_init (audio_mgr_t *am)
+audio_return_t _audio_ucm_init(audio_hal_t *ah)
{
- snd_use_case_mgr_open(&am->ucm.uc_mgr, ALSA_DEFAULT_CARD);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
- if (!am->ucm.uc_mgr) {
+ snd_use_case_mgr_open(&ah->ucm.uc_mgr, ALSA_DEFAULT_CARD);
+
+ if (!ah->ucm.uc_mgr) {
AUDIO_LOG_ERROR("uc_mgr open failed");
return AUDIO_ERR_RESOURCE;
}
return AUDIO_RET_OK;
}
-audio_return_t _audio_ucm_deinit (audio_mgr_t *am)
+audio_return_t _audio_ucm_deinit(audio_hal_t *ah)
{
- if (am->ucm.uc_mgr != NULL) {
- snd_use_case_mgr_close(am->ucm.uc_mgr);
- am->ucm.uc_mgr = NULL;
- }
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER);
+
+ snd_use_case_mgr_close(ah->ucm.uc_mgr);
+ ah->ucm.uc_mgr = NULL;
return AUDIO_RET_OK;
}
-void _audio_ucm_get_device_name (audio_mgr_t *am, const char *use_case, audio_direction_t direction, const char **value)
+void _audio_ucm_get_device_name(audio_hal_t *ah, const char *use_case, audio_direction_t direction, const char **value)
{
char identifier[70] = {0};
+ AUDIO_RETURN_IF_FAIL(ah);
+ AUDIO_RETURN_IF_FAIL(ah->ucm.uc_mgr);
+
if (direction == AUDIO_DIRECTION_IN) {
sprintf(identifier, "CapturePCM//%s", use_case);
} else {
sprintf(identifier, "PlaybackPCM//%s", use_case);
}
- snd_use_case_get(am->ucm.uc_mgr, identifier, value);
+ snd_use_case_get(ah->ucm.uc_mgr, identifier, value);
}
-static inline void __add_ucm_device_info (audio_mgr_t *am, const char *use_case, audio_direction_t direction, audio_device_info_t *device_info_list, int *device_info_count)
+static inline void __add_ucm_device_info(audio_hal_t *ah, const char *use_case, audio_direction_t direction, audio_device_info_t *device_info_list, int *device_info_count)
{
audio_device_info_t *device_info;
const char *device_name = NULL;
char *needle = NULL;
- _audio_ucm_get_device_name(am, use_case, direction, &device_name);
+ AUDIO_RETURN_IF_FAIL(ah);
+ AUDIO_RETURN_IF_FAIL(ah->ucm.uc_mgr);
+ AUDIO_RETURN_IF_FAIL(device_info_list);
+ AUDIO_RETURN_IF_FAIL(device_info_count);
+
+ _audio_ucm_get_device_name(ah, use_case, direction, &device_name);
if (device_name) {
device_info = &device_info_list[(*device_info_count)++];
@@ -95,19 +106,23 @@ static inline void __add_ucm_device_info (audio_mgr_t *am, const char *use_case,
}
}
-int _audio_ucm_fill_device_info_list (audio_mgr_t *am, audio_device_info_t *device_info_list, const char *verb)
+int _audio_ucm_fill_device_info_list(audio_hal_t *ah, audio_device_info_t *device_info_list, const char *verb)
{
int device_info_count = 0;
const char *curr_verb = NULL;
+ AUDIO_RETURN_VAL_IF_FAIL(ah, device_info_count);
+ AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, device_info_count);
+ AUDIO_RETURN_VAL_IF_FAIL(device_info_list, device_info_count);
+
if (!verb) {
- snd_use_case_get(am->ucm.uc_mgr, "_verb", &curr_verb);
+ snd_use_case_get(ah->ucm.uc_mgr, "_verb", &curr_verb);
verb = curr_verb;
}
if (verb) {
- __add_ucm_device_info(am, verb, AUDIO_DIRECTION_IN, device_info_list, &device_info_count);
- __add_ucm_device_info(am, verb, AUDIO_DIRECTION_OUT, device_info_list, &device_info_count);
+ __add_ucm_device_info(ah, verb, AUDIO_DIRECTION_IN, device_info_list, &device_info_count);
+ __add_ucm_device_info(ah, verb, AUDIO_DIRECTION_OUT, device_info_list, &device_info_count);
if (curr_verb)
free((void *)curr_verb);
@@ -187,7 +202,7 @@ static inline int __set_use_case_with_time(snd_use_case_mgr_t *uc_mgr, const cha
2) If verb is changed
-> Reset, set new verb, enable devices & modifiers
*/
-audio_return_t _audio_ucm_set_use_case (audio_mgr_t *am, const char *verb, const char *devices[], const char *modifiers[])
+audio_return_t _audio_ucm_set_use_case(audio_hal_t *ah, const char *verb, const char *devices[], const char *modifiers[])
{
audio_return_t audio_ret = AUDIO_RET_OK;
int is_verb_changed = 0, is_dev_changed = 0, is_mod_changed = 0;
@@ -201,12 +216,13 @@ audio_return_t _audio_ucm_set_use_case (audio_mgr_t *am, const char *verb, const
int i = 0, j = 0;
char dump_str[512];
- if (!am->ucm.uc_mgr || !verb)
- return AUDIO_ERR_PARAMETER;
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(verb, AUDIO_ERR_PARAMETER);
- snd_use_case_get(am->ucm.uc_mgr, "_verb", &old_verb);
- old_dev_count = snd_use_case_get_list(am->ucm.uc_mgr, "_enadevs", &old_dev_list);
- old_mod_count = snd_use_case_get_list(am->ucm.uc_mgr, "_enamods", &old_mod_list);
+ snd_use_case_get(ah->ucm.uc_mgr, "_verb", &old_verb);
+ old_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enadevs", &old_dev_list);
+ old_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enamods", &old_mod_list);
__dump_use_case(old_verb, old_dev_list, old_dev_count, old_mod_list, old_mod_count, &dump_str[0]);
AUDIO_LOG_INFO(">>> UCM current %s", dump_str);
@@ -319,28 +335,28 @@ audio_return_t _audio_ucm_set_use_case (audio_mgr_t *am, const char *verb, const
/* disable modifiers */
for (i = 0; i < dis_mod_count; i++) {
AUDIO_LOG_INFO("Disable modifier : %s", dis_mod_list[i]);
- if (snd_use_case_set(am->ucm.uc_mgr, "_dismod", dis_mod_list[i]) < 0)
+ if (snd_use_case_set(ah->ucm.uc_mgr, "_dismod", dis_mod_list[i]) < 0)
AUDIO_LOG_ERROR("disable %s modifier failed", dis_mod_list[i]);
}
/* disable devices */
for (i = 0; i < dis_dev_count; i++) {
AUDIO_LOG_INFO("Disable device : %s", dis_dev_list[i]);
- if (snd_use_case_set(am->ucm.uc_mgr, "_disdev", dis_dev_list[i]) < 0)
+ if (snd_use_case_set(ah->ucm.uc_mgr, "_disdev", dis_dev_list[i]) < 0)
AUDIO_LOG_ERROR("disable %s device failed", dis_dev_list[i]);
}
/* enable devices */
for (i = 0; i < ena_dev_count; i++) {
AUDIO_LOG_INFO("Enable device : %s", ena_dev_list[i]);
- if (snd_use_case_set(am->ucm.uc_mgr, "_enadev", ena_dev_list[i]) < 0)
+ if (snd_use_case_set(ah->ucm.uc_mgr, "_enadev", ena_dev_list[i]) < 0)
AUDIO_LOG_ERROR("enable %s device failed", ena_dev_list[i]);
}
/* enable modifiers */
for (i = 0; i < ena_mod_count; i++) {
AUDIO_LOG_INFO("Enable modifier : %s", ena_mod_list[i]);
- if (snd_use_case_set(am->ucm.uc_mgr, "_enamod", ena_mod_list[i]) < 0)
+ if (snd_use_case_set(ah->ucm.uc_mgr, "_enamod", ena_mod_list[i]) < 0)
AUDIO_LOG_ERROR("enable %s modifier failed", ena_mod_list[i]);
}
} else {
@@ -348,7 +364,7 @@ audio_return_t _audio_ucm_set_use_case (audio_mgr_t *am, const char *verb, const
AUDIO_LOG_DEBUG("Setting new verb: %s", verb);
/* set new verb */
- if (snd_use_case_set(am->ucm.uc_mgr, "_verb", verb) < 0) {
+ if (snd_use_case_set(ah->ucm.uc_mgr, "_verb", verb) < 0) {
AUDIO_LOG_ERROR("Setting verb %s failed", verb);
audio_ret = AUDIO_ERR_UNDEFINED;
goto exit;
@@ -356,13 +372,13 @@ audio_return_t _audio_ucm_set_use_case (audio_mgr_t *am, const char *verb, const
/* enable devices */
for (i = 0; i < dev_count; i++) {
AUDIO_LOG_DEBUG("Enable device : %s", devices[i]);
- if(snd_use_case_set(am->ucm.uc_mgr, "_enadev", devices[i]) < 0)
+ if(snd_use_case_set(ah->ucm.uc_mgr, "_enadev", devices[i]) < 0)
AUDIO_LOG_ERROR("Enable %s device failed", devices[i]);
}
/* enable modifiers */
for (i = 0; i < mod_count; i++) {
AUDIO_LOG_DEBUG("Enable modifier : %s", modifiers[i]);
- if(snd_use_case_set(am->ucm.uc_mgr, "_enamod", modifiers[i]) < 0)
+ if(snd_use_case_set(ah->ucm.uc_mgr, "_enamod", modifiers[i]) < 0)
AUDIO_LOG_ERROR("Enable %s modifier failed", modifiers[i]);
}
}
@@ -387,9 +403,9 @@ exit:
const char *new_verb = NULL, **new_dev_list = NULL, **new_mod_list = NULL;
int new_dev_count = 0, new_mod_count = 0;
- snd_use_case_get(am->ucm.uc_mgr, "_verb", &new_verb);
- new_dev_count = snd_use_case_get_list(am->ucm.uc_mgr, "_enadevs", &new_dev_list);
- new_mod_count = snd_use_case_get_list(am->ucm.uc_mgr, "_enamods", &new_mod_list);
+ snd_use_case_get(ah->ucm.uc_mgr, "_verb", &new_verb);
+ new_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enadevs", &new_dev_list);
+ new_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enamods", &new_mod_list);
__dump_use_case(new_verb, new_dev_list, new_dev_count, new_mod_list, new_mod_count, &dump_str[0]);
AUDIO_LOG_INFO("<<< UCM changed %s", dump_str);
@@ -404,7 +420,7 @@ exit:
return audio_ret;
}
-audio_return_t _audio_ucm_set_devices (audio_mgr_t *am, const char *verb, const char *devices[])
+audio_return_t _audio_ucm_set_devices(audio_hal_t *ah, const char *verb, const char *devices[])
{
audio_return_t audio_ret = AUDIO_RET_OK;
int is_verb_changed = 0, is_dev_changed = 0;
@@ -415,11 +431,13 @@ audio_return_t _audio_ucm_set_devices (audio_mgr_t *am, const char *verb, const
int i = 0, j = 0;
char dump_str[512];
- if (!am->ucm.uc_mgr || !verb)
- return AUDIO_ERR_PARAMETER;
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(verb, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);
- snd_use_case_get(am->ucm.uc_mgr, "_verb", &old_verb);
- old_dev_count = snd_use_case_get_list(am->ucm.uc_mgr, "_enadevs", &old_dev_list);
+ snd_use_case_get(ah->ucm.uc_mgr, "_verb", &old_verb);
+ old_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enadevs", &old_dev_list);
__dump_use_case(old_verb, old_dev_list, old_dev_count, NULL, 0, &dump_str[0]);
AUDIO_LOG_INFO(">>> UCM current %s", dump_str);
@@ -483,14 +501,14 @@ audio_return_t _audio_ucm_set_devices (audio_mgr_t *am, const char *verb, const
/* disable devices */
for (i = 0; i < dis_dev_count; i++) {
AUDIO_LOG_INFO("Disable device : %s", dis_dev_list[i]);
- if (snd_use_case_set(am->ucm.uc_mgr, "_disdev", dis_dev_list[i]) < 0)
+ if (snd_use_case_set(ah->ucm.uc_mgr, "_disdev", dis_dev_list[i]) < 0)
AUDIO_LOG_ERROR("disable %s device failed", dis_dev_list[i]);
}
/* enable devices */
for (i = 0; i < ena_dev_count; i++) {
AUDIO_LOG_INFO("Enable device : %s", ena_dev_list[i]);
- if (snd_use_case_set(am->ucm.uc_mgr, "_enadev", ena_dev_list[i]) < 0)
+ if (snd_use_case_set(ah->ucm.uc_mgr, "_enadev", ena_dev_list[i]) < 0)
AUDIO_LOG_ERROR("enable %s device failed", ena_dev_list[i]);
}
@@ -499,7 +517,7 @@ audio_return_t _audio_ucm_set_devices (audio_mgr_t *am, const char *verb, const
AUDIO_LOG_DEBUG("Setting new verb: %s", verb);
/* set new verb */
- if (snd_use_case_set(am->ucm.uc_mgr, "_verb", verb) < 0) {
+ if (snd_use_case_set(ah->ucm.uc_mgr, "_verb", verb) < 0) {
AUDIO_LOG_ERROR("Setting verb %s failed", verb);
audio_ret = AUDIO_ERR_UNDEFINED;
goto exit;
@@ -507,7 +525,7 @@ audio_return_t _audio_ucm_set_devices (audio_mgr_t *am, const char *verb, const
/* enable devices */
for (i = 0; i < dev_count; i++) {
AUDIO_LOG_DEBUG("Enable device : %s", devices[i]);
- if(snd_use_case_set(am->ucm.uc_mgr, "_enadev", devices[i]) < 0)
+ if(snd_use_case_set(ah->ucm.uc_mgr, "_enadev", devices[i]) < 0)
AUDIO_LOG_ERROR("Enable %s device failed", devices[i]);
}
}
@@ -526,8 +544,8 @@ exit:
const char *new_verb = NULL, **new_dev_list = NULL;
int new_dev_count = 0;
- snd_use_case_get(am->ucm.uc_mgr, "_verb", &new_verb);
- new_dev_count = snd_use_case_get_list(am->ucm.uc_mgr, "_enadevs", &new_dev_list);
+ snd_use_case_get(ah->ucm.uc_mgr, "_verb", &new_verb);
+ new_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enadevs", &new_dev_list);
__dump_use_case(new_verb, new_dev_list, new_dev_count, NULL, 0, &dump_str[0]);
AUDIO_LOG_INFO("<<< UCM changed %s", dump_str);
@@ -541,7 +559,7 @@ exit:
}
-audio_return_t _audio_ucm_set_modifiers (audio_mgr_t *am, const char *verb, const char *modifiers[])
+audio_return_t _audio_ucm_set_modifiers(audio_hal_t *ah, const char *verb, const char *modifiers[])
{
audio_return_t audio_ret = AUDIO_RET_OK;
int is_verb_changed = 0, is_mod_changed = 0;
@@ -552,11 +570,13 @@ audio_return_t _audio_ucm_set_modifiers (audio_mgr_t *am, const char *verb, cons
int i = 0, j = 0;
char dump_str[512];
- if (!am->ucm.uc_mgr || !verb)
- return AUDIO_ERR_PARAMETER;
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(verb, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(modifiers, AUDIO_ERR_PARAMETER);
- snd_use_case_get(am->ucm.uc_mgr, "_verb", &old_verb);
- old_mod_count = snd_use_case_get_list(am->ucm.uc_mgr, "_enamods", &old_mod_list);
+ snd_use_case_get(ah->ucm.uc_mgr, "_verb", &old_verb);
+ old_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enamods", &old_mod_list);
__dump_use_case(old_verb, NULL, 0, old_mod_list, old_mod_count, &dump_str[0]);
AUDIO_LOG_INFO(">>> UCM current %s", dump_str);
@@ -620,14 +640,14 @@ audio_return_t _audio_ucm_set_modifiers (audio_mgr_t *am, const char *verb, cons
/* disable modifiers */
for (i = 0; i < dis_mod_count; i++) {
AUDIO_LOG_INFO("Disable modifier : %s", dis_mod_list[i]);
- if (snd_use_case_set(am->ucm.uc_mgr, "_dismod", dis_mod_list[i]) < 0)
+ if (snd_use_case_set(ah->ucm.uc_mgr, "_dismod", dis_mod_list[i]) < 0)
AUDIO_LOG_ERROR("disable %s modifier failed", dis_mod_list[i]);
}
/* enable modifiers */
for (i = 0; i < ena_mod_count; i++) {
AUDIO_LOG_INFO("Enable modifier : %s", ena_mod_list[i]);
- if (snd_use_case_set(am->ucm.uc_mgr, "_enamod", ena_mod_list[i]) < 0)
+ if (snd_use_case_set(ah->ucm.uc_mgr, "_enamod", ena_mod_list[i]) < 0)
AUDIO_LOG_ERROR("enable %s modifier failed", ena_mod_list[i]);
}
} else {
@@ -635,7 +655,7 @@ audio_return_t _audio_ucm_set_modifiers (audio_mgr_t *am, const char *verb, cons
AUDIO_LOG_DEBUG("Setting new verb: %s", verb);
/* set new verb */
- if (snd_use_case_set(am->ucm.uc_mgr, "_verb", verb) < 0) {
+ if (snd_use_case_set(ah->ucm.uc_mgr, "_verb", verb) < 0) {
AUDIO_LOG_ERROR("Setting verb %s failed", verb);
audio_ret = AUDIO_ERR_UNDEFINED;
goto exit;
@@ -643,7 +663,7 @@ audio_return_t _audio_ucm_set_modifiers (audio_mgr_t *am, const char *verb, cons
/* enable modifiers */
for (i = 0; i < mod_count; i++) {
AUDIO_LOG_DEBUG("Enable modifier : %s", modifiers[i]);
- if(snd_use_case_set(am->ucm.uc_mgr, "_enamod", modifiers[i]) < 0)
+ if(snd_use_case_set(ah->ucm.uc_mgr, "_enamod", modifiers[i]) < 0)
AUDIO_LOG_ERROR("Enable %s modifier failed", modifiers[i]);
}
}
@@ -662,8 +682,8 @@ exit:
const char *new_verb = NULL, **new_mod_list = NULL;
int new_mod_count = 0;
- snd_use_case_get(am->ucm.uc_mgr, "_verb", &new_verb);
- new_mod_count = snd_use_case_get_list(am->ucm.uc_mgr, "_enamods", &new_mod_list);
+ snd_use_case_get(ah->ucm.uc_mgr, "_verb", &new_verb);
+ new_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enamods", &new_mod_list);
__dump_use_case(new_verb, NULL, 0, new_mod_list, new_mod_count, &dump_str[0]);
AUDIO_LOG_INFO("<<< UCM changed %s", dump_str);
@@ -676,14 +696,15 @@ exit:
return audio_ret;
}
-audio_return_t _audio_ucm_get_verb (audio_mgr_t *am, const char **value)
+audio_return_t _audio_ucm_get_verb(audio_hal_t *ah, const char **value)
{
audio_return_t ret = AUDIO_RET_OK;
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(value, AUDIO_ERR_PARAMETER);
- if ((ret = snd_use_case_get(am->ucm.uc_mgr, "_verb", value)) < 0) {
+ if ((ret = snd_use_case_get(ah->ucm.uc_mgr, "_verb", value)) < 0) {
AUDIO_LOG_ERROR("Getting current verb failed: Reason %d", ret);
ret = AUDIO_ERR_UNDEFINED;
}
@@ -692,15 +713,16 @@ audio_return_t _audio_ucm_get_verb (audio_mgr_t *am, const char **value)
}
-audio_return_t _audio_ucm_reset_use_case (audio_mgr_t *am)
+audio_return_t _audio_ucm_reset_use_case(audio_hal_t *ah)
{
audio_return_t ret = AUDIO_RET_OK;
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER);
AUDIO_LOG_INFO(">>> UCM reset Verb [ %s ]", AUDIO_USE_CASE_VERB_INACTIVE);
- if ((ret = snd_use_case_set(am->ucm.uc_mgr, "_verb", AUDIO_USE_CASE_VERB_INACTIVE)) < 0) {
+ if ((ret = snd_use_case_set(ah->ucm.uc_mgr, "_verb", AUDIO_USE_CASE_VERB_INACTIVE)) < 0) {
AUDIO_LOG_ERROR("Reset use case failed: Reason %d", ret);
ret = AUDIO_ERR_UNDEFINED;
}
diff --git a/tizen-audio-util.c b/tizen-audio-util.c
index 83785c0..00b09ce 100644
--- a/tizen-audio-util.c
+++ b/tizen-audio-util.c
@@ -28,15 +28,19 @@
#include "tizen-audio-internal.h"
-audio_return_t _audio_util_init (audio_mgr_t *am)
+audio_return_t _audio_util_init(audio_hal_t *ah)
{
- pthread_mutex_init(&(am->mixer.mutex), NULL);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+
+ pthread_mutex_init(&(ah->mixer.mutex), NULL);
return AUDIO_RET_OK;
}
-audio_return_t _audio_util_deinit (audio_mgr_t *am)
+audio_return_t _audio_util_deinit(audio_hal_t *ah)
{
- pthread_mutex_destroy(&(am->mixer.mutex));
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+
+ pthread_mutex_destroy(&(ah->mixer.mutex));
return AUDIO_RET_OK;
}
@@ -61,21 +65,25 @@ static void __dump_mixer_param(char *dump, long *param, int size)
#endif
-audio_return_t _audio_mixer_control_set_param(audio_mgr_t *am, const char* ctl_name, snd_ctl_elem_value_t* param, int size)
+audio_return_t _audio_mixer_control_set_param(audio_hal_t *ah, const char* ctl_name, snd_ctl_elem_value_t* param, int size)
{
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+
/* TODO. */
return AUDIO_RET_OK;
}
-audio_return_t audio_mixer_control_get_value (void *userdata, const char *ctl_name, int *val)
+audio_return_t audio_mixer_control_get_value(audio_hal_t *ah, const char *ctl_name, int *val)
{
audio_return_t audio_ret = AUDIO_RET_OK;
- audio_mgr_t *am = (audio_mgr_t *)userdata;
- audio_ret = _audio_mixer_control_get_value(am, ctl_name, val);
+
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+
+ audio_ret = _audio_mixer_control_get_value(ah, ctl_name, val);
return audio_ret;
}
-audio_return_t _audio_mixer_control_get_value(audio_mgr_t *am, const char *ctl_name, int *val)
+audio_return_t _audio_mixer_control_get_value(audio_hal_t *ah, const char *ctl_name, int *val)
{
snd_ctl_t *handle;
snd_ctl_elem_value_t *control;
@@ -85,12 +93,14 @@ audio_return_t _audio_mixer_control_get_value(audio_mgr_t *am, const char *ctl_n
int ret = 0, count = 0, i = 0;
- pthread_mutex_lock(&(am->mixer.mutex));
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+
+ pthread_mutex_lock(&(ah->mixer.mutex));
ret = snd_ctl_open(&handle, ALSA_DEFAULT_CARD, 0);
if (ret < 0) {
AUDIO_LOG_ERROR ("snd_ctl_open error, %s\n", snd_strerror(ret));
- pthread_mutex_unlock(&(am->mixer.mutex));
+ pthread_mutex_unlock(&(ah->mixer.mutex));
return AUDIO_ERR_IOCTL;
}
@@ -143,17 +153,17 @@ audio_return_t _audio_mixer_control_get_value(audio_mgr_t *am, const char *ctl_n
AUDIO_LOG_INFO("get mixer(%s) = %d success", ctl_name, *val);
#endif
- pthread_mutex_unlock(&(am->mixer.mutex));
+ pthread_mutex_unlock(&(ah->mixer.mutex));
return AUDIO_RET_OK;
close:
AUDIO_LOG_ERROR ("Error\n");
snd_ctl_close(handle);
- pthread_mutex_unlock(&(am->mixer.mutex));
+ pthread_mutex_unlock(&(ah->mixer.mutex));
return AUDIO_ERR_UNDEFINED;
}
-audio_return_t _audio_mixer_control_set_value(audio_mgr_t *am, const char *ctl_name, int val)
+audio_return_t _audio_mixer_control_set_value(audio_hal_t *ah, const char *ctl_name, int val)
{
snd_ctl_t *handle;
snd_ctl_elem_value_t *control;
@@ -164,12 +174,15 @@ audio_return_t _audio_mixer_control_set_value(audio_mgr_t *am, const char *ctl_n
char *card_name = NULL;
int ret = 0, count = 0, i = 0;
- pthread_mutex_lock(&(am->mixer.mutex));
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ctl_name, AUDIO_ERR_PARAMETER);
+
+ pthread_mutex_lock(&(ah->mixer.mutex));
ret = snd_ctl_open(&handle, ALSA_DEFAULT_CARD, 0);
if (ret < 0) {
AUDIO_LOG_ERROR("snd_ctl_open error, card: %s: %s", card_name, snd_strerror(ret));
- pthread_mutex_unlock(&(am->mixer.mutex));
+ pthread_mutex_unlock(&(ah->mixer.mutex));
return AUDIO_ERR_IOCTL;
}
@@ -221,25 +234,32 @@ audio_return_t _audio_mixer_control_set_value(audio_mgr_t *am, const char *ctl_n
AUDIO_LOG_INFO("set mixer(%s) = %d success", ctl_name, val);
- pthread_mutex_unlock(&(am->mixer.mutex));
+ pthread_mutex_unlock(&(ah->mixer.mutex));
return AUDIO_RET_OK;
close:
AUDIO_LOG_ERROR("Error");
snd_ctl_close(handle);
- pthread_mutex_unlock(&(am->mixer.mutex));
+ pthread_mutex_unlock(&(ah->mixer.mutex));
return AUDIO_ERR_UNDEFINED;
}
-audio_return_t _audio_mixer_control_set_value_string(audio_mgr_t *am, const char* ctl_name, const char* value)
+audio_return_t _audio_mixer_control_set_value_string(audio_hal_t *ah, const char* ctl_name, const char* value)
{
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ctl_name, AUDIO_ERR_PARAMETER);
+
/* TODO. */
return AUDIO_RET_OK;
}
-audio_return_t _audio_mixer_control_get_element(audio_mgr_t *am, const char *ctl_name, snd_hctl_elem_t **elem)
+audio_return_t _audio_mixer_control_get_element(audio_hal_t *ah, const char *ctl_name, snd_hctl_elem_t **elem)
{
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ctl_name, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(elem, AUDIO_ERR_PARAMETER);
+
/* TODO. */
return AUDIO_RET_OK;
}
@@ -289,6 +309,8 @@ audio_return_t _audio_pcm_set_hw_params(snd_pcm_t *pcm, audio_pcm_sample_spec_t
uint8_t _use_mmap = use_mmap && *use_mmap;
uint32_t channels = 0;
+ AUDIO_RETURN_VAL_IF_FAIL(pcm, AUDIO_ERR_PARAMETER);
+
snd_pcm_hw_params_alloca(&hwparams);
/* Skip parameter setting to null device. */
@@ -387,6 +409,8 @@ audio_return_t _audio_pcm_set_sw_params(snd_pcm_t *pcm, snd_pcm_uframes_t avail_
snd_pcm_uframes_t boundary;
int err;
+ AUDIO_RETURN_VAL_IF_FAIL(pcm, AUDIO_ERR_PARAMETER);
+
snd_pcm_sw_params_alloca(&swparams);
if ((err = snd_pcm_sw_params_current(pcm, swparams) < 0)) {
diff --git a/tizen-audio-volume.c b/tizen-audio-volume.c
index e841f4a..a7611db 100644
--- a/tizen-audio-volume.c
+++ b/tizen-audio-volume.c
@@ -44,10 +44,9 @@ static const char *g_volume_vconf[AUDIO_VOLUME_TYPE_MAX] = {
"file/private/sound/volume/call", /* AUDIO_VOLUME_TYPE_CALL */
"file/private/sound/volume/voip", /* AUDIO_VOLUME_TYPE_VOIP */
"file/private/sound/volume/voice", /* AUDIO_VOLUME_TYPE_VOICE */
- "file/private/sound/volume/fixed", /* AUDIO_VOLUME_TYPE_FIXED */
};
-static const char *__get_volume_type_string_by_idx (uint32_t vol_type_idx)
+static const char *__get_volume_type_string_by_idx(uint32_t vol_type_idx)
{
switch (vol_type_idx) {
case AUDIO_VOLUME_TYPE_SYSTEM: return "system";
@@ -58,12 +57,11 @@ static const char *__get_volume_type_string_by_idx (uint32_t vol_type_idx)
case AUDIO_VOLUME_TYPE_CALL: return "call";
case AUDIO_VOLUME_TYPE_VOIP: return "voip";
case AUDIO_VOLUME_TYPE_VOICE: return "voice";
- case AUDIO_VOLUME_TYPE_FIXED: return "fixed";
default: return "invalid";
}
}
-static uint32_t __get_volume_idx_by_string_type (const char *vol_type)
+static uint32_t __get_volume_idx_by_string_type(const char *vol_type)
{
if (!strncmp(vol_type, "system", strlen(vol_type)) || !strncmp(vol_type, "0", strlen(vol_type)))
return AUDIO_VOLUME_TYPE_SYSTEM;
@@ -81,13 +79,11 @@ static uint32_t __get_volume_idx_by_string_type (const char *vol_type)
return AUDIO_VOLUME_TYPE_VOIP;
else if (!strncmp(vol_type, "voice", strlen(vol_type)) || !strncmp(vol_type, "7", strlen(vol_type)))
return AUDIO_VOLUME_TYPE_VOICE;
- else if (!strncmp(vol_type, "fixed", strlen(vol_type)) || !strncmp(vol_type, "8", strlen(vol_type)))
- return AUDIO_VOLUME_TYPE_FIXED;
else
return AUDIO_VOLUME_TYPE_MEDIA;
}
-static const char *__get_gain_type_string_by_idx (uint32_t gain_type_idx)
+static const char *__get_gain_type_string_by_idx(uint32_t gain_type_idx)
{
switch (gain_type_idx) {
case AUDIO_GAIN_TYPE_DEFAULT: return "default";
@@ -105,9 +101,9 @@ static const char *__get_gain_type_string_by_idx (uint32_t gain_type_idx)
}
}
-static void __dump_tb (audio_mgr_t *am)
+static void __dump_tb(audio_hal_t *ah)
{
- audio_volume_value_table_t *volume_value_table = am->volume.volume_value_table;
+ audio_volume_value_table_t *volume_value_table = ah->volume.volume_value_table;
uint32_t vol_type_idx, vol_level_idx, gain_type_idx;
const char *gain_type_str[] = {
"def", /* AUDIO_GAIN_TYPE_DEFAULT */
@@ -146,7 +142,7 @@ static void __dump_tb (audio_mgr_t *am)
AUDIO_LOG_INFO("%s", dump_str);
}
- volume_value_table = am->volume.volume_value_table;
+ volume_value_table = ah->volume.volume_value_table;
/* Dump gain table */
AUDIO_LOG_INFO("<<<<< gain table >>>>>");
@@ -177,11 +173,11 @@ static void __dump_tb (audio_mgr_t *am)
}
-static audio_return_t __load_volume_value_table_from_ini (audio_mgr_t *am)
+static audio_return_t __load_volume_value_table_from_ini(audio_hal_t *ah)
{
dictionary * dict = NULL;
uint32_t vol_type_idx, vol_level_idx, gain_type_idx;
- audio_volume_value_table_t *volume_value_table = am->volume.volume_value_table;
+ audio_volume_value_table_t *volume_value_table = ah->volume.volume_value_table;
int size = 0;
dict = iniparser_load(VOLUME_INI_TEMP_PATH);
@@ -251,22 +247,22 @@ static audio_return_t __load_volume_value_table_from_ini (audio_mgr_t *am)
iniparser_freedict(dict);
- __dump_tb(am);
+ __dump_tb(ah);
return AUDIO_RET_OK;
}
-audio_return_t _audio_volume_init (audio_mgr_t *am)
+audio_return_t _audio_volume_init(audio_hal_t *ah)
{
int i;
int val = 0;
audio_return_t audio_ret = AUDIO_RET_OK;
- int init_value[AUDIO_VOLUME_TYPE_MAX] = { 9, 11, 7, 11, 7, 4, 4, 7, 4, 0 };
+ int init_value[AUDIO_VOLUME_TYPE_MAX] = { 9, 11, 7, 11, 7, 4, 4, 7 };
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
for (i = 0; i < AUDIO_VOLUME_TYPE_MAX; i++) {
- am->volume.volume_level[i] = init_value[i];
+ ah->volume.volume_level[i] = init_value[i];
}
for (i = 0; i < AUDIO_VOLUME_TYPE_MAX; i++) {
@@ -277,15 +273,15 @@ audio_return_t _audio_volume_init (audio_mgr_t *am)
}
AUDIO_LOG_INFO("read vconf. %s = %d", g_volume_vconf[i], val);
- am->volume.volume_level[i] = val;
+ ah->volume.volume_level[i] = val;
}
- if (!(am->volume.volume_value_table = malloc(AUDIO_VOLUME_DEVICE_MAX * sizeof(audio_volume_value_table_t)))) {
+ if (!(ah->volume.volume_value_table = malloc(AUDIO_VOLUME_DEVICE_MAX * sizeof(audio_volume_value_table_t)))) {
AUDIO_LOG_ERROR("volume_value_table malloc failed");
return AUDIO_ERR_RESOURCE;
}
- audio_ret = __load_volume_value_table_from_ini(am);
+ audio_ret = __load_volume_value_table_from_ini(ah);
if(audio_ret != AUDIO_RET_OK) {
AUDIO_LOG_ERROR("gain table load error");
return AUDIO_ERR_UNDEFINED;
@@ -294,28 +290,28 @@ audio_return_t _audio_volume_init (audio_mgr_t *am)
return audio_ret;
}
-audio_return_t _audio_volume_deinit (audio_mgr_t *am)
+audio_return_t _audio_volume_deinit(audio_hal_t *ah)
{
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
- if (am->volume.volume_value_table) {
- free(am->volume.volume_value_table);
- am->volume.volume_value_table = NULL;
+ if (ah->volume.volume_value_table) {
+ free(ah->volume.volume_value_table);
+ ah->volume.volume_value_table = NULL;
}
return AUDIO_RET_OK;
}
-audio_return_t audio_get_volume_level_max (void *userdata, audio_volume_info_t *info, uint32_t *level)
+audio_return_t audio_get_volume_level_max(void *audio_handle, audio_volume_info_t *info, uint32_t *level)
{
- audio_mgr_t *am = (audio_mgr_t *)userdata;
+ audio_hal_t *ah = (audio_hal_t *)audio_handle;
audio_volume_value_table_t *volume_value_table;
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
- AUDIO_RETURN_VAL_IF_FAIL(am->volume.volume_value_table, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah->volume.volume_value_table, AUDIO_ERR_PARAMETER);
/* Get max volume level by device & type */
- volume_value_table = am->volume.volume_value_table;
+ volume_value_table = ah->volume.volume_value_table;
*level = volume_value_table->volume_level_max[__get_volume_idx_by_string_type(info->type)];
AUDIO_LOG_DEBUG("get_[%s] volume_level_max: %d", info->type, *level);
@@ -323,30 +319,30 @@ audio_return_t audio_get_volume_level_max (void *userdata, audio_volume_info_t *
return AUDIO_RET_OK;
}
-audio_return_t audio_get_volume_level (void *userdata, audio_volume_info_t *info, uint32_t *level)
+audio_return_t audio_get_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t *level)
{
- audio_mgr_t *am = (audio_mgr_t *)userdata;
+ audio_hal_t *ah = (audio_hal_t *)audio_handle;
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
- *level = am->volume.volume_level[__get_volume_idx_by_string_type(info->type)];
+ *level = ah->volume.volume_level[__get_volume_idx_by_string_type(info->type)];
AUDIO_LOG_INFO("get [%s] volume_level: %d, direction(%d)", info->type, *level, info->direction);
return AUDIO_RET_OK;
}
-audio_return_t audio_get_volume_value (void *userdata, audio_volume_info_t *info, uint32_t level, double *value)
+audio_return_t audio_get_volume_value(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value)
{
- audio_mgr_t *am = (audio_mgr_t *)userdata;
+ audio_hal_t *ah = (audio_hal_t *)audio_handle;
audio_volume_value_table_t *volume_value_table;
char dump_str[AUDIO_DUMP_STR_LEN] = {0,};
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
- AUDIO_RETURN_VAL_IF_FAIL(am->volume.volume_value_table, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah->volume.volume_value_table, AUDIO_ERR_PARAMETER);
/* Get basic volume by device & type & level */
- volume_value_table = am->volume.volume_value_table;
+ volume_value_table = ah->volume.volume_value_table;
if (volume_value_table->volume_level_max[__get_volume_idx_by_string_type(info->type)] < level)
*value = VOLUME_VALUE_MAX;
else
@@ -358,15 +354,15 @@ audio_return_t audio_get_volume_value (void *userdata, audio_volume_info_t *info
return AUDIO_RET_OK;
}
-audio_return_t audio_set_volume_level (void *userdata, audio_volume_info_t *info, uint32_t level)
+audio_return_t audio_set_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t level)
{
audio_return_t audio_ret = AUDIO_RET_OK;
- audio_mgr_t *am = (audio_mgr_t *)userdata;
+ audio_hal_t *ah = (audio_hal_t *)audio_handle;
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
/* Update volume level */
- am->volume.volume_level[__get_volume_idx_by_string_type(info->type)] = level;
+ ah->volume.volume_level[__get_volume_idx_by_string_type(info->type)] = level;
AUDIO_LOG_INFO("set [%s] volume_level: %d, direction(%d)", info->type, level, info->direction);
/* set mixer related to H/W volume if needed */
@@ -374,24 +370,24 @@ audio_return_t audio_set_volume_level (void *userdata, audio_volume_info_t *info
return audio_ret;
}
-audio_return_t audio_get_volume_mute (void *userdata, audio_volume_info_t *info, uint32_t *mute)
+audio_return_t audio_get_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t *mute)
{
audio_return_t audio_ret = AUDIO_RET_OK;
- audio_mgr_t *am = (audio_mgr_t *)userdata;
+ audio_hal_t *ah = (audio_hal_t *)audio_handle;
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
/* TODO. Not implemented */
return audio_ret;
}
-audio_return_t audio_set_volume_mute (void *userdata, audio_volume_info_t *info, uint32_t mute)
+audio_return_t audio_set_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t mute)
{
audio_return_t audio_ret = AUDIO_RET_OK;
- audio_mgr_t *am = (audio_mgr_t *)userdata;
+ audio_hal_t *ah = (audio_hal_t *)audio_handle;
- AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
/* TODO. Not implemented */
return audio_ret;
diff --git a/tizen-audio.c b/tizen-audio.c
index b7df609..cad4284 100644
--- a/tizen-audio.c
+++ b/tizen-audio.c
@@ -23,67 +23,66 @@
#include "tizen-audio-internal.h"
-audio_return_t audio_init (void **userdata)
+/* audio latency */
+static const char* AUDIO_LATENCY_LOW = "low";
+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_init (void **audio_handle)
{
- audio_mgr_t *am;
+ audio_hal_t *ah;
audio_return_t ret = AUDIO_RET_OK;
- if (!(am = malloc(sizeof(audio_mgr_t)))) {
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
+
+ if (!(ah = malloc(sizeof(audio_hal_t)))) {
AUDIO_LOG_ERROR("am malloc failed");
return AUDIO_ERR_RESOURCE;
}
- if (AUDIO_IS_ERROR((ret = _audio_device_init(am)))) {
+ if (AUDIO_IS_ERROR((ret = _audio_device_init(ah)))) {
AUDIO_LOG_ERROR("device init failed");
goto error_exit;
}
- if (AUDIO_IS_ERROR((ret = _audio_volume_init(am)))) {
+ if (AUDIO_IS_ERROR((ret = _audio_volume_init(ah)))) {
AUDIO_LOG_ERROR("stream init failed");
goto error_exit;
}
- if (AUDIO_IS_ERROR((ret = _audio_ucm_init(am)))) {
+ if (AUDIO_IS_ERROR((ret = _audio_ucm_init(ah)))) {
AUDIO_LOG_ERROR("ucm init failed");
goto error_exit;
}
- if (AUDIO_IS_ERROR((ret = _audio_util_init(am)))) {
+ if (AUDIO_IS_ERROR((ret = _audio_util_init(ah)))) {
AUDIO_LOG_ERROR("mixer init failed");
goto error_exit;
}
- *userdata = (void *)am;
+ *audio_handle = (void *)ah;
return AUDIO_RET_OK;
error_exit:
- if (am)
- free(am);
+ if (ah)
+ free(ah);
return ret;
}
-audio_return_t audio_deinit (void **userdata)
+audio_return_t audio_deinit (void *audio_handle)
{
- audio_mgr_t *am = (audio_mgr_t *)*userdata;
+ audio_hal_t *ah = (audio_hal_t *)audio_handle;
- if (am) {
- _audio_device_deinit(am);
- _audio_volume_deinit(am);
- _audio_ucm_deinit(am);
- _audio_util_deinit(am);
- free(am);
- *userdata = NULL;
- }
+ AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+
+ _audio_device_deinit(ah);
+ _audio_volume_deinit(ah);
+ _audio_ucm_deinit(ah);
+ _audio_util_deinit(ah);
+ free(ah);
+ ah = NULL;
return AUDIO_RET_OK;
}
-static const unsigned int SAMPLES_PER_PERIOD_DEFAULT = 1536; /* Frames */
-static const unsigned int PERIODS_PER_BUFFER_FASTMODE = 4;
-static const unsigned int PERIODS_PER_BUFFER_DEFAULT = 6;
-static const unsigned int PERIODS_PER_BUFFER_VOIP = 2;
-static const unsigned int PERIODS_PER_BUFFER_PLAYBACK = 8;
-static const unsigned int PERIODS_PER_BUFFER_CAPTURE = 12;
-static const unsigned int PERIODS_PER_BUFFER_VIDEO = 10;
-
-
/* Latency msec */
static const unsigned int PERIOD_TIME_FOR_ULOW_LATENCY_MSEC = 20;
static const unsigned int PERIOD_TIME_FOR_LOW_LATENCY_MSEC = 25;
@@ -134,7 +133,7 @@ uint32_t _audio_sample_size(audio_sample_format_t format)
{
return g_size_table[format];
}
-audio_return_t audio_get_buffer_attr(void *userdata,
+audio_return_t audio_get_buffer_attr(void *audio_handle,
uint32_t direction,
const char *latency,
uint32_t samplerate,
@@ -146,21 +145,18 @@ audio_return_t audio_get_buffer_attr(void *userdata,
uint32_t *minreq,
uint32_t *fragsize)
{
- assert(userdata);
- assert(latency);
- assert(maxlength);
- assert(tlength);
- assert(prebuf);
- assert(minreq);
- assert(fragsize);
+ AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(latency, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(maxlength, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(tlength, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(prebuf, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(minreq, AUDIO_ERR_PARAMETER);
+ AUDIO_RETURN_VAL_IF_FAIL(fragsize, AUDIO_ERR_PARAMETER);
AUDIO_LOG_DEBUG("hal-latency - audio_get_buffer_attr(direction:%d, latency:%s, samplerate:%d, format:%d, channels:%d)", direction, latency, samplerate, format, channels);
- audio_mgr_t *am = (audio_mgr_t *)userdata;
-
uint32_t period_time = 0,
- sample_per_period = 0,
- periods_per_buffer = 0;
+ sample_per_period = 0;
if (_sample_spec_valid(samplerate, format, channels) == 0) {
return AUDIO_ERR_PARAMETER;
@@ -171,7 +167,6 @@ audio_return_t audio_get_buffer_attr(void *userdata,
AUDIO_LOG_DEBUG("AUDIO_DIRECTION_IN, AUDIO_LATENCY_LOW");
period_time = PERIOD_TIME_FOR_LOW_LATENCY_MSEC;
sample_per_period = (samplerate * period_time) / 1000;
- periods_per_buffer = PERIODS_PER_BUFFER_FASTMODE;
*prebuf = 0;
*minreq = -1;
*tlength = -1;
@@ -181,7 +176,6 @@ audio_return_t audio_get_buffer_attr(void *userdata,
AUDIO_LOG_DEBUG("AUDIO_DIRECTION_IN, AUDIO_LATENCY_MID");
period_time = PERIOD_TIME_FOR_MID_LATENCY_MSEC;
sample_per_period = (samplerate * period_time) / 1000;
- periods_per_buffer = PERIODS_PER_BUFFER_DEFAULT;
*prebuf = 0;
*minreq = -1;
*tlength = -1;
@@ -191,7 +185,6 @@ audio_return_t audio_get_buffer_attr(void *userdata,
AUDIO_LOG_DEBUG("AUDIO_DIRECTION_IN, AUDIO_LATENCY_HIGH");
period_time = PERIOD_TIME_FOR_HIGH_LATENCY_MSEC;
sample_per_period = (samplerate * period_time) / 1000;
- periods_per_buffer = PERIODS_PER_BUFFER_CAPTURE;
*prebuf = 0;
*minreq = -1;
*tlength = -1;
@@ -201,7 +194,6 @@ audio_return_t audio_get_buffer_attr(void *userdata,
AUDIO_LOG_DEBUG("AUDIO_DIRECTION_IN, AUDIO_LATENCY_VOIP");
period_time = PERIOD_TIME_FOR_VOIP_LATENCY_MSEC;
sample_per_period = (samplerate * period_time) / 1000;
- periods_per_buffer = PERIODS_PER_BUFFER_VOIP;
*prebuf = 0;
*minreq = -1;
*tlength = -1;
@@ -216,7 +208,6 @@ audio_return_t audio_get_buffer_attr(void *userdata,
AUDIO_LOG_DEBUG("AUDIO_DIRECTION_OUT, AUDIO_LATENCY_LOW");
period_time = PERIOD_TIME_FOR_LOW_LATENCY_MSEC;
sample_per_period = (samplerate * period_time) / 1000;
- periods_per_buffer = PERIODS_PER_BUFFER_FASTMODE;
*prebuf = 0;
*minreq = -1;
*tlength = (samplerate / 10) * _audio_sample_size(format) * channels; /* 100ms */
@@ -226,7 +217,6 @@ audio_return_t audio_get_buffer_attr(void *userdata,
AUDIO_LOG_DEBUG("AUDIO_DIRECTION_OUT, AUDIO_LATENCY_MID");
period_time = PERIOD_TIME_FOR_MID_LATENCY_MSEC;
sample_per_period = (samplerate * period_time) / 1000;
- periods_per_buffer = PERIODS_PER_BUFFER_DEFAULT;
*prebuf = 0;
*minreq = -1;
*tlength = (uint32_t) _audio_usec_to_bytes(200000, samplerate, format, channels);
@@ -236,7 +226,6 @@ audio_return_t audio_get_buffer_attr(void *userdata,
AUDIO_LOG_DEBUG("AUDIO_DIRECTION_OUT, AUDIO_LATENCY_HIGH");
period_time = PERIOD_TIME_FOR_HIGH_LATENCY_MSEC;
sample_per_period = (samplerate * period_time) / 1000;
- periods_per_buffer = PERIODS_PER_BUFFER_PLAYBACK;
*prebuf = 0;
*minreq = -1;
*tlength = (uint32_t) _audio_usec_to_bytes(400000, samplerate, format, channels);
@@ -246,7 +235,6 @@ audio_return_t audio_get_buffer_attr(void *userdata,
AUDIO_LOG_DEBUG("AUDIO_DIRECTION_OUT, AUDIO_LATENCY_VOIP");
period_time = PERIOD_TIME_FOR_VOIP_LATENCY_MSEC;
sample_per_period = (samplerate * period_time) / 1000;
- periods_per_buffer = PERIODS_PER_BUFFER_VOIP;
*prebuf = 0;
*minreq = _audio_usec_to_bytes(20000, samplerate, format, channels);
*tlength = _audio_usec_to_bytes(100000, samplerate, format, channels);
diff --git a/tizen-audio.h b/tizen-audio.h
index 9fdcafb..8dd3b44 100644
--- a/tizen-audio.h
+++ b/tizen-audio.h
@@ -20,12 +20,9 @@
*
*/
-#include <stdio.h>
-#include <stdlib.h>
#include <stdint.h>
/* Error code */
-
#define AUDIO_IS_ERROR(ret) (ret < 0)
typedef enum audio_return {
AUDIO_RET_OK = 0,
@@ -36,90 +33,11 @@ typedef enum audio_return {
AUDIO_ERR_NOT_IMPLEMENTED = (int32_t)0x80001004,
} audio_return_t ;
-/* Direction */
typedef enum audio_direction {
AUDIO_DIRECTION_IN, /**< Capture */
AUDIO_DIRECTION_OUT, /**< Playback */
} audio_direction_t;
-typedef enum audio_device_api {
- AUDIO_DEVICE_API_UNKNOWN,
- AUDIO_DEVICE_API_ALSA,
- AUDIO_DEVICE_API_BLUEZ,
-} audio_device_api_t;
-
-typedef enum audio_device_param {
- AUDIO_DEVICE_PARAM_NONE,
- AUDIO_DEVICE_PARAM_CHANNELS,
- AUDIO_DEVICE_PARAM_SAMPLERATE,
- AUDIO_DEVICE_PARAM_FRAGMENT_SIZE,
- AUDIO_DEVICE_PARAM_FRAGMENT_NB,
- AUDIO_DEVICE_PARAM_START_THRESHOLD,
- AUDIO_DEVICE_PARAM_USE_MMAP,
- AUDIO_DEVICE_PARAM_USE_TSCHED,
- AUDIO_DEVICE_PARAM_TSCHED_BUF_SIZE,
- AUDIO_DEVICE_PARAM_SUSPEND_TIMEOUT,
- AUDIO_DEVICE_PARAM_ALTERNATE_RATE,
- AUDIO_DEVICE_PARAM_MAX,
-} audio_device_param_t;
-
-/* audio format */
-typedef enum audio_sample_format {
- AUDIO_SAMPLE_U8,
- AUDIO_SAMPLE_ALAW,
- AUDIO_SAMPLE_ULAW,
- AUDIO_SAMPLE_S16LE,
- AUDIO_SAMPLE_S16BE,
- AUDIO_SAMPLE_FLOAT32LE,
- AUDIO_SAMPLE_FLOAT32BE,
- AUDIO_SAMPLE_S32LE,
- AUDIO_SAMPLE_S32BE,
- AUDIO_SAMPLE_S24LE,
- AUDIO_SAMPLE_S24BE,
- AUDIO_SAMPLE_S24_32LE,
- AUDIO_SAMPLE_S24_32BE,
- AUDIO_SAMPLE_MAX,
- AUDIO_SAMPLE_INVALID = -1
-} audio_sample_format_t;
-
-/* audio latency */
-static const char* AUDIO_LATENCY_LOW = "low";
-static const char* AUDIO_LATENCY_MID = "mid";
-static const char* AUDIO_LATENCY_HIGH = "high";
-static const char* AUDIO_LATENCY_VOIP = "voip";
-
-typedef struct audio_device_param_info {
- audio_device_param_t param;
- union {
- int64_t s64_v;
- uint64_t u64_v;
- int32_t s32_v;
- uint32_t u32_v;
- };
-} audio_device_param_info_t;
-
-typedef struct audio_device_alsa_info {
- char *card_name;
- uint32_t card_idx;
- uint32_t device_idx;
-} audio_device_alsa_info_t;
-
-typedef struct audio_device_bluz_info {
- char *protocol;
- uint32_t nrec;
-} audio_device_bluez_info_t;
-
-typedef struct audio_device_info {
- audio_device_api_t api;
- audio_direction_t direction;
- char *name;
- uint8_t is_default_device;
- union {
- audio_device_alsa_info_t alsa;
- audio_device_bluez_info_t bluez;
- };
-} audio_device_info_t;
-
typedef struct device_info {
const char *type;
uint32_t direction;
@@ -150,87 +68,57 @@ typedef struct audio_stream_info {
uint32_t idx;
} audio_stream_info_t ;
-/* Stream */
-
-typedef enum audio_volume {
- AUDIO_VOLUME_TYPE_SYSTEM, /**< System volume type */
- AUDIO_VOLUME_TYPE_NOTIFICATION, /**< Notification volume type */
- AUDIO_VOLUME_TYPE_ALARM, /**< Alarm volume type */
- AUDIO_VOLUME_TYPE_RINGTONE, /**< Ringtone volume type */
- AUDIO_VOLUME_TYPE_MEDIA, /**< Media volume type */
- AUDIO_VOLUME_TYPE_CALL, /**< Call volume type */
- AUDIO_VOLUME_TYPE_VOIP, /**< VOIP volume type */
- AUDIO_VOLUME_TYPE_VOICE, /**< Voice volume type */
- AUDIO_VOLUME_TYPE_FIXED, /**< Volume type for fixed acoustic level */
- AUDIO_VOLUME_TYPE_MAX, /**< Volume type count */
-} audio_volume_t;
-
-typedef enum audio_gain {
- AUDIO_GAIN_TYPE_DEFAULT,
- AUDIO_GAIN_TYPE_DIALER,
- AUDIO_GAIN_TYPE_TOUCH,
- AUDIO_GAIN_TYPE_AF,
- AUDIO_GAIN_TYPE_SHUTTER1,
- AUDIO_GAIN_TYPE_SHUTTER2,
- AUDIO_GAIN_TYPE_CAMCODING,
- AUDIO_GAIN_TYPE_MIDI,
- AUDIO_GAIN_TYPE_BOOTING,
- AUDIO_GAIN_TYPE_VIDEO,
- AUDIO_GAIN_TYPE_TTS,
- AUDIO_GAIN_TYPE_MAX,
-} audio_gain_t;
-
/* Overall */
typedef struct audio_interface {
- audio_return_t (*init)(void **userdata);
- audio_return_t (*deinit)(void **userdata);
- audio_return_t (*get_volume_level_max)(void *userdata, audio_volume_info_t *info, uint32_t *level);
- audio_return_t (*get_volume_level)(void *userdata, audio_volume_info_t *info, uint32_t *level);
- audio_return_t (*set_volume_level)(void *userdata, audio_volume_info_t *info, uint32_t level);
- audio_return_t (*get_volume_value)(void *userdata, audio_volume_info_t *info, uint32_t level, double *value);
- audio_return_t (*get_volume_mute)(void *userdata, audio_volume_info_t *info, uint32_t *mute);
- audio_return_t (*set_volume_mute)(void *userdata, audio_volume_info_t *info, uint32_t mute);
- audio_return_t (*do_route)(void *userdata, audio_route_info_t *info);
- audio_return_t (*update_route_option)(void *userdata, audio_route_option_t *option);
- audio_return_t (*update_stream_connection_info) (void *userdata, audio_stream_info_t *info, uint32_t is_connected);
- audio_return_t (*get_buffer_attr)(void *userdata, uint32_t direction, const char *latency, uint32_t samplerate, int format, uint32_t channels,
+ audio_return_t (*init)(void **audio_handle);
+ audio_return_t (*deinit)(void *audio_handle);
+ 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);
+ 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);
+ 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 */
- audio_return_t (*pcm_open)(void *userdata, void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods);
- audio_return_t (*pcm_start)(void *userdata, void *pcm_handle);
- audio_return_t (*pcm_stop)(void *userdata, void *pcm_handle);
- audio_return_t (*pcm_close)(void *userdata, void *pcm_handle);
- audio_return_t (*pcm_avail)(void *userdata, void *pcm_handle, uint32_t *avail);
- audio_return_t (*pcm_write)(void *userdata, void *pcm_handle, const void *buffer, uint32_t frames);
- audio_return_t (*pcm_read)(void *userdata, void *pcm_handle, void *buffer, uint32_t frames);
- audio_return_t (*pcm_get_fd)(void *userdata, void *pcm_handle, int *fd);
- audio_return_t (*pcm_recover)(void *userdata, void *pcm_handle, int revents);
- audio_return_t (*pcm_get_params)(void *userdata, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods);
- audio_return_t (*pcm_set_params)(void *userdata, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods);
+ audio_return_t (*pcm_open)(void *audio_handle, void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods);
+ audio_return_t (*pcm_start)(void *audio_handle, void *pcm_handle);
+ audio_return_t (*pcm_stop)(void *audio_handle, void *pcm_handle);
+ audio_return_t (*pcm_close)(void *audio_handle, void *pcm_handle);
+ audio_return_t (*pcm_avail)(void *audio_handle, void *pcm_handle, uint32_t *avail);
+ audio_return_t (*pcm_write)(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames);
+ audio_return_t (*pcm_read)(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames);
+ audio_return_t (*pcm_get_fd)(void *audio_handle, void *pcm_handle, int *fd);
+ 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);
} audio_interface_t;
-audio_return_t audio_init(void **userdata);
-audio_return_t audio_deinit(void **userdata);
-audio_return_t audio_get_volume_level_max(void *userdata, audio_volume_info_t *info, uint32_t *level);
-audio_return_t audio_get_volume_level(void *userdata, audio_volume_info_t *info, uint32_t *level);
-audio_return_t audio_set_volume_level(void *userdata, audio_volume_info_t *info, uint32_t level);
-audio_return_t audio_get_volume_value(void *userdata, audio_volume_info_t *info, uint32_t level, double *value);
-audio_return_t audio_get_volume_mute(void *userdata, audio_volume_info_t *info, uint32_t *mute);
-audio_return_t audio_set_volume_mute(void *userdata, audio_volume_info_t *info, uint32_t mute);
-audio_return_t audio_do_route(void *userdata, audio_route_info_t *info);
-audio_return_t audio_update_route_option(void *userdata, audio_route_option_t *option);
-audio_return_t audio_update_stream_connection_info(void *userdata, audio_stream_info_t *info, uint32_t is_connected);
-audio_return_t audio_get_buffer_attr(void *userdata, uint32_t direction, const char *latency, uint32_t samplerate, int format, uint32_t channels,
+audio_return_t audio_init(void **audio_handle);
+audio_return_t audio_deinit(void *audio_handle);
+audio_return_t audio_get_volume_level_max(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
+audio_return_t audio_get_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
+audio_return_t audio_set_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t level);
+audio_return_t audio_get_volume_value(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value);
+audio_return_t audio_get_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t *mute);
+audio_return_t audio_set_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t mute);
+audio_return_t audio_do_route(void *audio_handle, audio_route_info_t *info);
+audio_return_t audio_update_route_option(void *audio_handle, audio_route_option_t *option);
+audio_return_t audio_update_stream_connection_info(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected);
+audio_return_t audio_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);
-audio_return_t audio_pcm_open(void *userdata, void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods);
-audio_return_t audio_pcm_start(void *userdata, void *pcm_handle);
-audio_return_t audio_pcm_stop(void *userdata, void *pcm_handle);
-audio_return_t audio_pcm_close(void *userdata, void *pcm_handle);
-audio_return_t audio_pcm_avail(void *userdata, void *pcm_handle, uint32_t *avail);
-audio_return_t audio_pcm_write(void *userdata, void *pcm_handle, const void *buffer, uint32_t frames);
-audio_return_t audio_pcm_read(void *userdata, void *pcm_handle, void *buffer, uint32_t frames);
-audio_return_t audio_pcm_get_fd(void *userdata, void *pcm_handle, int *fd);
-audio_return_t audio_pcm_recover(void *userdata, void *pcm_handle, int revents);
-audio_return_t audio_pcm_get_params(void *userdata, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods);
-audio_return_t audio_pcm_set_params(void *userdata, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods);
+audio_return_t audio_pcm_open(void *audio_handle, void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods);
+audio_return_t audio_pcm_start(void *audio_handle, void *pcm_handle);
+audio_return_t audio_pcm_stop(void *audio_handle, void *pcm_handle);
+audio_return_t audio_pcm_close(void *audio_handle, void *pcm_handle);
+audio_return_t audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *avail);
+audio_return_t audio_pcm_write(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames);
+audio_return_t audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames);
+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);
#endif