blob: 670eb10b4c9af2a7f1a878dbd86444f4cba04371 [file] [log] [blame]
b.liu86b7ff22024-04-03 14:25:55 +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
8#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
295int main(int argc, char *argv[])
296{
297 char operator[10];
298 int opt;
299 int lv_voll = 0;
300 voice_client_handle_type handle = -1;
301 int voice_call_id = 0;
302 mbtk_log_init("radio", "CALL_TEST");
r.xiaoba8483c2024-04-14 18:53:10 -0700303
304 printf("=========call main=========\n"
305 "\t0 exit\n"
306 "\t1 call init\n"
307 "\t2 call add register handle\n"
308 "\t3 call start\n"
309 "\t4 call end\n"
310 "\t5 call answer\n"
311 "\t6 call remove register handle\n"
312 "\t7 call set volume level 0-5\n"
313 "\t8 call get volume\n"
314 "\t9 call dtmf\n"
315 "\t10 call deinit\n"
316 "operator: >> \n");
317
b.liu86b7ff22024-04-03 14:25:55 +0800318 while(1)
319 {
b.liu86b7ff22024-04-03 14:25:55 +0800320 fgets(operator, sizeof(operator), stdin);
321 fflush(stdin);
322 opt = atoi(operator);
323 switch (opt)
324 {
325 case 0:
326 printf("main exit\n");
327 return 0;
328 case 1:
329 qser_voice_call_client_init(&handle);
330 printf("test>>: handle = %d\n",handle);
331 break;
332 case 2:
333 qser_voice_call_addstatehandler(handle, yk_voice_call_cb_func, &voice_call_id);
334 break;
335 case 3:
336 qser_voice_call_start(handle, E_QSER_VCALL_EXTERNAL_SLOT_1, "18981904623", &voice_call_id);//被叫电话
337 break;
338 case 4:
339 qser_voice_call_end(handle, voice_call_id);
340 break;
341 case 5:
r.xiaod5764fb2024-04-07 00:30:29 -0700342 qser_voice_call_answer(handle, voice_call_id);
b.liu86b7ff22024-04-03 14:25:55 +0800343 break;
344 case 6:
345 qser_voice_call_removestatehandle(handle);
346 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 }
360 break;
361 case 8:
362 qser_voice_get_speech_volume(&lv_voll);
363 printf("volume level = %d\n",lv_voll);
364 break;
365 case 9:
r.xiaoba8483c2024-04-14 18:53:10 -0700366 {
367 char inputChar;
368
369 printf("Enter set dtmf\n");
370 scanf(" %c", &inputChar);
371 printf("inputChar is %c\n", inputChar);
372
373 if (qser_voice_set_dtmf(inputChar) != 0)
374 {
375 printf("qser set voice dtmf failed\n");
376 }
377 }
378 break;
379 case 10:
b.liu86b7ff22024-04-03 14:25:55 +0800380 qser_voice_call_client_deinit(handle);
381 break;
382 default:
383 break;
384 }
385
386 }
387
388 return 0;
389}
390
391#endif
392