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_private.h"
35 #include "../include/mm_sound_pa_client.h"
41 #include <sys/types.h>
47 #define POWERON_FILE "/usr/share/feedback/sound/operation/power_on.wav"
48 #define KEYTONE_FILE "/usr/share/feedback/sound/operation/operation.wav"
51 CURRENT_STATUS_MAINMENU = 0,
52 CURRENT_STATUS_FILENAME = 1,
53 CURRENT_STATUS_POSITION = 2,
54 CURRENT_STATUS_DIRNAME = 3,
57 int g_menu_state = CURRENT_STATUS_MAINMENU;
58 volume_type_t g_volume_type = VOLUME_TYPE_MEDIA;
59 unsigned int g_volume_value;
60 GIOChannel *stdin_channel;
61 char g_file_name[MAX_STRING_LEN];
62 char g_dir_name[MAX_PATH_LEN];
63 int g_focus_watch_index = -1;
65 unsigned int g_subs_id_test, g_subs_id_volume, g_subs_id_device_conn, g_subs_id_device_state;
67 static void interpret(char *buf);
68 gboolean timeout_menu_display(void *data);
69 gboolean timeout_quit_program(void *data);
70 gboolean input(GIOChannel *channel);
72 void mycallback(void *data, int id)
74 char *str = (char*)data;
76 debug_log("mycallback called (user data:%s ,id:%d)", str, id);
78 debug_log("mycallback called (no user data)");
80 volatile char test_callback_done;
81 void test_callback(void *data, int id)
83 debug_log("test_callback is called");
84 test_callback_done = 1;
86 void mm_sound_test_cb1(int a, void *user_data)
88 debug_log("dbus test user callback called: param(%d), userdata(%d)", a, (int)user_data);
89 g_print("my callback pid : %u tid : %ld\n", getpid(), pthread_self());
91 void device_connected_cb(MMSoundDevice_t device_h, bool is_connected, void *user_data)
94 mm_sound_device_type_e device_type = 0;
95 mm_sound_device_io_direction_e io_direction = 0;
96 mm_sound_device_state_e state = 0;
98 int vendor_id = -1, product_id = -1;
101 debug_log("*** device_connected_cb is called, device_h[%p], is_connected[%d], user_data[%p]", device_h, is_connected, user_data);
102 ret = mm_sound_get_device_type(device_h, &device_type);
104 debug_error("failed to mm_sound_get_device_type()");
105 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
107 debug_error("failed to mm_sound_get_device_io_direction()");
108 ret = mm_sound_get_device_state(device_h, &state);
110 debug_error("failed to mm_sound_get_device_state()");
111 ret = mm_sound_get_device_id(device_h, &id);
113 debug_error("failed to mm_sound_get_device_id()");
114 ret = mm_sound_get_device_name(device_h, &name);
116 debug_error("failed to mm_sound_get_device_name()");
117 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
119 debug_error("failed to mm_sound_get_device_vendor_id()");
120 ret = mm_sound_get_device_product_id(device_h, &product_id);
122 debug_error("failed to mm_sound_get_device_produt_id()");
123 debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s], "
124 "vendor-id(%04x) product-id(%04x)",
125 device_type, id, io_direction, state, name, vendor_id, product_id);
127 void device_state_changed_cb(MMSoundDevice_t device_h, mm_sound_device_state_e new_state, void *user_data)
130 mm_sound_device_type_e device_type = 0;
131 mm_sound_device_io_direction_e io_direction = 0;
132 mm_sound_device_state_e state = 0;
135 int vendor_id = -1, product_id = -1;
137 debug_log("*** device_state_changed_cb is called, device_h[%p], state[%d], user_data[%p]", device_h, new_state, user_data);
138 ret = mm_sound_get_device_type(device_h, &device_type);
140 debug_error("failed to mm_sound_get_device_type()");
141 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
143 debug_error("failed to mm_sound_get_device_io_direction()");
144 ret = mm_sound_get_device_state(device_h, &state);
146 debug_error("failed to mm_sound_get_device_state()");
147 ret = mm_sound_get_device_id(device_h, &id);
149 debug_error("failed to mm_sound_get_device_id()");
150 ret = mm_sound_get_device_name(device_h, &name);
152 debug_error("failed to mm_sound_get_device_name()");
153 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
155 debug_error("failed to mm_sound_get_device_vendor_id()");
156 ret = mm_sound_get_device_product_id(device_h, &product_id);
158 debug_error("failed to mm_sound_get_device_produt_id()");
159 debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s], "
160 "vendor-id(%04x) product-id(%04x)",
161 device_type, id, io_direction, state, name, vendor_id, product_id);
164 void focus_cb0(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)
167 if (state == FOCUS_IS_RELEASED)
171 debug_log("*** focus_cb0 is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], option[0x%x], ext_info[%s], user_data[%s]",
172 index, type, _state, reason_for_change, option, ext_info, (char*)user_data);
174 void focus_cb1(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)
177 if (state == FOCUS_IS_RELEASED)
181 debug_log("*** focus_cb1 is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], option[0x%x], ext_info[%s], user_data[%s]",
182 index, type, _state, reason_for_change, option, ext_info, (char*)user_data);
184 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)
187 if (state == FOCUS_IS_RELEASED)
191 debug_log("*** focus_watch_cb is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], ext_info[%s], user_data[%s]",
192 index, type, _state, reason_for_change, ext_info, (char*)user_data);
197 g_main_loop_quit(g_loop);
200 static void displaymenu()
202 if (g_menu_state == CURRENT_STATUS_MAINMENU) {
203 g_print("==================================================================\n");
204 g_print(" Sound Play APIs\n");
205 g_print("==================================================================\n");
206 g_print("k : Key Sound \t");
207 g_print("as : play sound with stream type\n");
208 g_print("FS : Play DTMF with stream type\t");
209 g_print("b : Play directory\n");
210 g_print("s : Stop play \n");
211 g_print("==================================================================\n");
212 g_print(" Volume APIs\n");
213 g_print("==================================================================\n");
214 g_print("q : Get media \t");
215 g_print("w : Inc. media \t");
216 g_print("e : Dec. media \n");
217 g_print("r : Get system \t");
218 g_print("t : Inc. system \t");
219 g_print("y : Dec. system \n");
220 g_print("g : Get voice \t");
221 g_print("h : Inc. voice \t");
222 g_print("j : Dec. voice \n");
223 g_print("==================================================================\n");
224 g_print(" Audio route APIs\n");
225 g_print("==================================================================\n");
226 g_print("u : Foreach Available Routes \t");
227 g_print("i : Get Active Devices \n");
228 g_print("o : Add Available Routes Callback \t");
229 g_print("O : Remove Available Routes Callback \n");
230 g_print("p : Add Active Route Callback\t");
231 g_print("P : Remove Active Route Callback \n");
232 g_print("{ : Get BT A2DP Status\n");
233 g_print("} : Set Active Route\n");
234 g_print("==================================================================\n");
235 g_print(" Audio device APIs\n");
236 g_print("==================================================================\n");
237 g_print("L : Get current list of connected devices \n");
238 g_print("I : Get device by id \n");
239 g_print("C : Add device connected callback \t");
240 g_print("D : Remove device connected callback \n");
241 g_print("Q : Add device state. changed callback \t");
242 g_print("W : Remove device state. changed callback \n");
243 g_print("==================================================================\n");
244 g_print(" Focus APIs\n");
245 g_print("==================================================================\n");
246 g_print("GU : Get Focus id\n");
247 g_print("SF : Set Focus Callback\t");
248 g_print("UF : Unset Focus Callback\n");
249 g_print("DF : Disable Auto Focus Reacquirement\t");
250 g_print("AF : Acquire Focus\t");
251 g_print("RF : Release Focus\n");
252 g_print("WS : Set Focus Watch Callback\t");
253 g_print("WU : Unset Focus Watch Callback\n");
254 g_print("==================================================================\n");
255 g_print("d : Input Directory \t");
256 g_print("f : Input File name \t");
257 g_print("x : Exit Program \n");
258 g_print("==================================================================\n");
259 g_print(" Input command >>>>>>>> ");
260 } else if (g_menu_state == CURRENT_STATUS_FILENAME) {
261 g_print(">>>>Input file name to play : ");
262 } else if (g_menu_state == CURRENT_STATUS_DIRNAME) {
263 g_print(">>>>Input directory which contain audio files : ");
265 g_print("**** Unknown status.\n");
270 gboolean timeout_menu_display(void* data)
276 gboolean timeout_quit_program(void* data)
282 gboolean input(GIOChannel *channel)
288 if (g_io_channel_read_line(channel, &buf, &length, NULL, &err) == G_IO_STATUS_NORMAL) {
300 static void input_filename(char *filename)
302 MMSOUND_STRNCPY(g_file_name, filename, MAX_STRING_LEN);
303 g_print("\nThe input filename is '%s' \n\n", g_file_name);
307 static void input_dirname(char *dirname)
309 MMSOUND_STRNCPY(g_dir_name, dirname, MAX_PATH_LEN);
310 g_print("\nThe input directory is '%s' \n\n", g_dir_name);
313 static void interpret(char *cmd)
316 static int handle = -1;
318 switch (g_menu_state) {
319 case CURRENT_STATUS_MAINMENU:
320 if (strncmp(cmd, "GU", 2) == 0) {
322 ret = mm_sound_focus_get_id(&id);
324 debug_log("mm_sound_focus_get_id() failed with 0x%x", ret);
326 debug_log("id : %d", id);
328 } else if (strncmp(cmd, "SF", 2) == 0) {
330 char input_string[128];
333 char *stream_type = "media";
334 const char *user_data = "this is user data";
337 g_print("1. Media\n");
338 g_print("2. Alarm\n");
339 g_print("3. Notification\n");
340 g_print("4. Emergency\n");
341 g_print("5. Voice Information\n");
342 g_print("6. Ringtone\n");
343 g_print("7. Ringtone Call\n");
344 g_print("8. VOIP\n");
345 g_print("0. Voice Recognition\n");
346 g_print("> select id and stream type: (eg. 0 3)");
348 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
349 flag_1 = input_string[0];
350 flag_2 = input_string[2];
354 else if (flag_1 == '1')
356 else if (flag_1 == '2')
360 stream_type = "media";
361 else if (flag_2 == '2')
362 stream_type = "alarm";
363 else if (flag_2 == '3')
364 stream_type = "notification";
365 else if (flag_2 == '4')
366 stream_type = "emergency";
367 else if (flag_2 == '5')
368 stream_type = "voice-information";
369 else if (flag_2 == '6')
370 stream_type = "ringtone";
371 else if (flag_2 == '7')
372 stream_type = "ringtone-call";
373 else if (flag_2 == '8')
374 stream_type = "voip";
375 else if (flag_2 == '0')
376 stream_type = "voice-recognition";
378 ret = mm_sound_register_focus(id, stream_type, (id == 0) ? focus_cb0 : focus_cb1, (void*)user_data);
380 g_print("failed to mm_sound_register_focus(), ret[0x%x]\n", ret);
382 g_print("id[%d], stream_type[%s], callback fun[%p]\n", id, stream_type, (id == 0) ? focus_cb0 : focus_cb1);
385 g_print("### fgets return NULL\n");
387 } else if (strncmp(cmd, "UF", 2) == 0) {
389 char input_string[128];
393 g_print("> select id:");
394 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
395 flag_1 = input_string[0];
398 else if (flag_1 == '1')
400 else if (flag_1 == '2')
402 ret = mm_sound_unregister_focus(id);
404 g_print("failed to mm_sound_unregister_focus(), ret[0x%x]\n", ret);
406 g_print("### fgets return NULL\n");
408 } else if (strncmp(cmd, "DF", 2) == 0) {
410 char input_string[128];
413 bool reacquisition = true;
415 g_print("1. enable auto reacquirement\n");
416 g_print("2. disable auto reacquirement\n");
417 g_print("> select id and option: (eg. 0 1)");
418 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
419 flag_1 = input_string[0];
420 flag_2 = input_string[2];
424 else if (flag_1 == '1')
426 else if (flag_1 == '2')
430 reacquisition = true;
431 else if (flag_2 == '2')
432 reacquisition = false;
434 ret = mm_sound_set_focus_reacquisition(id, reacquisition);
436 g_print("failed to mm_sound_disable_focus_reacquirement(), ret[0x%x]\n", ret);
438 g_print("### fgets return NULL\n");
442 else if (strncmp(cmd, "AF", 2) == 0) {
444 char input_string[128];
447 mm_sound_focus_type_e type = FOCUS_FOR_PLAYBACK;
449 g_print("1. focus for playback\n");
450 g_print("2. focus for recording\n");
451 g_print("3. focus for both\n");
452 g_print("> select id and focus_type: (eg. 0 1)");
453 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
454 flag_1 = input_string[0];
455 flag_2 = input_string[2];
459 else if (flag_1 == '1')
465 type = FOCUS_FOR_PLAYBACK;
466 else if (flag_2 == '2')
467 type = FOCUS_FOR_CAPTURE;
469 type = FOCUS_FOR_BOTH;
470 ret = mm_sound_acquire_focus(id, type, "additional_info. for acquire");
472 g_print("failed to mm_sound_acquire_focus(), ret[0x%x]\n", ret);
475 g_print("### fgets return NULL\n");
478 } else if (strncmp(cmd, "RF", 2) == 0) {
480 char input_string[128];
483 mm_sound_focus_type_e type = FOCUS_FOR_PLAYBACK;
485 g_print("1. focus for playback\n");
486 g_print("2. focus for recording\n");
487 g_print("3. focus for all\n");
488 g_print("> select id and focus_type: (eg. 0 1)");
489 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
490 flag_1 = input_string[0];
491 flag_2 = input_string[2];
495 else if (flag_1 == '1')
501 type = FOCUS_FOR_PLAYBACK;
502 else if (flag_2 == '2')
503 type = FOCUS_FOR_CAPTURE;
505 type = FOCUS_FOR_BOTH;
506 ret = mm_sound_release_focus(id, type, "additional_info. for release");
508 g_print("failed to mm_sound_release_focus(), ret[0x%x]\n", ret);
511 g_print("### fgets return NULL\n");
514 } else if (strncmp(cmd, "WS", 2) == 0) {
516 char input_string[128];
519 const char *user_data = "this is user data for watch";
522 g_print("1. playback\n");
523 g_print("2. recording\n");
524 g_print("3. both\n");
525 g_print("> select interest focus type:");
527 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
528 flag_1 = input_string[0];
532 else if (flag_1 == '2')
534 else if (flag_1 == '3')
538 ret = mm_sound_set_focus_watch_callback(type, focus_watch_cb, (void*)user_data, &g_focus_watch_index);
540 g_print("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
542 g_print("index[%d], type[%d], callback fun[%p]\n", g_focus_watch_index, type, focus_watch_cb);
544 g_print("### fgets return NULL\n");
547 } else if (strncmp(cmd, "WU", 2) == 0) {
549 ret = mm_sound_unset_focus_watch_callback(g_focus_watch_index);
551 g_print("failed to mm_sound_unset_focus_watch_callback(), ret[0x%x]\n", ret);
552 } else if (strncmp(cmd, "k", 1) == 0) {
553 ret = mm_sound_play_keysound(KEYTONE_FILE, 0);
555 debug_log("keysound play failed with 0x%x", ret);
556 } else if (strcmp(cmd, "dbus-m") == 0) {
561 g_print("dbus method test call\n");
562 ret = mm_sound_test(a, b, &result_val);
564 g_print("failed to mm_sound_test(), ret[0x%x]\n", ret);
566 g_print("Got answer : %d\n", result_val);
568 } else if (strcmp(cmd, "dbus-a") == 0) {
571 g_print("dbus method test add callback\n");
572 g_print("my testsuite pid : %u tid : %ld\n", getpid(), pthread_self());
573 ret = mm_sound_add_test_callback(mm_sound_test_cb1, (void *)user_data, &g_subs_id_test);
575 g_print("failed to mm_sound_add_test_callback(), ret[0x%x]\n", ret);
577 g_print("add test callback success\n");
579 } else if (strcmp(cmd, "dbus-r") == 0) {
581 g_print("dbus method test remove callback\n");
582 ret = mm_sound_remove_test_callback(g_subs_id_test);
584 g_print("failed to mm_sound_remove_test_callback(), ret[0x%x]\n", ret);
586 g_print("remove test callback success\n");
588 } else if (strncmp(cmd, "q", 1) == 0) {
589 unsigned int value = 100;
590 ret = mm_sound_volume_get_value(g_volume_type, &value);
592 debug_log("mm_sound_volume_get_value 0x%x", ret);
594 g_print("*** MEDIA VOLUME : %u ***\n", value);
595 g_volume_value = value;
598 } else if (strncmp(cmd, "e", 1) == 0) {
599 unsigned int value = 100;
600 ret = mm_sound_volume_get_value(g_volume_type, &value);
602 debug_log("mm_sound_volume_get_value 0x%x", ret);
606 ret = mm_sound_volume_set_value(g_volume_type, value);
608 debug_log("mm_sound_volume_set_value 0x%x", ret);
611 } else if (strncmp(cmd, "r", 1) == 0) {
612 unsigned int value = 100;
613 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
615 debug_log("mm_sound_volume_get_value 0x%x", ret);
617 g_print("*** SYSTEM VOLUME : %u ***\n", value);
618 g_volume_value = value;
621 } else if (strncmp(cmd, "y", 1) == 0) {
622 unsigned int value = 100;
623 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
625 debug_log("mm_sound_volume_get_value 0x%x", ret);
630 ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
632 debug_log("mm_sound_volume_set_value 0x%x", ret);
634 g_print("Current System volume is %d\n", value);
637 } else if (strncmp(cmd, "g", 1) == 0) {
638 unsigned int value = 100;
639 ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
641 debug_log("mm_sound_volume_get_value 0x%x", ret);
643 g_print("*** VOICE VOLUME : %u ***\n", value);
644 g_volume_value = value;
647 } else if (strncmp(cmd, "j", 1) == 0) {
648 unsigned int value = 100;
649 ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
651 debug_log("mm_sound_volume_get_value 0x%x", ret);
656 ret = mm_sound_volume_set_value(VOLUME_TYPE_VOICE, value);
658 debug_log("mm_sound_volume_set_value 0x%x", ret);
660 g_print("Current Voice volume is %d\n", value);
663 } else if (strncmp(cmd, "as", 2) == 0) {
664 debug_log("stream %s type, %d", "media", g_volume_value);
665 ret = mm_sound_play_sound_with_stream_info(g_file_name, "media", -1, 1, mycallback, "USERDATA", &handle);
667 debug_log("mm_sound_play_sound() failed with 0x%x", ret);
669 } else if (strncmp(cmd, "FS", 2) == 0) {
671 char input_string[128] = "";
674 char *stream_type = NULL;
677 MMSoundTone_t tone = MM_SOUND_TONE_DTMF_0;
681 g_print("enter number(0~H exit:q), stream type(media, system, ...), volume(0.0~1.0), time(ms):\t ");
682 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
683 tok = strtok_r(input_string, " ", &ptr);
688 } else if (tok[0] < '0' || tok[0] > '~') {
689 if (tok[0] != '*' && tok[0] != '#')
693 if (num >= '0' && num <= '9')
694 tone = (MMSoundTone_t)(num - '0');
696 tone = MM_SOUND_TONE_DTMF_S;
698 tone = MM_SOUND_TONE_DTMF_P;
700 tone = MM_SOUND_TONE_DTMF_A;
702 tone = MM_SOUND_TONE_DTMF_B;
704 tone = MM_SOUND_TONE_DTMF_C;
706 tone = MM_SOUND_TONE_DTMF_D;
708 tone = MM_SOUND_TONE_SUP_DIAL;
710 tone = MM_SOUND_TONE_ANSI_DIAL;
712 tone = MM_SOUND_TONE_JAPAN_DIAL;
714 tone = MM_SOUND_TONE_SUP_BUSY;
716 tone = MM_SOUND_TONE_ANSI_BUSY;
718 tone = MM_SOUND_TONE_JAPAN_BUSY;
720 tone = MM_SOUND_TONE_SUP_CONGESTION;
722 tone = MM_SOUND_TONE_ANSI_CONGESTION;
724 tone = MM_SOUND_TONE_SUP_RADIO_ACK;
726 tone = MM_SOUND_TONE_JAPAN_RADIO_ACK;
728 tone = MM_SOUND_TONE_SUP_RADIO_NOTAVAIL;
730 tone = MM_SOUND_TONE_SUP_ERROR;
732 tone = MM_SOUND_TONE_SUP_CALL_WAITING;
734 tone = MM_SOUND_TONE_ANSI_CALL_WAITING;
736 tone = MM_SOUND_TONE_SUP_RINGTONE;
738 tone = MM_SOUND_TONE_ANSI_RINGTONE;
740 tone = MM_SOUND_TONE_PROP_BEEP;
742 tone = MM_SOUND_TONE_PROP_ACK;
744 tone = MM_SOUND_TONE_PROP_NACK;
746 tone = MM_SOUND_TONE_PROP_PROMPT;
748 tone = MM_SOUND_TONE_PROP_BEEP2;
750 tone = MM_SOUND_TONE_CDMA_HIGH_SLS;
752 tone = MM_SOUND_TONE_CDMA_MED_SLS;
754 tone = MM_SOUND_TONE_CDMA_LOW_SLS;
756 tone = MM_SOUND_TONE_CDMA_HIGH_S_X4;
758 tone = MM_SOUND_TONE_CDMA_MED_S_X4;
760 tone = MM_SOUND_TONE_CDMA_LOW_S_X4;
762 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_L;
764 tone = MM_SOUND_TONE_CDMA_MED_PBX_L;
766 tone = MM_SOUND_TONE_CDMA_LOW_PBX_L;
768 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SS;
770 tone = MM_SOUND_TONE_CDMA_MED_PBX_SS;
772 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SS;
774 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SSL;
776 tone = MM_SOUND_TONE_CDMA_MED_PBX_SSL;
778 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SSL;
780 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SLS;
782 tone = MM_SOUND_TONE_CDMA_MED_PBX_SLS;
784 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SLS;
786 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_S_X4;
788 tone = MM_SOUND_TONE_CDMA_MED_PBX_S_X4;
790 tone = MM_SOUND_TONE_CDMA_LOW_PBX_S_X4;
792 tone = MM_SOUND_TONE_CDMA_ALERT_NETWORK_LITE;
794 tone = MM_SOUND_TONE_CDMA_ALERT_AUTOREDIAL_LITE;
796 tone = MM_SOUND_TONE_CDMA_ONE_MIN_BEEP;
798 tone = MM_SOUND_TONE_CDMA_KEYPAD_VOLUME_KEY_LITE;
800 tone = MM_SOUND_TONE_CDMA_PRESSHOLDKEY_LITE;
802 tone = MM_SOUND_TONE_CDMA_ALERT_INCALL_LITE;
804 tone = MM_SOUND_TONE_CDMA_EMERGENCY_RINGBACK;
806 tone = MM_SOUND_TONE_CDMA_ALERT_CALL_GUARD;
808 tone = MM_SOUND_TONE_CDMA_SOFT_ERROR_LITE;
810 tone = MM_SOUND_TONE_CDMA_CALLDROP_LITE;
812 tone = MM_SOUND_TONE_LOW_FRE;
814 tone = MM_SOUND_TONE_MED_FRE;
816 tone = MM_SOUND_TONE_HIGH_FRE;
818 stream_type = strtok_r(NULL, " ", &ptr);
820 tok = strtok_r(NULL, " ", &ptr);
822 volume = (double)atof(tok);
824 tok = strtok_r(NULL, " ", &ptr);
826 tonetime = atoi(tok);
828 tonetime = MIN_TONE_PLAY_TIME;
830 debug_log("stream type: %s\t volume is %f\t tonetime: %d", stream_type, volume, tonetime);
831 ret = mm_sound_play_tone_with_stream_info(tone, stream_type, -1, volume, tonetime, &handle);
833 debug_log("failed to mm_sound_play_tone_with_stream_info(), ret[0x%x]", ret);
835 g_print("### fgets return NULL\n");
839 } else if (strncmp(cmd, "b", 1) == 0) {
841 struct dirent *entry = NULL;
842 struct dirent *prev_entry = NULL;
845 struct stat file_stat;
846 char fullpath[MAX_PATH_LEN] = "";
847 struct timespec start_time = {0,};
848 struct timespec current_time = {0,};
850 if (g_dir_name[strlen(g_dir_name)-1] == '/')
851 g_dir_name[strlen(g_dir_name)-1] = '\0';
853 basedir = opendir(g_dir_name);
854 if (basedir != NULL) {
855 entry_len = offsetof(struct dirent, d_name) + fpathconf(dirfd(basedir), MAX_STRING_LEN) + 1;
856 prev_entry = malloc(entry_len);
862 ret = readdir_r(basedir, prev_entry, &entry);
864 debug_error("error on readdir_r(%p)", basedir);
870 if (entry->d_name[0] == '.')
872 memset(fullpath, '\0', sizeof(fullpath));
873 snprintf(fullpath, sizeof(fullpath) - 1, "%s/%s", g_dir_name, entry->d_name);
874 debug_log("Try %s", fullpath);
876 if (lstat(fullpath, &file_stat) == -1)
879 if (S_ISREG(file_stat.st_mode)) {
880 test_callback_done = 0 ;
881 start_time.tv_sec = (long int)(time(NULL));
882 start_time.tv_nsec = 0;
884 ret = mm_sound_play_sound_with_stream_info(fullpath, "media", -1, 1, test_callback, "USERDATA", &handle);
885 if (ret != MM_ERROR_NONE) {
886 debug_log("Play file error : %s", fullpath);
891 debug_log("this is not regular file : %s", fullpath);
894 while ((test_callback_done == 0) && (playfail == 0)) {
895 current_time.tv_sec = (long int)(time(NULL));
896 current_time.tv_nsec = 0;
897 if (current_time.tv_sec - start_time.tv_sec > 200) {
898 if ((++mywait)%5 == 0) {
899 debug_log("I'm waiting callback for %d seconds after play %s",
900 (int)(current_time.tv_sec - start_time.tv_sec), fullpath);
905 debug_log("goto next file");
910 debug_log("Cannot Open such a directory %s", g_dir_name);
913 } else if (strncmp(cmd, "f", 1) == 0) {
914 g_menu_state = CURRENT_STATUS_FILENAME;
916 } else if (strncmp(cmd, "d", 1) == 0) {
917 g_menu_state = CURRENT_STATUS_DIRNAME;
919 } else if (strncmp(cmd, "s", 1) == 0) {
920 if (mm_sound_stop_sound(handle))
921 debug_log(" Cannot stop sound !!! %d ", handle);
923 } else if (strncmp(cmd, "L", 1) == 0) {
925 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
926 MMSoundDeviceList_t device_list;
927 mm_sound_device_type_e device_type = 0;
928 mm_sound_device_io_direction_e io_direction = 0;
929 mm_sound_device_state_e state = 0;
932 MMSoundDevice_t device_h = NULL;
933 int dret = MM_ERROR_NONE;
934 int product_id = -1, vendor_id = -1;
936 ret = mm_sound_get_current_device_list(flags, &device_list);
938 g_print("failed to mm_sound_get_current_device_list(), ret[0x%x]\n", ret);
940 g_print("device_list[%p], device_h[%p]\n", device_list, device_h);
942 dret = mm_sound_get_next_device(device_list, &device_h);
944 debug_error("failed to mm_sound_get_next_device(), dret[0x%x]\n", dret);
946 ret = mm_sound_get_device_type(device_h, &device_type);
948 debug_error("failed to mm_sound_get_device_type()");
949 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
951 debug_error("failed to mm_sound_get_device_io_direction()");
952 ret = mm_sound_get_device_state(device_h, &state);
954 debug_error("failed to mm_sound_get_device_state()");
955 ret = mm_sound_get_device_id(device_h, &id);
957 debug_error("failed to mm_sound_get_device_id()");
958 ret = mm_sound_get_device_name(device_h, &name);
960 debug_error("failed to mm_sound_get_device_name()");
961 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
963 debug_error("failed to mm_sound_get_device_vendor_id()");
964 ret = mm_sound_get_device_product_id(device_h, &product_id);
966 debug_error("failed to mm_sound_get_device_product_id()");
967 debug_log("*** --- [NEXT DEVICE] type[%d], id[%d], io_direction[%d], state[%d], "
968 "name[%s] vendor_id[%04x] product_id[%04x]",
969 device_type, id, io_direction, state, name, vendor_id, product_id);
971 } while (dret == MM_ERROR_NONE);
973 dret = MM_ERROR_NONE;
974 dret = mm_sound_get_prev_device(device_list, &device_h);
976 debug_error("failed to mm_sound_get_prev_device(), dret[0x%x]", dret);
978 ret = mm_sound_get_device_type(device_h, &device_type);
980 debug_error("failed to mm_sound_get_device_type()");
981 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
983 debug_error("failed to mm_sound_get_device_io_direction()");
984 ret = mm_sound_get_device_state(device_h, &state);
986 debug_error("failed to mm_sound_get_device_state()");
987 ret = mm_sound_get_device_id(device_h, &id);
989 debug_error("failed to mm_sound_get_device_id()");
990 ret = mm_sound_get_device_name(device_h, &name);
992 debug_error("failed to mm_sound_get_device_name()");
993 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
995 debug_error("failed to mm_sound_get_device_vendor_id()");
996 ret = mm_sound_get_device_product_id(device_h, &product_id);
998 debug_error("failed to mm_sound_get_device_product_id()");
999 debug_log("*** --- [PREV DEVICE] type[%d], id[%d], io_direction[%d], state[%d], "
1000 "name[%s] vendor_id[%04x] product_id[%04x]",
1001 device_type, id, io_direction, state, name, vendor_id, product_id);
1003 } while (dret == MM_ERROR_NONE);
1006 } else if (strncmp(cmd, "I", 1) == 0) {
1008 MMSoundDevice_t device_h = NULL;
1009 mm_sound_device_type_e device_type = 0;
1010 mm_sound_device_io_direction_e io_direction = 0;
1011 mm_sound_device_state_e state = 0;
1013 int id = 0, input_id = 0;
1014 char input_string[128];
1017 g_print("> Input id : ");
1019 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1020 input_id = atoi(input_string);
1022 ret = mm_sound_get_device_by_id(input_id, &device_h);
1023 if (ret == MM_ERROR_NONE) {
1024 ret = mm_sound_get_device_type(device_h, &device_type);
1026 g_print("failed to mm_sound_get_device_type()\n");
1027 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
1029 g_print("failed to mm_sound_get_device_io_direction()\n");
1030 ret = mm_sound_get_device_state(device_h, &state);
1032 g_print("failed to mm_sound_get_device_state()\n");
1033 ret = mm_sound_get_device_id(device_h, &id);
1035 g_print("failed to mm_sound_get_device_id()\n");
1036 ret = mm_sound_get_device_name(device_h, &name);
1038 g_print("failed to mm_sound_get_device_name()\n");
1039 g_print("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
1041 g_print("failed to mm_sound_get_device_by_id()\n");
1044 ret = mm_sound_free_device(device_h);
1046 g_print("failed to mm_sound_free_device()\n");
1048 g_print("### fgets return NULL\n");
1051 } else if (strncmp(cmd, "C", 1) == 0) {
1053 char input_string[128];
1054 mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1055 mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1056 mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1058 char flag_1, flag_2, flag_3;
1061 g_print("1. IO_DIRECTION_IN_FLAG\n");
1062 g_print("2. IO_DIRECTION_OUT_FLAG\n");
1063 g_print("3. IO_DIRECTION_BOTH_FLAG\n");
1064 g_print("4. TYPE_INTERNAL_FLAG\n");
1065 g_print("5. TYPE_EXTERNAL_FLAG\n");
1066 g_print("6. STATE_DEACTIVATED_FLAG\n");
1067 g_print("7. STATE_ACTIVATED_FLAG\n");
1068 g_print("8. ALL_FLAG\n");
1069 g_print("> select flag numbers (total 3): (eg. 2 5 7)");
1071 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1072 flag_1 = input_string[0];
1073 flag_2 = input_string[2];
1074 flag_3 = input_string[4];
1077 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1078 else if (flag_1 == '2')
1079 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1080 else if (flag_1 == '3')
1081 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1082 else if (flag_1 == '4')
1083 device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1084 else if (flag_1 == '5')
1085 device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1086 else if (flag_1 == '6')
1087 device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1088 else if (flag_1 == '7')
1089 device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1090 else if (flag_1 == '8')
1091 device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1093 if (flag_2 == '1')device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1094 else if (flag_2 == '2')
1095 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1096 else if (flag_2 == '3')
1097 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1098 else if (flag_2 == '4')
1099 device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1100 else if (flag_2 == '5')
1101 device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1102 else if (flag_2 == '6')
1103 device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1104 else if (flag_2 == '7')
1105 device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1106 else if (flag_2 == '8')
1107 device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1110 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1111 else if (flag_3 == '2')
1112 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1113 else if (flag_3 == '3')
1114 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1115 else if (flag_3 == '4')
1116 device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1117 else if (flag_3 == '5')
1118 device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1119 else if (flag_3 == '6')
1120 device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1121 else if (flag_3 == '7')
1122 device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1123 else if (flag_3 == '8')
1124 device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1126 g_print("device_connected_callback");
1127 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);
1129 g_print("failed to mm_sound_add_device_connected_callback(), ret[0x%x]\n", ret);
1131 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);
1133 g_print("### fgets return NULL\n");
1136 } else if (strncmp(cmd, "D", 1) == 0) {
1138 ret = mm_sound_remove_device_connected_callback(g_subs_id_device_conn);
1140 g_print("failed to mm_sound_remove_device_connected_callback(), ret[0x%x]\n", ret);
1142 } else if (strncmp(cmd, "Q", 1) == 0) {
1144 char input_string[128];
1145 mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1146 mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1147 mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1149 char flag_1, flag_2, flag_3;
1152 g_print("1. IO_DIRECTION_IN_FLAG\n");
1153 g_print("2. IO_DIRECTION_OUT_FLAG\n");
1154 g_print("3. IO_DIRECTION_BOTH_FLAG\n");
1155 g_print("4. TYPE_INTERNAL_FLAG\n");
1156 g_print("5. TYPE_EXTERNAL_FLAG\n");
1157 g_print("6. STATE_DEACTIVATED_FLAG\n");
1158 g_print("7. STATE_ACTIVATED_FLAG\n");
1159 g_print("8. ALL_FLAG\n");
1160 g_print("> select flag numbers (total 3): (eg. 2 5 7)");
1162 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1163 flag_1 = input_string[0];
1164 flag_2 = input_string[2];
1165 flag_3 = input_string[4];
1168 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1169 else if (flag_1 == '2')
1170 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1171 else if (flag_1 == '3')
1172 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1173 else if (flag_1 == '4')
1174 device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1175 else if (flag_1 == '5')
1176 device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1177 else if (flag_1 == '6')
1178 device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1179 else if (flag_1 == '7')
1180 device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1181 else if (flag_1 == '8')
1182 device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1185 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1186 else if (flag_2 == '2')
1187 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1188 else if (flag_2 == '3')
1189 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1190 else if (flag_2 == '4')
1191 device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1192 else if (flag_2 == '5')
1193 device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1194 else if (flag_2 == '6')
1195 device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1196 else if (flag_2 == '7')
1197 device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1198 else if (flag_2 == '8')
1199 device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1202 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1203 else if (flag_3 == '2')
1204 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1205 else if (flag_3 == '3')
1206 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1207 else if (flag_3 == '4')
1208 device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1209 else if (flag_3 == '5')
1210 device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1211 else if (flag_3 == '6')
1212 device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1213 else if (flag_3 == '7')
1214 device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1215 else if (flag_3 == '8')
1216 device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1218 g_print("add_device_state_changed");
1219 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);
1221 g_print("failed to mm_sound_add_device_state_changed_callback(), ret[0x%x]\n", ret);
1223 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);
1226 g_print("### fgets return NULL\n");
1229 } else if (strncmp(cmd, "W", 1) == 0) {
1231 ret = mm_sound_remove_device_state_changed_callback(g_subs_id_device_state);
1233 g_print("failed to mm_sound_remove_device_state_changed_callback(), ret[0x%x]\n", ret);
1235 } else if (strncmp(cmd, "x", 1) == 0) {
1240 case CURRENT_STATUS_FILENAME:
1241 input_filename(cmd);
1242 g_menu_state = CURRENT_STATUS_MAINMENU;
1245 case CURRENT_STATUS_DIRNAME:
1247 g_menu_state = CURRENT_STATUS_MAINMENU;
1250 case CURRENT_STATUS_POSITION:
1256 void volume_change_callback(volume_type_t type, unsigned int volume, void *user_data)
1258 if (type == VOLUME_TYPE_MEDIA)
1259 g_print("Volume Callback Runs :::: MEDIA VALUME %d\n", volume);
1262 int main(int argc, char *argv[])
1266 stdin_channel = g_io_channel_unix_new(0);
1267 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
1268 g_loop = g_main_loop_new(NULL, 1);
1270 MMSOUND_STRNCPY(g_file_name, POWERON_FILE, MAX_STRING_LEN);
1271 g_print("\nThe input filename is '%s' \n\n", g_file_name);
1273 /* test volume changed callback */
1274 g_print("callback function addr :: %p\n", volume_change_callback);
1275 g_volume_type = VOLUME_TYPE_MEDIA;
1276 ret = mm_sound_volume_get_value(g_volume_type, &g_volume_value);
1278 g_print("mm_sound_volume_get_value 0x%x\n", ret);
1280 mm_sound_add_volume_changed_callback(volume_change_callback, (void*) &g_volume_type, &g_subs_id_volume);
1283 g_main_loop_run(g_loop);