From a01f638814af3103d2037605479ef1a3cfed210b Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Thu, 15 Dec 2016 17:25:07 +0900 Subject: [PATCH 01/16] Handle route option update for Radio Mute when Earjack is disconnected [Version] 0.1.20 [Profile] Mobile [Issue Type] PLM Change-Id: I6fcf42be12e6268d73eacfbec22f2d91c030ddc8 --- packaging/audio-hal-sc7727.spec | 2 +- tizen-audio-routing.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index 4d49877..460b156 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.19 +Version: 0.1.20 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-routing.c b/tizen-audio-routing.c index 960e55c..a9e8e47 100644 --- a/tizen-audio-routing.c +++ b/tizen-audio-routing.c @@ -286,7 +286,6 @@ static audio_return_t __update_route_fmradio(audio_hal_t *ah, device_info_t *dev AUDIO_LOG_ERROR("Failed to _fmradio_pcm_open(): error = 0x%x", audio_ret); return audio_ret; } - _audio_volume_set_level_radio(ah, 0); } audio_ret = __set_devices(ah, verb, devices, num_of_devices); @@ -297,7 +296,6 @@ static audio_return_t __update_route_fmradio(audio_hal_t *ah, device_info_t *dev /* FIXME. If necessary, set VERB_VOIP */ ah->device.mode = VERB_RADIO; - _audio_volume_set_level_radio(ah, ah->volume.volume_level[AUDIO_VOLUME_TYPE_MEDIA]); if ((audio_ret = __connect_fm_radio(ah))) AUDIO_LOG_ERROR("failed to __connect_fm_radio(), ret(0x%x)", audio_ret); @@ -499,5 +497,13 @@ audio_return_t audio_update_route_option(void *audio_handle, audio_route_option_ AUDIO_LOG_INFO("role:%s, name:%s, value:%d", option->role, option->name, option->value); + /* Handle RADIO MUTE due to earjack disconnection */ + if ((option->role && strcmp(option->role, "radio") == 0) && + (option->name && strcmp(option->name, "mute") == 0) && + option->value == 1) { + AUDIO_LOG_INFO("MUTE RADIO!!!!"); + audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_MUTE, 0); + } + return audio_ret; } -- 2.7.4 From 03780e47497a0f6c1f1e658004f1f23a42c4368e Mon Sep 17 00:00:00 2001 From: Jeongho Mok Date: Tue, 3 Jan 2017 19:42:53 +0900 Subject: [PATCH 02/16] Skip master volume in set_volume_level [Version] 0.1.21 [Profile] Common [Issue Type] Code Enhancement Change-Id: Ib2a9aab42debaeef4108b2cc2f2895e5eca0f64a --- packaging/audio-hal-sc7727.spec | 2 +- tizen-audio-volume.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index 460b156..24f038c 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.20 +Version: 0.1.21 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-volume.c b/tizen-audio-volume.c index 18582de..fa96693 100644 --- a/tizen-audio-volume.c +++ b/tizen-audio-volume.c @@ -42,6 +42,8 @@ #define RADIO_TUNING_VOLUME_TABLE "fmradio:volume_table" #define RADIO_VOLUME_NUM_MAX 100 +uint32_t g_master_volume_level = 100; + static const char *g_volume_vconf[AUDIO_VOLUME_TYPE_MAX] = { "file/private/sound/volume/system", /* AUDIO_VOLUME_TYPE_SYSTEM */ "file/private/sound/volume/notification", /* AUDIO_VOLUME_TYPE_NOTIFICATION */ @@ -458,6 +460,11 @@ audio_return_t audio_get_volume_level_max(void *audio_handle, audio_volume_info_ AUDIO_RETURN_VAL_IF_FAIL(info, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(level, AUDIO_ERR_PARAMETER); + if (!strncmp(info->type, "master", strlen("master"))) { + *level = g_master_volume_level; + return AUDIO_RET_OK; + } + /* Get max volume level by device & type */ *level = ah->volume.volume_level_max[__get_volume_idx_by_string_type(info->type)]; @@ -512,6 +519,10 @@ audio_return_t audio_set_volume_level(void *audio_handle, audio_volume_info_t *i AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(info, AUDIO_ERR_PARAMETER); + if (!strncmp(info->type, "master", strlen("master"))) { + g_master_volume_level = level; + return AUDIO_RET_OK; + } AUDIO_RETURN_VAL_IF_FAIL((ah->volume.volume_level_max[__get_volume_idx_by_string_type(info->type)] >= level), AUDIO_ERR_PARAMETER); /* Update volume level */ -- 2.7.4 From 5ca6991ba9e922909342d117c868067b5926b793 Mon Sep 17 00:00:00 2001 From: Jeongho Mok Date: Fri, 6 Jan 2017 21:02:05 +0900 Subject: [PATCH 03/16] Fix bug, get master volume correctly [Version] 0.1.22 [Profile] Common [Issue Type] Code Enhancement Change-Id: I2f8b87aad7dcbace0b04d86e09bde4c28b843d48 --- packaging/audio-hal-sc7727.spec | 2 +- tizen-audio-volume.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index 24f038c..74ff5d2 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.21 +Version: 0.1.22 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-volume.c b/tizen-audio-volume.c index fa96693..a9c427a 100644 --- a/tizen-audio-volume.c +++ b/tizen-audio-volume.c @@ -460,11 +460,6 @@ audio_return_t audio_get_volume_level_max(void *audio_handle, audio_volume_info_ AUDIO_RETURN_VAL_IF_FAIL(info, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(level, AUDIO_ERR_PARAMETER); - if (!strncmp(info->type, "master", strlen("master"))) { - *level = g_master_volume_level; - return AUDIO_RET_OK; - } - /* Get max volume level by device & type */ *level = ah->volume.volume_level_max[__get_volume_idx_by_string_type(info->type)]; @@ -481,6 +476,11 @@ audio_return_t audio_get_volume_level(void *audio_handle, audio_volume_info_t *i AUDIO_RETURN_VAL_IF_FAIL(info, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(level, AUDIO_ERR_PARAMETER); + if (!strncmp(info->type, "master", strlen("master"))) { + *level = g_master_volume_level; + return AUDIO_RET_OK; + } + *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); -- 2.7.4 From c393b9555d51d2ab2863d2e9e8f55de79b17f735 Mon Sep 17 00:00:00 2001 From: Jeongho Mok Date: Wed, 22 Mar 2017 17:00:16 +0900 Subject: [PATCH 04/16] Use license macro in spec [Version] 0.1.23 [Profile] Common [Issue Type] License Change-Id: If0183e24f406b54952cf0f15472c343a80143ecb --- LICENSE.Apache-2.0 => LICENSE.APLv2 | 0 packaging/audio-hal-sc7727.spec | 8 +++----- 2 files changed, 3 insertions(+), 5 deletions(-) rename LICENSE.Apache-2.0 => LICENSE.APLv2 (100%) diff --git a/LICENSE.Apache-2.0 b/LICENSE.APLv2 similarity index 100% rename from LICENSE.Apache-2.0 rename to LICENSE.APLv2 diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index 74ff5d2..7e9421f 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.22 +Version: 0.1.23 Release: 0 Group: System/Libraries License: Apache-2.0 @@ -33,9 +33,7 @@ export USE_TINYALSA="0" make %{?jobs:-j%jobs} %install -rm -rf %{buildroot} -mkdir -p %{buildroot}%{_datadir}/license -cp LICENSE.Apache-2.0 %{buildroot}%{_datadir}/license/%{name} + %make_install %post @@ -48,4 +46,4 @@ cp LICENSE.Apache-2.0 %{buildroot}%{_datadir}/license/%{name} %manifest audio-hal-sc7727.manifest %defattr(-,root,root,-) %{_libdir}/libtizen-audio.so -%{_datadir}/license/%{name} +%license LICENSE.APLv2 -- 2.7.4 From 2cda60dc12b2f808ccbf8c315a92ae328d80de13 Mon Sep 17 00:00:00 2001 From: Jeongho Mok Date: Tue, 4 Apr 2017 16:25:13 +0900 Subject: [PATCH 05/16] Use big enough array for radio volume Change-Id: I8acbbd85f59c4f85aff219252a7b0f99bbcc28a1 --- tizen-audio-internal.h | 4 ++-- tizen-audio-volume.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tizen-audio-internal.h b/tizen-audio-internal.h index 33518bb..d383b5c 100644 --- a/tizen-audio-internal.h +++ b/tizen-audio-internal.h @@ -205,7 +205,7 @@ typedef struct audio_hal_device { /* Volume */ #define AUDIO_VOLUME_LEVEL_MAX 16 -#define RADIO_VOLUME_MAX 16 +#define RADIO_VOLUME_LEVEL_MAX 100 typedef enum audio_volume { AUDIO_VOLUME_TYPE_SYSTEM, /**< System volume type */ @@ -248,7 +248,7 @@ typedef struct audio_hal_volume { uint32_t volume_level_max[AUDIO_VOLUME_LEVEL_MAX]; uint32_t volume_level[AUDIO_VOLUME_TYPE_MAX]; audio_volume_value_table_t *volume_value_table; - int32_t radio_volume_value_table[RADIO_VOLUME_MAX]; + int32_t radio_volume_value_table[RADIO_VOLUME_LEVEL_MAX]; } audio_hal_volume_t; /* UCM */ diff --git a/tizen-audio-volume.c b/tizen-audio-volume.c index a9c427a..a4d3950 100644 --- a/tizen-audio-volume.c +++ b/tizen-audio-volume.c @@ -40,7 +40,6 @@ #define RADIO_TUNING_ENABLE "tuning:enable" #define RADIO_TUNING_VOLUME_LEVELS "fmradio:volume_levels" #define RADIO_TUNING_VOLUME_TABLE "fmradio:volume_table" -#define RADIO_VOLUME_NUM_MAX 100 uint32_t g_master_volume_level = 100; @@ -313,7 +312,7 @@ static audio_return_t __load_radio_volume_table(int** volume_table, int *number_ } *number_of_elements = iniparser_getint(dict, RADIO_TUNING_VOLUME_LEVELS, -1); - if (*number_of_elements <= 0 || *number_of_elements > RADIO_VOLUME_NUM_MAX) { + if (*number_of_elements <= 0 || *number_of_elements > RADIO_VOLUME_LEVEL_MAX) { AUDIO_LOG_ERROR("invalid number of elements, %d", *number_of_elements); ret = AUDIO_ERR_INTERNAL; goto error; -- 2.7.4 From 7776d3b124e9a858937059fd4de70f21662d2f2f Mon Sep 17 00:00:00 2001 From: "aravind.gara" Date: Mon, 16 Oct 2017 19:37:13 +0900 Subject: [PATCH 06/16] Rectify arguments mismatch Change-Id: I564038e2d0eb6b67bd190a1f7011f50080392e19 Signed-off-by: aravind.gara (cherry picked from commit 840e5901561ab3c34ff81936d0511ede4c35ef1f) --- tizen-audio-impl-pcm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tizen-audio-impl-pcm.c b/tizen-audio-impl-pcm.c index efb62fc..6f1a02b 100644 --- a/tizen-audio-impl-pcm.c +++ b/tizen-audio-impl-pcm.c @@ -761,12 +761,12 @@ audio_return_t _pcm_set_params(void *pcm_handle, uint32_t direction, void *sampl } if ((err = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, ss.channels)) < 0) { - AUDIO_LOG_ERROR("snd_pcm_hw_params_set_channels(%u) failed : %d", err); + AUDIO_LOG_ERROR("snd_pcm_hw_params_set_channels(%u) failed : %d", ss.channels, err); return AUDIO_ERR_PARAMETER; } if ((err = snd_pcm_hw_params_set_period_size(pcm_handle, hwparams, period_size, 0)) < 0) { - AUDIO_LOG_ERROR("snd_pcm_hw_params_set_period_size(%u) failed : %d", err); + AUDIO_LOG_ERROR("snd_pcm_hw_params_set_period_size(%u) failed : %d", period_size, err); return AUDIO_ERR_PARAMETER; } @@ -981,4 +981,4 @@ audio_return_t _pcm_set_sw_params(snd_pcm_t *pcm, snd_pcm_uframes_t avail_min, u return AUDIO_RET_OK; error: return err; -} \ No newline at end of file +} -- 2.7.4 From 8dab939f22e28efa0524c4115f386723be1560dd Mon Sep 17 00:00:00 2001 From: Jungsup Lee Date: Tue, 26 Jun 2018 14:38:32 +0900 Subject: [PATCH 07/16] Card and device arguments are added to pcm open API [Version] 0.1.24 [Issue Type] API Change-Id: Ia1ba2a63b3aa3212e756debf548611046ebb9495 Signed-off-by: Sangchul Lee --- packaging/audio-hal-sc7727.spec | 2 +- tizen-audio-impl-pcm.c | 85 +++++++++++++++++++++++++++++------------ tizen-audio-impl.h | 2 +- tizen-audio-internal.h | 8 ---- tizen-audio-pcm.c | 9 +++-- tizen-audio.h | 8 ++-- 6 files changed, 73 insertions(+), 41 deletions(-) diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index 7e9421f..cfbc7ad 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.23 +Version: 0.1.24 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-impl-pcm.c b/tizen-audio-impl-pcm.c index 6f1a02b..0c1304c 100644 --- a/tizen-audio-impl-pcm.c +++ b/tizen-audio-impl-pcm.c @@ -29,6 +29,10 @@ #include "tizen-audio-internal.h" #include "tizen-audio-impl.h" +#ifndef __USE_TINYALSA__ +#define DEVICE_NAME_MAX 32 +#endif + #ifdef __USE_TINYALSA__ /* Convert pcm format from pulse to alsa */ static const uint32_t g_format_convert_table[] = { @@ -128,11 +132,27 @@ error: } #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 int __parse_card_device_number(const char *card, const char *device, unsigned int *card_u, unsigned int *device_u) { + AUDIO_RETURN_VAL_IF_FAIL(card, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(device, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(card_u, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(device_u, AUDIO_ERR_PARAMETER); + + AUDIO_LOG_DEBUG("card : %s, device : %s", card, device); + + *card_u = (unsigned int) strtol(card, NULL, 10); + *device_u = (unsigned int) strtol(device, NULL, 10); + + return 0; +} + +static struct pcm *__tinyalsa_open_device(const char *card, const char *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; + unsigned int card_u, device_u; + AUDIO_RETURN_NULL_IF_FAIL(device); AUDIO_RETURN_NULL_IF_FAIL(ss); config.channels = ss->channels; @@ -144,12 +164,15 @@ static struct pcm *__tinyalsa_open_device(audio_pcm_sample_spec_t *ss, size_t pe config.stop_threshold = 0xFFFFFFFF; config.silence_threshold = 0; - AUDIO_LOG_INFO("direction %d, channels %d, rate %d, format %d, period_size %d, period_count %d", direction, ss->channels, ss->rate, ss->format, period_size, period_count); + AUDIO_LOG_INFO("card %s, device %s, direction %d, channels %d, rate %d, format %d, period_size %d, period_count %d", + card, device, direction, ss->channels, ss->rate, ss->format, period_size, period_count); + + if (__parse_card_device_number(card, device, &card_u, &device_u) < 0) { + AUDIO_LOG_ERROR("Failed to get card device number from %s", device); + return NULL; + } - pcm = pcm_open((direction == AUDIO_DIRECTION_OUT) ? PLAYBACK_CARD_ID : CAPTURE_CARD_ID, - (direction == AUDIO_DIRECTION_OUT) ? PLAYBACK_PCM_DEVICE_ID : CAPTURE_PCM_DEVICE_ID, - (direction == AUDIO_DIRECTION_OUT) ? PCM_OUT : PCM_IN, - &config); + pcm = pcm_open(card_u, device_u, (direction == AUDIO_DIRECTION_OUT) ? PCM_OUT : PCM_IN, &config); if (!pcm || !pcm_is_ready(pcm)) { AUDIO_LOG_ERROR("Unable to open device (%s)", pcm_get_error(pcm)); pcm_close(pcm); @@ -334,16 +357,37 @@ audio_return_t _reset_pcm_devices(audio_hal_t *ah) return audio_ret; } -audio_return_t _pcm_open(void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods) +#ifndef __USE_TINYALSA__ +static int __make_alsa_device_name(const char *card, const char *device, char device_name[]) { + AUDIO_RETURN_VAL_IF_FAIL(card, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(device, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(device_name, AUDIO_ERR_PARAMETER); + + snprintf(device_name, DEVICE_NAME_MAX, "hw:%s,%s", card, device); + return 0; +} +#endif + +audio_return_t _pcm_open(const char *card, const char *device, uint32_t direction, void *sample_spec, + uint32_t period_size, uint32_t periods, void **pcm_handle) +{ + int err; + + AUDIO_RETURN_VAL_IF_FAIL(card, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(device, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL((direction == AUDIO_DIRECTION_OUT) || (direction == AUDIO_DIRECTION_IN), + AUDIO_ERR_PARAMETER); + + AUDIO_LOG_INFO("card(%s) device(%s) direction(%u) period_size(%u) periods(%u)", + card, device, direction, period_size, periods); #ifdef __USE_TINYALSA__ audio_pcm_sample_spec_t *ss; - int err; ss = (audio_pcm_sample_spec_t *)sample_spec; ss->format = __convert_format((audio_sample_format_t)ss->format); - *pcm_handle = __tinyalsa_open_device(ss, (size_t)period_size, (size_t)periods, direction); + *pcm_handle = __tinyalsa_open_device(card, device, ss, (size_t)period_size, (size_t)periods, direction); if (*pcm_handle == NULL) { AUDIO_LOG_ERROR("Error opening PCM device"); return AUDIO_ERR_RESOURCE; @@ -354,28 +398,21 @@ audio_return_t _pcm_open(void **pcm_handle, uint32_t direction, void *sample_spe } #else /* alsa-lib */ - int err, mode; - char *device_name = NULL; + int mode; + audio_return_t ret; + char device_name[DEVICE_NAME_MAX]; + __make_alsa_device_name(card, device, device_name); mode = SND_PCM_NONBLOCK | SND_PCM_NO_AUTO_RESAMPLE | SND_PCM_NO_AUTO_CHANNELS | SND_PCM_NO_AUTO_FORMAT; - if (direction == AUDIO_DIRECTION_OUT) - device_name = PLAYBACK_PCM_DEVICE; - else if (direction == AUDIO_DIRECTION_IN) - device_name = CAPTURE_PCM_DEVICE; - else { - AUDIO_LOG_ERROR("Error get device_name, direction : %d", direction); - return AUDIO_ERR_RESOURCE; - } - if ((err = snd_pcm_open((snd_pcm_t **)pcm_handle, device_name, (direction == AUDIO_DIRECTION_OUT) ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE, mode)) < 0) { AUDIO_LOG_ERROR("Error opening PCM device %s : %s", device_name, snd_strerror(err)); return AUDIO_ERR_RESOURCE; } - if ((err = _pcm_set_params(*pcm_handle, direction, sample_spec, period_size, periods)) != AUDIO_RET_OK) { - AUDIO_LOG_ERROR("Failed to set pcm parameters : %d", err); - return err; + if ((ret = _pcm_set_params(*pcm_handle, direction, sample_spec, period_size, periods)) != AUDIO_RET_OK) { + AUDIO_LOG_ERROR("Failed to set pcm parameters : %d", ret); + return ret; } AUDIO_LOG_INFO("PCM device %s", device_name); @@ -777,7 +814,7 @@ audio_return_t _pcm_set_params(void *pcm_handle, uint32_t direction, void *sampl _buffer_size = period_size * periods; if ((err = snd_pcm_hw_params_set_buffer_size(pcm_handle, hwparams, _buffer_size)) < 0) { - AUDIO_LOG_ERROR("snd_pcm_hw_params_set_buffer_size(%u) failed : %d", periods * periods, err); + AUDIO_LOG_ERROR("snd_pcm_hw_params_set_buffer_size(%u) failed : %d", _buffer_size, err); return AUDIO_ERR_PARAMETER; } diff --git a/tizen-audio-impl.h b/tizen-audio-impl.h index 26a54a5..051eb84 100644 --- a/tizen-audio-impl.h +++ b/tizen-audio-impl.h @@ -26,7 +26,7 @@ audio_return_t _fmradio_pcm_close(audio_hal_t *ah); audio_return_t _voice_pcm_open(audio_hal_t *ah); audio_return_t _voice_pcm_close(audio_hal_t *ah, uint32_t direction); audio_return_t _reset_pcm_devices(audio_hal_t *ah); -audio_return_t _pcm_open(void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); +audio_return_t _pcm_open(const char *card, const char *device, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **pcm_handle); audio_return_t _pcm_start(void *pcm_handle); audio_return_t _pcm_stop(void *pcm_handle); audio_return_t _pcm_close(void *pcm_handle); diff --git a/tizen-audio-internal.h b/tizen-audio-internal.h index d383b5c..62d4646 100644 --- a/tizen-audio-internal.h +++ b/tizen-audio-internal.h @@ -155,14 +155,6 @@ typedef struct device_type { #define ALSA_DEFAULT_CARD "sprdphone" #define VOICE_PCM_DEVICE "hw:sprdphone,1" -#define PLAYBACK_PCM_DEVICE "hw:sprdphone,0" -#define CAPTURE_PCM_DEVICE "hw:sprdphone,0" - -#define PLAYBACK_CARD_ID ALSA_DEFAULT_CARD -#define PLAYBACK_PCM_DEVICE_ID 0 - -#define CAPTURE_CARD_ID ALSA_DEFAULT_CARD -#define CAPTURE_PCM_DEVICE_ID 0 #define MAX_DEVICES 5 #define MAX_MODIFIERS 5 diff --git a/tizen-audio-pcm.c b/tizen-audio-pcm.c index de97595..e11f8cc 100644 --- a/tizen-audio-pcm.c +++ b/tizen-audio-pcm.c @@ -50,7 +50,8 @@ audio_return_t _audio_pcm_deinit(audio_hal_t *ah) return AUDIO_RET_OK; } -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_open(void *audio_handle, const char *card, const char *device, uint32_t direction, void *sample_spec, + uint32_t period_size, uint32_t periods, void **pcm_handle) { audio_return_t audio_ret = AUDIO_RET_OK; audio_hal_t *ah = NULL; @@ -61,12 +62,12 @@ audio_return_t audio_pcm_open(void *audio_handle, void **pcm_handle, uint32_t di AUDIO_RETURN_VAL_IF_FAIL((period_size > 0), AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL((periods > 0), AUDIO_ERR_PARAMETER); - if ((audio_ret = _pcm_open(pcm_handle, direction, sample_spec, period_size, periods))) + if ((audio_ret = _pcm_open(card, device, direction, sample_spec, period_size, periods, pcm_handle))) return audio_ret; ah = (audio_hal_t*)audio_handle; ah->device.pcm_count++; - AUDIO_LOG_INFO("Opening PCM handle 0x%x", *pcm_handle); + AUDIO_LOG_INFO("Opening PCM handle 0x%x", (unsigned int)*pcm_handle); return AUDIO_RET_OK; } @@ -205,4 +206,4 @@ audio_return_t audio_pcm_set_params(void *audio_handle, void *pcm_handle, uint32 audio_ret = _pcm_set_params(pcm_handle, direction, sample_spec, period_size, periods); return audio_ret; -} \ No newline at end of file +} diff --git a/tizen-audio.h b/tizen-audio.h index 5bc47a9..94efa03 100644 --- a/tizen-audio.h +++ b/tizen-audio.h @@ -137,7 +137,7 @@ typedef struct audio_interface { /* Stream */ audio_return_t (*notify_stream_connection_changed)(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected); /* PCM */ - 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_open)(void *audio_handle, const char *card, const char *device, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **pcm_handle); 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); @@ -318,18 +318,20 @@ audio_return_t audio_notify_stream_connection_changed(void *audio_handle, audio_ * @brief Opens a PCM device. * @since_tizen 3.0 * @param[in] audio_handle The audio hal handle - * @param[out] pcm_handle The PCM handle + * @param[in] card The card of PCM + * @param[in] device The device of PCM * @param[in] direction The direction of PCM * @param[in] sample_spec The sample specification * @param[in] period_size The period size * @param[in] periods The periods + * @param[out] pcm_handle The PCM handle * * @return @c 0 on success, * otherwise a negative error value * @retval #AUDIO_RET_OK Success * @see audio_pcm_close() */ -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_open(void *audio_handle, const char *card, const char *device, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **pcm_handle); /** * @brief Starts a PCM device. -- 2.7.4 From c1ab82f1c74e9060446a13121ffd898342dd28e5 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Thu, 2 Aug 2018 10:31:59 +0900 Subject: [PATCH 08/16] Fix for hal unit test - Join vbc voice/voip thread properly on the exit. - Init/Deinit mutex control properly. [Version] 0.1.25 [Issue Type] BUG Change-Id: I3fad7b4590fb32ddeb30f3d5c1c2089b1d924ba6 --- packaging/audio-hal-sc7727.spec | 2 +- tizen-audio-ctrl.c | 45 +++++++++++++++++++++++++++++++++++++++++ tizen-audio-impl-ctrl.c | 6 +++--- tizen-audio-impl.h | 4 ++-- tizen-audio-internal.h | 2 ++ tizen-audio-modem.c | 12 +++++++++-- tizen-audio.c | 9 ++++++++- 7 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 tizen-audio-ctrl.c diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index cfbc7ad..7771611 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.24 +Version: 0.1.25 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-ctrl.c b/tizen-audio-ctrl.c new file mode 100644 index 0000000..561bd92 --- /dev/null +++ b/tizen-audio-ctrl.c @@ -0,0 +1,45 @@ +/* + * audio-hal + * + * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "tizen-audio-internal.h" + +audio_return_t _audio_ctrl_init(audio_hal_t *ah) +{ + audio_return_t audio_ret = AUDIO_RET_OK; + + AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); + + audio_ret = _mixer_control_init(ah); + + return audio_ret; +} + +audio_return_t _audio_ctrl_deinit(audio_hal_t *ah) +{ + audio_return_t audio_ret = AUDIO_RET_OK; + + AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); + + audio_ret = _mixer_control_deinit(ah); + + return audio_ret; +} diff --git a/tizen-audio-impl-ctrl.c b/tizen-audio-impl-ctrl.c index 253eaab..c52715a 100644 --- a/tizen-audio-impl-ctrl.c +++ b/tizen-audio-impl-ctrl.c @@ -47,7 +47,7 @@ static void __dump_mixer_param(char *dump, long *param, int size) } #endif -audio_return_t _control_init(audio_hal_t *ah) +audio_return_t _mixer_control_init(audio_hal_t *ah) { AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); @@ -55,7 +55,7 @@ audio_return_t _control_init(audio_hal_t *ah) return AUDIO_RET_OK; } -audio_return_t _control_deinit(audio_hal_t *ah) +audio_return_t _mixer_control_deinit(audio_hal_t *ah) { AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); @@ -248,4 +248,4 @@ audio_return_t _mixer_control_get_element(audio_hal_t *ah, const char *ctl_name, /* TODO. */ return AUDIO_RET_OK; -} \ No newline at end of file +} diff --git a/tizen-audio-impl.h b/tizen-audio-impl.h index 051eb84..c3f8e85 100644 --- a/tizen-audio-impl.h +++ b/tizen-audio-impl.h @@ -58,8 +58,8 @@ audio_return_t _pcm_set_hw_params(snd_pcm_t *pcm, audio_pcm_sample_spec_t *sampl #define MIXER_FMRADIO_L_VOLUME "VBC STR DG Set" #define MIXER_FMRADIO_R_VOLUME "VBC STL DG Set" #define MIXER_FMRADIO_MUTE "Digital FM Function" -audio_return_t _control_init(audio_hal_t *ah); -audio_return_t _control_deinit(audio_hal_t *ah); +audio_return_t _mixer_control_init(audio_hal_t *ah); +audio_return_t _mixer_control_deinit(audio_hal_t *ah); audio_return_t _mixer_control_set_param(audio_hal_t *ah, const char* ctl_name, snd_ctl_elem_value_t* value, int size); audio_return_t _mixer_control_set_value(audio_hal_t *ah, const char *ctl_name, int val); audio_return_t _mixer_control_set_value_string(audio_hal_t *ah, const char* ctl_name, const char* value); diff --git a/tizen-audio-internal.h b/tizen-audio-internal.h index 62d4646..8bd6f5a 100644 --- a/tizen-audio-internal.h +++ b/tizen-audio-internal.h @@ -318,6 +318,8 @@ typedef struct audio_hal { audio_hal_comm_t comm; } audio_hal_t; +audio_return_t _audio_ctrl_init(audio_hal_t *ah); +audio_return_t _audio_ctrl_deinit(audio_hal_t *ah); audio_return_t _audio_volume_init(audio_hal_t *ah); audio_return_t _audio_volume_deinit(audio_hal_t *ah); audio_return_t _audio_routing_init(audio_hal_t *ah); diff --git a/tizen-audio-modem.c b/tizen-audio-modem.c index 78651bc..54caf4c 100644 --- a/tizen-audio-modem.c +++ b/tizen-audio-modem.c @@ -669,12 +669,20 @@ static audio_return_t __vbc_control_open(audio_hal_t *ah) void __vbc_control_close(audio_hal_t *ah) { + int ret; /* TODO. Make sure we always receive CLOSE command from modem and then close pcm device */ ah->modem.vbc.exit_vbc_thread = 1; close(ah->modem.vbc.vbpipe_fd); - pthread_cancel(ah->modem.vbc.voice_thread_handle); - pthread_cancel(ah->modem.vbc.voip_thread_handle); + ret = pthread_cancel(ah->modem.vbc.voice_thread_handle); + AUDIO_LOG_INFO("cancel voice thread : %d", ret); + ret = pthread_cancel(ah->modem.vbc.voip_thread_handle); + AUDIO_LOG_INFO("cancel voip thread : %d", ret); + + ret = pthread_join(ah->modem.vbc.voice_thread_handle, NULL); + AUDIO_LOG_INFO("join voice thread : %d", ret); + ret = pthread_join(ah->modem.vbc.voip_thread_handle, NULL); + AUDIO_LOG_INFO("join voip thread : %d", ret); return; } diff --git a/tizen-audio.c b/tizen-audio.c index c7a3098..c61f063 100644 --- a/tizen-audio.c +++ b/tizen-audio.c @@ -34,6 +34,11 @@ audio_return_t audio_init(void **audio_handle) AUDIO_LOG_ERROR("failed to malloc()"); return AUDIO_ERR_RESOURCE; } + + if ((ret = _audio_ctrl_init(ah))) { + AUDIO_LOG_ERROR("failed to _audio_ctrl_init(), ret(0x%x)", ret); + goto error_exit; + } if ((ret = _audio_volume_init(ah))) { AUDIO_LOG_ERROR("failed to _audio_volume_init(), ret(0x%x)", ret); goto error_exit; @@ -81,8 +86,10 @@ audio_return_t audio_deinit(void *audio_handle) _audio_pcm_deinit(ah); _audio_modem_deinit(ah); _audio_comm_deinit(ah); + _audio_ctrl_deinit(ah); + free(ah); ah = NULL; return AUDIO_RET_OK; -} \ No newline at end of file +} -- 2.7.4 From 47a4be4f97030030ddd2592f650509970d97248b Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Tue, 7 Aug 2018 15:06:10 +0900 Subject: [PATCH 09/16] fixup! Fix for hal unit test Change-Id: Id7f0b2d5113fca6b6915590cb00cae765061a3fb --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index 089ad7a..822767a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,6 +8,7 @@ libtizen_audio_la_SOURCES = tizen-audio.c \ tizen-audio-modem.c \ tizen-audio-comm.c \ tizen-audio-util.c \ + tizen-audio-ctrl.c \ tizen-audio-impl-pcm.c \ tizen-audio-impl-ucm.c \ tizen-audio-impl-ctrl.c -- 2.7.4 From d571bdd9370e8fbbc9b5177cd0cc54b4059b98bc Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Fri, 24 Aug 2018 16:56:33 +0900 Subject: [PATCH 10/16] Fix condition check macro to support multiple expression. - open temp volume ini if file exists only (to avoid unnecessary stdout error) [Version] 0.1.26 [Issue Type] BUG Change-Id: I70a35e2345a7078aa9a1552967187240c6f2101e --- packaging/audio-hal-sc7727.spec | 2 +- tizen-audio-internal.h | 6 +++--- tizen-audio-volume.c | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index 7771611..21bc0d3 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.25 +Version: 0.1.26 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-internal.h b/tizen-audio-internal.h index 8bd6f5a..f4b3ff2 100644 --- a/tizen-audio-internal.h +++ b/tizen-audio-internal.h @@ -59,19 +59,19 @@ #endif #define AUDIO_RETURN_IF_FAIL(expr) do { \ - if (!expr) { \ + if (!(expr)) { \ AUDIO_LOG_ERROR("%s failed", #expr); \ return; \ } \ } while (0) #define AUDIO_RETURN_VAL_IF_FAIL(expr, val) do { \ - if (!expr) { \ + if (!(expr)) { \ AUDIO_LOG_ERROR("%s failed", #expr); \ return val; \ } \ } while (0) #define AUDIO_RETURN_NULL_IF_FAIL(expr) do { \ - if (!expr) { \ + if (!(expr)) { \ AUDIO_LOG_ERROR("%s failed", #expr); \ return NULL; \ } \ diff --git a/tizen-audio-volume.c b/tizen-audio-volume.c index a4d3950..12492c7 100644 --- a/tizen-audio-volume.c +++ b/tizen-audio-volume.c @@ -188,7 +188,8 @@ static audio_return_t __load_volume_value_table_from_ini(audio_hal_t *ah) audio_volume_value_table_t *volume_value_table = ah->volume.volume_value_table; int size = 0; - dict = iniparser_load(VOLUME_INI_TEMP_PATH); + if (access(VOLUME_INI_TEMP_PATH, F_OK) == 0) + dict = iniparser_load(VOLUME_INI_TEMP_PATH); if (!dict) { AUDIO_LOG_DEBUG("Use default volume&gain ini file"); dict = iniparser_load(VOLUME_INI_DEFAULT_PATH); -- 2.7.4 From 3a0323a6fea77f5f48b44693e58618cd6935ede6 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Tue, 4 Sep 2018 17:30:01 +0900 Subject: [PATCH 11/16] Remove build warnings [Version] 0.1.27 [Issue Type] Revise Change-Id: Icdeb6362c9782fa3ce0f02a05f140f7165e2ff68 --- packaging/audio-hal-sc7727.spec | 2 +- tizen-audio-ctrl.c | 7 ++++--- tizen-audio-impl-pcm.c | 2 +- tizen-audio-impl-ucm.c | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index 21bc0d3..270f2af 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.26 +Version: 0.1.27 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-ctrl.c b/tizen-audio-ctrl.c index 561bd92..2b9bacd 100644 --- a/tizen-audio-ctrl.c +++ b/tizen-audio-ctrl.c @@ -1,7 +1,7 @@ /* * audio-hal * - * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ #endif #include "tizen-audio-internal.h" +#include "tizen-audio-impl.h" audio_return_t _audio_ctrl_init(audio_hal_t *ah) { @@ -28,7 +29,7 @@ audio_return_t _audio_ctrl_init(audio_hal_t *ah) AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); - audio_ret = _mixer_control_init(ah); + audio_ret = _mixer_control_init(ah); return audio_ret; } @@ -39,7 +40,7 @@ audio_return_t _audio_ctrl_deinit(audio_hal_t *ah) AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); - audio_ret = _mixer_control_deinit(ah); + audio_ret = _mixer_control_deinit(ah); return audio_ret; } diff --git a/tizen-audio-impl-pcm.c b/tizen-audio-impl-pcm.c index 0c1304c..e809bab 100644 --- a/tizen-audio-impl-pcm.c +++ b/tizen-audio-impl-pcm.c @@ -465,7 +465,7 @@ audio_return_t _pcm_close(void *pcm_handle) { int err; - AUDIO_LOG_INFO("Try to close PCM handle 0x%x", pcm_handle); + AUDIO_LOG_INFO("Try to close PCM handle %p", pcm_handle); #ifdef __USE_TINYALSA__ if ((err = pcm_close(pcm_handle)) < 0) { diff --git a/tizen-audio-impl-ucm.c b/tizen-audio-impl-ucm.c index a15128f..aa574d7 100644 --- a/tizen-audio-impl-ucm.c +++ b/tizen-audio-impl-ucm.c @@ -397,8 +397,9 @@ audio_return_t _ucm_set_devices(audio_hal_t *ah, const char *verb, const char *d break; } } - } else + } else { for (dev_count = 0; devices[dev_count]; dev_count++); + } } __dump_use_case(UCM_PREFIX_REQUESTED, verb, devices, dev_count, NULL, 0); -- 2.7.4 From 45d19b200968587aac853e9af30f370009e7d6cb Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Fri, 14 Dec 2018 15:10:45 +0900 Subject: [PATCH 12/16] Fix invalid format string [Version] 0.1.28 [Issue Type] Build Change-Id: I08f58b4a889a0c2d8ce01c7e21ae51cc352d92a4 --- packaging/audio-hal-sc7727.spec | 2 +- tizen-audio-impl-pcm.c | 27 +++++++++++++++------------ tizen-audio-pcm.c | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index 270f2af..8fc978a 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.27 +Version: 0.1.28 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-impl-pcm.c b/tizen-audio-impl-pcm.c index e809bab..1385f36 100644 --- a/tizen-audio-impl-pcm.c +++ b/tizen-audio-impl-pcm.c @@ -437,7 +437,7 @@ audio_return_t _pcm_start(void *pcm_handle) } #endif - AUDIO_LOG_INFO("PCM handle 0x%x start", pcm_handle); + AUDIO_LOG_INFO("PCM handle %p start", pcm_handle); return AUDIO_RET_OK; } @@ -457,7 +457,7 @@ audio_return_t _pcm_stop(void *pcm_handle) } #endif - AUDIO_LOG_INFO("PCM handle 0x%x stop", pcm_handle); + AUDIO_LOG_INFO("PCM handle %p stop", pcm_handle); return AUDIO_RET_OK; } @@ -491,7 +491,7 @@ audio_return_t _pcm_avail(void *pcm_handle, uint32_t *avail) err = pcm_get_htimestamp(pcm_handle, &frames_avail, &tspec); if (err < 0) { - AUDIO_LOG_ERROR("Could not get avail and timespec at PCM handle 0x%x : %d", pcm_handle, err); + AUDIO_LOG_ERROR("Could not get avail and timespec at PCM handle %p : %d", pcm_handle, err); return AUDIO_ERR_IOCTL; } @@ -504,7 +504,7 @@ audio_return_t _pcm_avail(void *pcm_handle, uint32_t *avail) snd_pcm_sframes_t frames_avail; if ((frames_avail = snd_pcm_avail(pcm_handle)) < 0) { - AUDIO_LOG_ERROR("Could not get avail at PCM handle 0x%x : %d", pcm_handle, frames_avail); + AUDIO_LOG_ERROR("Could not get avail at PCM handle %p : %ld", pcm_handle, frames_avail); return AUDIO_ERR_IOCTL; } @@ -539,7 +539,7 @@ audio_return_t _pcm_write(void *pcm_handle, const void *buffer, uint32_t frames) frames_written = snd_pcm_writei(pcm_handle, buffer, (snd_pcm_uframes_t) frames); if (frames_written < 0) { - AUDIO_LOG_ERROR("Failed to write pcm : %d", frames_written); + AUDIO_LOG_ERROR("Failed to write pcm : %ld", frames_written); return AUDIO_ERR_IOCTL; } @@ -570,7 +570,7 @@ audio_return_t _pcm_read(void *pcm_handle, void *buffer, uint32_t frames) frames_read = snd_pcm_readi(pcm_handle, buffer, (snd_pcm_uframes_t)frames); if (frames_read < 0) { - AUDIO_LOG_ERROR("Failed to read pcm : %d", frames_read); + AUDIO_LOG_ERROR("Failed to read pcm : %ld", frames_read); return AUDIO_ERR_IOCTL; } @@ -696,7 +696,8 @@ audio_return_t _pcm_get_params(void *pcm_handle, uint32_t direction, void **samp _stop_threshold = config->stop_threshold; _silence_threshold = config->silence_threshold; - AUDIO_LOG_DEBUG("_pcm_get_params (handle 0x%x, format %d, rate %d, channels %d, period_size %d, periods %d, buffer_size %d)", pcm_handle, config->format, config->rate, config->channels, config->period_size, config->period_count, _buffer_size); + AUDIO_LOG_DEBUG("_pcm_get_params (handle %p, format %d, rate %u, channels %u, period_size %u, periods %u, buffer_size %u)", + pcm_handle, config->format, config->rate, config->channels, config->period_size, config->period_count, _buffer_size); #else /* alsa-lib */ int err; audio_pcm_sample_spec_t *ss; @@ -725,7 +726,7 @@ audio_return_t _pcm_get_params(void *pcm_handle, uint32_t direction, void **samp (err = snd_pcm_hw_params_get_format(hwparams, &_format)) < 0 || (err = snd_pcm_hw_params_get_rate(hwparams, &_rate, &dir)) < 0 || (err = snd_pcm_hw_params_get_channels(hwparams, &_channels)) < 0) { - AUDIO_LOG_ERROR("snd_pcm_hw_params_get_{period_size|buffer_size|periods|format|rate|channels}() failed : %s", err); + AUDIO_LOG_ERROR("snd_pcm_hw_params_get_{period_size|buffer_size|periods|format|rate|channels}() failed : %d", err); return AUDIO_ERR_PARAMETER; } @@ -744,10 +745,11 @@ audio_return_t _pcm_get_params(void *pcm_handle, uint32_t direction, void **samp (err = snd_pcm_sw_params_get_stop_threshold(swparams, &_stop_threshold)) < 0 || (err = snd_pcm_sw_params_get_silence_threshold(swparams, &_silence_threshold)) < 0 || (err = snd_pcm_sw_params_get_avail_min(swparams, &_avail_min)) < 0) { - AUDIO_LOG_ERROR("snd_pcm_sw_params_get_{start_threshold|stop_threshold|silence_threshold|avail_min}() failed : %s", err); + AUDIO_LOG_ERROR("snd_pcm_sw_params_get_{start_threshold|stop_threshold|silence_threshold|avail_min}() failed : %d", err); } - AUDIO_LOG_DEBUG("_pcm_get_params (handle 0x%x, format %d, rate %d, channels %d, period_size %d, periods %d, buffer_size %d)", pcm_handle, _format, _rate, _channels, _period_size, _periods, _buffer_size); + AUDIO_LOG_DEBUG("_pcm_get_params (handle %p, format %d, rate %u, channels %u, period_size %lu, periods %u, buffer_size %lu)", + pcm_handle, _format, _rate, _channels, _period_size, _periods, _buffer_size); #endif return AUDIO_RET_OK; @@ -814,7 +816,7 @@ audio_return_t _pcm_set_params(void *pcm_handle, uint32_t direction, void *sampl _buffer_size = period_size * periods; if ((err = snd_pcm_hw_params_set_buffer_size(pcm_handle, hwparams, _buffer_size)) < 0) { - AUDIO_LOG_ERROR("snd_pcm_hw_params_set_buffer_size(%u) failed : %d", _buffer_size, err); + AUDIO_LOG_ERROR("snd_pcm_hw_params_set_buffer_size(%lu) failed : %d", _buffer_size, err); return AUDIO_ERR_PARAMETER; } @@ -860,7 +862,8 @@ audio_return_t _pcm_set_params(void *pcm_handle, uint32_t direction, void *sampl return AUDIO_ERR_IOCTL; } - AUDIO_LOG_DEBUG("_pcm_set_params (handle 0x%x, format %d, rate %d, channels %d, period_size %d, periods %d, buffer_size %d)", pcm_handle, ss.format, ss.rate, ss.channels, period_size, periods, _buffer_size); + AUDIO_LOG_DEBUG("_pcm_set_params (handle %p, format %d, rate %u, channels %u, period_size %u, periods %u, buffer_size %lu)", + pcm_handle, ss.format, ss.rate, ss.channels, period_size, periods, _buffer_size); #endif return AUDIO_RET_OK; diff --git a/tizen-audio-pcm.c b/tizen-audio-pcm.c index e11f8cc..ee836f1 100644 --- a/tizen-audio-pcm.c +++ b/tizen-audio-pcm.c @@ -67,7 +67,7 @@ audio_return_t audio_pcm_open(void *audio_handle, const char *card, const char * ah = (audio_hal_t*)audio_handle; ah->device.pcm_count++; - AUDIO_LOG_INFO("Opening PCM handle 0x%x", (unsigned int)*pcm_handle); + AUDIO_LOG_INFO("Opening PCM handle %p", *pcm_handle); return AUDIO_RET_OK; } -- 2.7.4 From 0786984f147fa2c41c6c55e7f9edc0339d634aaf Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Wed, 17 Apr 2019 11:37:13 +0900 Subject: [PATCH 13/16] Add new API - audio_set_volume_ratio This new API is to set the individual volume ratio of each stream. The parameters of this API consist of stream role, direction, index and its ratio. Because the stream role can differ among the streams which have same volume type, this new API could be used where the H/W volume has to be set for a specific stream role with distinguishing it from others. [Version] 0.1.29 [Issue Type] New API Change-Id: Id2d35aaef4a6db489e8fb27cb6c4affe10b81dd4 Signed-off-by: Sangchul Lee --- packaging/audio-hal-sc7727.spec | 2 +- tizen-audio-volume.c | 13 +++++++++++++ tizen-audio.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index 8fc978a..3eaddec 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.28 +Version: 0.1.29 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-volume.c b/tizen-audio-volume.c index 12492c7..9fca5cc 100644 --- a/tizen-audio-volume.c +++ b/tizen-audio-volume.c @@ -562,3 +562,16 @@ audio_return_t audio_set_volume_mute(void *audio_handle, audio_volume_info_t *in return audio_ret; } + +audio_return_t audio_set_volume_ratio(void *audio_handle, audio_stream_info_t *info, double ratio) +{ + audio_return_t audio_ret = AUDIO_RET_OK; + audio_hal_t *ah = (audio_hal_t *)audio_handle; + + AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(info, AUDIO_ERR_PARAMETER); + + AUDIO_LOG_INFO("set [%s] volume_ratio: %f, direction(%u), index(%u)", info->role, ratio, info->direction, info->idx); + + return audio_ret; +} \ No newline at end of file diff --git a/tizen-audio.h b/tizen-audio.h index 94efa03..f18afa4 100644 --- a/tizen-audio.h +++ b/tizen-audio.h @@ -131,6 +131,7 @@ typedef struct audio_interface { 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 (*set_volume_ratio)(void *audio_handle, audio_stream_info_t *info, double ratio); /* Routing */ audio_return_t (*update_route)(void *audio_handle, audio_route_info_t *info); audio_return_t (*update_route_option)(void *audio_handle, audio_route_option_t *option); -- 2.7.4 From 958c83f2a5ef336e54285f332c58720eaff714ba Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Thu, 11 Jul 2019 10:28:55 +0900 Subject: [PATCH 14/16] Add support for radio volume The operation of radio volume is moved from radio HAL. [Version] 0.1.30 [Issue Type] Improvement Change-Id: Ie35ca5cfb9c56a4130d9db5e03e1b108822b2982 Signed-off-by: Sangchul Lee --- packaging/audio-hal-sc7727.spec | 2 +- tizen-audio-impl.h | 2 + tizen-audio-internal.h | 2 +- tizen-audio-volume.c | 90 ++++++++++++++++++++++++----------------- 4 files changed, 56 insertions(+), 40 deletions(-) diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index 3eaddec..ffa9242 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.29 +Version: 0.1.30 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-impl.h b/tizen-audio-impl.h index c3f8e85..b1879b2 100644 --- a/tizen-audio-impl.h +++ b/tizen-audio-impl.h @@ -58,6 +58,8 @@ audio_return_t _pcm_set_hw_params(snd_pcm_t *pcm, audio_pcm_sample_spec_t *sampl #define MIXER_FMRADIO_L_VOLUME "VBC STR DG Set" #define MIXER_FMRADIO_R_VOLUME "VBC STL DG Set" #define MIXER_FMRADIO_MUTE "Digital FM Function" +#define FMRADIO_MUTE_ON 0 +#define FMRADIO_MUTE_OFF 1 audio_return_t _mixer_control_init(audio_hal_t *ah); audio_return_t _mixer_control_deinit(audio_hal_t *ah); audio_return_t _mixer_control_set_param(audio_hal_t *ah, const char* ctl_name, snd_ctl_elem_value_t* value, int size); diff --git a/tizen-audio-internal.h b/tizen-audio-internal.h index f4b3ff2..1d595a6 100644 --- a/tizen-audio-internal.h +++ b/tizen-audio-internal.h @@ -241,6 +241,7 @@ typedef struct audio_hal_volume { uint32_t volume_level[AUDIO_VOLUME_TYPE_MAX]; audio_volume_value_table_t *volume_value_table; int32_t radio_volume_value_table[RADIO_VOLUME_LEVEL_MAX]; + int32_t radio_volume_num_of_levels; } audio_hal_volume_t; /* UCM */ @@ -336,7 +337,6 @@ audio_return_t _audio_comm_deinit(audio_hal_t *ah); audio_return_t _audio_update_route_voicecall(audio_hal_t *ah, device_info_t *devices, int32_t num_of_devices); int _audio_modem_is_call_connected(audio_hal_t *ah); audio_return_t _audio_comm_send_message(audio_hal_t *ah, const char *name, int value); -audio_return_t _audio_volume_set_level_radio(audio_hal_t *ah, uint32_t level); typedef struct _dump_data { char *strbuf; diff --git a/tizen-audio-volume.c b/tizen-audio-volume.c index 9fca5cc..97e445c 100644 --- a/tizen-audio-volume.c +++ b/tizen-audio-volume.c @@ -339,49 +339,63 @@ error: return ret; } -audio_return_t _audio_volume_set_level_radio(audio_hal_t *ah, uint32_t level) +static audio_return_t _audio_volume_set_ratio_radio(audio_hal_t *ah, double ratio) { audio_return_t audio_ret = AUDIO_RET_OK; - int volume = 0; + int new_value = 0; + int prev_value = -1; int mute = -1; + int max_value; + int min_value; AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); /* Applying mute at volume zero */ - if (level == 0) { - if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_MUTE, 0))) - AUDIO_LOG_ERROR("set mixer(%s) failed", MIXER_FMRADIO_MUTE); + if (ratio == 0) { + if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_MUTE, FMRADIO_MUTE_ON))) { + AUDIO_LOG_ERROR("[mute on] set mixer(%s) failed", MIXER_FMRADIO_MUTE); + return AUDIO_ERR_INTERNAL; + } + new_value = 0; + goto set_volume; + } - } else { - if ((audio_ret = _mixer_control_get_value(ah, MIXER_FMRADIO_MUTE, &mute))) { - AUDIO_LOG_ERROR("get mixer(%s) failed", MIXER_FMRADIO_MUTE); + /* Unmute if muted */ + if ((audio_ret = _mixer_control_get_value(ah, MIXER_FMRADIO_MUTE, &mute))) { + AUDIO_LOG_ERROR("[mute get] get mixer(%s) failed", MIXER_FMRADIO_MUTE); + return audio_ret; + } + if (mute == FMRADIO_MUTE_ON) { + if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_MUTE, FMRADIO_MUTE_OFF))) { + AUDIO_LOG_ERROR("[mute off] set mixer(%s) failed", MIXER_FMRADIO_MUTE); return audio_ret; } - if (mute == 0) { - if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_MUTE, 1))) { - AUDIO_LOG_ERROR("set mixer(%s) failed", MIXER_FMRADIO_MUTE); - return audio_ret; - } - } } - if ((_mixer_control_get_value(ah, MIXER_FMRADIO_L_VOLUME, &volume))) - AUDIO_LOG_ERROR("get mixer(%s) failed", MIXER_FMRADIO_L_VOLUME); - else { - if (volume != ah->volume.radio_volume_value_table[level]) { - if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_L_VOLUME, ah->volume.radio_volume_value_table[level]))) { - AUDIO_LOG_ERROR("set mixer(%s) failed", MIXER_FMRADIO_L_VOLUME); - return audio_ret; - } + max_value = ah->volume.radio_volume_value_table[ah->volume.radio_volume_num_of_levels - 1]; + min_value = ah->volume.radio_volume_value_table[0]; + new_value = (int) (ratio * (max_value - min_value) + min_value); + +set_volume: + /* Left volume */ + if ((_mixer_control_get_value(ah, MIXER_FMRADIO_L_VOLUME, &prev_value))) + AUDIO_LOG_ERROR("[volume get] get mixer(%s) failed", MIXER_FMRADIO_L_VOLUME); + if (new_value != prev_value) { + AUDIO_LOG_INFO("[volume set] set mixer(%s), %d", MIXER_FMRADIO_L_VOLUME, new_value); + if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_L_VOLUME, new_value))) { + AUDIO_LOG_ERROR("[volume set] set mixer(%s) failed", MIXER_FMRADIO_L_VOLUME); + return audio_ret; } } - if ((_mixer_control_get_value(ah, MIXER_FMRADIO_R_VOLUME, &volume))) - AUDIO_LOG_ERROR("get mixer(%s) failed", MIXER_FMRADIO_R_VOLUME); - else { - if (volume != ah->volume.radio_volume_value_table[level]) { - if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_R_VOLUME, ah->volume.radio_volume_value_table[level]))) - AUDIO_LOG_ERROR("set mixer(%s) failed", MIXER_FMRADIO_R_VOLUME); + /* Right volume */ + if ((_mixer_control_get_value(ah, MIXER_FMRADIO_R_VOLUME, &prev_value))) + AUDIO_LOG_ERROR("[volume get] get mixer(%s) failed", MIXER_FMRADIO_R_VOLUME); + if (new_value != prev_value) { + AUDIO_LOG_INFO("[volume set] set mixer(%s), %d", MIXER_FMRADIO_R_VOLUME, new_value); + if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_R_VOLUME, new_value))) { + AUDIO_LOG_ERROR("[volume set] set mixer(%s) failed", MIXER_FMRADIO_R_VOLUME); + return audio_ret; } } @@ -395,7 +409,6 @@ audio_return_t _audio_volume_init(audio_hal_t *ah) audio_return_t audio_ret = AUDIO_RET_OK; int init_value[AUDIO_VOLUME_TYPE_MAX] = { 9, 11, 7, 11, 7, 4, 4, 7 }; int* fm_table = NULL; - int number_of_steps = 0; AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); @@ -426,13 +439,13 @@ audio_return_t _audio_volume_init(audio_hal_t *ah) } /* radio volume table */ - __load_radio_volume_table(&fm_table, &number_of_steps); + __load_radio_volume_table(&fm_table, &ah->volume.radio_volume_num_of_levels); if (fm_table) { - AUDIO_LOG_DEBUG("number of steps -> %d", number_of_steps); + AUDIO_LOG_DEBUG("number of levels -> %d", ah->volume.radio_volume_num_of_levels); /*copy from temp structure to main strcture*/ - for (i = 0; i < number_of_steps; i++) { + for (i = 0; i < ah->volume.radio_volume_num_of_levels; i++) ah->volume.radio_volume_value_table[i] = fm_table[i]; - } + free(fm_table); fm_table = NULL; } @@ -529,10 +542,6 @@ audio_return_t audio_set_volume_level(void *audio_handle, audio_volume_info_t *i 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 */ - if ((__get_volume_idx_by_string_type(info->type) == AUDIO_VOLUME_TYPE_MEDIA) && ah->device.is_radio_on) - audio_ret = _audio_volume_set_level_radio(ah, level); - return audio_ret; } @@ -573,5 +582,10 @@ audio_return_t audio_set_volume_ratio(void *audio_handle, audio_stream_info_t *i AUDIO_LOG_INFO("set [%s] volume_ratio: %f, direction(%u), index(%u)", info->role, ratio, info->direction, info->idx); + if (!strncmp(info->role, "radio", strlen(info->role))) { + AUDIO_LOG_INFO("set radio volume according to the ratio[%f]", ratio); + audio_ret = _audio_volume_set_ratio_radio(ah, ratio); + } + return audio_ret; -} \ No newline at end of file +} -- 2.7.4 From c48d8ac46662c7eb4a24813da5302a5f4112e6da Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Thu, 18 Jul 2019 13:06:22 +0900 Subject: [PATCH 15/16] Fix noise when unmuting radio volume [Version] 0.1.31 [Issue Type] Improvement Change-Id: I8b8063986c3e17d812afcf654c099967ec70919a Signed-off-by: Sangchul Lee --- packaging/audio-hal-sc7727.spec | 2 +- tizen-audio-volume.c | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index ffa9242..a575d74 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.30 +Version: 0.1.31 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-volume.c b/tizen-audio-volume.c index 97e445c..8dd03f1 100644 --- a/tizen-audio-volume.c +++ b/tizen-audio-volume.c @@ -360,18 +360,6 @@ static audio_return_t _audio_volume_set_ratio_radio(audio_hal_t *ah, double rati goto set_volume; } - /* Unmute if muted */ - if ((audio_ret = _mixer_control_get_value(ah, MIXER_FMRADIO_MUTE, &mute))) { - AUDIO_LOG_ERROR("[mute get] get mixer(%s) failed", MIXER_FMRADIO_MUTE); - return audio_ret; - } - if (mute == FMRADIO_MUTE_ON) { - if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_MUTE, FMRADIO_MUTE_OFF))) { - AUDIO_LOG_ERROR("[mute off] set mixer(%s) failed", MIXER_FMRADIO_MUTE); - return audio_ret; - } - } - max_value = ah->volume.radio_volume_value_table[ah->volume.radio_volume_num_of_levels - 1]; min_value = ah->volume.radio_volume_value_table[0]; new_value = (int) (ratio * (max_value - min_value) + min_value); @@ -399,6 +387,21 @@ set_volume: } } + if (ratio == 0) + return audio_ret; + + /* Unmute if muted */ + if ((audio_ret = _mixer_control_get_value(ah, MIXER_FMRADIO_MUTE, &mute))) { + AUDIO_LOG_ERROR("[mute get] get mixer(%s) failed", MIXER_FMRADIO_MUTE); + return audio_ret; + } + if (mute == FMRADIO_MUTE_ON) { + if ((audio_ret = _mixer_control_set_value(ah, MIXER_FMRADIO_MUTE, FMRADIO_MUTE_OFF))) { + AUDIO_LOG_ERROR("[mute off] set mixer(%s) failed", MIXER_FMRADIO_MUTE); + return audio_ret; + } + } + return audio_ret; } -- 2.7.4 From 03b339411a0dcec99091e7ad772544b2732e1e38 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Thu, 9 Jul 2020 17:09:14 +0900 Subject: [PATCH 16/16] tizen-audio-routing: Initialize value to avoid a crash There was a call related case dereferencing this value without initializing it in __reset_voice_devices_info(). [Version] 0.1.32 [Issue Type] Improvement Change-Id: I1c6ea3448d072501985ec6c8287efc316bc62cbf Signed-off-by: Sangchul Lee --- packaging/audio-hal-sc7727.spec | 2 +- tizen-audio-routing.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index a575d74..7a84689 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.31 +Version: 0.1.32 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-routing.c b/tizen-audio-routing.c index a9e8e47..54ebdbf 100644 --- a/tizen-audio-routing.c +++ b/tizen-audio-routing.c @@ -375,6 +375,8 @@ audio_return_t _audio_routing_init(audio_hal_t *ah) ah->device.active_out = 0x0; ah->device.mode = VERB_NORMAL; ah->device.is_radio_on = 0; + ah->device.init_call_devices = NULL; + ah->device.num_of_call_devices = 0; if ((audio_ret = _ucm_init(ah))) AUDIO_LOG_ERROR("failed to _ucm_init(), ret(0x%x)", audio_ret); -- 2.7.4