b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame^] | 1 | #include <stdlib.h>
|
| 2 | #include <stdio.h>
|
| 3 | #include <string.h>
|
| 4 | #include <sys/types.h>
|
| 5 | #include <pthread.h>
|
| 6 | #include <unistd.h>
|
| 7 | #include <dlfcn.h>
|
| 8 | #include <stdint.h>
|
| 9 |
|
| 10 | #include"lynq-qser-voice-demo.h"
|
| 11 |
|
| 12 | typedef struct
|
| 13 | {
|
| 14 | int cmdIdx;
|
| 15 | char *funcName;
|
| 16 | } st_api_test_case;
|
| 17 |
|
| 18 | //for server test
|
| 19 | st_api_test_case at_api_testcases[] =
|
| 20 | {
|
| 21 | {0, "print_help"},
|
| 22 | {1, "qser_voice_call_start"},
|
| 23 | {2, "qser_voice_call_end"},
|
| 24 | {3, "qser_voice_call_answer"},
|
| 25 | {4, "qser_voice_set_speech_volume"},
|
| 26 | {5, "qser_voice_get_speech_volume"},
|
| 27 | {6, "qser_voice_set_dtmf"},
|
| 28 | {-1, NULL}
|
| 29 | };
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 | typedef uint32_t voice_client_handle_type;
|
| 34 |
|
| 35 |
|
| 36 | int (*qser_voice_call_client_init)(voice_client_handle_type *ph_voice);
|
| 37 | int (*qser_voice_call_client_deinit)(voice_client_handle_type );
|
| 38 | int (*qser_voice_call_addstatehandler)(voice_client_handle_type h_voice,
|
| 39 | QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
|
| 40 | void *contextPtr);
|
| 41 |
|
| 42 | int (*qser_voice_call_removestatehandle)(voice_client_handle_type );
|
| 43 | int (*qser_voice_call_start)(voice_client_handle_type h_voice,
|
| 44 | E_QSER_VCALL_ID_T simId,
|
| 45 | char *phone_number, int *call_id);
|
| 46 |
|
| 47 | int (*qser_voice_call_end)(voice_client_handle_type ,int );
|
| 48 | int (*qser_voice_call_answer)(voice_client_handle_type ,int );
|
| 49 | int (*qser_voice_set_speech_volume)(const int volume);
|
| 50 | int (*qser_voice_get_speech_volume)(int *volume);
|
| 51 | int (*qser_voice_set_dtmf)(const char callnum);
|
| 52 |
|
| 53 | void *dlHandle_call = NULL;
|
| 54 |
|
| 55 | static void yk_voice_call_cb_func(int call_id,
|
| 56 | char* phone_num,
|
| 57 | qser_voice_call_state_t state,
|
| 58 | void *contextPtr)
|
| 59 | {
|
| 60 | char *call_state[] = {"INCOMING", "DIALING", "ALERTING", "ACTIVE", "HOLDING", "END", "WAITING"};
|
| 61 |
|
| 62 | printf("######### Call id=%d, PhoneNum:%s, event=%s! ######\n", call_id, phone_num, call_state[state]);
|
| 63 | }
|
| 64 |
|
| 65 | void print_help(void)
|
| 66 | {
|
| 67 | int i;
|
| 68 | printf("Supported test cases:\n");
|
| 69 | for(i = 0; ; i++)
|
| 70 | {
|
| 71 | if(at_api_testcases[i].cmdIdx == -1)
|
| 72 | {
|
| 73 | break;
|
| 74 | }
|
| 75 | printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName);
|
| 76 | }
|
| 77 | }
|
| 78 |
|
| 79 | int main(int argc, char const *argv[])
|
| 80 | {
|
| 81 | int cmdIdx = 0;
|
| 82 | int ret = 0;
|
| 83 | int voice_call_id = 0;
|
| 84 | voice_client_handle_type h_voice = 0;
|
| 85 |
|
| 86 | const char *lynqLibPath_Call = "/lib/liblynq-qser-voice.so";
|
| 87 | dlHandle_call = dlopen(lynqLibPath_Call, RTLD_NOW);
|
| 88 | if (dlHandle_call == NULL)
|
| 89 | {
|
| 90 | printf("dlopen dlHandle_call failed: %s\n", dlerror());
|
| 91 | exit(EXIT_FAILURE);
|
| 92 | }
|
| 93 |
|
| 94 | qser_voice_call_client_init = (int(*)(voice_client_handle_type *ph_voice))dlsym(dlHandle_call, "qser_voice_call_client_init");
|
| 95 | if(qser_voice_call_client_init == NULL)
|
| 96 | {
|
| 97 | printf("qser_voice_call_client_init not defined or exported in %s\n", lynqLibPath_Call);
|
| 98 | return -1;
|
| 99 | }
|
| 100 |
|
| 101 | qser_voice_call_addstatehandler = (int(*)(voice_client_handle_type h_voice,
|
| 102 | QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
|
| 103 | void *contextPtr))dlsym(dlHandle_call,"qser_voice_call_addstatehandler");
|
| 104 | if(qser_voice_call_addstatehandler == NULL)
|
| 105 | {
|
| 106 | printf("qser_voice_call_addstatehandler not defined or exported in %s\n", lynqLibPath_Call);
|
| 107 | return -1;
|
| 108 | }
|
| 109 |
|
| 110 | qser_voice_call_answer = (int(*)(voice_client_handle_type,int ))dlsym(dlHandle_call,"qser_voice_call_answer");
|
| 111 | if(qser_voice_call_answer == NULL)
|
| 112 | {
|
| 113 | printf("qser_voice_call_answer not defined or exported in %s\n", lynqLibPath_Call);
|
| 114 | return -1;
|
| 115 | }
|
| 116 |
|
| 117 | qser_voice_call_start = (int(*)(voice_client_handle_type h_voice,E_QSER_VCALL_ID_T simId,
|
| 118 | char *phone_number, int *call_id))dlsym(dlHandle_call,"qser_voice_call_start");
|
| 119 | if(qser_voice_call_start == NULL)
|
| 120 | {
|
| 121 | printf("qser_voice_call_start not defined or exported in %s\n", lynqLibPath_Call);
|
| 122 | return -1;
|
| 123 | }
|
| 124 |
|
| 125 | qser_voice_call_end = (int(*)(voice_client_handle_type ,int))dlsym(dlHandle_call,"qser_voice_call_end");
|
| 126 | if(qser_voice_call_end == NULL)
|
| 127 | {
|
| 128 | printf("qser_voice_call_end not defined or exported in %s\n", lynqLibPath_Call);
|
| 129 | return -1;
|
| 130 | }
|
| 131 |
|
| 132 |
|
| 133 | qser_voice_call_client_deinit = (int (*)(voice_client_handle_type h_voice))dlsym(dlHandle_call,"qser_voice_call_client_deinit");
|
| 134 | if(qser_voice_call_client_deinit == NULL)
|
| 135 | {
|
| 136 | printf("qser_voice_call_client_deinit not defined or exported in %s\n", lynqLibPath_Call);
|
| 137 | return -1;
|
| 138 | }
|
| 139 |
|
| 140 | qser_voice_call_removestatehandle = (int (*)(voice_client_handle_type))dlsym(dlHandle_call,"qser_voice_call_removestatehandle");
|
| 141 | if(qser_voice_call_removestatehandle == NULL)
|
| 142 | {
|
| 143 | printf("qser_voice_call_removestatehandle not defined or exported in %s\n", lynqLibPath_Call);
|
| 144 | return -1;
|
| 145 | }
|
| 146 |
|
| 147 | qser_voice_set_speech_volume = (int (*)(const int ))dlsym(dlHandle_call,"qser_voice_set_speech_volume");
|
| 148 | if(qser_voice_set_speech_volume == NULL)
|
| 149 | {
|
| 150 | printf("qser_voice_set_speech_volume not defined or exported in %s\n", lynqLibPath_Call);
|
| 151 | return -1;
|
| 152 | }
|
| 153 |
|
| 154 | qser_voice_get_speech_volume = (int (*)(int* ))dlsym(dlHandle_call,"qser_voice_get_speech_volume");
|
| 155 | if(qser_voice_get_speech_volume == NULL)
|
| 156 | {
|
| 157 | printf("qser_voice_get_speech_volume not defined or exported in %s\n", lynqLibPath_Call);
|
| 158 | return -1;
|
| 159 | }
|
| 160 |
|
| 161 | qser_voice_set_dtmf = (int (*)(const char ))dlsym(dlHandle_call,"qser_voice_set_dtmf");
|
| 162 | if(qser_voice_set_dtmf == NULL)
|
| 163 | {
|
| 164 | printf("qser_voice_set_dtmf not defined or exported in %s\n", lynqLibPath_Call);
|
| 165 | return -1;
|
| 166 | }
|
| 167 |
|
| 168 | ret = qser_voice_call_client_init(&h_voice);
|
| 169 | if(ret != 0 )
|
| 170 | {
|
| 171 | printf("qser_voice_call_client_init FAIL\n");
|
| 172 | return -1;
|
| 173 | }
|
| 174 |
|
| 175 | ret = qser_voice_call_addstatehandler(h_voice, yk_voice_call_cb_func, &voice_call_id);
|
| 176 | if(ret != 0)
|
| 177 | {
|
| 178 | printf("qser_voice_call_addstatehandler FAIL\n");
|
| 179 | return -1;
|
| 180 | }
|
| 181 |
|
| 182 |
|
| 183 | print_help();
|
| 184 | while(1)
|
| 185 | {
|
| 186 | printf("\nplease input cmd index(-1 exit): ");
|
| 187 | scanf("%d", &cmdIdx);
|
| 188 | if(cmdIdx == -1)
|
| 189 | {
|
| 190 | break;
|
| 191 | }
|
| 192 |
|
| 193 | switch(cmdIdx)
|
| 194 | {
|
| 195 | //"print_help
|
| 196 | case 0:
|
| 197 | print_help();
|
| 198 | break;
|
| 199 |
|
| 200 | //"qser_voice_call_start"
|
| 201 | case 1:
|
| 202 | {
|
| 203 | char PhoneNum[32] = {0};
|
| 204 |
|
| 205 | printf("please input dest phone number: \n");
|
| 206 | scanf("%s", PhoneNum);
|
| 207 |
|
| 208 | ret = qser_voice_call_start(h_voice, E_QSER_VCALL_EXTERNAL_SLOT_1, PhoneNum, &voice_call_id);
|
| 209 | printf("qser_voice_call_start ret = %d, with voice_call_id=%d\n", ret, voice_call_id);
|
| 210 | break;
|
| 211 | }
|
| 212 |
|
| 213 | //"qser_voice_call_end"
|
| 214 | case 2:
|
| 215 | {
|
| 216 | int call_id = -1;
|
| 217 | printf("please input end call id: \n");
|
| 218 | scanf("%d", &call_id);
|
| 219 | ret = qser_voice_call_end(h_voice, call_id);
|
| 220 | printf(" ret = %d\n", ret);
|
| 221 | break;
|
| 222 | }
|
| 223 |
|
| 224 | //"qser_voice_call_answer"
|
| 225 | case 3:
|
| 226 | {
|
| 227 | int call_id = -1;
|
| 228 | printf(" please input answer call id\n");
|
| 229 | scanf("%d", &call_id);
|
| 230 | ret = qser_voice_call_answer(h_voice, call_id);
|
| 231 | printf(" ret = %d\n", ret);
|
| 232 | break;
|
| 233 | }
|
| 234 |
|
| 235 | case 4:
|
| 236 | {
|
| 237 | int volume = 0;
|
| 238 | printf("Please set speech volume:0-5 level\n");
|
| 239 | scanf("%d",&volume);
|
| 240 | ret = qser_voice_set_speech_volume(volume);
|
| 241 | printf("ret is %d\n",ret);
|
| 242 | break;
|
| 243 |
|
| 244 | }
|
| 245 |
|
| 246 | case 5:
|
| 247 | {
|
| 248 | int volume = -1;
|
| 249 | printf("Enter get speech volume\n");
|
| 250 | ret = qser_voice_get_speech_volume(&volume);
|
| 251 | printf("ret is %d,get volume is %d\n",ret,volume);
|
| 252 | break;
|
| 253 |
|
| 254 | }
|
| 255 | case 6:
|
| 256 | {
|
| 257 |
|
| 258 | int ret;
|
| 259 | char inputChar;
|
| 260 |
|
| 261 | printf("Enter set dtmf\n");
|
| 262 | scanf(" %c", &inputChar);
|
| 263 | printf("inputChar is %c\n", inputChar);
|
| 264 | ret = qser_voice_set_dtmf(inputChar);
|
| 265 |
|
| 266 | if (ret != 0)
|
| 267 | {
|
| 268 | printf("qser set voice dtmf failed\n");
|
| 269 | return -1;
|
| 270 | }
|
| 271 | break;
|
| 272 | }
|
| 273 |
|
| 274 | default:
|
| 275 | print_help();
|
| 276 | break;
|
| 277 | }
|
| 278 |
|
| 279 | }
|
| 280 |
|
| 281 | ret = qser_voice_call_removestatehandle(h_voice);
|
| 282 | if(ret != 0 && ret != 1)
|
| 283 | {
|
| 284 | printf("qser_voice_call_removestatehandle FAIL!!!\n");
|
| 285 | return -1;
|
| 286 | }
|
| 287 | printf("qser_voice_call_removestatehandle ret = %d\n", ret);
|
| 288 |
|
| 289 |
|
| 290 | ret = qser_voice_call_client_deinit(h_voice);
|
| 291 | if(ret != 0)
|
| 292 | {
|
| 293 | printf("qser_voice_call_client_deinit FAIL\n");
|
| 294 | return -1;
|
| 295 | }
|
| 296 | printf("qser_voice_call_client_deinit ret = %d, with h_voice=%d\n", ret, h_voice);
|
| 297 |
|
| 298 | return 0;
|
| 299 |
|
| 300 |
|
| 301 | }
|
| 302 |
|
| 303 |
|