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 avsys_info(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_private.h"
38 #include <sys/types.h>
43 #include <mm_session_private.h>
44 #include <audio-session-manager-types.h>
46 #define POWERON_FILE "/usr/share/keysound/poweron.wav"
49 // For testsuite status
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;
59 volume_type_t g_volume_type = VOLUME_TYPE_MEDIA;
60 unsigned int g_volume_value;
62 GIOChannel *stdin_channel;
63 char g_file_name[MAX_STRING_LEN];
64 char g_dir_name[MAX_PATH_LEN];
70 static void interpret (char *buf);
71 gboolean timeout_menu_display(void *data);
72 gboolean timeout_quit_program(void *data);
73 gboolean input (GIOChannel *channel);
75 static char* __get_playback_device_str (mm_sound_device_out out);
76 static char* __get_capture_device_str (mm_sound_device_in in);
77 static char* __get_route_str (mm_sound_route route);
78 static int __mm_sound_foreach_available_route_cb (mm_sound_route route, void *user_data);
79 static void __mm_sound_available_route_changed_cb (mm_sound_route route, bool available, void *user_data);
80 static void __mm_sound_active_device_changed_cb (mm_sound_device_in device_in, mm_sound_device_out device_out, void *user_data);
82 void mycallback(void *data)
84 char *str = (char*)data;
86 debug_log("mycallback called (user data:%s)\n", str);
88 debug_log("mycallback called (no user data)\n");
90 volatile char test_callback_done;
91 void test_callback(void *data)
93 debug_log("test_callback is called\n");
94 test_callback_done = 1;
98 g_main_loop_quit(g_loop);
101 static void displaymenu()
103 if (g_menu_state == CURRENT_STATUS_MAINMENU) {
104 g_print("==================================================================\n");
105 g_print(" Sound Path APIs\n");
106 g_print("==================================================================\n");
107 g_print("1. Play speaker \t");
108 g_print("2. Play headset \n");
109 g_print("3. (blank) \n");
110 g_print("4. Rec. with mic \t");
111 g_print("5. (blank) \t");
112 g_print("6. Call receiver \n");
113 g_print("7. Call end \t");
114 g_print("8. VT call speaker \t");
115 g_print("9. VT call end \n");
116 g_print("==================================================================\n");
117 g_print(" Sound Play APIs\n");
118 g_print("==================================================================\n");
119 g_print("k : Key Sound \t");
120 g_print("a : play sound \t");
121 g_print("A : play loud solo\n");
122 g_print("c : play sound ex \t");
123 g_print("F : Play DTMF \t");
124 g_print("b : Play directory\n");
125 g_print("s : Stop play \n");
126 g_print("==================================================================\n");
127 g_print(" Volume APIs\n");
128 g_print("==================================================================\n");
129 g_print("q : Get media \t");
130 g_print("w : Inc. media \t");
131 g_print("e : Dec. media \n");
132 g_print("r : Get system \t");
133 g_print("t : Inc. system \t");
134 g_print("y : Dec. system \n");
135 g_print("==================================================================\n");
136 g_print(" Audio route APIs\n");
137 g_print("==================================================================\n");
138 g_print("u : Foreach Available Routes \t");
139 g_print("i : Get Active Devices \n");
140 g_print("o : Add Available Routes Callback \t");
141 g_print("O : Remove Available Routes Callback \n");
142 g_print("p : Add Active Route Callback\t");
143 g_print("P : Remove Active Route Callback \n");
144 g_print("{ : Get BT A2DP Status\n");
145 g_print("==================================================================\n");
146 g_print(" Session Test\n");
147 g_print("==================================================================\n");
148 g_print("z : Call start \t");
149 g_print("Z : VideoCall start \t");
150 g_print("v : Call/VideoCall end \t");
151 g_print("V : Current Status \n");
152 g_print("==================================================================\n");
153 g_print("d : Input Directory \t");
154 g_print("f : Input File name \t");
155 g_print("x : Exit Program \n");
156 g_print("==================================================================\n");
157 g_print(" Input command >>>>>>>> ");
159 else if (g_menu_state == CURRENT_STATUS_FILENAME) {
160 g_print(">>>>Input file name to play : ");
162 else if (g_menu_state == CURRENT_STATUS_DIRNAME) {
163 g_print(">>>>Input directory which contain audio files : ");
166 g_print("**** Unknown status.\n");
171 gboolean timeout_menu_display(void* data)
177 gboolean timeout_quit_program(void* data)
183 gboolean input (GIOChannel *channel)
185 char buf[MAX_STRING_LEN + 3];
188 g_io_channel_read(channel, buf, MAX_STRING_LEN, &read);
196 static void input_filename(char *filename)
198 strncpy(g_file_name, filename, sizeof(g_file_name)-1);
199 g_print("\nThe input filename is '%s' \n\n",g_file_name);
203 static void input_dirname(char *dirname)
205 strncpy(g_dir_name, dirname, sizeof(g_dir_name)-1);
206 g_print("\nThe input directory is '%s' \n\n",g_dir_name);
209 static char* __get_playback_device_str (mm_sound_device_out out)
212 case MM_SOUND_DEVICE_OUT_SPEAKER: return "SPEAKER";
213 case MM_SOUND_DEVICE_OUT_RECEIVER: return "RECEIVER";
214 case MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY: return "HEADSET";
215 case MM_SOUND_DEVICE_OUT_BT_SCO: return "BTSCO";
216 case MM_SOUND_DEVICE_OUT_BT_A2DP: return "BTA2DP";
217 case MM_SOUND_DEVICE_OUT_DOCK: return "DOCK";
218 case MM_SOUND_DEVICE_OUT_HDMI: return "HDMI";
219 case MM_SOUND_DEVICE_OUT_WFD: return "WFD";
220 case MM_SOUND_DEVICE_OUT_USB_AUDIO: return "USB";
221 default: return NULL;
225 static char* __get_capture_device_str (mm_sound_device_in in)
228 case MM_SOUND_DEVICE_IN_MIC: return "MAINMIC";
229 case MM_SOUND_DEVICE_IN_WIRED_ACCESSORY: return "HEADSET";
230 case MM_SOUND_DEVICE_IN_BT_SCO: return "BTMIC";
231 default: return NULL;
235 static char* __get_route_str (mm_sound_route route)
238 case MM_SOUND_ROUTE_OUT_SPEAKER: return "OUT_SPEAKER";
239 case MM_SOUND_ROUTE_OUT_WIRED_ACCESSORY: return "OUT_WIRED_ACCESSORY";
240 case MM_SOUND_ROUTE_OUT_BLUETOOTH: return "OUT_BLUETOOTH";
241 case MM_SOUND_ROUTE_OUT_DOCK: return "OUT_DOCK";
242 case MM_SOUND_ROUTE_OUT_HDMI: return "OUT_HDMI";
243 case MM_SOUND_ROUTE_OUT_WFD: return "OUT_WFD";
244 case MM_SOUND_ROUTE_OUT_USB_AUDIO: return "OUT_USB";
245 case MM_SOUND_ROUTE_IN_MIC: return "IN_MIC";
246 case MM_SOUND_ROUTE_IN_WIRED_ACCESSORY: return "IN_WIRED_ACCESSORY";
247 case MM_SOUND_ROUTE_IN_MIC_OUT_RECEIVER: return "IN_MIC_OUT_RECEIVER";
248 case MM_SOUND_ROUTE_IN_MIC_OUT_SPEAKER: return "IN_MIC_OUT_SPEAKER";
249 case MM_SOUND_ROUTE_IN_MIC_OUT_HEADPHONE: return "IN_MIC_OUT_HEADPHONE";
250 case MM_SOUND_ROUTE_INOUT_HEADSET: return "INOUT_HEADSET";
251 case MM_SOUND_ROUTE_INOUT_BLUETOOTH: return "INOUT_BLUETOOTH";
252 default: return NULL;
256 static int __mm_sound_foreach_available_route_cb (mm_sound_route route, void *user_data)
258 g_print ("[%s] route = [0x%08x][%s]\n", __func__, route, __get_route_str(route));
262 static void __mm_sound_available_route_changed_cb (mm_sound_route route, bool available, void *user_data)
264 g_print ("[%s] route = [%d][0x%08x][%s]\n", __func__, available, route, __get_route_str(route));
267 static void __mm_sound_active_device_changed_cb (mm_sound_device_in device_in, mm_sound_device_out device_out, void *user_data)
269 g_print ("[%s] in[0x%08x][%s], out[0x%08x][%s]\n", __func__,
270 device_in, __get_capture_device_str(device_in), device_out, __get_playback_device_str(device_out));
273 static void interpret (char *cmd)
276 static int handle = -1;
277 MMSoundPlayParam soundparam = {0,};
279 switch (g_menu_state)
281 case CURRENT_STATUS_MAINMENU:
282 if(strncmp(cmd, "k", 1) == 0)
284 ret = mm_sound_play_keysound(POWERON_FILE, 8);
286 debug_log("keysound play failed with 0x%x\n", ret);
288 else if(strncmp(cmd, "q", 1) == 0)
290 unsigned int value = 100;
291 ret = mm_sound_volume_get_value(g_volume_type, &value);
293 debug_log("mm_sound_volume_get_value 0x%x\n", ret);
296 g_print("*** MEDIA VOLUME : %u ***\n", value);
297 g_volume_value = value;
300 else if(strncmp(cmd, "w", 1) == 0)
301 {//set media volume up
302 unsigned int value = 100;
303 ret = mm_sound_volume_get_value(g_volume_type, &value);
305 debug_log("mm_sound_volume_get_value 0x%x\n", ret);
308 debug_log("Loaded media volume is %d\n", value);
311 mm_sound_volume_get_step(g_volume_type, &step);
315 ret = mm_sound_volume_set_value(g_volume_type, value);
317 debug_log("mm_sound_volume_set_value 0x%x\n", ret);
321 else if(strncmp(cmd, "e", 1) == 0)
322 {//set media volume down
323 unsigned int value = 100;
324 ret = mm_sound_volume_get_value(g_volume_type, &value);
326 debug_log("mm_sound_volume_get_value 0x%x\n", ret);
333 ret = mm_sound_volume_set_value(g_volume_type, value);
335 debug_log("mm_sound_volume_set_value 0x%x\n", ret);
339 else if(strncmp(cmd, "r", 1) == 0)
341 unsigned int value = 100;
342 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
344 debug_log("mm_sound_volume_get_value 0x%x\n", ret);
347 g_print("*** SYSTEM VOLUME : %u ***\n", value);
348 g_volume_value = value;
351 else if(strncmp(cmd, "t", 1) == 0)
352 {//set media volume up
353 unsigned int value = 100;
354 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
356 debug_log("mm_sound_volume_get_value 0x%x\n", ret);
359 debug_log("Loaded system volume is %d\n", value);
362 mm_sound_volume_get_step(VOLUME_TYPE_SYSTEM, &step);
366 ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
368 debug_log("mm_sound_volume_set_value 0x%x\n", ret);
370 g_print("Current System volume is %d\n", value);
374 else if(strncmp(cmd, "y", 1) == 0)
375 {//set media volume down
376 unsigned int value = 100;
377 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
379 debug_log("mm_sound_volume_get_value 0x%x\n", ret);
386 ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
388 debug_log("mm_sound_volume_set_value 0x%x\n", ret);
390 g_print("Current System volume is %d\n", value);
394 else if(strncmp(cmd, "a", 1) == 0)
396 debug_log("volume is %d type, %d\n", g_volume_type, g_volume_value);
397 ret = mm_sound_play_sound(g_file_name, g_volume_type, mycallback ,"USERDATA", &handle);
399 debug_log("mm_sound_play_sound() failed with 0x%x\n", ret);
401 else if(strncmp(cmd, "A", 1) == 0)
403 debug_log("volume is %d type, %d\n", g_volume_type, g_volume_value);
404 ret = mm_sound_play_loud_solo_sound(g_file_name, g_volume_type, mycallback ,"USERDATA", &handle);
406 debug_log("mm_sound_play_sound_loud_solo() failed with 0x%x\n", ret);
408 else if(strncmp(cmd, "F", 1) == 0)
411 char input_string[128] = "";
415 int volume_type = -1;
416 MMSoundTone_t tone = MM_SOUND_TONE_DTMF_0;
420 g_print("enter number(0~H exit:q), volume type(0~7), volume(0.0~1.0), time(ms):\t ");
421 fgets(input_string, sizeof(input_string)-1, stdin);
422 tok = strtok(input_string, " ");
427 else if(tok[0] < '0' || tok[0] > '~') {
428 if(tok[0] == '*' || tok[0] == '#')
434 if(num >= '0' && num <= '9') {
435 tone = (MMSoundTone_t)(num - '0');
437 else if(num == '*') {
438 tone = MM_SOUND_TONE_DTMF_S;
440 else if(num == '#') {
441 tone =MM_SOUND_TONE_DTMF_P;
443 else if(num == 'A') { tone = MM_SOUND_TONE_DTMF_A; }
444 else if(num == 'B') { tone = MM_SOUND_TONE_DTMF_B; }
445 else if(num == 'C') { tone = MM_SOUND_TONE_DTMF_C; }
446 else if(num == 'D') { tone = MM_SOUND_TONE_DTMF_D; }
447 else if(num == 'E') { tone = MM_SOUND_TONE_SUP_DIAL; }
448 else if(num == 'F') { tone = MM_SOUND_TONE_ANSI_DIAL; }
449 else if(num == 'G') { tone = MM_SOUND_TONE_JAPAN_DIAL; }
450 else if(num == 'H') { tone = MM_SOUND_TONE_SUP_BUSY; }
451 else if(num == 'I') { tone = MM_SOUND_TONE_ANSI_BUSY; }
452 else if(num == 'J') { tone = MM_SOUND_TONE_JAPAN_BUSY; }
453 else if(num == 'K') { tone = MM_SOUND_TONE_SUP_CONGESTION; }
454 else if(num == 'L') { tone = MM_SOUND_TONE_ANSI_CONGESTION; }
455 else if(num == 'M') { tone = MM_SOUND_TONE_SUP_RADIO_ACK; }
456 else if(num == 'N') { tone = MM_SOUND_TONE_JAPAN_RADIO_ACK; }
457 else if(num == 'O') { tone = MM_SOUND_TONE_SUP_RADIO_NOTAVAIL; }
458 else if(num == 'P') { tone = MM_SOUND_TONE_SUP_ERROR; }
459 else if(num == 'Q') { tone = MM_SOUND_TONE_SUP_CALL_WAITING; }
460 else if(num == 'R') { tone = MM_SOUND_TONE_ANSI_CALL_WAITING; }
461 else if(num == 'S') { tone = MM_SOUND_TONE_SUP_RINGTONE; }
462 else if(num == 'T') { tone = MM_SOUND_TONE_ANSI_RINGTONE; }
463 else if(num == 'U') { tone = MM_SOUND_TONE_PROP_BEEP; }
464 else if(num == 'V') { tone = MM_SOUND_TONE_PROP_ACK; }
465 else if(num == 'W') { tone = MM_SOUND_TONE_PROP_NACK; }
466 else if(num == 'X') { tone = MM_SOUND_TONE_PROP_PROMPT; }
467 else if(num == 'Y') { tone = MM_SOUND_TONE_PROP_BEEP2; }
468 else if(num == 'Z') { tone =MM_SOUND_TONE_CDMA_HIGH_SLS; }
469 else if(num == '[') { tone = MM_SOUND_TONE_CDMA_MED_SLS; }
470 else if(num == ']') { tone = MM_SOUND_TONE_CDMA_LOW_SLS; }
471 else if(num == '^') { tone =MM_SOUND_TONE_CDMA_HIGH_S_X4; }
472 else if(num == '_') { tone =MM_SOUND_TONE_CDMA_MED_S_X4; }
473 else if(num == 'a') { tone =MM_SOUND_TONE_CDMA_LOW_S_X4; }
474 else if(num == 'b') { tone =MM_SOUND_TONE_CDMA_HIGH_PBX_L; }
475 else if(num == 'c') { tone =MM_SOUND_TONE_CDMA_MED_PBX_L; }
476 else if(num == 'd') { tone =MM_SOUND_TONE_CDMA_LOW_PBX_L; }
477 else if(num == 'e') { tone =MM_SOUND_TONE_CDMA_HIGH_PBX_SS; }
478 else if(num == 'f') { tone =MM_SOUND_TONE_CDMA_MED_PBX_SS; }
479 else if(num == 'g') { tone =MM_SOUND_TONE_CDMA_LOW_PBX_SS; }
480 else if(num == 'h') { tone =MM_SOUND_TONE_CDMA_HIGH_PBX_SSL; }
481 else if(num == 'i') { tone =MM_SOUND_TONE_CDMA_MED_PBX_SSL; }
482 else if(num == 'j') { tone =MM_SOUND_TONE_CDMA_LOW_PBX_SSL; }
483 else if(num == 'k') { tone =MM_SOUND_TONE_CDMA_HIGH_PBX_SLS; }
484 else if(num == 'l') { tone =MM_SOUND_TONE_CDMA_MED_PBX_SLS; }
485 else if(num == 'm') { tone =MM_SOUND_TONE_CDMA_LOW_PBX_SLS; }
486 else if(num == 'n') { tone =MM_SOUND_TONE_CDMA_HIGH_PBX_S_X4; }
487 else if(num == 'o') { tone =MM_SOUND_TONE_CDMA_MED_PBX_S_X4; }
488 else if(num == 'p') { tone =MM_SOUND_TONE_CDMA_LOW_PBX_S_X4; }
489 else if(num == 'q') { tone =MM_SOUND_TONE_CDMA_ALERT_NETWORK_LITE; }
490 else if(num == 'r') { tone =MM_SOUND_TONE_CDMA_ALERT_AUTOREDIAL_LITE; }
491 else if(num == 's') { tone =MM_SOUND_TONE_CDMA_ONE_MIN_BEEP; }
492 else if(num == 't') { tone =MM_SOUND_TONE_CDMA_KEYPAD_VOLUME_KEY_LITE; }
493 else if(num == 'u') { tone =MM_SOUND_TONE_CDMA_PRESSHOLDKEY_LITE; }
494 else if(num == 'v') { tone =MM_SOUND_TONE_CDMA_ALERT_INCALL_LITE; }
495 else if(num == 'w') { tone =MM_SOUND_TONE_CDMA_EMERGENCY_RINGBACK; }
496 else if(num == 'x') { tone =MM_SOUND_TONE_CDMA_ALERT_CALL_GUARD; }
497 else if(num == 'y') { tone =MM_SOUND_TONE_CDMA_SOFT_ERROR_LITE; }
498 else if(num == 'z') { tone =MM_SOUND_TONE_CDMA_CALLDROP_LITE; }
499 else if(num == '{') { tone =MM_SOUND_TONE_CDMA_NETWORK_BUSY_ONE_SHOT; }
500 else if(num == '}') { tone =MM_SOUND_TONE_CDMA_CALL_SIGNAL_ISDN_PING_RING; }
501 else if(num == '~') { tone =MM_SOUND_TONE_CDMA_SIGNAL_OFF; }
502 tok = strtok(NULL, " ");
503 if(tok) volume_type = (double)atoi(tok);
505 tok = strtok(NULL, " ");
506 if(tok) volume = (double)atof(tok);
508 tok = strtok(NULL, " ");
511 tonetime = atoi(tok);
515 tonetime = MIN_TONE_PLAY_TIME;
518 debug_log("volume type: %d\t volume is %f\t tonetime: %d \n", volume_type, volume, tonetime);
519 ret = mm_sound_play_tone(tone, volume_type, volume, tonetime, &handle);
521 debug_log ("[magpie] Play DTMF sound cannot be played ! %d\n", handle);
524 else if (strncmp (cmd, "b",1) == 0)
527 struct dirent *entry;
528 struct stat file_stat;
529 char fullpath[MAX_PATH_LEN]="";
530 struct timespec start_time = {0,};
531 struct timespec current_time = {0,};
533 if(g_dir_name[strlen(g_dir_name)-1] == '/')
534 g_dir_name[strlen(g_dir_name)-1] = '\0';
536 basedir = opendir(g_dir_name);
539 while( (entry = readdir(basedir)) != NULL)
543 if(entry->d_name[0] == '.')
545 memset(fullpath, '\0' ,sizeof(fullpath));
546 snprintf(fullpath, sizeof(fullpath)-1,"%s/%s", g_dir_name, entry->d_name);
547 debug_log("Try %s\n", fullpath);
549 if (lstat(fullpath, &file_stat) == -1)
552 if(S_ISREG(file_stat.st_mode))
554 test_callback_done = 0 ;
555 start_time.tv_sec = (long int)(time(NULL));
556 start_time.tv_nsec = 0;
557 ret = mm_sound_play_sound(fullpath, g_volume_type, test_callback, NULL, &handle);
558 if(ret != MM_ERROR_NONE)
560 debug_log("Play file error : %s\n", fullpath);
567 debug_log("this is not regular file : %s\n", fullpath);
570 while((test_callback_done == 0) && (playfail ==0))
572 current_time.tv_sec = (long int)(time(NULL));
573 current_time.tv_nsec = 0;
574 if(current_time.tv_sec - start_time.tv_sec > 200)
576 if((++mywait)%5 == 0)
578 debug_log("I'm waiting callback for %d seconds after play %s\n",
579 (int)(current_time.tv_sec - start_time.tv_sec),
585 debug_log("goto next file\n");
591 debug_log("Cannot Open such a directory %s\n", g_dir_name);
596 else if (strncmp (cmd, "c",1) == 0)
598 soundparam.volume = g_volume_value;
599 soundparam.loop = -1; /* loop case */
600 soundparam.callback = mycallback;
601 soundparam.data = NULL;
602 soundparam.mem_ptr = NULL;
603 soundparam.mem_size = 0;
604 soundparam.filename = g_file_name;
605 soundparam.volume_config = g_volume_type;
607 if ((mm_sound_play_sound_ex (&soundparam, &handle))<0)
608 debug_log ("Play EX sound cannot be played !\n");
610 debug_log ("Ex sound is played Handle is [%d]\n", handle);
612 else if (strncmp (cmd, "f",1) == 0) {
613 g_menu_state=CURRENT_STATUS_FILENAME;
616 else if (strncmp (cmd, "d",1) == 0) {
617 g_menu_state=CURRENT_STATUS_DIRNAME;
619 else if (strncmp (cmd, "s",1) == 0) {
620 if(mm_sound_stop_sound(handle))
621 debug_log (" Cannot stop sound !!! %d \n", handle);
623 else if (strncmp (cmd, "1",1) == 0) {
625 if (mm_sound_set_path (MM_SOUND_GAIN_KEYTONE, MM_SOUND_PATH_SPK, MM_SOUND_PATH_NONE, MM_SOUND_PATH_OPTION_NONE)<0)
626 debug_log ("Fail to set sound path !!!\n");
627 g_print("Set path for speaker playback\n");
630 else if (strncmp (cmd, "2",1) == 0) {
632 if (mm_sound_set_path(MM_SOUND_GAIN_KEYTONE, MM_SOUND_PATH_HEADSET, MM_SOUND_PATH_NONE, MM_SOUND_PATH_OPTION_NONE)<0)
633 debug_log ("Fail to set sound path !!!\n");
634 g_print("Set path for headset playback\n");
636 else if (strncmp (cmd, "3",1) == 0) {
639 else if (strncmp (cmd, "4",1) == 0) {
641 if (mm_sound_set_path(MM_SOUND_GAIN_VOICEREC, MM_SOUND_PATH_NONE, MM_SOUND_PATH_MIC, MM_SOUND_PATH_OPTION_NONE)<0)
642 debug_log ("Fail to set sound path !!!\n");
643 g_print("Set path for recording with main mic\n");
645 else if (strncmp (cmd, "5",1) == 0) {
648 else if (strncmp (cmd, "6",1) == 0) {
650 if (mm_sound_set_path(MM_SOUND_GAIN_VOICECALL, MM_SOUND_PATH_RECV, MM_SOUND_PATH_MIC, MM_SOUND_PATH_OPTION_NONE)<0)
651 debug_log ("Fail to set sound path !!!\n");
652 g_print("Set path for voicecall\n");
654 else if (strncmp (cmd, "7",1) == 0) {
656 if (mm_sound_set_path(MM_SOUND_GAIN_VOICECALL, MM_SOUND_PATH_NONE, MM_SOUND_PATH_NONE, MM_SOUND_PATH_OPTION_NONE)<0)
657 debug_log ("Fail to set sound path !!!\n");
658 g_print("release path for voicecall\n");
660 else if (strncmp (cmd, "8",1) == 0) {
662 if (mm_sound_set_path(MM_SOUND_GAIN_VIDEOCALL, MM_SOUND_PATH_SPK, MM_SOUND_PATH_MIC, MM_SOUND_PATH_OPTION_NONE)<0)
663 debug_log ("Fail to set sound path !!!\n");
664 g_print("Set path for VT call\n");
667 else if (strncmp (cmd, "9",1) == 0) {
669 if (mm_sound_set_path(MM_SOUND_GAIN_VIDEOCALL, MM_SOUND_PATH_NONE, MM_SOUND_PATH_NONE, MM_SOUND_PATH_OPTION_NONE)<0)
670 debug_log ("[magpie] Fail to set sound path !!!\n");
671 g_print("release path for VT call\n");
674 /* -------------------------- Route Test : Starts -------------------------- */
676 g_print("==================================================================\n");
677 g_print(" Audio route APIs\n");
678 g_print("==================================================================\n");
679 g_print("u : Foreach Available Routes \t");
680 g_print("i : Get Active Devices \n");
681 g_print("o : Add Available Routes Callback \t");
682 g_print("O : Remove Available Routes Callback \n");
683 g_print("p : Add Active Route Callback\t");
684 g_print("P : Remove Active Route Callback \n");
685 g_print("{ : Get BT A2DP Status\n");
687 else if (strncmp(cmd, "u", 1) == 0) {
689 ret = mm_sound_foreach_available_route_cb(__mm_sound_foreach_available_route_cb, NULL);
690 if (ret == MM_ERROR_NONE) {
691 g_print ("### mm_sound_foreach_available_route_cb() Success\n\n");
693 g_print ("### mm_sound_foreach_available_route_cb() Error : errno [%x]\n\n", ret);
696 else if (strncmp(cmd, "i", 1) == 0) {
698 mm_sound_device_in in;
699 mm_sound_device_out out;
700 ret = mm_sound_get_active_device(&in, &out);
701 if (ret == MM_ERROR_NONE) {
702 g_print ("### mm_sound_get_active_device() Success : in[0x%08x][%s], out[0x%08x][%s]\n\n",
703 in, __get_capture_device_str(in), out, __get_playback_device_str(out));
705 g_print ("### mm_sound_get_active_device() Error : errno [%x]\n\n", ret);
708 else if (strncmp(cmd, "o", 1) == 0) {
710 ret = mm_sound_add_available_route_changed_callback(__mm_sound_available_route_changed_cb, NULL);
711 if (ret == MM_ERROR_NONE) {
712 g_print ("### mm_sound_add_available_route_changed_callback() Success\n\n");
714 g_print ("### mm_sound_add_available_route_changed_callback() Error : errno [%x]\n\n", ret);
717 else if (strncmp(cmd, "O", 1) == 0) {
719 ret = mm_sound_remove_available_route_changed_callback();
720 if (ret == MM_ERROR_NONE) {
721 g_print ("### mm_sound_remove_available_route_changed_callback() Success\n\n");
723 g_print ("### mm_sound_remove_available_route_changed_callback() Error : errno [%x]\n\n", ret);
726 else if (strncmp(cmd, "p", 1) == 0) {
728 ret = mm_sound_add_active_device_changed_callback(__mm_sound_active_device_changed_cb, NULL);
729 if (ret == MM_ERROR_NONE) {
730 g_print ("### mm_sound_add_active_device_changed_callback() Success\n\n");
732 g_print ("### mm_sound_add_active_device_changed_callback() Error : errno [%x]\n\n", ret);
735 else if (strncmp(cmd, "P", 1) == 0) {
737 ret = mm_sound_remove_active_device_changed_callback();
738 if (ret == MM_ERROR_NONE) {
739 g_print ("### mm_sound_remove_active_device_changed_callback() Success\n\n");
741 g_print ("### mm_sound_remove_active_device_changed_callback() Error : errno [%x]\n\n", ret);
744 else if (strncmp(cmd, "{", 1) == 0) {
747 char* bt_name = NULL;
749 ret = mm_sound_route_get_a2dp_status (&connected, &bt_name);
750 if (ret == MM_ERROR_NONE) {
751 g_print ("### mm_sound_route_get_a2dp_status() Success : connected=[%d] name=[%s]\n", connected, bt_name);
755 g_print ("### mm_sound_route_get_a2dp_status() Error : errno [%x]\n", ret);
759 else if(strncmp(cmd, "}", 1) == 0)
762 char input_string[128];
763 mm_sound_route route = MM_SOUND_ROUTE_OUT_SPEAKER;
767 g_print ("1. MM_SOUND_ROUTE_OUT_SPEAKER\n");
768 g_print ("2. MM_SOUND_ROUTE_OUT_WIRED_ACCESSORY\n");
769 g_print ("3. MM_SOUND_ROUTE_OUT_BLUETOOTH\n");
770 g_print ("4. MM_SOUND_ROUTE_OUT_DOCK\n");
771 g_print ("5. MM_SOUND_ROUTE_OUT_HDMI\n");
772 g_print ("6. MM_SOUND_ROUTE_OUT_WFD\n");
773 g_print ("7. MM_SOUND_ROUTE_OUT_USB_AUDIO\n");
774 g_print ("8. MM_SOUND_ROUTE_IN_MIC\n");
775 g_print ("9. MM_SOUND_ROUTE_IN_WIRED_ACCESSORY\n");
776 g_print ("0. MM_SOUND_ROUTE_IN_MIC_OUT_RECEIVER\n");
777 g_print ("a. MM_SOUND_ROUTE_IN_MIC_OUT_SPEAKER\n");
778 g_print ("b. MM_SOUND_ROUTE_IN_MIC_OUT_HEADPHONE\n");
779 g_print ("c. MM_SOUND_ROUTE_INOUT_HEADSET\n");
780 g_print ("d. MM_SOUND_ROUTE_INOUT_BLUETOOTH\n");
781 g_print("> select route number : ");
783 fgets(input_string, sizeof(input_string)-1, stdin);
784 num = input_string[0];
786 if(num == '1') { route = MM_SOUND_ROUTE_OUT_SPEAKER; }
787 else if(num == '2') { route = MM_SOUND_ROUTE_OUT_WIRED_ACCESSORY; }
788 else if(num == '3') { route = MM_SOUND_ROUTE_OUT_BLUETOOTH; }
789 else if(num == '4') { route = MM_SOUND_ROUTE_OUT_DOCK; }
790 else if(num == '5') { route = MM_SOUND_ROUTE_OUT_HDMI; }
791 else if(num == '6') { route = MM_SOUND_ROUTE_OUT_WFD; }
792 else if(num == '7') { route = MM_SOUND_ROUTE_OUT_USB_AUDIO; }
793 else if(num == '8') { route = MM_SOUND_ROUTE_IN_MIC; }
794 else if(num == '9') { route = MM_SOUND_ROUTE_IN_WIRED_ACCESSORY; }
795 else if(num == '0') { route = MM_SOUND_ROUTE_IN_MIC_OUT_RECEIVER; }
796 else if(num == 'a') { route = MM_SOUND_ROUTE_IN_MIC_OUT_SPEAKER; }
797 else if(num == 'b') { route = MM_SOUND_ROUTE_IN_MIC_OUT_HEADPHONE; }
798 else if(num == 'c') { route = MM_SOUND_ROUTE_INOUT_HEADSET; }
799 else if(num == 'd') { route = MM_SOUND_ROUTE_INOUT_BLUETOOTH; }
801 ret = mm_sound_set_active_route(route);
802 if (ret == MM_ERROR_NONE) {
803 g_print ("### mm_sound_set_active_route(%s) Success\n\n", __get_route_str (route));
805 g_print ("### mm_sound_set_acstive_route(%s) Error : errno [%x]\n\n", __get_route_str (route), ret);
809 else if(strncmp(cmd, "z", 1) ==0) {
810 if(MM_ERROR_NONE != mm_session_init(MM_SESSION_TYPE_CALL))
812 g_print("Call session init failed\n");
815 else if(strncmp(cmd, "Z", 1) ==0) {
816 if(MM_ERROR_NONE != mm_session_init(MM_SESSION_TYPE_VIDEOCALL))
818 g_print("VideoCall session init failed\n");
821 else if(strncmp(cmd, "v", 1) ==0) {
822 if(MM_ERROR_NONE != mm_session_finish())
824 g_print("Call session finish failed\n");
828 else if(strncmp(cmd, "V", 1) ==0) {
830 if(vconf_get_int(SOUND_STATUS_KEY, &value)) {
831 g_print("Can not get %s\n", SOUND_STATUS_KEY);
835 if(value == ASM_STATUS_NONE || value == ASM_STATUS_MONITOR)
837 g_print("No Session Instance\n");
839 if(value & ASM_STATUS_SHARE_MMPLAYER) {
840 g_print("SHARE - PLAYER\n");
842 if(value & ASM_STATUS_EXCLUSIVE_MMPLAYER) {
843 g_print("EXCLUSIVE - PLAYER\n");
845 if(value & ASM_STATUS_SHARE_MMSOUND) {
846 g_print("SHARE - SOUND\n");
848 if(value & ASM_STATUS_EXCLUSIVE_MMSOUND) {
849 g_print("EXCLUSIVE - SOUND\n");
851 if(value & ASM_STATUS_SHARE_MMCAMCORDER) {
852 g_print("SHARE - CAMCORDER\n");
854 if(value & ASM_STATUS_EXCLUSIVE_MMCAMCORDER) {
855 g_print("EXCLUSIVE - CAMCORDER\n");
857 if(value & ASM_STATUS_SHARE_OPENAL) {
858 g_print("SHARE - OPENAL\n");
860 if(value & ASM_STATUS_EXCLUSIVE_OPENAL) {
861 g_print("EXCLUSIVE - OPENAL\n");
863 if(value & ASM_STATUS_SHARE_AVSYSTEM) {
864 g_print("SHARE - AVSYSTEM\n");
866 if(value & ASM_STATUS_EXCLUSIVE_AVSYSTEM) {
867 g_print("EXCLUSIVE - AVSYSTEM\n");
869 if(value & ASM_STATUS_NOTIFY) {
872 if(value & ASM_STATUS_ALARM) {
875 if(value & ASM_STATUS_CALL) {
878 if(value & ASM_STATUS_VIDEOCALL) {
879 g_print("VIDEOCALL\n");
884 // End of sound & avsystem interpret
885 else if (strncmp(cmd, "x", 1) == 0) {
890 case CURRENT_STATUS_FILENAME:
892 g_menu_state=CURRENT_STATUS_MAINMENU;
895 case CURRENT_STATUS_DIRNAME:
897 g_menu_state=CURRENT_STATUS_MAINMENU;
899 case CURRENT_STATUS_POSITION:
902 //g_timeout_add(100, timeout_menu_display, 0);
905 void volume_change_callback(void* data)
907 volume_type_t* type = (volume_type_t*) data;
909 g_volume_type = *type;
910 mm_sound_volume_get_value(g_volume_type, &g_volume_value);
911 g_print("Volume Callback Runs :::: MEDIA VALUME %d\n", g_volume_value);
915 void audio_route_policy_changed_callback(void* data, system_audio_route_t policy)
917 int dummy = (int) data;
918 system_audio_route_t lv_policy;
919 char *str_route[SYSTEM_AUDIO_ROUTE_POLICY_MAX] = {
920 "DEFAULT","IGN_A2DP","HANDSET"
922 g_print("Audio Route Policy has changed to [%s]\n", str_route[policy]);
923 g_print("...read....current....policy...to cross check..%d\n", dummy);
924 if(0 > mm_sound_route_get_system_policy(&lv_policy)) {
925 g_print("Can not get policy...in callback function\n");
928 g_print("...readed policy [%s]\n", str_route[lv_policy]);
932 int main(int argc, char *argv[])
934 stdin_channel = g_io_channel_unix_new(0);
935 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
936 g_loop = g_main_loop_new (NULL, 1);
938 g_print("callback function addr :: %p\n", volume_change_callback);
939 g_volume_type = VOLUME_TYPE_MEDIA;
940 mm_sound_volume_get_value(g_volume_type, &g_volume_value);
941 mm_sound_volume_add_callback(g_volume_type, volume_change_callback, (void*) &g_volume_type);
943 g_main_loop_run (g_loop);