From 010cf35f45f7b6f7a80c9205d37dfbbc0e23be02 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Wed, 28 Sep 2022 10:45:38 +0900 Subject: [PATCH] add wav_player_start_loop_stop_others internal api [Version] 0.3.9 [Issue Type] Internal Change-Id: I0d6f3235eb54ff7fb6c9b22c3129e74a8d703408 --- include/wav_player_internal.h | 30 +++++++++++++++++++++++++++++- include/wav_player_private.h | 2 +- packaging/capi-media-wav-player.spec | 2 +- src/wav_player.c | 4 ++-- src/wav_player_internal.c | 10 ++++++++++ src/wav_player_private.c | 10 +++++----- test/wav_player_test.c | 31 ++++++++++++++++++++++--------- 7 files changed, 70 insertions(+), 19 deletions(-) mode change 100755 => 100644 src/wav_player.c mode change 100755 => 100644 src/wav_player_private.c diff --git a/include/wav_player_internal.h b/include/wav_player_internal.h index 15be664..3a48671 100644 --- a/include/wav_player_internal.h +++ b/include/wav_player_internal.h @@ -59,6 +59,34 @@ extern "C" */ int wav_player_play_simple(const char *path, const char *stream_role); +/** + * @internal + * @brief Plays a WAV file after stopping previous WAV playbacks + * @since_tizen 7.0 + * + * @param[in] path The file path to play + * @param[in] stream_info The sound stream information handle + * @param[in] loop_count The number of times the file should be played (@c 0 indicates infinite loops) + * @param[in] callback The callback function to be invoked when the WAV file is no longer being played + * @param[in] user_data The user data to be passed to the callback function + * @param[out] id The WAV player ID (can be set to @c NULL) + * + * @return @c 0 on success, + * otherwise a negative error value + * @retval #WAV_PLAYER_ERROR_NONE Successful + * @retval #WAV_PLAYER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WAV_PLAYER_ERROR_INVALID_OPERATION Invalid operation + * @retval #WAV_PLAYER_ERROR_FORMAT_NOT_SUPPORTED Not supported format + * @retval #WAV_PLAYER_ERROR_NOT_SUPPORTED_TYPE Not supported stream type + * + */ +int wav_player_start_loop_stop_others(const char *path, + sound_stream_info_h stream_info, + unsigned int loop_count, + wav_player_playback_completed_cb callback, + void *user_data, + int *id); + /** * @} @@ -68,4 +96,4 @@ int wav_player_play_simple(const char *path, const char *stream_role); } #endif -#endif /* __TIZEN_MEDIA_WAV_PLAYER_INTERNAL_H__ */ \ No newline at end of file +#endif /* __TIZEN_MEDIA_WAV_PLAYER_INTERNAL_H__ */ diff --git a/include/wav_player_private.h b/include/wav_player_private.h index 591bd60..cde21c3 100644 --- a/include/wav_player_private.h +++ b/include/wav_player_private.h @@ -36,7 +36,7 @@ extern "C" int _convert_wav_player_error_code(const char *func, int code); int _wav_play_sound(const char *path, sound_stream_info_h stream_info, unsigned int loop_count, - wav_player_playback_completed_cb cb, void *user_data, int *id); + wav_player_playback_completed_cb cb, void *user_data, bool stop_others, int *id); int _wav_play_sound_simple(const char *path, const char *stream_role); int _wav_stop_sound(int id); diff --git a/packaging/capi-media-wav-player.spec b/packaging/capi-media-wav-player.spec index d36f6d1..ef6f885 100755 --- a/packaging/capi-media-wav-player.spec +++ b/packaging/capi-media-wav-player.spec @@ -1,6 +1,6 @@ Name: capi-media-wav-player Summary: A wav player library in Tizen C API -Version: 0.3.8 +Version: 0.3.9 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/wav_player.c b/src/wav_player.c old mode 100755 new mode 100644 index 1f28594..68c4bc6 --- a/src/wav_player.c +++ b/src/wav_player.c @@ -30,13 +30,13 @@ int wav_player_start_new(const char *path, sound_stream_info_h stream_info, wav_player_playback_completed_cb callback, void *user_data, int *id) { - return _wav_play_sound(path, stream_info, 1, callback, user_data, id); + return _wav_play_sound(path, stream_info, 1, callback, user_data, false, id); } int wav_player_start_loop(const char *path, sound_stream_info_h stream_info, unsigned int loop_count, wav_player_playback_completed_cb callback, void *user_data, int *id) { - return _wav_play_sound(path, stream_info, loop_count, callback, user_data, id); + return _wav_play_sound(path, stream_info, loop_count, callback, user_data, false, id); } int wav_player_stop(int id) diff --git a/src/wav_player_internal.c b/src/wav_player_internal.c index 067e9a3..444ba84 100644 --- a/src/wav_player_internal.c +++ b/src/wav_player_internal.c @@ -22,3 +22,13 @@ int wav_player_play_simple(const char *path, const char *stream_role) { return _wav_play_sound_simple(path, stream_role); } + +int wav_player_start_loop_stop_others(const char *path, + sound_stream_info_h stream_info, + unsigned int loop_count, + wav_player_playback_completed_cb callback, + void *user_data, + int *id) +{ + return _wav_play_sound(path, stream_info, loop_count, callback, user_data, true, id); +} diff --git a/src/wav_player_private.c b/src/wav_player_private.c old mode 100755 new mode 100644 index 978ed5d..7b8e048 --- a/src/wav_player_private.c +++ b/src/wav_player_private.c @@ -105,7 +105,7 @@ static void __internal_complete_cb(GDBusConnection *connection, } int _wav_play_sound(const char *path, sound_stream_info_h stream_info, unsigned loop_count, - wav_player_playback_completed_cb callback, void *user_data, int *id) + wav_player_playback_completed_cb callback, void *user_data, bool stop_others, int *id) { int ret = WAV_PLAYER_ERROR_NONE; char m_path[PATH_MAX]; @@ -163,8 +163,8 @@ int _wav_play_sound(const char *path, sound_stream_info_h stream_info, unsigned PA_SOUND_PLAYER_OBJECT_PATH, PA_SOUND_PLAYER_INTERFACE, PA_SOUND_PLAYER_METHOD_NAME_SOUND_PLAY, - g_variant_new("(siisi)", m_path, loop_count == 0 ? -1 : loop_count, - getpid(), stream_type, stream_id), + g_variant_new("(siisib)", m_path, loop_count == 0 ? -1 : loop_count, + getpid(), stream_type, stream_id, (gboolean)stop_others), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err); if (!reply) { LOGE("g_dbus_connection_call_sync error (%s)", err->message); @@ -242,8 +242,8 @@ int _wav_play_sound_simple(const char *path, const char *stream_role) PA_SOUND_PLAYER_OBJECT_PATH, PA_SOUND_PLAYER_INTERFACE, PA_SOUND_PLAYER_METHOD_NAME_SOUND_PLAY, - g_variant_new("(siisi)", m_path, 1, - getpid(), stream_role, -1), + g_variant_new("(siisib)", m_path, 1, + getpid(), stream_role, -1, FALSE), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err); if (!reply) { if (err) { diff --git a/test/wav_player_test.c b/test/wav_player_test.c index 36d1357..d8eac67 100644 --- a/test/wav_player_test.c +++ b/test/wav_player_test.c @@ -43,6 +43,7 @@ void help() " -s, --streamtype stream type (0:media(default), 1:system, 2:notification, 3:voice-information, 4:solo)\n" " -i, --iterate how many times to play\n" " -q, --quickplay play quick\n" + " -o, --stopothers play after stopping others\n" " -h, --help help\n"); } @@ -59,7 +60,7 @@ void stream_focus_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e return; } -void wav_play_test(const char *file_path, int iterate, int stream_type) +void wav_play_test(const char *file_path, int iterate, int stream_type, bool stop_others) { int ret = 0; sound_stream_info_h stream_info; @@ -101,8 +102,13 @@ void wav_play_test(const char *file_path, int iterate, int stream_type) } printf("Play Wav, File Path : %s, Iterate : %d\n", file_path, iterate); - ret = wav_player_start_loop(file_path, stream_info, iterate, _player_stop_cb, (void*)stream_info, &gid); - printf("wav_player_start_loop(id=%d) ret = %d\n", gid, ret); + if (stop_others) { + ret = wav_player_start_loop_stop_others(file_path, stream_info, iterate, _player_stop_cb, (void*)stream_info, &gid); + printf("wav_player_start_loop_stop_others(id=%d) ret = %d\n", gid, ret); + } else { + ret = wav_player_start_loop(file_path, stream_info, iterate, _player_stop_cb, (void*)stream_info, &gid); + printf("wav_player_start_loop(id=%d) ret = %d\n", gid, ret); + } if (ret) { sound_manager_destroy_stream_information(stream_info); return; @@ -155,6 +161,7 @@ int main(int argc, char**argv) int iterate = 1; int stream_type = 0; bool quickplay = false; + bool stop_others = false; char file_path[FILE_PATH_MAX] = DEFAULT_FILE; struct sigaction sig_action; sig_action.sa_handler = __sig_handler; @@ -171,26 +178,32 @@ int main(int argc, char**argv) {"file" , required_argument, 0, 'f'}, {"streamtype" , required_argument, 0, 's'}, {"quickplay" , no_argument, 0, 'q'}, + {"stopothers" , no_argument, 0, 'o'}, + {"help" , no_argument, 0, 'h'}, { 0, 0, 0, 0 } }; - if ((opt = getopt_long(argc, argv, "i:f:s:q", long_options, &opt_idx)) == -1) + if ((opt = getopt_long(argc, argv, "i:f:s:qoh", long_options, &opt_idx)) == -1) break; + printf("opt = %d(%c), opt_idx = %d\n", opt, opt, opt_idx); + switch (opt) { - case 'f': - strncpy(file_path, optarg, FILE_PATH_MAX - 1); - file_path[FILE_PATH_MAX - 1] = '\0'; - break; case 'i': iterate = atoi(optarg); break; + case 'f': + snprintf(file_path, FILE_PATH_MAX, "%s", optarg); + break; case 's': stream_type = atoi(optarg); break; case 'q': quickplay = true; break; + case 'o': + stop_others = true; + break; case 'h': default: help(); @@ -201,7 +214,7 @@ int main(int argc, char**argv) if (quickplay) wav_play_test_quick(file_path); else - wav_play_test(file_path, iterate, stream_type); + wav_play_test(file_path, iterate, stream_type, stop_others); return 0; } -- 2.7.4