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"
53 CURRENT_STATUS_MAINMENU = 0,
54 CURRENT_STATUS_FILENAME = 1,
55 CURRENT_STATUS_POSITION = 2,
56 CURRENT_STATUS_DIRNAME = 3,
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;
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);
75 void mycallback(void *data, int id)
77 char *str = (char*)data;
79 debug_log("mycallback called (user data:%s ,id:%d)", str, id);
81 debug_log("mycallback called (no user data)");
83 static volatile char test_callback_done;
84 void test_callback(void *data, int id)
86 debug_log("test_callback is called");
87 test_callback_done = 1;
89 void mm_sound_test_cb1(int a, void *user_data)
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());
94 void device_connected_cb(MMSoundDevice_t device_h, bool is_connected, void *user_data)
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;
101 int vendor_id = -1, product_id = -1;
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);
107 debug_error("failed to mm_sound_get_device_type()");
108 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
110 debug_error("failed to mm_sound_get_device_io_direction()");
111 ret = mm_sound_get_device_state(device_h, &state);
113 debug_error("failed to mm_sound_get_device_state()");
114 ret = mm_sound_get_device_id(device_h, &id);
116 debug_error("failed to mm_sound_get_device_id()");
117 ret = mm_sound_get_device_name(device_h, &name);
119 debug_error("failed to mm_sound_get_device_name()");
120 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
122 debug_error("failed to mm_sound_get_device_vendor_id()");
123 ret = mm_sound_get_device_product_id(device_h, &product_id);
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);
130 void device_state_changed_cb(MMSoundDevice_t device_h, mm_sound_device_state_e new_state, void *user_data)
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;
138 int vendor_id = -1, product_id = -1;
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);
143 debug_error("failed to mm_sound_get_device_type()");
144 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
146 debug_error("failed to mm_sound_get_device_io_direction()");
147 ret = mm_sound_get_device_state(device_h, &state);
149 debug_error("failed to mm_sound_get_device_state()");
150 ret = mm_sound_get_device_id(device_h, &id);
152 debug_error("failed to mm_sound_get_device_id()");
153 ret = mm_sound_get_device_name(device_h, &name);
155 debug_error("failed to mm_sound_get_device_name()");
156 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
158 debug_error("failed to mm_sound_get_device_vendor_id()");
159 ret = mm_sound_get_device_product_id(device_h, &product_id);
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);
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) {
293 static void input_filename(char *filename)
295 MMSOUND_STRNCPY(g_file_name, filename, MAX_STRING_LEN);
296 g_print("\nThe input filename is '%s' \n\n", g_file_name);
300 static void input_dirname(char *dirname)
302 MMSOUND_STRNCPY(g_dir_name, dirname, MAX_PATH_LEN);
303 g_print("\nThe input directory is '%s' \n\n", g_dir_name);
306 static void interpret(char *cmd)
310 switch (g_menu_state) {
311 case CURRENT_STATUS_MAINMENU:
312 if (strncmp(cmd, "SF", 2) == 0) {
314 char input_string[128];
316 char *stream_type = NULL;
317 const char *user_data = "this is user data";
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: ");
331 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
332 select = input_string[0];
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";
353 ret = mm_sound_register_focus(stream_type, focus_cb, (void*)user_data, &g_focus_id);
355 g_print("failed to mm_sound_register_focus(), ret[0x%x]\n", ret);
357 g_print("id[%d], stream_type[%s], callback fun[%p]\n", g_focus_id, stream_type, focus_cb);
359 g_print("### fgets return NULL\n");
361 } else if (strncmp(cmd, "UF", 2) == 0) {
364 ret = mm_sound_unregister_focus(g_focus_id);
366 g_print("failed to mm_sound_unregister_focus(), ret[0x%x]\n", ret);
367 } else if (strncmp(cmd, "DF", 2) == 0) {
369 char input_string[128];
372 bool reacquisition = true;
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];
383 else if (flag_1 == '1')
385 else if (flag_1 == '2')
389 reacquisition = true;
390 else if (flag_2 == '2')
391 reacquisition = false;
393 ret = mm_sound_set_focus_reacquisition(id, reacquisition);
395 g_print("failed to mm_sound_disable_focus_reacquirement(), ret[0x%x]\n", ret);
397 g_print("### fgets return NULL\n");
399 } else if (strncmp(cmd, "AF", 2) == 0) {
401 char input_string[128];
404 mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
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];
416 else if (flag_1 == '1')
420 type = FOCUS_FOR_PLAYBACK;
421 else if (flag_2 == '2')
422 type = FOCUS_FOR_CAPTURE;
424 ret = mm_sound_acquire_focus(id, type, "additional_info. for acquire");
426 g_print("failed to mm_sound_acquire_focus(), ret[0x%x]\n", ret);
429 g_print("### fgets return NULL\n");
432 } else if (strncmp(cmd, "RF", 2) == 0) {
434 char input_string[128];
437 mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
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];
449 else if (flag_1 == '1')
453 type = FOCUS_FOR_PLAYBACK;
454 else if (flag_2 == '2')
455 type = FOCUS_FOR_CAPTURE;
457 ret = mm_sound_release_focus(id, type, "additional_info. for release");
459 g_print("failed to mm_sound_release_focus(), ret[0x%x]\n", ret);
462 g_print("### fgets return NULL\n");
465 } else if (strncmp(cmd, "WS", 2) == 0) {
467 char input_string[128];
470 const char *user_data = "this is user data for watch";
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:");
478 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
479 flag_1 = input_string[0];
483 else if (flag_1 == '2')
485 else if (flag_1 == '3')
488 ret = mm_sound_set_focus_watch_callback(type, focus_watch_cb, (void*)user_data, &g_focus_watch_index);
490 g_print("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
492 g_print("index[%d], type[%d], callback fun[%p]\n", g_focus_watch_index, type, focus_watch_cb);
494 g_print("### fgets return NULL\n");
497 } else if (strncmp(cmd, "WU", 2) == 0) {
499 ret = mm_sound_unset_focus_watch_callback(g_focus_watch_index);
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);
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);
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);
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);
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);
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);
526 debug_log("mm_sound_volume_get_value 0x%x", ret);
528 g_print("*** MEDIA VOLUME : %u ***\n", value);
529 g_volume_value = value;
532 } else if (strncmp(cmd, "e", 1) == 0) {
533 unsigned int value = 100;
534 ret = mm_sound_volume_get_value(g_volume_type, &value);
536 debug_log("mm_sound_volume_get_value 0x%x", ret);
540 ret = mm_sound_volume_set_value(g_volume_type, value);
542 debug_log("mm_sound_volume_set_value 0x%x", ret);
545 } else if (strncmp(cmd, "r", 1) == 0) {
546 unsigned int value = 100;
547 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
549 debug_log("mm_sound_volume_get_value 0x%x", ret);
551 g_print("*** SYSTEM VOLUME : %u ***\n", value);
552 g_volume_value = value;
555 } else if (strncmp(cmd, "y", 1) == 0) {
556 unsigned int value = 100;
557 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
559 debug_log("mm_sound_volume_get_value 0x%x", ret);
564 ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
566 debug_log("mm_sound_volume_set_value 0x%x", ret);
568 g_print("Current System volume is %d\n", value);
571 } else if (strncmp(cmd, "g", 1) == 0) {
572 unsigned int value = 100;
573 ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
575 debug_log("mm_sound_volume_get_value 0x%x", ret);
577 g_print("*** VOICE VOLUME : %u ***\n", value);
578 g_volume_value = value;
581 } else if (strncmp(cmd, "j", 1) == 0) {
582 unsigned int value = 100;
583 ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
585 debug_log("mm_sound_volume_get_value 0x%x", ret);
590 ret = mm_sound_volume_set_value(VOLUME_TYPE_VOICE, value);
592 debug_log("mm_sound_volume_set_value 0x%x", ret);
594 g_print("Current Voice volume is %d\n", value);
597 } else if (strncmp(cmd, "f", 1) == 0) {
598 g_menu_state = CURRENT_STATUS_FILENAME;
600 } else if (strncmp(cmd, "d", 1) == 0) {
601 g_menu_state = CURRENT_STATUS_DIRNAME;
603 } else if (strncmp(cmd, "L", 1) == 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;
612 MMSoundDevice_t device_h = NULL;
613 int dret = MM_ERROR_NONE;
614 int product_id = -1, vendor_id = -1;
616 ret = mm_sound_get_current_device_list(flags, &device_list);
618 g_print("failed to mm_sound_get_current_device_list(), ret[0x%x]\n", ret);
620 g_print("device_list[%p], device_h[%p]\n", device_list, device_h);
622 dret = mm_sound_get_next_device(device_list, &device_h);
624 debug_error("failed to mm_sound_get_next_device(), dret[0x%x]\n", dret);
626 ret = mm_sound_get_device_type(device_h, &device_type);
628 debug_error("failed to mm_sound_get_device_type()");
629 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
631 debug_error("failed to mm_sound_get_device_io_direction()");
632 ret = mm_sound_get_device_state(device_h, &state);
634 debug_error("failed to mm_sound_get_device_state()");
635 ret = mm_sound_get_device_id(device_h, &id);
637 debug_error("failed to mm_sound_get_device_id()");
638 ret = mm_sound_get_device_name(device_h, &name);
640 debug_error("failed to mm_sound_get_device_name()");
641 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
643 debug_error("failed to mm_sound_get_device_vendor_id()");
644 ret = mm_sound_get_device_product_id(device_h, &product_id);
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);
651 } while (dret == MM_ERROR_NONE);
653 dret = MM_ERROR_NONE;
654 dret = mm_sound_get_prev_device(device_list, &device_h);
656 debug_error("failed to mm_sound_get_prev_device(), dret[0x%x]", dret);
658 ret = mm_sound_get_device_type(device_h, &device_type);
660 debug_error("failed to mm_sound_get_device_type()");
661 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
663 debug_error("failed to mm_sound_get_device_io_direction()");
664 ret = mm_sound_get_device_state(device_h, &state);
666 debug_error("failed to mm_sound_get_device_state()");
667 ret = mm_sound_get_device_id(device_h, &id);
669 debug_error("failed to mm_sound_get_device_id()");
670 ret = mm_sound_get_device_name(device_h, &name);
672 debug_error("failed to mm_sound_get_device_name()");
673 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
675 debug_error("failed to mm_sound_get_device_vendor_id()");
676 ret = mm_sound_get_device_product_id(device_h, &product_id);
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);
683 } while (dret == MM_ERROR_NONE);
686 } else if (strncmp(cmd, "I", 1) == 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;
693 int id = 0, input_id = 0;
694 char input_string[128];
697 g_print("> Input id : ");
699 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
700 input_id = atoi(input_string);
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);
706 g_print("failed to mm_sound_get_device_type()\n");
707 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
709 g_print("failed to mm_sound_get_device_io_direction()\n");
710 ret = mm_sound_get_device_state(device_h, &state);
712 g_print("failed to mm_sound_get_device_state()\n");
713 ret = mm_sound_get_device_id(device_h, &id);
715 g_print("failed to mm_sound_get_device_id()\n");
716 ret = mm_sound_get_device_name(device_h, &name);
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);
721 g_print("failed to mm_sound_get_device_by_id()\n");
724 ret = mm_sound_free_device(device_h);
726 g_print("failed to mm_sound_free_device()\n");
728 g_print("### fgets return NULL\n");
731 } else if (strncmp(cmd, "C", 1) == 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;
738 char flag_1, flag_2, flag_3;
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)");
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];
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;
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;
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;
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);
809 g_print("failed to mm_sound_add_device_connected_callback(), ret[0x%x]\n", ret);
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);
813 g_print("### fgets return NULL\n");
816 } else if (strncmp(cmd, "D", 1) == 0) {
818 ret = mm_sound_remove_device_connected_callback(g_subs_id_device_conn);
820 g_print("failed to mm_sound_remove_device_connected_callback(), ret[0x%x]\n", ret);
822 } else if (strncmp(cmd, "Q", 1) == 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;
829 char flag_1, flag_2, flag_3;
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)");
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];
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;
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;
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;
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);
901 g_print("failed to mm_sound_add_device_state_changed_callback(), ret[0x%x]\n", ret);
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);
906 g_print("### fgets return NULL\n");
909 } else if (strncmp(cmd, "W", 1) == 0) {
911 ret = mm_sound_remove_device_state_changed_callback(g_subs_id_device_state);
913 g_print("failed to mm_sound_remove_device_state_changed_callback(), ret[0x%x]\n", ret);
915 } else if (strncmp(cmd, "x", 1) == 0) {
920 case CURRENT_STATUS_FILENAME:
922 g_menu_state = CURRENT_STATUS_MAINMENU;
925 case CURRENT_STATUS_DIRNAME:
927 g_menu_state = CURRENT_STATUS_MAINMENU;
930 case CURRENT_STATUS_POSITION:
936 void volume_change_callback(volume_type_t type, unsigned int volume, void *user_data)
938 if (type == VOLUME_TYPE_MEDIA)
939 g_print("Volume Callback Runs :::: MEDIA VALUME %d\n", volume);
942 int main(int argc, char *argv[])
946 mm_sound_gcov_set_prefix();
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);
952 MMSOUND_STRNCPY(g_file_name, POWERON_FILE, MAX_STRING_LEN);
953 g_print("\nThe input filename is '%s' \n\n", g_file_name);
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);
960 g_print("mm_sound_volume_get_value 0x%x\n", ret);
962 mm_sound_add_volume_changed_callback(volume_change_callback, (void*) &g_volume_type, &g_subs_id_volume);
965 g_main_loop_run(g_loop);