Tizen 2.0 Release
[profile/ivi/libmm-sound.git] / testsuite / mm_sound_testsuite_simple.c
1 /*
2  * libmm-sound
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungbae Shin <seungbae.shin@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25
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"
33
34 #include <glib.h>
35
36 #include <pthread.h>
37
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <unistd.h>
41 #include <dirent.h>
42 #include <vconf.h>
43 #include <mm_session_private.h>
44 #include <audio-session-manager-types.h>
45
46 #define POWERON_FILE    "/usr/share/keysound/poweron.wav"
47
48
49 // For testsuite status
50 enum {
51     CURRENT_STATUS_MAINMENU = 0,
52     CURRENT_STATUS_FILENAME = 1,
53     CURRENT_STATUS_POSITION = 2,
54     CURRENT_STATUS_DIRNAME = 3,
55 };
56
57 int g_menu_state = CURRENT_STATUS_MAINMENU;
58
59 volume_type_t g_volume_type = VOLUME_TYPE_MEDIA;
60 unsigned int g_volume_value;
61
62 GIOChannel *stdin_channel;
63 char g_file_name[MAX_STRING_LEN];
64 char g_dir_name[MAX_PATH_LEN];
65
66
67 GMainLoop* g_loop;
68
69 // Function
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);
74
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);
81
82 void mycallback(void *data)
83 {
84         char *str = (char*)data;
85         if(data != NULL)
86                 debug_log("mycallback called (user data:%s)\n", str);
87         else
88                 debug_log("mycallback called (no user data)\n");
89 }
90 volatile char test_callback_done;
91 void test_callback(void *data)
92 {
93         debug_log("test_callback is called\n");
94         test_callback_done = 1;
95 }
96 void quit_program()
97 {
98         g_main_loop_quit(g_loop);
99 }
100
101 static void displaymenu()
102 {
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 >>>>>>>> ");
158         }
159         else if (g_menu_state == CURRENT_STATUS_FILENAME) {
160                 g_print(">>>>Input file name to play : ");
161         }
162         else if (g_menu_state == CURRENT_STATUS_DIRNAME) {
163                         g_print(">>>>Input directory which contain audio files : ");
164         }
165         else {
166                 g_print("**** Unknown status.\n");
167                 quit_program();
168         }
169 }
170
171 gboolean timeout_menu_display(void* data)
172 {
173         displaymenu();
174         return FALSE;
175 }
176
177 gboolean timeout_quit_program(void* data)
178 {
179         quit_program();
180         return FALSE;
181 }
182
183 gboolean input (GIOChannel *channel)
184 {
185     char buf[MAX_STRING_LEN + 3];
186     gsize read;
187
188     g_io_channel_read(channel, buf, MAX_STRING_LEN, &read);
189     buf[read] = '\0';
190     g_strstrip(buf);
191     interpret (buf);
192     return TRUE;
193 }
194
195
196 static void input_filename(char *filename)
197 {
198         strncpy(g_file_name, filename, sizeof(g_file_name)-1);
199         g_print("\nThe input filename is '%s' \n\n",g_file_name);
200
201 }
202
203 static void input_dirname(char *dirname)
204 {
205         strncpy(g_dir_name, dirname, sizeof(g_dir_name)-1);
206         g_print("\nThe input directory is '%s' \n\n",g_dir_name);
207 }
208
209 static char* __get_playback_device_str (mm_sound_device_out out)
210 {
211         switch (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;
222         }
223 }
224
225 static char* __get_capture_device_str (mm_sound_device_in in)
226 {
227         switch (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;
232         }
233 }
234
235 static char* __get_route_str (mm_sound_route route)
236 {
237         switch (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;
253         }
254 }
255
256 static int __mm_sound_foreach_available_route_cb (mm_sound_route route, void *user_data)
257 {
258         g_print ("[%s] route = [0x%08x][%s]\n", __func__, route, __get_route_str(route));
259         return true;
260 }
261
262 static void __mm_sound_available_route_changed_cb (mm_sound_route route, bool available, void *user_data)
263 {
264         g_print ("[%s] route = [%d][0x%08x][%s]\n", __func__, available, route, __get_route_str(route));
265 }
266
267 static void __mm_sound_active_device_changed_cb (mm_sound_device_in device_in, mm_sound_device_out device_out, void *user_data)
268 {
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));
271 }
272
273 static void interpret (char *cmd)
274 {
275         int ret=0;
276         static int handle = -1;
277         MMSoundPlayParam soundparam = {0,};
278
279         switch (g_menu_state)
280         {
281                 case CURRENT_STATUS_MAINMENU:
282                         if(strncmp(cmd, "k", 1) == 0)
283                         {
284                                 ret = mm_sound_play_keysound(POWERON_FILE, 8);
285                                 if(ret < 0)
286                                         debug_log("keysound play failed with 0x%x\n", ret);
287                         }
288                         else if(strncmp(cmd, "q", 1) == 0)
289                         {//get media volume
290                                 unsigned int value = 100;
291                                 ret = mm_sound_volume_get_value(g_volume_type, &value);
292                                 if(ret < 0) {
293                                         debug_log("mm_sound_volume_get_value 0x%x\n", ret);
294                                 }
295                                 else{
296                                         g_print("*** MEDIA VOLUME : %u ***\n", value);
297                                         g_volume_value = value;
298                                 }
299                         }
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);
304                                 if(ret < 0) {
305                                         debug_log("mm_sound_volume_get_value 0x%x\n", ret);
306                                 }
307                                 else {
308                                         debug_log("Loaded media volume is %d\n", value);
309                                         int step;
310                                         value++;
311                                         mm_sound_volume_get_step(g_volume_type, &step);
312                                         if(value >= step) {
313                                                 value = step-1;
314                                         }
315                                         ret = mm_sound_volume_set_value(g_volume_type, value);
316                                         if(ret < 0) {
317                                                 debug_log("mm_sound_volume_set_value 0x%x\n", ret);
318                                         }
319                                 }
320                         }
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);
325                                 if(ret < 0) {
326                                         debug_log("mm_sound_volume_get_value 0x%x\n", ret);
327                                 }
328                                 else {
329                                         if(value != 0) {
330                                                 value--;
331                                         }
332
333                                         ret = mm_sound_volume_set_value(g_volume_type, value);
334                                         if(ret < 0) {
335                                                 debug_log("mm_sound_volume_set_value 0x%x\n", ret);
336                                         }
337                                 }
338                         }
339                         else if(strncmp(cmd, "r", 1) == 0)
340                         {//get media volume
341                                 unsigned int value = 100;
342                                 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
343                                 if(ret < 0) {
344                                         debug_log("mm_sound_volume_get_value 0x%x\n", ret);
345                                 }
346                                 else{
347                                         g_print("*** SYSTEM VOLUME : %u ***\n", value);
348                                         g_volume_value = value;
349                                 }
350                         }
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);
355                                 if(ret < 0) {
356                                         debug_log("mm_sound_volume_get_value 0x%x\n", ret);
357                                 }
358                                 else {
359                                         debug_log("Loaded system volume is %d\n", value);
360                                         int step;
361                                         value++;
362                                         mm_sound_volume_get_step(VOLUME_TYPE_SYSTEM, &step);
363                                         if(value >= step) {
364                                                 value = step-1;
365                                         }
366                                         ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
367                                         if(ret < 0) {
368                                                 debug_log("mm_sound_volume_set_value 0x%x\n", ret);
369                                         }else {
370                                                 g_print("Current System volume is %d\n", value);
371                                         }
372                                 }
373                         }
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);
378                                 if(ret < 0) {
379                                         debug_log("mm_sound_volume_get_value 0x%x\n", ret);
380                                 }
381                                 else {
382                                         if(value != 0) {
383                                                 value--;
384                                         }
385
386                                         ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
387                                         if(ret < 0) {
388                                                 debug_log("mm_sound_volume_set_value 0x%x\n", ret);
389                                         }else {
390                                                 g_print("Current System volume is %d\n", value);
391                                         }
392                                 }
393                         }
394                         else if(strncmp(cmd, "a", 1) == 0)
395                         {
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);
398                                 if(ret < 0)
399                                         debug_log("mm_sound_play_sound() failed with 0x%x\n", ret);
400                         }
401                         else if(strncmp(cmd, "A", 1) == 0)
402                         {
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);
405                                 if(ret < 0)
406                                         debug_log("mm_sound_play_sound_loud_solo() failed with 0x%x\n", ret);
407                         }
408                         else if(strncmp(cmd, "F", 1) == 0)
409                         {
410                                 char num = 0;
411                                 char input_string[128] = "";
412                                 char *tok = NULL;
413                                 int tonetime=0;
414                                 double volume=1.0;
415                                 int volume_type = -1;
416                                 MMSoundTone_t tone = MM_SOUND_TONE_DTMF_0;
417
418                                 while(num != 'q') {
419                                         fflush(stdin);
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, " ");
423                                         if(!tok) continue;
424                                         if(tok[0] == 'q') {
425                                                 break;
426                                         }
427                                         else if(tok[0] < '0' || tok[0] > '~') {
428                                                 if(tok[0] == '*' || tok[0] == '#')
429                                                         ;
430                                                 else
431                                                         continue;
432                                         }
433                                         num = tok[0];
434                                         if(num >= '0' && num <= '9') {
435                                                 tone = (MMSoundTone_t)(num - '0');
436                                         }
437                                         else if(num == '*') {
438                                                 tone = MM_SOUND_TONE_DTMF_S;
439                                         }
440                                         else if(num == '#') {
441                                                 tone =MM_SOUND_TONE_DTMF_P;
442                                         }
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);
504
505                                         tok = strtok(NULL, " ");
506                                         if(tok)  volume = (double)atof(tok);
507
508                                         tok = strtok(NULL, " ");
509                                         if(tok)
510                                         {
511                                                 tonetime = atoi(tok);
512                                         }
513                                         else
514                                         {
515                                                 tonetime = MIN_TONE_PLAY_TIME;
516                                         }
517
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);
520                                         if(ret<0)
521                                                 debug_log ("[magpie] Play DTMF sound cannot be played ! %d\n", handle);
522                                 }
523                         }
524                         else if (strncmp (cmd, "b",1) == 0)
525                         {
526                                 DIR     *basedir;
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,};
532
533                                 if(g_dir_name[strlen(g_dir_name)-1] == '/')
534                                         g_dir_name[strlen(g_dir_name)-1] = '\0';
535
536                                 basedir = opendir(g_dir_name);
537                                 if(basedir != NULL)
538                                 {
539                                         while( (entry = readdir(basedir)) != NULL)
540                                         {
541                                                 int playfail =0;
542                                                 int mywait = 0;
543                                                 if(entry->d_name[0] == '.')
544                                                         continue;
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);
548
549                                                 if (lstat(fullpath, &file_stat) == -1)
550                                                         continue;
551
552                                                 if(S_ISREG(file_stat.st_mode))
553                                                 {
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)
559                                                         {
560                                                                 debug_log("Play file error : %s\n", fullpath);
561                                                                 sleep(4);
562                                                                 playfail = 1;
563                                                         }
564                                                 }
565                                                 else
566                                                 {
567                                                         debug_log("this is not regular file : %s\n", fullpath);
568                                                         playfail = 1;
569                                                 }
570                                                 while((test_callback_done == 0) && (playfail ==0))
571                                                 {
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)
575                                                         {
576                                                                 if((++mywait)%5 == 0)
577                                                                 {
578                                                                         debug_log("I'm waiting callback for %d seconds after play %s\n",
579                                                                                         (int)(current_time.tv_sec - start_time.tv_sec),
580                                                                                         fullpath);
581                                                                 }
582                                                         }
583                                                         sleep(2);
584                                                 }
585                                                 debug_log("goto next file\n");
586                                         }
587                                         closedir(basedir);
588                                 }
589                                 else
590                                 {
591                                         debug_log("Cannot Open such a directory %s\n", g_dir_name);
592                                 }
593
594                         }
595
596                 else if (strncmp (cmd, "c",1) == 0)
597                 {
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;
606
607                         if ((mm_sound_play_sound_ex (&soundparam, &handle))<0)
608                                 debug_log ("Play EX sound cannot be played !\n");
609
610                         debug_log ("Ex sound is played Handle is [%d]\n", handle);
611                 }
612                 else if (strncmp (cmd, "f",1) == 0) {
613                         g_menu_state=CURRENT_STATUS_FILENAME;
614                 }
615
616                 else if (strncmp (cmd, "d",1) == 0) {
617                         g_menu_state=CURRENT_STATUS_DIRNAME;
618                 }
619                 else if (strncmp (cmd, "s",1) == 0) {
620                         if(mm_sound_stop_sound(handle))
621                                 debug_log (" Cannot stop sound !!! %d \n", handle);
622                 }
623                 else if (strncmp (cmd, "1",1) == 0) {
624                         //ap to spk
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");
628                 }
629
630                 else if (strncmp (cmd, "2",1) == 0) {
631                         //ap to headset
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");
635                 }
636                 else if (strncmp (cmd, "3",1) == 0) {
637
638                 }
639                 else if (strncmp (cmd, "4",1) == 0) {
640                         //recording
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");
644                 }
645                 else if (strncmp (cmd, "5",1) == 0) {
646
647                 }
648                 else if (strncmp (cmd, "6",1) == 0) {
649                         //voice call
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");
653                 }
654                 else if (strncmp (cmd, "7",1) == 0) {
655                         //voicecall release
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");
659                 }
660                 else if (strncmp (cmd, "8",1) == 0) {
661                         //voice call
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");
665                 }
666
667                 else if (strncmp (cmd, "9",1) == 0) {
668                         //voicecall release
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");
672                 }
673
674                 /* -------------------------- Route Test : Starts -------------------------- */
675 #if 0
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");
686 #endif
687                 else if (strncmp(cmd, "u", 1) == 0) {
688                         int ret = 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");
692                         } else {
693                                 g_print ("### mm_sound_foreach_available_route_cb() Error : errno [%x]\n\n", ret);
694                         }
695                 }
696                 else if (strncmp(cmd, "i", 1) == 0) {
697                         int ret = 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));
704                         } else {
705                                 g_print ("### mm_sound_get_active_device() Error : errno [%x]\n\n", ret);
706                         }
707                 }
708                 else if (strncmp(cmd, "o", 1) == 0) {
709                         int ret = 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");
713                         } else {
714                                 g_print ("### mm_sound_add_available_route_changed_callback() Error : errno [%x]\n\n", ret);
715                         }
716                 }
717                 else if (strncmp(cmd, "O", 1) == 0) {
718                         int ret = 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");
722                         } else {
723                                 g_print ("### mm_sound_remove_available_route_changed_callback() Error : errno [%x]\n\n", ret);
724                         }
725                 }
726                 else if (strncmp(cmd, "p", 1) == 0) {
727                         int ret = 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");
731                         } else {
732                                 g_print ("### mm_sound_add_active_device_changed_callback() Error : errno [%x]\n\n", ret);
733                         }
734                 }
735                 else if (strncmp(cmd, "P", 1) == 0) {
736                         int ret = 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");
740                         } else {
741                                 g_print ("### mm_sound_remove_active_device_changed_callback() Error : errno [%x]\n\n", ret);
742                         }
743                 }
744                 else if (strncmp(cmd, "{", 1) == 0) {
745                         int ret = 0;
746                         int connected = 0;
747                         char* bt_name = NULL;
748
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);
752                                 if (bt_name)
753                                         free (bt_name);
754                         } else {
755                                 g_print ("### mm_sound_route_get_a2dp_status() Error : errno [%x]\n", ret);
756                         }
757                 }
758
759                 else if(strncmp(cmd, "}", 1) == 0)
760                 {
761                         int ret = 0;
762                         char input_string[128];
763                         mm_sound_route route = MM_SOUND_ROUTE_OUT_SPEAKER;
764                         char num;
765
766                         fflush(stdin);
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 : ");
782
783                         fgets(input_string, sizeof(input_string)-1, stdin);
784                         num = input_string[0];
785
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; }
800
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));
804                         } else {
805                                 g_print ("### mm_sound_set_acstive_route(%s) Error : errno [%x]\n\n", __get_route_str (route), ret);
806                         }
807                 }
808
809                 else if(strncmp(cmd, "z", 1) ==0) {
810                         if(MM_ERROR_NONE != mm_session_init(MM_SESSION_TYPE_CALL))
811                         {
812                                 g_print("Call session init failed\n");
813                         }
814                 }
815                 else if(strncmp(cmd, "Z", 1) ==0) {
816                         if(MM_ERROR_NONE != mm_session_init(MM_SESSION_TYPE_VIDEOCALL))
817                         {
818                                 g_print("VideoCall session init failed\n");
819                         }
820                 }
821                 else if(strncmp(cmd, "v", 1) ==0) {
822                         if(MM_ERROR_NONE != mm_session_finish())
823                         {
824                                 g_print("Call session finish failed\n");
825                         }
826                 }
827
828                 else if(strncmp(cmd, "V", 1) ==0) {
829                         int value;
830                         if(vconf_get_int(SOUND_STATUS_KEY, &value)) {
831                                 g_print("Can not get %s\n", SOUND_STATUS_KEY);
832                         }
833                         else
834                         {
835                                 if(value == ASM_STATUS_NONE || value == ASM_STATUS_MONITOR)
836                                 {
837                                         g_print("No Session Instance\n");
838                                 }
839                                 if(value & ASM_STATUS_SHARE_MMPLAYER) {
840                                         g_print("SHARE - PLAYER\n");
841                                 }
842                                 if(value & ASM_STATUS_EXCLUSIVE_MMPLAYER) {
843                                         g_print("EXCLUSIVE - PLAYER\n");
844                                 }
845                                 if(value & ASM_STATUS_SHARE_MMSOUND) {
846                                         g_print("SHARE - SOUND\n");
847                                 }
848                                 if(value & ASM_STATUS_EXCLUSIVE_MMSOUND) {
849                                         g_print("EXCLUSIVE - SOUND\n");
850                                 }
851                                 if(value & ASM_STATUS_SHARE_MMCAMCORDER) {
852                                         g_print("SHARE - CAMCORDER\n");
853                                 }
854                                 if(value & ASM_STATUS_EXCLUSIVE_MMCAMCORDER) {
855                                         g_print("EXCLUSIVE - CAMCORDER\n");
856                                 }
857                                 if(value & ASM_STATUS_SHARE_OPENAL) {
858                                         g_print("SHARE - OPENAL\n");
859                                 }
860                                 if(value & ASM_STATUS_EXCLUSIVE_OPENAL) {
861                                         g_print("EXCLUSIVE - OPENAL\n");
862                                 }
863                                 if(value & ASM_STATUS_SHARE_AVSYSTEM) {
864                                         g_print("SHARE - AVSYSTEM\n");
865                                 }
866                                 if(value & ASM_STATUS_EXCLUSIVE_AVSYSTEM) {
867                                         g_print("EXCLUSIVE - AVSYSTEM\n");
868                                 }
869                                 if(value & ASM_STATUS_NOTIFY) {
870                                         g_print("NOTIFY\n");
871                                 }
872                                 if(value & ASM_STATUS_ALARM) {
873                                         g_print("ALARM\n");
874                                 }
875                                 if(value & ASM_STATUS_CALL) {
876                                         g_print("CALL\n");
877                                 }
878                                 if(value & ASM_STATUS_VIDEOCALL) {
879                                         g_print("VIDEOCALL\n");
880                                 }
881                         }
882                 }
883
884                 // End of sound & avsystem interpret
885                 else if (strncmp(cmd, "x", 1) == 0) {
886                         quit_program();
887                 }
888                 break;
889
890         case CURRENT_STATUS_FILENAME:
891                 input_filename(cmd);
892                 g_menu_state=CURRENT_STATUS_MAINMENU;
893                 break;
894
895         case CURRENT_STATUS_DIRNAME:
896                 input_dirname(cmd);
897                 g_menu_state=CURRENT_STATUS_MAINMENU;
898                 break;
899         case CURRENT_STATUS_POSITION:
900                 break;
901         }
902         //g_timeout_add(100, timeout_menu_display, 0);
903 }
904
905 void volume_change_callback(void* data)
906 {
907         volume_type_t* type = (volume_type_t*) data;
908
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);
912 }
913
914
915 void audio_route_policy_changed_callback(void* data, system_audio_route_t policy)
916 {
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"
921                 };
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");
926         }
927         else {
928                 g_print("...readed policy [%s]\n", str_route[lv_policy]);
929         }
930 }
931
932 int main(int argc, char *argv[])
933 {
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);
937
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);
942         displaymenu();
943         g_main_loop_run (g_loop);
944
945         return 0;
946 }
947