From 795c8e93aaa5218df5c46ac14f788e88fdd5a12f Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Mon, 20 Nov 2023 19:10:01 +0900 Subject: [PATCH] keysound: support keysound priority - The new higher(or the same) priority plays after stopping the previous lower(or the same) priority playbacks. - If the new playback is lower priority, then will be no operation. - The priority with -1 will be mixed always with others, no matter what other playback's priority is. [Version] 0.14.0 [Issue Type] Feature Change-Id: I3752c80049b64c1218a1f5128a9df3fe27545d05 --- include/mm_sound_private.h | 18 ++++++++++- mm_sound_keysound.c | 58 +++++++++++++++++++---------------- packaging/libmm-sound.spec | 2 +- testsuite/mm_sound_testsuite_simple.c | 4 +-- 4 files changed, 52 insertions(+), 30 deletions(-) diff --git a/include/mm_sound_private.h b/include/mm_sound_private.h index 9258ce7..eda49ff 100644 --- a/include/mm_sound_private.h +++ b/include/mm_sound_private.h @@ -64,7 +64,7 @@ typedef struct { * @return This function returns MM_ERROR_NONE on success, or negative value * with error code. * - * @remark This function provide low latency sound play (such as dialer keytone) + * @remark This function provides low latency sound play (such as dialer keytone) * using fixed spec of wave file (44100Hz, mono channel) * @see mm_sound_stop_keysound() * @see volume_type_t volume_gain_t @@ -72,6 +72,22 @@ typedef struct { int mm_sound_play_keysound(const char *filename, int volume_config); /** + * This function is to play key sound with a priority. + * + * @param filename [in] keytone filename to play + * @param volume_config [in] volume type & volume gain + * @param priority [in] priority lower as a higher priority, -1 for no priority (= don't care) + * + * @return This function returns MM_ERROR_NONE on success, or negative value + * with error code. + * + * @remark This function provides low latency sound play with a given priority + * @see mm_sound_stop_keysound() + * @see volume_type_t volume_gain_t + */ +int mm_sound_play_keysound_priority(const char *filename, int volume_config, int priority); + +/** * This function is to stop key sound. * * @param filename [in] keytone filename to stop (can be null if whole exist keytones need stops) diff --git a/mm_sound_keysound.c b/mm_sound_keysound.c index fc7272e..d23a6fa 100644 --- a/mm_sound_keysound.c +++ b/mm_sound_keysound.c @@ -44,12 +44,15 @@ #define AUDIO_VOLUME_CONFIG_TYPE(vol) (vol & 0x00FF) #define AUDIO_VOLUME_CONFIG_GAIN(vol) (vol & 0xFF00) +#define FILENAME_LEN 1024 +#define MIN_KEYTONE_INTERVAL_US 30000 +#define NO_PRIORITY (-1) + #define USE_PIPE /* default is pipe now */ #ifdef USE_PIPE #define KEYTONE_PATH "/tmp/keytone" -#define FILENAME_LEN 1024 #define ROLE_LEN 64 #define VOLUME_GAIN_TYPE_LEN 32 #define METHOD_LEN 32 @@ -57,17 +60,20 @@ #define MAX_WRITE_RETRY 50 #define WRITE_RETRY_INTERVAL_MS 20 -#define MIN_KEYTONE_INTERVAL_US 30000 +#define MM_SOUND_SIMPLE __mm_sound_simple_pipe typedef struct ipc_data { char filename[FILENAME_LEN]; char role[ROLE_LEN]; char volume_gain_type[VOLUME_GAIN_TYPE_LEN]; char method[METHOD_LEN]; + int priority; /* lower as a higher priority, -1 for no priority (= don't care) */ } ipc_t; -static int __mm_sound_simple_pipe(const char *filename, int volume_config, const char *method); +static int __mm_sound_simple_pipe(const char *filename, int volume_config, int priority, const char *method); + #else /* USE_PIPE */ + #include #define PA_BUS_NAME "org.pulseaudio.Server" @@ -75,7 +81,9 @@ static int __mm_sound_simple_pipe(const char *filename, int volume_config, const #define PA_SOUND_PLAYER_INTERFACE "org.pulseaudio.SoundPlayer" #define PA_SOUND_RESPONSE_TIMEOUT 5000 -static int __mm_sound_simple_dbus(const char *filename, int volume_config, const char *method); +#define MM_SOUND_SIMPLE __mm_sound_simple_dbus + +static int __mm_sound_simple_dbus(const char *filename, int volume_config, int priority, const char *method); #endif /* USE_PIPE */ static const char* __convert_volume_type_to_role(int volume_type) @@ -161,7 +169,7 @@ static bool __is_interval_too_short(const char *filename) } EXPORT_API -int mm_sound_play_keysound(const char *filename, int volume_config) +int mm_sound_play_keysound_priority(const char *filename, int volume_config, int priority) { #ifndef TIZEN_TV if (__is_interval_too_short(filename)) { @@ -170,23 +178,20 @@ int mm_sound_play_keysound(const char *filename, int volume_config) } #endif -#ifdef USE_PIPE - return __mm_sound_simple_pipe(filename, volume_config, PA_SOUND_PLAYER_METHOD_NAME_SIMPLE_PLAY); -#else - return __mm_sound_simple_dbus(filename, volume_config, PA_SOUND_PLAYER_METHOD_NAME_SIMPLE_PLAY); -#endif + return MM_SOUND_SIMPLE(filename, volume_config, priority, PA_SOUND_PLAYER_METHOD_NAME_SIMPLE_PLAY); +} + +EXPORT_API +int mm_sound_play_keysound(const char *filename, int volume_config) +{ + return mm_sound_play_keysound_priority(filename, volume_config, NO_PRIORITY); } EXPORT_API int mm_sound_stop_keysound(const char *filename) { -#ifdef USE_PIPE - return __mm_sound_simple_pipe(filename, 0, - (filename) ? PA_SOUND_PLAYER_METHOD_NAME_SIMPLE_STOP : PA_SOUND_PLAYER_METHOD_NAME_SIMPLE_STOP_ALL); -#else - return __mm_sound_simple_dbus(filename, 0, - (filename) ? PA_SOUND_PLAYER_METHOD_NAME_SIMPLE_STOP : PA_SOUND_PLAYER_METHOD_NAME_SIMPLE_STOP_ALL); -#endif + return MM_SOUND_SIMPLE(filename, 0, NO_PRIORITY, + filename ? PA_SOUND_PLAYER_METHOD_NAME_SIMPLE_STOP : PA_SOUND_PLAYER_METHOD_NAME_SIMPLE_STOP_ALL); } #ifdef USE_LWIPC @@ -227,7 +232,7 @@ static int __verify_input_file(const char *filename) } #ifdef USE_PIPE -static int __mm_sound_simple_pipe(const char *filename, int volume_config, const char *method) +static int __mm_sound_simple_pipe(const char *filename, int volume_config, int priority, const char *method) { int ret = MM_ERROR_NONE; int retry_remaining = MAX_WRITE_RETRY; @@ -264,10 +269,11 @@ static int __mm_sound_simple_pipe(const char *filename, int volume_config, const g_strlcpy(data.volume_gain_type, __convert_volume_gain_type_to_string(AUDIO_VOLUME_CONFIG_GAIN(volume_config)), VOLUME_GAIN_TYPE_LEN); + data.priority = priority; } - debug_msg("filepath=[%s], role=[%s], volume_gain_type=[%s], method=[%s]", - data.filename, data.role, data.volume_gain_type, data.method); + debug_msg("filepath=[%s], role=[%s], volume_gain_type=[%s], priority=[%d], method=[%s]", + data.filename, data.role, data.volume_gain_type, data.priority, data.method); /* Open PIPE */ fd = open(KEYTONE_PATH, O_WRONLY | O_NONBLOCK); @@ -309,7 +315,7 @@ static int __mm_sound_simple_pipe(const char *filename, int volume_config, const } #else /* USE_PIPE */ -static int __mm_sound_simple_dbus(const char *filename, int volume_config, const char *method) +static int __mm_sound_simple_dbus(const char *filename, int volume_config, int priority, const char *method) { int ret = MM_ERROR_NONE; const char *role = NULL; @@ -347,7 +353,7 @@ static int __mm_sound_simple_dbus(const char *filename, int volume_config, const PA_SOUND_PLAYER_OBJECT_PATH, PA_SOUND_PLAYER_INTERFACE, PA_SOUND_PLAYER_METHOD_NAME_SIMPLE_PLAY, - g_variant_new("(sss)", filename, role, vol_gain_type), + g_variant_new("(sssi)", filename, role, vol_gain_type, priority), NULL, G_DBUS_CALL_FLAGS_NONE, PA_SOUND_RESPONSE_TIMEOUT, NULL, &err); if (!result || err) { debug_error("g_dbus_connection_call_sync() for %s error (%s)", method, err ? err->message : NULL); @@ -357,13 +363,13 @@ static int __mm_sound_simple_dbus(const char *filename, int volume_config, const g_variant_get(result, "(i)", &idx); if (idx == -1) { - debug_error("[%s] failure, filename(%s)/role(%s)/gain(%s)/stream idx(%d)", - method, filename, role, vol_gain_type, idx); + debug_error("[%s] failure, filename(%s)/role(%s)/gain(%s)/priority(%d)/stream idx(%d)", + method, filename, role, vol_gain_type, priority, idx); ret = MM_ERROR_SOUND_INTERNAL; goto END; } - debug_msg("[%s] success, filename(%s)/role(%s)/gain(%s)/stream idx(%d)", - method, filename, role, vol_gain_type, idx); + debug_msg("[%s] success, filename(%s)/role(%s)/gain(%s)/priority(%d),stream idx(%d)", + method, filename, role, vol_gain_type, priority, idx); } else if (g_strcmp0(method, PA_SOUND_PLAYER_METHOD_NAME_SIMPLE_STOP) == 0) { ret = __verify_input_file(filename); diff --git a/packaging/libmm-sound.spec b/packaging/libmm-sound.spec index 83e57e8..16e3b8f 100644 --- a/packaging/libmm-sound.spec +++ b/packaging/libmm-sound.spec @@ -1,6 +1,6 @@ Name: libmm-sound Summary: MMSound Package contains client lib and focus server binary -Version: 0.13.26 +Version: 0.14.0 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/testsuite/mm_sound_testsuite_simple.c b/testsuite/mm_sound_testsuite_simple.c index 1509653..d1fd1f0 100755 --- a/testsuite/mm_sound_testsuite_simple.c +++ b/testsuite/mm_sound_testsuite_simple.c @@ -580,7 +580,7 @@ static void interpret(char *cmd) if (ret < 0) debug_error("keysound stop(all) failed with 0x%x", ret); } else if (strncmp(cmd, "kn", 2) == 0) { - ret = mm_sound_play_keysound(KEYTONE_NOTI_FILE, VOLUME_TYPE_NOTIFICATION); + ret = mm_sound_play_keysound_priority(KEYTONE_NOTI_FILE, VOLUME_TYPE_NOTIFICATION, 2); /* priority 2 for test */ if (ret < 0) debug_error("keysound play(noti) failed with 0x%x", ret); } else if (strncmp(cmd, "ks", 2) == 0) { @@ -599,7 +599,7 @@ static void interpret(char *cmd) keytone_path, count, interval_us); for (unsigned int i = 0; i < count; i++) { - ret = mm_sound_play_keysound(keytone_path, 0); + ret = mm_sound_play_keysound_priority(keytone_path, 0, 5); /* priority 5 for test */ if (ret < 0) debug_error("keysound play failed with 0x%x", ret); -- 2.7.4