Add new API to remove all devices from stream information handle
[platform/core/api/sound-manager.git] / test / sound_manager_test.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <stdio.h>
18 #include <string.h>
19 #include <stdlib.h>
20
21 #include <sound_manager.h>
22 #include <sound_manager_private.h>
23 #include <sound_manager_internal.h>
24 #include <mm_sound.h>
25 #include <pthread.h>
26 #include <glib.h>
27
28 #define MAX_STRING_LEN  2048
29 #define NOT_AVAIL       "N/A";
30
31 enum {
32         CURRENT_STATUS_MAINMENU,
33         CURRENT_STATUS_GET_MAX_VOLUME,
34         CURRENT_STATUS_SET_VOLUME,
35         CURRENT_STATUS_GET_VOLUME,
36         CURRENT_STATUS_SET_CURRENT_SOUND_TYPE,
37         CURRENT_STATUS_GET_CURRENT_SOUND_TYPE,
38         CURRENT_STATUS_UNSET_CURRENT_SOUND_TYPE,
39         CURRENT_STATUS_SET_VOLUME_CHANGED_CB,
40         CURRENT_STATUS_UNSET_VOLUME_CHANGED_CB,
41         CURRENT_STATUS_SET_SESSION_TYPE,
42         CURRENT_STATUS_GET_SESSION_TYPE,
43         CURRENT_STATUS_SET_MEDIA_SESSION_OPTION,
44         CURRENT_STATUS_GET_MEDIA_SESSION_OPTION,
45         CURRENT_STATUS_SET_MEDIA_SESSION_RESUMPTION_OPTION,
46         CURRENT_STATUS_GET_MEDIA_SESSION_RESUMPTION_OPTION,
47         CURRENT_STATUS_SET_VOIP_SESSION_MODE,
48         CURRENT_STATUS_GET_VOIP_SESSION_MODE,
49         CURRENT_STATUS_SET_CALL_SESSION_MODE,
50         CURRENT_STATUS_GET_CALL_SESSION_MODE,
51         CURRENT_STATUS_SET_SESSION_INTERRUPTED_CB,
52         CURRENT_STATUS_UNSET_SESSION_INTERRUPTED_CB,
53         CURRENT_STATUS_SET_DEVICE_MASK,
54         CURRENT_STATUS_GET_DEVICE_MASK,
55         CURRENT_STATUS_GET_CURRENT_DEVICE_LIST,
56         CURRENT_STATUS_PRINT_DEVICE_LIST,
57         CURRENT_STATUS_GET_DEVICE_LIST,
58         CURRENT_STATUS_FREE_DEVICE_LIST,
59         CURRENT_STATUS_GET_DEVICE_NEXT,
60         CURRENT_STATUS_GET_DEVICE_PREV,
61         CURRENT_STATUS_SET_DEVICE_CONNECTED_CB,
62         CURRENT_STATUS_UNSET_DEVICE_CONNECTED_CB,
63         CURRENT_STATUS_ADD_DEVICE_CONNECTION_CHANGED_CB,
64         CURRENT_STATUS_REMOVE_DEVICE_CONNECTION_CHANGED_CB,
65         CURRENT_STATUS_SET_DEVICE_INFO_CHANGED_CB,
66         CURRENT_STATUS_UNSET_DEVICE_INFO_CHANGED_CB,
67         CURRENT_STATUS_ADD_DEVICE_STATE_CHANGED_CB,
68         CURRENT_STATUS_REMOVE_DEVICE_STATE_CHANGED_CB,
69         CURRENT_STATUS_CREATE_STREAM_INFO,
70         CURRENT_STATUS_ADD_DEVICE_FOR_STREAM_ROUTING,
71         CURRENT_STATUS_REMOVE_DEVICE_FOR_STREAM_ROUTING,
72         CURRENT_STATUS_REMOVE_ALL_DEVICES_FOR_STREAM_ROUTING,
73         CURRENT_STATUS_ADD_DEVICE_ID_FOR_STREAM_ROUTING,
74         CURRENT_STATUS_REMOVE_DEVICE_ID_FOR_STREAM_ROUTING,
75         CURRENT_STATUS_APPLY_STREAM_ROUTING,
76         CURRENT_STATUS_SET_STREAM_ROUTING_OPTION,
77         CURRENT_STATUS_ACQUIRE_FOCUS,
78         CURRENT_STATUS_RELEASE_FOCUS,
79         CURRENT_STATUS_ACQUIRE_FOCUS_ALL,
80         CURRENT_STATUS_RELEASE_FOCUS_ALL,
81         CURRENT_STATUS_GET_ACQUIRED_FOCUS,
82         CURRENT_STATUS_GET_SOUND_TYPE,
83         CURRENT_STATUS_DELIVER_FOCUS,
84         CURRENT_STATUS_DESTROY_STREAM_INFO,
85         CURRENT_STATUS_ADD_FOCUS_WATCH_CB,
86         CURRENT_STATUS_REMOVE_FOCUS_WATCH_CB,
87         CURRENT_STATUS_SET_FOCUS_REACQUISITION,
88         CURRENT_STATUS_GET_FOCUS_REACQUISITION,
89         CURRENT_STATUS_GET_REASON_FOR_P_FOCUS,
90         CURRENT_STATUS_GET_REASON_FOR_R_FOCUS,
91         CURRENT_STATUS_GET_CURRENT_MEDIA_PLAYBACK_DEVICE_TYPE,
92         CURRENT_STATUS_CREATE_VIRTUAL_STREAM,
93         CURRENT_STATUS_START_VIRTUAL_STREAM,
94         CURRENT_STATUS_STOP_VIRTUAL_STREAM,
95         CURRENT_STATUS_DESTROY_VIRTUAL_STREAM,
96         CURRENT_STATUS_SET_FILTER,
97         CURRENT_STATUS_SET_FILTER_PRESET,
98         CURRENT_STATUS_UNSET_FILTER,
99 #ifndef TIZEN_FEATURE_TV_PROD
100         CURRENT_STATUS_GET_MAX_MASTER_VOLUME,
101         CURRENT_STATUS_SET_MASTER_VOLUME,
102         CURRENT_STATUS_GET_MASTER_VOLUME,
103 #endif
104 };
105
106
107 static int g_menu_state = CURRENT_STATUS_MAINMENU;
108
109 GMainLoop* g_loop;
110 sound_device_list_h g_device_list = NULL;
111 sound_device_mask_e g_device_mask = SOUND_DEVICE_ALL_MASK;
112 sound_stream_info_h g_stream_info_h = NULL;
113 virtual_sound_stream_h g_vstream_h = NULL;
114 int g_device_conn_cb_id;
115 int g_device_state_cb_id;
116
117 static const char *g_device_direction_str[] = {"IN", "OUT", "BOTH"};
118 static const char *g_device_state_str[] = {"De-Activated", "Activated"};
119
120 void focus_callback(sound_stream_info_h stream_info,
121                                         sound_stream_focus_mask_e focus_mask,
122                                         sound_stream_focus_state_e focus_state,
123                                         sound_stream_focus_change_reason_e reason,
124                                         int sound_behavior,
125                                         const char *extra_info,
126                                         void *user_data)
127 {
128         int ret = SOUND_MANAGER_ERROR_NONE;
129         sound_stream_focus_state_e playback_focus_state;
130         sound_stream_focus_state_e recording_focus_state;
131
132         g_print("\n*** FOCUS callback is called, stream_info(%p) ***\n", stream_info);
133
134         g_print(" - changed focus: mask(%x), state(%d) (0:released, 1:acquired)\n", focus_mask, focus_state);
135         g_print(" - change_reason(%d), behavior(0x%x), extra_info(%s), user_data(%p)\n", reason, sound_behavior, extra_info, user_data);
136
137         ret = sound_manager_get_focus_state(stream_info, &playback_focus_state, &recording_focus_state);
138         if (!ret)
139                 g_print(" - focus_state : PLAYBACK(%d), RECORDING(%d) (0:released, 1:acquired)\n", playback_focus_state, recording_focus_state);
140
141         g_print("*** FOCUS callback is ended, stream_info(%p) ****\n\n", stream_info);
142
143         return;
144 }
145
146 void focus_watch_callback(int id, sound_stream_focus_mask_e  focus_mask, sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason, const char *extra_info, void *user_data)
147 {
148         g_print("\n*** FOCUS WATCH callback is called, id(%d) ***\n", id);
149         g_print(" - changed_focus_mask(%d), changed_focus_state(%d), change_reason(%d), extra_info(%s), user_data(%p)\n",
150                         focus_mask, focus_state, reason, extra_info, user_data);
151         return;
152 }
153
154 void quit_program()
155 {
156         g_main_loop_quit(g_loop);
157 }
158
159 void _interpret_main_menu(char *cmd)
160 {
161         if (strncmp(cmd, "gx", 3) == 0)
162                 g_menu_state = CURRENT_STATUS_GET_MAX_VOLUME;
163         else if (strncmp(cmd, "sv", 3) == 0)
164                 g_menu_state = CURRENT_STATUS_SET_VOLUME;
165         else if (strncmp(cmd, "gv", 3) == 0)
166                 g_menu_state = CURRENT_STATUS_GET_VOLUME;
167         else if (strncmp(cmd, "st", 3) == 0)
168                 g_menu_state = CURRENT_STATUS_SET_CURRENT_SOUND_TYPE;
169         else if (strncmp(cmd, "gt", 3) == 0)
170                 g_menu_state = CURRENT_STATUS_GET_CURRENT_SOUND_TYPE;
171         else if (strncmp(cmd, "ut", 3) == 0)
172                 g_menu_state = CURRENT_STATUS_UNSET_CURRENT_SOUND_TYPE;
173         else if (strncmp(cmd, "vc", 3) == 0)
174                 g_menu_state = CURRENT_STATUS_SET_VOLUME_CHANGED_CB;
175         else if (strncmp(cmd, "uv", 3) == 0)
176                 g_menu_state = CURRENT_STATUS_UNSET_VOLUME_CHANGED_CB;
177         else if (strncmp(cmd, "ss", 3) == 0)
178                 g_menu_state = CURRENT_STATUS_SET_SESSION_TYPE;
179         else if (strncmp(cmd, "gs", 3) == 0)
180                 g_menu_state = CURRENT_STATUS_GET_SESSION_TYPE;
181         else if (strncmp(cmd, "sm", 3) == 0)
182                 g_menu_state = CURRENT_STATUS_SET_MEDIA_SESSION_OPTION;
183         else if (strncmp(cmd, "gm", 3) == 0)
184                 g_menu_state = CURRENT_STATUS_GET_MEDIA_SESSION_OPTION;
185         else if (strncmp(cmd, "sr", 3) == 0)
186                 g_menu_state = CURRENT_STATUS_SET_MEDIA_SESSION_RESUMPTION_OPTION;
187         else if (strncmp(cmd, "gr", 3) == 0)
188                 g_menu_state = CURRENT_STATUS_GET_MEDIA_SESSION_RESUMPTION_OPTION;
189         else if (strncmp(cmd, "so", 3) == 0)
190                 g_menu_state = CURRENT_STATUS_SET_VOIP_SESSION_MODE;
191         else if (strncmp(cmd, "go", 3) == 0)
192                 g_menu_state = CURRENT_STATUS_GET_VOIP_SESSION_MODE;
193         else if (strncmp(cmd, "sl", 3) == 0)
194                 g_menu_state = CURRENT_STATUS_SET_CALL_SESSION_MODE;
195         else if (strncmp(cmd, "gc", 3) == 0)
196                 g_menu_state = CURRENT_STATUS_GET_CALL_SESSION_MODE;
197         else if (strncmp(cmd, "sc", 3) == 0)
198                 g_menu_state = CURRENT_STATUS_SET_SESSION_INTERRUPTED_CB;
199         else if (strncmp(cmd, "us", 3) == 0)
200                 g_menu_state = CURRENT_STATUS_UNSET_SESSION_INTERRUPTED_CB;
201         else if (strncmp(cmd, "sk", 3) == 0)
202                 g_menu_state = CURRENT_STATUS_SET_DEVICE_MASK;
203         else if (strncmp(cmd, "gk", 3) == 0)
204                 g_menu_state = CURRENT_STATUS_GET_DEVICE_MASK;
205         else if (strncmp(cmd, "gcl", 3) == 0)
206                 g_menu_state = CURRENT_STATUS_GET_CURRENT_DEVICE_LIST;
207         else if (strncmp(cmd, "gl", 3) == 0)
208                 g_menu_state = CURRENT_STATUS_GET_DEVICE_LIST;
209         else if (strncmp(cmd, "pl", 3) == 0)
210                 g_menu_state = CURRENT_STATUS_PRINT_DEVICE_LIST;
211         else if (strncmp(cmd, "fl", 3) == 0)
212                 g_menu_state = CURRENT_STATUS_FREE_DEVICE_LIST;
213         else if (strncmp(cmd, "gn", 3) == 0)
214                 g_menu_state = CURRENT_STATUS_GET_DEVICE_NEXT;
215         else if (strncmp(cmd, "gp", 3) == 0)
216                 g_menu_state = CURRENT_STATUS_GET_DEVICE_PREV;
217         else if (strncmp(cmd, "sd", 3) == 0)
218                 g_menu_state = CURRENT_STATUS_SET_DEVICE_CONNECTED_CB;
219         else if (strncmp(cmd, "ud", 3) == 0)
220                 g_menu_state = CURRENT_STATUS_UNSET_DEVICE_CONNECTED_CB;
221         else if (strncmp(cmd, "adcc", 4) == 0)
222                 g_menu_state = CURRENT_STATUS_ADD_DEVICE_CONNECTION_CHANGED_CB;
223         else if (strncmp(cmd, "rdcc", 4) == 0)
224                 g_menu_state = CURRENT_STATUS_REMOVE_DEVICE_CONNECTION_CHANGED_CB;
225         else if (strncmp(cmd, "si", 3) == 0)
226                 g_menu_state = CURRENT_STATUS_SET_DEVICE_INFO_CHANGED_CB;
227         else if (strncmp(cmd, "ui", 3) == 0)
228                 g_menu_state = CURRENT_STATUS_UNSET_DEVICE_INFO_CHANGED_CB;
229         else if (strncmp(cmd, "adsc", 4) == 0)
230                 g_menu_state = CURRENT_STATUS_ADD_DEVICE_STATE_CHANGED_CB;
231         else if (strncmp(cmd, "rdsc", 4) == 0)
232                 g_menu_state = CURRENT_STATUS_REMOVE_DEVICE_STATE_CHANGED_CB;
233         else if (strncmp(cmd, "csi", 3) == 0)
234                 g_menu_state = CURRENT_STATUS_CREATE_STREAM_INFO;
235         else if (strncmp(cmd, "ads", 3) == 0)
236                 g_menu_state = CURRENT_STATUS_ADD_DEVICE_FOR_STREAM_ROUTING;
237         else if (strncmp(cmd, "rds", 3) == 0)
238                 g_menu_state = CURRENT_STATUS_REMOVE_DEVICE_FOR_STREAM_ROUTING;
239         else if (strncmp(cmd, "rad", 3) == 0)
240                 g_menu_state = CURRENT_STATUS_REMOVE_ALL_DEVICES_FOR_STREAM_ROUTING;
241         else if (strncmp(cmd, "adi", 3) == 0)
242                 g_menu_state = CURRENT_STATUS_ADD_DEVICE_ID_FOR_STREAM_ROUTING;
243         else if (strncmp(cmd, "rdi", 3) == 0)
244                 g_menu_state = CURRENT_STATUS_REMOVE_DEVICE_ID_FOR_STREAM_ROUTING;
245         else if (strncmp(cmd, "aps", 3) == 0)
246                 g_menu_state = CURRENT_STATUS_APPLY_STREAM_ROUTING;
247         else if (strncmp(cmd, "sso", 3) == 0)
248                 g_menu_state = CURRENT_STATUS_SET_STREAM_ROUTING_OPTION;
249         else if (strncmp(cmd, "afc", 3) == 0)
250                 g_menu_state = CURRENT_STATUS_ACQUIRE_FOCUS;
251         else if (strncmp(cmd, "rfc", 3) == 0)
252                 g_menu_state = CURRENT_STATUS_RELEASE_FOCUS;
253         else if (strncmp(cmd, "afa", 3) == 0)
254                 g_menu_state = CURRENT_STATUS_ACQUIRE_FOCUS_ALL;
255         else if (strncmp(cmd, "rfa", 3) == 0)
256                 g_menu_state = CURRENT_STATUS_RELEASE_FOCUS_ALL;
257         else if (strncmp(cmd, "gfs", 3) == 0)
258                 g_menu_state = CURRENT_STATUS_GET_ACQUIRED_FOCUS;
259         else if (strncmp(cmd, "gst", 3) == 0)
260                 g_menu_state = CURRENT_STATUS_GET_SOUND_TYPE;
261         else if (strncmp(cmd, "dfc", 3) == 0)
262                 g_menu_state = CURRENT_STATUS_DELIVER_FOCUS;
263         else if (strncmp(cmd, "afw", 3) == 0)
264                 g_menu_state = CURRENT_STATUS_ADD_FOCUS_WATCH_CB;
265         else if (strncmp(cmd, "rfw", 3) == 0)
266                 g_menu_state = CURRENT_STATUS_REMOVE_FOCUS_WATCH_CB;
267         else if (strncmp(cmd, "sfr", 3) == 0)
268                 g_menu_state = CURRENT_STATUS_SET_FOCUS_REACQUISITION;
269         else if (strncmp(cmd, "gfr", 3) == 0)
270                 g_menu_state = CURRENT_STATUS_GET_FOCUS_REACQUISITION;
271         else if (strncmp(cmd, "grp", 3) == 0)
272                 g_menu_state = CURRENT_STATUS_GET_REASON_FOR_P_FOCUS;
273         else if (strncmp(cmd, "grr", 3) == 0)
274                 g_menu_state = CURRENT_STATUS_GET_REASON_FOR_R_FOCUS;
275         else if (strncmp(cmd, "gmp", 3) == 0)
276                 g_menu_state = CURRENT_STATUS_GET_CURRENT_MEDIA_PLAYBACK_DEVICE_TYPE;
277         else if (strncmp(cmd, "dsi", 3) == 0)
278                 g_menu_state = CURRENT_STATUS_DESTROY_STREAM_INFO;
279         else if (strncmp(cmd, "vcr", 3) == 0)
280                 g_menu_state = CURRENT_STATUS_CREATE_VIRTUAL_STREAM;
281         else if (strncmp(cmd, "vsr", 3) == 0)
282                 g_menu_state = CURRENT_STATUS_START_VIRTUAL_STREAM;
283         else if (strncmp(cmd, "vst", 3) == 0)
284                 g_menu_state = CURRENT_STATUS_STOP_VIRTUAL_STREAM;
285         else if (strncmp(cmd, "vdt", 3) == 0)
286                 g_menu_state = CURRENT_STATUS_DESTROY_VIRTUAL_STREAM;
287         else if (strncmp(cmd, "sft", 3) == 0)
288                 g_menu_state = CURRENT_STATUS_SET_FILTER;
289         else if (strncmp(cmd, "sfp", 3) == 0)
290                 g_menu_state = CURRENT_STATUS_SET_FILTER_PRESET;
291         else if (strncmp(cmd, "uft", 3) == 0)
292                 g_menu_state = CURRENT_STATUS_UNSET_FILTER;
293 #ifndef TIZEN_FEATURE_TV_PROD
294         else if (strncmp(cmd, "mgx", 3) == 0)
295                 g_menu_state = CURRENT_STATUS_GET_MAX_MASTER_VOLUME;
296         else if (strncmp(cmd, "msv", 3) == 0)
297                 g_menu_state = CURRENT_STATUS_SET_MASTER_VOLUME;
298         else if (strncmp(cmd, "mgv", 3) == 0)
299                 g_menu_state = CURRENT_STATUS_GET_MASTER_VOLUME;
300 #endif
301         else if (strncmp(cmd, "q", 3) == 0) {
302                 g_print("closing the test suite\n");
303                 quit_program();
304         } else
305                 g_print("unknown menu \n");
306 }
307
308 void display_sub_basic()
309 {
310         g_print("\n");
311         g_print("=========================================================================================\n");
312         g_print("                          Sound Manager Test (press q to quit) \n");
313         g_print("-----------------------------------------------------------------------------------------\n");
314         g_print("                                    VOLUME MODULE \n");
315         g_print("-----------------------------------------------------------------------------------------\n");
316         g_print("gx. Get Max Volume \t");
317         g_print("gv. Get Volume \t");
318         g_print("sv. Set Volume \n");
319         g_print("st. Set Current Sound Type \t");
320         g_print("gt. Get Current Sound Type \t");
321         g_print("ut. Unset Current Sound Type \n");
322         g_print("vc. Set Volume Changed CB \t");
323         g_print("uv. Unset Volume Changed CB \n");
324 #ifndef TIZEN_FEATURE_TV_PROD
325         g_print("mgx. *Get Max Master Volume \t");
326         g_print("mgv. *Get Master Volume \t");
327         g_print("msv. *Set Master Volume \n");
328 #endif
329         g_print("-----------------------------------------------------------------------------------------\n");
330         g_print("                                    SESSION MODULE \n");
331         g_print("-----------------------------------------------------------------------------------------\n");
332         g_print("ss. Set Session Type\t\t");
333         g_print("gs. Get Session Type\n");
334         g_print("sm. Set Media Session Option \t");
335         g_print("gm. Get Media Session Option \n");
336         g_print("sr. Set Media Session Resumption Option \t");
337         g_print("gr. Get Media Session Resumption Option \n");
338         g_print("so. Set Voip Session Mode \t");
339         g_print("go. Get Voip Session Mode \n");
340         g_print("sc. Set Session Interruped CB \t");
341         g_print("us. Unset Session Interrupted CB \n");
342         g_print("-----------------------------------------------------------------------------------------\n");
343         g_print("                                    DEVICE MODULE \n");
344         g_print("-----------------------------------------------------------------------------------------\n");
345         g_print("sk. Set Devices Mask(default ALL)\t");
346         g_print("gk. Get Devices Mask\n");
347         g_print("gcl. Get Devices List\t");
348         g_print("pl. Print Devices List\t");
349         g_print("gl. Get Devices List\t");
350         g_print("fl. Free Devices List\n");
351         g_print("gn. Get Next Device\t\t");
352         g_print("gp. Get Prev Device\n");
353         g_print("sd. Set Device Connenected CB\t\t");
354         g_print("ud. Unset Device Connenected CB\n");
355         g_print("si. Set Device Information Changed CB\t");
356         g_print("ui. Unset Device Information Changed CB\n");
357         g_print("adcc. Add Device Connenection Changed CB\t\t");
358         g_print("rdcc. Remove Device Connenection Changed CB\n");
359         g_print("adsc. Add Device State Changed CB\t\t");
360         g_print("rdsc. Remove Device State Changed CB\n");
361         g_print("-----------------------------------------------------------------------------------------\n");
362         g_print("                                    STREAM POLICY MODULE \n");
363         g_print("-----------------------------------------------------------------------------------------\n");
364         g_print("csi. Create Stream Info\t");
365         g_print("dsi. Destroy Stream Info\n");
366         g_print("gst. Get Sound Type\n");
367         g_print("ads. Add Device for Stream Routing\t");
368         g_print("rds. Remove Device for Stream Routing\n");
369         g_print("adi. *Add Device ID for Stream Routing\t");
370         g_print("rdi. *Remove Device ID for Stream Routing\n");
371         g_print("aps. Apply devices for Stream Routing\t");
372         g_print("rad. Remove all devices for Stream Routing\n");
373         g_print("afc. Acquire Focus\t");
374         g_print("rfc. Release Focus\t");
375         g_print("gfs. Get Focus State\n");
376         g_print("afa. Acquire Focus All\t");
377         g_print("rfa. Release Focus All\t");
378         g_print("dfc. Deliver Focus\n");
379         g_print("afw. Add Focus State Watch CB\t");
380         g_print("rfw. Remove Focus State Watch CB\n");
381         g_print("sfr. Set Focus Reacquisition\t");
382         g_print("gfr. Get Focus Reacquisition\n");
383         g_print("grp. Get Reason for Current Acquired Playback Focus\t");
384         g_print("grr. Get Reason for Current Acquired Recording Focus\n");
385         g_print("gmp. Get Current Media Playback Routing Path\n");
386         g_print("sso. *Set option for stream routing\n");
387         g_print("vcr. *Create VStream\t");
388         g_print("vsr. *Start VStream\t");
389         g_print("vst. *Stop VStream\t");
390         g_print("vdt. *Destroy VStream\n");
391         g_print("sft. *Set Filter\t");
392         g_print("sfp. *Set Filter Preset\t");
393         g_print("uft. *Unset Filter\n");
394         g_print("                                                                 * is for internal usage.\n");
395         g_print("=========================================================================================\n");
396 }
397
398 static void displaymenu()
399 {
400         static int flag = 0;
401         if (g_menu_state == CURRENT_STATUS_MAINMENU) {
402                 display_sub_basic();
403                 flag = 0;
404         } else if (g_menu_state == CURRENT_STATUS_GET_MAX_VOLUME)
405                 g_print("*** input sound type(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:VOICE)\n");
406         else if (g_menu_state == CURRENT_STATUS_SET_VOLUME) {
407                 if (flag == 0)
408                         g_print("*** input sound type and desired volume level(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:VOICE, (0~max volum).\n");
409                 flag = 1;
410         } else if (g_menu_state == CURRENT_STATUS_GET_VOLUME)
411                 g_print("*** input sound type(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:VOICE)\n");
412         else if (g_menu_state == CURRENT_STATUS_SET_CURRENT_SOUND_TYPE)
413                 g_print("*** input sound type.(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:VOICE)\n");
414         else if (g_menu_state == CURRENT_STATUS_GET_CURRENT_SOUND_TYPE)
415                 g_print("*** press enter to get current sound type\n");
416         else if (g_menu_state == CURRENT_STATUS_UNSET_CURRENT_SOUND_TYPE)
417                 g_print("*** press enter to unset current sound type\n");
418         else if (g_menu_state == CURRENT_STATUS_SET_VOLUME_CHANGED_CB)
419                 g_print("*** press enter to set volume changed cb\n");
420         else if (g_menu_state == CURRENT_STATUS_UNSET_VOLUME_CHANGED_CB)
421                 g_print("*** press enter to unset volume changed cb\n");
422         else if (g_menu_state == CURRENT_STATUS_SET_SESSION_TYPE)
423                 g_print("*** input session type(0:MEDIA, 1:ALARM, 2:NOTIFICATION, 3:EMERGENCY, 4:VOIP)\n");
424         else if (g_menu_state == CURRENT_STATUS_GET_SESSION_TYPE)
425                 g_print("*** press enter to get session type\n");
426         else if (g_menu_state == CURRENT_STATUS_SET_MEDIA_SESSION_OPTION) {
427                 if (flag == 0)
428                         g_print("*** input starting option, and ongoing(for starting(0:MIX WITH OTHERS, 1:PAUSE OTHERS), for ongoing(0:INTERRUPTABLE, 1:UNINTERRUPABLE)\n");
429                 flag = 1;
430         } else if (g_menu_state == CURRENT_STATUS_GET_MEDIA_SESSION_OPTION)
431                 g_print("*** press enter to get media session option\n");
432         else if (g_menu_state == CURRENT_STATUS_SET_MEDIA_SESSION_RESUMPTION_OPTION)
433                 g_print("*** input media session resumption option(0:BY SYSTEM, 1:OR MEDIA PAUSE)\n");
434         else if (g_menu_state == CURRENT_STATUS_GET_MEDIA_SESSION_RESUMPTION_OPTION)
435                 g_print("*** press enter to get media session resumption option\n");
436         else if (g_menu_state == CURRENT_STATUS_SET_VOIP_SESSION_MODE)
437                 g_print("*** input voip session mode (0:RINGTONE, 1:VOICE with RCV, 2:VOICE with SPK, 3:VOICE with AudioJack, 4:VOICE with BT)\n");
438         else if (g_menu_state == CURRENT_STATUS_GET_VOIP_SESSION_MODE)
439                 g_print("*** press enter to get voip session mode\n");
440         else if (g_menu_state == CURRENT_STATUS_SET_CALL_SESSION_MODE)
441                 g_print("*** input call session mode (0:RINGTONE, 1:VOICE with RCV, 2:VOICE with SPK, 3:VOICE with AudioJack, 4:VOICE with BT)\n");
442         else if (g_menu_state == CURRENT_STATUS_GET_CALL_SESSION_MODE)
443                 g_print("*** press enter to get call session mode\n");
444         else if (g_menu_state == CURRENT_STATUS_SET_SESSION_INTERRUPTED_CB)
445                 g_print("*** press enter to set session interrupted cb\n");
446         else if (g_menu_state == CURRENT_STATUS_UNSET_SESSION_INTERRUPTED_CB)
447                 g_print("*** press enter to unset session interrupted cb\n");
448         else if (g_menu_state == CURRENT_STATUS_SET_DEVICE_MASK)
449                 g_print("*** input device mask (0:ALL, 1:INTERNAL, 2:EXTERNAL, 3:INPUT, 4:OUTPUT, 5:BOTH, 6:ACTIVATED, 7:DEACTIVATED, b:back to the menu\n");
450         else if (g_menu_state == CURRENT_STATUS_GET_DEVICE_MASK)
451                 g_print("*** press enter to get device mask\n");
452         else if (g_menu_state == CURRENT_STATUS_GET_CURRENT_DEVICE_LIST)
453                 g_print("*** press enter to get current device list\n");
454         else if (g_menu_state == CURRENT_STATUS_GET_DEVICE_LIST)
455                 g_print("*** press enter to get device list\n");
456         else if (g_menu_state == CURRENT_STATUS_PRINT_DEVICE_LIST)
457                 g_print("*** press enter to print device list\n");
458         else if (g_menu_state == CURRENT_STATUS_FREE_DEVICE_LIST)
459                 g_print("*** press enter to free device list\n");
460         else if (g_menu_state == CURRENT_STATUS_GET_DEVICE_NEXT)
461                 g_print("*** press enter to get next device from the list\n");
462         else if (g_menu_state == CURRENT_STATUS_GET_DEVICE_PREV)
463                 g_print("*** press enter to get previous device from the list\n");
464         else if (g_menu_state == CURRENT_STATUS_SET_DEVICE_CONNECTED_CB)
465                 g_print("*** press enter to set device connected cb\n");
466         else if (g_menu_state == CURRENT_STATUS_UNSET_DEVICE_CONNECTED_CB)
467                 g_print("*** press enter to unset device connected cb\n");
468         else if (g_menu_state == CURRENT_STATUS_ADD_DEVICE_CONNECTION_CHANGED_CB)
469                 g_print("*** press enter to add device connected cb\n");
470         else if (g_menu_state == CURRENT_STATUS_REMOVE_DEVICE_CONNECTION_CHANGED_CB)
471                 g_print("*** press enter to remove device connected cb\n");
472         else if (g_menu_state == CURRENT_STATUS_SET_DEVICE_INFO_CHANGED_CB)
473                 g_print("*** press enter to set device information changed cb\n");
474         else if (g_menu_state == CURRENT_STATUS_UNSET_DEVICE_INFO_CHANGED_CB)
475                 g_print("*** press enter to unset device information changed cb\n");
476         else if (g_menu_state == CURRENT_STATUS_ADD_DEVICE_STATE_CHANGED_CB)
477                 g_print("*** press enter to add device state changed cb\n");
478         else if (g_menu_state == CURRENT_STATUS_REMOVE_DEVICE_STATE_CHANGED_CB)
479                 g_print("*** press enter to remove device state changed cb\n");
480         else if (g_menu_state == CURRENT_STATUS_CREATE_STREAM_INFO)
481                 g_print("*** input stream type to create stream information\n(0:media, 1:system, 2:alarm, 3:notification, 4:emergency, 5:ringtone-call, 6:voice-call, 7:voip, 8:media-ext-only, 9:loopback, 10:solo, 11:radio)\n");
482         else if (g_menu_state == CURRENT_STATUS_ADD_DEVICE_FOR_STREAM_ROUTING)
483                 g_print("*** input device type to add (0:built-in mic, 1:built-in spk, 2:built-in rcv, 3:audio-jack, 4:bt-a2dp, 5:bt-sco 6:usb)\n");
484         else if (g_menu_state == CURRENT_STATUS_REMOVE_DEVICE_FOR_STREAM_ROUTING)
485                 g_print("*** input device type to remove (0:built-in mic, 1:built-in spk, 2:built-in rcv, 3:audio-jack, 4:bt-a2dp, 5:bt-sco 6:usb)\n");
486         else if (g_menu_state == CURRENT_STATUS_REMOVE_ALL_DEVICES_FOR_STREAM_ROUTING)
487                 g_print("*** press enter to remove all devices in stream info\n");
488         else if (g_menu_state == CURRENT_STATUS_ADD_DEVICE_ID_FOR_STREAM_ROUTING)
489                 g_print("*** input device type to add (0:built-in mic, 1:built-in spk, 2:built-in rcv, 3:audio-jack, 4:bt-a2dp, 5:bt-sco 6:usb)\n");
490         else if (g_menu_state == CURRENT_STATUS_REMOVE_DEVICE_ID_FOR_STREAM_ROUTING)
491                 g_print("*** input device type to remove (0:built-in mic, 1:built-in spk, 2:built-in rcv, 3:audio-jack, 4:bt-a2dp, 5:bt-sco 6:usb)\n");
492         else if (g_menu_state == CURRENT_STATUS_APPLY_STREAM_ROUTING)
493                 g_print("*** press enter to apply devices for stream routing\n");
494         else if (g_menu_state == CURRENT_STATUS_SET_STREAM_ROUTING_OPTION)
495                 g_print("*** input option(name/value) for routing (0:option_1/0, 1:option_1/1, 2:option_2/0, 3:option_2:1)\n");
496         else if (g_menu_state == CURRENT_STATUS_ACQUIRE_FOCUS)
497                 g_print("*** input focus type to acquire (0:playback, 1:recording, 2:both, 3:both+noResume, 4:both+fading)\n");
498         else if (g_menu_state == CURRENT_STATUS_RELEASE_FOCUS)
499                 g_print("*** input focus type to release (0:playback, 1:recording, 2:both, 3:both+noResume, 4:both+fading)\n");
500         else if (g_menu_state == CURRENT_STATUS_ACQUIRE_FOCUS_ALL)
501                 g_print("*** input behavior for acquire all (0:without behavior, 1:with noResume, 2:with fading)\n");
502         else if (g_menu_state == CURRENT_STATUS_RELEASE_FOCUS_ALL)
503                 g_print("*** input behavior for release all (0:without behavior, 1:with noResume, 2:with fading)\n");
504         else if (g_menu_state == CURRENT_STATUS_DELIVER_FOCUS)
505                 g_print("*** input focus type to deliver (0:playback, 1:recording, 2:both)\n");
506         else if (g_menu_state == CURRENT_STATUS_GET_ACQUIRED_FOCUS)
507                 g_print("*** press enter to get focus state\n");
508         else if (g_menu_state == CURRENT_STATUS_GET_SOUND_TYPE)
509                 g_print("*** press enter to get sound type\n");
510         else if (g_menu_state == CURRENT_STATUS_DESTROY_STREAM_INFO)
511                 g_print("*** press enter to destroy stream information\n");
512         else if (g_menu_state == CURRENT_STATUS_ADD_FOCUS_WATCH_CB)
513                 g_print("*** input focus type to watch for (0:playback, 1:recording, 2:both)\n");
514         else if (g_menu_state == CURRENT_STATUS_REMOVE_FOCUS_WATCH_CB)
515                 g_print("*** input focus watch callback id to remove\n");
516         else if (g_menu_state == CURRENT_STATUS_SET_FOCUS_REACQUISITION)
517                 g_print("*** input focus reacquisition property (1:enable, 2:disable)\n");
518         else if (g_menu_state == CURRENT_STATUS_GET_FOCUS_REACQUISITION)
519                 g_print("*** press enter to get focus reacquisition property\n");
520         else if (g_menu_state == CURRENT_STATUS_GET_REASON_FOR_P_FOCUS)
521                 g_print("*** press enter to get reason for current playback focus\n");
522         else if (g_menu_state == CURRENT_STATUS_GET_REASON_FOR_R_FOCUS)
523                 g_print("*** press enter to get reason for current recording focus\n");
524         else if (g_menu_state == CURRENT_STATUS_GET_CURRENT_MEDIA_PLAYBACK_DEVICE_TYPE)
525                 g_print("*** press enter to get current_media_playback_device type\n");
526         else if (g_menu_state == CURRENT_STATUS_CREATE_VIRTUAL_STREAM)
527                 g_print("*** press enter to create virtual stream\n");
528         else if (g_menu_state == CURRENT_STATUS_START_VIRTUAL_STREAM)
529                 g_print("*** press enter to start virtual stream\n");
530         else if (g_menu_state == CURRENT_STATUS_STOP_VIRTUAL_STREAM)
531                 g_print("*** press enter to stop virtual stream\n");
532         else if (g_menu_state == CURRENT_STATUS_DESTROY_VIRTUAL_STREAM)
533                 g_print("*** press enter to destroy virtual stream\n");
534         else if (g_menu_state == CURRENT_STATUS_SET_FILTER)
535                 g_print("*** input filter type of media stream (0:LOW_PASS 1:HIGH_PASS 2:DELAY 3:SOUNDALIVE)\n");
536         else if (g_menu_state == CURRENT_STATUS_SET_FILTER_PRESET)
537                 g_print("*** input filter preset of media stream (LOW_PASS(1:none 2:240hz 3:480hz), HIGH_PASS(3:none 4:240hz 5:480hz) DELAY(6:none 7:1sec 8:2sec) SOUNDALIVE(9:normal 10:concert_hall))\n");
538         else if (g_menu_state == CURRENT_STATUS_UNSET_FILTER)
539                 g_print("*** press enter to unset filter of media stream\n");
540 #ifndef TIZEN_FEATURE_TV_PROD
541         else if (g_menu_state == CURRENT_STATUS_GET_MAX_MASTER_VOLUME)
542                 g_print("*** press enter to get max master volume level\n");
543         else if (g_menu_state == CURRENT_STATUS_SET_MASTER_VOLUME)
544                 g_print("*** input master volume level\n");
545         else if (g_menu_state == CURRENT_STATUS_GET_MASTER_VOLUME)
546                 g_print("*** press enter to get master volume level\n");
547 #endif
548         else {
549                 g_print("*** unknown status.\n");
550                 quit_program();
551         }
552         g_print(" >>> ");
553 }
554
555 gboolean timeout_menu_display(void* data)
556 {
557         displaymenu();
558         return FALSE;
559 }
560
561 int convert_sound_type(sound_type_e *type, char *cmd)
562 {
563         int sound_type_n = atoi(cmd);
564         if (SOUND_TYPE_SYSTEM > sound_type_n || sound_type_n > SOUND_TYPE_VOICE) {
565                 g_print("not supported sound type(%d)\n", sound_type_n);
566                 return 0;
567         } else {
568                 switch (sound_type_n) {
569                 case 0:
570                         *type = SOUND_TYPE_SYSTEM;
571                         break;
572                 case 1:
573                         *type = SOUND_TYPE_NOTIFICATION;
574                         break;
575                 case 2:
576                         *type = SOUND_TYPE_ALARM;
577                         break;
578                 case 3:
579                         *type = SOUND_TYPE_RINGTONE;
580                         break;
581                 case 4:
582                         *type = SOUND_TYPE_MEDIA;
583                         break;
584                 case 5:
585                         *type = SOUND_TYPE_CALL;
586                         break;
587                 case 6:
588                         *type = SOUND_TYPE_VOIP;
589                         break;
590                 case 7:
591                         *type = SOUND_TYPE_VOICE;
592                         break;
593                 }
594         }
595         return 1;
596 }
597
598 int convert_session_type(sound_session_type_e *type, char *cmd)
599 {
600         int session_type_n = atoi(cmd);
601         if (SOUND_SESSION_TYPE_MEDIA > session_type_n || session_type_n > SOUND_SESSION_TYPE_VOIP) {
602                 g_print("not supported session type(%d)\n", session_type_n);
603                 return 0;
604         } else {
605                 switch (session_type_n) {
606                 case 0:
607                         *type = SOUND_SESSION_TYPE_MEDIA;
608                         break;
609                 case 1:
610                         *type = SOUND_SESSION_TYPE_ALARM;
611                         break;
612                 case 2:
613                         *type = SOUND_SESSION_TYPE_NOTIFICATION;
614                         break;
615                 case 3:
616                         *type = SOUND_SESSION_TYPE_EMERGENCY;
617                         break;
618                 case 4:
619                         *type = SOUND_SESSION_TYPE_VOIP;
620                         break;
621                 }
622         }
623         return 1;
624 }
625
626 void _set_volume_changed_cb(sound_type_e type, unsigned int volume, void *user_data)
627 {
628         g_print("***the volume has changed. the volume of this sound type(%d) is : %d \n", type, volume);
629 }
630
631 void _set_session_interrupted_cb(sound_session_interrupted_code_e code, void *user_data)
632 {
633         g_print("***your session has been interrupted by (%d)\n", code);
634 }
635
636 /* If failed to get some property, just give some default value */
637 void _get_device_props_simple(sound_device_h device, int *id, char **type, char **name,
638                 const char **direc, const char **state, int *vendor_id, int *product_id)
639 {
640         int ret;
641         sound_device_type_e _type;
642         sound_device_io_direction_e _direc;
643         sound_device_state_e _state;
644
645         *id = -1;
646         *vendor_id = -1;
647         *product_id = -1;
648
649         if ((ret = sound_manager_get_device_type(device, &_type)))
650                 g_print("failed to get device type, ret[0x%x]\n",  ret);
651         else
652                 _convert_device_type_enum_to_str(_type, type);
653
654         if ((ret = sound_manager_get_device_id(device, id)))
655                 g_print("failed to get device id, ret[0x%x]\n", ret);
656
657         if (_type == SOUND_DEVICE_BLUETOOTH_MEDIA || _type == SOUND_DEVICE_BLUETOOTH_VOICE || _type == SOUND_DEVICE_USB_AUDIO) {
658                 if ((ret = sound_manager_get_device_name(device, name))) {
659                         g_print("failed to get device name, ret[0x%x]\n", ret);
660                         *name = NOT_AVAIL;
661                 }
662                 if (_type == SOUND_DEVICE_USB_AUDIO) {
663                         if ((ret = sound_manager_get_device_vendor_id(device, vendor_id)))
664                                 g_print("failed to get device vendor id, ret[0x%x]\n", ret);
665                         if ((ret = sound_manager_get_device_product_id(device, product_id)))
666                                 g_print("failed to get device product id, ret[0x%x]\n", ret);
667                 }
668         } else {
669                 *name = "";
670         }
671
672         if ((ret = sound_manager_get_device_io_direction(device, &_direc))) {
673                 g_print("failed to get device io direction, ret[0x%x]\n", ret);
674                 *direc = NOT_AVAIL;
675         } else {
676                 *direc = g_device_direction_str[_direc];
677         }
678
679         if ((ret = sound_manager_get_device_state(device, &_state))) {
680                 g_print("failed to get device state, ret[0x%x]\n", ret);
681                 *state = NOT_AVAIL;
682         } else {
683                 *state = g_device_state_str[_state];
684         }
685 }
686
687 void _set_device_connected_cb(sound_device_h device, bool is_connected, void *user_data)
688 {
689         int id = -1;
690         int vendor_id = -1;
691         int product_id = -1;
692         char *type, *name;
693         const char *direc, *state;
694
695         _get_device_props_simple(device, &id, &type, &name, &direc, &state, &vendor_id, &product_id);
696
697         g_print("[ Device #%d %s %s ] %s\n", id, type, name, is_connected ? "Connected" : "Disconnected");
698         g_print("    Direc[ %-4s ] State[ %-12s ] VendorID[ %04x ], ProductID[ %04x ]\n", direc, state, vendor_id, product_id);
699 }
700
701 void _set_device_info_changed_cb(sound_device_h device, sound_device_changed_info_e changed_info, void *user_data)
702 {
703
704         int id = -1;
705         int vendor_id = -1;
706         int product_id = -1;
707         char *type, *name;
708         const char *direc, *state;
709         const char *changed_info_str[] = {"State", "Direction", "Avail-Mode"};
710
711         _get_device_props_simple(device, &id, &type, &name, &direc, &state, &vendor_id, &product_id);
712
713         g_print("[Device #%d %s %s] %s changed\n", id, type, name, changed_info_str[changed_info]);
714         g_print("    Direc[ %-4s ] State[ %-12s ] VendorID[ %04x ], ProductID[ %04x ]\n", direc, state, vendor_id, product_id);
715 }
716
717 void _device_state_changed_cb(sound_device_h device, sound_device_state_e state, void *user_data)
718 {
719         int id = -1;
720         int vendor_id = -1;
721         int product_id = -1;
722         char *type, *name;
723         const char *direc, *_state;
724
725         _get_device_props_simple(device, &id, &type, &name, &direc, &_state, &vendor_id, &product_id);
726
727         g_print("[Device #%d %s %s] state changed\n", id, type, name);
728         g_print("    Direc[ %-4s ] State(%d)[ %-12s ] VendorID[ %04x ], ProductID[ %04x ]\n", direc, state, _state, vendor_id, product_id);
729 }
730
731 void reset_menu_state(void)
732 {
733         g_menu_state = CURRENT_STATUS_MAINMENU;
734 }
735
736 static void interpret(char *cmd)
737 {
738         switch (g_menu_state) {
739         case CURRENT_STATUS_MAINMENU:
740                 _interpret_main_menu(cmd);
741                 break;
742         case CURRENT_STATUS_GET_MAX_VOLUME: {
743                 sound_type_e type;
744                 int max;
745                 if (convert_sound_type(&type, cmd) == 1) {
746                         if (sound_manager_get_max_volume(type, &max) != SOUND_MANAGER_ERROR_NONE)
747                                 g_print("failt to get max volume\n");
748                         else
749                                 g_print("the max volume of this type(%d) is %d\n", type, max);
750                 }
751                 reset_menu_state();
752                 break;
753         }
754         case CURRENT_STATUS_SET_VOLUME: {
755                 static int cnt = 0;
756                 static sound_type_e type;
757                 int volume;
758                 switch (cnt) {
759                 case 0:
760                         if (convert_sound_type(&type, cmd) == 1)
761                                 cnt++;
762                         else
763                                 reset_menu_state();
764                         break;
765                 case 1:
766                         volume = atoi(cmd);
767                         if (sound_manager_set_volume(type, volume) != SOUND_MANAGER_ERROR_NONE)
768                                 g_print("fail to set volume(%d) check sound type(%d)'s available volume level\n", volume, type);
769                         else
770                                 g_print("set volume success : sound type(%d), volume(%d)\n", type, volume);
771                         cnt = 0;
772                         reset_menu_state();
773                         break;
774                 default:
775                         break;
776                 }
777                 break;
778         }
779         case CURRENT_STATUS_GET_VOLUME: {
780                 sound_type_e type;
781                 int volume;
782                 if (convert_sound_type(&type, cmd) == 1) {
783                         if (sound_manager_get_volume(type, &volume) != SOUND_MANAGER_ERROR_NONE)
784                                 g_print("fail to get volume\n");
785                         else
786                                 g_print("current volume of this type(%d) is : %d\n", type, volume);
787                 }
788                 reset_menu_state();
789                 break;
790         }
791         case CURRENT_STATUS_SET_CURRENT_SOUND_TYPE: {
792                 sound_type_e type;
793                 if (convert_sound_type(&type, cmd) == 1) {
794                         if (sound_manager_set_current_sound_type(type) != SOUND_MANAGER_ERROR_NONE)
795                                 g_print("fail to set sound type(%d)\n", type);
796                         else
797                                 g_print("success to set sound type(%d)\n", type);
798                 }
799                 reset_menu_state();
800                 break;
801         }
802         case CURRENT_STATUS_GET_CURRENT_SOUND_TYPE: {
803                 sound_type_e type;
804                 if (sound_manager_get_current_sound_type(&type) != SOUND_MANAGER_ERROR_NONE)
805                         g_print("fail to get current sound type\n");
806                 else
807                         g_print("current sound type is (%d)\n", type);
808                 reset_menu_state();
809                 break;
810         }
811         case CURRENT_STATUS_UNSET_CURRENT_SOUND_TYPE: {
812                 if (sound_manager_unset_current_sound_type() != SOUND_MANAGER_ERROR_NONE)
813                         g_print("fail to unset current sound type\n");
814                 else
815                         g_print("success to unset current sound type\n");
816                 reset_menu_state();
817                 break;
818         }
819         case CURRENT_STATUS_SET_VOLUME_CHANGED_CB: {
820                 if (sound_manager_set_volume_changed_cb(_set_volume_changed_cb, NULL) != SOUND_MANAGER_ERROR_NONE)
821                         g_print("fail to set volume changed cb\n");
822                 else
823                         g_print("success to set volume changed cb\n");
824                 reset_menu_state();
825                 break;
826         }
827         case CURRENT_STATUS_UNSET_VOLUME_CHANGED_CB: {
828                 if (sound_manager_unset_volume_changed_cb() != SOUND_MANAGER_ERROR_NONE)
829                         g_print("fail to unset volume changed cb\n");
830                 else
831                         g_print("success to unset volume changed cb\n");
832                 reset_menu_state();
833                 break;
834         }
835         case CURRENT_STATUS_SET_SESSION_TYPE: {
836                 sound_session_type_e type;
837                 if (convert_session_type(&type, cmd) == 1) {
838                         if (sound_manager_set_session_type(type) != SOUND_MANAGER_ERROR_NONE)
839                                 g_print("fail to set session type\n");
840                         else
841                                 g_print("success to set session type(%d)\n", type);
842                 }
843                 reset_menu_state();
844                 break;
845         }
846         case CURRENT_STATUS_GET_SESSION_TYPE: {
847                 sound_session_type_e type;
848                 if (sound_manager_get_session_type(&type) != SOUND_MANAGER_ERROR_NONE)
849                         g_print("fail to get session type\n");
850                 else
851                         g_print("current session type is : %d (0:MEDIA, 1:ALARM, 2:NOTIFICATION, 3:EMERGENCY, 4:VOIP, 5:CALL)\n", type);
852                 reset_menu_state();
853                 break;
854         }
855         case CURRENT_STATUS_SET_MEDIA_SESSION_OPTION: {
856                 sound_session_type_e type = SOUND_SESSION_TYPE_MEDIA;
857                 static sound_session_option_for_starting_e option_s;
858                 static sound_session_option_for_during_play_e option_d;
859                 static int cnt = 0;
860                 if (sound_manager_set_session_type(type) != SOUND_MANAGER_ERROR_NONE) {
861                         g_print("fail to set media session type\n");
862                         reset_menu_state();
863                 } else {
864                         switch (cnt) {
865                         case 0:
866                                 option_s = (sound_session_option_for_starting_e)atoi(cmd);
867                                 if (SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START < option_s)
868                                         g_print("not supported option type\n");
869                                 else
870                                         cnt++;
871                                 break;
872                         case 1:
873                                 option_d = (sound_session_option_for_during_play_e)atoi(cmd);
874                                 if (SOUND_SESSION_OPTION_UNINTERRUPTIBLE_DURING_PLAY < option_d)
875                                         g_print("not supported option type\n");
876                                 else {
877                                         if (sound_manager_set_media_session_option(option_s, option_d) != SOUND_MANAGER_ERROR_NONE)
878                                                 g_print("fail to set media session option\n");
879                                         else
880                                                 g_print("success to set media session option\n");
881                                         cnt = 0;
882                                 }
883                                 reset_menu_state();
884                                 break;
885                         default:
886                                 break;
887                         }
888                 }
889                 break;
890         }
891         case CURRENT_STATUS_GET_MEDIA_SESSION_OPTION: {
892                 sound_session_type_e type = SOUND_SESSION_TYPE_MEDIA;
893                 sound_session_option_for_starting_e option_s;
894                 sound_session_option_for_during_play_e option_d;
895                 if (sound_manager_set_session_type(type) != SOUND_MANAGER_ERROR_NONE)
896                         g_print("fail to set media session type\n");
897                 else {
898                         if (sound_manager_get_media_session_option(&option_s, &option_d) != SOUND_MANAGER_ERROR_NONE)
899                                 g_print("fail to get media session option\n");
900                         else
901                                 g_print("current media session options are (%d) for starting, (%d) for ongoing\n", option_s, option_d);
902                 }
903                 reset_menu_state();
904                 break;
905         }
906         case CURRENT_STATUS_SET_MEDIA_SESSION_RESUMPTION_OPTION: {
907                 sound_session_type_e type = SOUND_SESSION_TYPE_MEDIA;
908                 sound_session_option_for_resumption_e option_r;
909                 if (sound_manager_set_session_type(type) != SOUND_MANAGER_ERROR_NONE)
910                         g_print("fail to set media session type\n");
911                 else {
912                         option_r = (sound_session_option_for_resumption_e)atoi(cmd);
913                         if (SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM_OR_MEDIA_PAUSED < option_r)
914                                 g_print("not supported option type\n");
915                         else {
916                                 if (sound_manager_set_media_session_resumption_option(option_r) != SOUND_MANAGER_ERROR_NONE)
917                                         g_print("fail to set media session resumption option\n");
918                                 else
919                                         g_print("succese to set media session resumption option\n");
920                         }
921                 }
922                 reset_menu_state();
923                 break;
924         }
925         case CURRENT_STATUS_GET_MEDIA_SESSION_RESUMPTION_OPTION: {
926                 sound_session_type_e type = SOUND_SESSION_TYPE_MEDIA;
927                 sound_session_option_for_resumption_e option_r;
928                 if (sound_manager_set_session_type(type) != SOUND_MANAGER_ERROR_NONE)
929                         g_print("fail to set media session type\n");
930                 else {
931                         if (sound_manager_get_media_session_resumption_option(&option_r) != SOUND_MANAGER_ERROR_NONE)
932                                 g_print("fail to get media session resumption option\n");
933                         else
934                                 g_print("current media session resumption option is : %d\n", option_r);
935                 }
936                 reset_menu_state();
937                 break;
938         }
939         case CURRENT_STATUS_SET_VOIP_SESSION_MODE: {
940                 int ret = SOUND_MANAGER_ERROR_NONE;
941                 sound_session_voip_mode_e mode;
942                 mode = (sound_session_voip_mode_e)atoi(cmd);
943                 ret = sound_manager_set_voip_session_mode(mode);
944                 if (ret)
945                         g_print("failed to set voip session mode(%d), ret[0x%x]\n", mode, ret);
946                 else
947                         g_print("success to set voip session mode\n");
948                 reset_menu_state();
949                 break;
950         }
951         case CURRENT_STATUS_GET_VOIP_SESSION_MODE: {
952                 int ret = SOUND_MANAGER_ERROR_NONE;
953                 sound_session_voip_mode_e mode;
954                 ret = sound_manager_get_voip_session_mode(&mode);
955                 if (ret)
956                         g_print("fail to get voip session mode, ret[0x%x]\n", ret);
957                 else
958                         g_print("success to get voip session mode, mode[%d]\n", mode);
959                 reset_menu_state();
960                 break;
961         }
962         case CURRENT_STATUS_SET_SESSION_INTERRUPTED_CB: {
963                 if (sound_manager_set_session_interrupted_cb(_set_session_interrupted_cb, NULL) != SOUND_MANAGER_ERROR_NONE)
964                         g_print("fail to set interrupted changed cb\n");
965                 else
966                         g_print("success to set interrupted changed cb\n");
967                 reset_menu_state();
968                 break;
969         }
970         case CURRENT_STATUS_UNSET_SESSION_INTERRUPTED_CB: {
971                 if (sound_manager_unset_session_interrupted_cb() != 0)
972                         g_print("fail to unset interrupted changed cb\n");
973                 else
974                         g_print("success to unset interrupted changed cb\n");
975                 reset_menu_state();
976                 break;
977         }
978         case CURRENT_STATUS_SET_DEVICE_MASK: {
979                 if (strncmp(cmd, "0", 1) == 0) {
980                                 g_device_mask = SOUND_DEVICE_ALL_MASK;
981                                 reset_menu_state();
982                 } else if (strncmp(cmd, "1", 1) == 0) {
983                         if (g_device_mask == SOUND_DEVICE_ALL_MASK)
984                                 g_device_mask = SOUND_DEVICE_TYPE_INTERNAL_MASK;
985                         else
986                                 g_device_mask |= SOUND_DEVICE_TYPE_INTERNAL_MASK;
987                         g_print("add TYPE_INTERNAL MASK\n");
988                 } else if (strncmp(cmd, "2", 1) == 0) {
989                         if (g_device_mask == SOUND_DEVICE_ALL_MASK)
990                                 g_device_mask = SOUND_DEVICE_TYPE_EXTERNAL_MASK;
991                         else
992                                 g_device_mask |= SOUND_DEVICE_TYPE_EXTERNAL_MASK;
993                         g_print("add TYPE_EXTERNAL MASK\n");
994                 } else if (strncmp(cmd, "3", 1) == 0) {
995                         if (g_device_mask == SOUND_DEVICE_ALL_MASK)
996                                 g_device_mask = SOUND_DEVICE_IO_DIRECTION_IN_MASK;
997                         else
998                                 g_device_mask |= SOUND_DEVICE_IO_DIRECTION_IN_MASK;
999                         g_print("add IO_DIRECTION_IN MASK\n");
1000                 } else if (strncmp(cmd, "4", 1) == 0) {
1001                         if (g_device_mask == SOUND_DEVICE_ALL_MASK)
1002                                 g_device_mask = SOUND_DEVICE_IO_DIRECTION_OUT_MASK;
1003                         else
1004                                 g_device_mask |= SOUND_DEVICE_IO_DIRECTION_OUT_MASK;
1005                         g_print("add IO_DIRECTION_OUT MASK\n");
1006                 } else if (strncmp(cmd, "5", 1) == 0) {
1007                         if (g_device_mask == SOUND_DEVICE_ALL_MASK)
1008                                 g_device_mask = SOUND_DEVICE_IO_DIRECTION_BOTH_MASK;
1009                         else
1010                                 g_device_mask |= SOUND_DEVICE_IO_DIRECTION_BOTH_MASK;
1011                         g_print("add IO_DIRECTION_BOTH MASK\n");
1012                 } else if (strncmp(cmd, "6", 1) == 0) {
1013                         if (g_device_mask == SOUND_DEVICE_ALL_MASK)
1014                                 g_device_mask = SOUND_DEVICE_STATE_ACTIVATED_MASK;
1015                         else
1016                                 g_device_mask |= SOUND_DEVICE_STATE_ACTIVATED_MASK;
1017                         g_print("add STATE_ACTIVATED MASK\n");
1018                 } else if (strncmp(cmd, "7", 1) == 0) {
1019                         if (g_device_mask == SOUND_DEVICE_ALL_MASK)
1020                                 g_device_mask = SOUND_DEVICE_STATE_DEACTIVATED_MASK;
1021                         else
1022                                 g_device_mask |= SOUND_DEVICE_STATE_DEACTIVATED_MASK;
1023                         g_print("add STATE_DEACTIVATED MASK\n");
1024                 } else if (strncmp(cmd, "b", 1) == 0) {
1025                         g_print("device mask[0x%x]\n", g_device_mask);
1026                         reset_menu_state();
1027                 } else {
1028                         g_print("invalid selection, please select again..\n");
1029                 }
1030                 break;
1031         }
1032         case CURRENT_STATUS_GET_DEVICE_MASK: {
1033                 g_print("current device mask[0x%x]\n", g_device_mask);
1034                 reset_menu_state();
1035                 break;
1036         }
1037         case CURRENT_STATUS_GET_CURRENT_DEVICE_LIST: {
1038                 int ret = SOUND_MANAGER_ERROR_NONE;
1039                 if (!(ret = sound_manager_get_current_device_list(g_device_mask, &g_device_list)))
1040                         g_print("success to get current device list\n");
1041                 else
1042                         g_print("fail to get current device list, ret[0x%x]\n", ret);
1043                 reset_menu_state();
1044                 break;
1045         }
1046         case CURRENT_STATUS_GET_DEVICE_LIST: {
1047                 int ret = SOUND_MANAGER_ERROR_NONE;
1048                 if (!(ret = sound_manager_get_device_list(g_device_mask, &g_device_list)))
1049                         g_print("success to get device list\n");
1050                 else
1051                         g_print("fail to get device list, ret[0x%x]\n", ret);
1052                 reset_menu_state();
1053                 break;
1054         }
1055         case CURRENT_STATUS_PRINT_DEVICE_LIST: {
1056                 sound_device_list_h device_list;
1057                 sound_device_h device;
1058                 int ret = SOUND_MANAGER_ERROR_NONE;
1059                 int id = -1;
1060                 int vendor_id = -1;
1061                 int product_id = -1;
1062                 char *type;
1063                 char *name;
1064                 const char *direc;
1065                 const char *state;
1066                 if (!(ret = sound_manager_get_device_list(g_device_mask, &device_list))) {
1067                         g_print("success to get current device list\n");
1068                         while (!sound_manager_get_next_device(device_list, &device)) {
1069                                 _get_device_props_simple(device, &id, &type, &name, &direc, &state, &vendor_id, &product_id);
1070                                 g_print("[ Device #%d %s %s ]\n", id, type, name);
1071                                 g_print("    Direc[ %-4s ] State[ %-12s ] VendorID[ %04x ], ProductID[ %04x ]\n", direc, state, vendor_id, product_id);
1072                         }
1073                 } else {
1074                         g_print("fail to get current device list, ret[0x%x]\n", ret);
1075                 }
1076                 reset_menu_state();
1077                 break;
1078         }
1079         case CURRENT_STATUS_FREE_DEVICE_LIST: {
1080                 int ret = SOUND_MANAGER_ERROR_NONE;
1081                 if (!(ret = sound_manager_free_device_list(g_device_list))) {
1082                         g_print("success to free device list\n");
1083                         g_device_list = NULL;
1084                         g_print("device list freed\n");
1085                 } else {
1086                         g_print("fail to free device list, ret[0x%x]\n", ret);
1087                 }
1088                 reset_menu_state();
1089                 break;
1090         }
1091         case CURRENT_STATUS_GET_DEVICE_NEXT: {
1092                 sound_device_h device;
1093                 sound_device_type_e type;
1094                 sound_device_io_direction_e io_direction;
1095                 sound_device_state_e state;
1096                 int id;
1097                 char *name;
1098                 int ret = SOUND_MANAGER_ERROR_NONE;
1099                 if (!(ret = sound_manager_get_next_device(g_device_list, &device))) {
1100                         g_print("success to get next device\n");
1101                         if ((ret = sound_manager_get_device_type(device, &type)))
1102                                 g_print("failed to get device type, ret[0x%x]\n", ret);
1103                         if ((ret = sound_manager_get_device_io_direction(device, &io_direction)))
1104                                 g_print("failed to get device io direction, ret[0x%x]\n", ret);
1105                         if ((ret = sound_manager_get_device_id(device, &id)))
1106                                 g_print("failed to get device id, ret[0x%x]\n", ret);
1107                         if ((ret = sound_manager_get_device_name(device, &name)))
1108                                 g_print("failed to get device name, ret[0x%x]\n", ret);
1109                         if ((ret = sound_manager_get_device_state(device, &state)))
1110                                 g_print("failed to get device state, ret[0x%x]\n", ret);
1111                         if (!ret)
1112                                 g_print("-- NEXT device type[%d], io_direction[%d], id[%d], name[%s], state[%d]\n", type, io_direction, id, name, state);
1113                 } else {
1114                         g_print("failed to get next device, ret[0x%x]\n", ret);
1115                 }
1116                 reset_menu_state();
1117                 break;
1118         }
1119         case CURRENT_STATUS_GET_DEVICE_PREV: {
1120                 sound_device_h device;
1121                 sound_device_type_e type;
1122                 sound_device_io_direction_e io_direction;
1123                 sound_device_state_e state;
1124                 int id;
1125                 char *name;
1126                 int ret = SOUND_MANAGER_ERROR_NONE;
1127                 if (!(ret = sound_manager_get_prev_device(g_device_list, &device))) {
1128                         g_print("success to get previous device\n");
1129                         if ((ret = sound_manager_get_device_type(device, &type)))
1130                                 g_print("failed to get device type, ret[0x%x]\n", ret);
1131                         if ((ret = sound_manager_get_device_io_direction(device, &io_direction)))
1132                                 g_print("failed to get device io direction, ret[0x%x]\n", ret);
1133                         if ((ret = sound_manager_get_device_id(device, &id)))
1134                                 g_print("failed to get device id, ret[0x%x]\n", ret);
1135                         if ((ret = sound_manager_get_device_name(device, &name)))
1136                                 g_print("failed to get device name, ret[0x%x]\n", ret);
1137                         if ((ret = sound_manager_get_device_state(device, &state)))
1138                                 g_print("failed to get device state, ret[0x%x]\n", ret);
1139                         if (!ret)
1140                                 g_print("-- PREV device type[%d], io_direction[%d], id[%d], name[%s], state[%d]\n", type, io_direction, id, name, state);
1141                 } else {
1142                         g_print("failed to get previous device, ret[0x%x]\n", ret);
1143                 }
1144                 reset_menu_state();
1145                 break;
1146         }
1147         case CURRENT_STATUS_SET_DEVICE_CONNECTED_CB: {
1148                 if (sound_manager_set_device_connected_cb(g_device_mask, _set_device_connected_cb, NULL))
1149                         g_print("fail to set device connected cb\n");
1150                 else
1151                         g_print("success to set device connected cb\n");
1152                 reset_menu_state();
1153                 break;
1154         }
1155         case CURRENT_STATUS_UNSET_DEVICE_CONNECTED_CB: {
1156                 if (sound_manager_unset_device_connected_cb())
1157                         g_print("fail to unset device connected cb\n");
1158                 else
1159                         g_print("success to unset device connected cb\n");
1160                 reset_menu_state();
1161                 break;
1162         }
1163         case CURRENT_STATUS_ADD_DEVICE_CONNECTION_CHANGED_CB: {
1164                 if (sound_manager_add_device_connection_changed_cb(g_device_mask, _set_device_connected_cb, NULL, &g_device_conn_cb_id))
1165                         g_print("fail to add device connection changed cb\n");
1166                 else
1167                         g_print("success to add device connection changed cb\n");
1168                 reset_menu_state();
1169                 break;
1170         }
1171         case CURRENT_STATUS_REMOVE_DEVICE_CONNECTION_CHANGED_CB: {
1172                 if (sound_manager_remove_device_connection_changed_cb(g_device_conn_cb_id))
1173                         g_print("fail to remove device connection changed cb\n");
1174                 else
1175                         g_print("success to remove device connection changed cb\n");
1176                 reset_menu_state();
1177                 break;
1178         }
1179         case CURRENT_STATUS_SET_DEVICE_INFO_CHANGED_CB: {
1180                 if (sound_manager_set_device_information_changed_cb(g_device_mask, _set_device_info_changed_cb, NULL))
1181                         g_print("fail to set device information changed cb\n");
1182                 else
1183                         g_print("success to set device information changed cb\n");
1184                 reset_menu_state();
1185                 break;
1186         }
1187         case CURRENT_STATUS_UNSET_DEVICE_INFO_CHANGED_CB: {
1188                 if (sound_manager_unset_device_information_changed_cb())
1189                         g_print("fail to unset device information changed cb\n");
1190                 else
1191                         g_print("success to unset device information changed cb\n");
1192                 reset_menu_state();
1193                 break;
1194         }
1195         case CURRENT_STATUS_ADD_DEVICE_STATE_CHANGED_CB: {
1196                 if (sound_manager_add_device_state_changed_cb(g_device_mask, _device_state_changed_cb, NULL, &g_device_state_cb_id))
1197                         g_print("fail to add device state changed cb\n");
1198                 else
1199                         g_print("success to add device state changed cb\n");
1200                 reset_menu_state();
1201                 break;
1202         }
1203         case CURRENT_STATUS_REMOVE_DEVICE_STATE_CHANGED_CB: {
1204                 if (sound_manager_remove_device_state_changed_cb(g_device_state_cb_id))
1205                         g_print("fail to remove device state  changed cb\n");
1206                 else
1207                         g_print("success to remove device state changed cb\n");
1208                 reset_menu_state();
1209                 break;
1210         }
1211         case CURRENT_STATUS_CREATE_STREAM_INFO: {
1212                 int ret = SOUND_MANAGER_ERROR_NONE;
1213                 int stream_type = 0;
1214                 sound_stream_type_e type = SOUND_STREAM_TYPE_MEDIA;
1215                 if (g_stream_info_h) {
1216                         g_print("fail to create stream information, g_stream_info_h(%p) is already set\n", g_stream_info_h);
1217                         reset_menu_state();
1218                         break;
1219                 }
1220                 stream_type = atoi(cmd);
1221                 switch (stream_type) {
1222                 case 0: /* media */
1223                         type = SOUND_STREAM_TYPE_MEDIA;
1224                         break;
1225                 case 1: /* system */
1226                         type = SOUND_STREAM_TYPE_SYSTEM;
1227                         break;
1228                 case 2: /* alarm */
1229                         type = SOUND_STREAM_TYPE_ALARM;
1230                         break;
1231                 case 3: /* notification */
1232                         type = SOUND_STREAM_TYPE_NOTIFICATION;
1233                         break;
1234                 case 4: /* emergency */
1235                         type = SOUND_STREAM_TYPE_EMERGENCY;
1236                         break;
1237                 case 5: /* ringtone for call*/
1238                         type = SOUND_STREAM_TYPE_RINGTONE_CALL;
1239                         break;
1240                 case 6: /* voice call */
1241                         type = SOUND_STREAM_TYPE_VOICE_CALL;
1242                         break;
1243                 case 7: /* voip */
1244                         type = SOUND_STREAM_TYPE_VOIP;
1245                         break;
1246                 case 8: /* media only for external devices */
1247                         type = SOUND_STREAM_TYPE_MEDIA_EXTERNAL_ONLY;
1248                         break;
1249                 case 9: /* loopback */
1250                         type = SOUND_STREAM_TYPE_LOOPBACK;
1251                         break;
1252                 case 10: /* solo */
1253                         type = SOUND_STREAM_TYPE_SOLO;
1254                         break;
1255                 case 11: /* radio */
1256                         type = SOUND_STREAM_TYPE_RADIO;
1257                         break;
1258                 default:
1259                         type = SOUND_STREAM_TYPE_MEDIA;
1260                         break;
1261                 }
1262                 if (type == (int)SOUND_STREAM_TYPE_RINGTONE_CALL ||
1263                     type == (int)SOUND_STREAM_TYPE_VOICE_CALL ||
1264                     type == (int)SOUND_STREAM_TYPE_RADIO ||
1265                     type == (int)SOUND_STREAM_TYPE_LOOPBACK)
1266                         ret = sound_manager_create_stream_information_internal(type, focus_callback, NULL, &g_stream_info_h);
1267                 else if (type == (int)SOUND_STREAM_TYPE_SOLO)
1268                         ret = sound_manager_create_stream_information_internal(type, NULL, NULL, &g_stream_info_h);
1269                 else
1270                         ret = sound_manager_create_stream_information(type, focus_callback, NULL, &g_stream_info_h);
1271
1272                 if (ret)
1273                         g_print("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
1274
1275                 reset_menu_state();
1276                 break;
1277         }
1278         case CURRENT_STATUS_ADD_DEVICE_FOR_STREAM_ROUTING: {
1279                 int ret = SOUND_MANAGER_ERROR_NONE;
1280                 int device_type = 0;
1281                 sound_device_h device = NULL;
1282                 sound_device_type_e selected_type = SOUND_DEVICE_BUILTIN_SPEAKER;
1283                 sound_device_type_e type = SOUND_DEVICE_BUILTIN_SPEAKER;
1284                 bool need_to_go = false;
1285
1286                 device_type = atoi(cmd);
1287                 switch (device_type) {
1288                 case 0: /* built-in mic */
1289                         selected_type = SOUND_DEVICE_BUILTIN_MIC;
1290                         break;
1291                 case 1: /* built-in spk */
1292                         selected_type = SOUND_DEVICE_BUILTIN_SPEAKER;
1293                         break;
1294                 case 2: /* built-in rcv */
1295                         selected_type = SOUND_DEVICE_BUILTIN_RECEIVER;
1296                         break;
1297                 case 3: /* audio-jack */
1298                         selected_type = SOUND_DEVICE_AUDIO_JACK;
1299                         break;
1300                 case 4: /* bt a2dp */
1301                         selected_type = SOUND_DEVICE_BLUETOOTH_MEDIA;
1302                         break;
1303                 case 5: /* bt sco */
1304                         selected_type = SOUND_DEVICE_BLUETOOTH_VOICE;
1305                         break;
1306                 case 6: /* usb */
1307                         selected_type = SOUND_DEVICE_USB_AUDIO;
1308                         break;
1309                 default:
1310                         g_print("invalid argument, device_type(%d) is not valid for this feature\n", device_type);
1311                         reset_menu_state();
1312                         break;
1313                 }
1314                 if (!(ret = sound_manager_get_device_list(SOUND_DEVICE_ALL_MASK, &g_device_list))) {
1315                         g_print("success to get current device list\n");
1316                         while (!sound_manager_get_next_device(g_device_list, &device)) {
1317                                 if ((ret = sound_manager_get_device_type(device, &type))) {
1318                                         g_print("fail to get type of device, ret(0x%x)\n", ret);
1319                                         reset_menu_state();
1320                                         break;
1321                                 }
1322                                 if (selected_type == type) {
1323                                         need_to_go = true;
1324                                         break;
1325                                 }
1326                         }
1327                         if (need_to_go) {
1328                                 ret = sound_manager_add_device_for_stream_routing(g_stream_info_h, device);
1329                                 if (ret)
1330                                         g_print("failed to sound_manager_add_device_for_stream_routing(), ret(0x%x)\n", ret);
1331                         } else
1332                                 g_print("the device is not available now\n");
1333                         reset_menu_state();
1334
1335                         if (!(ret = sound_manager_free_device_list(g_device_list))) {
1336                                 g_print("success to free device list\n");
1337                                 g_device_list = NULL;
1338                         } else {
1339                                 g_print("fail to free device list, ret[0x%x]\n", ret);
1340                         }
1341                 } else {
1342                         g_print("fail to get current device list, ret(0x%x)\n", ret);
1343                         reset_menu_state();
1344                 }
1345                 break;
1346         }
1347         case CURRENT_STATUS_REMOVE_DEVICE_FOR_STREAM_ROUTING: {
1348                 int ret = SOUND_MANAGER_ERROR_NONE;
1349                 int device_type = 0;
1350                 sound_device_h device = NULL;
1351                 sound_device_type_e selected_type = SOUND_DEVICE_BUILTIN_SPEAKER;
1352                 sound_device_type_e type = SOUND_DEVICE_BUILTIN_SPEAKER;
1353                 bool need_to_go = false;
1354
1355                 device_type = atoi(cmd);
1356                 switch (device_type) {
1357                 case 0: /* built-in mic */
1358                         selected_type = SOUND_DEVICE_BUILTIN_MIC;
1359                         break;
1360                 case 1: /* built-in spk */
1361                         selected_type = SOUND_DEVICE_BUILTIN_SPEAKER;
1362                         break;
1363                 case 2: /* built-in rcv */
1364                         selected_type = SOUND_DEVICE_BUILTIN_RECEIVER;
1365                         break;
1366                 case 3: /* audio-jack */
1367                         selected_type = SOUND_DEVICE_AUDIO_JACK;
1368                         break;
1369                 case 4: /* bt a2dp */
1370                         selected_type = SOUND_DEVICE_BLUETOOTH_MEDIA;
1371                         break;
1372                 case 5: /* bt sco */
1373                         selected_type = SOUND_DEVICE_BLUETOOTH_VOICE;
1374                         break;
1375                 case 6: /* usb */
1376                         selected_type = SOUND_DEVICE_USB_AUDIO;
1377                         break;
1378                 default:
1379                         g_print("invalid argument, device_type(%d) is not valid for this feature\n", device_type);
1380                         reset_menu_state();
1381                         break;
1382                 }
1383                 if (!(ret = sound_manager_get_device_list(SOUND_DEVICE_ALL_MASK, &g_device_list))) {
1384                         g_print("success to get current device list\n");
1385                         while (!sound_manager_get_next_device(g_device_list, &device)) {
1386                                 if ((ret = sound_manager_get_device_type(device, &type))) {
1387                                         g_print("fail to get type of device, ret(0x%x)\n", ret);
1388                                         reset_menu_state();
1389                                         break;
1390                                 }
1391                                 if (selected_type == type) {
1392                                         need_to_go = true;
1393                                         break;
1394                                 }
1395                         }
1396                         if (need_to_go) {
1397                                 ret = sound_manager_remove_device_for_stream_routing(g_stream_info_h, device);
1398                                 if (ret)
1399                                         g_print("failed to sound_manager_remove_device_for_stream_routing(), ret(0x%x)\n", ret);
1400                                 else
1401                                         g_print("the device is not available now\n");
1402                                 reset_menu_state();
1403                         } else {
1404                                 g_print("fail to get current device list, ret(0x%x)\n", ret);
1405                                 reset_menu_state();
1406                         }
1407
1408                         if (!(ret = sound_manager_free_device_list(g_device_list))) {
1409                                 g_print("success to free device list\n");
1410                                 g_device_list = NULL;
1411                         } else {
1412                                 g_print("fail to free device list, ret[0x%x]\n", ret);
1413                         }
1414                 }
1415                 break;
1416         }
1417         case CURRENT_STATUS_REMOVE_ALL_DEVICES_FOR_STREAM_ROUTING: {
1418                 int ret = SOUND_MANAGER_ERROR_NONE;
1419
1420                 if ((ret = sound_manager_remove_all_devices_for_stream_routing(g_stream_info_h)))
1421                         g_print("fail to remove all devices for stream routing, ret[0x%x]\n", ret);
1422
1423                 reset_menu_state();
1424                 break;
1425         }
1426         case CURRENT_STATUS_ADD_DEVICE_ID_FOR_STREAM_ROUTING: {
1427                 int ret = SOUND_MANAGER_ERROR_NONE;
1428                 int device_type = 0;
1429                 sound_device_h device = NULL;
1430                 sound_device_type_e selected_type = SOUND_DEVICE_BUILTIN_SPEAKER;
1431                 sound_device_type_e type = SOUND_DEVICE_BUILTIN_SPEAKER;
1432                 bool need_to_go = false;
1433                 int device_id = 0;
1434
1435                 device_type = atoi(cmd);
1436                 switch (device_type) {
1437                 case 0: /* built-in mic */
1438                         selected_type = SOUND_DEVICE_BUILTIN_MIC;
1439                         break;
1440                 case 1: /* built-in spk */
1441                         selected_type = SOUND_DEVICE_BUILTIN_SPEAKER;
1442                         break;
1443                 case 2: /* built-in rcv */
1444                         selected_type = SOUND_DEVICE_BUILTIN_RECEIVER;
1445                         break;
1446                 case 3: /* audio-jack */
1447                         selected_type = SOUND_DEVICE_AUDIO_JACK;
1448                         break;
1449                 case 4: /* bt a2dp */
1450                         selected_type = SOUND_DEVICE_BLUETOOTH_MEDIA;
1451                         break;
1452                 case 5: /* bt sco */
1453                         selected_type = SOUND_DEVICE_BLUETOOTH_VOICE;
1454                         break;
1455                 case 6: /* usb */
1456                         selected_type = SOUND_DEVICE_USB_AUDIO;
1457                         break;
1458                 default:
1459                         g_print("invalid argument, device_type(%d) is not valid for this feature\n", device_type);
1460                         reset_menu_state();
1461                         break;
1462                 }
1463                 if (!(ret = sound_manager_get_device_list(SOUND_DEVICE_ALL_MASK, &g_device_list))) {
1464                         g_print("success to get current device list\n");
1465                         while (!sound_manager_get_next_device(g_device_list, &device)) {
1466                                 if ((ret = sound_manager_get_device_type(device, &type))) {
1467                                         g_print("fail to get type of device, ret(0x%x)\n", ret);
1468                                         reset_menu_state();
1469                                         break;
1470                                 }
1471                                 if (selected_type == type) {
1472                                         if ((ret = sound_manager_get_device_id(device, &device_id))) {
1473                                                 g_print("fail to get device id, ret(0x%x)\n", ret);
1474                                                 reset_menu_state();
1475                                                 break;
1476                                         }
1477                                         need_to_go = true;
1478                                         break;
1479                                 }
1480                         }
1481                         if (need_to_go) {
1482                                 ret = sound_manager_add_device_id_for_stream_routing(g_stream_info_h, device_id);
1483                                 if (ret)
1484                                         g_print("failed to sound_manager_add_device_id_for_stream_routing(), ret(0x%x)\n", ret);
1485                         } else
1486                                 g_print("the device is not available now\n");
1487                         reset_menu_state();
1488
1489                         if (!(ret = sound_manager_free_device_list(g_device_list))) {
1490                                 g_print("success to free device list\n");
1491                                 g_device_list = NULL;
1492                         } else {
1493                                 g_print("fail to free device list, ret[0x%x]\n", ret);
1494                         }
1495                 } else {
1496                         g_print("fail to get current device list, ret(0x%x)\n", ret);
1497                         reset_menu_state();
1498                 }
1499                 break;
1500         }
1501         case CURRENT_STATUS_REMOVE_DEVICE_ID_FOR_STREAM_ROUTING: {
1502                 int ret = SOUND_MANAGER_ERROR_NONE;
1503                 int device_type = 0;
1504                 sound_device_h device = NULL;
1505                 sound_device_type_e selected_type = SOUND_DEVICE_BUILTIN_SPEAKER;
1506                 sound_device_type_e type = SOUND_DEVICE_BUILTIN_SPEAKER;
1507                 bool need_to_go = false;
1508                 int device_id = 0;
1509
1510                 device_type = atoi(cmd);
1511                 switch (device_type) {
1512                 case 0: /* built-in mic */
1513                         selected_type = SOUND_DEVICE_BUILTIN_MIC;
1514                         break;
1515                 case 1: /* built-in spk */
1516                         selected_type = SOUND_DEVICE_BUILTIN_SPEAKER;
1517                         break;
1518                 case 2: /* built-in rcv */
1519                         selected_type = SOUND_DEVICE_BUILTIN_RECEIVER;
1520                         break;
1521                 case 3: /* audio-jack */
1522                         selected_type = SOUND_DEVICE_AUDIO_JACK;
1523                         break;
1524                 case 4: /* bt a2dp */
1525                         selected_type = SOUND_DEVICE_BLUETOOTH_MEDIA;
1526                         break;
1527                 case 5: /* bt sco */
1528                         selected_type = SOUND_DEVICE_BLUETOOTH_VOICE;
1529                         break;
1530                 case 6: /* usb */
1531                         selected_type = SOUND_DEVICE_USB_AUDIO;
1532                         break;
1533                 default:
1534                         g_print("invalid argument, device_type(%d) is not valid for this feature\n", device_type);
1535                         reset_menu_state();
1536                         break;
1537                 }
1538                 if (!(ret = sound_manager_get_device_list(SOUND_DEVICE_ALL_MASK, &g_device_list))) {
1539                         g_print("success to get current device list\n");
1540                         while (!sound_manager_get_next_device(g_device_list, &device)) {
1541                                 if ((ret = sound_manager_get_device_type(device, &type))) {
1542                                         g_print("fail to get type of device, ret(0x%x)\n", ret);
1543                                         reset_menu_state();
1544                                         break;
1545                                 }
1546                                 if (selected_type == type) {
1547                                         if ((ret = sound_manager_get_device_id(device, &device_id))) {
1548                                                 g_print("fail to get device id, ret(0x%x)\n", ret);
1549                                                 reset_menu_state();
1550                                                 break;
1551                                         }
1552                                         need_to_go = true;
1553                                         break;
1554                                 }
1555                         }
1556                         if (need_to_go) {
1557                                 ret = sound_manager_remove_device_id_for_stream_routing(g_stream_info_h, device_id);
1558                                 if (ret)
1559                                         g_print("failed to sound_manager_remove_device_id_for_stream_routing(), ret(0x%x)\n", ret);
1560                                 else
1561                                         g_print("the device is not available now\n");
1562                                 reset_menu_state();
1563                         } else {
1564                                 g_print("fail to get current device list, ret(0x%x)\n", ret);
1565                                 reset_menu_state();
1566                         }
1567
1568                         if (!(ret = sound_manager_free_device_list(g_device_list))) {
1569                                 g_print("success to free device list\n");
1570                                 g_device_list = NULL;
1571                         } else {
1572                                 g_print("fail to free device list, ret[0x%x]\n", ret);
1573                         }
1574                 }
1575                 break;
1576         }
1577         case CURRENT_STATUS_APPLY_STREAM_ROUTING: {
1578                 int ret = SOUND_MANAGER_ERROR_NONE;
1579                 ret = sound_manager_apply_stream_routing(g_stream_info_h);
1580                 if (ret)
1581                         g_print("failed to sound_manager_apply_stream_routing(), ret(0x%x)\n", ret);
1582
1583                 reset_menu_state();
1584                 break;
1585         }
1586         case CURRENT_STATUS_SET_STREAM_ROUTING_OPTION: {
1587                 int ret = SOUND_MANAGER_ERROR_NONE;
1588                 int selection = 0;
1589                 char *name = NULL;
1590                 int value = -1;
1591
1592                 selection = atoi(cmd);
1593                 switch (selection) {
1594                 case 0:
1595                         name = "option_1";
1596                         value = 0;
1597                         break;
1598                 case 1:
1599                         name = "option_1";
1600                         value = 1;
1601                         break;
1602                 case 2:
1603                         name = "option_2";
1604                         value = 0;
1605                         break;
1606                 case 3:
1607                         name = "option_2";
1608                         value = 1;
1609                         break;
1610                 default:
1611                         g_print("invalid argument, try again..\n");
1612                         reset_menu_state();
1613                         break;
1614                 }
1615                 ret = sound_manager_set_stream_routing_option(g_stream_info_h, name, value);
1616                 if (ret)
1617                         g_print("failed to sound_manager_set_stream_routing_option(), ret(0x%x)\n", ret);
1618
1619                 reset_menu_state();
1620                 break;
1621         }
1622         case CURRENT_STATUS_ACQUIRE_FOCUS: {
1623                 int ret = SOUND_MANAGER_ERROR_NONE;
1624                 int focus_type = 0;
1625                 sound_stream_focus_mask_e focus_mask;
1626                 int behavior = SOUND_BEHAVIOR_NONE;
1627
1628                 focus_type = atoi(cmd);
1629                 switch (focus_type) {
1630                 case 0: /* playback */
1631                         focus_mask = SOUND_STREAM_FOCUS_FOR_PLAYBACK;
1632                         break;
1633                 case 1: /* recording */
1634                         focus_mask = SOUND_STREAM_FOCUS_FOR_RECORDING;
1635                         break;
1636                 case 2: /* both */
1637                         focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH;
1638                         break;
1639                 case 3: /* both + no-resumption */
1640                         focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH;
1641                         behavior = SOUND_BEHAVIOR_NO_RESUME;
1642                         break;
1643                 case 4: /* both + fading */
1644                         focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH;
1645                         behavior = SOUND_BEHAVIOR_FADING;
1646                         break;
1647                 default:
1648                         g_print("invalid selection(%d), keep going with PLAYBACK focus..\n", focus_type);
1649                         focus_mask = SOUND_STREAM_FOCUS_FOR_PLAYBACK;
1650                         break;
1651                 }
1652                 ret = sound_manager_acquire_focus(g_stream_info_h, focus_mask,
1653                                 behavior,
1654                                 "sound_manager_test(acquire_focus)");
1655                 if (ret)
1656                         g_print("fail to sound_manager_acquire_focus(), ret(0x%x)\n", ret);
1657
1658                 reset_menu_state();
1659                 break;
1660         }
1661         case CURRENT_STATUS_RELEASE_FOCUS: {
1662                 int ret = SOUND_MANAGER_ERROR_NONE;
1663                 int focus_type = 0;
1664                 sound_stream_focus_mask_e focus_mask;
1665                 int behavior = SOUND_BEHAVIOR_NONE;
1666
1667                 focus_type = atoi(cmd);
1668                 switch (focus_type) {
1669                 case 0: /* playback */
1670                         focus_mask = SOUND_STREAM_FOCUS_FOR_PLAYBACK;
1671                         break;
1672                 case 1: /* recording */
1673                         focus_mask = SOUND_STREAM_FOCUS_FOR_RECORDING;
1674                         break;
1675                 case 2: /* both */
1676                         focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH;
1677                         break;
1678                 case 3: /* both + no-resumption */
1679                         focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH;
1680                         behavior = SOUND_BEHAVIOR_NO_RESUME;
1681                         break;
1682                 case 4: /* both + fading */
1683                         focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH;
1684                         behavior = SOUND_BEHAVIOR_FADING;
1685                         break;
1686                 default:
1687                         g_print("invalid selection(%d), keep going with PLAYBACK focus..\n", focus_type);
1688                         focus_mask = SOUND_STREAM_FOCUS_FOR_PLAYBACK;
1689                         break;
1690                 }
1691                 ret = sound_manager_release_focus(g_stream_info_h, focus_mask,
1692                                 behavior,
1693                                 "sound_manager_test(release_focus)");
1694                 if (ret)
1695                         g_print("fail to sound_manager_release_focus(), ret(0x%x)\n", ret);
1696
1697                 reset_menu_state();
1698                 break;
1699         }
1700         case CURRENT_STATUS_ACQUIRE_FOCUS_ALL: {
1701                 int ret = SOUND_MANAGER_ERROR_NONE;
1702                 int behavior = atoi(cmd);
1703
1704                 switch (behavior) {
1705                 case 0: /* without behavior */
1706                         behavior = SOUND_BEHAVIOR_NONE;
1707                         break;
1708                 case 1: /* no-resumption */
1709                         behavior = SOUND_BEHAVIOR_NO_RESUME;
1710                         break;
1711                 case 2: /* fading */
1712                         behavior = SOUND_BEHAVIOR_FADING;
1713                         break;
1714                 default:
1715                         g_print("invalid selection(%d), keep going without behavior..\n", behavior);
1716                         behavior = SOUND_BEHAVIOR_NONE;
1717                         break;
1718                 }
1719                 ret = sound_manager_acquire_focus_all(g_stream_info_h, behavior, "sound_manager_test(acquire_focus_all)");
1720                 if (ret)
1721                         g_print("fail to sound_manager_acquire_focus_all(), ret(0x%x)\n", ret);
1722
1723                 reset_menu_state();
1724                 break;
1725         }
1726         case CURRENT_STATUS_RELEASE_FOCUS_ALL: {
1727                 int ret = SOUND_MANAGER_ERROR_NONE;
1728                 int behavior = atoi(cmd);
1729
1730                 switch (behavior) {
1731                 case 0: /* without behavior */
1732                         behavior = SOUND_BEHAVIOR_NONE;
1733                         break;
1734                 case 1: /* no-resumption */
1735                         behavior = SOUND_BEHAVIOR_NO_RESUME;
1736                         break;
1737                 case 2: /* fading */
1738                         behavior = SOUND_BEHAVIOR_FADING;
1739                         break;
1740                 default:
1741                         g_print("invalid selection(%d), keep going without behavior..\n", behavior);
1742                         behavior = SOUND_BEHAVIOR_NONE;
1743                         break;
1744                 }
1745                 ret = sound_manager_release_focus_all(g_stream_info_h, behavior, "sound_manager_test(release_focus_all)");
1746                 if (ret)
1747                         g_print("fail to sound_manager_release_focus_all(), ret(0x%x)\n", ret);
1748
1749                 reset_menu_state();
1750                 break;
1751         }
1752         case CURRENT_STATUS_DELIVER_FOCUS: {
1753                 int ret = SOUND_MANAGER_ERROR_NONE;
1754                 sound_stream_focus_mask_e focus_mask;
1755                 sound_stream_info_h stream_info_h = NULL;
1756                 int focus_type = atoi(cmd);
1757
1758                 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &stream_info_h);
1759                 if (ret) {
1760                         g_print("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
1761                         reset_menu_state();
1762                         break;
1763                 }
1764
1765                 switch (focus_type) {
1766                 case 0: /* playback */
1767                         focus_mask = SOUND_STREAM_FOCUS_FOR_PLAYBACK;
1768                         break;
1769                 case 1: /* recording */
1770                         focus_mask = SOUND_STREAM_FOCUS_FOR_RECORDING;
1771                         break;
1772                 case 2: /* both */
1773                         focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH;
1774                         break;
1775                 default:
1776                         g_print("invalid selection(%d), keep going with PLAYBACK focus..\n", focus_type);
1777                         focus_mask = SOUND_STREAM_FOCUS_FOR_PLAYBACK;
1778                         break;
1779                 }
1780                 ret = sound_manager_deliver_focus(g_stream_info_h, stream_info_h, focus_mask);
1781                 if (ret)
1782                         g_print("fail to sound_manager_deliver_focus(), ret(0x%x)\n", ret);
1783
1784                 sound_manager_destroy_stream_information(stream_info_h);
1785
1786                 reset_menu_state();
1787                 break;
1788         }
1789         case CURRENT_STATUS_GET_ACQUIRED_FOCUS: {
1790                 sound_stream_focus_state_e for_playback;
1791                 sound_stream_focus_state_e for_recording;
1792                 int ret = SOUND_MANAGER_ERROR_NONE;
1793                 if (g_stream_info_h) {
1794                         ret = sound_manager_get_focus_state(g_stream_info_h, &for_playback, &for_recording);
1795                         if (ret)
1796                                 g_print("fail to sound_manager_get_focus_state(), ret(0x%x)\n", ret);
1797                         else
1798                                 g_print("focus_state(playback:%d, capture:%d)\n", for_playback, for_recording);
1799
1800                 } else
1801                         g_print("please create stream info. first\n");
1802
1803                 reset_menu_state();
1804                 break;
1805         }
1806         case CURRENT_STATUS_GET_SOUND_TYPE: {
1807                 int ret = SOUND_MANAGER_ERROR_NONE;
1808                 sound_type_e sound_type;
1809                 if (g_stream_info_h) {
1810                         ret = sound_manager_get_sound_type(g_stream_info_h, &sound_type);
1811                         if (ret)
1812                                 g_print("fail to sound_manager_get_sound_type(), ret(0x%x)\n", ret);
1813                         else
1814                                 g_print("sound_type(%d)\n", sound_type);
1815
1816                 } else
1817                         g_print("please create stream info. first\n");
1818
1819                 reset_menu_state();
1820                 break;
1821         }
1822         case CURRENT_STATUS_DESTROY_STREAM_INFO: {
1823                 int ret = SOUND_MANAGER_ERROR_NONE;
1824                 ret = sound_manager_destroy_stream_information(g_stream_info_h);
1825                 if (ret)
1826                         g_print("fail to sound_manager_destroy_stream_information(), ret(0x%x)\n", ret);
1827                 else
1828                         g_stream_info_h = NULL;
1829
1830                 reset_menu_state();
1831                 break;
1832         }
1833         case CURRENT_STATUS_ADD_FOCUS_WATCH_CB: {
1834                 int ret = SOUND_MANAGER_ERROR_NONE;
1835                 int focus_type = 0;
1836                 sound_stream_focus_mask_e focus_mask;
1837                 int id;
1838
1839                 focus_type = atoi(cmd);
1840                 switch (focus_type) {
1841                 case 0: /* playback */
1842                         focus_mask = SOUND_STREAM_FOCUS_FOR_PLAYBACK;
1843                         break;
1844                 case 1: /* recording */
1845                         focus_mask = SOUND_STREAM_FOCUS_FOR_RECORDING;
1846                         break;
1847                 case 2: /* both */
1848                         focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH;
1849                         break;
1850                 default:
1851                         focus_mask = SOUND_STREAM_FOCUS_FOR_PLAYBACK;
1852                         break;
1853                 }
1854                 ret = sound_manager_add_focus_state_watch_cb(focus_mask, focus_watch_callback, NULL, &id);
1855                 if (ret)
1856                         g_print("fail to sound_manager_add_focus_state_watch_cb(), ret(0x%x)\n", ret);
1857                 else
1858                         g_print("id: %d\n", id);
1859
1860                 reset_menu_state();
1861                 break;
1862         }
1863         case CURRENT_STATUS_REMOVE_FOCUS_WATCH_CB: {
1864                 int ret = SOUND_MANAGER_ERROR_NONE;
1865                 int id = 0;
1866
1867                 id = atoi(cmd);
1868                 ret = sound_manager_remove_focus_state_watch_cb(id);
1869                 if (ret)
1870                         g_print("fail to sound_manager_remove_focus_state_watch_cb(%d), ret(0x%x)\n", id, ret);
1871                 reset_menu_state();
1872                 break;
1873         }
1874         case CURRENT_STATUS_SET_FOCUS_REACQUISITION: {
1875                 int ret = SOUND_MANAGER_ERROR_NONE;
1876                 bool enable;
1877
1878                 switch (atoi(cmd)) {
1879                 case 1: /* enable */
1880                         enable = true;
1881                         break;
1882                 case 2: /* disable */
1883                         enable = false;
1884                         break;
1885                 default:
1886                         enable = true;
1887                         break;
1888                 }
1889                 ret = sound_manager_set_focus_reacquisition(g_stream_info_h, enable);
1890                 if (ret)
1891                         g_print("fail to sound_manager_set_focus_reacquisition, ret(0x%x)\n", ret);
1892                 reset_menu_state();
1893                 break;
1894         }
1895         case CURRENT_STATUS_GET_FOCUS_REACQUISITION: {
1896                 int ret = SOUND_MANAGER_ERROR_NONE;
1897                 bool enabled;
1898
1899                 ret = sound_manager_get_focus_reacquisition(g_stream_info_h, &enabled);
1900                 if (ret)
1901                         g_print("fail to sound_manager_get_focus_reacquisition, ret(0x%x)\n", ret);
1902                 if (enabled)
1903                         g_print("auto focus reacquisition is enabled\n");
1904                 else
1905                         g_print("auto focus reacquisition is disabled\n");
1906                 reset_menu_state();
1907                 break;
1908         }
1909         case CURRENT_STATUS_GET_REASON_FOR_P_FOCUS: {
1910                 int ret = SOUND_MANAGER_ERROR_NONE;
1911                 char *extra_info = NULL;
1912                 sound_stream_focus_change_reason_e reason;
1913                 int sound_behavior;
1914
1915                 ret = sound_manager_get_current_playback_focus(&reason, &sound_behavior, &extra_info);
1916                 if (ret)
1917                         g_print("fail to sound_manager_get_current_playback_focus, ret(0x%x)\n", ret);
1918                 else
1919                         g_print("reason(%d), sound_behavior(0x%x, 0x0:none 0x1:no_resume 0x2:fading), extra_info(%s)\n", reason, sound_behavior, extra_info);
1920                 free(extra_info);
1921
1922                 reset_menu_state();
1923                 break;
1924         }
1925         case CURRENT_STATUS_GET_REASON_FOR_R_FOCUS: {
1926                 int ret = SOUND_MANAGER_ERROR_NONE;
1927                 char *extra_info = NULL;
1928                 sound_stream_focus_change_reason_e reason;
1929                 int sound_behavior;
1930
1931                 ret = sound_manager_get_current_recording_focus(&reason, &sound_behavior, &extra_info);
1932                 if (ret)
1933                         g_print("fail to sound_manager_get_current_recording_focus, ret(0x%x)\n", ret);
1934                 else
1935                         g_print("reason(%d), sound_behavior(0x%x, 0x0:none 0x1:no_resume 0x2:fading), extra_info(%s)\n", reason, sound_behavior, extra_info);
1936                 free(extra_info);
1937
1938                 reset_menu_state();
1939                 break;
1940         }
1941         case CURRENT_STATUS_GET_CURRENT_MEDIA_PLAYBACK_DEVICE_TYPE: {
1942                 int ret = SOUND_MANAGER_ERROR_NONE;
1943                 sound_device_type_e device_type;
1944
1945                 ret = sound_manager_get_current_media_playback_device_type(&device_type);
1946                 if (ret)
1947                         g_print("fail to sound_manager_get_current_media_playback_device_type, ret(0x%x)\n", ret);
1948                 else
1949                         g_print("device_type(%d)\n", device_type);
1950
1951                 reset_menu_state();
1952                 break;
1953         }
1954         case CURRENT_STATUS_CREATE_VIRTUAL_STREAM: {
1955                 int ret = SOUND_MANAGER_ERROR_NONE;
1956                 if (!g_stream_info_h || g_vstream_h) {
1957                         g_print("fail to create virtual stream, g_stream_info_h(%p)/g_vstream_h(%p)\n", g_stream_info_h, g_vstream_h);
1958                         reset_menu_state();
1959                         break;
1960                 }
1961                 ret = sound_manager_create_virtual_stream(g_stream_info_h, &g_vstream_h);
1962                 if (ret)
1963                         g_print("fail to sound_manager_create_virtual_stream(), ret(0x%x)\n", ret);
1964                 else
1965                         g_print("success to sound_manager_create_virtual_stream(), ret(0x%x)\n", ret);
1966
1967                 reset_menu_state();
1968                 break;
1969         }
1970         case CURRENT_STATUS_START_VIRTUAL_STREAM: {
1971                 int ret = SOUND_MANAGER_ERROR_NONE;
1972                 if (g_vstream_h) {
1973                         ret = sound_manager_start_virtual_stream(g_vstream_h);
1974                         if (ret)
1975                                 g_print("fail to sound_manager_start_virtual_stream(), ret(0x%x)\n", ret);
1976                         else
1977                                 g_print("success to sound_manager_start_virtual_stream(), ret(0x%x)\n", ret);
1978                 }
1979                 reset_menu_state();
1980                 break;
1981         }
1982         case CURRENT_STATUS_STOP_VIRTUAL_STREAM: {
1983                 int ret = SOUND_MANAGER_ERROR_NONE;
1984                 if (g_vstream_h) {
1985                         ret = sound_manager_stop_virtual_stream(g_vstream_h);
1986                         if (ret)
1987                                 g_print("fail to sound_manager_stop_virtual_stream(), ret(0x%x)\n", ret);
1988                         else
1989                                 g_print("success to sound_manager_stop_virtual_stream(), ret(0x%x)\n", ret);
1990                 }
1991                 reset_menu_state();
1992                 break;
1993         }
1994         case CURRENT_STATUS_DESTROY_VIRTUAL_STREAM: {
1995                 int ret = SOUND_MANAGER_ERROR_NONE;
1996                 if (g_vstream_h) {
1997                         ret = sound_manager_destroy_virtual_stream(g_vstream_h);
1998                         if (ret)
1999                                 g_print("fail to sound_manager_destroy_virtual_stream(), ret(0x%x)\n", ret);
2000                         else
2001                                 g_print("success to sound_manager_destroy_virtual_stream(), ret(0x%x)\n", ret);
2002                         g_vstream_h = NULL;
2003                 }
2004                 reset_menu_state();
2005                 break;
2006         }
2007         case CURRENT_STATUS_SET_FILTER: {
2008                 int ret = SOUND_MANAGER_ERROR_NONE;
2009                 sound_filter_e filter;
2010                 int selection = atoi(cmd);
2011                 switch (selection) {
2012                 case 0: /* low pass filter */
2013                         filter = SOUND_FILTER_LOW_PASS;
2014                         break;
2015                 case 1: /* high pass filter */
2016                         filter = SOUND_FILTER_HIGH_PASS;
2017                         break;
2018                 case 2: /* delay */
2019                         filter = SOUND_FILTER_DELAY;
2020                         break;
2021                 case 3: /* soundAlive */
2022                         filter = SOUND_FILTER_SOUNDALIVE;
2023                         break;
2024                 default:
2025                         filter = SOUND_FILTER_DELAY;
2026                         g_print("invalid selection(%d), keep going with filter(%d)\n", selection, filter);
2027                         break;
2028                 }
2029
2030                 ret = sound_manager_set_filter(SOUND_STREAM_TYPE_MEDIA, filter);
2031                 if (ret)
2032                         g_print("fail to sound_manager_set_filter(), ret(0x%x)\n", ret);
2033                 else
2034                         g_print("success to sound_manager_set_filter(), ret(0x%x)\n", ret);
2035
2036                 reset_menu_state();
2037                 break;
2038         }
2039         case CURRENT_STATUS_SET_FILTER_PRESET: {
2040                 int ret = SOUND_MANAGER_ERROR_NONE;
2041                 sound_filter_e filter;
2042                 sound_filter_preset_e preset;
2043                 int selection = atoi(cmd);
2044
2045                 switch (selection) {
2046                 case 0: /* low pass under none */
2047                         filter = SOUND_FILTER_LOW_PASS;
2048                         preset = SOUND_FILTER_PRESET_LOW_PASS_NONE;
2049                         break;
2050                 case 1: /* low pass under 240hz */
2051                         filter = SOUND_FILTER_LOW_PASS;
2052                         preset = SOUND_FILTER_PRESET_LOW_PASS_UNDER_240HZ;
2053                         break;
2054                 case 2: /* low pass under 480hz */
2055                         filter = SOUND_FILTER_LOW_PASS;
2056                         preset = SOUND_FILTER_PRESET_LOW_PASS_UNDER_480HZ;
2057                         break;
2058                 case 3: /* high pass over none */
2059                         filter = SOUND_FILTER_HIGH_PASS;
2060                         preset = SOUND_FILTER_PRESET_HIGH_PASS_NONE;
2061                         break;
2062                 case 4: /* high pass over 240hz */
2063                         filter = SOUND_FILTER_HIGH_PASS;
2064                         preset = SOUND_FILTER_PRESET_HIGH_PASS_OVER_240HZ;
2065                         break;
2066                 case 5: /* high pass over 480hz */
2067                         filter = SOUND_FILTER_HIGH_PASS;
2068                         preset = SOUND_FILTER_PRESET_HIGH_PASS_OVER_480HZ;
2069                         break;
2070                 case 6: /* delay none */
2071                         filter = SOUND_FILTER_DELAY;
2072                         preset = SOUND_FILTER_PRESET_DELAY_NONE;
2073                         break;
2074                 case 7: /* delay 1 sec */
2075                         filter = SOUND_FILTER_DELAY;
2076                         preset = SOUND_FILTER_PRESET_DELAY_1SEC;
2077                         break;
2078                 case 8: /* delay 2 sec */
2079                         filter = SOUND_FILTER_DELAY;
2080                         preset = SOUND_FILTER_PRESET_DELAY_2SEC;
2081                         break;
2082                 case 9: /* soundAlive concert normal */
2083                         filter = SOUND_FILTER_SOUNDALIVE;
2084                         preset = SOUND_FILTER_PRESET_SOUNDALIVE_NORMAL;
2085                         break;
2086                 case 10: /* soundAlive concert hall */
2087                         filter = SOUND_FILTER_SOUNDALIVE;
2088                         preset = SOUND_FILTER_PRESET_SOUNDALIVE_CONCERT_HALL;
2089                         break;
2090                 default:
2091                         filter = SOUND_FILTER_DELAY;
2092                         preset = SOUND_FILTER_PRESET_DELAY_NONE;
2093                         g_print("invalid selection(%d), keep going with filter(%d), preset(%d)\n", selection, filter, preset);
2094                         break;
2095                 }
2096
2097                 ret = sound_manager_set_filter_preset(SOUND_STREAM_TYPE_MEDIA, filter, preset);
2098                 if (ret)
2099                         g_print("fail to sound_manager_set_filter_preset(), ret(0x%x)\n", ret);
2100                 else
2101                         g_print("success to sound_manager_set_filter_preset(), ret(0x%x)\n", ret);
2102
2103                 reset_menu_state();
2104                 break;
2105         }
2106         case CURRENT_STATUS_UNSET_FILTER: {
2107                 int ret = SOUND_MANAGER_ERROR_NONE;
2108                 ret = sound_manager_unset_filter(SOUND_STREAM_TYPE_MEDIA);
2109                 if (ret)
2110                         g_print("fail to sound_manager_unset_filter(), ret(0x%x)\n", ret);
2111                 else
2112                         g_print("success to sound_manager_unset_filter(), ret(0x%x)\n", ret);
2113                 reset_menu_state();
2114                 break;
2115         }
2116 #ifndef TIZEN_FEATURE_TV_PROD
2117         case CURRENT_STATUS_GET_MAX_MASTER_VOLUME: {
2118                 int max_level;
2119                 if (sound_manager_get_max_master_volume(&max_level) != SOUND_MANAGER_ERROR_NONE)
2120                         g_print("failed to get max master volume\n");
2121                 else
2122                         g_print("the max level of master volume is %d\n", max_level);
2123
2124                 reset_menu_state();
2125                 break;
2126         }
2127         case CURRENT_STATUS_SET_MASTER_VOLUME: {
2128                 int level;
2129                 level = atoi(cmd);
2130                 if (sound_manager_set_master_volume(level) != SOUND_MANAGER_ERROR_NONE)
2131                         g_print("failed to set master volume(%d)\n", level);
2132                 else
2133                         g_print("set master volume success : level(%d)\n", level);
2134
2135                 reset_menu_state();
2136                 break;
2137         }
2138         case CURRENT_STATUS_GET_MASTER_VOLUME: {
2139                 int level;
2140                 if (sound_manager_get_master_volume(&level) != SOUND_MANAGER_ERROR_NONE)
2141                         g_print("failed to get master volume\n");
2142                 else
2143                         g_print("current master volume is : %d\n", level);
2144
2145                 reset_menu_state();
2146                 break;
2147         }
2148 #endif
2149         }
2150         g_timeout_add(100, timeout_menu_display, 0);
2151 }
2152
2153 gboolean input(GIOChannel *channel)
2154 {
2155         gchar buf[MAX_STRING_LEN];
2156         gsize read;
2157         GError *error = NULL;
2158
2159         g_io_channel_read_chars(channel, buf, MAX_STRING_LEN - 1, &read, &error);
2160         buf[read] = '\0';
2161         g_strstrip(buf);
2162         interpret(buf);
2163
2164         return TRUE;
2165 }
2166
2167 /* it will be removed when session features are deprecated. */
2168 void signal_callback(mm_sound_signal_name_t signal, int value, void *user_data)
2169 {
2170         g_print("*** signal callback is called: signal(%d), value(%d), user_data(%p)\n", signal, value, user_data);
2171 }
2172
2173 int main(int argc, char *argv[])
2174 {
2175         unsigned int subscribe_id = 0;
2176         int ret = MM_ERROR_NONE;
2177         GIOChannel *stdin_channel;
2178         stdin_channel = g_io_channel_unix_new(0);
2179         g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
2180         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
2181         g_loop = g_main_loop_new(NULL, 1);
2182
2183         /* subscribe a signal for convering session-focus */
2184         /* it will be removed when session features are deprecated. */
2185         if ((ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &subscribe_id, signal_callback, NULL)))
2186                 g_print("failed to subscribe signal, ret(0x%x)\n", ret);
2187
2188         displaymenu();
2189         g_main_loop_run(g_loop);
2190
2191         /* it will be removed when session features are deprecated. */
2192         if (subscribe_id)
2193                 mm_sound_unsubscribe_signal(subscribe_id);
2194
2195         return 0;
2196 }