4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungbae Shin <seungbae.shin@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
42 #include <sys/types.h>
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"
52 #define MM_SOUND_KEYTONE_PATH "MM_SOUND_KEYTONE_PATH"
54 #define MM_SOUND_KEYTONE_COUNT "MM_SOUND_KEYTONE_COUNT"
55 #define MM_SOUND_KEYTONE_COUNT_MAX 10000
57 #define MM_SOUND_KEYTONE_INTERVAL "MM_SOUND_KEYTONE_INTERVAL"
58 #define MM_SOUND_KEYTONE_INTERVAL_MAX 10000 /* 10 sec. */
61 CURRENT_STATUS_MAINMENU = 0,
62 CURRENT_STATUS_FILENAME = 1,
63 CURRENT_STATUS_POSITION = 2,
64 CURRENT_STATUS_DIRNAME = 3,
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;
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);
83 static void print_device_info(MMSoundDevice_t device_h)
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;
90 int vendor_id = -1, product_id = -1;
91 char vendor_string[MAX_STRING_LEN], product_string[MAX_STRING_LEN];
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);
117 snprintf(vendor_string, MAX_STRING_LEN, "NO ID");
119 snprintf(vendor_string, MAX_STRING_LEN, "%d", vendor_id);
121 if (product_id == -1)
122 snprintf(product_string, MAX_STRING_LEN, "NO ID");
124 snprintf(product_string, MAX_STRING_LEN, "%d", product_id);
126 debug_log("[DEVICE INFO]--------------------------- \n"
129 "io_direction : %d\n"
134 device_type, id, io_direction, state, name, vendor_string, product_string);
137 void mycallback(void *data, int id)
139 char *str = (char*)data;
141 debug_log("mycallback called (user data:%s ,id:%d)", str, id);
143 debug_log("mycallback called (no user data)");
145 static volatile char test_callback_done;
146 void test_callback(void *data, int id)
148 debug_log("test_callback is called");
149 test_callback_done = 1;
151 void mm_sound_test_cb1(int a, void *user_data)
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());
156 void device_connected_cb(MMSoundDevice_t device_h, bool is_connected, void *user_data)
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);
161 void device_state_changed_cb(MMSoundDevice_t device_h, mm_sound_device_state_e new_state, void *user_data)
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);
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)
170 if (state == FOCUS_IS_RELEASED)
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);
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)
181 if (state == FOCUS_IS_RELEASED)
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);
191 g_main_loop_quit(g_loop);
194 static void displaymenu()
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 : ");
258 g_print("**** Unknown status.\n");
263 gboolean timeout_menu_display(void* data)
269 gboolean timeout_quit_program(void* data)
275 gboolean input(GIOChannel *channel)
281 if (g_io_channel_read_line(channel, &buf, &length, NULL, &err) == G_IO_STATUS_NORMAL) {
290 g_print("g_io_channel_read_line() error (%s)", err->message);
297 static void input_filename(char *filename)
299 MMSOUND_STRNCPY(g_file_name, filename, MAX_STRING_LEN);
300 g_print("\nThe input filename is '%s' \n\n", g_file_name);
304 static void input_dirname(char *dirname)
306 MMSOUND_STRNCPY(g_dir_name, dirname, MAX_PATH_LEN);
307 g_print("\nThe input directory is '%s' \n\n", g_dir_name);
310 mm_sound_device_flags_e no2flag(char flag_no)
314 return MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
316 return MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
318 return MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
320 return MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
322 return MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
324 return MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
326 return MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
328 return MM_SOUND_DEVICE_ALL_FLAG;
332 mm_sound_device_flags_e select_device_flags(void)
334 char input_string[MAX_STRING_LEN];
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'): ");
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;
352 return (no2flag(input_string[0]) | no2flag(input_string[2]) | no2flag(input_string[4]));
355 static const char *env_get_str(const char *key, const char *default_str)
357 char *env_str = getenv(key);
359 return env_str ? env_str : default_str;
362 static unsigned int env_get_uint(const char *key, unsigned int min, unsigned int max, unsigned int default_value)
364 char *env_str = getenv(key);
365 unsigned int value = 0;
368 return default_value;
370 value = (unsigned int)atoi(env_str);
372 g_assert(value >= min);
373 g_assert(value <= max);
378 static void interpret(char *cmd)
382 switch (g_menu_state) {
383 case CURRENT_STATUS_MAINMENU:
384 if (strncmp(cmd, "SF", 2) == 0) {
386 char input_string[128];
388 char *stream_type = NULL;
389 const char *user_data = "this is user data";
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: ");
403 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
404 select = input_string[0];
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";
425 ret = mm_sound_register_focus(stream_type, focus_cb, (void*)user_data, &g_focus_id);
427 g_print("failed to mm_sound_register_focus(), ret[0x%x]\n", ret);
429 g_print("id[%d], stream_type[%s], callback fun[%p]\n", g_focus_id, stream_type, focus_cb);
431 g_print("### fgets return NULL\n");
433 } else if (strncmp(cmd, "UF", 2) == 0) {
436 ret = mm_sound_unregister_focus(g_focus_id);
438 g_print("failed to mm_sound_unregister_focus(), ret[0x%x]\n", ret);
439 } else if (strncmp(cmd, "DF", 2) == 0) {
441 char input_string[128];
444 bool reacquisition = true;
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];
455 else if (flag_1 == '1')
457 else if (flag_1 == '2')
461 reacquisition = true;
462 else if (flag_2 == '2')
463 reacquisition = false;
465 ret = mm_sound_set_focus_reacquisition(id, reacquisition);
467 g_print("failed to mm_sound_disable_focus_reacquirement(), ret[0x%x]\n", ret);
469 g_print("### fgets return NULL\n");
471 } else if (strncmp(cmd, "AF", 2) == 0) {
473 char input_string[128];
476 mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
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];
488 else if (flag_1 == '1')
492 type = FOCUS_FOR_PLAYBACK;
493 else if (flag_2 == '2')
494 type = FOCUS_FOR_CAPTURE;
496 ret = mm_sound_acquire_focus(id, type, "additional_info. for acquire");
498 g_print("failed to mm_sound_acquire_focus(), ret[0x%x]\n", ret);
501 g_print("### fgets return NULL\n");
504 } else if (strncmp(cmd, "RF", 2) == 0) {
506 char input_string[128];
509 mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
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];
521 else if (flag_1 == '1')
525 type = FOCUS_FOR_PLAYBACK;
526 else if (flag_2 == '2')
527 type = FOCUS_FOR_CAPTURE;
529 ret = mm_sound_release_focus(id, type, "additional_info. for release");
531 g_print("failed to mm_sound_release_focus(), ret[0x%x]\n", ret);
534 g_print("### fgets return NULL\n");
537 } else if (strncmp(cmd, "WS", 2) == 0) {
539 char input_string[128];
542 const char *user_data = "this is user data for watch";
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:");
550 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
551 flag_1 = input_string[0];
555 else if (flag_1 == '2')
557 else if (flag_1 == '3')
560 ret = mm_sound_set_focus_watch_callback(type, focus_watch_cb, (void*)user_data, &g_focus_watch_index);
562 g_print("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
564 g_print("index[%d], type[%d], callback fun[%p]\n", g_focus_watch_index, type, focus_watch_cb);
566 g_print("### fgets return NULL\n");
569 } else if (strncmp(cmd, "WU", 2) == 0) {
571 ret = mm_sound_unset_focus_watch_callback(g_focus_watch_index);
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);
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);
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);
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);
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);
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;
598 g_message("keytone path(%s), count(%u), interval(%u us)",
599 keytone_path, count, interval_us);
601 for (unsigned int i = 0; i < count; i++) {
602 ret = mm_sound_play_keysound(keytone_path, 0);
604 debug_error("keysound play failed with 0x%x", ret);
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);
614 debug_log("mm_sound_volume_get_value 0x%x", ret);
616 g_print("*** MEDIA VOLUME : %u ***\n", value);
617 g_volume_value = value;
620 } else if (strncmp(cmd, "e", 1) == 0) {
621 unsigned int value = 100;
622 ret = mm_sound_volume_get_value(g_volume_type, &value);
624 debug_log("mm_sound_volume_get_value 0x%x", ret);
628 ret = mm_sound_volume_set_value(g_volume_type, value);
630 debug_log("mm_sound_volume_set_value 0x%x", ret);
633 } else if (strncmp(cmd, "r", 1) == 0) {
634 unsigned int value = 100;
635 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
637 debug_log("mm_sound_volume_get_value 0x%x", ret);
639 g_print("*** SYSTEM VOLUME : %u ***\n", value);
640 g_volume_value = value;
643 } else if (strncmp(cmd, "y", 1) == 0) {
644 unsigned int value = 100;
645 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
647 debug_log("mm_sound_volume_get_value 0x%x", ret);
652 ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
654 debug_log("mm_sound_volume_set_value 0x%x", ret);
656 g_print("Current System volume is %d\n", value);
659 } else if (strncmp(cmd, "g", 1) == 0) {
660 unsigned int value = 100;
661 ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
663 debug_log("mm_sound_volume_get_value 0x%x", ret);
665 g_print("*** VOICE VOLUME : %u ***\n", value);
666 g_volume_value = value;
669 } else if (strncmp(cmd, "j", 1) == 0) {
670 unsigned int value = 100;
671 ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
673 debug_log("mm_sound_volume_get_value 0x%x", ret);
678 ret = mm_sound_volume_set_value(VOLUME_TYPE_VOICE, value);
680 debug_log("mm_sound_volume_set_value 0x%x", ret);
682 g_print("Current Voice volume is %d\n", value);
685 } else if (strncmp(cmd, "f", 1) == 0) {
686 g_menu_state = CURRENT_STATUS_FILENAME;
688 } else if (strncmp(cmd, "d", 1) == 0) {
689 g_menu_state = CURRENT_STATUS_DIRNAME;
691 } else if (strncmp(cmd, "L", 1) == 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;
698 ret = mm_sound_get_current_device_list(flags, &device_list);
700 g_print("failed to mm_sound_get_current_device_list(), ret[0x%x]\n", ret);
702 g_print("device_list[%p], device_h[%p]\n", device_list, device_h);
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);
710 } while (dret == MM_ERROR_NONE);
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);
718 } while (dret == MM_ERROR_NONE);
721 } else if (strncmp(cmd, "I", 1) == 0) {
723 MMSoundDevice_t device_h = NULL;
725 char input_string[128];
728 g_print("> Input id : ");
730 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
731 input_id = atoi(input_string);
733 ret = mm_sound_get_device_by_id(input_id, &device_h);
734 if (ret == MM_ERROR_NONE) {
735 print_device_info(device_h);
737 g_print("failed to mm_sound_get_device_by_id(), ret[0x%x]\n", ret);
740 ret = mm_sound_free_device(device_h);
742 g_print("failed to mm_sound_free_device(), ret[0x%x]\n", ret);
744 g_print("### fgets return NULL\n");
747 } else if (strncmp(cmd, "C", 1) == 0) {
749 mm_sound_device_flags_e flags = select_device_flags();
751 g_print("device_connected_callback");
752 ret = mm_sound_add_device_connected_callback(flags, device_connected_cb, NULL, &g_subs_id_device_conn);
754 g_print("failed to mm_sound_add_device_connected_callback(), ret[0x%x]\n", ret);
756 g_print("device_flags[0x%x], callback fun[%p], subs_id[%u]\n", flags, device_connected_cb, g_subs_id_device_conn);
758 } else if (strncmp(cmd, "D", 1) == 0) {
760 ret = mm_sound_remove_device_connected_callback(g_subs_id_device_conn);
762 g_print("failed to mm_sound_remove_device_connected_callback(), ret[0x%x]\n", ret);
764 } else if (strncmp(cmd, "Q", 1) == 0) {
766 mm_sound_device_flags_e flags = select_device_flags();
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);
771 g_print("failed to mm_sound_add_device_state_changed_callback(), ret[0x%x]\n", ret);
773 g_print("device_flags[0x%x], callback fun[%p], subs_id[%u]\n", flags, device_state_changed_cb, g_subs_id_device_state);
775 } else if (strncmp(cmd, "W", 1) == 0) {
777 ret = mm_sound_remove_device_state_changed_callback(g_subs_id_device_state);
779 g_print("failed to mm_sound_remove_device_state_changed_callback(), ret[0x%x]\n", ret);
781 } else if (strncmp(cmd, "x", 1) == 0) {
786 case CURRENT_STATUS_FILENAME:
788 g_menu_state = CURRENT_STATUS_MAINMENU;
791 case CURRENT_STATUS_DIRNAME:
793 g_menu_state = CURRENT_STATUS_MAINMENU;
796 case CURRENT_STATUS_POSITION:
802 void volume_change_callback(volume_type_t type, unsigned int volume, void *user_data)
804 if (type == VOLUME_TYPE_MEDIA)
805 g_print("Volume Callback Runs :::: MEDIA VALUME %d\n", volume);
808 int main(int argc, char *argv[])
812 mm_sound_gcov_set_prefix();
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);
818 MMSOUND_STRNCPY(g_file_name, POWERON_FILE, MAX_STRING_LEN);
819 g_print("\nThe input filename is '%s' \n\n", g_file_name);
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);
826 g_print("mm_sound_volume_get_value 0x%x\n", ret);
828 mm_sound_add_volume_changed_callback(volume_change_callback, (void*) &g_volume_type, &g_subs_id_volume);
831 g_main_loop_run(g_loop);