Remove sound_server legacies
[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 enum {
53         CURRENT_STATUS_MAINMENU = 0,
54         CURRENT_STATUS_FILENAME = 1,
55         CURRENT_STATUS_POSITION = 2,
56         CURRENT_STATUS_DIRNAME = 3,
57 };
58
59 static int g_focus_id = 0;
60 static int g_menu_state = CURRENT_STATUS_MAINMENU;
61 static volume_type_t g_volume_type = VOLUME_TYPE_MEDIA;
62 static unsigned int g_volume_value;
63 static GIOChannel *stdin_channel;
64 static char g_file_name[MAX_STRING_LEN];
65 static char g_dir_name[MAX_PATH_LEN];
66 static int g_focus_watch_index = -1;
67 static GMainLoop* g_loop;
68 static unsigned int g_subs_id_test, g_subs_id_volume, g_subs_id_device_conn, g_subs_id_device_state;
69
70 static void interpret(char *buf);
71 gboolean timeout_menu_display(void *data);
72 gboolean timeout_quit_program(void *data);
73 gboolean input(GIOChannel *channel);
74
75 void mycallback(void *data, int id)
76 {
77         char *str = (char*)data;
78         if (data != NULL)
79                 debug_log("mycallback called (user data:%s ,id:%d)", str, id);
80         else
81                 debug_log("mycallback called (no user data)");
82 }
83 static volatile char test_callback_done;
84 void test_callback(void *data, int id)
85 {
86         debug_log("test_callback is called");
87         test_callback_done = 1;
88 }
89 void mm_sound_test_cb1(int a, void *user_data)
90 {
91         debug_log("dbus test user callback called: param(%d), userdata(%d)", a, (int)user_data);
92         g_print("my callback pid : %u  tid : %ld\n", getpid(), pthread_self());
93 }
94 void device_connected_cb(MMSoundDevice_t device_h, bool is_connected, void *user_data)
95 {
96         int ret = 0;
97         mm_sound_device_type_e device_type = 0;
98         mm_sound_device_io_direction_e io_direction = 0;
99         mm_sound_device_state_e state = 0;
100         int id = 0;
101         int vendor_id = -1, product_id = -1;
102         char *name = NULL;
103
104         debug_log("*** device_connected_cb is called, device_h[%p], is_connected[%d], user_data[%p]", device_h, is_connected, user_data);
105         ret = mm_sound_get_device_type(device_h, &device_type);
106         if (ret)
107                 debug_error("failed to mm_sound_get_device_type()");
108         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
109         if (ret)
110                 debug_error("failed to mm_sound_get_device_io_direction()");
111         ret = mm_sound_get_device_state(device_h, &state);
112         if (ret)
113                 debug_error("failed to mm_sound_get_device_state()");
114         ret = mm_sound_get_device_id(device_h, &id);
115         if (ret)
116                 debug_error("failed to mm_sound_get_device_id()");
117         ret = mm_sound_get_device_name(device_h, &name);
118         if (ret)
119                 debug_error("failed to mm_sound_get_device_name()");
120         ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
121         if (ret)
122                 debug_error("failed to mm_sound_get_device_vendor_id()");
123         ret = mm_sound_get_device_product_id(device_h, &product_id);
124         if (ret)
125                 debug_error("failed to mm_sound_get_device_produt_id()");
126         debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s], "
127                         "vendor-id(%04x) product-id(%04x)",
128                         device_type, id, io_direction, state, name, vendor_id, product_id);
129 }
130 void device_state_changed_cb(MMSoundDevice_t device_h, mm_sound_device_state_e new_state, void *user_data)
131 {
132         int ret = 0;
133         mm_sound_device_type_e device_type = 0;
134         mm_sound_device_io_direction_e io_direction = 0;
135         mm_sound_device_state_e state = 0;
136         int id = 0;
137         char *name = NULL;
138         int vendor_id = -1, product_id = -1;
139
140         debug_log("*** device_state_changed_cb is called, device_h[%p], state[%d], user_data[%p]", device_h, new_state, user_data);
141         ret = mm_sound_get_device_type(device_h, &device_type);
142         if (ret)
143                 debug_error("failed to mm_sound_get_device_type()");
144         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
145         if (ret)
146                 debug_error("failed to mm_sound_get_device_io_direction()");
147         ret = mm_sound_get_device_state(device_h, &state);
148         if (ret)
149                 debug_error("failed to mm_sound_get_device_state()");
150         ret = mm_sound_get_device_id(device_h, &id);
151         if (ret)
152                 debug_error("failed to mm_sound_get_device_id()");
153         ret = mm_sound_get_device_name(device_h, &name);
154         if (ret)
155                 debug_error("failed to mm_sound_get_device_name()");
156         ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
157         if (ret)
158                 debug_error("failed to mm_sound_get_device_vendor_id()");
159         ret = mm_sound_get_device_product_id(device_h, &product_id);
160         if (ret)
161                 debug_error("failed to mm_sound_get_device_produt_id()");
162         debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s], "
163                         "vendor-id(%04x) product-id(%04x)",
164                         device_type, id, io_direction, state, name, vendor_id, product_id);
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         return TRUE;
290 }
291
292
293 static void input_filename(char *filename)
294 {
295         MMSOUND_STRNCPY(g_file_name, filename, MAX_STRING_LEN);
296         g_print("\nThe input filename is '%s' \n\n", g_file_name);
297
298 }
299
300 static void input_dirname(char *dirname)
301 {
302         MMSOUND_STRNCPY(g_dir_name, dirname, MAX_PATH_LEN);
303         g_print("\nThe input directory is '%s' \n\n", g_dir_name);
304 }
305
306 static void interpret(char *cmd)
307 {
308         int ret = 0;
309
310         switch (g_menu_state) {
311         case CURRENT_STATUS_MAINMENU:
312                 if (strncmp(cmd, "SF", 2) == 0) {
313                         int ret = 0;
314                         char input_string[128];
315                         char select;
316                         char *stream_type = NULL;
317                         const char *user_data = "this is user data";
318
319                         fflush(stdin);
320                         g_print("1. Media\n");
321                         g_print("2. Alarm\n");
322                         g_print("3. Notification\n");
323                         g_print("4. Emergency\n");
324                         g_print("5. Voice Information\n");
325                         g_print("6. Ringtone\n");
326                         g_print("7. Ringtone Call\n");
327                         g_print("8. VOIP\n");
328                         g_print("0. Voice Recognition\n");
329                         g_print("> stream type: ");
330
331                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
332                                 select = input_string[0];
333
334                                 if (select == '1')
335                                         stream_type = "media";
336                                 else if (select == '2')
337                                         stream_type = "alarm";
338                                 else if (select == '3')
339                                         stream_type = "notification";
340                                 else if (select == '4')
341                                         stream_type = "emergency";
342                                 else if (select == '5')
343                                         stream_type = "voice-information";
344                                 else if (select == '6')
345                                         stream_type = "ringtone";
346                                 else if (select == '7')
347                                         stream_type = "ringtone-call";
348                                 else if (select == '8')
349                                         stream_type = "voip";
350                                 else if (select == '0')
351                                         stream_type = "voice-recognition";
352
353                                 ret = mm_sound_register_focus(stream_type, focus_cb, (void*)user_data, &g_focus_id);
354                                 if (ret)
355                                         g_print("failed to mm_sound_register_focus(), ret[0x%x]\n", ret);
356                                 else
357                                         g_print("id[%d], stream_type[%s], callback fun[%p]\n", g_focus_id, stream_type, focus_cb);
358                         } else {
359                                 g_print("### fgets return  NULL\n");
360                         }
361                 } else if (strncmp(cmd, "UF", 2) == 0) {
362                         int ret = 0;
363
364                         ret = mm_sound_unregister_focus(g_focus_id);
365                         if (ret)
366                                 g_print("failed to mm_sound_unregister_focus(), ret[0x%x]\n", ret);
367                 } else if (strncmp(cmd, "DF", 2) == 0) {
368                         int ret = 0;
369                         char input_string[128];
370                         char flag_1, flag_2;
371                         int id = 2;
372                         bool reacquisition = true;
373                         fflush(stdin);
374                         g_print("1. enable auto reacquirement\n");
375                         g_print("2. disable auto reacquirement\n");
376                         g_print("> select id and option: (eg. 0 1)");
377                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
378                                 flag_1 = input_string[0];
379                                 flag_2 = input_string[2];
380
381                                 if (flag_1 == '0')
382                                         id = 0;
383                                 else if (flag_1 == '1')
384                                         id = 1;
385                                 else if (flag_1 == '2')
386                                         id = 2;
387
388                                 if (flag_2 == '1')
389                                         reacquisition = true;
390                                 else if (flag_2 == '2')
391                                         reacquisition = false;
392
393                                 ret = mm_sound_set_focus_reacquisition(id, reacquisition);
394                                 if (ret)
395                                         g_print("failed to mm_sound_disable_focus_reacquirement(), ret[0x%x]\n", ret);
396                         } else {
397                                 g_print("### fgets return  NULL\n");
398                         }
399                 } else if (strncmp(cmd, "AF", 2) == 0) {
400                         int ret = 0;
401                         char input_string[128];
402                         char flag_1, flag_2;
403                         int id = 0;
404                         mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
405                         fflush(stdin);
406                         g_print("1. focus for playback\n");
407                         g_print("2. focus for recording\n");
408                         g_print("3. focus for both\n");
409                         g_print("> select id and focus_type: (eg. 0 1)");
410                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
411                                 flag_1 = input_string[0];
412                                 flag_2 = input_string[2];
413
414                                 if (flag_1 == '0')
415                                         id = 0;
416                                 else if (flag_1 == '1')
417                                         id = 1;
418
419                                 if (flag_2 == '1')
420                                         type = FOCUS_FOR_PLAYBACK;
421                                 else if (flag_2 == '2')
422                                         type = FOCUS_FOR_CAPTURE;
423
424                                 ret = mm_sound_acquire_focus(id, type, "additional_info. for acquire");
425                                 if (ret)
426                                         g_print("failed to mm_sound_acquire_focus(), ret[0x%x]\n", ret);
427
428                         } else {
429                                 g_print("### fgets return  NULL\n");
430                         }
431
432                 } else if (strncmp(cmd, "RF", 2) == 0) {
433                         int ret = 0;
434                         char input_string[128];
435                         char flag_1, flag_2;
436                         int id = 2;
437                         mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
438                         fflush(stdin);
439                         g_print("1. focus for playback\n");
440                         g_print("2. focus for recording\n");
441                         g_print("3. focus for all\n");
442                         g_print("> select id and focus_type: (eg. 0 1)");
443                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
444                                 flag_1 = input_string[0];
445                                 flag_2 = input_string[2];
446
447                                 if (flag_1 == '0')
448                                         id = 0;
449                                 else if (flag_1 == '1')
450                                         id = 1;
451
452                                 if (flag_2 == '1')
453                                         type = FOCUS_FOR_PLAYBACK;
454                                 else if (flag_2 == '2')
455                                         type = FOCUS_FOR_CAPTURE;
456
457                                 ret = mm_sound_release_focus(id, type, "additional_info. for release");
458                                 if (ret)
459                                         g_print("failed to mm_sound_release_focus(), ret[0x%x]\n", ret);
460
461                         } else {
462                                 g_print("### fgets return  NULL\n");
463                         }
464
465                 } else if (strncmp(cmd, "WS", 2) == 0) {
466                         int ret = 0;
467                         char input_string[128];
468                         char flag_1;
469                         int type = 1;
470                         const char *user_data = "this is user data for watch";
471
472                         fflush(stdin);
473                         g_print("1. playback\n");
474                         g_print("2. recording\n");
475                         g_print("3. both\n");
476                         g_print("> select interest focus type:");
477
478                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
479                                 flag_1 = input_string[0];
480
481                                 if (flag_1 == '1')
482                                         type = 1;
483                                 else if (flag_1 == '2')
484                                         type = 2;
485                                 else if (flag_1 == '3')
486                                         type = 3;
487
488                                 ret = mm_sound_set_focus_watch_callback(type, focus_watch_cb, (void*)user_data, &g_focus_watch_index);
489                                 if (ret)
490                                         g_print("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
491                                 else
492                                         g_print("index[%d], type[%d], callback fun[%p]\n", g_focus_watch_index, type, focus_watch_cb);
493                         } else {
494                                 g_print("### fgets return  NULL\n");
495                         }
496
497                 } else if (strncmp(cmd, "WU", 2) == 0) {
498                         int ret = 0;
499                         ret = mm_sound_unset_focus_watch_callback(g_focus_watch_index);
500                         if (ret)
501                                 g_print("failed to mm_sound_unset_focus_watch_callback(), ret[0x%x]\n", ret);
502                 } else if (strncmp(cmd, "ksn", 3) == 0) {
503                         ret = mm_sound_stop_keysound(KEYTONE_NOTI_FILE);
504                         if (ret < 0)
505                                 debug_error("keysound stop(noti) failed with 0x%x", ret);
506                 } else if (strncmp(cmd, "ksa", 3) == 0) {
507                         ret = mm_sound_stop_keysound(NULL);
508                         if (ret < 0)
509                                 debug_error("keysound stop(all) failed with 0x%x", ret);
510                 } else if (strncmp(cmd, "kn", 2) == 0) {
511                         ret = mm_sound_play_keysound(KEYTONE_NOTI_FILE, VOLUME_TYPE_NOTIFICATION);
512                         if (ret < 0)
513                                 debug_error("keysound play(noti) failed with 0x%x", ret);
514                 } else if (strncmp(cmd, "ks", 2) == 0) {
515                         ret = mm_sound_stop_keysound(KEYTONE_FILE);
516                         if (ret < 0)
517                                 debug_error("keysound stop failed with 0x%x", ret);
518                 } else if (strncmp(cmd, "k", 1) == 0) {
519                         ret = mm_sound_play_keysound(KEYTONE_FILE, 0);
520                         if (ret < 0)
521                                 debug_error("keysound play failed with 0x%x", ret);
522                 } else if (strncmp(cmd, "q", 1) == 0) {
523                         unsigned int value = 100;
524                         ret = mm_sound_volume_get_value(g_volume_type, &value);
525                         if (ret < 0) {
526                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
527                         } else {
528                                 g_print("*** MEDIA VOLUME : %u ***\n", value);
529                                 g_volume_value = value;
530                         }
531
532                 } else if (strncmp(cmd, "e", 1) == 0) {
533                         unsigned int value = 100;
534                         ret = mm_sound_volume_get_value(g_volume_type, &value);
535                         if (ret < 0) {
536                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
537                         } else {
538                                 if (value != 0)
539                                         value--;
540                                 ret = mm_sound_volume_set_value(g_volume_type, value);
541                                 if (ret < 0)
542                                         debug_log("mm_sound_volume_set_value 0x%x", ret);
543                         }
544
545                 } else if (strncmp(cmd, "r", 1) == 0) {
546                         unsigned int value = 100;
547                         ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
548                         if (ret < 0) {
549                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
550                         } else {
551                                 g_print("*** SYSTEM VOLUME : %u ***\n", value);
552                                 g_volume_value = value;
553                         }
554
555                 } else if (strncmp(cmd, "y", 1) == 0) {
556                         unsigned int value = 100;
557                         ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
558                         if (ret < 0) {
559                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
560                         } else {
561                                 if (value != 0)
562                                         value--;
563
564                                 ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
565                                 if (ret < 0)
566                                         debug_log("mm_sound_volume_set_value 0x%x", ret);
567                                 else
568                                         g_print("Current System volume is %d\n", value);
569                         }
570
571                 } else if (strncmp(cmd, "g", 1) == 0) {
572                         unsigned int value = 100;
573                         ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
574                         if (ret < 0) {
575                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
576                         } else {
577                                 g_print("*** VOICE VOLUME : %u ***\n", value);
578                                 g_volume_value = value;
579                         }
580
581                 } else if (strncmp(cmd, "j", 1) == 0) {
582                         unsigned int value = 100;
583                         ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
584                         if (ret < 0) {
585                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
586                         } else {
587                                 if (value != 0)
588                                         value--;
589
590                                 ret = mm_sound_volume_set_value(VOLUME_TYPE_VOICE, value);
591                                 if (ret < 0)
592                                         debug_log("mm_sound_volume_set_value 0x%x", ret);
593                                 else
594                                         g_print("Current Voice volume is %d\n", value);
595                         }
596
597                 } else if (strncmp(cmd, "f", 1) == 0) {
598                         g_menu_state = CURRENT_STATUS_FILENAME;
599
600                 } else if (strncmp(cmd, "d", 1) == 0) {
601                         g_menu_state = CURRENT_STATUS_DIRNAME;
602
603                 } else if (strncmp(cmd, "L", 1) == 0) {
604                         int ret = 0;
605                         mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
606                         MMSoundDeviceList_t device_list;
607                         mm_sound_device_type_e device_type = 0;
608                         mm_sound_device_io_direction_e io_direction = 0;
609                         mm_sound_device_state_e state = 0;
610                         int id = 0;
611                         char *name = NULL;
612                         MMSoundDevice_t device_h = NULL;
613                         int dret = MM_ERROR_NONE;
614                         int product_id = -1, vendor_id = -1;
615
616                         ret = mm_sound_get_current_device_list(flags, &device_list);
617                         if (ret) {
618                                 g_print("failed to mm_sound_get_current_device_list(), ret[0x%x]\n", ret);
619                         } else {
620                                 g_print("device_list[%p], device_h[%p]\n", device_list, device_h);
621                                 do {
622                                         dret = mm_sound_get_next_device(device_list, &device_h);
623                                         if (dret) {
624                                                 debug_error("failed to mm_sound_get_next_device(), dret[0x%x]\n", dret);
625                                         } else {
626                                                 ret = mm_sound_get_device_type(device_h, &device_type);
627                                                 if (ret)
628                                                         debug_error("failed to mm_sound_get_device_type()");
629                                                 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
630                                                 if (ret)
631                                                         debug_error("failed to mm_sound_get_device_io_direction()");
632                                                 ret = mm_sound_get_device_state(device_h, &state);
633                                                 if (ret)
634                                                         debug_error("failed to mm_sound_get_device_state()");
635                                                 ret = mm_sound_get_device_id(device_h, &id);
636                                                 if (ret)
637                                                         debug_error("failed to mm_sound_get_device_id()");
638                                                 ret = mm_sound_get_device_name(device_h, &name);
639                                                 if (ret)
640                                                         debug_error("failed to mm_sound_get_device_name()");
641                                                 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
642                                                 if (ret)
643                                                         debug_error("failed to mm_sound_get_device_vendor_id()");
644                                                 ret = mm_sound_get_device_product_id(device_h, &product_id);
645                                                 if (ret)
646                                                         debug_error("failed to mm_sound_get_device_product_id()");
647                                                 debug_log("*** --- [NEXT DEVICE] type[%d], id[%d], io_direction[%d], state[%d], "
648                                                                 "name[%s] vendor_id[%04x] product_id[%04x]",
649                                                                 device_type, id, io_direction, state, name, vendor_id, product_id);
650                                         }
651                                 } while (dret == MM_ERROR_NONE);
652                                 do {
653                                         dret = MM_ERROR_NONE;
654                                         dret = mm_sound_get_prev_device(device_list, &device_h);
655                                         if (dret) {
656                                                 debug_error("failed to mm_sound_get_prev_device(), dret[0x%x]", dret);
657                                         } else {
658                                                 ret = mm_sound_get_device_type(device_h, &device_type);
659                                                 if (ret)
660                                                         debug_error("failed to mm_sound_get_device_type()");
661                                                 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
662                                                 if (ret)
663                                                         debug_error("failed to mm_sound_get_device_io_direction()");
664                                                 ret = mm_sound_get_device_state(device_h, &state);
665                                                 if (ret)
666                                                         debug_error("failed to mm_sound_get_device_state()");
667                                                 ret = mm_sound_get_device_id(device_h, &id);
668                                                 if (ret)
669                                                         debug_error("failed to mm_sound_get_device_id()");
670                                                 ret = mm_sound_get_device_name(device_h, &name);
671                                                 if (ret)
672                                                         debug_error("failed to mm_sound_get_device_name()");
673                                                 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
674                                                 if (ret)
675                                                         debug_error("failed to mm_sound_get_device_vendor_id()");
676                                                 ret = mm_sound_get_device_product_id(device_h, &product_id);
677                                                 if (ret)
678                                                         debug_error("failed to mm_sound_get_device_product_id()");
679                                                 debug_log("*** --- [PREV DEVICE] type[%d], id[%d], io_direction[%d], state[%d], "
680                                                                 "name[%s] vendor_id[%04x] product_id[%04x]",
681                                                                 device_type, id, io_direction, state, name, vendor_id, product_id);
682                                         }
683                                 } while (dret == MM_ERROR_NONE);
684                         }
685
686                 } else if (strncmp(cmd, "I", 1) == 0) {
687                         int ret = 0;
688                         MMSoundDevice_t device_h = NULL;
689                         mm_sound_device_type_e device_type = 0;
690                         mm_sound_device_io_direction_e io_direction = 0;
691                         mm_sound_device_state_e state = 0;
692                         char *name;
693                         int id = 0, input_id = 0;
694                         char input_string[128];
695
696                         fflush(stdin);
697                         g_print("> Input id : ");
698
699                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
700                                 input_id = atoi(input_string);
701
702                                 ret = mm_sound_get_device_by_id(input_id, &device_h);
703                                 if (ret == MM_ERROR_NONE) {
704                                         ret = mm_sound_get_device_type(device_h, &device_type);
705                                         if (ret)
706                                                 g_print("failed to mm_sound_get_device_type()\n");
707                                         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
708                                         if (ret)
709                                                 g_print("failed to mm_sound_get_device_io_direction()\n");
710                                         ret = mm_sound_get_device_state(device_h, &state);
711                                         if (ret)
712                                                 g_print("failed to mm_sound_get_device_state()\n");
713                                         ret = mm_sound_get_device_id(device_h, &id);
714                                         if (ret)
715                                                 g_print("failed to mm_sound_get_device_id()\n");
716                                         ret = mm_sound_get_device_name(device_h, &name);
717                                         if (ret)
718                                                 g_print("failed to mm_sound_get_device_name()\n");
719                                         g_print("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
720                                 } else {
721                                         g_print("failed to mm_sound_get_device_by_id()\n");
722                                 }
723
724                                 ret = mm_sound_free_device(device_h);
725                                 if (ret)
726                                         g_print("failed to mm_sound_free_device()\n");
727                         } else {
728                                 g_print("### fgets return  NULL\n");
729                         }
730
731                 } else if (strncmp(cmd, "C", 1) == 0) {
732                         int ret = 0;
733                         char input_string[128];
734                         mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
735                         mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
736                         mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
737
738                         char flag_1, flag_2, flag_3;
739
740                         fflush(stdin);
741                         g_print("1. IO_DIRECTION_IN_FLAG\n");
742                         g_print("2. IO_DIRECTION_OUT_FLAG\n");
743                         g_print("3. IO_DIRECTION_BOTH_FLAG\n");
744                         g_print("4. TYPE_INTERNAL_FLAG\n");
745                         g_print("5. TYPE_EXTERNAL_FLAG\n");
746                         g_print("6. STATE_DEACTIVATED_FLAG\n");
747                         g_print("7. STATE_ACTIVATED_FLAG\n");
748                         g_print("8. ALL_FLAG\n");
749                         g_print("> select flag numbers (total 3):  (eg. 2 5 7)");
750
751                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
752                                 flag_1 = input_string[0];
753                                 flag_2 = input_string[2];
754                                 flag_3 = input_string[4];
755
756                                 if (flag_1 == '1')
757                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
758                                 else if (flag_1 == '2')
759                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
760                                 else if (flag_1 == '3')
761                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
762                                 else if (flag_1 == '4')
763                                         device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
764                                 else if (flag_1 == '5')
765                                         device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
766                                 else if (flag_1 == '6')
767                                         device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
768                                 else if (flag_1 == '7')
769                                         device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
770                                 else if (flag_1 == '8')
771                                         device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
772
773                                 if (flag_2 == '1')device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
774                                 else if (flag_2 == '2')
775                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
776                                 else if (flag_2 == '3')
777                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
778                                 else if (flag_2 == '4')
779                                         device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
780                                 else if (flag_2 == '5')
781                                         device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
782                                 else if (flag_2 == '6')
783                                         device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
784                                 else if (flag_2 == '7')
785                                         device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
786                                 else if (flag_2 == '8')
787                                         device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
788
789                                 if (flag_3 == '1')
790                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
791                                 else if (flag_3 == '2')
792                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
793                                 else if (flag_3 == '3')
794                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
795                                 else if (flag_3 == '4')
796                                         device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
797                                 else if (flag_3 == '5')
798                                         device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
799                                 else if (flag_3 == '6')
800                                         device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
801                                 else if (flag_3 == '7')
802                                         device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
803                                 else if (flag_3 == '8')
804                                         device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
805
806                                 g_print("device_connected_callback");
807                                 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);
808                                 if (ret)
809                                         g_print("failed to mm_sound_add_device_connected_callback(), ret[0x%x]\n", ret);
810                                 else
811                                         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);
812                         } else {
813                                 g_print("### fgets return  NULL\n");
814                         }
815
816                 } else if (strncmp(cmd, "D", 1) == 0) {
817                         int ret = 0;
818                         ret = mm_sound_remove_device_connected_callback(g_subs_id_device_conn);
819                         if (ret)
820                                 g_print("failed to mm_sound_remove_device_connected_callback(), ret[0x%x]\n", ret);
821
822                 } else if (strncmp(cmd, "Q", 1) == 0) {
823                         int ret = 0;
824                         char input_string[128];
825                         mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
826                         mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
827                         mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
828
829                         char flag_1, flag_2, flag_3;
830
831                         fflush(stdin);
832                         g_print("1. IO_DIRECTION_IN_FLAG\n");
833                         g_print("2. IO_DIRECTION_OUT_FLAG\n");
834                         g_print("3. IO_DIRECTION_BOTH_FLAG\n");
835                         g_print("4. TYPE_INTERNAL_FLAG\n");
836                         g_print("5. TYPE_EXTERNAL_FLAG\n");
837                         g_print("6. STATE_DEACTIVATED_FLAG\n");
838                         g_print("7. STATE_ACTIVATED_FLAG\n");
839                         g_print("8. ALL_FLAG\n");
840                         g_print("> select flag numbers (total 3):  (eg. 2 5 7)");
841
842                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
843                                 flag_1 = input_string[0];
844                                 flag_2 = input_string[2];
845                                 flag_3 = input_string[4];
846
847                                 if (flag_1 == '1')
848                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
849                                 else if (flag_1 == '2')
850                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
851                                 else if (flag_1 == '3')
852                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
853                                 else if (flag_1 == '4')
854                                         device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
855                                 else if (flag_1 == '5')
856                                         device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
857                                 else if (flag_1 == '6')
858                                         device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
859                                 else if (flag_1 == '7')
860                                         device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
861                                 else if (flag_1 == '8')
862                                         device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
863
864                                 if (flag_2 == '1')
865                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
866                                 else if (flag_2 == '2')
867                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
868                                 else if (flag_2 == '3')
869                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
870                                 else if (flag_2 == '4')
871                                         device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
872                                 else if (flag_2 == '5')
873                                         device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
874                                 else if (flag_2 == '6')
875                                         device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
876                                 else if (flag_2 == '7')
877                                         device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
878                                 else if (flag_2 == '8')
879                                         device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
880
881                                 if (flag_3 == '1')
882                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
883                                 else if (flag_3 == '2')
884                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
885                                 else if (flag_3 == '3')
886                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
887                                 else if (flag_3 == '4')
888                                         device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
889                                 else if (flag_3 == '5')
890                                         device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
891                                 else if (flag_3 == '6')
892                                         device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
893                                 else if (flag_3 == '7')
894                                         device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
895                                 else if (flag_3 == '8')
896                                         device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
897
898                                 g_print("add_device_state_changed");
899                                 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);
900                                 if (ret)
901                                         g_print("failed to mm_sound_add_device_state_changed_callback(), ret[0x%x]\n", ret);
902                                 else
903                                         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);
904
905                         } else {
906                                 g_print("### fgets return  NULL\n");
907                         }
908
909                 } else if (strncmp(cmd, "W", 1) == 0) {
910                         int ret = 0;
911                         ret = mm_sound_remove_device_state_changed_callback(g_subs_id_device_state);
912                         if (ret)
913                                 g_print("failed to mm_sound_remove_device_state_changed_callback(), ret[0x%x]\n", ret);
914
915                 } else if (strncmp(cmd, "x", 1) == 0) {
916                         quit_program();
917                 }
918                 break;
919
920         case CURRENT_STATUS_FILENAME:
921                 input_filename(cmd);
922                 g_menu_state = CURRENT_STATUS_MAINMENU;
923                 break;
924
925         case CURRENT_STATUS_DIRNAME:
926                 input_dirname(cmd);
927                 g_menu_state = CURRENT_STATUS_MAINMENU;
928                 break;
929
930         case CURRENT_STATUS_POSITION:
931                 break;
932
933         }
934 }
935
936 void volume_change_callback(volume_type_t type, unsigned int volume, void *user_data)
937 {
938         if (type == VOLUME_TYPE_MEDIA)
939                 g_print("Volume Callback Runs :::: MEDIA VALUME %d\n", volume);
940 }
941
942 int main(int argc, char *argv[])
943 {
944         int ret = 0;
945 #ifdef USE_GCOV
946         mm_sound_gcov_set_prefix();
947 #endif
948         stdin_channel = g_io_channel_unix_new(0);
949         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
950         g_loop = g_main_loop_new(NULL, 1);
951
952         MMSOUND_STRNCPY(g_file_name, POWERON_FILE, MAX_STRING_LEN);
953         g_print("\nThe input filename is '%s' \n\n", g_file_name);
954
955         /* test volume changed callback */
956         g_print("callback function addr :: %p\n", volume_change_callback);
957         g_volume_type = VOLUME_TYPE_MEDIA;
958         ret = mm_sound_volume_get_value(g_volume_type, &g_volume_value);
959         if (ret < 0)
960                 g_print("mm_sound_volume_get_value 0x%x\n", ret);
961
962         mm_sound_add_volume_changed_callback(volume_change_callback, (void*) &g_volume_type, &g_subs_id_volume);
963
964         displaymenu();
965         g_main_loop_run(g_loop);
966
967         return 0;
968 }