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