#include <stdio.h>
#include <wav_player_internal.h>
#include <sound_manager.h>
+#include <sound_manager_internal.h>
#include <glib.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
+#include <signal.h>
#define FILE_PATH_MAX 128
#define DEFAULT_FILE "/usr/share/sounds/alsa/Front_Center.wav"
static GMainLoop *g_mainloop = NULL;
+static int gid = -1;
+struct sigaction sig_int_old_action;
void help()
{
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:solo)\n"
" -i, --iterate how many times to play\n"
" -h, --help help\n");
}
return;
}
-void wav_play_test(const char* file_path, int iterate)
+void wav_play_test(const char* file_path, int iterate, int stream_type)
{
int ret = 0;
- int id;
int i;
sound_stream_info_h stream_info;
+ sound_stream_type_e type;
- if (iterate <= 0 || file_path == NULL) {
- printf("invalid param, iterate(%d), file_path(%s)\n", iterate, file_path);
+ if (iterate <= 0 || file_path == NULL || (stream_type > 3 || stream_type < 0)) {
+ printf("invalid param, iterate(%d), file_path(%s), stream_type(%d)\n", iterate, file_path, stream_type);
return;
}
- if (sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, stream_focus_cb, NULL, &stream_info)) {
- printf("failed to create stream info\n");
- return;
+ 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_SOLO;
+ break;
+ }
+
+ if (stream_type == 3) {
+ if (sound_manager_create_stream_information_internal(type, stream_focus_cb, NULL, &stream_info)) {
+ printf("failed to create stream info internal\n");
+ return;
+ }
+ } else {
+ if (sound_manager_create_stream_information(type, stream_focus_cb, NULL, &stream_info)) {
+ printf("failed to create stream info\n");
+ return;
+ }
}
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, &id);
- printf("wav_player_start(%d)(id=%d) ret = %d\n", i, id, ret);
+ ret = wav_player_start_loop(file_path, stream_info, iterate, _player_stop_cb, (void*)stream_info, &gid);
+ printf("wav_player_start(%d)(id=%d) ret = %d\n", i, gid, ret);
if (ret) {
sound_manager_destroy_stream_information(stream_info);
return;
g_main_loop_run(g_mainloop);
}
+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);
+
+ 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;
+ }
+}
+
int main(int argc, char**argv)
{
int iterate = 1;
+ int stream_type = 0;
char file_path[FILE_PATH_MAX] = DEFAULT_FILE;
+ struct sigaction sig_action;
+ sig_action.sa_handler = __sig_handler;
+ sig_action.sa_flags = SA_NOCLDSTOP;
+ sigemptyset(&sig_action.sa_mask);
+ sigaction(SIGINT, &sig_action, &sig_int_old_action);
while (1) {
int opt;
static struct option long_options[] = {
{"iterate" , required_argument, 0, 'i'},
{"file" , required_argument, 0, 'f'},
+ {"streamtype" , required_argument, 0, 's'},
{ 0, 0, 0, 0 }
};
- if ((opt = getopt_long(argc, argv, "i:f:", long_options, &opt_idx)) == -1)
+ if ((opt = getopt_long(argc, argv, "i:f:s:", long_options, &opt_idx)) == -1)
break;
switch (opt) {
case 'i':
iterate = atoi(optarg);
break;
+ case 's':
+ stream_type = atoi(optarg);
+ break;
case 'h':
default:
help();
}
}
- wav_play_test(file_path, iterate);
+ wav_play_test(file_path, iterate, stream_type);
return 0;
}