wav_player_test: Add support '-s' option for selecting stream type to play and subscr... 34/87434/1 accepted/tizen/common/20160921.162234 accepted/tizen/ivi/20160922.042635 accepted/tizen/mobile/20160922.042408 accepted/tizen/tv/20160922.042506 accepted/tizen/wearable/20160922.042552 submit/tizen/20160921.041639
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 8 Sep 2016 03:59:26 +0000 (12:59 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 8 Sep 2016 04:04:16 +0000 (13:04 +0900)
Usage :
    wav_player_test [OPTION]
        -f, --file            file path to play
        -s, --streamtype      stream type (0:media(default), 1:system, 2:notification, 3:solo)
        -i, --iterate         how many times to play
        -h, --help            help

[Version] Release 0.1.20
[Profile] Common
[ssue Type] Testsuit

Change-Id: I983338a7fca4b209c6c2ae21a3b701f8aeff49e4
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-wav-player.spec
test/wav_player_test.c

index 5588d45..1758108 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-wav-player
 Summary:    A wav player library in Tizen C API
-Version:    0.1.19
+Version:    0.1.20
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 0a98d86..1bb2313 100644 (file)
 #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");
 }
@@ -51,26 +56,48 @@ void stream_focus_cb(sound_stream_info_h stream_info, sound_stream_focus_change_
        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;
@@ -80,10 +107,39 @@ void wav_play_test(const char* file_path, int iterate)
        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;
@@ -92,10 +148,11 @@ int main(int argc, char**argv)
                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) {
@@ -106,6 +163,9 @@ int main(int argc, char**argv)
                case 'i':
                        iterate = atoi(optarg);
                        break;
+               case 's':
+                       stream_type = atoi(optarg);
+                       break;
                case 'h':
                default:
                        help();
@@ -113,7 +173,7 @@ int main(int argc, char**argv)
                }
        }
 
-       wav_play_test(file_path, iterate);
+       wav_play_test(file_path, iterate, stream_type);
 
        return 0;
 }