From: Seungbae Shin Date: Fri, 4 Dec 2020 06:35:49 +0000 (+0900) Subject: Add wav_player_play_simple internal function to support boot-animation case X-Git-Tag: accepted/tizen/6.0/unified/20201209.211153^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7c757c0f85c368666ad70c6010ecf6ca59289b40;p=platform%2Fcore%2Fapi%2Fwav-player.git Add wav_player_play_simple internal function to support boot-animation case [Version] 0.3.4 [Issue Type] Improvement Change-Id: I76a890dc56b6d45e874fc55ca3b2640354334513 (cherry picked from commit 4e44b1bf043b8aa7421911744b0c6cb254015a08) --- diff --git a/include/wav_player_internal.h b/include/wav_player_internal.h new file mode 100644 index 0000000..15be664 --- /dev/null +++ b/include/wav_player_internal.h @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2020 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 __TIZEN_MEDIA_WAV_PLAYER_INTERNAL_H__ +#define __TIZEN_MEDIA_WAV_PLAYER_INTERNAL_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + +/** + * @file wav_player_internal.h + * @brief This file contains the WAV player internal API + */ + +/** + * @addtogroup CAPI_MEDIA_WAV_PLAYER_MODULE + * @{ + */ + +/** + * @internal + * @brief Plays a WAV file by simple + * @since_tizen 6.0 + * + * + * @param[in] path The file path to play + * @param[in] stream_role The sound stream role + * + * @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_play_simple(const char *path, const char *stream_role); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_MEDIA_WAV_PLAYER_INTERNAL_H__ */ \ No newline at end of file diff --git a/include/wav_player_private.h b/include/wav_player_private.h index 83772b1..591bd60 100644 --- a/include/wav_player_private.h +++ b/include/wav_player_private.h @@ -37,6 +37,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); +int _wav_play_sound_simple(const char *path, const char *stream_role); int _wav_stop_sound(int id); #ifdef __cplusplus diff --git a/packaging/capi-media-wav-player.spec b/packaging/capi-media-wav-player.spec index dc5fa32..26a716f 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.3 +Version: 0.3.4 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/wav_player_internal.c b/src/wav_player_internal.c new file mode 100644 index 0000000..067e9a3 --- /dev/null +++ b/src/wav_player_internal.c @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2020 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. +*/ + +#define LOG_TAG "TIZEN_N_WAV_PLAYER" + +#include "wav_player_private.h" + +int wav_player_play_simple(const char *path, const char *stream_role) +{ + return _wav_play_sound_simple(path, stream_role); +} diff --git a/src/wav_player_private.c b/src/wav_player_private.c index 8de2dff..bf97425 100755 --- a/src/wav_player_private.c +++ b/src/wav_player_private.c @@ -198,6 +198,67 @@ int _wav_play_sound(const char *path, sound_stream_info_h stream_info, unsigned return WAV_PLAYER_ERROR_NONE; } +int _wav_play_sound_simple(const char *path, const char *stream_role) +{ + int ret = WAV_PLAYER_ERROR_NONE; + char m_path[PATH_MAX]; + int handle; + GError *err = NULL; + GVariant *reply = NULL; + GDBusConnection *conn = NULL; + + if (!path || !stream_role) { + LOGE("invalid params path(%p), stream_role(%p)", path, stream_role); + return WAV_PLAYER_ERROR_INVALID_PARAMETER; + } + + LOGI("path(%s), stream_role(%s)", path, stream_role); + + /* FIXME : need extraction of duplicated path validation code */ + m_path[0] = '\0'; + if (path[0] != '/' && getcwd(m_path, PATH_MAX) != NULL) + strncat(m_path, "/", PATH_MAX - strlen(m_path) - 1); + + strncat(m_path, path, PATH_MAX - strlen(m_path) - 1); + if (access(m_path, R_OK) != 0) { + char str_error[256]; + strerror_r(errno, str_error, sizeof(str_error)); + LOGE("file [%s] doesn't exists : [%s][%d]", m_path, str_error, errno); + return WAV_PLAYER_ERROR_INVALID_OPERATION; + } + + if (!(conn = __get_dbus_connection())) + return WAV_PLAYER_ERROR_INVALID_OPERATION; + + reply = g_dbus_connection_call_sync(conn, PA_BUS_NAME, + 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), + NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err); + if (!reply) { + if (err) { + LOGE("g_dbus_connection_call_sync error (%s)", err->message); + ret = __convert_dbus_error(err->message); + g_error_free(err); + } else { + ret = WAV_PLAYER_ERROR_INVALID_OPERATION; + } + goto finish; + } + + g_variant_get(reply, "(i)", &handle); + g_variant_unref(reply); + + LOGI("handle : %d", handle); + +finish: + g_object_unref(conn); + + return ret; +} + int _wav_stop_sound(int id) { GDBusConnection *conn = NULL; diff --git a/test/wav_player_test.c b/test/wav_player_test.c index 76cd9e9..36d1357 100644 --- a/test/wav_player_test.c +++ b/test/wav_player_test.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,7 @@ void help() " -f, --file file path to play\n" " -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" " -h, --help help\n"); } @@ -57,7 +59,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) { int ret = 0; sound_stream_info_h stream_info; @@ -110,6 +112,21 @@ void wav_play_test(const char* file_path, int iterate, int stream_type) g_main_loop_run(g_mainloop); } +void wav_play_test_quick(const char *file_path) +{ + int ret = 0; + + if (file_path == NULL) { + printf("invalid file path\n"); + return; + } + + printf("Play Wav, File Path : %s\n", file_path); + + ret = wav_player_play_simple(file_path, "system"); + printf("wav_player_play_simple() ret = 0x%X\n", ret); +} + void __sig_handler(int signo) { sigset_t old_mask, all_mask; @@ -137,6 +154,7 @@ int main(int argc, char**argv) { int iterate = 1; int stream_type = 0; + bool quickplay = false; char file_path[FILE_PATH_MAX] = DEFAULT_FILE; struct sigaction sig_action; sig_action.sa_handler = __sig_handler; @@ -152,10 +170,11 @@ int main(int argc, char**argv) {"iterate" , required_argument, 0, 'i'}, {"file" , required_argument, 0, 'f'}, {"streamtype" , required_argument, 0, 's'}, + {"quickplay" , no_argument, 0, 'q'}, { 0, 0, 0, 0 } }; - if ((opt = getopt_long(argc, argv, "i:f:s:", long_options, &opt_idx)) == -1) + if ((opt = getopt_long(argc, argv, "i:f:s:q", long_options, &opt_idx)) == -1) break; switch (opt) { @@ -169,6 +188,9 @@ int main(int argc, char**argv) case 's': stream_type = atoi(optarg); break; + case 'q': + quickplay = true; + break; case 'h': default: help(); @@ -176,7 +198,10 @@ int main(int argc, char**argv) } } - wav_play_test(file_path, iterate, stream_type); + if (quickplay) + wav_play_test_quick(file_path); + else + wav_play_test(file_path, iterate, stream_type); return 0; }