From d73c2ca10ae92822b9d38f4592be73d2cf9b325f Mon Sep 17 00:00:00 2001 From: Jaechul Lee Date: Thu, 7 Sep 2023 16:45:41 +0900 Subject: [PATCH] Support various types of interfaces It supports various types of interfaces like file, audio-share, and pipe. And it works well on both tizen2-sink/source and tizen-sink/source. * Added a glue layer. * Added file interfaces. [Version] 0.1.20 [Issue Type] Update Change-Id: I2ee734e4bcd56d9553ff98435b47a1b464ed2a11 Signed-off-by: Jaechul Lee --- Makefile.am | 5 +- hal-backend-audio.c | 23 +-- packaging/audio-hal-emul.spec | 2 +- tizen-audio-file.c | 198 ++++++++++++++++++++++++++ tizen-audio-file.h | 35 +++++ tizen-audio-glue.c | 259 ++++++++++++++++++++++++++++++++++ tizen-audio-glue.h | 14 ++ tizen-audio-internal.h | 1 - tizen-audio-pcm.c | 42 ++---- tizen-audio.h | 22 +-- 10 files changed, 546 insertions(+), 55 deletions(-) create mode 100644 tizen-audio-file.c create mode 100644 tizen-audio-file.h create mode 100644 tizen-audio-glue.c create mode 100644 tizen-audio-glue.h diff --git a/Makefile.am b/Makefile.am index 6457672..170ee43 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,8 @@ lib_LTLIBRARIES = libhal-backend-audio.la libhal_backend_audio_la_SOURCES = tizen-audio.c \ + tizen-audio-glue.c \ + tizen-audio-file.c \ tizen-audio-volume.c \ tizen-audio-routing.c \ tizen-audio-stream.c \ @@ -18,4 +20,5 @@ libhal_backend_audio_la_CFLAGS = $(AM_CFLAGS) $(ASOUNDLIB_CFLAGS) $(VCONF_CFLAGS if USE_TINYALSA libhal_backend_audio_la_LIBADD += $(TINYALSA_LIBS) libhal_backend_audio_la_CFLAGS += $(TINYALSA_CFLAGS) -D__USE_TINYALSA__ -endif \ No newline at end of file +endif + diff --git a/hal-backend-audio.c b/hal-backend-audio.c index 5048b7b..9edf847 100644 --- a/hal-backend-audio.c +++ b/hal-backend-audio.c @@ -22,6 +22,7 @@ #include #include #include +#include #include static int audio_emul_init(void **data) @@ -49,17 +50,17 @@ static int audio_emul_init(void **data) funcs->notify_stream_connection_changed = audio_notify_stream_connection_changed; - funcs->pcm_open = audio_pcm_open; - funcs->pcm_start = audio_pcm_start; - funcs->pcm_stop = audio_pcm_stop; - funcs->pcm_close = audio_pcm_close; - funcs->pcm_avail = audio_pcm_avail; - funcs->pcm_write = audio_pcm_write; - funcs->pcm_read = audio_pcm_read; - funcs->pcm_get_fd = audio_pcm_get_fd; - funcs->pcm_recover = audio_pcm_recover; - funcs->pcm_get_params = audio_pcm_get_params; - funcs->pcm_set_params = audio_pcm_set_params; + funcs->pcm_open = audio_open; + funcs->pcm_start = audio_start; + funcs->pcm_stop = audio_stop; + funcs->pcm_close = audio_close; + funcs->pcm_avail = audio_avail; + funcs->pcm_write = audio_write; + funcs->pcm_read = audio_read; + funcs->pcm_get_fd = audio_get_fd; + funcs->pcm_recover = audio_recover; + funcs->pcm_get_params = audio_get_params; + funcs->pcm_set_params = audio_set_params; funcs->add_message_cb = audio_add_message_cb; funcs->remove_message_cb = audio_remove_message_cb; diff --git a/packaging/audio-hal-emul.spec b/packaging/audio-hal-emul.spec index 88dc58f..3d68631 100644 --- a/packaging/audio-hal-emul.spec +++ b/packaging/audio-hal-emul.spec @@ -1,6 +1,6 @@ Name: audio-hal-emul Summary: TIZEN Audio HAL for Emulator -Version: 0.1.19 +Version: 0.1.20 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-file.c b/tizen-audio-file.c new file mode 100644 index 0000000..1ad1488 --- /dev/null +++ b/tizen-audio-file.c @@ -0,0 +1,198 @@ +/* + * audio-hal + * + * Copyright (c) 2023 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 +#include +#include +#include +#include + +#include +#include +#include +#include + +audio_return_e audio_file_open(const char *type, const char *filename, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **handle) +{ + FILE *f; + audio_pcm_sample_spec_s ss; + + AUDIO_RETURN_VAL_IF_FAIL(type, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(filename, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER); + + /* TODO: FIXME format will contains a wrong value */ + ss = *(audio_pcm_sample_spec_s *)sample_spec; + + if (ss.rate != 16000) { + AUDIO_LOG_ERROR("Not support rate. rate(%d)", ss.rate); + return AUDIO_ERR_PARAMETER; + } + + if (ss.channels != 1) { + AUDIO_LOG_ERROR("Not support channels. channels(%d)", ss.channels); + return AUDIO_ERR_PARAMETER; + } + + /* Skip + if (ss.format != SND_PCM_FORMAT_S16_LE) { + AUDIO_LOG_ERROR("Not support format"); + return AUDIO_ERR_PARAMETER; + } + */ + + f = fopen(filename, "r"); + if (!f) { + AUDIO_LOG_ERROR("Failed to open file name(%s)", filename); + return AUDIO_ERR_INTERNAL; + } + + *handle = (void *)f; + + return AUDIO_RET_OK; +} + +audio_return_e audio_file_start(void *handle) +{ + AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER); + + AUDIO_LOG_DEBUG("file start was called"); + + return AUDIO_RET_OK; +} + +audio_return_e audio_file_stop(void *handle) +{ + AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER); + + AUDIO_LOG_DEBUG("file stop was called"); + + return AUDIO_RET_OK; +} + +audio_return_e audio_file_close(void *handle) +{ + FILE *f; + + AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER); + + f = (FILE *)handle; + + fclose(f); + + return AUDIO_RET_OK; +} + +audio_return_e audio_file_avail(void *handle, uint32_t *avail) +{ + FILE *f; + long cur, end; + + AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER); + + f = (FILE *)handle; + + cur = ftell(f); + if (cur < 0) { + AUDIO_LOG_ERROR("Failed to get ftell(%s)", strerror(errno)); + return AUDIO_ERR_INTERNAL; + } + + if (fseek(f, 0L, SEEK_END) < 0) { + AUDIO_LOG_ERROR("Failed to seek. err(%s)", strerror(errno)); + return AUDIO_ERR_INTERNAL; + } + + end = ftell(f); + if (end < 0) { + AUDIO_LOG_ERROR("Failed to get ftell(%s)", strerror(errno)); + return AUDIO_ERR_INTERNAL; + } + + if (fseek(f, cur, SEEK_SET) < 0) { + AUDIO_LOG_ERROR("Failed to seek. err(%s)", strerror(errno)); + return AUDIO_ERR_INTERNAL; + } + + *avail = end - cur; + + return AUDIO_RET_OK; +} + +audio_return_e audio_file_write(void *handle, const void *buffer, uint32_t frames) +{ + FILE *f; + size_t ret; + + AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER); + + f = (FILE *)handle; + + ret = fwrite(buffer, sizeof(short), frames, f); + if (ret == 0) { + AUDIO_LOG_ERROR("Failed to write(%s)", strerror(errno)); + return AUDIO_ERR_INTERNAL; + } + + return AUDIO_RET_OK; +} + +audio_return_e audio_file_read(void *handle, void *buffer, uint32_t frames) +{ + FILE *f; + size_t ret; + + AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER); + + f = (FILE *)handle; + + ret = fread(buffer, sizeof(short), frames, f); + if (ret == 0) { + AUDIO_LOG_ERROR("Failed to read(%s)", strerror(errno)); + return AUDIO_ERR_INTERNAL; + } + + return AUDIO_RET_OK; +} + +audio_return_e audio_file_get_fd(void *handle, int *fd) +{ + return AUDIO_ERR_IOCTL; +} + +audio_return_e audio_file_recover(void *handle, int revents) +{ + return AUDIO_ERR_IOCTL; +} + +audio_return_e audio_file_get_params(void *handle, uint32_t direction, void *sample_spec, uint32_t *period_size, uint32_t *periods) +{ + return AUDIO_ERR_IOCTL; +} + +audio_return_e audio_file_set_params(void *handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods) +{ + return AUDIO_ERR_IOCTL; +} + diff --git a/tizen-audio-file.h b/tizen-audio-file.h new file mode 100644 index 0000000..00d50d1 --- /dev/null +++ b/tizen-audio-file.h @@ -0,0 +1,35 @@ +/* + * audio-hal + * + * Copyright (c) 2023 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. + * + */ + +#ifndef footizenaudiofilefoo +#define footizenaudiofilefoo + +audio_return_e audio_file_open(const char *type, const char *filename, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **handle); +audio_return_e audio_file_start(void *handle); +audio_return_e audio_file_stop(void *handle); +audio_return_e audio_file_close(void *handle); +audio_return_e audio_file_avail(void *handle, uint32_t *avail); +audio_return_e audio_file_write(void *handle, const void *buffer, uint32_t frames); +audio_return_e audio_file_read(void *handle, void *buffer, uint32_t frames); +audio_return_e audio_file_get_fd(void *handle, int *fd); +audio_return_e audio_file_recover(void *handle, int revents); +audio_return_e audio_file_get_params(void *handle, uint32_t direction, void *sample_spec, uint32_t *period_size, uint32_t *periods); +audio_return_e audio_file_set_params(void *handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); + +#endif diff --git a/tizen-audio-glue.c b/tizen-audio-glue.c new file mode 100644 index 0000000..d2cb085 --- /dev/null +++ b/tizen-audio-glue.c @@ -0,0 +1,259 @@ +#include +#include +#include "tizen-audio-glue.h" +#include "tizen-audio.h" +#include "tizen-audio-internal.h" +#include "tizen-audio-file.h" + +struct audio_interface_s { + audio_return_e (*open)(const char *card, const char *device, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **interface); + audio_return_e (*start)(void *handle); + audio_return_e (*stop)(void *handle); + audio_return_e (*close)(void *handle); + audio_return_e (*avail)(void *handle, uint32_t *avail); + audio_return_e (*write)(void *handle, const void *buffer, uint32_t frames); + audio_return_e (*read)(void *handle, void *buffer, uint32_t frames); + audio_return_e (*get_fd)(void *handle, int *fd); + audio_return_e (*recover)(void *handle, int revents); + audio_return_e (*get_params)(void *handle, uint32_t direction, void *sample_spec, uint32_t *period_size, uint32_t *periods); + audio_return_e (*set_params)(void *handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); + void *glue_handle; +}; + +audio_return_e audio_open(void *audio_handle, const char *card, const char *device, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **handle) +{ + struct audio_interface_s *interface = (struct audio_interface_s *)calloc(1, sizeof(struct audio_interface_s)); + void *glue_handle = NULL; + + AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_RESOURCE); + + AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_RESOURCE); + AUDIO_RETURN_VAL_IF_FAIL(card, AUDIO_ERR_RESOURCE); + AUDIO_RETURN_VAL_IF_FAIL(device, AUDIO_ERR_RESOURCE); + AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_RESOURCE); + AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_RESOURCE); + + AUDIO_LOG_INFO("card(%s), device(%s), direction(%u), period_size(%u), periods(%u)", + card, device, direction, period_size, periods); + + if (!strcmp(card,"file")) { + interface->open = audio_file_open; + interface->start = audio_file_start; + interface->stop = audio_file_stop; + interface->close = audio_file_close; + interface->avail = audio_file_avail; + interface->write = audio_file_write; + interface->read = audio_file_read; + interface->get_fd = audio_file_get_fd; + interface->recover = audio_file_recover; + interface->get_params = audio_file_get_params; + interface->set_params = audio_file_set_params; + } else { + interface->open = audio_pcm_open; + interface->start = audio_pcm_start; + interface->stop = audio_pcm_stop; + interface->close = audio_pcm_close; + interface->avail = audio_pcm_avail; + interface->write = audio_pcm_write; + interface->read = audio_pcm_read; + interface->get_fd = audio_pcm_get_fd; + interface->recover = audio_pcm_recover; + interface->get_params = audio_pcm_get_params; + interface->set_params = audio_pcm_set_params; + } + + if (!interface->open) { + AUDIO_LOG_ERROR("Failed to find open interface"); + goto fail; + } + + if (interface->open(card, device, direction, sample_spec, period_size, periods, &glue_handle) != AUDIO_RET_OK) { + AUDIO_LOG_ERROR("Failed to open device"); + goto fail; + } + + interface->glue_handle = glue_handle; + *handle = (void *)interface; + + return AUDIO_RET_OK; + +fail: + free(interface); + + return AUDIO_ERR_INTERNAL; +} + +audio_return_e audio_start(void *audio_handle, void *handle) +{ + struct audio_interface_s *interface = (struct audio_interface_s *)handle; + + AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->start, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->glue_handle, AUDIO_ERR_PARAMETER); + + if (interface->start(interface->glue_handle) != AUDIO_RET_OK) { + AUDIO_LOG_ERROR("Failed to start device"); + return AUDIO_ERR_INTERNAL; + } + + return AUDIO_RET_OK; +} + +audio_return_e audio_stop(void *audio_handle, void *handle) +{ + struct audio_interface_s *interface = (struct audio_interface_s *)handle; + + AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->stop, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->glue_handle, AUDIO_ERR_PARAMETER); + + if (interface->stop(interface->glue_handle) != AUDIO_RET_OK) { + AUDIO_LOG_ERROR("Failed to stop device"); + return AUDIO_ERR_INTERNAL; + } + + return AUDIO_RET_OK; +} + +audio_return_e audio_close(void *audio_handle, void *handle) +{ + struct audio_interface_s *interface = (struct audio_interface_s *)handle; + + AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->close, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->glue_handle, AUDIO_ERR_PARAMETER); + + if (interface->close(interface->glue_handle) != AUDIO_RET_OK) { + AUDIO_LOG_ERROR("Failed to close device"); + return AUDIO_ERR_INTERNAL; + } + + interface->glue_handle = NULL; + + free(interface); + + AUDIO_LOG_INFO("PCM handle close success"); + + return AUDIO_RET_OK; +} + +audio_return_e audio_avail(void *audio_handle, void *handle, uint32_t *avail) +{ + struct audio_interface_s *interface = (struct audio_interface_s *)handle; + + AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->avail, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->glue_handle, AUDIO_ERR_PARAMETER); + + if (interface->avail(interface->glue_handle, avail) != AUDIO_RET_OK) { + AUDIO_LOG_ERROR("Failed to get avail"); + return AUDIO_ERR_INTERNAL; + } + + return AUDIO_RET_OK; +} + +audio_return_e audio_write(void *audio_handle, void *handle, const void *buffer, uint32_t frames) +{ + struct audio_interface_s *interface = (struct audio_interface_s *)handle; + + AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->write, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->glue_handle, AUDIO_ERR_PARAMETER); + + if (interface->write(interface->glue_handle, buffer, frames) != AUDIO_RET_OK) { + AUDIO_LOG_ERROR("Failed to write pcm"); + return AUDIO_ERR_INTERNAL; + } + + return AUDIO_RET_OK; +} + +audio_return_e audio_read(void *audio_handle, void *handle, void *buffer, uint32_t frames) +{ + struct audio_interface_s *interface = (struct audio_interface_s *)handle; + + AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->read, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->glue_handle, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(buffer, AUDIO_ERR_PARAMETER); + + if (interface->read(interface->glue_handle, buffer, frames) != AUDIO_RET_OK) { + AUDIO_LOG_ERROR("Failed to read pcm"); + return AUDIO_ERR_INTERNAL; + } + + return AUDIO_RET_OK; +} + +audio_return_e audio_get_fd(void *audio_handle, void *handle, int *fd) +{ + struct audio_interface_s *interface = (struct audio_interface_s *)handle; + + AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->get_fd, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->glue_handle, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(fd, AUDIO_ERR_PARAMETER); + + if (interface->get_fd(interface->glue_handle, fd) != AUDIO_RET_OK) { + AUDIO_LOG_ERROR("Failed to get pcm fd"); + return AUDIO_ERR_INTERNAL; + } + + return AUDIO_RET_OK; +} + +audio_return_e audio_recover(void *audio_handle, void *handle, int revents) +{ + struct audio_interface_s *interface = (struct audio_interface_s *)handle; + + AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->recover, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->glue_handle, AUDIO_ERR_PARAMETER); + + if (interface->recover(interface->glue_handle, revents) != AUDIO_RET_OK) { + AUDIO_LOG_ERROR("Failed to recover devices"); + return AUDIO_ERR_INTERNAL; + } + + return AUDIO_RET_OK; +} + +audio_return_e audio_get_params(void *audio_handle, void *handle, uint32_t direction, void *sample_spec, uint32_t *period_size, uint32_t *periods) +{ + struct audio_interface_s *interface = (struct audio_interface_s *)handle; + + AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->get_params, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->glue_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); + + if (interface->get_params(interface->glue_handle, direction, sample_spec, period_size, periods) != AUDIO_RET_OK) { + AUDIO_LOG_ERROR("Failed to get params"); + return AUDIO_ERR_INTERNAL; + } + + return AUDIO_RET_OK; +} + +audio_return_e audio_set_params(void *audio_handle, void *handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods) +{ + struct audio_interface_s *interface = (struct audio_interface_s *)handle; + + AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->set_params, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(interface->glue_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); + + if (interface->set_params(interface->glue_handle, direction, sample_spec, period_size, periods) != AUDIO_RET_OK) { + AUDIO_LOG_ERROR("Failed to set params"); + return AUDIO_ERR_INTERNAL; + } + + return AUDIO_RET_OK; +} + diff --git a/tizen-audio-glue.h b/tizen-audio-glue.h new file mode 100644 index 0000000..4fd384d --- /dev/null +++ b/tizen-audio-glue.h @@ -0,0 +1,14 @@ +#include +#include + +audio_return_e audio_open(void *audio_handle, const char *card, const char *device, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **handle); +audio_return_e audio_start(void *audio_handle, void *handle); +audio_return_e audio_stop(void *audio_handle, void *handle); +audio_return_e audio_close(void *audio_handle, void *handle); +audio_return_e audio_avail(void *audio_handle, void *handle, uint32_t *avail); +audio_return_e audio_write(void *audio_handle, void *handle, const void *buffer, uint32_t frames); +audio_return_e audio_read(void *audio_handle, void *handle, void *buffer, uint32_t frames); +audio_return_e audio_get_fd(void *audio_handle, void *handle, int *fd); +audio_return_e audio_recover(void *audio_handle, void *handle, int revents); +audio_return_e audio_get_params(void *audio_handle, void *handle, uint32_t direction, void *sample_spec, uint32_t *period_size, uint32_t *periods); +audio_return_e audio_set_params(void *audio_handle, void *handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); diff --git a/tizen-audio-internal.h b/tizen-audio-internal.h index 77cd6c6..2a49fd0 100644 --- a/tizen-audio-internal.h +++ b/tizen-audio-internal.h @@ -132,7 +132,6 @@ typedef struct audio_hal_device { snd_pcm_t *pcm_in; snd_pcm_t *pcm_out; pthread_mutex_t pcm_lock; - uint32_t pcm_count; } audio_hal_device_s; /* Volume */ diff --git a/tizen-audio-pcm.c b/tizen-audio-pcm.c index be4c59e..15cfdda 100644 --- a/tizen-audio-pcm.c +++ b/tizen-audio-pcm.c @@ -31,7 +31,6 @@ audio_return_e _audio_pcm_init(audio_hal_s *ah) ah->device.pcm_in = NULL; ah->device.pcm_out = NULL; pthread_mutex_init(&ah->device.pcm_lock, NULL); - ah->device.pcm_count = 0; return AUDIO_RET_OK; } @@ -45,13 +44,11 @@ audio_return_e _audio_pcm_deinit(audio_hal_s *ah) return AUDIO_RET_OK; } -audio_return_e audio_pcm_open(void *audio_handle, const char *card, const char *device, uint32_t direction, void *sample_spec, +audio_return_e audio_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_e audio_ret = AUDIO_RET_OK; - audio_hal_s *ah = NULL; - 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); @@ -60,18 +57,15 @@ audio_return_e audio_pcm_open(void *audio_handle, const char *card, const char * if ((audio_ret = _pcm_open(card, device, direction, sample_spec, period_size, periods, pcm_handle))) return audio_ret; - ah = (audio_hal_s*)audio_handle; - ah->device.pcm_count++; AUDIO_LOG_INFO("Opening PCM handle %p", *pcm_handle); return AUDIO_RET_OK; } -audio_return_e audio_pcm_start(void *audio_handle, void *pcm_handle) +audio_return_e audio_pcm_start(void *pcm_handle) { audio_return_e audio_ret = AUDIO_RET_OK; - AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER); audio_ret = _pcm_start(pcm_handle); @@ -79,11 +73,10 @@ audio_return_e audio_pcm_start(void *audio_handle, void *pcm_handle) return audio_ret; } -audio_return_e audio_pcm_stop(void *audio_handle, void *pcm_handle) +audio_return_e audio_pcm_stop(void *pcm_handle) { audio_return_e audio_ret = AUDIO_RET_OK; - AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER); audio_ret = _pcm_stop(pcm_handle); @@ -91,31 +84,26 @@ audio_return_e audio_pcm_stop(void *audio_handle, void *pcm_handle) return audio_ret; } -audio_return_e audio_pcm_close(void *audio_handle, void *pcm_handle) +audio_return_e audio_pcm_close(void *pcm_handle) { audio_return_e audio_ret = AUDIO_RET_OK; - audio_hal_s *ah = NULL; - AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER); if ((audio_ret = _pcm_close(pcm_handle))) return audio_ret; pcm_handle = NULL; - ah = (audio_hal_s*)audio_handle; - ah->device.pcm_count--; - AUDIO_LOG_INFO("PCM handle close success (count:%d)", ah->device.pcm_count); + AUDIO_LOG_INFO("PCM handle close success"); return audio_ret; } -audio_return_e audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *avail) +audio_return_e audio_pcm_avail(void *pcm_handle, uint32_t *avail) { audio_return_e audio_ret = AUDIO_RET_OK; - 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); @@ -124,11 +112,10 @@ audio_return_e audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *a return audio_ret; } -audio_return_e audio_pcm_write(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames) +audio_return_e audio_pcm_write(void *pcm_handle, const void *buffer, uint32_t frames) { audio_return_e audio_ret = AUDIO_RET_OK; - AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER); audio_ret = _pcm_write(pcm_handle, buffer, frames); @@ -136,11 +123,10 @@ audio_return_e audio_pcm_write(void *audio_handle, void *pcm_handle, const void return audio_ret; } -audio_return_e audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames) +audio_return_e audio_pcm_read(void *pcm_handle, void *buffer, uint32_t frames) { audio_return_e audio_ret = AUDIO_RET_OK; - AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER); audio_ret = _pcm_read(pcm_handle, buffer, frames); @@ -148,11 +134,10 @@ audio_return_e audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer return audio_ret; } -audio_return_e audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd) +audio_return_e audio_pcm_get_fd(void *pcm_handle, int *fd) { audio_return_e audio_ret = AUDIO_RET_OK; - 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); @@ -161,11 +146,10 @@ audio_return_e audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd) return audio_ret; } -audio_return_e audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents) +audio_return_e audio_pcm_recover(void *pcm_handle, int revents) { audio_return_e audio_ret = AUDIO_RET_OK; - AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER); audio_ret = _pcm_recover(pcm_handle, revents); @@ -173,11 +157,10 @@ audio_return_e audio_pcm_recover(void *audio_handle, void *pcm_handle, int reven return audio_ret; } -audio_return_e 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_e audio_pcm_get_params(void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t *period_size, uint32_t *periods) { audio_return_e audio_ret = AUDIO_RET_OK; - 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); @@ -188,11 +171,10 @@ audio_return_e audio_pcm_get_params(void *audio_handle, void *pcm_handle, uint32 return audio_ret; } -audio_return_e audio_pcm_set_params(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods) +audio_return_e audio_pcm_set_params(void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods) { audio_return_e audio_ret = AUDIO_RET_OK; - 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); diff --git a/tizen-audio.h b/tizen-audio.h index 15ee937..5473099 100644 --- a/tizen-audio.h +++ b/tizen-audio.h @@ -239,7 +239,7 @@ audio_return_e audio_notify_stream_connection_changed(void *audio_handle, audio_ * @retval #AUDIO_RET_OK Success * @see audio_pcm_close() */ -audio_return_e 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_e audio_pcm_open(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. @@ -256,7 +256,7 @@ audio_return_e audio_pcm_open(void *audio_handle, const char *card, const char * * @see audio_pcm_stop() * @see audio_pcm_recover() */ -audio_return_e audio_pcm_start(void *audio_handle, void *pcm_handle); +audio_return_e audio_pcm_start(void *pcm_handle); /** * @brief Stops a PCM device. @@ -269,7 +269,7 @@ audio_return_e audio_pcm_start(void *audio_handle, void *pcm_handle); * @retval #AUDIO_RET_OK Success * @see audio_pcm_start() */ -audio_return_e audio_pcm_stop(void *audio_handle, void *pcm_handle); +audio_return_e audio_pcm_stop(void *pcm_handle); /** * @brief Closes a PCM device. @@ -282,7 +282,7 @@ audio_return_e audio_pcm_stop(void *audio_handle, void *pcm_handle); * @retval #AUDIO_RET_OK Success * @see audio_pcm_open() */ -audio_return_e audio_pcm_close(void *audio_handle, void *pcm_handle); +audio_return_e audio_pcm_close(void *pcm_handle); /** * @brief Gets available number of frames. @@ -297,7 +297,7 @@ audio_return_e audio_pcm_close(void *audio_handle, void *pcm_handle); * @see audio_pcm_write() * @see audio_pcm_read() */ -audio_return_e audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *avail); +audio_return_e audio_pcm_avail(void *pcm_handle, uint32_t *avail); /** * @brief Writes frames to a PCM device. @@ -313,7 +313,7 @@ audio_return_e audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *a * @see audio_pcm_avail() * @see audio_pcm_recover() */ -audio_return_e audio_pcm_write(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames); +audio_return_e audio_pcm_write(void *pcm_handle, const void *buffer, uint32_t frames); /** * @brief Reads frames from a PCM device. @@ -329,7 +329,7 @@ audio_return_e audio_pcm_write(void *audio_handle, void *pcm_handle, const void * @see audio_pcm_avail() * @see audio_pcm_recover() */ -audio_return_e audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames); +audio_return_e audio_pcm_read(void *pcm_handle, void *buffer, uint32_t frames); /** * @brief Gets poll descriptor for a PCM handle. @@ -344,7 +344,7 @@ audio_return_e audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer * @see audio_pcm_open() * @see audio_pcm_recover() */ -audio_return_e audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd); +audio_return_e audio_pcm_get_fd(void *pcm_handle, int *fd); /** * @brief Recovers the PCM state. @@ -361,7 +361,7 @@ audio_return_e audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd); * @see audio_pcm_read() * @see audio_pcm_get_fd() */ -audio_return_e audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents); +audio_return_e audio_pcm_recover(void *pcm_handle, int revents); /** * @brief Gets parameters of a PCM device. @@ -378,7 +378,7 @@ audio_return_e audio_pcm_recover(void *audio_handle, void *pcm_handle, int reven * @retval #AUDIO_RET_OK Success * @see audio_pcm_set_params() */ -audio_return_e 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_e audio_pcm_get_params(void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t *period_size, uint32_t *periods); /** * @brief Sets hardware and software parameters of a PCM device. @@ -395,7 +395,7 @@ audio_return_e audio_pcm_get_params(void *audio_handle, void *pcm_handle, uint32 * @retval #AUDIO_RET_OK Success * @see audio_pcm_set_params() */ -audio_return_e audio_pcm_set_params(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); +audio_return_e audio_pcm_set_params(void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods); /** * @brief Adds the message callback function. -- 2.34.1