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