5 #include <audio-session-manager.h>
11 gint event_type = ASM_EVENT_NONE;
12 gint asm_state = ASM_STATE_NONE;
13 ASM_resource_t g_resource = ASM_RESOURCE_NONE;
17 asm_callback (int handle, ASM_event_sources_t event_src, ASM_sound_commands_t command, unsigned int sound_status, void* cb_data)
19 g_print ("\n[%s][%d] handle = %d, event src = %d, command = %d, sound_state = %d\n\n", __func__, __LINE__, handle ,event_src, command, sound_status);
20 return ASM_CB_RES_IGNORE;
23 void print_menu_main(void)
25 printf("========ASM Testsuite======\n");
26 printf(" r. Register ASM\n");
27 printf(" s. Set state\n");
28 printf(" u. Unregister ASM\n");
30 printf("============================\n");
34 void menu_unregister(void)
37 if(asm_handle == -1) {
38 g_print("Register sound first..\n\n");
41 if( !ASM_unregister_sound(asm_handle, event_type, &errorcode) ) {
42 g_print("Unregister sound failed 0x%X\n\n", errorcode);
44 g_print("Unregister success..\n\n");
49 void menu_register(void)
55 g_resource = ASM_RESOURCE_NONE;
58 printf("==========select ASM event=============\n");
59 printf(" 0. ASM_EVENT_SHARE_MMPLAYER \n");
60 printf(" 1. ASM_EVENT_SHARE_MMCAMCORDER\n");
61 printf(" 2. ASM_EVENT_SHARE_MMSOUND\n");
62 printf(" 3. ASM_EVENT_SHARE_OPENAL\n");
63 printf(" 4. ASM_EVENT_SHARE_AVSYSTEM\n");
64 printf(" 5. ASM_EVENT_SHARE_FMRADIO\n");
65 printf(" 6. ASM_EVENT_EXCLUSIVE_MMPLAYER\n");
66 printf(" 7. ASM_EVENT_EXCLUSIVE_MMCAMCORDER\n");
67 printf(" 8. ASM_EVENT_EXCLUSIVE_MMSOUND\n");
68 printf(" 9. ASM_EVENT_EXCLUSIVE_OPENAL\n");
69 printf(" a. ASM_EVENT_EXCLUSIVE_AVSYSTEM\n");
70 printf(" b. ASM_EVENT_EXCLUSIVE_FMRADIO\n");
71 printf(" c. ASM_EVENT_NOTIFY\n");
72 printf(" d. ASM_EVENT_CALL\n");
73 printf(" e. ASM_EVENT_EARJACK_UNPLUG\n");
74 printf(" f. ASM_EVENT_ALARM\n");
75 printf(" g. ASM_EVENT_VIDEOCALL\n");
76 printf(" h. ASM_EVENT_MONITOR\n");
77 printf(" i. ASM_EVENT_RICHCALL\n");
78 printf(" j. ASM_EVENT_EMERGENCY\n");
79 printf(" k. ASM_EVENT_EXCLUSIVE_RESOURCE\n");
80 printf(" q. Back to main menu\n");
81 printf("=======================================\n");
85 while( (input = getchar())!= '\n' && input != EOF) {
90 event_type = ASM_EVENT_SHARE_MMPLAYER;
93 event_type = ASM_EVENT_SHARE_MMCAMCORDER;
94 g_resource = ASM_RESOURCE_CAMERA;
97 event_type = ASM_EVENT_SHARE_MMSOUND;
100 event_type = ASM_EVENT_SHARE_OPENAL;
103 event_type = ASM_EVENT_SHARE_AVSYSTEM;
106 event_type = ASM_EVENT_SHARE_FMRADIO;
109 event_type = ASM_EVENT_EXCLUSIVE_MMPLAYER;
112 event_type = ASM_EVENT_EXCLUSIVE_MMCAMCORDER;
113 g_resource = ASM_RESOURCE_CAMERA;
116 event_type = ASM_EVENT_EXCLUSIVE_MMSOUND;
119 event_type = ASM_EVENT_EXCLUSIVE_OPENAL;
122 event_type = ASM_EVENT_EXCLUSIVE_AVSYSTEM;
125 event_type = ASM_EVENT_EXCLUSIVE_FMRADIO;
128 event_type = ASM_EVENT_NOTIFY;
131 event_type = ASM_EVENT_CALL;
134 event_type = ASM_EVENT_EARJACK_UNPLUG;
137 event_type = ASM_EVENT_ALARM;
140 event_type = ASM_EVENT_VIDEOCALL;
141 g_resource = ASM_RESOURCE_CAMERA;
144 event_type = ASM_EVENT_MONITOR;
147 event_type = ASM_EVENT_RICH_CALL;
148 g_resource = ASM_RESOURCE_CAMERA;
151 event_type = ASM_EVENT_EMERGENCY;
154 event_type = ASM_EVENT_EXCLUSIVE_RESOURCE;
155 /* temporarily set it ASM_RESOURCE_CAMERA */
156 g_resource = ASM_RESOURCE_CAMERA;
161 g_print("select event again...\n");
165 if (event_type == -1) {
168 if( ! ASM_register_sound(pid, &asm_handle, event_type, ASM_STATE_NONE, asm_callback, NULL, g_resource, &errorcode)) {
169 g_print("ASM_register_sound() failed, error = %x\n\n", errorcode);
172 g_print("ASM_register_sound() success, ASM handle=%d, ASM_EVENT=%d, ASM_RESOURCE=%d, ASM_STATE_NONE.\n\n", asm_handle, event_type, g_resource);
178 void menu_set_state(void)
184 printf("==========ASM state==========\n");
185 printf(" 0. ASM_STATE_IGNORE\n");
186 printf(" 1. ASM_STATE_NONE\n");
187 printf(" 2. ASM_STATE_PLAYING\n");
188 printf(" 3. ASM_STATE_WAITING\n");
189 printf(" 4. ASM_STATE_STOP\n");
190 printf(" 5. ASM_STATE_PAUSE\n");
191 printf(" 6. ASM_STATE_PAUSE_BY_APP\n");
192 printf(" q. Back to main menu\n");
193 printf("=============================\n");
195 while( (input = getchar())!= '\n' && input != EOF) {
201 asm_state = ASM_STATE_IGNORE;
204 asm_state = ASM_STATE_NONE;
207 asm_state = ASM_STATE_PLAYING;
210 asm_state = ASM_STATE_WAITING;
213 asm_state = ASM_STATE_STOP;
216 asm_state = ASM_STATE_PAUSE;
219 asm_state = ASM_STATE_PAUSE_BY_APP;
224 g_print("select ASM state again...\n");
227 if (asm_state == 9) {
230 /* set ASM sound state */
231 if( ! ASM_set_sound_state( asm_handle, event_type, asm_state, g_resource, &ret) ) {
232 g_print("ASM_set_sound_state() failed, Set state to [%d] failed 0x%X\n\n", asm_state, ret);
235 g_print("ASM_set_sound_state() success, ASM handle=%d, ASM_EVENT=%d, ASM_RESOURCE=%d, ASM_STATE=%d\n\n", asm_handle, event_type, g_resource, asm_state);
241 gpointer keythread(gpointer data)
248 while( (input = getchar())!= '\n' && input != EOF) {
263 if(asm_handle != -1) {
266 g_main_loop_quit(g_loop);
269 g_print("wrong input, select again...\n\n");
277 g_thread_init (NULL);
280 g_loop = g_main_loop_new (NULL, 0);
281 GThread * command_thread = g_thread_create (keythread, NULL, FALSE, NULL);
282 if (!command_thread) {
283 g_print ("key thread creation failure\n");
287 g_main_loop_run (g_loop);
288 g_print ("loop finished !!\n");
290 if (command_thread) {
291 g_thread_join (command_thread);
292 command_thread = NULL;