From 10f33ec7a356f81090087cb53568bef80dea2541 Mon Sep 17 00:00:00 2001 From: zhao_haipeng Date: Tue, 16 Nov 2021 14:25:33 +0800 Subject: [PATCH] tinyalsa adapter rk3568 Signed-off-by: zhao_haipeng --- BUILD.gn | 108 +++++++++++++++++++++++++++++++++++++++++ include/tinyalsa/pcm.h | 8 +-- src/mixer.c | 12 +++++ src/pcm.c | 35 +++++++++---- 4 files changed, 150 insertions(+), 13 deletions(-) create mode 100644 BUILD.gn diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 0000000..fb327b2 --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,108 @@ +#Copyright (C) 2021 HiHope Open Source Organization . +#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. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") + +config("libtinyalsa_config") { + include_dirs = [ + "include", + "include/tinyalsa", + ] + cflags = [ + "-Wno-incompatible-pointer-types", + "-Werror", + "-Wimplicit-function-declaration", + "-Wno-error=unused-variable", + "-Wno-macro-redefined", + ] +} + +ohos_shared_library("libtinyalsa") { + sources = [ + "src/mixer.c", + "src/mixer_hw.c", + "src/mixer_plugin.c", + "src/pcm.c", + "src/pcm_hw.c", + "src/pcm_plugin.c", + "src/snd_card_plugin.c", + ] + + install_images = [ + "system", + "updater", + ] + install_enable = true + configs = [ ":libtinyalsa_config" ] + + subsystem_name = "hdf" +} + +#ohos_executable("tinycap") { +# +# sources = [ +# "tinycap.c", +# ] +# +# configs = [ ":libtinyalsa_config" ] +# deps = [ +# ":libtinyalsa", +# ] +# +# install_images = [ +# "system", +# "updater", +# ] +# install_enable = true +# +# subsystem_name = "hdf" +#} +# +#ohos_executable("tinyplay") { +# sources = [ +# "tinyplay.c", +# ] +# +# configs = [ ":libtinyalsa_config" ] +# deps = [ +# ":libtinyalsa", +# ] +# +# install_images = [ +# "system", +# "updater", +# ] +# install_enable = true +# +# subsystem_name = "hdf" +#} +# +#ohos_executable("tinymix") { +# sources = [ +# "tinymix.c", +# ] +# +# configs = [ ":libtinyalsa_config" ] +# deps = [ +# ":libtinyalsa", +# ] +# install_enable = true +# +# install_images = [ +# "system", +# "updater", +# ] +# +# subsystem_name = "hdf" +#} diff --git a/include/tinyalsa/pcm.h b/include/tinyalsa/pcm.h index b40550c..e472475 100644 --- a/include/tinyalsa/pcm.h +++ b/include/tinyalsa/pcm.h @@ -327,13 +327,13 @@ int pcm_get_htimestamp(struct pcm *pcm, unsigned int *avail, struct timespec *ts unsigned int pcm_get_subdevice(const struct pcm *pcm); -int pcm_writei(struct pcm *pcm, const void *data, unsigned int frame_count) TINYALSA_WARN_UNUSED_RESULT; +int pcm_writei(struct pcm *pcm, const void *data, unsigned int frame_count); -int pcm_readi(struct pcm *pcm, void *data, unsigned int frame_count) TINYALSA_WARN_UNUSED_RESULT; +int pcm_readi(struct pcm *pcm, void *data, unsigned int frame_count); -int pcm_write(struct pcm *pcm, const void *data, unsigned int count) TINYALSA_DEPRECATED; +int pcm_write(struct pcm *pcm, const void *data, unsigned int count); -int pcm_read(struct pcm *pcm, void *data, unsigned int count) TINYALSA_DEPRECATED; +int pcm_read(struct pcm *pcm, void *data, unsigned int count); int pcm_mmap_write(struct pcm *pcm, const void *data, unsigned int count) TINYALSA_DEPRECATED; diff --git a/src/mixer.c b/src/mixer.c index a45502e..6e37d71 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -62,6 +62,18 @@ #include "mixer_io.h" +#ifndef INT_MAX +#define INT_MAX 2147483647 +#endif + +#ifndef UINT_MAX +#define UINT_MAX 4294967295UL +#endif + +#ifndef ULONG_MAX +#define ULONG_MAX 4294967295UL +#endif + /** A mixer control. * @ingroup libtinyalsa-mixer */ diff --git a/src/pcm.c b/src/pcm.c index 10e477b..1efeb2f 100644 --- a/src/pcm.c +++ b/src/pcm.c @@ -82,6 +82,18 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #endif +#ifndef INT_MAX +#define INT_MAX 2147483647 +#endif + +#ifndef UINT_MAX +#define UINT_MAX 4294967295UL +#endif + +#ifndef ULONG_MAX +#define ULONG_MAX 4294967295UL +#endif + /* refer to SNDRV_PCM_ACCESS_##index in sound/asound.h. */ static const char * const access_lookup[] = { "MMAP_INTERLEAVED", @@ -616,6 +628,16 @@ static int pcm_sync_ptr(struct pcm *pcm, int flags) return 0; } +int pcm_state(struct pcm *pcm) +{ + // Update the state only. Do not sync HW sync. + int err = pcm_sync_ptr(pcm, SNDRV_PCM_SYNC_PTR_APPL | SNDRV_PCM_SYNC_PTR_AVAIL_MIN); + if (err < 0) + return err; + + return pcm->mmap_status->state; +} + static int pcm_hw_mmap_status(struct pcm *pcm) { if (pcm->sync_ptr) @@ -1189,6 +1211,10 @@ int pcm_prepare(struct pcm *pcm) */ int pcm_start(struct pcm *pcm) { + if (pcm_state(pcm) == PCM_STATE_SETUP && pcm_prepare(pcm) != 0) { + return -1; + } + /* set appl_ptr and avail_min in kernel */ if (pcm_sync_ptr(pcm, 0) < 0) return -1; @@ -1402,15 +1428,6 @@ again: return 0; } -int pcm_state(struct pcm *pcm) -{ - int err = pcm_sync_ptr(pcm, 0); - if (err < 0) - return err; - - return pcm->mmap_status->state; -} - /** Waits for frames to be available for read or write operations. * @param pcm A PCM handle. * @param timeout The maximum amount of time to wait for, in terms of milliseconds.