2 * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <wav_player.h>
19 #include <wav_player_internal.h>
20 #include <sound_manager.h>
21 #include <sound_manager_internal.h>
29 #define FILE_PATH_MAX 128
30 #define DEFAULT_FILE "/usr/share/sounds/alsa/Front_Center.wav"
32 static GMainLoop *g_mainloop = NULL;
34 static struct sigaction sig_int_old_action;
38 g_message("Usage : ");
39 g_message("wav_player_test [OPTION]\n\n"
40 " -f, --file File path to play\n"
41 " -s, --streamtype Stream type:\n"
42 " 0: media (default)\n"
47 " 5: voice information\n"
51 " 107: solo (internal)\n"
52 " -i, --iterate Number of times to play (default:1)\n"
53 " -q, --quickplay Play quick\n"
54 " -o, --stopothers Play after stopping others\n"
55 " -h, --help Help\n");
58 static void __player_stop_cb(int id, void *user_data)
60 g_message("complete id = %d,%p\n", id, user_data);
61 sound_manager_destroy_stream_information((sound_stream_info_h)user_data);
62 g_main_loop_quit(g_mainloop);
65 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,
66 sound_stream_focus_change_reason_e reason, int sound_behavior, const char *extra_info, void *user_data)
68 g_message("*** FOCUS callback is called, stream_info(%p) ***", stream_info);
70 g_message(" - changed focus: mask(%x), state(%d) (0:released, 1:acquired)", focus_mask, focus_state);
71 g_message(" - change_reason(%d), behavior(0x%x), extra_info(%s), user_data(%p)", reason, sound_behavior, extra_info, user_data);
74 static void __sig_handler(int signo)
76 sigset_t old_mask, all_mask;
77 sigfillset(&all_mask);
78 sigprocmask(SIG_BLOCK, &all_mask, &old_mask);
79 sigprocmask(SIG_SETMASK, &old_mask, NULL);
81 g_message("sig.num(%d)", signo);
86 g_message("stop wav-player");
89 sigaction(SIGINT, &sig_int_old_action, NULL);
97 int wav_play_test(const char *file_path, int iterate, int stream_type, bool stop_others)
100 sound_stream_info_h stream_info;
103 g_message("invalid param, null file_path");
107 if (stream_type >= SOUND_STREAM_TYPE_RINGTONE_CALL) {
108 ret = sound_manager_create_stream_information_internal((sound_stream_type_internal_e)stream_type, __stream_focus_cb, NULL, &stream_info);
110 g_message("failed to create stream info internal");
114 ret = sound_manager_create_stream_information((sound_stream_type_e)stream_type, __stream_focus_cb, NULL, &stream_info);
116 g_message("failed to create stream info");
121 g_message("Play Wav, File Path : %s, Iterate : %d", file_path, iterate);
123 ret = wav_player_start_loop_stop_others(file_path, stream_info, iterate, __player_stop_cb, (void*)stream_info, &gid);
124 g_message("wav_player_start_loop_stop_others(id=%d) ret = %d", gid, ret);
126 ret = wav_player_start_loop(file_path, stream_info, iterate, __player_stop_cb, (void*)stream_info, &gid);
127 g_message("wav_player_start_loop(id=%d) ret = %d", gid, ret);
131 sound_manager_destroy_stream_information(stream_info);
135 g_mainloop = g_main_loop_new(NULL, 0);
136 g_assert(g_mainloop);
138 g_main_loop_run(g_mainloop);
140 g_main_loop_unref(g_mainloop);
145 int wav_play_test_quick(const char *file_path)
150 g_message("invalid file path");
154 g_message("Play Wav, File Path : %s", file_path);
156 ret = wav_player_play_simple(file_path, "system");
157 g_message("wav_player_play_simple() ret = 0x%X", ret);
162 int main(int argc, char**argv)
166 bool quickplay = false;
167 bool stop_others = false;
168 char file_path[FILE_PATH_MAX] = DEFAULT_FILE;
169 struct sigaction sig_action;
170 sig_action.sa_handler = __sig_handler;
171 sig_action.sa_flags = SA_NOCLDSTOP;
172 sigemptyset(&sig_action.sa_mask);
173 sigaction(SIGINT, &sig_action, &sig_int_old_action);
179 static struct option long_options[] = {
180 {"iterate" , required_argument, 0, 'i'},
181 {"file" , required_argument, 0, 'f'},
182 {"streamtype" , required_argument, 0, 's'},
183 {"quickplay" , no_argument, 0, 'q'},
184 {"stopothers" , no_argument, 0, 'o'},
185 {"help" , no_argument, 0, 'h'},
189 if ((opt = getopt_long(argc, argv, "i:f:s:qoh", long_options, &opt_idx)) == -1)
192 g_message("opt = %d(%c), opt_idx = %d", opt, opt, opt_idx);
196 iterate = atoi(optarg);
199 snprintf(file_path, FILE_PATH_MAX, "%s", optarg);
202 stream_type = atoi(optarg);
218 return wav_play_test_quick(file_path);
220 return wav_play_test(file_path, iterate, stream_type, stop_others);