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/keysound/poweron.ogg"
48 #define KEYTONE_FILE "/usr/share/sounds/sound-server/Tizen_HW_Touch.ogg"
49 #define KEYTONE_NOTI_FILE "/usr/share/sounds/alsa/Front_Center.wav"
52 CURRENT_STATUS_MAINMENU = 0,
53 CURRENT_STATUS_FILENAME = 1,
54 CURRENT_STATUS_POSITION = 2,
55 CURRENT_STATUS_DIRNAME = 3,
58 static int g_focus_id = 0;
59 static int g_menu_state = CURRENT_STATUS_MAINMENU;
60 static volume_type_t g_volume_type = VOLUME_TYPE_MEDIA;
61 static unsigned int g_volume_value;
62 static GIOChannel *stdin_channel;
63 static char g_file_name[MAX_STRING_LEN];
64 static char g_dir_name[MAX_PATH_LEN];
65 static int g_focus_watch_index = -1;
66 static GMainLoop* g_loop;
67 static unsigned int g_subs_id_test, g_subs_id_volume, g_subs_id_device_conn, g_subs_id_device_state;
69 static void interpret(char *buf);
70 gboolean timeout_menu_display(void *data);
71 gboolean timeout_quit_program(void *data);
72 gboolean input(GIOChannel *channel);
74 void mycallback(void *data, int id)
76 char *str = (char*)data;
78 debug_log("mycallback called (user data:%s ,id:%d)", str, id);
80 debug_log("mycallback called (no user data)");
82 static volatile char test_callback_done;
83 void test_callback(void *data, int id)
85 debug_log("test_callback is called");
86 test_callback_done = 1;
88 void mm_sound_test_cb1(int a, void *user_data)
90 debug_log("dbus test user callback called: param(%d), userdata(%d)", a, (int)user_data);
91 g_print("my callback pid : %u tid : %ld\n", getpid(), pthread_self());
93 void device_connected_cb(MMSoundDevice_t device_h, bool is_connected, void *user_data)
96 mm_sound_device_type_e device_type = 0;
97 mm_sound_device_io_direction_e io_direction = 0;
98 mm_sound_device_state_e state = 0;
100 int vendor_id = -1, product_id = -1;
103 debug_log("*** device_connected_cb is called, device_h[%p], is_connected[%d], user_data[%p]", device_h, is_connected, user_data);
104 ret = mm_sound_get_device_type(device_h, &device_type);
106 debug_error("failed to mm_sound_get_device_type()");
107 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
109 debug_error("failed to mm_sound_get_device_io_direction()");
110 ret = mm_sound_get_device_state(device_h, &state);
112 debug_error("failed to mm_sound_get_device_state()");
113 ret = mm_sound_get_device_id(device_h, &id);
115 debug_error("failed to mm_sound_get_device_id()");
116 ret = mm_sound_get_device_name(device_h, &name);
118 debug_error("failed to mm_sound_get_device_name()");
119 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
121 debug_error("failed to mm_sound_get_device_vendor_id()");
122 ret = mm_sound_get_device_product_id(device_h, &product_id);
124 debug_error("failed to mm_sound_get_device_produt_id()");
125 debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s], "
126 "vendor-id(%04x) product-id(%04x)",
127 device_type, id, io_direction, state, name, vendor_id, product_id);
129 void device_state_changed_cb(MMSoundDevice_t device_h, mm_sound_device_state_e new_state, void *user_data)
132 mm_sound_device_type_e device_type = 0;
133 mm_sound_device_io_direction_e io_direction = 0;
134 mm_sound_device_state_e state = 0;
137 int vendor_id = -1, product_id = -1;
139 debug_log("*** device_state_changed_cb is called, device_h[%p], state[%d], user_data[%p]", device_h, new_state, user_data);
140 ret = mm_sound_get_device_type(device_h, &device_type);
142 debug_error("failed to mm_sound_get_device_type()");
143 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
145 debug_error("failed to mm_sound_get_device_io_direction()");
146 ret = mm_sound_get_device_state(device_h, &state);
148 debug_error("failed to mm_sound_get_device_state()");
149 ret = mm_sound_get_device_id(device_h, &id);
151 debug_error("failed to mm_sound_get_device_id()");
152 ret = mm_sound_get_device_name(device_h, &name);
154 debug_error("failed to mm_sound_get_device_name()");
155 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
157 debug_error("failed to mm_sound_get_device_vendor_id()");
158 ret = mm_sound_get_device_product_id(device_h, &product_id);
160 debug_error("failed to mm_sound_get_device_produt_id()");
161 debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s], "
162 "vendor-id(%04x) product-id(%04x)",
163 device_type, id, io_direction, state, name, vendor_id, product_id);
166 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)
169 if (state == FOCUS_IS_RELEASED)
173 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]",
174 index, type, _state, reason_for_change, option, ext_info, (char*)user_data);
177 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)
180 if (state == FOCUS_IS_RELEASED)
184 debug_log("*** focus_watch_cb is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], ext_info[%s], user_data[%s]",
185 index, type, _state, reason_for_change, ext_info, (char*)user_data);
190 g_main_loop_quit(g_loop);
193 static void displaymenu()
195 if (g_menu_state == CURRENT_STATUS_MAINMENU) {
196 g_print("==================================================================\n");
197 g_print(" Sound Play APIs\n");
198 g_print("==================================================================\n");
199 g_print("k : Play Keysound \t");
200 g_print("ks : Stop Keysound \t");
201 g_print("kn : Play Keysound (Notification) \t");
202 g_print("ksn : Stop Keysound (Notification) \t");
203 g_print("ksa : Stop Keysound (All) \n");
204 g_print("as : play sound with stream type\n");
205 g_print("FS : Play DTMF with stream type\t");
206 g_print("b : Play directory\n");
207 g_print("s : Stop play \n");
208 g_print("==================================================================\n");
209 g_print(" Volume APIs\n");
210 g_print("==================================================================\n");
211 g_print("q : Get media \t");
212 g_print("w : Inc. media \t");
213 g_print("e : Dec. media \n");
214 g_print("r : Get system \t");
215 g_print("t : Inc. system \t");
216 g_print("y : Dec. system \n");
217 g_print("g : Get voice \t");
218 g_print("h : Inc. voice \t");
219 g_print("j : Dec. voice \n");
220 g_print("==================================================================\n");
221 g_print(" Audio route APIs\n");
222 g_print("==================================================================\n");
223 g_print("u : Foreach Available Routes \t");
224 g_print("i : Get Active Devices \n");
225 g_print("o : Add Available Routes Callback \t");
226 g_print("O : Remove Available Routes Callback \n");
227 g_print("p : Add Active Route Callback\t");
228 g_print("P : Remove Active Route Callback \n");
229 g_print("{ : Get BT A2DP Status\n");
230 g_print("} : Set Active Route\n");
231 g_print("==================================================================\n");
232 g_print(" Audio device APIs\n");
233 g_print("==================================================================\n");
234 g_print("L : Get current list of connected devices \n");
235 g_print("I : Get device by id \n");
236 g_print("C : Add device connected callback \t");
237 g_print("D : Remove device connected callback \n");
238 g_print("Q : Add device state. changed callback \t");
239 g_print("W : Remove device state. changed callback \n");
240 g_print("==================================================================\n");
241 g_print(" Focus APIs\n");
242 g_print("==================================================================\n");
243 g_print("SF : Set Focus Callback\t");
244 g_print("UF : Unset Focus Callback\n");
245 g_print("DF : Disable Auto Focus Reacquirement\t");
246 g_print("AF : Acquire Focus\t");
247 g_print("RF : Release Focus\n");
248 g_print("WS : Set Focus Watch Callback\t");
249 g_print("WU : Unset Focus Watch Callback\n");
250 g_print("==================================================================\n");
251 g_print("d : Input Directory \t");
252 g_print("f : Input File name \t");
253 g_print("x : Exit Program \n");
254 g_print("==================================================================\n");
255 g_print(" Input command >>>>>>>> ");
256 } else if (g_menu_state == CURRENT_STATUS_FILENAME) {
257 g_print(">>>>Input file name to play : ");
258 } else if (g_menu_state == CURRENT_STATUS_DIRNAME) {
259 g_print(">>>>Input directory which contain audio files : ");
261 g_print("**** Unknown status.\n");
266 gboolean timeout_menu_display(void* data)
272 gboolean timeout_quit_program(void* data)
278 gboolean input(GIOChannel *channel)
284 if (g_io_channel_read_line(channel, &buf, &length, NULL, &err) == G_IO_STATUS_NORMAL) {
296 static void input_filename(char *filename)
298 MMSOUND_STRNCPY(g_file_name, filename, MAX_STRING_LEN);
299 g_print("\nThe input filename is '%s' \n\n", g_file_name);
303 static void input_dirname(char *dirname)
305 MMSOUND_STRNCPY(g_dir_name, dirname, MAX_PATH_LEN);
306 g_print("\nThe input directory is '%s' \n\n", g_dir_name);
309 static void interpret(char *cmd)
312 static int handle = -1;
314 switch (g_menu_state) {
315 case CURRENT_STATUS_MAINMENU:
316 if (strncmp(cmd, "SF", 2) == 0) {
318 char input_string[128];
320 char *stream_type = NULL;
321 const char *user_data = "this is user data";
324 g_print("1. Media\n");
325 g_print("2. Alarm\n");
326 g_print("3. Notification\n");
327 g_print("4. Emergency\n");
328 g_print("5. Voice Information\n");
329 g_print("6. Ringtone\n");
330 g_print("7. Ringtone Call\n");
331 g_print("8. VOIP\n");
332 g_print("0. Voice Recognition\n");
333 g_print("> stream type: ");
335 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
336 select = input_string[0];
339 stream_type = "media";
340 else if (select == '2')
341 stream_type = "alarm";
342 else if (select == '3')
343 stream_type = "notification";
344 else if (select == '4')
345 stream_type = "emergency";
346 else if (select == '5')
347 stream_type = "voice-information";
348 else if (select == '6')
349 stream_type = "ringtone";
350 else if (select == '7')
351 stream_type = "ringtone-call";
352 else if (select == '8')
353 stream_type = "voip";
354 else if (select == '0')
355 stream_type = "voice-recognition";
357 ret = mm_sound_register_focus(stream_type, focus_cb, (void*)user_data, &g_focus_id);
359 g_print("failed to mm_sound_register_focus(), ret[0x%x]\n", ret);
361 g_print("id[%d], stream_type[%s], callback fun[%p]\n", g_focus_id, stream_type, focus_cb);
363 g_print("### fgets return NULL\n");
365 } else if (strncmp(cmd, "UF", 2) == 0) {
368 ret = mm_sound_unregister_focus(g_focus_id);
370 g_print("failed to mm_sound_unregister_focus(), ret[0x%x]\n", ret);
371 } else if (strncmp(cmd, "DF", 2) == 0) {
373 char input_string[128];
376 bool reacquisition = true;
378 g_print("1. enable auto reacquirement\n");
379 g_print("2. disable auto reacquirement\n");
380 g_print("> select id and option: (eg. 0 1)");
381 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
382 flag_1 = input_string[0];
383 flag_2 = input_string[2];
387 else if (flag_1 == '1')
389 else if (flag_1 == '2')
393 reacquisition = true;
394 else if (flag_2 == '2')
395 reacquisition = false;
397 ret = mm_sound_set_focus_reacquisition(id, reacquisition);
399 g_print("failed to mm_sound_disable_focus_reacquirement(), ret[0x%x]\n", ret);
401 g_print("### fgets return NULL\n");
403 } else if (strncmp(cmd, "AF", 2) == 0) {
405 char input_string[128];
408 mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
410 g_print("1. focus for playback\n");
411 g_print("2. focus for recording\n");
412 g_print("3. focus for both\n");
413 g_print("> select id and focus_type: (eg. 0 1)");
414 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
415 flag_1 = input_string[0];
416 flag_2 = input_string[2];
420 else if (flag_1 == '1')
424 type = FOCUS_FOR_PLAYBACK;
425 else if (flag_2 == '2')
426 type = FOCUS_FOR_CAPTURE;
428 ret = mm_sound_acquire_focus(id, type, "additional_info. for acquire");
430 g_print("failed to mm_sound_acquire_focus(), ret[0x%x]\n", ret);
433 g_print("### fgets return NULL\n");
436 } else if (strncmp(cmd, "RF", 2) == 0) {
438 char input_string[128];
441 mm_sound_focus_type_e type = FOCUS_FOR_BOTH;
443 g_print("1. focus for playback\n");
444 g_print("2. focus for recording\n");
445 g_print("3. focus for all\n");
446 g_print("> select id and focus_type: (eg. 0 1)");
447 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
448 flag_1 = input_string[0];
449 flag_2 = input_string[2];
453 else if (flag_1 == '1')
457 type = FOCUS_FOR_PLAYBACK;
458 else if (flag_2 == '2')
459 type = FOCUS_FOR_CAPTURE;
461 ret = mm_sound_release_focus(id, type, "additional_info. for release");
463 g_print("failed to mm_sound_release_focus(), ret[0x%x]\n", ret);
466 g_print("### fgets return NULL\n");
469 } else if (strncmp(cmd, "WS", 2) == 0) {
471 char input_string[128];
474 const char *user_data = "this is user data for watch";
477 g_print("1. playback\n");
478 g_print("2. recording\n");
479 g_print("3. both\n");
480 g_print("> select interest focus type:");
482 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
483 flag_1 = input_string[0];
487 else if (flag_1 == '2')
489 else if (flag_1 == '3')
492 ret = mm_sound_set_focus_watch_callback(type, focus_watch_cb, (void*)user_data, &g_focus_watch_index);
494 g_print("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
496 g_print("index[%d], type[%d], callback fun[%p]\n", g_focus_watch_index, type, focus_watch_cb);
498 g_print("### fgets return NULL\n");
501 } else if (strncmp(cmd, "WU", 2) == 0) {
503 ret = mm_sound_unset_focus_watch_callback(g_focus_watch_index);
505 g_print("failed to mm_sound_unset_focus_watch_callback(), ret[0x%x]\n", ret);
506 } else if (strncmp(cmd, "ksn", 3) == 0) {
507 ret = mm_sound_stop_keysound(KEYTONE_NOTI_FILE);
509 debug_error("keysound stop(noti) failed with 0x%x", ret);
510 } else if (strncmp(cmd, "ksa", 3) == 0) {
511 ret = mm_sound_stop_keysound(NULL);
513 debug_error("keysound stop(all) failed with 0x%x", ret);
514 } else if (strncmp(cmd, "kn", 2) == 0) {
515 ret = mm_sound_play_keysound(KEYTONE_NOTI_FILE, VOLUME_TYPE_NOTIFICATION);
517 debug_error("keysound play(noti) failed with 0x%x", ret);
518 } else if (strncmp(cmd, "ks", 2) == 0) {
519 ret = mm_sound_stop_keysound(KEYTONE_FILE);
521 debug_error("keysound stop failed with 0x%x", ret);
522 } else if (strncmp(cmd, "k", 1) == 0) {
523 ret = mm_sound_play_keysound(KEYTONE_FILE, 0);
525 debug_error("keysound play failed with 0x%x", ret);
526 } else if (strcmp(cmd, "dbus-m") == 0) {
531 g_print("dbus method test call\n");
532 ret = mm_sound_test(a, b, &result_val);
534 g_print("failed to mm_sound_test(), ret[0x%x]\n", ret);
536 g_print("Got answer : %d\n", result_val);
538 } else if (strcmp(cmd, "dbus-a") == 0) {
541 g_print("dbus method test add callback\n");
542 g_print("my testsuite pid : %u tid : %ld\n", getpid(), pthread_self());
543 ret = mm_sound_add_test_callback(mm_sound_test_cb1, (void *)user_data, &g_subs_id_test);
545 g_print("failed to mm_sound_add_test_callback(), ret[0x%x]\n", ret);
547 g_print("add test callback success\n");
549 } else if (strcmp(cmd, "dbus-r") == 0) {
551 g_print("dbus method test remove callback\n");
552 ret = mm_sound_remove_test_callback(g_subs_id_test);
554 g_print("failed to mm_sound_remove_test_callback(), ret[0x%x]\n", ret);
556 g_print("remove test callback success\n");
558 } else if (strncmp(cmd, "q", 1) == 0) {
559 unsigned int value = 100;
560 ret = mm_sound_volume_get_value(g_volume_type, &value);
562 debug_log("mm_sound_volume_get_value 0x%x", ret);
564 g_print("*** MEDIA VOLUME : %u ***\n", value);
565 g_volume_value = value;
568 } else if (strncmp(cmd, "e", 1) == 0) {
569 unsigned int value = 100;
570 ret = mm_sound_volume_get_value(g_volume_type, &value);
572 debug_log("mm_sound_volume_get_value 0x%x", ret);
576 ret = mm_sound_volume_set_value(g_volume_type, value);
578 debug_log("mm_sound_volume_set_value 0x%x", ret);
581 } else if (strncmp(cmd, "r", 1) == 0) {
582 unsigned int value = 100;
583 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
585 debug_log("mm_sound_volume_get_value 0x%x", ret);
587 g_print("*** SYSTEM VOLUME : %u ***\n", value);
588 g_volume_value = value;
591 } else if (strncmp(cmd, "y", 1) == 0) {
592 unsigned int value = 100;
593 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
595 debug_log("mm_sound_volume_get_value 0x%x", ret);
600 ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
602 debug_log("mm_sound_volume_set_value 0x%x", ret);
604 g_print("Current System volume is %d\n", value);
607 } else if (strncmp(cmd, "g", 1) == 0) {
608 unsigned int value = 100;
609 ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
611 debug_log("mm_sound_volume_get_value 0x%x", ret);
613 g_print("*** VOICE VOLUME : %u ***\n", value);
614 g_volume_value = value;
617 } else if (strncmp(cmd, "j", 1) == 0) {
618 unsigned int value = 100;
619 ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
621 debug_log("mm_sound_volume_get_value 0x%x", ret);
626 ret = mm_sound_volume_set_value(VOLUME_TYPE_VOICE, value);
628 debug_log("mm_sound_volume_set_value 0x%x", ret);
630 g_print("Current Voice volume is %d\n", value);
633 } else if (strncmp(cmd, "as", 2) == 0) {
634 debug_log("stream %s type, %d", "media", g_volume_value);
635 ret = mm_sound_play_sound_with_stream_info(g_file_name, "media", -1, 1, mycallback, "USERDATA", &handle);
637 debug_log("mm_sound_play_sound() failed with 0x%x", ret);
639 } else if (strncmp(cmd, "FS", 2) == 0) {
641 char input_string[128] = "";
644 char *stream_type = NULL;
647 MMSoundTone_t tone = MM_SOUND_TONE_DTMF_0;
651 g_print("enter number(0~H exit:q), stream type(media, system, ...), volume(0.0~1.0), time(ms):\t ");
652 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
653 tok = strtok_r(input_string, " ", &ptr);
658 } else if (tok[0] < '0' || tok[0] > '~') {
659 if (tok[0] != '*' && tok[0] != '#')
663 if (num >= '0' && num <= '9')
664 tone = (MMSoundTone_t)(num - '0');
666 tone = MM_SOUND_TONE_DTMF_S;
668 tone = MM_SOUND_TONE_DTMF_P;
670 tone = MM_SOUND_TONE_DTMF_A;
672 tone = MM_SOUND_TONE_DTMF_B;
674 tone = MM_SOUND_TONE_DTMF_C;
676 tone = MM_SOUND_TONE_DTMF_D;
678 tone = MM_SOUND_TONE_SUP_DIAL;
680 tone = MM_SOUND_TONE_ANSI_DIAL;
682 tone = MM_SOUND_TONE_JAPAN_DIAL;
684 tone = MM_SOUND_TONE_SUP_BUSY;
686 tone = MM_SOUND_TONE_ANSI_BUSY;
688 tone = MM_SOUND_TONE_JAPAN_BUSY;
690 tone = MM_SOUND_TONE_SUP_CONGESTION;
692 tone = MM_SOUND_TONE_ANSI_CONGESTION;
694 tone = MM_SOUND_TONE_SUP_RADIO_ACK;
696 tone = MM_SOUND_TONE_JAPAN_RADIO_ACK;
698 tone = MM_SOUND_TONE_SUP_RADIO_NOTAVAIL;
700 tone = MM_SOUND_TONE_SUP_ERROR;
702 tone = MM_SOUND_TONE_SUP_CALL_WAITING;
704 tone = MM_SOUND_TONE_ANSI_CALL_WAITING;
706 tone = MM_SOUND_TONE_SUP_RINGTONE;
708 tone = MM_SOUND_TONE_ANSI_RINGTONE;
710 tone = MM_SOUND_TONE_PROP_BEEP;
712 tone = MM_SOUND_TONE_PROP_ACK;
714 tone = MM_SOUND_TONE_PROP_NACK;
716 tone = MM_SOUND_TONE_PROP_PROMPT;
718 tone = MM_SOUND_TONE_PROP_BEEP2;
720 tone = MM_SOUND_TONE_CDMA_HIGH_SLS;
722 tone = MM_SOUND_TONE_CDMA_MED_SLS;
724 tone = MM_SOUND_TONE_CDMA_LOW_SLS;
726 tone = MM_SOUND_TONE_CDMA_HIGH_S_X4;
728 tone = MM_SOUND_TONE_CDMA_MED_S_X4;
730 tone = MM_SOUND_TONE_CDMA_LOW_S_X4;
732 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_L;
734 tone = MM_SOUND_TONE_CDMA_MED_PBX_L;
736 tone = MM_SOUND_TONE_CDMA_LOW_PBX_L;
738 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SS;
740 tone = MM_SOUND_TONE_CDMA_MED_PBX_SS;
742 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SS;
744 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SSL;
746 tone = MM_SOUND_TONE_CDMA_MED_PBX_SSL;
748 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SSL;
750 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SLS;
752 tone = MM_SOUND_TONE_CDMA_MED_PBX_SLS;
754 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SLS;
756 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_S_X4;
758 tone = MM_SOUND_TONE_CDMA_MED_PBX_S_X4;
760 tone = MM_SOUND_TONE_CDMA_LOW_PBX_S_X4;
762 tone = MM_SOUND_TONE_CDMA_ALERT_NETWORK_LITE;
764 tone = MM_SOUND_TONE_CDMA_ALERT_AUTOREDIAL_LITE;
766 tone = MM_SOUND_TONE_CDMA_ONE_MIN_BEEP;
768 tone = MM_SOUND_TONE_CDMA_KEYPAD_VOLUME_KEY_LITE;
770 tone = MM_SOUND_TONE_CDMA_PRESSHOLDKEY_LITE;
772 tone = MM_SOUND_TONE_CDMA_ALERT_INCALL_LITE;
774 tone = MM_SOUND_TONE_CDMA_EMERGENCY_RINGBACK;
776 tone = MM_SOUND_TONE_CDMA_ALERT_CALL_GUARD;
778 tone = MM_SOUND_TONE_CDMA_SOFT_ERROR_LITE;
780 tone = MM_SOUND_TONE_CDMA_CALLDROP_LITE;
782 tone = MM_SOUND_TONE_LOW_FRE;
784 tone = MM_SOUND_TONE_MED_FRE;
786 tone = MM_SOUND_TONE_HIGH_FRE;
788 stream_type = strtok_r(NULL, " ", &ptr);
790 tok = strtok_r(NULL, " ", &ptr);
792 volume = (double)atof(tok);
794 tok = strtok_r(NULL, " ", &ptr);
796 tonetime = atoi(tok);
798 tonetime = MIN_TONE_PLAY_TIME;
800 debug_log("stream type: %s\t volume is %f\t tonetime: %d", stream_type, volume, tonetime);
801 ret = mm_sound_play_tone_with_stream_info(tone, stream_type, -1, volume, tonetime, &handle);
803 debug_log("failed to mm_sound_play_tone_with_stream_info(), ret[0x%x]", ret);
805 g_print("### fgets return NULL\n");
809 } else if (strncmp(cmd, "b", 1) == 0) {
811 struct dirent *entry = NULL;
812 struct dirent *prev_entry = NULL;
815 struct stat file_stat;
816 char fullpath[MAX_PATH_LEN] = "";
817 struct timespec start_time = {0,};
818 struct timespec current_time = {0,};
820 if (g_dir_name[strlen(g_dir_name)-1] == '/')
821 g_dir_name[strlen(g_dir_name)-1] = '\0';
823 basedir = opendir(g_dir_name);
824 if (basedir != NULL) {
825 entry_len = offsetof(struct dirent, d_name) + fpathconf(dirfd(basedir), MAX_STRING_LEN) + 1;
826 prev_entry = malloc(entry_len);
827 if (prev_entry == NULL) {
828 debug_error("malloc error");
837 ret = readdir_r(basedir, prev_entry, &entry);
839 debug_error("error on readdir_r(%p)", basedir);
845 if (entry->d_name[0] == '.')
847 memset(fullpath, '\0', sizeof(fullpath));
848 snprintf(fullpath, sizeof(fullpath) - 1, "%s/%s", g_dir_name, entry->d_name);
849 debug_log("Try %s", fullpath);
851 if (lstat(fullpath, &file_stat) == -1)
854 if (S_ISREG(file_stat.st_mode)) {
855 test_callback_done = 0 ;
856 start_time.tv_sec = (long int)(time(NULL));
857 start_time.tv_nsec = 0;
859 ret = mm_sound_play_sound_with_stream_info(fullpath, "media", -1, 1, test_callback, "USERDATA", &handle);
860 if (ret != MM_ERROR_NONE) {
861 debug_log("Play file error : %s", fullpath);
866 debug_log("this is not regular file : %s", fullpath);
869 while ((test_callback_done == 0) && (playfail == 0)) {
870 current_time.tv_sec = (long int)(time(NULL));
871 current_time.tv_nsec = 0;
872 if (current_time.tv_sec - start_time.tv_sec > 200) {
873 if ((++mywait)%5 == 0) {
874 debug_log("I'm waiting callback for %d seconds after play %s",
875 (int)(current_time.tv_sec - start_time.tv_sec), fullpath);
880 debug_log("goto next file");
885 debug_log("Cannot Open such a directory %s", g_dir_name);
888 } else if (strncmp(cmd, "f", 1) == 0) {
889 g_menu_state = CURRENT_STATUS_FILENAME;
891 } else if (strncmp(cmd, "d", 1) == 0) {
892 g_menu_state = CURRENT_STATUS_DIRNAME;
894 } else if (strncmp(cmd, "s", 1) == 0) {
895 if (mm_sound_stop_sound(handle))
896 debug_log(" Cannot stop sound !!! %d ", handle);
898 } else if (strncmp(cmd, "L", 1) == 0) {
900 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
901 MMSoundDeviceList_t device_list;
902 mm_sound_device_type_e device_type = 0;
903 mm_sound_device_io_direction_e io_direction = 0;
904 mm_sound_device_state_e state = 0;
907 MMSoundDevice_t device_h = NULL;
908 int dret = MM_ERROR_NONE;
909 int product_id = -1, vendor_id = -1;
911 ret = mm_sound_get_current_device_list(flags, &device_list);
913 g_print("failed to mm_sound_get_current_device_list(), ret[0x%x]\n", ret);
915 g_print("device_list[%p], device_h[%p]\n", device_list, device_h);
917 dret = mm_sound_get_next_device(device_list, &device_h);
919 debug_error("failed to mm_sound_get_next_device(), dret[0x%x]\n", dret);
921 ret = mm_sound_get_device_type(device_h, &device_type);
923 debug_error("failed to mm_sound_get_device_type()");
924 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
926 debug_error("failed to mm_sound_get_device_io_direction()");
927 ret = mm_sound_get_device_state(device_h, &state);
929 debug_error("failed to mm_sound_get_device_state()");
930 ret = mm_sound_get_device_id(device_h, &id);
932 debug_error("failed to mm_sound_get_device_id()");
933 ret = mm_sound_get_device_name(device_h, &name);
935 debug_error("failed to mm_sound_get_device_name()");
936 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
938 debug_error("failed to mm_sound_get_device_vendor_id()");
939 ret = mm_sound_get_device_product_id(device_h, &product_id);
941 debug_error("failed to mm_sound_get_device_product_id()");
942 debug_log("*** --- [NEXT DEVICE] type[%d], id[%d], io_direction[%d], state[%d], "
943 "name[%s] vendor_id[%04x] product_id[%04x]",
944 device_type, id, io_direction, state, name, vendor_id, product_id);
946 } while (dret == MM_ERROR_NONE);
948 dret = MM_ERROR_NONE;
949 dret = mm_sound_get_prev_device(device_list, &device_h);
951 debug_error("failed to mm_sound_get_prev_device(), dret[0x%x]", dret);
953 ret = mm_sound_get_device_type(device_h, &device_type);
955 debug_error("failed to mm_sound_get_device_type()");
956 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
958 debug_error("failed to mm_sound_get_device_io_direction()");
959 ret = mm_sound_get_device_state(device_h, &state);
961 debug_error("failed to mm_sound_get_device_state()");
962 ret = mm_sound_get_device_id(device_h, &id);
964 debug_error("failed to mm_sound_get_device_id()");
965 ret = mm_sound_get_device_name(device_h, &name);
967 debug_error("failed to mm_sound_get_device_name()");
968 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
970 debug_error("failed to mm_sound_get_device_vendor_id()");
971 ret = mm_sound_get_device_product_id(device_h, &product_id);
973 debug_error("failed to mm_sound_get_device_product_id()");
974 debug_log("*** --- [PREV DEVICE] type[%d], id[%d], io_direction[%d], state[%d], "
975 "name[%s] vendor_id[%04x] product_id[%04x]",
976 device_type, id, io_direction, state, name, vendor_id, product_id);
978 } while (dret == MM_ERROR_NONE);
981 } else if (strncmp(cmd, "I", 1) == 0) {
983 MMSoundDevice_t device_h = NULL;
984 mm_sound_device_type_e device_type = 0;
985 mm_sound_device_io_direction_e io_direction = 0;
986 mm_sound_device_state_e state = 0;
988 int id = 0, input_id = 0;
989 char input_string[128];
992 g_print("> Input id : ");
994 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
995 input_id = atoi(input_string);
997 ret = mm_sound_get_device_by_id(input_id, &device_h);
998 if (ret == MM_ERROR_NONE) {
999 ret = mm_sound_get_device_type(device_h, &device_type);
1001 g_print("failed to mm_sound_get_device_type()\n");
1002 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
1004 g_print("failed to mm_sound_get_device_io_direction()\n");
1005 ret = mm_sound_get_device_state(device_h, &state);
1007 g_print("failed to mm_sound_get_device_state()\n");
1008 ret = mm_sound_get_device_id(device_h, &id);
1010 g_print("failed to mm_sound_get_device_id()\n");
1011 ret = mm_sound_get_device_name(device_h, &name);
1013 g_print("failed to mm_sound_get_device_name()\n");
1014 g_print("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
1016 g_print("failed to mm_sound_get_device_by_id()\n");
1019 ret = mm_sound_free_device(device_h);
1021 g_print("failed to mm_sound_free_device()\n");
1023 g_print("### fgets return NULL\n");
1026 } else if (strncmp(cmd, "C", 1) == 0) {
1028 char input_string[128];
1029 mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1030 mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1031 mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1033 char flag_1, flag_2, flag_3;
1036 g_print("1. IO_DIRECTION_IN_FLAG\n");
1037 g_print("2. IO_DIRECTION_OUT_FLAG\n");
1038 g_print("3. IO_DIRECTION_BOTH_FLAG\n");
1039 g_print("4. TYPE_INTERNAL_FLAG\n");
1040 g_print("5. TYPE_EXTERNAL_FLAG\n");
1041 g_print("6. STATE_DEACTIVATED_FLAG\n");
1042 g_print("7. STATE_ACTIVATED_FLAG\n");
1043 g_print("8. ALL_FLAG\n");
1044 g_print("> select flag numbers (total 3): (eg. 2 5 7)");
1046 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1047 flag_1 = input_string[0];
1048 flag_2 = input_string[2];
1049 flag_3 = input_string[4];
1052 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1053 else if (flag_1 == '2')
1054 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1055 else if (flag_1 == '3')
1056 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1057 else if (flag_1 == '4')
1058 device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1059 else if (flag_1 == '5')
1060 device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1061 else if (flag_1 == '6')
1062 device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1063 else if (flag_1 == '7')
1064 device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1065 else if (flag_1 == '8')
1066 device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1068 if (flag_2 == '1')device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1069 else if (flag_2 == '2')
1070 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1071 else if (flag_2 == '3')
1072 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1073 else if (flag_2 == '4')
1074 device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1075 else if (flag_2 == '5')
1076 device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1077 else if (flag_2 == '6')
1078 device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1079 else if (flag_2 == '7')
1080 device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1081 else if (flag_2 == '8')
1082 device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1085 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1086 else if (flag_3 == '2')
1087 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1088 else if (flag_3 == '3')
1089 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1090 else if (flag_3 == '4')
1091 device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1092 else if (flag_3 == '5')
1093 device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1094 else if (flag_3 == '6')
1095 device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1096 else if (flag_3 == '7')
1097 device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1098 else if (flag_3 == '8')
1099 device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1101 g_print("device_connected_callback");
1102 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);
1104 g_print("failed to mm_sound_add_device_connected_callback(), ret[0x%x]\n", ret);
1106 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);
1108 g_print("### fgets return NULL\n");
1111 } else if (strncmp(cmd, "D", 1) == 0) {
1113 ret = mm_sound_remove_device_connected_callback(g_subs_id_device_conn);
1115 g_print("failed to mm_sound_remove_device_connected_callback(), ret[0x%x]\n", ret);
1117 } else if (strncmp(cmd, "Q", 1) == 0) {
1119 char input_string[128];
1120 mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1121 mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1122 mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1124 char flag_1, flag_2, flag_3;
1127 g_print("1. IO_DIRECTION_IN_FLAG\n");
1128 g_print("2. IO_DIRECTION_OUT_FLAG\n");
1129 g_print("3. IO_DIRECTION_BOTH_FLAG\n");
1130 g_print("4. TYPE_INTERNAL_FLAG\n");
1131 g_print("5. TYPE_EXTERNAL_FLAG\n");
1132 g_print("6. STATE_DEACTIVATED_FLAG\n");
1133 g_print("7. STATE_ACTIVATED_FLAG\n");
1134 g_print("8. ALL_FLAG\n");
1135 g_print("> select flag numbers (total 3): (eg. 2 5 7)");
1137 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1138 flag_1 = input_string[0];
1139 flag_2 = input_string[2];
1140 flag_3 = input_string[4];
1143 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1144 else if (flag_1 == '2')
1145 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1146 else if (flag_1 == '3')
1147 device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1148 else if (flag_1 == '4')
1149 device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1150 else if (flag_1 == '5')
1151 device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1152 else if (flag_1 == '6')
1153 device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1154 else if (flag_1 == '7')
1155 device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1156 else if (flag_1 == '8')
1157 device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1160 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1161 else if (flag_2 == '2')
1162 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1163 else if (flag_2 == '3')
1164 device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1165 else if (flag_2 == '4')
1166 device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1167 else if (flag_2 == '5')
1168 device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1169 else if (flag_2 == '6')
1170 device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1171 else if (flag_2 == '7')
1172 device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1173 else if (flag_2 == '8')
1174 device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1177 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1178 else if (flag_3 == '2')
1179 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1180 else if (flag_3 == '3')
1181 device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1182 else if (flag_3 == '4')
1183 device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1184 else if (flag_3 == '5')
1185 device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1186 else if (flag_3 == '6')
1187 device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1188 else if (flag_3 == '7')
1189 device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1190 else if (flag_3 == '8')
1191 device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1193 g_print("add_device_state_changed");
1194 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);
1196 g_print("failed to mm_sound_add_device_state_changed_callback(), ret[0x%x]\n", ret);
1198 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);
1201 g_print("### fgets return NULL\n");
1204 } else if (strncmp(cmd, "W", 1) == 0) {
1206 ret = mm_sound_remove_device_state_changed_callback(g_subs_id_device_state);
1208 g_print("failed to mm_sound_remove_device_state_changed_callback(), ret[0x%x]\n", ret);
1210 } else if (strncmp(cmd, "x", 1) == 0) {
1215 case CURRENT_STATUS_FILENAME:
1216 input_filename(cmd);
1217 g_menu_state = CURRENT_STATUS_MAINMENU;
1220 case CURRENT_STATUS_DIRNAME:
1222 g_menu_state = CURRENT_STATUS_MAINMENU;
1225 case CURRENT_STATUS_POSITION:
1231 void volume_change_callback(volume_type_t type, unsigned int volume, void *user_data)
1233 if (type == VOLUME_TYPE_MEDIA)
1234 g_print("Volume Callback Runs :::: MEDIA VALUME %d\n", volume);
1237 int main(int argc, char *argv[])
1241 stdin_channel = g_io_channel_unix_new(0);
1242 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
1243 g_loop = g_main_loop_new(NULL, 1);
1245 MMSOUND_STRNCPY(g_file_name, POWERON_FILE, MAX_STRING_LEN);
1246 g_print("\nThe input filename is '%s' \n\n", g_file_name);
1248 /* test volume changed callback */
1249 g_print("callback function addr :: %p\n", volume_change_callback);
1250 g_volume_type = VOLUME_TYPE_MEDIA;
1251 ret = mm_sound_volume_get_value(g_volume_type, &g_volume_value);
1253 g_print("mm_sound_volume_get_value 0x%x\n", ret);
1255 mm_sound_add_volume_changed_callback(volume_change_callback, (void*) &g_volume_type, &g_subs_id_volume);
1258 g_main_loop_run(g_loop);