summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJungsup Lee <jungsup4.lee@samsung.com>2018-06-26 14:38:32 +0900
committerSangchul Lee <sc11.lee@samsung.com>2018-07-20 15:27:42 +0900
commitee7289bb97278beed335c2bd454f18ba08e96555 (patch)
tree8aa39f185b007ac6527d0c1b6e8f8a3a0cc94919
parent36f95bfad9876c321c648c16568601d0d5f9ea73 (diff)
downloadaudio-hal-wm1831-tw2-ee7289bb97278beed335c2bd454f18ba08e96555.tar.gz
audio-hal-wm1831-tw2-ee7289bb97278beed335c2bd454f18ba08e96555.tar.bz2
audio-hal-wm1831-tw2-ee7289bb97278beed335c2bd454f18ba08e96555.zip
Card and device arguments are added to pcm open APIsubmit/tizen/20180724.034640accepted/tizen/unified/20180726.064854
[Version] 0.1.8 [Issue Type] API Change-Id: Ia1ba2a63b3aa3212e756debf548611046ebb9495 Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
-rw-r--r--packaging/audio-hal-wm1831-tw2.spec2
-rw-r--r--tizen-audio-impl-pcm.c85
-rw-r--r--tizen-audio-impl.h2
-rw-r--r--tizen-audio-internal.h10
-rw-r--r--tizen-audio-pcm.c9
-rw-r--r--tizen-audio.h8
6 files changed, 73 insertions, 43 deletions
diff --git a/packaging/audio-hal-wm1831-tw2.spec b/packaging/audio-hal-wm1831-tw2.spec
index ffb7a5a..b4db7b8 100644
--- a/packaging/audio-hal-wm1831-tw2.spec
+++ b/packaging/audio-hal-wm1831-tw2.spec
@@ -1,6 +1,6 @@
Name: audio-hal-wm1831-tw2
Summary: TIZEN Audio HAL for WM1831(TW2)
-Version: 0.1.7
+Version: 0.1.8
Release: 0
Group: System/Libraries
License: Apache-2.0
diff --git a/tizen-audio-impl-pcm.c b/tizen-audio-impl-pcm.c
index 0713e85..e661aa9 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[] = {
@@ -134,11 +138,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;
@@ -150,12 +170,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);
@@ -352,16 +375,37 @@ void _reset_pcm_devices(audio_hal_t *ah)
_bt_pcm_close_all(ah);
}
-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;
@@ -372,28 +416,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);
@@ -795,7 +832,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 b744ef0..99e738c 100644
--- a/tizen-audio-impl.h
+++ b/tizen-audio-impl.h
@@ -30,7 +30,7 @@ audio_return_t _bt_pcm_close_all(audio_hal_t *ah);
bool _is_voice_pcm_opened_all(audio_hal_t *ah);
bool _is_bt_pcm_opened_all(audio_hal_t *ah);
void _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 862ba5c..c1e8de0 100644
--- a/tizen-audio-internal.h
+++ b/tizen-audio-internal.h
@@ -156,21 +156,11 @@ typedef struct device_type {
#define strneq strcmp
#define ALSA_DEFAULT_CARD "universal7270la"
-#define PLAYBACK_PCM_DEVICE "hw:0,0"
-#define CAPTURE_PCM_DEVICE "hw:0,0"
/* DAI PCM DEVICE */
#define VOICE_PCM_DEVICE "hw:0,1"
#define BT_PCM_DEVICE "hw:0,2"
-/* 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_NAME_LEN 32
diff --git a/tizen-audio-pcm.c b/tizen-audio-pcm.c
index 89ca482..16b72d4 100644
--- a/tizen-audio-pcm.c
+++ b/tizen-audio-pcm.c
@@ -43,7 +43,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;
@@ -53,10 +54,10 @@ 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;
- 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;
}
@@ -192,4 +193,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 282f7f0..d752d89 100644
--- a/tizen-audio.h
+++ b/tizen-audio.h
@@ -125,7 +125,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);
@@ -303,18 +303,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.