From 89a9431273af74e4922adf221d11774068a40c84 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Mon, 21 Aug 2023 13:59:18 +0900 Subject: [PATCH] Fix GlobalVariable violation SAM Score: 4.68 -> 4.95 GV: 3.33 -> 5 + fix build warning, minor refactoring [Version] 0.3.12 [Issue Type] SAM Change-Id: I324fbeb1a03601db2a78937fae7ef417e93b359a --- packaging/capi-media-wav-player.spec | 2 +- test/wav_player_test.c | 169 ++++++++++++++++++----------------- 2 files changed, 86 insertions(+), 85 deletions(-) diff --git a/packaging/capi-media-wav-player.spec b/packaging/capi-media-wav-player.spec index 051b5c3..961133d 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.11 +Version: 0.3.12 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/test/wav_player_test.c b/test/wav_player_test.c index d8eac67..6a0c0d0 100644 --- a/test/wav_player_test.c +++ b/test/wav_player_test.c @@ -14,8 +14,6 @@ * limitations under the License. */ - - #include #include #include @@ -33,127 +31,132 @@ static GMainLoop *g_mainloop = NULL; static int gid = -1; -struct sigaction sig_int_old_action; +static struct sigaction sig_int_old_action; -void help() +void help(void) { - printf("Usage : "); - printf("wav_player_test [OPTION]\n\n" - " -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" - " -o, --stopothers play after stopping others\n" - " -h, --help help\n"); + g_message("Usage : "); + g_message("wav_player_test [OPTION]\n\n" + " -f, --file File path to play\n" + " -s, --streamtype Stream type:\n" + " 0: media (default)\n" + " 1: system\n" + " 2: alarm\n" + " 3: notification\n" + " 4: emergency\n" + " 5: voice information\n" + " 7: ringtone voip\n" + " 8: voip\n" + " 9: ringtone voip\n" + " 107: solo (internal)\n" + " -i, --iterate Number of times to play (default:1)\n" + " -q, --quickplay Play quick\n" + " -o, --stopothers Play after stopping others\n" + " -h, --help Help\n"); } -void _player_stop_cb(int id, void *user_data) +static void __player_stop_cb(int id, void *user_data) { - printf("complete id = %d,%p\n", id, user_data); + g_message("complete id = %d,%p\n", id, user_data); sound_manager_destroy_stream_information((sound_stream_info_h)user_data); g_main_loop_quit(g_mainloop); } -void stream_focus_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, +static void __stream_focus_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason, int sound_behavior, const char *extra_info, void *user_data) { - return; + g_message("*** FOCUS callback is called, stream_info(%p) ***", stream_info); + + g_message(" - changed focus: mask(%x), state(%d) (0:released, 1:acquired)", focus_mask, focus_state); + g_message(" - change_reason(%d), behavior(0x%x), extra_info(%s), user_data(%p)", reason, sound_behavior, extra_info, user_data); } -void wav_play_test(const char *file_path, int iterate, int stream_type, bool stop_others) +static void __sig_handler(int signo) { - int ret = 0; - sound_stream_info_h stream_info; - sound_stream_type_e type; + sigset_t old_mask, all_mask; + sigfillset(&all_mask); + sigprocmask(SIG_BLOCK, &all_mask, &old_mask); + sigprocmask(SIG_SETMASK, &old_mask, NULL); - if (file_path == NULL || (stream_type > 4 || stream_type < 0)) { - printf("invalid param, file_path(%s), stream_type(%d)\n", file_path, stream_type); - return; - } + g_message("sig.num(%d)", signo); - switch (stream_type) { - case 0: - type = SOUND_STREAM_TYPE_MEDIA; - break; - case 1: - type = SOUND_STREAM_TYPE_SYSTEM; - break; - case 2: - type = SOUND_STREAM_TYPE_NOTIFICATION; - break; - case 3: - type = SOUND_STREAM_TYPE_VOICE_INFORMATION; + switch (signo) { + case SIGINT: + if (gid > -1) { + g_message("stop wav-player"); + wav_player_stop(gid); + } + sigaction(SIGINT, &sig_int_old_action, NULL); + raise(signo); break; - case 4: - type = SOUND_STREAM_TYPE_SOLO; + default: break; } +} + +int wav_play_test(const char *file_path, int iterate, int stream_type, bool stop_others) +{ + int ret = 0; + sound_stream_info_h stream_info; - if (stream_type == 4) { - if (sound_manager_create_stream_information_internal(type, stream_focus_cb, NULL, &stream_info)) { - printf("failed to create stream info internal\n"); - return; + if (!file_path) { + g_message("invalid param, null file_path"); + return -1; + } + + if (stream_type >= SOUND_STREAM_TYPE_RINGTONE_CALL) { + ret = sound_manager_create_stream_information_internal((sound_stream_type_internal_e)stream_type, __stream_focus_cb, NULL, &stream_info); + if (ret) { + g_message("failed to create stream info internal"); + return ret; } } else { - if (sound_manager_create_stream_information(type, stream_focus_cb, NULL, &stream_info)) { - printf("failed to create stream info\n"); - return; + ret = sound_manager_create_stream_information((sound_stream_type_e)stream_type, __stream_focus_cb, NULL, &stream_info); + if (ret) { + g_message("failed to create stream info"); + return ret; } } - printf("Play Wav, File Path : %s, Iterate : %d\n", file_path, iterate); + g_message("Play Wav, File Path : %s, Iterate : %d", file_path, iterate); 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); + ret = wav_player_start_loop_stop_others(file_path, stream_info, iterate, __player_stop_cb, (void*)stream_info, &gid); + g_message("wav_player_start_loop_stop_others(id=%d) ret = %d", 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); + ret = wav_player_start_loop(file_path, stream_info, iterate, __player_stop_cb, (void*)stream_info, &gid); + g_message("wav_player_start_loop(id=%d) ret = %d", gid, ret); } + if (ret) { sound_manager_destroy_stream_information(stream_info); - return; + return ret; } g_mainloop = g_main_loop_new(NULL, 0); + g_assert(g_mainloop); + g_main_loop_run(g_mainloop); + + g_main_loop_unref(g_mainloop); + + return ret; } -void wav_play_test_quick(const char *file_path) +int wav_play_test_quick(const char *file_path) { int ret = 0; - if (file_path == NULL) { - printf("invalid file path\n"); - return; + if (!file_path) { + g_message("invalid file path"); + return -1; } - printf("Play Wav, File Path : %s\n", file_path); + g_message("Play Wav, File Path : %s", 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; - sigfillset(&all_mask); - sigprocmask(SIG_BLOCK, &all_mask, &old_mask); - sigprocmask(SIG_SETMASK, &old_mask, NULL); + g_message("wav_player_play_simple() ret = 0x%X", ret); - printf("sig.num(%d)\n", signo); - - switch (signo) { - case SIGINT: - if (gid > -1) { - printf("stop wav-player\n"); - wav_player_stop(gid); - } - sigaction(SIGINT, &sig_int_old_action, NULL); - raise(signo); - break; - default: - break; - } + return ret; } int main(int argc, char**argv) @@ -186,7 +189,7 @@ int main(int argc, char**argv) 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); + g_message("opt = %d(%c), opt_idx = %d", opt, opt, opt_idx); switch (opt) { case 'i': @@ -212,9 +215,7 @@ int main(int argc, char**argv) } if (quickplay) - wav_play_test_quick(file_path); - else - wav_play_test(file_path, iterate, stream_type, stop_others); + return wav_play_test_quick(file_path); - return 0; + return wav_play_test(file_path, iterate, stream_type, stop_others); } -- 2.7.4