1509653d040996c932f887c7799e026ece1ba570
[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_utils.h"
35 #include "../include/mm_sound_private.h"
36 #include "../include/mm_sound_pa_client.h"
37
38 #include <glib.h>
39
40 #include <pthread.h>
41
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <unistd.h>
45 #include <dirent.h>
46 #include <vconf.h>
47
48 #define POWERON_FILE    "/usr/share/keysound/poweron.ogg"
49 #define KEYTONE_FILE    "/usr/share/sounds/mm-sound/Tizen_HW_Touch.ogg"
50 #define KEYTONE_NOTI_FILE       "/usr/share/sounds/alsa/Front_Center.wav"
51
52 #define MM_SOUND_KEYTONE_PATH "MM_SOUND_KEYTONE_PATH"
53
54 #define MM_SOUND_KEYTONE_COUNT "MM_SOUND_KEYTONE_COUNT"
55 #define MM_SOUND_KEYTONE_COUNT_MAX 10000
56
57 #define MM_SOUND_KEYTONE_INTERVAL "MM_SOUND_KEYTONE_INTERVAL"
58 #define MM_SOUND_KEYTONE_INTERVAL_MAX 10000 /* 10 sec. */
59
60 enum {
61         CURRENT_STATUS_MAINMENU = 0,
62         CURRENT_STATUS_FILENAME = 1,
63         CURRENT_STATUS_POSITION = 2,
64         CURRENT_STATUS_DIRNAME = 3,
65 };
66
67 static int g_focus_id = 0;
68 static int g_menu_state = CURRENT_STATUS_MAINMENU;
69 static volume_type_t g_volume_type = VOLUME_TYPE_MEDIA;
70 static unsigned int g_volume_value;
71 static GIOChannel *stdin_channel;
72 static char g_file_name[MAX_STRING_LEN];
73 static char g_dir_name[MAX_PATH_LEN];
74 static int g_focus_watch_index = -1;
75 static GMainLoop* g_loop;
76 static unsigned int g_subs_id_volume, g_subs_id_device_conn, g_subs_id_device_state;
77
78 static void interpret(char *buf);
79 gboolean timeout_menu_display(void *data);
80 gboolean timeout_quit_program(void *data);
81 gboolean input(GIOChannel *channel);
82
83 static void print_device_info(MMSoundDevice_t device_h)
84 {
85         mm_sound_device_type_e device_type = 0;
86         mm_sound_device_io_direction_e io_direction = 0;
87         mm_sound_device_state_e state = 0;
88         int ret = 0;
89         int id = 0;
90         int vendor_id = -1, product_id = -1;
91         char vendor_string[MAX_STRING_LEN], product_string[MAX_STRING_LEN];
92         char *name = NULL;
93
94         ret = mm_sound_get_device_type(device_h, &device_type);
95         if (ret != MM_ERROR_NONE)
96                 debug_error("failed to mm_sound_get_device_type(). ret:0x%x", ret);
97         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
98         if (ret != MM_ERROR_NONE)
99                 debug_error("failed to mm_sound_get_device_io_direction(). ret:0x%x", ret);
100         ret = mm_sound_get_device_state(device_h, &state);
101         if (ret != MM_ERROR_NONE)
102                 debug_error("failed to mm_sound_get_device_state(). ret:0x%x", ret);
103         ret = mm_sound_get_device_id(device_h, &id);
104         if (ret != MM_ERROR_NONE)
105                 debug_error("failed to mm_sound_get_device_id(). ret:0x%x", ret);
106         ret = mm_sound_get_device_name(device_h, &name);
107         if (ret != MM_ERROR_NONE)
108                 debug_error("failed to mm_sound_get_device_name(). ret:0x%x", ret);
109         ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
110         if (ret != MM_ERROR_NONE)
111                 debug_error("failed to mm_sound_get_device_vendor_id(). ret:0x%x", ret);
112         ret = mm_sound_get_device_product_id(device_h, &product_id);
113         if (ret != MM_ERROR_NONE)
114                 debug_error("failed to mm_sound_get_device_product_id(). ret:0x%x", ret);
115
116         if (vendor_id == -1)
117                 snprintf(vendor_string, MAX_STRING_LEN, "NO ID");
118         else
119                 snprintf(vendor_string, MAX_STRING_LEN, "%d", vendor_id);
120
121         if (product_id == -1)
122                 snprintf(product_string, MAX_STRING_LEN, "NO ID");
123         else
124                 snprintf(product_string, MAX_STRING_LEN, "%d", product_id);
125
126         debug_log("[DEVICE INFO]--------------------------- \n"
127                 "type : %d\n"
128                 "id : %d\n"
129                 "io_direction : %d\n"
130                 "state : %d\n"
131                 "name : %s\n"
132                 "vendor id : %s\n"
133                 "product id : %s\n",
134                 device_type, id, io_direction, state, name, vendor_string, product_string);
135 }
136
137 void mycallback(void *data, int id)
138 {
139         char *str = (char*)data;
140         if (data != NULL)
141                 debug_log("mycallback called (user data:%s ,id:%d)", str, id);
142         else
143                 debug_log("mycallback called (no user data)");
144 }
145 static volatile char test_callback_done;
146 void test_callback(void *data, int id)
147 {
148         debug_log("test_callback is called");
149         test_callback_done = 1;
150 }
151 void mm_sound_test_cb1(int a, void *user_data)
152 {
153         debug_log("dbus test user callback called: param(%d), userdata(%d)", a, (int)(uintptr_t)user_data);
154         g_print("my callback pid : %u  tid : %ld\n", getpid(), pthread_self());
155 }
156 void device_connected_cb(MMSoundDevice_t device_h, bool is_connected, void *user_data)
157 {
158         debug_log("*** device_connected_cb is called, device_h[%p], is_connected[%d], user_data[%p]", device_h, is_connected, user_data);
159         print_device_info(device_h);
160 }
161 void device_state_changed_cb(MMSoundDevice_t device_h, mm_sound_device_state_e new_state, void *user_data)
162 {
163         debug_log("*** device_state_changed_cb is called, device_h[%p], state[%d], user_data[%p]", device_h, new_state, user_data);
164         print_device_info(device_h);
165 }
166
167 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)
168 {
169         char *_state = NULL;
170         if (state == FOCUS_IS_RELEASED)
171                 _state = "RELEASED";
172         else
173                 _state = "ACQUIRED";
174         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]",
175                         index, type, _state, reason_for_change, option, ext_info, (char*)user_data);
176 }
177
178 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)
179 {
180         char *_state = NULL;
181         if (state == FOCUS_IS_RELEASED)
182                 _state = "RELEASED";
183         else
184                 _state = "ACQUIRED";
185         debug_log("*** focus_watch_cb is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], ext_info[%s], user_data[%s]",
186                         index, type, _state, reason_for_change, ext_info, (char*)user_data);
187 }
188
189 void quit_program()
190 {
191         g_main_loop_quit(g_loop);
192 }
193
194 static void displaymenu()
195 {
196         if (g_menu_state == CURRENT_STATUS_MAINMENU) {
197                 g_print("==================================================================\n");
198                 g_print("       Sound Play APIs\n");
199                 g_print("==================================================================\n");
200                 g_print("k : Play Keysound     \t");
201                 g_print("ks : Stop Keysound     \t");
202                 g_print("kn : Play Keysound (Notification) \t");
203                 g_print("ksn : Stop Keysound (Notification)    \t");
204                 g_print("ksa : Stop Keysound (All)    \n");
205                 g_print("==================================================================\n");
206                 g_print("       Volume APIs\n");
207                 g_print("==================================================================\n");
208                 g_print("q : Get media    \t");
209                 g_print("w : Inc. media   \t");
210                 g_print("e : Dec. media   \n");
211                 g_print("r : Get system   \t");
212                 g_print("t : Inc. system  \t");
213                 g_print("y : Dec. system  \n");
214                 g_print("g : Get voice   \t");
215                 g_print("h : Inc. voice  \t");
216                 g_print("j : Dec. voice  \n");
217                 g_print("==================================================================\n");
218                 g_print("       Audio route APIs\n");
219                 g_print("==================================================================\n");
220                 g_print("u : Foreach Available Routes \t");
221                 g_print("i : Get Active Devices     \n");
222                 g_print("o : Add Available Routes Callback   \t");
223                 g_print("O : Remove Available Routes Callback   \n");
224                 g_print("p : Add Active Route Callback\t");
225                 g_print("P : Remove Active Route Callback \n");
226                 g_print("{ : Get BT A2DP Status\n");
227                 g_print("} : Set Active Route\n");
228                 g_print("==================================================================\n");
229                 g_print("       Audio device APIs\n");
230                 g_print("==================================================================\n");
231                 g_print("L : Get current list of connected devices \n");
232                 g_print("I : Get device by id \n");
233                 g_print("C : Add device connected callback \t");
234                 g_print("D : Remove device connected callback \n");
235                 g_print("Q : Add device state. changed callback \t");
236                 g_print("W : Remove device state. changed callback \n");
237                 g_print("==================================================================\n");
238                 g_print("       Focus APIs\n");
239                 g_print("==================================================================\n");
240                 g_print("SF : Set Focus Callback\t");
241                 g_print("UF : Unset Focus Callback\n");
242                 g_print("DF : Disable Auto Focus Reacquirement\t");
243                 g_print("AF : Acquire Focus\t");
244                 g_print("RF : Release Focus\n");
245                 g_print("WS : Set Focus Watch Callback\t");
246                 g_print("WU : Unset Focus Watch Callback\n");
247                 g_print("==================================================================\n");
248                 g_print("d : Input Directory \t");
249                 g_print("f : Input File name \t");
250                 g_print("x : Exit Program \n");
251                 g_print("==================================================================\n");
252                 g_print(" Input command >>>>>>>> ");
253         } else if (g_menu_state == CURRENT_STATUS_FILENAME) {
254                 g_print(">>>>Input file name to play : ");
255         } else if (g_menu_state == CURRENT_STATUS_DIRNAME) {
256                         g_print(">>>>Input directory which contain audio files : ");
257         } else {
258                 g_print("**** Unknown status.\n");
259                 quit_program();
260         }
261 }
262
263 gboolean timeout_menu_display(void* data)
264 {
265         displaymenu();
266         return FALSE;
267 }
268
269 gboolean timeout_quit_program(void* data)
270 {
271         quit_program();
272         return FALSE;
273 }
274
275 gboolean input(GIOChannel *channel)
276 {
277         GError *err = NULL;
278         gchar *buf = NULL;
279         gsize length = 0;
280
281         if (g_io_channel_read_line(channel, &buf, &length, NULL, &err) == G_IO_STATUS_NORMAL) {
282                 if (length > 1) {
283                         g_strstrip(buf);
284                         interpret(buf);
285                 }
286                 g_free(buf);
287         }
288
289         if (err) {
290                 g_print("g_io_channel_read_line() error (%s)", err->message);
291                 g_error_free(err);
292         }
293
294         return TRUE;
295 }
296
297 static void input_filename(char *filename)
298 {
299         MMSOUND_STRNCPY(g_file_name, filename, MAX_STRING_LEN);
300         g_print("\nThe input filename is '%s' \n\n", g_file_name);
301
302 }
303
304 static void input_dirname(char *dirname)
305 {
306         MMSOUND_STRNCPY(g_dir_name, dirname, MAX_PATH_LEN);
307         g_print("\nThe input directory is '%s' \n\n", g_dir_name);
308 }
309
310 mm_sound_device_flags_e no2flag(char flag_no)
311 {
312         switch (flag_no) {
313         case '1':
314                 return MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
315         case '2':
316                 return MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
317         case '3':
318                 return MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
319         case '4':
320                 return MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
321         case '5':
322                 return MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
323         case '6':
324                 return MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
325         case '7':
326                 return MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
327         default:
328                 return MM_SOUND_DEVICE_ALL_FLAG;
329         }
330 }
331
332 mm_sound_device_flags_e select_device_flags(void)
333 {
334         char input_string[MAX_STRING_LEN];
335
336         fflush(stdin);
337         g_print("1. IO_DIRECTION_IN_FLAG\n");
338         g_print("2. IO_DIRECTION_OUT_FLAG\n");
339         g_print("3. IO_DIRECTION_BOTH_FLAG\n");
340         g_print("4. TYPE_INTERNAL_FLAG\n");
341         g_print("5. TYPE_EXTERNAL_FLAG\n");
342         g_print("6. STATE_DEACTIVATED_FLAG\n");
343         g_print("7. STATE_ACTIVATED_FLAG\n");
344         g_print("8. ALL_FLAG\n");
345         g_print("> select three flags(eg.'2 5 7'): ");
346
347         if (!fgets(input_string, MAX_STRING_LEN-1, stdin)) {
348                 g_print("### fgets return NULL. using all flags\n");
349                 return MM_SOUND_DEVICE_ALL_FLAG;
350         }
351
352         return (no2flag(input_string[0]) | no2flag(input_string[2]) | no2flag(input_string[4]));
353 }
354
355 static const char *env_get_str(const char *key, const char *default_str)
356 {
357         char *env_str = getenv(key);
358
359         return env_str ? env_str : default_str;
360 }
361
362 static unsigned int env_get_uint(const char *key, unsigned int min, unsigned int max, unsigned int default_value)
363 {
364         char *env_str = getenv(key);
365         unsigned int value = 0;
366
367         if (!env_str)
368                 return default_value;
369
370         value = (unsigned int)atoi(env_str);
371
372         g_assert(value >= min);
373         g_assert(value <= max);
374
375         return value;
376 }
377
378 static void interpret(char *cmd)
379 {
380         int ret = 0;
381
382         switch (g_menu_state) {
383         case CURRENT_STATUS_MAINMENU:
384                 if (strncmp(cmd, "SF", 2) == 0) {
385                         int ret = 0;
386                         char input_string[128];
387                         char select;
388                         char *stream_type = NULL;
389                         const char *user_data = "this is user data";
390
391                         fflush(stdin);
392                         g_print("1. Media\n");
393                         g_print("2. Alarm\n");
394                         g_print("3. Notification\n");
395                         g_print("4. Emergency\n");
396                         g_print("5. Voice Information\n");
397                         g_print("6. Ringtone\n");
398                         g_print("7. Ringtone Call\n");
399                         g_print("8. VOIP\n");
400                         g_print("0. Voice Recognition\n");
401                         g_print("> stream type: ");
402
403                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
404                                 select = input_string[0];
405
406                                 if (select == '1')
407                                         stream_type = "media";
408                                 else if (select == '2')
409                                         stream_type = "alarm";
410                                 else if (select == '3')
411                                         stream_type = "notification";
412                                 else if (select == '4')
413                                         stream_type = "emergency";
414                                 else if (select == '5')
415                                         stream_type = "voice-information";
416                                 else if (select == '6')
417                                         stream_type = "ringtone";
418                                 else if (select == '7')
419                                         stream_type = "ringtone-call";
420                                 else if (select == '8')
421                                         stream_type = "voip";
422                                 else if (select == '0')
423                                         stream_type = "voice-recognition";
424
425                                 ret = mm_sound_register_focus(stream_type, focus_cb, (void*)user_data, &g_focus_id);
426                                 if (ret)
427                                         g_print("failed to mm_sound_register_focus(), ret[0x%x]\n", ret);
428                                 else
429                                         g_print("id[%d], stream_type[%s], callback fun[%p]\n", g_focus_id, stream_type, focus_cb);
430                         } else {
431                                 g_print("### fgets return  NULL\n");
432                         }
433                 } else if (strncmp(cmd, "UF", 2) == 0) {
434                         int ret = 0;
435
436                         ret = mm_sound_unregister_focus(g_focus_id);
437                         if (ret)
438                                 g_print("failed to mm_sound_unregister_focus(), ret[0x%x]\n", ret);
439                 } else if (strncmp(cmd, "DF", 2) == 0) {
440                         int ret = 0;
441                         char input_string[128];
442                         char flag_1, flag_2;
443                         int id = 2;
444                         bool reacquisition = true;
445                         fflush(stdin);
446                         g_print("1. enable auto reacquirement\n");
447                         g_print("2. disable auto reacquirement\n");
448                         g_print("> select id and option: (eg. 0 1)");
449                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
450                                 flag_1 = input_string[0];
451                                 flag_2 = input_string[2];
452
453                                 if (flag_1 == '0')
454                                         id = 0;
455                                 else if (flag_1 == '1')
456                                         id = 1;
457                                 else if (flag_1 == '2')
458                                         id = 2;
459
460                                 if (flag_2 == '1')
461                                         reacquisition = true;
462                                 else if (flag_2 == '2')
463                                         reacquisition = false;
464
465                                 ret = mm_sound_set_focus_reacquisition(id, reacquisition);
466                                 if (ret)
467                                         g_print("failed to mm_sound_disable_focus_reacquirement(), ret[0x%x]\n", ret);
468                         } else {
469                                 g_print("### fgets return  NULL\n");
470                         }
471                 } else if (strncmp(cmd, "AF", 2) == 0) {
472                         int ret = 0;
473                         char input_string[128];
474                         char flag_1, flag_2;
475                         int id = 0;
476                         mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
477                         fflush(stdin);
478                         g_print("1. focus for playback\n");
479                         g_print("2. focus for recording\n");
480                         g_print("3. focus for both\n");
481                         g_print("> select id and focus_type: (eg. 0 1)");
482                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
483                                 flag_1 = input_string[0];
484                                 flag_2 = input_string[2];
485
486                                 if (flag_1 == '0')
487                                         id = 0;
488                                 else if (flag_1 == '1')
489                                         id = 1;
490
491                                 if (flag_2 == '1')
492                                         type = FOCUS_FOR_PLAYBACK;
493                                 else if (flag_2 == '2')
494                                         type = FOCUS_FOR_CAPTURE;
495
496                                 ret = mm_sound_acquire_focus(id, type, "additional_info. for acquire");
497                                 if (ret)
498                                         g_print("failed to mm_sound_acquire_focus(), ret[0x%x]\n", ret);
499
500                         } else {
501                                 g_print("### fgets return  NULL\n");
502                         }
503
504                 } else if (strncmp(cmd, "RF", 2) == 0) {
505                         int ret = 0;
506                         char input_string[128];
507                         char flag_1, flag_2;
508                         int id = 2;
509                         mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
510                         fflush(stdin);
511                         g_print("1. focus for playback\n");
512                         g_print("2. focus for recording\n");
513                         g_print("3. focus for all\n");
514                         g_print("> select id and focus_type: (eg. 0 1)");
515                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
516                                 flag_1 = input_string[0];
517                                 flag_2 = input_string[2];
518
519                                 if (flag_1 == '0')
520                                         id = 0;
521                                 else if (flag_1 == '1')
522                                         id = 1;
523
524                                 if (flag_2 == '1')
525                                         type = FOCUS_FOR_PLAYBACK;
526                                 else if (flag_2 == '2')
527                                         type = FOCUS_FOR_CAPTURE;
528
529                                 ret = mm_sound_release_focus(id, type, "additional_info. for release");
530                                 if (ret)
531                                         g_print("failed to mm_sound_release_focus(), ret[0x%x]\n", ret);
532
533                         } else {
534                                 g_print("### fgets return  NULL\n");
535                         }
536
537                 } else if (strncmp(cmd, "WS", 2) == 0) {
538                         int ret = 0;
539                         char input_string[128];
540                         char flag_1;
541                         int type = 1;
542                         const char *user_data = "this is user data for watch";
543
544                         fflush(stdin);
545                         g_print("1. playback\n");
546                         g_print("2. recording\n");
547                         g_print("3. both\n");
548                         g_print("> select interest focus type:");
549
550                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
551                                 flag_1 = input_string[0];
552
553                                 if (flag_1 == '1')
554                                         type = 1;
555                                 else if (flag_1 == '2')
556                                         type = 2;
557                                 else if (flag_1 == '3')
558                                         type = 3;
559
560                                 ret = mm_sound_set_focus_watch_callback(type, focus_watch_cb, (void*)user_data, &g_focus_watch_index);
561                                 if (ret)
562                                         g_print("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
563                                 else
564                                         g_print("index[%d], type[%d], callback fun[%p]\n", g_focus_watch_index, type, focus_watch_cb);
565                         } else {
566                                 g_print("### fgets return  NULL\n");
567                         }
568
569                 } else if (strncmp(cmd, "WU", 2) == 0) {
570                         int ret = 0;
571                         ret = mm_sound_unset_focus_watch_callback(g_focus_watch_index);
572                         if (ret)
573                                 g_print("failed to mm_sound_unset_focus_watch_callback(), ret[0x%x]\n", ret);
574                 } else if (strncmp(cmd, "ksn", 3) == 0) {
575                         ret = mm_sound_stop_keysound(KEYTONE_NOTI_FILE);
576                         if (ret < 0)
577                                 debug_error("keysound stop(noti) failed with 0x%x", ret);
578                 } else if (strncmp(cmd, "ksa", 3) == 0) {
579                         ret = mm_sound_stop_keysound(NULL);
580                         if (ret < 0)
581                                 debug_error("keysound stop(all) failed with 0x%x", ret);
582                 } else if (strncmp(cmd, "kn", 2) == 0) {
583                         ret = mm_sound_play_keysound(KEYTONE_NOTI_FILE, VOLUME_TYPE_NOTIFICATION);
584                         if (ret < 0)
585                                 debug_error("keysound play(noti) failed with 0x%x", ret);
586                 } else if (strncmp(cmd, "ks", 2) == 0) {
587                         ret = mm_sound_stop_keysound(KEYTONE_FILE);
588                         if (ret < 0)
589                                 debug_error("keysound stop failed with 0x%x", ret);
590                 } else if (strncmp(cmd, "k", 1) == 0) {
591                         const char* keytone_path =
592                                 env_get_str(MM_SOUND_KEYTONE_PATH, KEYTONE_FILE);
593                         unsigned int count =
594                                 env_get_uint(MM_SOUND_KEYTONE_COUNT, 0, MM_SOUND_KEYTONE_COUNT_MAX, 1);
595                         unsigned int interval_us =
596                                 env_get_uint(MM_SOUND_KEYTONE_INTERVAL, 0, MM_SOUND_KEYTONE_INTERVAL_MAX, 0) * 1000;
597
598                         g_message("keytone path(%s), count(%u), interval(%u us)",
599                                 keytone_path, count, interval_us);
600
601                         for (unsigned int i = 0; i < count; i++) {
602                                 ret = mm_sound_play_keysound(keytone_path, 0);
603                                 if (ret < 0)
604                                         debug_error("keysound play failed with 0x%x", ret);
605
606                                 usleep(interval_us);
607                         }
608
609                         g_message("keytone play done");
610                 } else if (strncmp(cmd, "q", 1) == 0) {
611                         unsigned int value = 100;
612                         ret = mm_sound_volume_get_value(g_volume_type, &value);
613                         if (ret < 0) {
614                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
615                         } else {
616                                 g_print("*** MEDIA VOLUME : %u ***\n", value);
617                                 g_volume_value = value;
618                         }
619
620                 } else if (strncmp(cmd, "e", 1) == 0) {
621                         unsigned int value = 100;
622                         ret = mm_sound_volume_get_value(g_volume_type, &value);
623                         if (ret < 0) {
624                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
625                         } else {
626                                 if (value != 0)
627                                         value--;
628                                 ret = mm_sound_volume_set_value(g_volume_type, value);
629                                 if (ret < 0)
630                                         debug_log("mm_sound_volume_set_value 0x%x", ret);
631                         }
632
633                 } else if (strncmp(cmd, "r", 1) == 0) {
634                         unsigned int value = 100;
635                         ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
636                         if (ret < 0) {
637                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
638                         } else {
639                                 g_print("*** SYSTEM VOLUME : %u ***\n", value);
640                                 g_volume_value = value;
641                         }
642
643                 } else if (strncmp(cmd, "y", 1) == 0) {
644                         unsigned int value = 100;
645                         ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
646                         if (ret < 0) {
647                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
648                         } else {
649                                 if (value != 0)
650                                         value--;
651
652                                 ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
653                                 if (ret < 0)
654                                         debug_log("mm_sound_volume_set_value 0x%x", ret);
655                                 else
656                                         g_print("Current System volume is %d\n", value);
657                         }
658
659                 } else if (strncmp(cmd, "g", 1) == 0) {
660                         unsigned int value = 100;
661                         ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
662                         if (ret < 0) {
663                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
664                         } else {
665                                 g_print("*** VOICE VOLUME : %u ***\n", value);
666                                 g_volume_value = value;
667                         }
668
669                 } else if (strncmp(cmd, "j", 1) == 0) {
670                         unsigned int value = 100;
671                         ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
672                         if (ret < 0) {
673                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
674                         } else {
675                                 if (value != 0)
676                                         value--;
677
678                                 ret = mm_sound_volume_set_value(VOLUME_TYPE_VOICE, value);
679                                 if (ret < 0)
680                                         debug_log("mm_sound_volume_set_value 0x%x", ret);
681                                 else
682                                         g_print("Current Voice volume is %d\n", value);
683                         }
684
685                 } else if (strncmp(cmd, "f", 1) == 0) {
686                         g_menu_state = CURRENT_STATUS_FILENAME;
687
688                 } else if (strncmp(cmd, "d", 1) == 0) {
689                         g_menu_state = CURRENT_STATUS_DIRNAME;
690
691                 } else if (strncmp(cmd, "L", 1) == 0) {
692                         int ret = 0;
693                         mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
694                         MMSoundDeviceList_t device_list;
695                         MMSoundDevice_t device_h = NULL;
696                         int dret = MM_ERROR_NONE;
697
698                         ret = mm_sound_get_current_device_list(flags, &device_list);
699                         if (ret) {
700                                 g_print("failed to mm_sound_get_current_device_list(), ret[0x%x]\n", ret);
701                         } else {
702                                 g_print("device_list[%p], device_h[%p]\n", device_list, device_h);
703                                 do {
704                                         dret = mm_sound_get_next_device(device_list, &device_h);
705                                         if (dret == MM_ERROR_NONE) {
706                                                 print_device_info(device_h);
707                                         } else if (dret != MM_ERROR_SOUND_NO_DATA){
708                                                 debug_error("failed to mm_sound_get_next_device(), dret[0x%x]\n", dret);
709                                         }
710                                 } while (dret == MM_ERROR_NONE);
711                                 do {
712                                         dret = mm_sound_get_prev_device(device_list, &device_h);
713                                         if (dret == MM_ERROR_NONE) {
714                                                 print_device_info(device_h);
715                                         } else if (dret != MM_ERROR_SOUND_NO_DATA){
716                                                 debug_error("failed to mm_sound_get_prev_device(), dret[0x%x]", dret);
717                                         }
718                                 } while (dret == MM_ERROR_NONE);
719                         }
720
721                 } else if (strncmp(cmd, "I", 1) == 0) {
722                         int ret = 0;
723                         MMSoundDevice_t device_h = NULL;
724                         int input_id = 0;
725                         char input_string[128];
726
727                         fflush(stdin);
728                         g_print("> Input id : ");
729
730                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
731                                 input_id = atoi(input_string);
732
733                                 ret = mm_sound_get_device_by_id(input_id, &device_h);
734                                 if (ret == MM_ERROR_NONE) {
735                                         print_device_info(device_h);
736                                 } else {
737                                         g_print("failed to mm_sound_get_device_by_id(), ret[0x%x]\n", ret);
738                                 }
739
740                                 ret = mm_sound_free_device(device_h);
741                                 if (ret)
742                                         g_print("failed to mm_sound_free_device(), ret[0x%x]\n", ret);
743                         } else {
744                                 g_print("### fgets return  NULL\n");
745                         }
746
747                 } else if (strncmp(cmd, "C", 1) == 0) {
748                         int ret = 0;
749                         mm_sound_device_flags_e flags = select_device_flags();
750
751                         g_print("device_connected_callback");
752                         ret = mm_sound_add_device_connected_callback(flags, device_connected_cb, NULL, &g_subs_id_device_conn);
753                         if (ret)
754                                 g_print("failed to mm_sound_add_device_connected_callback(), ret[0x%x]\n", ret);
755                         else
756                                 g_print("device_flags[0x%x], callback fun[%p], subs_id[%u]\n", flags, device_connected_cb, g_subs_id_device_conn);
757
758                 } else if (strncmp(cmd, "D", 1) == 0) {
759                         int ret = 0;
760                         ret = mm_sound_remove_device_connected_callback(g_subs_id_device_conn);
761                         if (ret)
762                                 g_print("failed to mm_sound_remove_device_connected_callback(), ret[0x%x]\n", ret);
763
764                 } else if (strncmp(cmd, "Q", 1) == 0) {
765                         int ret = 0;
766                         mm_sound_device_flags_e flags = select_device_flags();
767
768                         g_print("add_device_state_changed");
769                         ret = mm_sound_add_device_state_changed_callback(flags, device_state_changed_cb, NULL, &g_subs_id_device_state);
770                         if (ret)
771                                 g_print("failed to mm_sound_add_device_state_changed_callback(), ret[0x%x]\n", ret);
772                         else
773                                 g_print("device_flags[0x%x], callback fun[%p], subs_id[%u]\n", flags, device_state_changed_cb, g_subs_id_device_state);
774
775                 } else if (strncmp(cmd, "W", 1) == 0) {
776                         int ret = 0;
777                         ret = mm_sound_remove_device_state_changed_callback(g_subs_id_device_state);
778                         if (ret)
779                                 g_print("failed to mm_sound_remove_device_state_changed_callback(), ret[0x%x]\n", ret);
780
781                 } else if (strncmp(cmd, "x", 1) == 0) {
782                         quit_program();
783                 }
784                 break;
785
786         case CURRENT_STATUS_FILENAME:
787                 input_filename(cmd);
788                 g_menu_state = CURRENT_STATUS_MAINMENU;
789                 break;
790
791         case CURRENT_STATUS_DIRNAME:
792                 input_dirname(cmd);
793                 g_menu_state = CURRENT_STATUS_MAINMENU;
794                 break;
795
796         case CURRENT_STATUS_POSITION:
797                 break;
798
799         }
800 }
801
802 void volume_change_callback(volume_type_t type, unsigned int volume, void *user_data)
803 {
804         if (type == VOLUME_TYPE_MEDIA)
805                 g_print("Volume Callback Runs :::: MEDIA VALUME %d\n", volume);
806 }
807
808 int main(int argc, char *argv[])
809 {
810         int ret = 0;
811 #ifdef USE_GCOV
812         mm_sound_gcov_set_prefix();
813 #endif
814         stdin_channel = g_io_channel_unix_new(0);
815         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
816         g_loop = g_main_loop_new(NULL, 1);
817
818         MMSOUND_STRNCPY(g_file_name, POWERON_FILE, MAX_STRING_LEN);
819         g_print("\nThe input filename is '%s' \n\n", g_file_name);
820
821         /* test volume changed callback */
822         g_print("callback function addr :: %p\n", volume_change_callback);
823         g_volume_type = VOLUME_TYPE_MEDIA;
824         ret = mm_sound_volume_get_value(g_volume_type, &g_volume_value);
825         if (ret < 0)
826                 g_print("mm_sound_volume_get_value 0x%x\n", ret);
827
828         mm_sound_add_volume_changed_callback(volume_change_callback, (void*) &g_volume_type, &g_subs_id_volume);
829
830         displaymenu();
831         g_main_loop_run(g_loop);
832
833         return 0;
834 }