diff options
author | Jungsup Lee <jungsup4.lee@samsung.com> | 2018-06-26 14:38:32 +0900 |
---|---|---|
committer | Sangchul Lee <sc11.lee@samsung.com> | 2018-07-20 15:21:59 +0900 |
commit | 2f3a2412f93097091e156227e9dc38fb34e38816 (patch) | |
tree | 3b763675e503c73e92ee9d094c37351e2a7da072 | |
parent | 945d7c11d453a93b108ff068a45e90b5b259e03b (diff) | |
download | audio-hal-max98090-2f3a2412f93097091e156227e9dc38fb34e38816.tar.gz audio-hal-max98090-2f3a2412f93097091e156227e9dc38fb34e38816.tar.bz2 audio-hal-max98090-2f3a2412f93097091e156227e9dc38fb34e38816.zip |
Card and device arguments are added to pcm open APIsubmit/tizen/20180724.034640accepted/tizen/unified/20180726.064859
[Version] 0.2.25
[Issue Type] API
Change-Id: Ia1ba2a63b3aa3212e756debf548611046ebb9495
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
-rw-r--r-- | packaging/audio-hal-max98090.spec | 2 | ||||
-rw-r--r-- | tizen-audio-impl-pcm.c | 85 | ||||
-rw-r--r-- | tizen-audio-impl.h | 2 | ||||
-rw-r--r-- | tizen-audio-internal.h | 10 | ||||
-rw-r--r-- | tizen-audio-pcm.c | 9 | ||||
-rw-r--r-- | tizen-audio.h | 8 |
6 files changed, 73 insertions, 43 deletions
diff --git a/packaging/audio-hal-max98090.spec b/packaging/audio-hal-max98090.spec index e666118..1489670 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.24 +Version: 0.2.25 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-impl-pcm.c b/tizen-audio-impl-pcm.c index 57229c8..d5808d8 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[] = { @@ -64,11 +68,27 @@ static uint32_t __convert_format(audio_sample_format_t format) } #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; @@ -80,12 +100,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); @@ -119,16 +142,37 @@ static int __tinyalsa_pcm_recover(struct pcm *pcm, int err) } #endif -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; @@ -139,28 +183,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); @@ -562,7 +599,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 4287ac8..b7ece02 100644 --- a/tizen-audio-impl.h +++ b/tizen-audio-impl.h @@ -21,7 +21,7 @@ */ /* PCM */ -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 a43c39d..7535997 100644 --- a/tizen-audio-internal.h +++ b/tizen-audio-internal.h @@ -124,16 +124,6 @@ typedef struct device_type { #define strneq strcmp #define ALSA_DEFAULT_CARD "max98090" -#define PLAYBACK_PCM_DEVICE "hw:0,0" -#define CAPTURE_PCM_DEVICE "hw:0,0" - -/* hw:0,0 */ -#define PLAYBACK_CARD_ID 0 -#define PLAYBACK_PCM_DEVICE_ID 0 - -/* hw:0,0 */ -#define CAPTURE_CARD_ID 0 -#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 0a09cba..b18ad7e 100644 --- a/tizen-audio-pcm.c +++ b/tizen-audio-pcm.c @@ -45,7 +45,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; @@ -56,12 +57,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; } @@ -200,4 +201,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. |