Add mm_sound_stop_keysound()
[platform/core/multimedia/libmm-sound.git] / testsuite / mm_sound_testsuite_simple.c
1 /*
2  * libmm-sound
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungbae Shin <seungbae.shin@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25
26 #define debug_log(msg, args...) fprintf(stderr, msg, ##args)
27 #define debug_error(msg, args...) fprintf(stderr, msg, ##args)
28 #define MAX_STRING_LEN 256
29 #define MAX_PATH_LEN            1024
30 #define MIN_TONE_PLAY_TIME 300
31 #include "../include/mm_sound.h"
32 #include "../include/mm_sound_focus.h"
33 #include "../include/mm_sound_common.h"
34 #include "../include/mm_sound_private.h"
35 #include "../include/mm_sound_pa_client.h"
36
37 #include <glib.h>
38
39 #include <pthread.h>
40
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <unistd.h>
44 #include <dirent.h>
45 #include <vconf.h>
46
47 #define POWERON_FILE    "/usr/share/keysound/poweron.ogg"
48 #define KEYTONE_FILE    "/usr/share/sounds/sound-server/Tizen_HW_Touch.ogg"
49 #define KEYTONE_NOTI_FILE       "/usr/share/sounds/alsa/Front_Center.wav"
50
51 enum {
52         CURRENT_STATUS_MAINMENU = 0,
53         CURRENT_STATUS_FILENAME = 1,
54         CURRENT_STATUS_POSITION = 2,
55         CURRENT_STATUS_DIRNAME = 3,
56 };
57
58 static int g_focus_id = 0;
59 static int g_menu_state = CURRENT_STATUS_MAINMENU;
60 static volume_type_t g_volume_type = VOLUME_TYPE_MEDIA;
61 static unsigned int g_volume_value;
62 static GIOChannel *stdin_channel;
63 static char g_file_name[MAX_STRING_LEN];
64 static char g_dir_name[MAX_PATH_LEN];
65 static int g_focus_watch_index = -1;
66 static GMainLoop* g_loop;
67 static unsigned int g_subs_id_test, g_subs_id_volume, g_subs_id_device_conn, g_subs_id_device_state;
68
69 static void interpret(char *buf);
70 gboolean timeout_menu_display(void *data);
71 gboolean timeout_quit_program(void *data);
72 gboolean input(GIOChannel *channel);
73
74 void mycallback(void *data, int id)
75 {
76         char *str = (char*)data;
77         if (data != NULL)
78                 debug_log("mycallback called (user data:%s ,id:%d)", str, id);
79         else
80                 debug_log("mycallback called (no user data)");
81 }
82 static volatile char test_callback_done;
83 void test_callback(void *data, int id)
84 {
85         debug_log("test_callback is called");
86         test_callback_done = 1;
87 }
88 void mm_sound_test_cb1(int a, void *user_data)
89 {
90         debug_log("dbus test user callback called: param(%d), userdata(%d)", a, (int)user_data);
91         g_print("my callback pid : %u  tid : %ld\n", getpid(), pthread_self());
92 }
93 void device_connected_cb(MMSoundDevice_t device_h, bool is_connected, void *user_data)
94 {
95         int ret = 0;
96         mm_sound_device_type_e device_type = 0;
97         mm_sound_device_io_direction_e io_direction = 0;
98         mm_sound_device_state_e state = 0;
99         int id = 0;
100         int vendor_id = -1, product_id = -1;
101         char *name = NULL;
102
103         debug_log("*** device_connected_cb is called, device_h[%p], is_connected[%d], user_data[%p]", device_h, is_connected, user_data);
104         ret = mm_sound_get_device_type(device_h, &device_type);
105         if (ret)
106                 debug_error("failed to mm_sound_get_device_type()");
107         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
108         if (ret)
109                 debug_error("failed to mm_sound_get_device_io_direction()");
110         ret = mm_sound_get_device_state(device_h, &state);
111         if (ret)
112                 debug_error("failed to mm_sound_get_device_state()");
113         ret = mm_sound_get_device_id(device_h, &id);
114         if (ret)
115                 debug_error("failed to mm_sound_get_device_id()");
116         ret = mm_sound_get_device_name(device_h, &name);
117         if (ret)
118                 debug_error("failed to mm_sound_get_device_name()");
119         ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
120         if (ret)
121                 debug_error("failed to mm_sound_get_device_vendor_id()");
122         ret = mm_sound_get_device_product_id(device_h, &product_id);
123         if (ret)
124                 debug_error("failed to mm_sound_get_device_produt_id()");
125         debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s], "
126                         "vendor-id(%04x) product-id(%04x)",
127                         device_type, id, io_direction, state, name, vendor_id, product_id);
128 }
129 void device_state_changed_cb(MMSoundDevice_t device_h, mm_sound_device_state_e new_state, void *user_data)
130 {
131         int ret = 0;
132         mm_sound_device_type_e device_type = 0;
133         mm_sound_device_io_direction_e io_direction = 0;
134         mm_sound_device_state_e state = 0;
135         int id = 0;
136         char *name = NULL;
137         int vendor_id = -1, product_id = -1;
138
139         debug_log("*** device_state_changed_cb is called, device_h[%p], state[%d], user_data[%p]", device_h, new_state, user_data);
140         ret = mm_sound_get_device_type(device_h, &device_type);
141         if (ret)
142                 debug_error("failed to mm_sound_get_device_type()");
143         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
144         if (ret)
145                 debug_error("failed to mm_sound_get_device_io_direction()");
146         ret = mm_sound_get_device_state(device_h, &state);
147         if (ret)
148                 debug_error("failed to mm_sound_get_device_state()");
149         ret = mm_sound_get_device_id(device_h, &id);
150         if (ret)
151                 debug_error("failed to mm_sound_get_device_id()");
152         ret = mm_sound_get_device_name(device_h, &name);
153         if (ret)
154                 debug_error("failed to mm_sound_get_device_name()");
155         ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
156         if (ret)
157                 debug_error("failed to mm_sound_get_device_vendor_id()");
158         ret = mm_sound_get_device_product_id(device_h, &product_id);
159         if (ret)
160                 debug_error("failed to mm_sound_get_device_produt_id()");
161         debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s], "
162                         "vendor-id(%04x) product-id(%04x)",
163                         device_type, id, io_direction, state, name, vendor_id, product_id);
164 }
165
166 void focus_cb(int index, mm_sound_focus_type_e type, mm_sound_focus_state_e state, const char *reason_for_change, int option, const char *ext_info, void *user_data)
167 {
168         char *_state = NULL;
169         if (state == FOCUS_IS_RELEASED)
170                 _state = "RELEASED";
171         else
172                 _state = "ACQUIRED";
173         debug_log("*** focus_cb is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], option[0x%x], ext_info[%s], user_data[%s]",
174                         index, type, _state, reason_for_change, option, ext_info, (char*)user_data);
175 }
176
177 void focus_watch_cb(int index, mm_sound_focus_type_e type, mm_sound_focus_state_e state, const char *reason_for_change, const char *ext_info, void *user_data)
178 {
179         char *_state = NULL;
180         if (state == FOCUS_IS_RELEASED)
181                 _state = "RELEASED";
182         else
183                 _state = "ACQUIRED";
184         debug_log("*** focus_watch_cb is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], ext_info[%s], user_data[%s]",
185                         index, type, _state, reason_for_change, ext_info, (char*)user_data);
186 }
187
188 void quit_program()
189 {
190         g_main_loop_quit(g_loop);
191 }
192
193 static void displaymenu()
194 {
195         if (g_menu_state == CURRENT_STATUS_MAINMENU) {
196                 g_print("==================================================================\n");
197                 g_print("       Sound Play APIs\n");
198                 g_print("==================================================================\n");
199                 g_print("k : Play Keysound     \t");
200                 g_print("ks : Stop Keysound     \t");
201                 g_print("kn : Play Keysound (Notification) \t");
202                 g_print("ksn : Stop Keysound (Notification)    \t");
203                 g_print("ksa : Stop Keysound (All)    \n");
204                 g_print("as : play sound with stream type\n");
205                 g_print("FS : Play DTMF with stream type\t");
206                 g_print("b : Play directory\n");
207                 g_print("s : Stop play     \n");
208                 g_print("==================================================================\n");
209                 g_print("       Volume APIs\n");
210                 g_print("==================================================================\n");
211                 g_print("q : Get media    \t");
212                 g_print("w : Inc. media   \t");
213                 g_print("e : Dec. media   \n");
214                 g_print("r : Get system   \t");
215                 g_print("t : Inc. system  \t");
216                 g_print("y : Dec. system  \n");
217                 g_print("g : Get voice   \t");
218                 g_print("h : Inc. voice  \t");
219                 g_print("j : Dec. voice  \n");
220                 g_print("==================================================================\n");
221                 g_print("       Audio route APIs\n");
222                 g_print("==================================================================\n");
223                 g_print("u : Foreach Available Routes \t");
224                 g_print("i : Get Active Devices     \n");
225                 g_print("o : Add Available Routes Callback   \t");
226                 g_print("O : Remove Available Routes Callback   \n");
227                 g_print("p : Add Active Route Callback\t");
228                 g_print("P : Remove Active Route Callback \n");
229                 g_print("{ : Get BT A2DP Status\n");
230                 g_print("} : Set Active Route\n");
231                 g_print("==================================================================\n");
232                 g_print("       Audio device APIs\n");
233                 g_print("==================================================================\n");
234                 g_print("L : Get current list of connected devices \n");
235                 g_print("I : Get device by id \n");
236                 g_print("C : Add device connected callback \t");
237                 g_print("D : Remove device connected callback \n");
238                 g_print("Q : Add device state. changed callback \t");
239                 g_print("W : Remove device state. changed callback \n");
240                 g_print("==================================================================\n");
241                 g_print("       Focus APIs\n");
242                 g_print("==================================================================\n");
243                 g_print("SF : Set Focus Callback\t");
244                 g_print("UF : Unset Focus Callback\n");
245                 g_print("DF : Disable Auto Focus Reacquirement\t");
246                 g_print("AF : Acquire Focus\t");
247                 g_print("RF : Release Focus\n");
248                 g_print("WS : Set Focus Watch Callback\t");
249                 g_print("WU : Unset Focus Watch Callback\n");
250                 g_print("==================================================================\n");
251                 g_print("d : Input Directory \t");
252                 g_print("f : Input File name \t");
253                 g_print("x : Exit Program \n");
254                 g_print("==================================================================\n");
255                 g_print(" Input command >>>>>>>> ");
256         } else if (g_menu_state == CURRENT_STATUS_FILENAME) {
257                 g_print(">>>>Input file name to play : ");
258         } else if (g_menu_state == CURRENT_STATUS_DIRNAME) {
259                         g_print(">>>>Input directory which contain audio files : ");
260         } else {
261                 g_print("**** Unknown status.\n");
262                 quit_program();
263         }
264 }
265
266 gboolean timeout_menu_display(void* data)
267 {
268         displaymenu();
269         return FALSE;
270 }
271
272 gboolean timeout_quit_program(void* data)
273 {
274         quit_program();
275         return FALSE;
276 }
277
278 gboolean input(GIOChannel *channel)
279 {
280         GError *err = NULL;
281         gchar *buf = NULL;
282         gsize length = 0;
283
284         if (g_io_channel_read_line(channel, &buf, &length, NULL, &err) == G_IO_STATUS_NORMAL) {
285                 if (length > 1) {
286                         g_strstrip(buf);
287                         interpret(buf);
288                 }
289                 g_free(buf);
290         }
291
292         return TRUE;
293 }
294
295
296 static void input_filename(char *filename)
297 {
298         MMSOUND_STRNCPY(g_file_name, filename, MAX_STRING_LEN);
299         g_print("\nThe input filename is '%s' \n\n", g_file_name);
300
301 }
302
303 static void input_dirname(char *dirname)
304 {
305         MMSOUND_STRNCPY(g_dir_name, dirname, MAX_PATH_LEN);
306         g_print("\nThe input directory is '%s' \n\n", g_dir_name);
307 }
308
309 static void interpret(char *cmd)
310 {
311         int ret = 0;
312         static int handle = -1;
313
314         switch (g_menu_state) {
315         case CURRENT_STATUS_MAINMENU:
316                 if (strncmp(cmd, "SF", 2) == 0) {
317                         int ret = 0;
318                         char input_string[128];
319                         char select;
320                         char *stream_type = NULL;
321                         const char *user_data = "this is user data";
322
323                         fflush(stdin);
324                         g_print("1. Media\n");
325                         g_print("2. Alarm\n");
326                         g_print("3. Notification\n");
327                         g_print("4. Emergency\n");
328                         g_print("5. Voice Information\n");
329                         g_print("6. Ringtone\n");
330                         g_print("7. Ringtone Call\n");
331                         g_print("8. VOIP\n");
332                         g_print("0. Voice Recognition\n");
333                         g_print("> stream type: ");
334
335                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
336                                 select = input_string[0];
337
338                                 if (select == '1')
339                                         stream_type = "media";
340                                 else if (select == '2')
341                                         stream_type = "alarm";
342                                 else if (select == '3')
343                                         stream_type = "notification";
344                                 else if (select == '4')
345                                         stream_type = "emergency";
346                                 else if (select == '5')
347                                         stream_type = "voice-information";
348                                 else if (select == '6')
349                                         stream_type = "ringtone";
350                                 else if (select == '7')
351                                         stream_type = "ringtone-call";
352                                 else if (select == '8')
353                                         stream_type = "voip";
354                                 else if (select == '0')
355                                         stream_type = "voice-recognition";
356
357                                 ret = mm_sound_register_focus(stream_type, focus_cb, (void*)user_data, &g_focus_id);
358                                 if (ret)
359                                         g_print("failed to mm_sound_register_focus(), ret[0x%x]\n", ret);
360                                 else
361                                         g_print("id[%d], stream_type[%s], callback fun[%p]\n", g_focus_id, stream_type, focus_cb);
362                         } else {
363                                 g_print("### fgets return  NULL\n");
364                         }
365                 } else if (strncmp(cmd, "UF", 2) == 0) {
366                         int ret = 0;
367
368                         ret = mm_sound_unregister_focus(g_focus_id);
369                         if (ret)
370                                 g_print("failed to mm_sound_unregister_focus(), ret[0x%x]\n", ret);
371                 } else if (strncmp(cmd, "DF", 2) == 0) {
372                         int ret = 0;
373                         char input_string[128];
374                         char flag_1, flag_2;
375                         int id = 2;
376                         bool reacquisition = true;
377                         fflush(stdin);
378                         g_print("1. enable auto reacquirement\n");
379                         g_print("2. disable auto reacquirement\n");
380                         g_print("> select id and option: (eg. 0 1)");
381                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
382                                 flag_1 = input_string[0];
383                                 flag_2 = input_string[2];
384
385                                 if (flag_1 == '0')
386                                         id = 0;
387                                 else if (flag_1 == '1')
388                                         id = 1;
389                                 else if (flag_1 == '2')
390                                         id = 2;
391
392                                 if (flag_2 == '1')
393                                         reacquisition = true;
394                                 else if (flag_2 == '2')
395                                         reacquisition = false;
396
397                                 ret = mm_sound_set_focus_reacquisition(id, reacquisition);
398                                 if (ret)
399                                         g_print("failed to mm_sound_disable_focus_reacquirement(), ret[0x%x]\n", ret);
400                         } else {
401                                 g_print("### fgets return  NULL\n");
402                         }
403                 } else if (strncmp(cmd, "AF", 2) == 0) {
404                         int ret = 0;
405                         char input_string[128];
406                         char flag_1, flag_2;
407                         int id = 0;
408                         mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
409                         fflush(stdin);
410                         g_print("1. focus for playback\n");
411                         g_print("2. focus for recording\n");
412                         g_print("3. focus for both\n");
413                         g_print("> select id and focus_type: (eg. 0 1)");
414                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
415                                 flag_1 = input_string[0];
416                                 flag_2 = input_string[2];
417
418                                 if (flag_1 == '0')
419                                         id = 0;
420                                 else if (flag_1 == '1')
421                                         id = 1;
422
423                                 if (flag_2 == '1')
424                                         type = FOCUS_FOR_PLAYBACK;
425                                 else if (flag_2 == '2')
426                                         type = FOCUS_FOR_CAPTURE;
427
428                                 ret = mm_sound_acquire_focus(id, type, "additional_info. for acquire");
429                                 if (ret)
430                                         g_print("failed to mm_sound_acquire_focus(), ret[0x%x]\n", ret);
431
432                         } else {
433                                 g_print("### fgets return  NULL\n");
434                         }
435
436                 } else if (strncmp(cmd, "RF", 2) == 0) {
437                         int ret = 0;
438                         char input_string[128];
439                         char flag_1, flag_2;
440                         int id = 2;
441                         mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
442                         fflush(stdin);
443                         g_print("1. focus for playback\n");
444                         g_print("2. focus for recording\n");
445                         g_print("3. focus for all\n");
446                         g_print("> select id and focus_type: (eg. 0 1)");
447                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
448                                 flag_1 = input_string[0];
449                                 flag_2 = input_string[2];
450
451                                 if (flag_1 == '0')
452                                         id = 0;
453                                 else if (flag_1 == '1')
454                                         id = 1;
455
456                                 if (flag_2 == '1')
457                                         type = FOCUS_FOR_PLAYBACK;
458                                 else if (flag_2 == '2')
459                                         type = FOCUS_FOR_CAPTURE;
460
461                                 ret = mm_sound_release_focus(id, type, "additional_info. for release");
462                                 if (ret)
463                                         g_print("failed to mm_sound_release_focus(), ret[0x%x]\n", ret);
464
465                         } else {
466                                 g_print("### fgets return  NULL\n");
467                         }
468
469                 } else if (strncmp(cmd, "WS", 2) == 0) {
470                         int ret = 0;
471                         char input_string[128];
472                         char flag_1;
473                         int type = 1;
474                         const char *user_data = "this is user data for watch";
475
476                         fflush(stdin);
477                         g_print("1. playback\n");
478                         g_print("2. recording\n");
479                         g_print("3. both\n");
480                         g_print("> select interest focus type:");
481
482                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
483                                 flag_1 = input_string[0];
484
485                                 if (flag_1 == '1')
486                                         type = 1;
487                                 else if (flag_1 == '2')
488                                         type = 2;
489                                 else if (flag_1 == '3')
490                                         type = 3;
491
492                                 ret = mm_sound_set_focus_watch_callback(type, focus_watch_cb, (void*)user_data, &g_focus_watch_index);
493                                 if (ret)
494                                         g_print("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
495                                 else
496                                         g_print("index[%d], type[%d], callback fun[%p]\n", g_focus_watch_index, type, focus_watch_cb);
497                         } else {
498                                 g_print("### fgets return  NULL\n");
499                         }
500
501                 } else if (strncmp(cmd, "WU", 2) == 0) {
502                         int ret = 0;
503                         ret = mm_sound_unset_focus_watch_callback(g_focus_watch_index);
504                         if (ret)
505                                 g_print("failed to mm_sound_unset_focus_watch_callback(), ret[0x%x]\n", ret);
506                 } else if (strncmp(cmd, "ksn", 3) == 0) {
507                         ret = mm_sound_stop_keysound(KEYTONE_NOTI_FILE);
508                         if (ret < 0)
509                                 debug_error("keysound stop(noti) failed with 0x%x", ret);
510                 } else if (strncmp(cmd, "ksa", 3) == 0) {
511                         ret = mm_sound_stop_keysound(NULL);
512                         if (ret < 0)
513                                 debug_error("keysound stop(all) failed with 0x%x", ret);
514                 } else if (strncmp(cmd, "kn", 2) == 0) {
515                         ret = mm_sound_play_keysound(KEYTONE_NOTI_FILE, VOLUME_TYPE_NOTIFICATION);
516                         if (ret < 0)
517                                 debug_error("keysound play(noti) failed with 0x%x", ret);
518                 } else if (strncmp(cmd, "ks", 2) == 0) {
519                         ret = mm_sound_stop_keysound(KEYTONE_FILE);
520                         if (ret < 0)
521                                 debug_error("keysound stop failed with 0x%x", ret);
522                 } else if (strncmp(cmd, "k", 1) == 0) {
523                         ret = mm_sound_play_keysound(KEYTONE_FILE, 0);
524                         if (ret < 0)
525                                 debug_error("keysound play failed with 0x%x", ret);
526                 } else if (strcmp(cmd, "dbus-m") == 0) {
527                         int ret = 0;
528                         int a = 3;
529                         int b = 4;
530                         int result_val = 0;
531                         g_print("dbus method test call\n");
532                         ret = mm_sound_test(a, b, &result_val);
533                         if (ret)
534                                 g_print("failed to mm_sound_test(), ret[0x%x]\n", ret);
535                         else
536                                 g_print("Got answer : %d\n", result_val);
537
538                 } else if (strcmp(cmd, "dbus-a") == 0) {
539                         int ret = 0;
540                         int user_data = 3;
541                         g_print("dbus method test add callback\n");
542                         g_print("my testsuite pid : %u  tid : %ld\n", getpid(), pthread_self());
543                         ret = mm_sound_add_test_callback(mm_sound_test_cb1, (void *)user_data, &g_subs_id_test);
544                         if (ret)
545                                 g_print("failed to mm_sound_add_test_callback(), ret[0x%x]\n", ret);
546                         else
547                                 g_print("add test callback success\n");
548
549                 } else if (strcmp(cmd, "dbus-r") == 0) {
550                         int ret = 0;
551                         g_print("dbus method test remove callback\n");
552                         ret = mm_sound_remove_test_callback(g_subs_id_test);
553                         if (ret)
554                                 g_print("failed to mm_sound_remove_test_callback(), ret[0x%x]\n", ret);
555                         else
556                                 g_print("remove test callback success\n");
557
558                 } else if (strncmp(cmd, "q", 1) == 0) {
559                         unsigned int value = 100;
560                         ret = mm_sound_volume_get_value(g_volume_type, &value);
561                         if (ret < 0) {
562                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
563                         } else {
564                                 g_print("*** MEDIA VOLUME : %u ***\n", value);
565                                 g_volume_value = value;
566                         }
567
568                 } else if (strncmp(cmd, "e", 1) == 0) {
569                         unsigned int value = 100;
570                         ret = mm_sound_volume_get_value(g_volume_type, &value);
571                         if (ret < 0) {
572                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
573                         } else {
574                                 if (value != 0)
575                                         value--;
576                                 ret = mm_sound_volume_set_value(g_volume_type, value);
577                                 if (ret < 0)
578                                         debug_log("mm_sound_volume_set_value 0x%x", ret);
579                         }
580
581                 } else if (strncmp(cmd, "r", 1) == 0) {
582                         unsigned int value = 100;
583                         ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
584                         if (ret < 0) {
585                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
586                         } else {
587                                 g_print("*** SYSTEM VOLUME : %u ***\n", value);
588                                 g_volume_value = value;
589                         }
590
591                 } else if (strncmp(cmd, "y", 1) == 0) {
592                         unsigned int value = 100;
593                         ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
594                         if (ret < 0) {
595                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
596                         } else {
597                                 if (value != 0)
598                                         value--;
599
600                                 ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
601                                 if (ret < 0)
602                                         debug_log("mm_sound_volume_set_value 0x%x", ret);
603                                 else
604                                         g_print("Current System volume is %d\n", value);
605                         }
606
607                 } else if (strncmp(cmd, "g", 1) == 0) {
608                         unsigned int value = 100;
609                         ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
610                         if (ret < 0) {
611                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
612                         } else {
613                                 g_print("*** VOICE VOLUME : %u ***\n", value);
614                                 g_volume_value = value;
615                         }
616
617                 } else if (strncmp(cmd, "j", 1) == 0) {
618                         unsigned int value = 100;
619                         ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
620                         if (ret < 0) {
621                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
622                         } else {
623                                 if (value != 0)
624                                         value--;
625
626                                 ret = mm_sound_volume_set_value(VOLUME_TYPE_VOICE, value);
627                                 if (ret < 0)
628                                         debug_log("mm_sound_volume_set_value 0x%x", ret);
629                                 else
630                                         g_print("Current Voice volume is %d\n", value);
631                         }
632
633                 } else if (strncmp(cmd, "as", 2) == 0) {
634                         debug_log("stream %s type, %d", "media", g_volume_value);
635                         ret = mm_sound_play_sound_with_stream_info(g_file_name, "media", -1, 1, mycallback, "USERDATA", &handle);
636                         if (ret < 0)
637                                 debug_log("mm_sound_play_sound() failed with 0x%x", ret);
638
639                 } else if (strncmp(cmd, "FS", 2) == 0) {
640                         char num = 0;
641                         char input_string[128] = "";
642                         char *tok = NULL;
643                         char *ptr = NULL;
644                         char *stream_type = NULL;
645                         int tonetime = 0;
646                         double volume = 1.0;
647                         MMSoundTone_t tone = MM_SOUND_TONE_DTMF_0;
648
649                         while (num != 'q') {
650                                 fflush(stdin);
651                                 g_print("enter number(0~H exit:q), stream type(media, system, ...),  volume(0.0~1.0),  time(ms):\t ");
652                                 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
653                                         tok = strtok_r(input_string, " ", &ptr);
654                                         if (!tok)
655                                                 continue;
656                                         if (tok[0] == 'q') {
657                                                 break;
658                                         } else if (tok[0] < '0' || tok[0] > '~') {
659                                                 if (tok[0] != '*' && tok[0] != '#')
660                                                         continue;
661                                         }
662                                         num = tok[0];
663                                         if (num >= '0' && num <= '9')
664                                                 tone = (MMSoundTone_t)(num - '0');
665                                         else if (num == '*')
666                                                 tone = MM_SOUND_TONE_DTMF_S;
667                                         else if (num == '#')
668                                                 tone = MM_SOUND_TONE_DTMF_P;
669                                         else if (num == 'A')
670                                                 tone = MM_SOUND_TONE_DTMF_A;
671                                         else if (num == 'B')
672                                                 tone = MM_SOUND_TONE_DTMF_B;
673                                         else if (num == 'C')
674                                                 tone = MM_SOUND_TONE_DTMF_C;
675                                         else if (num == 'D')
676                                                 tone = MM_SOUND_TONE_DTMF_D;
677                                         else if (num == 'E')
678                                                 tone = MM_SOUND_TONE_SUP_DIAL;
679                                         else if (num == 'F')
680                                                 tone = MM_SOUND_TONE_ANSI_DIAL;
681                                         else if (num == 'G')
682                                                 tone = MM_SOUND_TONE_JAPAN_DIAL;
683                                         else if (num == 'H')
684                                                 tone = MM_SOUND_TONE_SUP_BUSY;
685                                         else if (num == 'I')
686                                                 tone = MM_SOUND_TONE_ANSI_BUSY;
687                                         else if (num == 'J')
688                                                 tone = MM_SOUND_TONE_JAPAN_BUSY;
689                                         else if (num == 'K')
690                                                 tone = MM_SOUND_TONE_SUP_CONGESTION;
691                                         else if (num == 'L')
692                                                 tone = MM_SOUND_TONE_ANSI_CONGESTION;
693                                         else if (num == 'M')
694                                                 tone = MM_SOUND_TONE_SUP_RADIO_ACK;
695                                         else if (num == 'N')
696                                                 tone = MM_SOUND_TONE_JAPAN_RADIO_ACK;
697                                         else if (num == 'O')
698                                                 tone = MM_SOUND_TONE_SUP_RADIO_NOTAVAIL;
699                                         else if (num == 'P')
700                                                 tone = MM_SOUND_TONE_SUP_ERROR;
701                                         else if (num == 'Q')
702                                                 tone = MM_SOUND_TONE_SUP_CALL_WAITING;
703                                         else if (num == 'R')
704                                                 tone = MM_SOUND_TONE_ANSI_CALL_WAITING;
705                                         else if (num == 'S')
706                                                 tone = MM_SOUND_TONE_SUP_RINGTONE;
707                                         else if (num == 'T')
708                                                 tone = MM_SOUND_TONE_ANSI_RINGTONE;
709                                         else if (num == 'U')
710                                                 tone = MM_SOUND_TONE_PROP_BEEP;
711                                         else if (num == 'V')
712                                                 tone = MM_SOUND_TONE_PROP_ACK;
713                                         else if (num == 'W')
714                                                 tone = MM_SOUND_TONE_PROP_NACK;
715                                         else if (num == 'X')
716                                                 tone = MM_SOUND_TONE_PROP_PROMPT;
717                                         else if (num == 'Y')
718                                                 tone = MM_SOUND_TONE_PROP_BEEP2;
719                                         else if (num == 'Z')
720                                                 tone = MM_SOUND_TONE_CDMA_HIGH_SLS;
721                                         else if (num == '[')
722                                                 tone = MM_SOUND_TONE_CDMA_MED_SLS;
723                                         else if (num == ']')
724                                                 tone = MM_SOUND_TONE_CDMA_LOW_SLS;
725                                         else if (num == '^')
726                                                 tone = MM_SOUND_TONE_CDMA_HIGH_S_X4;
727                                         else if (num == '_')
728                                                 tone = MM_SOUND_TONE_CDMA_MED_S_X4;
729                                         else if (num == 'a')
730                                                 tone = MM_SOUND_TONE_CDMA_LOW_S_X4;
731                                         else if (num == 'b')
732                                                 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_L;
733                                         else if (num == 'c')
734                                                 tone = MM_SOUND_TONE_CDMA_MED_PBX_L;
735                                         else if (num == 'd')
736                                                 tone = MM_SOUND_TONE_CDMA_LOW_PBX_L;
737                                         else if (num == 'e')
738                                                 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SS;
739                                         else if (num == 'f')
740                                                 tone = MM_SOUND_TONE_CDMA_MED_PBX_SS;
741                                         else if (num == 'g')
742                                                 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SS;
743                                         else if (num == 'h')
744                                                 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SSL;
745                                         else if (num == 'i')
746                                                 tone = MM_SOUND_TONE_CDMA_MED_PBX_SSL;
747                                         else if (num == 'j')
748                                                 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SSL;
749                                         else if (num == 'k')
750                                                 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SLS;
751                                         else if (num == 'l')
752                                                 tone = MM_SOUND_TONE_CDMA_MED_PBX_SLS;
753                                         else if (num == 'm')
754                                                 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SLS;
755                                         else if (num == 'n')
756                                                 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_S_X4;
757                                         else if (num == 'o')
758                                                 tone = MM_SOUND_TONE_CDMA_MED_PBX_S_X4;
759                                         else if (num == 'p')
760                                                 tone = MM_SOUND_TONE_CDMA_LOW_PBX_S_X4;
761                                         else if (num == 'q')
762                                                 tone = MM_SOUND_TONE_CDMA_ALERT_NETWORK_LITE;
763                                         else if (num == 'r')
764                                                 tone = MM_SOUND_TONE_CDMA_ALERT_AUTOREDIAL_LITE;
765                                         else if (num == 's')
766                                                 tone = MM_SOUND_TONE_CDMA_ONE_MIN_BEEP;
767                                         else if (num == 't')
768                                                 tone = MM_SOUND_TONE_CDMA_KEYPAD_VOLUME_KEY_LITE;
769                                         else if (num == 'u')
770                                                 tone = MM_SOUND_TONE_CDMA_PRESSHOLDKEY_LITE;
771                                         else if (num == 'v')
772                                                 tone = MM_SOUND_TONE_CDMA_ALERT_INCALL_LITE;
773                                         else if (num == 'w')
774                                                 tone = MM_SOUND_TONE_CDMA_EMERGENCY_RINGBACK;
775                                         else if (num == 'x')
776                                                 tone = MM_SOUND_TONE_CDMA_ALERT_CALL_GUARD;
777                                         else if (num == 'y')
778                                                 tone = MM_SOUND_TONE_CDMA_SOFT_ERROR_LITE;
779                                         else if (num == 'z')
780                                                 tone = MM_SOUND_TONE_CDMA_CALLDROP_LITE;
781                                         else if (num == '{')
782                                                 tone = MM_SOUND_TONE_LOW_FRE;
783                                         else if (num == '}')
784                                                 tone = MM_SOUND_TONE_MED_FRE;
785                                         else if (num == '~')
786                                                 tone = MM_SOUND_TONE_HIGH_FRE;
787
788                                         stream_type = strtok_r(NULL, " ", &ptr);
789
790                                         tok = strtok_r(NULL, " ", &ptr);
791                                         if (tok)
792                                                 volume = (double)atof(tok);
793
794                                         tok = strtok_r(NULL, " ", &ptr);
795                                         if (tok)
796                                                 tonetime = atoi(tok);
797                                         else
798                                                 tonetime = MIN_TONE_PLAY_TIME;
799
800                                         debug_log("stream type: %s\t volume is %f\t tonetime: %d", stream_type, volume, tonetime);
801                                         ret = mm_sound_play_tone_with_stream_info(tone, stream_type, -1, volume, tonetime, &handle);
802                                         if (ret < 0)
803                                                 debug_log("failed to mm_sound_play_tone_with_stream_info(), ret[0x%x]", ret);
804                                 } else {
805                                         g_print("### fgets return  NULL\n");
806                                 }
807                         }
808
809                 } else if (strncmp(cmd, "b", 1) == 0) {
810                         DIR     *basedir;
811                         struct dirent *entry = NULL;
812                         struct dirent *prev_entry = NULL;
813                         int entry_len;
814                         int ret;
815                         struct stat file_stat;
816                         char fullpath[MAX_PATH_LEN] = "";
817                         struct timespec start_time = {0,};
818                         struct timespec current_time = {0,};
819
820                         if (g_dir_name[strlen(g_dir_name)-1] == '/')
821                                 g_dir_name[strlen(g_dir_name)-1] = '\0';
822
823                         basedir = opendir(g_dir_name);
824                         if (basedir != NULL) {
825                                 entry_len = offsetof(struct dirent, d_name) + fpathconf(dirfd(basedir), MAX_STRING_LEN) + 1;
826                                 prev_entry = malloc(entry_len);
827                                 if (prev_entry == NULL) {
828                                         debug_error("malloc error");
829                                         closedir(basedir);
830                                         break;
831                                 }
832
833                                 while (1) {
834                                         int playfail = 0;
835                                         int mywait = 0;
836
837                                         ret = readdir_r(basedir, prev_entry, &entry);
838                                         if (ret == 0) {
839                                                 debug_error("error on readdir_r(%p)", basedir);
840                                                 break;
841                                         }
842                                         if (entry == NULL)
843                                                 break;
844
845                                         if (entry->d_name[0] == '.')
846                                                 continue;
847                                         memset(fullpath, '\0', sizeof(fullpath));
848                                         snprintf(fullpath, sizeof(fullpath) - 1, "%s/%s", g_dir_name, entry->d_name);
849                                         debug_log("Try %s", fullpath);
850
851                                         if (lstat(fullpath, &file_stat) == -1)
852                                                 continue;
853
854                                         if (S_ISREG(file_stat.st_mode)) {
855                                                 test_callback_done = 0 ;
856                                                 start_time.tv_sec = (long int)(time(NULL));
857                                                 start_time.tv_nsec = 0;
858
859                                                 ret = mm_sound_play_sound_with_stream_info(fullpath, "media", -1, 1, test_callback, "USERDATA", &handle);
860                                                 if (ret != MM_ERROR_NONE) {
861                                                         debug_log("Play file error : %s", fullpath);
862                                                         sleep(4);
863                                                         playfail = 1;
864                                                 }
865                                         } else {
866                                                 debug_log("this is not regular file : %s", fullpath);
867                                                 playfail = 1;
868                                         }
869                                         while ((test_callback_done == 0) && (playfail == 0)) {
870                                                 current_time.tv_sec = (long int)(time(NULL));
871                                                 current_time.tv_nsec = 0;
872                                                 if (current_time.tv_sec - start_time.tv_sec > 200) {
873                                                         if ((++mywait)%5 == 0) {
874                                                                 debug_log("I'm waiting callback for %d seconds after play %s",
875                                                                                 (int)(current_time.tv_sec - start_time.tv_sec), fullpath);
876                                                         }
877                                                 }
878                                                 sleep(2);
879                                         }
880                                         debug_log("goto next file");
881                                 }
882                                 free(prev_entry);
883                                 closedir(basedir);
884                         } else {
885                                 debug_log("Cannot Open such a directory %s", g_dir_name);
886                         }
887
888                 } else if (strncmp(cmd, "f", 1) == 0) {
889                         g_menu_state = CURRENT_STATUS_FILENAME;
890
891                 } else if (strncmp(cmd, "d", 1) == 0) {
892                         g_menu_state = CURRENT_STATUS_DIRNAME;
893
894                 } else if (strncmp(cmd, "s", 1) == 0) {
895                         if (mm_sound_stop_sound(handle))
896                                 debug_log(" Cannot stop sound !!! %d ", handle);
897
898                 } else if (strncmp(cmd, "L", 1) == 0) {
899                         int ret = 0;
900                         mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
901                         MMSoundDeviceList_t device_list;
902                         mm_sound_device_type_e device_type = 0;
903                         mm_sound_device_io_direction_e io_direction = 0;
904                         mm_sound_device_state_e state = 0;
905                         int id = 0;
906                         char *name = NULL;
907                         MMSoundDevice_t device_h = NULL;
908                         int dret = MM_ERROR_NONE;
909                         int product_id = -1, vendor_id = -1;
910
911                         ret = mm_sound_get_current_device_list(flags, &device_list);
912                         if (ret) {
913                                 g_print("failed to mm_sound_get_current_device_list(), ret[0x%x]\n", ret);
914                         } else {
915                                 g_print("device_list[%p], device_h[%p]\n", device_list, device_h);
916                                 do {
917                                         dret = mm_sound_get_next_device(device_list, &device_h);
918                                         if (dret) {
919                                                 debug_error("failed to mm_sound_get_next_device(), dret[0x%x]\n", dret);
920                                         } else {
921                                                 ret = mm_sound_get_device_type(device_h, &device_type);
922                                                 if (ret)
923                                                         debug_error("failed to mm_sound_get_device_type()");
924                                                 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
925                                                 if (ret)
926                                                         debug_error("failed to mm_sound_get_device_io_direction()");
927                                                 ret = mm_sound_get_device_state(device_h, &state);
928                                                 if (ret)
929                                                         debug_error("failed to mm_sound_get_device_state()");
930                                                 ret = mm_sound_get_device_id(device_h, &id);
931                                                 if (ret)
932                                                         debug_error("failed to mm_sound_get_device_id()");
933                                                 ret = mm_sound_get_device_name(device_h, &name);
934                                                 if (ret)
935                                                         debug_error("failed to mm_sound_get_device_name()");
936                                                 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
937                                                 if (ret)
938                                                         debug_error("failed to mm_sound_get_device_vendor_id()");
939                                                 ret = mm_sound_get_device_product_id(device_h, &product_id);
940                                                 if (ret)
941                                                         debug_error("failed to mm_sound_get_device_product_id()");
942                                                 debug_log("*** --- [NEXT DEVICE] type[%d], id[%d], io_direction[%d], state[%d], "
943                                                                 "name[%s] vendor_id[%04x] product_id[%04x]",
944                                                                 device_type, id, io_direction, state, name, vendor_id, product_id);
945                                         }
946                                 } while (dret == MM_ERROR_NONE);
947                                 do {
948                                         dret = MM_ERROR_NONE;
949                                         dret = mm_sound_get_prev_device(device_list, &device_h);
950                                         if (dret) {
951                                                 debug_error("failed to mm_sound_get_prev_device(), dret[0x%x]", dret);
952                                         } else {
953                                                 ret = mm_sound_get_device_type(device_h, &device_type);
954                                                 if (ret)
955                                                         debug_error("failed to mm_sound_get_device_type()");
956                                                 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
957                                                 if (ret)
958                                                         debug_error("failed to mm_sound_get_device_io_direction()");
959                                                 ret = mm_sound_get_device_state(device_h, &state);
960                                                 if (ret)
961                                                         debug_error("failed to mm_sound_get_device_state()");
962                                                 ret = mm_sound_get_device_id(device_h, &id);
963                                                 if (ret)
964                                                         debug_error("failed to mm_sound_get_device_id()");
965                                                 ret = mm_sound_get_device_name(device_h, &name);
966                                                 if (ret)
967                                                         debug_error("failed to mm_sound_get_device_name()");
968                                                 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
969                                                 if (ret)
970                                                         debug_error("failed to mm_sound_get_device_vendor_id()");
971                                                 ret = mm_sound_get_device_product_id(device_h, &product_id);
972                                                 if (ret)
973                                                         debug_error("failed to mm_sound_get_device_product_id()");
974                                                 debug_log("*** --- [PREV DEVICE] type[%d], id[%d], io_direction[%d], state[%d], "
975                                                                 "name[%s] vendor_id[%04x] product_id[%04x]",
976                                                                 device_type, id, io_direction, state, name, vendor_id, product_id);
977                                         }
978                                 } while (dret == MM_ERROR_NONE);
979                         }
980
981                 } else if (strncmp(cmd, "I", 1) == 0) {
982                         int ret = 0;
983                         MMSoundDevice_t device_h = NULL;
984                         mm_sound_device_type_e device_type = 0;
985                         mm_sound_device_io_direction_e io_direction = 0;
986                         mm_sound_device_state_e state = 0;
987                         char *name;
988                         int id = 0, input_id = 0;
989                         char input_string[128];
990
991                         fflush(stdin);
992                         g_print("> Input id : ");
993
994                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
995                                 input_id = atoi(input_string);
996
997                                 ret = mm_sound_get_device_by_id(input_id, &device_h);
998                                 if (ret == MM_ERROR_NONE) {
999                                         ret = mm_sound_get_device_type(device_h, &device_type);
1000                                         if (ret)
1001                                                 g_print("failed to mm_sound_get_device_type()\n");
1002                                         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
1003                                         if (ret)
1004                                                 g_print("failed to mm_sound_get_device_io_direction()\n");
1005                                         ret = mm_sound_get_device_state(device_h, &state);
1006                                         if (ret)
1007                                                 g_print("failed to mm_sound_get_device_state()\n");
1008                                         ret = mm_sound_get_device_id(device_h, &id);
1009                                         if (ret)
1010                                                 g_print("failed to mm_sound_get_device_id()\n");
1011                                         ret = mm_sound_get_device_name(device_h, &name);
1012                                         if (ret)
1013                                                 g_print("failed to mm_sound_get_device_name()\n");
1014                                         g_print("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
1015                                 } else {
1016                                         g_print("failed to mm_sound_get_device_by_id()\n");
1017                                 }
1018
1019                                 ret = mm_sound_free_device(device_h);
1020                                 if (ret)
1021                                         g_print("failed to mm_sound_free_device()\n");
1022                         } else {
1023                                 g_print("### fgets return  NULL\n");
1024                         }
1025
1026                 } else if (strncmp(cmd, "C", 1) == 0) {
1027                         int ret = 0;
1028                         char input_string[128];
1029                         mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1030                         mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1031                         mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1032
1033                         char flag_1, flag_2, flag_3;
1034
1035                         fflush(stdin);
1036                         g_print("1. IO_DIRECTION_IN_FLAG\n");
1037                         g_print("2. IO_DIRECTION_OUT_FLAG\n");
1038                         g_print("3. IO_DIRECTION_BOTH_FLAG\n");
1039                         g_print("4. TYPE_INTERNAL_FLAG\n");
1040                         g_print("5. TYPE_EXTERNAL_FLAG\n");
1041                         g_print("6. STATE_DEACTIVATED_FLAG\n");
1042                         g_print("7. STATE_ACTIVATED_FLAG\n");
1043                         g_print("8. ALL_FLAG\n");
1044                         g_print("> select flag numbers (total 3):  (eg. 2 5 7)");
1045
1046                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1047                                 flag_1 = input_string[0];
1048                                 flag_2 = input_string[2];
1049                                 flag_3 = input_string[4];
1050
1051                                 if (flag_1 == '1')
1052                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1053                                 else if (flag_1 == '2')
1054                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1055                                 else if (flag_1 == '3')
1056                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1057                                 else if (flag_1 == '4')
1058                                         device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1059                                 else if (flag_1 == '5')
1060                                         device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1061                                 else if (flag_1 == '6')
1062                                         device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1063                                 else if (flag_1 == '7')
1064                                         device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1065                                 else if (flag_1 == '8')
1066                                         device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1067
1068                                 if (flag_2 == '1')device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1069                                 else if (flag_2 == '2')
1070                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1071                                 else if (flag_2 == '3')
1072                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1073                                 else if (flag_2 == '4')
1074                                         device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1075                                 else if (flag_2 == '5')
1076                                         device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1077                                 else if (flag_2 == '6')
1078                                         device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1079                                 else if (flag_2 == '7')
1080                                         device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1081                                 else if (flag_2 == '8')
1082                                         device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1083
1084                                 if (flag_3 == '1')
1085                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1086                                 else if (flag_3 == '2')
1087                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1088                                 else if (flag_3 == '3')
1089                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1090                                 else if (flag_3 == '4')
1091                                         device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1092                                 else if (flag_3 == '5')
1093                                         device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1094                                 else if (flag_3 == '6')
1095                                         device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1096                                 else if (flag_3 == '7')
1097                                         device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1098                                 else if (flag_3 == '8')
1099                                         device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1100
1101                                 g_print("device_connected_callback");
1102                                 ret = mm_sound_add_device_connected_callback(device_flag_1|device_flag_2|device_flag_3, device_connected_cb, NULL, &g_subs_id_device_conn);
1103                                 if (ret)
1104                                         g_print("failed to mm_sound_add_device_connected_callback(), ret[0x%x]\n", ret);
1105                                 else
1106                                         g_print("device_flags[0x%x], callback fun[%p], subs_id[%u]\n", device_flag_1|device_flag_2|device_flag_3, device_connected_cb, g_subs_id_device_conn);
1107                         } else {
1108                                 g_print("### fgets return  NULL\n");
1109                         }
1110
1111                 } else if (strncmp(cmd, "D", 1) == 0) {
1112                         int ret = 0;
1113                         ret = mm_sound_remove_device_connected_callback(g_subs_id_device_conn);
1114                         if (ret)
1115                                 g_print("failed to mm_sound_remove_device_connected_callback(), ret[0x%x]\n", ret);
1116
1117                 } else if (strncmp(cmd, "Q", 1) == 0) {
1118                         int ret = 0;
1119                         char input_string[128];
1120                         mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1121                         mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1122                         mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1123
1124                         char flag_1, flag_2, flag_3;
1125
1126                         fflush(stdin);
1127                         g_print("1. IO_DIRECTION_IN_FLAG\n");
1128                         g_print("2. IO_DIRECTION_OUT_FLAG\n");
1129                         g_print("3. IO_DIRECTION_BOTH_FLAG\n");
1130                         g_print("4. TYPE_INTERNAL_FLAG\n");
1131                         g_print("5. TYPE_EXTERNAL_FLAG\n");
1132                         g_print("6. STATE_DEACTIVATED_FLAG\n");
1133                         g_print("7. STATE_ACTIVATED_FLAG\n");
1134                         g_print("8. ALL_FLAG\n");
1135                         g_print("> select flag numbers (total 3):  (eg. 2 5 7)");
1136
1137                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1138                                 flag_1 = input_string[0];
1139                                 flag_2 = input_string[2];
1140                                 flag_3 = input_string[4];
1141
1142                                 if (flag_1 == '1')
1143                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1144                                 else if (flag_1 == '2')
1145                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1146                                 else if (flag_1 == '3')
1147                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1148                                 else if (flag_1 == '4')
1149                                         device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1150                                 else if (flag_1 == '5')
1151                                         device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1152                                 else if (flag_1 == '6')
1153                                         device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1154                                 else if (flag_1 == '7')
1155                                         device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1156                                 else if (flag_1 == '8')
1157                                         device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1158
1159                                 if (flag_2 == '1')
1160                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1161                                 else if (flag_2 == '2')
1162                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1163                                 else if (flag_2 == '3')
1164                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1165                                 else if (flag_2 == '4')
1166                                         device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1167                                 else if (flag_2 == '5')
1168                                         device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1169                                 else if (flag_2 == '6')
1170                                         device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1171                                 else if (flag_2 == '7')
1172                                         device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1173                                 else if (flag_2 == '8')
1174                                         device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1175
1176                                 if (flag_3 == '1')
1177                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1178                                 else if (flag_3 == '2')
1179                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1180                                 else if (flag_3 == '3')
1181                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1182                                 else if (flag_3 == '4')
1183                                         device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1184                                 else if (flag_3 == '5')
1185                                         device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1186                                 else if (flag_3 == '6')
1187                                         device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1188                                 else if (flag_3 == '7')
1189                                         device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1190                                 else if (flag_3 == '8')
1191                                         device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1192
1193                                 g_print("add_device_state_changed");
1194                                 ret = mm_sound_add_device_state_changed_callback(device_flag_1 | device_flag_2 | device_flag_3, device_state_changed_cb, NULL, &g_subs_id_device_state);
1195                                 if (ret)
1196                                         g_print("failed to mm_sound_add_device_state_changed_callback(), ret[0x%x]\n", ret);
1197                                 else
1198                                         g_print("device_flags[0x%x], callback fun[%p], subs_id[%u]\n", device_flag_1|device_flag_2|device_flag_3, device_state_changed_cb, g_subs_id_device_state);
1199
1200                         } else {
1201                                 g_print("### fgets return  NULL\n");
1202                         }
1203
1204                 } else if (strncmp(cmd, "W", 1) == 0) {
1205                         int ret = 0;
1206                         ret = mm_sound_remove_device_state_changed_callback(g_subs_id_device_state);
1207                         if (ret)
1208                                 g_print("failed to mm_sound_remove_device_state_changed_callback(), ret[0x%x]\n", ret);
1209
1210                 } else if (strncmp(cmd, "x", 1) == 0) {
1211                         quit_program();
1212                 }
1213                 break;
1214
1215         case CURRENT_STATUS_FILENAME:
1216                 input_filename(cmd);
1217                 g_menu_state = CURRENT_STATUS_MAINMENU;
1218                 break;
1219
1220         case CURRENT_STATUS_DIRNAME:
1221                 input_dirname(cmd);
1222                 g_menu_state = CURRENT_STATUS_MAINMENU;
1223                 break;
1224
1225         case CURRENT_STATUS_POSITION:
1226                 break;
1227
1228         }
1229 }
1230
1231 void volume_change_callback(volume_type_t type, unsigned int volume, void *user_data)
1232 {
1233         if (type == VOLUME_TYPE_MEDIA)
1234                 g_print("Volume Callback Runs :::: MEDIA VALUME %d\n", volume);
1235 }
1236
1237 int main(int argc, char *argv[])
1238 {
1239         int ret = 0;
1240
1241         stdin_channel = g_io_channel_unix_new(0);
1242         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
1243         g_loop = g_main_loop_new(NULL, 1);
1244
1245         MMSOUND_STRNCPY(g_file_name, POWERON_FILE, MAX_STRING_LEN);
1246         g_print("\nThe input filename is '%s' \n\n", g_file_name);
1247
1248         /* test volume changed callback */
1249         g_print("callback function addr :: %p\n", volume_change_callback);
1250         g_volume_type = VOLUME_TYPE_MEDIA;
1251         ret = mm_sound_volume_get_value(g_volume_type, &g_volume_value);
1252         if (ret < 0)
1253                 g_print("mm_sound_volume_get_value 0x%x\n", ret);
1254
1255         mm_sound_add_volume_changed_callback(volume_change_callback, (void*) &g_volume_type, &g_subs_id_volume);
1256
1257         displaymenu();
1258         g_main_loop_run(g_loop);
1259
1260         return 0;
1261 }