Git init
[framework/api/sound-manager.git] / test / multimedia_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
18
19 #include <stdio.h>
20 #include <sound_manager.h>
21 #include <glib.h>
22 #include <mm_sound.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <player.h>
26 #include <stdlib.h>
27
28 static GMainLoop *g_mainloop = NULL;
29 static GThread *event_thread;
30 #define MAX_VOLUME_TYPE 5
31
32 gpointer GmainThread(gpointer data){
33         g_mainloop = g_main_loop_new (NULL, 0);
34         g_main_loop_run (g_mainloop);
35
36         return NULL;
37 }
38
39 void _sound_manager_volume_changed_cb(sound_type_e type, unsigned int volume, void* user_data)
40 {
41         printf("changed!! type=%d, volume = %d\n", type, volume);
42 }
43
44 int set_volume_test()
45 {
46         printf("set volume test\n");
47         int i;
48         sound_manager_set_volume_changed_cb(_sound_manager_volume_changed_cb ,NULL);
49         for( i = SOUND_TYPE_SYSTEM ; i <=MAX_VOLUME_TYPE; i++){
50                 int max_value;
51                 int j;
52                 sound_manager_get_max_volume(i, &max_value);
53                 printf(" sound type = %d , max volume = %d\n", i, max_value);
54                 for( j = 0; j <= max_value+1 ; j++){
55                         int ret;
56                         int getvalue;
57                         ret = sound_manager_set_volume(i, j);
58                         if( j <=  max_value && ret == 0 ){
59                                 sound_manager_get_volume(i, &getvalue);
60                                 if( j == getvalue )
61                                         printf("PASS\n");
62                                 else
63                                         printf("FAIL!set=%d, get=%d\n", j, getvalue);
64                         } else if( j > max_value && ret == 0 )
65                                 printf("FAIL! max_value over!!\n");
66
67                 }
68         }
69         //sound_manager_unset_volume_changed_cb();
70         printf("end set volume test!!!\n");
71         sleep(10);
72         return 0;
73 }
74
75 void _sound_manager_route_policy_changed_cb(sound_route_policy_e route , void* user_data)
76 {
77         printf("new route policy %d\n", route);
78 }
79
80 int set_policy_test()
81 {
82         printf("-----------set policy test--------------\n");
83         int ret;
84         //int i;
85         //sound_route_policy_e value;
86         sound_manager_set_route_policy_changed_cb(_sound_manager_route_policy_changed_cb,NULL);
87         /*
88         for( i = SOUND_ROUTE_DEFAULT ; i <= SOUND_ROUTE_HANDSET_ONLY ; i++){
89                 ret = sound_manager_set_route_policy(i);
90                 ret = sound_manager_get_route_policy(&value);
91                 if( i == value )
92                         printf("PASS\n");
93                 else
94                         printf("FAIL\n");
95         }
96         */
97         ret = sound_manager_set_route_policy(SOUND_ROUTE_DEFAULT);
98         ret = sound_manager_set_route_policy(SOUND_ROUTE_DEFAULT);
99         ret = sound_manager_set_route_policy(SOUND_ROUTE_DEFAULT);
100         ret = sound_manager_set_route_policy(SOUND_ROUTE_DEFAULT);
101         
102         
103         return 0;
104 }
105
106
107 static void mm_volume_changed_cb(void *user_data)
108 {
109         int v = (int)user_data;
110         unsigned int value = 0;
111         int ret = mm_sound_volume_get_value(v, &value);
112         printf("mm_volume_changed_cb type = %d ,volume = %d , ret = %x\n", v, value, ret );
113 }
114
115
116 int mm_bug_test()
117 {
118         int ret = 0;
119         mm_sound_volume_add_callback(0 , mm_volume_changed_cb , (void*)0);              
120         mm_sound_volume_add_callback(1 , mm_volume_changed_cb ,(void*) 1);      
121         mm_sound_volume_add_callback(2 , mm_volume_changed_cb , (void*)2);      
122         mm_sound_volume_add_callback(5 , mm_volume_changed_cb , (void*)5);              
123
124         int i;
125
126         for( i = 0 ; i < 10 ; i++)
127         {
128                 ret = mm_sound_volume_set_value(0, i);
129                 printf("type = 0 , volume = %d set , ret = %x\n", i, ret);
130                 ret = mm_sound_volume_set_value(1, i);  
131                 printf("type = 1 , volume = %d set , ret = %x\n", i, ret);              
132                 ret = mm_sound_volume_set_value(2, i);
133                 printf("type = 2 , volume = %d set , ret = %x\n", i, ret);              
134                 ret = mm_sound_volume_set_value(5, i);
135                 printf("type = 5 , volume = %d set , ret = %x\n", i, ret);              
136                 sleep(1);       
137         }
138         
139         //mm_sound_volume_remove_callback(0);
140         //mm_sound_volume_remove_callback(1);
141         //mm_sound_volume_remove_callback(2);   
142         //mm_sound_volume_remove_callback(5);   
143
144         
145         ret = mm_sound_volume_set_value(5, 4);  
146         
147         mm_sound_route_set_system_policy(SOUND_ROUTE_DEFAULT);
148         mm_sound_route_set_system_policy(SOUND_ROUTE_DEFAULT);
149         mm_sound_route_set_system_policy(SOUND_ROUTE_DEFAULT);  
150         return 0;       
151 }
152
153 void mm_test(){
154
155         char path[255];
156         int id;
157         int i;
158         getcwd(path, 255);
159         strcat(path, "/test2.wav");
160         for( i =0 ; i < 10 ; i++){
161                 mm_sound_play_sound(path, SOUND_TYPE_MEDIA, NULL ,NULL, &id);
162                 mm_sound_stop_sound(id);
163         }
164 }
165
166 void session_notify_cb(sound_session_notify_e notify, void *user_data)
167 {
168         printf("notify %d\n", notify);
169
170
171 }
172
173
174 void session_test(){
175         printf("session_test\n");
176         int ret = 0;
177         player_h player;
178
179         ret = sound_manager_set_session_type(SOUND_SESSION_TYPE_EXCLUSIVE);
180         sound_manager_set_session_notify_cb(session_notify_cb,NULL);    
181
182
183
184         ret = player_create(&player);
185         printf("player_create ret =%x\n", ret);
186         ret = player_set_uri(player, "title_theme.mp3");
187         printf("player_set_uri ret =%x\n", ret);
188         ret =player_prepare(player);
189         printf("player_prepare ret =%x\n", ret);                
190         ret = player_start(player);
191         printf("player_start ret =%x\n", ret);  
192
193         while(1){
194                 player_state_e state;
195                 player_get_state(player, &state);
196                 printf("state %d\n", state);
197                 //if( state == 4)
198                         //player_start(player);
199                 sleep(1);
200                 //wav_player_start("test.wav", SOUND_TYPE_MEDIA,NULL, NULL,NULL);
201         }
202         
203         
204 }
205
206
207 void a2dp_test(){
208         bool isconnected;
209         char * name;
210         sound_manager_get_a2dp_status(&isconnected, &name);
211         if( isconnected ){
212                 printf("name = %s\n", name);
213                 free(name);
214         }else{
215                 printf("disconnected\n");
216         }
217         sound_device_e device;
218         sound_manager_get_current_sound_device(&device);
219         printf("device =%d\n", device);
220                 
221 }
222
223 int main()
224 {
225         if( !g_thread_supported() )
226         {
227                 g_thread_init(NULL);
228         }
229
230         GError *gerr = NULL;
231         event_thread = g_thread_create(GmainThread, NULL, 1, &gerr);
232
233
234
235         //set_volume_test();
236         //set_policy_test();
237         //mm_bug_test();
238         //wav_play_test();
239         //tone_play_test();
240         //wav_play_test();
241         session_test();
242         //a2dp_test();
243         return 0;
244 }