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 static int g_focus_id = 0;
58 static int g_menu_state = CURRENT_STATUS_MAINMENU;
59 static volume_type_t g_volume_type = VOLUME_TYPE_MEDIA;
60 static unsigned int g_volume_value;
61 static GIOChannel *stdin_channel;
62 static char g_file_name[MAX_STRING_LEN];
63 static char g_dir_name[MAX_PATH_LEN];
64 static int g_focus_watch_index = -1;
65 static GMainLoop* g_loop;
66 static unsigned int g_subs_id_test, g_subs_id_volume, g_subs_id_device_conn, g_subs_id_device_state;
68 static void interpret(char *buf);
69 gboolean timeout_menu_display(void *data);
70 gboolean timeout_quit_program(void *data);
71 gboolean input(GIOChannel *channel);
73 void mycallback(void *data, int id)
75 char *str = (char*)data;
77 debug_log("mycallback called (user data:%s ,id:%d)", str, id);
79 debug_log("mycallback called (no user data)");
81 static volatile char test_callback_done;
82 void test_callback(void *data, int id)
84 debug_log("test_callback is called");
85 test_callback_done = 1;
87 void mm_sound_test_cb1(int a, void *user_data)
89 debug_log("dbus test user callback called: param(%d), userdata(%d)", a, (int)user_data);
90 g_print("my callback pid : %u tid : %ld\n", getpid(), pthread_self());
92 void device_connected_cb(MMSoundDevice_t device_h, bool is_connected, void *user_data)
95 mm_sound_device_type_e device_type = 0;
96 mm_sound_device_io_direction_e io_direction = 0;
97 mm_sound_device_state_e state = 0;
99 int vendor_id = -1, product_id = -1;
102 debug_log("*** device_connected_cb is called, device_h[%p], is_connected[%d], user_data[%p]", device_h, is_connected, user_data);
103 ret = mm_sound_get_device_type(device_h, &device_type);
105 debug_error("failed to mm_sound_get_device_type()");
106 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
108 debug_error("failed to mm_sound_get_device_io_direction()");
109 ret = mm_sound_get_device_state(device_h, &state);
111 debug_error("failed to mm_sound_get_device_state()");
112 ret = mm_sound_get_device_id(device_h, &id);
114 debug_error("failed to mm_sound_get_device_id()");
115 ret = mm_sound_get_device_name(device_h, &name);
117 debug_error("failed to mm_sound_get_device_name()");
118 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
120 debug_error("failed to mm_sound_get_device_vendor_id()");
121 ret = mm_sound_get_device_product_id(device_h, &product_id);
123 debug_error("failed to mm_sound_get_device_produt_id()");
124 debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s], "
125 "vendor-id(%04x) product-id(%04x)",
126 device_type, id, io_direction, state, name, vendor_id, product_id);
128 void device_state_changed_cb(MMSoundDevice_t device_h, mm_sound_device_state_e new_state, void *user_data)
131 mm_sound_device_type_e device_type = 0;
132 mm_sound_device_io_direction_e io_direction = 0;
133 mm_sound_device_state_e state = 0;
136 int vendor_id = -1, product_id = -1;
138 debug_log("*** device_state_changed_cb is called, device_h[%p], state[%d], user_data[%p]", device_h, new_state, user_data);
139 ret = mm_sound_get_device_type(device_h, &device_type);
141 debug_error("failed to mm_sound_get_device_type()");
142 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
144 debug_error("failed to mm_sound_get_device_io_direction()");
145 ret = mm_sound_get_device_state(device_h, &state);
147 debug_error("failed to mm_sound_get_device_state()");
148 ret = mm_sound_get_device_id(device_h, &id);
150 debug_error("failed to mm_sound_get_device_id()");
151 ret = mm_sound_get_device_name(device_h, &name);
153 debug_error("failed to mm_sound_get_device_name()");
154 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
156 debug_error("failed to mm_sound_get_device_vendor_id()");
157 ret = mm_sound_get_device_product_id(device_h, &product_id);
159 debug_error("failed to mm_sound_get_device_produt_id()");
160 debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s], "
161 "vendor-id(%04x) product-id(%04x)",
162 device_type, id, io_direction, state, name, vendor_id, product_id);
165 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 if (state == FOCUS_IS_RELEASED)
172 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]",
173 index, type, _state, reason_for_change, option, ext_info, (char*)user_data);
176 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 if (state == FOCUS_IS_RELEASED)
183 debug_log("*** focus_watch_cb is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], ext_info[%s], user_data[%s]",
184 index, type, _state, reason_for_change, ext_info, (char*)user_data);
189 g_main_loop_quit(g_loop);
192 static void displaymenu()
194 if (g_menu_state == CURRENT_STATUS_MAINMENU) {
195 g_print("==================================================================\n");
196 g_print(" Sound Play APIs\n");
197 g_print("==================================================================\n");
198 g_print("k : Key Sound \t");
199 g_print("as : play sound with stream type\n");
200 g_print("FS : Play DTMF with stream type\t");
201 g_print("b : Play directory\n");
202 g_print("s : Stop play \n");
203 g_print("==================================================================\n");
204 g_print(" Volume APIs\n");
205 g_print("==================================================================\n");
206 g_print("q : Get media \t");
207 g_print("w : Inc. media \t");
208 g_print("e : Dec. media \n");
209 g_print("r : Get system \t");
210 g_print("t : Inc. system \t");
211 g_print("y : Dec. system \n");
212 g_print("g : Get voice \t");
213 g_print("h : Inc. voice \t");
214 g_print("j : Dec. voice \n");
215 g_print("==================================================================\n");
216 g_print(" Audio route APIs\n");
217 g_print("==================================================================\n");
218 g_print("u : Foreach Available Routes \t");
219 g_print("i : Get Active Devices \n");
220 g_print("o : Add Available Routes Callback \t");
221 g_print("O : Remove Available Routes Callback \n");
222 g_print("p : Add Active Route Callback\t");
223 g_print("P : Remove Active Route Callback \n");
224 g_print("{ : Get BT A2DP Status\n");
225 g_print("} : Set Active Route\n");
226 g_print("==================================================================\n");
227 g_print(" Audio device APIs\n");
228 g_print("==================================================================\n");
229 g_print("L : Get current list of connected devices \n");
230 g_print("I : Get device by id \n");
231 g_print("C : Add device connected callback \t");
232 g_print("D : Remove device connected callback \n");
233 g_print("Q : Add device state. changed callback \t");
234 g_print("W : Remove device state. changed callback \n");
235 g_print("==================================================================\n");
236 g_print(" Focus APIs\n");
237 g_print("==================================================================\n");
238 g_print("SF : Set Focus Callback\t");
239 g_print("UF : Unset Focus Callback\n");
240 g_print("DF : Disable Auto Focus Reacquirement\t");
241 g_print("AF : Acquire Focus\t");
242 g_print("RF : Release Focus\n");
243 g_print("WS : Set Focus Watch Callback\t");
244 g_print("WU : Unset Focus Watch Callback\n");
245 g_print("==================================================================\n");
246 g_print("d : Input Directory \t");
247 g_print("f : Input File name \t");
248 g_print("x : Exit Program \n");
249 g_print("==================================================================\n");
250 g_print(" Input command >>>>>>>> ");
251 } else if (g_menu_state == CURRENT_STATUS_FILENAME) {
252 g_print(">>>>Input file name to play : ");
253 } else if (g_menu_state == CURRENT_STATUS_DIRNAME) {
254 g_print(">>>>Input directory which contain audio files : ");
256 g_print("**** Unknown status.\n");
261 gboolean timeout_menu_display(void* data)
267 gboolean timeout_quit_program(void* data)
273 gboolean input(GIOChannel *channel)
279 if (g_io_channel_read_line(channel, &buf, &length, NULL, &err) == G_IO_STATUS_NORMAL) {
291 static void input_filename(char *filename)
293 MMSOUND_STRNCPY(g_file_name, filename, MAX_STRING_LEN);
294 g_print("\nThe input filename is '%s' \n\n", g_file_name);
298 static void input_dirname(char *dirname)
300 MMSOUND_STRNCPY(g_dir_name, dirname, MAX_PATH_LEN);
301 g_print("\nThe input directory is '%s' \n\n", g_dir_name);
304 static void interpret(char *cmd)
307 static int handle = -1;
309 switch (g_menu_state) {
310 case CURRENT_STATUS_MAINMENU:
311 if (strncmp(cmd, "SF", 2) == 0) {
313 char input_string[128];
315 char *stream_type = NULL;
316 const char *user_data = "this is user data";
319 g_print("1. Media\n");
320 g_print("2. Alarm\n");
321 g_print("3. Notification\n");
322 g_print("4. Emergency\n");
323 g_print("5. Voice Information\n");
324 g_print("6. Ringtone\n");
325 g_print("7. Ringtone Call\n");
326 g_print("8. VOIP\n");
327 g_print("0. Voice Recognition\n");
328 g_print("> stream type: ");
330 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
331 select = input_string[0];
334 stream_type = "media";
335 else if (select == '2')
336 stream_type = "alarm";
337 else if (select == '3')
338 stream_type = "notification";
339 else if (select == '4')
340 stream_type = "emergency";
341 else if (select == '5')
342 stream_type = "voice-information";
343 else if (select == '6')
344 stream_type = "ringtone";
345 else if (select == '7')
346 stream_type = "ringtone-call";
347 else if (select == '8')
348 stream_type = "voip";
349 else if (select == '0')
350 stream_type = "voice-recognition";
352 ret = mm_sound_register_focus(stream_type, focus_cb, (void*)user_data, &g_focus_id);
354 g_print("failed to mm_sound_register_focus(), ret[0x%x]\n", ret);
356 g_print("id[%d], stream_type[%s], callback fun[%p]\n", g_focus_id, stream_type, focus_cb);
358 g_print("### fgets return NULL\n");
360 } else if (strncmp(cmd, "UF", 2) == 0) {
363 ret = mm_sound_unregister_focus(g_focus_id);
365 g_print("failed to mm_sound_unregister_focus(), ret[0x%x]\n", ret);
366 } else if (strncmp(cmd, "DF", 2) == 0) {
368 char input_string[128];
371 bool reacquisition = true;
373 g_print("1. enable auto reacquirement\n");
374 g_print("2. disable auto reacquirement\n");
375 g_print("> select id and option: (eg. 0 1)");
376 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
377 flag_1 = input_string[0];
378 flag_2 = input_string[2];
382 else if (flag_1 == '1')
384 else if (flag_1 == '2')
388 reacquisition = true;
389 else if (flag_2 == '2')
390 reacquisition = false;
392 ret = mm_sound_set_focus_reacquisition(id, reacquisition);
394 g_print("failed to mm_sound_disable_focus_reacquirement(), ret[0x%x]\n", ret);
396 g_print("### fgets return NULL\n");
398 } else if (strncmp(cmd, "AF", 2) == 0) {
400 char input_string[128];
403 mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
405 g_print("1. focus for playback\n");
406 g_print("2. focus for recording\n");
407 g_print("3. focus for both\n");
408 g_print("> select id and focus_type: (eg. 0 1)");
409 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
410 flag_1 = input_string[0];
411 flag_2 = input_string[2];
415 else if (flag_1 == '1')
419 type = FOCUS_FOR_PLAYBACK;
420 else if (flag_2 == '2')
421 type = FOCUS_FOR_CAPTURE;
423 ret = mm_sound_acquire_focus(id, type, "additional_info. for acquire");
425 g_print("failed to mm_sound_acquire_focus(), ret[0x%x]\n", ret);
428 g_print("### fgets return NULL\n");
431 } else if (strncmp(cmd, "RF", 2) == 0) {
433 char input_string[128];
436 mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
438 g_print("1. focus for playback\n");
439 g_print("2. focus for recording\n");
440 g_print("3. focus for all\n");
441 g_print("> select id and focus_type: (eg. 0 1)");
442 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
443 flag_1 = input_string[0];
444 flag_2 = input_string[2];
448 else if (flag_1 == '1')
452 type = FOCUS_FOR_PLAYBACK;
453 else if (flag_2 == '2')
454 type = FOCUS_FOR_CAPTURE;
456 ret = mm_sound_release_focus(id, type, "additional_info. for release");
458 g_print("failed to mm_sound_release_focus(), ret[0x%x]\n", ret);
461 g_print("### fgets return NULL\n");
464 } else if (strncmp(cmd, "WS", 2) == 0) {
466 char input_string[128];
469 const char *user_data = "this is user data for watch";
472 g_print("1. playback\n");
473 g_print("2. recording\n");
474 g_print("3. both\n");
475 g_print("> select interest focus type:");
477 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
478 flag_1 = input_string[0];
482 else if (flag_1 == '2')
484 else if (flag_1 == '3')
487 ret = mm_sound_set_focus_watch_callback(type, focus_watch_cb, (void*)user_data, &g_focus_watch_index);
489 g_print("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
491 g_print("index[%d], type[%d], callback fun[%p]\n", g_focus_watch_index, type, focus_watch_cb);
493 g_print("### fgets return NULL\n");
496 } else if (strncmp(cmd, "WU", 2) == 0) {
498 ret = mm_sound_unset_focus_watch_callback(g_focus_watch_index);
500 g_print("failed to mm_sound_unset_focus_watch_callback(), ret[0x%x]\n", ret);
501 } else if (strncmp(cmd, "k", 1) == 0) {
502 ret = mm_sound_play_keysound(KEYTONE_FILE, 0);
504 debug_log("keysound play failed with 0x%x", ret);
505 } else if (strcmp(cmd, "dbus-m") == 0) {
510 g_print("dbus method test call\n");
511 ret = mm_sound_test(a, b, &result_val);
513 g_print("failed to mm_sound_test(), ret[0x%x]\n", ret);
515 g_print("Got answer : %d\n", result_val);
517 } else if (strcmp(cmd, "dbus-a") == 0) {
520 g_print("dbus method test add callback\n");
521 g_print("my testsuite pid : %u tid : %ld\n", getpid(), pthread_self());
522 ret = mm_sound_add_test_callback(mm_sound_test_cb1, (void *)user_data, &g_subs_id_test);
524 g_print("failed to mm_sound_add_test_callback(), ret[0x%x]\n", ret);
526 g_print("add test callback success\n");
528 } else if (strcmp(cmd, "dbus-r") == 0) {
530 g_print("dbus method test remove callback\n");
531 ret = mm_sound_remove_test_callback(g_subs_id_test);
533 g_print("failed to mm_sound_remove_test_callback(), ret[0x%x]\n", ret);
535 g_print("remove test callback success\n");
537 } else if (strncmp(cmd, "q", 1) == 0) {
538 unsigned int value = 100;
539 ret = mm_sound_volume_get_value(g_volume_type, &value);
541 debug_log("mm_sound_volume_get_value 0x%x", ret);
543 g_print("*** MEDIA VOLUME : %u ***\n", value);
544 g_volume_value = value;
547 } else if (strncmp(cmd, "e", 1) == 0) {
548 unsigned int value = 100;
549 ret = mm_sound_volume_get_value(g_volume_type, &value);
551 debug_log("mm_sound_volume_get_value 0x%x", ret);
555 ret = mm_sound_volume_set_value(g_volume_type, value);
557 debug_log("mm_sound_volume_set_value 0x%x", ret);
560 } else if (strncmp(cmd, "r", 1) == 0) {
561 unsigned int value = 100;
562 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
564 debug_log("mm_sound_volume_get_value 0x%x", ret);
566 g_print("*** SYSTEM VOLUME : %u ***\n", value);
567 g_volume_value = value;
570 } else if (strncmp(cmd, "y", 1) == 0) {
571 unsigned int value = 100;
572 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
574 debug_log("mm_sound_volume_get_value 0x%x", ret);
579 ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
581 debug_log("mm_sound_volume_set_value 0x%x", ret);
583 g_print("Current System volume is %d\n", value);
586 } else if (strncmp(cmd, "g", 1) == 0) {
587 unsigned int value = 100;
588 ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
590 debug_log("mm_sound_volume_get_value 0x%x", ret);
592 g_print("*** VOICE VOLUME : %u ***\n", value);
593 g_volume_value = value;
596 } else if (strncmp(cmd, "j", 1) == 0) {
597 unsigned int value = 100;
598 ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
600 debug_log("mm_sound_volume_get_value 0x%x", ret);
605 ret = mm_sound_volume_set_value(VOLUME_TYPE_VOICE, value);
607 debug_log("mm_sound_volume_set_value 0x%x", ret);
609 g_print("Current Voice volume is %d\n", value);
612 } else if (strncmp(cmd, "as", 2) == 0) {
613 debug_log("stream %s type, %d", "media", g_volume_value);
614 ret = mm_sound_play_sound_with_stream_info(g_file_name, "media", -1, 1, mycallback, "USERDATA", &handle);
616 debug_log("mm_sound_play_sound() failed with 0x%x", ret);
618 } else if (strncmp(cmd, "FS", 2) == 0) {
620 char input_string[128] = "";
623 char *stream_type = NULL;
626 MMSoundTone_t tone = MM_SOUND_TONE_DTMF_0;
630 g_print("enter number(0~H exit:q), stream type(media, system, ...), volume(0.0~1.0), time(ms):\t ");
631 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
632 tok = strtok_r(input_string, " ", &ptr);
637 } else if (tok[0] < '0' || tok[0] > '~') {
638 if (tok[0] != '*' && tok[0] != '#')
642 if (num >= '0' && num <= '9')
643 tone = (MMSoundTone_t)(num - '0');
645 tone = MM_SOUND_TONE_DTMF_S;
647 tone = MM_SOUND_TONE_DTMF_P;
649 tone = MM_SOUND_TONE_DTMF_A;
651 tone = MM_SOUND_TONE_DTMF_B;
653 tone = MM_SOUND_TONE_DTMF_C;
655 tone = MM_SOUND_TONE_DTMF_D;
657 tone = MM_SOUND_TONE_SUP_DIAL;
659 tone = MM_SOUND_TONE_ANSI_DIAL;
661 tone = MM_SOUND_TONE_JAPAN_DIAL;
663 tone = MM_SOUND_TONE_SUP_BUSY;
665 tone = MM_SOUND_TONE_ANSI_BUSY;
667 tone = MM_SOUND_TONE_JAPAN_BUSY;
669 tone = MM_SOUND_TONE_SUP_CONGESTION;
671 tone = MM_SOUND_TONE_ANSI_CONGESTION;
673 tone = MM_SOUND_TONE_SUP_RADIO_ACK;
675 tone = MM_SOUND_TONE_JAPAN_RADIO_ACK;
677 tone = MM_SOUND_TONE_SUP_RADIO_NOTAVAIL;
679 tone = MM_SOUND_TONE_SUP_ERROR;
681 tone = MM_SOUND_TONE_SUP_CALL_WAITING;
683 tone = MM_SOUND_TONE_ANSI_CALL_WAITING;
685 tone = MM_SOUND_TONE_SUP_RINGTONE;
687 tone = MM_SOUND_TONE_ANSI_RINGTONE;
689 tone = MM_SOUND_TONE_PROP_BEEP;
691 tone = MM_SOUND_TONE_PROP_ACK;
693 tone = MM_SOUND_TONE_PROP_NACK;
695 tone = MM_SOUND_TONE_PROP_PROMPT;
697 tone = MM_SOUND_TONE_PROP_BEEP2;
699 tone = MM_SOUND_TONE_CDMA_HIGH_SLS;
701 tone = MM_SOUND_TONE_CDMA_MED_SLS;
703 tone = MM_SOUND_TONE_CDMA_LOW_SLS;
705 tone = MM_SOUND_TONE_CDMA_HIGH_S_X4;
707 tone = MM_SOUND_TONE_CDMA_MED_S_X4;
709 tone = MM_SOUND_TONE_CDMA_LOW_S_X4;
711 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_L;
713 tone = MM_SOUND_TONE_CDMA_MED_PBX_L;
715 tone = MM_SOUND_TONE_CDMA_LOW_PBX_L;
717 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SS;
719 tone = MM_SOUND_TONE_CDMA_MED_PBX_SS;
721 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SS;
723 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SSL;
725 tone = MM_SOUND_TONE_CDMA_MED_PBX_SSL;
727 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SSL;
729 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SLS;
731 tone = MM_SOUND_TONE_CDMA_MED_PBX_SLS;
733 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SLS;
735 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_S_X4;
737 tone = MM_SOUND_TONE_CDMA_MED_PBX_S_X4;
739 tone = MM_SOUND_TONE_CDMA_LOW_PBX_S_X4;
741 tone = MM_SOUND_TONE_CDMA_ALERT_NETWORK_LITE;
743 tone = MM_SOUND_TONE_CDMA_ALERT_AUTOREDIAL_LITE;
745 tone = MM_SOUND_TONE_CDMA_ONE_MIN_BEEP;
747 tone = MM_SOUND_TONE_CDMA_KEYPAD_VOLUME_KEY_LITE;
749 tone = MM_SOUND_TONE_CDMA_PRESSHOLDKEY_LITE;
751 tone = MM_SOUND_TONE_CDMA_ALERT_INCALL_LITE;
753 tone = MM_SOUND_TONE_CDMA_EMERGENCY_RINGBACK;
755 tone = MM_SOUND_TONE_CDMA_ALERT_CALL_GUARD;
757 tone = MM_SOUND_TONE_CDMA_SOFT_ERROR_LITE;
759 tone = MM_SOUND_TONE_CDMA_CALLDROP_LITE;
761 tone = MM_SOUND_TONE_LOW_FRE;
763 tone = MM_SOUND_TONE_MED_FRE;
765 tone = MM_SOUND_TONE_HIGH_FRE;
767 stream_type = strtok_r(NULL, " ", &ptr);
769 tok = strtok_r(NULL, " ", &ptr);
771 volume = (double)atof(tok);
773 tok = strtok_r(NULL, " ", &ptr);
775 tonetime = atoi(tok);
777 tonetime = MIN_TONE_PLAY_TIME;
779 debug_log("stream type: %s\t volume is %f\t tonetime: %d", stream_type, volume, tonetime);
780 ret = mm_sound_play_tone_with_stream_info(tone, stream_type, -1, volume, tonetime, &handle);
782 debug_log("failed to mm_sound_play_tone_with_stream_info(), ret[0x%x]", ret);
784 g_print("### fgets return NULL\n");
788 } else if (strncmp(cmd, "b", 1) == 0) {
790 struct dirent *entry = NULL;
791 struct dirent *prev_entry = NULL;
794 struct stat file_stat;
795 char fullpath[MAX_PATH_LEN] = "";
796 struct timespec start_time = {0,};
797 struct timespec current_time = {0,};
799 if (g_dir_name[strlen(g_dir_name)-1] == '/')
800 g_dir_name[strlen(g_dir_name)-1] = '\0';
802 basedir = opendir(g_dir_name);
803 if (basedir != NULL) {
804 entry_len = offsetof(struct dirent, d_name) + fpathconf(dirfd(basedir), MAX_STRING_LEN) + 1;
805 prev_entry = malloc(entry_len);
806 if (prev_entry == NULL) {
807 debug_error("malloc error");
816 ret = readdir_r(basedir, prev_entry, &entry);
818 debug_error("error on readdir_r(%p)", basedir);
824 if (entry->d_name[0] == '.')
826 memset(fullpath, '\0', sizeof(fullpath));
827 snprintf(fullpath, sizeof(fullpath) - 1, "%s/%s", g_dir_name, entry->d_name);
828 debug_log("Try %s", fullpath);
830 if (lstat(fullpath, &file_stat) == -1)
833 if (S_ISREG(file_stat.st_mode)) {
834 test_callback_done = 0 ;
835 start_time.tv_sec = (long int)(time(NULL));
836 start_time.tv_nsec = 0;
838 ret = mm_sound_play_sound_with_stream_info(fullpath, "media", -1, 1, test_callback, "USERDATA", &handle);
839 if (ret != MM_ERROR_NONE) {
840 debug_log("Play file error : %s", fullpath);
845 debug_log("this is not regular file : %s", fullpath);
848 while ((test_callback_done == 0) && (playfail == 0)) {
849 current_time.tv_sec = (long int)(time(NULL));
850 current_time.tv_nsec = 0;
851 if (current_time.tv_sec - start_time.tv_sec > 200) {
852 if ((++mywait)%5 == 0) {
853 debug_log("I'm waiting callback for %d seconds after play %s",
854 (int)(current_time.tv_sec - start_time.tv_sec), fullpath);
859 debug_log("goto next file");
864 debug_log("Cannot Open such a directory %s", g_dir_name);
867 } else if (strncmp(cmd, "f", 1) == 0) {
868 g_menu_state = CURRENT_STATUS_FILENAME;
870 } else if (strncmp(cmd, "d", 1) == 0) {
871 g_menu_state = CURRENT_STATUS_DIRNAME;
873 } else if (strncmp(cmd, "s", 1) == 0) {
874 if (mm_sound_stop_sound(handle))
875 debug_log(" Cannot stop sound !!! %d ", handle);
877 } else if (strncmp(cmd, "L", 1) == 0) {
879 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
880 MMSoundDeviceList_t device_list;
881 mm_sound_device_type_e device_type = 0;
882 mm_sound_device_io_direction_e io_direction = 0;
883 mm_sound_device_state_e state = 0;
886 MMSoundDevice_t device_h = NULL;
887 int dret = MM_ERROR_NONE;
888 int product_id = -1, vendor_id = -1;
890 ret = mm_sound_get_current_device_list(flags, &device_list);
892 g_print("failed to mm_sound_get_current_device_list(), ret[0x%x]\n", ret);
894 g_print("device_list[%p], device_h[%p]\n", device_list, device_h);
896 dret = mm_sound_get_next_device(device_list, &device_h);
898 debug_error("failed to mm_sound_get_next_device(), dret[0x%x]\n", dret);
900 ret = mm_sound_get_device_type(device_h, &device_type);
902 debug_error("failed to mm_sound_get_device_type()");
903 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
905 debug_error("failed to mm_sound_get_device_io_direction()");
906 ret = mm_sound_get_device_state(device_h, &state);
908 debug_error("failed to mm_sound_get_device_state()");
909 ret = mm_sound_get_device_id(device_h, &id);
911 debug_error("failed to mm_sound_get_device_id()");
912 ret = mm_sound_get_device_name(device_h, &name);
914 debug_error("failed to mm_sound_get_device_name()");
915 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
917 debug_error("failed to mm_sound_get_device_vendor_id()");
918 ret = mm_sound_get_device_product_id(device_h, &product_id);
920 debug_error("failed to mm_sound_get_device_product_id()");
921 debug_log("*** --- [NEXT DEVICE] type[%d], id[%d], io_direction[%d], state[%d], "
922 "name[%s] vendor_id[%04x] product_id[%04x]",
923 device_type, id, io_direction, state, name, vendor_id, product_id);
925 } while (dret == MM_ERROR_NONE);
927 dret = MM_ERROR_NONE;
928 dret = mm_sound_get_prev_device(device_list, &device_h);
930 debug_error("failed to mm_sound_get_prev_device(), dret[0x%x]", dret);
932 ret = mm_sound_get_device_type(device_h, &device_type);
934 debug_error("failed to mm_sound_get_device_type()");
935 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
937 debug_error("failed to mm_sound_get_device_io_direction()");
938 ret = mm_sound_get_device_state(device_h, &state);
940 debug_error("failed to mm_sound_get_device_state()");
941 ret = mm_sound_get_device_id(device_h, &id);
943 debug_error("failed to mm_sound_get_device_id()");
944 ret = mm_sound_get_device_name(device_h, &name);
946 debug_error("failed to mm_sound_get_device_name()");
947 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
949 debug_error("failed to mm_sound_get_device_vendor_id()");
950 ret = mm_sound_get_device_product_id(device_h, &product_id);
952 debug_error("failed to mm_sound_get_device_product_id()");
953 debug_log("*** --- [PREV DEVICE] type[%d], id[%d], io_direction[%d], state[%d], "
954 "name[%s] vendor_id[%04x] product_id[%04x]",
955 device_type, id, io_direction, state, name, vendor_id, product_id);
957 } while (dret == MM_ERROR_NONE);
960 } else if (strncmp(cmd, "I", 1) == 0) {
962 MMSoundDevice_t device_h = NULL;
963 mm_sound_device_type_e device_type = 0;
964 mm_sound_device_io_direction_e io_direction = 0;
965 mm_sound_device_state_e state = 0;
967 int id = 0, input_id = 0;
968 char input_string[128];
971 g_print("> Input id : ");
973 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
974 input_id = atoi(input_string);
976 ret = mm_sound_get_device_by_id(input_id, &device_h);
977 if (ret == MM_ERROR_NONE) {
978 ret = mm_sound_get_device_type(device_h, &device_type);
980 g_print("failed to mm_sound_get_device_type()\n");
981 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
983 g_print("failed to mm_sound_get_device_io_direction()\n");
984 ret = mm_sound_get_device_state(device_h, &state);
986 g_print("failed to mm_sound_get_device_state()\n");
987 ret = mm_sound_get_device_id(device_h, &id);
989 g_print("failed to mm_sound_get_device_id()\n");
990 ret = mm_sound_get_device_name(device_h, &name);
992 g_print("failed to mm_sound_get_device_name()\n");
993 g_print("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
995 g_print("failed to mm_sound_get_device_by_id()\n");
998 ret = mm_sound_free_device(device_h);
1000 g_print("failed to mm_sound_free_device()\n");
1002 g_print("### fgets return NULL\n");
1005 } else if (strncmp(cmd, "C", 1) == 0) {
1007 char input_string[128];
1008 mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1009 mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1010 mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1012 char flag_1, flag_2, flag_3;
1015 g_print("1. IO_DIRECTION_IN_FLAG\n");
1016 g_print("2. IO_DIRECTION_OUT_FLAG\n");
1017 g_print("3. IO_DIRECTION_BOTH_FLAG\n");
1018 g_print("4. TYPE_INTERNAL_FLAG\n");
1019 g_print("5. TYPE_EXTERNAL_FLAG\n");
1020 g_print("6. STATE_DEACTIVATED_FLAG\n");
1021 g_print("7. STATE_ACTIVATED_FLAG\n");
1022 g_print("8. ALL_FLAG\n");
1023 g_print("> select flag numbers (total 3): (eg. 2 5 7)");
1025 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1026 flag_1 = input_string[0];
1027 flag_2 = input_string[2];
1028 flag_3 = input_string[4];
1031 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1032 else if (flag_1 == '2')
1033 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1034 else if (flag_1 == '3')
1035 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1036 else if (flag_1 == '4')
1037 device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1038 else if (flag_1 == '5')
1039 device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1040 else if (flag_1 == '6')
1041 device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1042 else if (flag_1 == '7')
1043 device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1044 else if (flag_1 == '8')
1045 device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1047 if (flag_2 == '1')device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1048 else if (flag_2 == '2')
1049 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1050 else if (flag_2 == '3')
1051 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1052 else if (flag_2 == '4')
1053 device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1054 else if (flag_2 == '5')
1055 device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1056 else if (flag_2 == '6')
1057 device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1058 else if (flag_2 == '7')
1059 device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1060 else if (flag_2 == '8')
1061 device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1064 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1065 else if (flag_3 == '2')
1066 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1067 else if (flag_3 == '3')
1068 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1069 else if (flag_3 == '4')
1070 device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1071 else if (flag_3 == '5')
1072 device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1073 else if (flag_3 == '6')
1074 device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1075 else if (flag_3 == '7')
1076 device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1077 else if (flag_3 == '8')
1078 device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1080 g_print("device_connected_callback");
1081 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);
1083 g_print("failed to mm_sound_add_device_connected_callback(), ret[0x%x]\n", ret);
1085 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);
1087 g_print("### fgets return NULL\n");
1090 } else if (strncmp(cmd, "D", 1) == 0) {
1092 ret = mm_sound_remove_device_connected_callback(g_subs_id_device_conn);
1094 g_print("failed to mm_sound_remove_device_connected_callback(), ret[0x%x]\n", ret);
1096 } else if (strncmp(cmd, "Q", 1) == 0) {
1098 char input_string[128];
1099 mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1100 mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1101 mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1103 char flag_1, flag_2, flag_3;
1106 g_print("1. IO_DIRECTION_IN_FLAG\n");
1107 g_print("2. IO_DIRECTION_OUT_FLAG\n");
1108 g_print("3. IO_DIRECTION_BOTH_FLAG\n");
1109 g_print("4. TYPE_INTERNAL_FLAG\n");
1110 g_print("5. TYPE_EXTERNAL_FLAG\n");
1111 g_print("6. STATE_DEACTIVATED_FLAG\n");
1112 g_print("7. STATE_ACTIVATED_FLAG\n");
1113 g_print("8. ALL_FLAG\n");
1114 g_print("> select flag numbers (total 3): (eg. 2 5 7)");
1116 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1117 flag_1 = input_string[0];
1118 flag_2 = input_string[2];
1119 flag_3 = input_string[4];
1122 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1123 else if (flag_1 == '2')
1124 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1125 else if (flag_1 == '3')
1126 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1127 else if (flag_1 == '4')
1128 device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1129 else if (flag_1 == '5')
1130 device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1131 else if (flag_1 == '6')
1132 device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1133 else if (flag_1 == '7')
1134 device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1135 else if (flag_1 == '8')
1136 device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1139 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1140 else if (flag_2 == '2')
1141 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1142 else if (flag_2 == '3')
1143 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1144 else if (flag_2 == '4')
1145 device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1146 else if (flag_2 == '5')
1147 device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1148 else if (flag_2 == '6')
1149 device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1150 else if (flag_2 == '7')
1151 device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1152 else if (flag_2 == '8')
1153 device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1156 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1157 else if (flag_3 == '2')
1158 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1159 else if (flag_3 == '3')
1160 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1161 else if (flag_3 == '4')
1162 device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1163 else if (flag_3 == '5')
1164 device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1165 else if (flag_3 == '6')
1166 device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1167 else if (flag_3 == '7')
1168 device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1169 else if (flag_3 == '8')
1170 device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1172 g_print("add_device_state_changed");
1173 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);
1175 g_print("failed to mm_sound_add_device_state_changed_callback(), ret[0x%x]\n", ret);
1177 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);
1180 g_print("### fgets return NULL\n");
1183 } else if (strncmp(cmd, "W", 1) == 0) {
1185 ret = mm_sound_remove_device_state_changed_callback(g_subs_id_device_state);
1187 g_print("failed to mm_sound_remove_device_state_changed_callback(), ret[0x%x]\n", ret);
1189 } else if (strncmp(cmd, "x", 1) == 0) {
1194 case CURRENT_STATUS_FILENAME:
1195 input_filename(cmd);
1196 g_menu_state = CURRENT_STATUS_MAINMENU;
1199 case CURRENT_STATUS_DIRNAME:
1201 g_menu_state = CURRENT_STATUS_MAINMENU;
1204 case CURRENT_STATUS_POSITION:
1210 void volume_change_callback(volume_type_t type, unsigned int volume, void *user_data)
1212 if (type == VOLUME_TYPE_MEDIA)
1213 g_print("Volume Callback Runs :::: MEDIA VALUME %d\n", volume);
1216 int main(int argc, char *argv[])
1220 stdin_channel = g_io_channel_unix_new(0);
1221 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
1222 g_loop = g_main_loop_new(NULL, 1);
1224 MMSOUND_STRNCPY(g_file_name, POWERON_FILE, MAX_STRING_LEN);
1225 g_print("\nThe input filename is '%s' \n\n", g_file_name);
1227 /* test volume changed callback */
1228 g_print("callback function addr :: %p\n", volume_change_callback);
1229 g_volume_type = VOLUME_TYPE_MEDIA;
1230 ret = mm_sound_volume_get_value(g_volume_type, &g_volume_value);
1232 g_print("mm_sound_volume_get_value 0x%x\n", ret);
1234 mm_sound_add_volume_changed_callback(volume_change_callback, (void*) &g_volume_type, &g_subs_id_volume);
1237 g_main_loop_run(g_loop);