blob: 7885848fd0ec6d241035de749ae569ec60e9a226 [file] [log] [blame]
r.xiaob9e69d02023-12-17 18:59:14 -08001#include "lynq-qser-voice.h"
2
3#include "mbtk_type.h"
4#include "mbtk_info_api.h"
5#include "mbtk_audio.h"
6
7
r.xiao79feffd2024-01-03 03:29:44 -08008#if 0
9#include <stdlib.h>
10#include <stdio.h>
11#include <string.h>
12#include <sys/types.h>
13#include <pthread.h>
14#include <unistd.h>
15#include <dlfcn.h>
16#include <stdint.h>
17
18//#include"lynq-qser-voice-demo.h"
19
20typedef struct
21{
22 int cmdIdx;
23 char *funcName;
24} st_api_test_case;
25
26//for server test
27st_api_test_case at_api_testcases[] =
28{
29 {0, "print_help"},
30 {1, "qser_voice_call_start"},
31 {2, "qser_voice_call_end"},
32 {3, "qser_voice_call_answer"},
33 {4, "qser_voice_set_speech_volume"},
34 {5, "qser_voice_get_speech_volume"},
35 {-1, NULL}
36};
37
38
39
40typedef uint32_t voice_client_handle_type;
41
42static pthread_t s_lynq_voice_tid = -1;
43
44
45int (*qser_voice_call_client_init)(voice_client_handle_type *ph_voice);
46int (*qser_voice_call_client_deinit)(voice_client_handle_type );
47int (*qser_voice_call_addstatehandler)(voice_client_handle_type h_voice,
48 QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
49 void *contextPtr);
50
51int (*qser_voice_call_removestatehandle)(voice_client_handle_type );
52int (*qser_voice_call_start)(voice_client_handle_type h_voice,
53 E_QSER_VCALL_ID_T simId,
54 char *phone_number, int *call_id);
55
56int (*qser_voice_call_end)(voice_client_handle_type ,int );
57int (*qser_voice_call_answer)(voice_client_handle_type ,int );
58int (*qser_voice_set_speech_volume)(const int volume);
59int (*qser_voice_get_speech_volume)(int *volume);
60
61void *dlHandle_call = NULL;
62
63static void yk_voice_call_cb_func(int call_id,
64 char* phone_num,
65 qser_voice_call_state_t state,
66 void *contextPtr)
67{
68 char *call_state[] = {"INCOMING", "DIALING", "ALERTING", "ACTIVE", "HOLDING", "END", "WAITING"};
69
70 printf("######### Call id=%d, PhoneNum:%s, event=%s! ######\n", call_id, phone_num, call_state[state]);
71}
72
73void print_help(void)
74{
75 int i;
76 printf("Supported test cases:\n");
77 for(i = 0; ; i++)
78 {
79 if(at_api_testcases[i].cmdIdx == -1)
80 {
81 break;
82 }
83 printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName);
84 }
85}
86
87int main(int argc, char const *argv[])
88{
89 int cmdIdx = 0;
90 int ret = 0;
91 int voice_call_id = 0;
92 voice_client_handle_type h_voice = 0;
93
94 //const char *lynqLibPath_Call = "/lib/liblynq-qser-voice.so";
95 const char *lynqLibPath_Call = "/lib/liblynq_lib.so";
96 dlHandle_call = dlopen(lynqLibPath_Call, RTLD_NOW);
97 if (dlHandle_call == NULL)
98 {
99 printf("dlopen dlHandle_call failed: %s\n", dlerror());
100 exit(EXIT_FAILURE);
101 }
102
103 qser_voice_call_client_init = (int(*)(voice_client_handle_type *ph_voice))dlsym(dlHandle_call, "qser_voice_call_client_init");
104 if(qser_voice_call_client_init == NULL)
105 {
106 printf("qser_voice_call_client_init not defined or exported in %s\n", lynqLibPath_Call);
107 return -1;
108 }
109
110 qser_voice_call_addstatehandler = (int(*)(voice_client_handle_type h_voice,
111 QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
112 void *contextPtr))dlsym(dlHandle_call,"qser_voice_call_addstatehandler");
113 if(qser_voice_call_addstatehandler == NULL)
114 {
115 printf("qser_voice_call_addstatehandler not defined or exported in %s\n", lynqLibPath_Call);
116 return -1;
117 }
118
119 qser_voice_call_answer = (int(*)(voice_client_handle_type,int ))dlsym(dlHandle_call,"qser_voice_call_answer");
120 if(qser_voice_call_answer == NULL)
121 {
122 printf("qser_voice_call_answer not defined or exported in %s\n", lynqLibPath_Call);
123 return -1;
124 }
125
126 qser_voice_call_start = (int(*)(voice_client_handle_type h_voice,E_QSER_VCALL_ID_T simId,
127 char *phone_number, int *call_id))dlsym(dlHandle_call,"qser_voice_call_start");
128 if(qser_voice_call_start == NULL)
129 {
130 printf("qser_voice_call_start not defined or exported in %s\n", lynqLibPath_Call);
131 return -1;
132 }
133
134 qser_voice_call_end = (int(*)(voice_client_handle_type ,int))dlsym(dlHandle_call,"qser_voice_call_end");
135 if(qser_voice_call_end == NULL)
136 {
137 printf("qser_voice_call_end not defined or exported in %s\n", lynqLibPath_Call);
138 return -1;
139 }
140
141
142 qser_voice_call_client_deinit = (int (*)(voice_client_handle_type h_voice))dlsym(dlHandle_call,"qser_voice_call_client_deinit");
143 if(qser_voice_call_client_deinit == NULL)
144 {
145 printf("qser_voice_call_client_deinit not defined or exported in %s\n", lynqLibPath_Call);
146 return -1;
147 }
148
149 qser_voice_call_removestatehandle = (int (*)(voice_client_handle_type))dlsym(dlHandle_call,"qser_voice_call_removestatehandle");
150 if(qser_voice_call_removestatehandle == NULL)
151 {
152 printf("qser_voice_call_removestatehandle not defined or exported in %s\n", lynqLibPath_Call);
153 return -1;
154 }
155
156 qser_voice_set_speech_volume = (int (*)(const int ))dlsym(dlHandle_call,"qser_voice_set_speech_volume");
157 if(qser_voice_set_speech_volume == NULL)
158 {
159 printf("qser_voice_set_speech_volume not defined or exported in %s\n", lynqLibPath_Call);
160 return -1;
161 }
162
163 qser_voice_get_speech_volume = (int (*)(int* ))dlsym(dlHandle_call,"qser_voice_get_speech_volume");
164 if(qser_voice_get_speech_volume == NULL)
165 {
166 printf("qser_voice_get_speech_volume not defined or exported in %s\n", lynqLibPath_Call);
167 return -1;
168 }
169
170 ret = qser_voice_call_client_init(&h_voice);
171 if(ret != 0 )
172 {
173 printf("qser_voice_call_client_init FAIL\n");
174 return -1;
175 }
176
177 ret = qser_voice_call_addstatehandler(h_voice, yk_voice_call_cb_func, &voice_call_id);
178 if(ret != 0)
179 {
180 printf("qser_voice_call_addstatehandler FAIL\n");
181 return -1;
182 }
183
184
185 print_help();
186 while(1)
187 {
188 printf("\nplease input cmd index(-1 exit): ");
189 scanf("%d", &cmdIdx);
190 if(cmdIdx == -1)
191 {
192 break;
193 }
194
195 switch(cmdIdx)
196 {
197 //"print_help
198 case 0:
199 print_help();
200 break;
201
202 //"qser_voice_call_start"
203 case 1:
204 {
205 char PhoneNum[32] = {0};
206
207 printf("please input dest phone number: \n");
208 scanf("%s", PhoneNum);
209
210 ret = qser_voice_call_start(h_voice, E_QSER_VCALL_EXTERNAL_SLOT_1, PhoneNum, &voice_call_id);
211 printf("qser_voice_call_start ret = %d, with voice_call_id=%d\n", ret, voice_call_id);
212 break;
213 }
214
215 //"qser_voice_call_end"
216 case 2:
217 {
218 int call_id = -1;
219 printf("please input end call id: \n");
220 scanf("%d", &call_id);
221 ret = qser_voice_call_end(h_voice, call_id);
222 printf(" ret = %d\n", ret);
223 break;
224 }
225
226 //"qser_voice_call_answer"
227 case 3:
228 {
229 int call_id = -1;
230 printf(" please input answer call id\n");
231 scanf("%d", &call_id);
232 ret = qser_voice_call_answer(h_voice, call_id);
233 printf(" ret = %d\n", ret);
234 break;
235 }
236 case 4:
237 {
238 int volume = 0;
239 printf("Please set speech volume:0-5 level\n");
240 scanf("%d",&volume);
241 ret = qser_voice_set_speech_volume(volume);
242 printf("ret is %d\n",ret);
243 break;
244
245 }
246
247 case 5:
248 {
249 int volume = -1;
250 printf("Enter get speech volume\n");
251 ret = qser_voice_get_speech_volume(&volume);
252 printf("ret is %d,get volume is %d\n",ret,volume);
253 break;
254
255 }
256 default:
257 print_help();
258 break;
259 }
260
261 }
262 ret = qser_voice_call_removestatehandle(h_voice);
263 if(ret != 0 && ret != 1)
264 {
265 printf("qser_voice_call_removestatehandle FAIL!!!\n");
266 return -1;
267 }
268 printf("qser_voice_call_removestatehandle ret = %d\n", ret);
269
270
271 ret = qser_voice_call_client_deinit(h_voice);
272 if(ret != 0)
273 {
274 printf("qser_voice_call_client_deinit FAIL\n");
275 return -1;
276 }
277 printf("qser_voice_call_client_deinit ret = %d, with h_voice=%d\n", ret, h_voice);
278
279 return 0;
280}
281
282
283#else
284
285static void yk_voice_call_cb_func(int call_id,
286 char* phone_num,
287 qser_voice_call_state_t state,
288 void *contextPtr)
289{
290 char *call_state[] = {"INCOMING", "DIALING", "ALERTING", "ACTIVE", "HOLDING", "END", "WAITING"};
291
292 printf("######### Call id=%d, PhoneNum:%s, event=%s! ######\n", call_id, phone_num, call_state[state]);
293}
294
r.xiaob9e69d02023-12-17 18:59:14 -0800295int main(int argc, char *argv[])
296{
297 char operator[10];
298 int opt;
299 int lv_voll = 0;
r.xiao79feffd2024-01-03 03:29:44 -0800300 voice_client_handle_type handle = -1;
301 int voice_call_id = 1;
r.xiaob9e69d02023-12-17 18:59:14 -0800302
303 while(1)
304 {
305 printf("=========call main=========\n"
306 "\t0 exit\n"
307 "\t1 call init\n"
308 "\t2 call add register handle\n"
309 "\t3 call start\n"
310 "\t4 call end\n"
311 "\t5 call answer\n"
312 "\t6 call remove register handle\n"
r.xiao79feffd2024-01-03 03:29:44 -0800313 "\t7 call set volume level 0-5\n"
r.xiaob9e69d02023-12-17 18:59:14 -0800314 "\t8 call get volume\n"
315 "\t9 call deinit\n"
316 "operator: >> ");
317
318 fgets(operator, sizeof(operator), stdin);
319 fflush(stdin);
320 opt = atoi(operator);
321 switch (opt)
322 {
323 case 0:
324 printf("main exit\n");
325 return 0;
326 case 1:
r.xiao79feffd2024-01-03 03:29:44 -0800327 qser_voice_call_client_init(&handle);
328 printf("test>>: handle = %d\n",handle);
r.xiaob9e69d02023-12-17 18:59:14 -0800329 break;
330 case 2:
r.xiao79feffd2024-01-03 03:29:44 -0800331 {
332 qser_voice_call_addstatehandler(handle, yk_voice_call_cb_func, &voice_call_id);
r.xiaob9e69d02023-12-17 18:59:14 -0800333 break;
r.xiao79feffd2024-01-03 03:29:44 -0800334 }
r.xiaob9e69d02023-12-17 18:59:14 -0800335 case 3:
r.xiao79feffd2024-01-03 03:29:44 -0800336 qser_voice_call_start(handle, E_QSER_VCALL_EXTERNAL_SLOT_1, "18981904623", &voice_call_id);//被叫电话
r.xiaob9e69d02023-12-17 18:59:14 -0800337 break;
338 case 4:
r.xiao79feffd2024-01-03 03:29:44 -0800339 qser_voice_call_end(handle, voice_call_id);
r.xiaob9e69d02023-12-17 18:59:14 -0800340 break;
341 case 5:
r.xiao79feffd2024-01-03 03:29:44 -0800342 qser_voice_call_anser(handle, voice_call_id);
r.xiaob9e69d02023-12-17 18:59:14 -0800343 break;
344 case 6:
r.xiao79feffd2024-01-03 03:29:44 -0800345 qser_voice_call_removestatehandle(handle);
r.xiaob9e69d02023-12-17 18:59:14 -0800346 break;
347 case 7:
348 {
349 printf("Pleas set volume level(0-5)>>>>\n");
350 memset(operator, 0x00, sizeof(operator));
351 fgets(operator, sizeof(operator), stdin);
352 fflush(stdin);
353 //def level 3
354 lv_voll = atoi(operator);
355 if (lv_voll >= 0 && lv_voll <= 5)
356 qser_voice_set_speech_volume(lv_voll);
357 else
358 printf("set volume level(0-5) ERR\n");
359 break;
360 }
361 case 8:
362 {
r.xiaoe73f8702024-01-06 01:40:03 -0800363 qser_voice_get_speech_volume(&lv_voll);
r.xiaob9e69d02023-12-17 18:59:14 -0800364 printf("volume level = %d\n",lv_voll);
365 break;
366 }
367 case 9:
r.xiao79feffd2024-01-03 03:29:44 -0800368 qser_voice_call_client_deinit(handle);
r.xiaob9e69d02023-12-17 18:59:14 -0800369 break;
370 default:
371 break;
372 }
373
374 }
375
376 return 0;
377}
378
r.xiao79feffd2024-01-03 03:29:44 -0800379#endif
380