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