l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <stdint.h> |
| 4 | #include <string.h> |
| 5 | #include <errno.h> |
| 6 | #include <unistd.h> |
| 7 | #include <liblog/lynq_deflog.h> |
| 8 | #include <sys/types.h> |
| 9 | #include <pthread.h> |
| 10 | #include <libcall/lynq_call.h> |
| 11 | |
| 12 | #include "lynq-qser-voice.h" |
| 13 | |
| 14 | #define USER_LOG_TAG "LYNQ_QSER_CALL" |
| 15 | |
| 16 | #define RESULT_OK (0) |
| 17 | #define RESULT_ERROR (-1) |
| 18 | |
l.yang | 6f3f70b | 2023-09-08 13:33:58 +0800 | [diff] [blame] | 19 | #define MIN_VOLUME 0 |
| 20 | #define MAX_VOLUME 5 |
| 21 | |
q.huang | 0d2cbed | 2024-03-28 10:50:55 +0800 | [diff] [blame] | 22 | #ifdef ECALL_SUPPORT |
| 23 | static pthread_t s_lynq_ecall_tid = -1; |
| 24 | static QSER_ECall_IndHandlerFunc_t s_ecall_cb = NULL; |
| 25 | static int s_ecall_thread_status = 0; |
| 26 | #endif |
l.yang | 6f3f70b | 2023-09-08 13:33:58 +0800 | [diff] [blame] | 27 | |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 28 | static pthread_t s_lynq_voice_tid = -1; |
| 29 | static QSER_VoiceCall_StateHandlerFunc_t s_voice_cb = NULL; |
| 30 | static int s_voice_thread_status = 0; |
| 31 | |
| 32 | typedef enum { |
| 33 | LYNQ_CALL_ACTIVE = 0, |
| 34 | LYNQ_CALL_HOLDING = 1, |
| 35 | LYNQ_CALL_DIALING = 2, /* MO call only */ |
| 36 | LYNQ_CALL_ALERTING = 3, /* MO call only */ |
| 37 | LYNQ_CALL_INCOMING = 4, /* MT call only */ |
| 38 | LYNQ_CALL_WAITING = 5, /* MT call only */ |
| 39 | /*warren add for T800 platform 2022/04/26 start*/ |
| 40 | LYNQ_CALL_END = 6, /*CALL END*/ |
| 41 | /*warren add for T800 platform 2022/04/26 end*/ |
| 42 | }lynq_call_state_t; |
| 43 | |
| 44 | |
| 45 | void *voice_thread_recv(void *context) |
| 46 | { |
| 47 | int handle = 0; |
l.yang | 58be67c | 2025-02-28 14:10:31 +0800 | [diff] [blame] | 48 | int call_state = -1; |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 49 | int toa; |
| 50 | int direction; |
| 51 | char addr[64]; |
| 52 | E_QSER_VOICE_CALL_STATE_T voice_state; |
| 53 | while (s_voice_thread_status) |
| 54 | { |
| 55 | lynq_wait_call_state_change(&handle); |
l.yang | 3025489 | 2023-09-18 10:35:05 +0800 | [diff] [blame] | 56 | if(s_voice_thread_status == 0) |
| 57 | { |
| 58 | return NULL; |
| 59 | } |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 60 | lynq_get_current_call_state(&handle,&call_state,&toa,&direction,addr); |
| 61 | if (call_state == LYNQ_CALL_ACTIVE) |
| 62 | { |
| 63 | voice_state = E_QSER_VOICE_CALL_STATE_ACTIVE; |
| 64 | } |
| 65 | else if(call_state == LYNQ_CALL_HOLDING) |
| 66 | { |
| 67 | voice_state = E_QSER_VOICE_CALL_STATE_HOLDING; |
| 68 | } |
| 69 | else if(call_state == LYNQ_CALL_DIALING) |
| 70 | { |
| 71 | voice_state = E_QSER_VOICE_CALL_STATE_DIALING; |
| 72 | } |
| 73 | else if(call_state == LYNQ_CALL_ALERTING) |
| 74 | { |
| 75 | voice_state = E_QSER_VOICE_CALL_STATE_ALERTING; |
| 76 | } |
| 77 | else if(call_state == LYNQ_CALL_INCOMING) |
| 78 | { |
| 79 | voice_state = E_QSER_VOICE_CALL_STATE_INCOMING; |
| 80 | } |
| 81 | else if(call_state == LYNQ_CALL_WAITING) |
| 82 | { |
| 83 | voice_state = E_QSER_VOICE_CALL_STATE_WAITING; |
| 84 | } |
| 85 | else if(call_state == LYNQ_CALL_END) |
| 86 | { |
| 87 | voice_state = E_QSER_VOICE_CALL_STATE_END; |
| 88 | } |
| 89 | else |
| 90 | { |
l.yang | 58be67c | 2025-02-28 14:10:31 +0800 | [diff] [blame] | 91 | LYERRLOG("unknow call state %d",call_state); |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 92 | continue; |
| 93 | } |
| 94 | if (s_voice_cb != NULL) |
| 95 | { |
| 96 | s_voice_cb(handle,addr,voice_state,context); |
| 97 | } |
| 98 | } |
| 99 | return NULL; |
| 100 | } |
| 101 | |
| 102 | int qser_voice_call_client_init(voice_client_handle_type *ph_voice) |
| 103 | { |
| 104 | if(NULL == ph_voice) |
| 105 | { |
| 106 | LYERRLOG("input error"); |
| 107 | return RESULT_ERROR; |
| 108 | } |
| 109 | *ph_voice = (voice_client_handle_type)getpid(); |
| 110 | return lynq_init_call(*ph_voice); |
| 111 | } |
| 112 | |
| 113 | int qser_voice_call_client_deinit(voice_client_handle_type h_voice) |
| 114 | { |
l.yang | 6f13136 | 2023-07-25 09:45:37 +0800 | [diff] [blame] | 115 | if (0 == h_voice) |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 116 | { |
| 117 | LYERRLOG("init first"); |
| 118 | return RESULT_ERROR; |
| 119 | } |
q.huang | 0d2cbed | 2024-03-28 10:50:55 +0800 | [diff] [blame] | 120 | |
| 121 | |
| 122 | #ifdef ECALL_SUPPORT |
| 123 | s_ecall_thread_status = 0; |
| 124 | |
| 125 | if(s_lynq_ecall_tid!=-1) |
| 126 | { |
| 127 | int ret = pthread_cancel(s_lynq_ecall_tid); |
| 128 | LYINFLOG("pthread cancel waiting urc thread, ret = %d",ret); |
| 129 | |
| 130 | ret = pthread_join(s_lynq_ecall_tid,NULL); |
| 131 | LYINFLOG("pthread join waiting urc thread ret = %d",ret); |
| 132 | s_lynq_ecall_tid =-1; |
| 133 | } |
| 134 | |
| 135 | s_ecall_cb=NULL; |
| 136 | #endif |
| 137 | |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 138 | return lynq_deinit_call(); |
| 139 | } |
| 140 | |
| 141 | int qser_voice_call_addstatehandler(voice_client_handle_type h_voice, |
| 142 | QSER_VoiceCall_StateHandlerFunc_t handlerPtr, |
| 143 | void* contextPtr) |
| 144 | { |
| 145 | if(h_voice == 0 || handlerPtr== NULL) |
| 146 | { |
| 147 | LYERRLOG("input error"); |
| 148 | return RESULT_ERROR; |
| 149 | } |
| 150 | if (s_voice_cb != NULL) |
| 151 | { |
| 152 | LYERRLOG("The existing state handle does not need to be added"); |
| 153 | return RESULT_ERROR; |
| 154 | } |
| 155 | s_voice_cb = handlerPtr; |
| 156 | s_voice_thread_status = 1; |
| 157 | int rt = pthread_create(&s_lynq_voice_tid, NULL, voice_thread_recv, contextPtr); |
| 158 | if(rt < 0) |
| 159 | { |
| 160 | LYDBGLOG("qser_voice_call_addstatehandler pthread_create error!!!\n"); |
| 161 | s_voice_cb = NULL; |
| 162 | s_voice_thread_status = 0; |
| 163 | s_lynq_voice_tid = -1; |
| 164 | return RESULT_ERROR; |
| 165 | } |
| 166 | return RESULT_OK; |
| 167 | } |
| 168 | |
| 169 | int qser_voice_call_removestatehandle(voice_client_handle_type h_voice) |
| 170 | { |
l.yang | 3025489 | 2023-09-18 10:35:05 +0800 | [diff] [blame] | 171 | |
| 172 | LYINFLOG("Enter removestatehandle !!!"); |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 173 | s_voice_thread_status = 0; |
l.yang | 3025489 | 2023-09-18 10:35:05 +0800 | [diff] [blame] | 174 | if(s_lynq_voice_tid != -1) |
| 175 | { |
| 176 | lynq_release_wait_call(); |
| 177 | } |
| 178 | |
l.yang | 6f13136 | 2023-07-25 09:45:37 +0800 | [diff] [blame] | 179 | s_voice_cb = NULL; |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 180 | return RESULT_OK; |
| 181 | } |
| 182 | |
| 183 | int qser_voice_call_start(voice_client_handle_type h_voice, |
| 184 | E_QSER_VCALL_ID_T simId, |
| 185 | char* phone_number, |
| 186 | int *call_id) |
| 187 | { |
| 188 | if(h_voice == 0 || NULL == phone_number || NULL == call_id) |
| 189 | { |
| 190 | LYERRLOG("qser_voice_call_start input error"); |
| 191 | return RESULT_ERROR; |
| 192 | } |
| 193 | return lynq_call(call_id,phone_number); |
| 194 | } |
| 195 | |
| 196 | int qser_voice_call_end(voice_client_handle_type h_voice,int call_id) |
| 197 | { |
| 198 | if(h_voice == 0 || call_id <= 0) |
| 199 | { |
| 200 | LYERRLOG("qser_voice_call_end input error"); |
| 201 | return RESULT_ERROR; |
| 202 | } |
| 203 | return lynq_call_hungup(&call_id); |
| 204 | } |
| 205 | |
| 206 | int qser_voice_call_answer(voice_client_handle_type h_voice,int call_id) |
| 207 | { |
| 208 | if(h_voice == 0 || call_id <= 0) |
| 209 | { |
| 210 | LYERRLOG("qser_voice_call_answer input error"); |
| 211 | return RESULT_ERROR; |
| 212 | } |
| 213 | return lynq_call_answer(); |
| 214 | } |
| 215 | |
l.yang | 6f13136 | 2023-07-25 09:45:37 +0800 | [diff] [blame] | 216 | int qser_voice_call_getwaitingstatus(int h_voice,qser_voice_call_waiting_service_t *pe_service) |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 217 | { |
| 218 | LYINFLOG("To be completed"); |
| 219 | return RESULT_OK; |
| 220 | } |
| 221 | |
| 222 | int qser_voice_call_setwaiting(int h_voice, qser_voice_call_waiting_service_t e_service) |
| 223 | { |
| 224 | LYINFLOG("To be completed"); |
| 225 | return RESULT_OK; |
| 226 | } |
| 227 | |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 228 | |
l.yang | 6f13136 | 2023-07-25 09:45:37 +0800 | [diff] [blame] | 229 | int qser_voice_call_switch_waiting_or_holding_and_active(voice_client_handle_type h_voice) |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 230 | { |
| 231 | if (h_voice == 0) |
| 232 | { |
| 233 | LYERRLOG("init first"); |
| 234 | return RESULT_ERROR; |
| 235 | } |
| 236 | return lynq_switch_waiting_or_holding_and_active(); |
you.chen | 21c62b7 | 2023-09-08 09:41:11 +0800 | [diff] [blame] | 237 | } |
| 238 | |
l.yang | 6f3f70b | 2023-09-08 13:33:58 +0800 | [diff] [blame] | 239 | int qser_voice_set_speech_volume(const int volume) |
| 240 | { |
| 241 | if(volume < MIN_VOLUME || volume > MAX_VOLUME) |
| 242 | { |
| 243 | LYERRLOG("Illeage input volume"); |
| 244 | return RESULT_ERROR; |
| 245 | } |
| 246 | return lynq_set_speech_volume(volume); |
| 247 | } |
| 248 | |
| 249 | |
| 250 | int qser_voice_get_speech_volume(int *volume) |
| 251 | { |
| 252 | return lynq_get_speech_volume(volume); |
| 253 | } |
| 254 | |
l.yang | af69e4b | 2023-12-27 19:42:49 +0800 | [diff] [blame] | 255 | int qser_voice_set_dtmf(const char callnum) |
| 256 | { |
| 257 | return lynq_set_DTMF(callnum); |
| 258 | |
| 259 | } |
| 260 | |
q.huang | 846ba97 | 2024-09-20 12:00:44 +0800 | [diff] [blame] | 261 | int qser_voice_set_audio_mode(const E_QSER_VOICE_CALL_AUDIO_MODE_T audio_mode) |
| 262 | { |
| 263 | return lynq_set_voice_audio_mode((LYNQ_Audio_Mode) audio_mode); |
| 264 | } |
| 265 | |
| 266 | int qser_voice_get_audio_mode(E_QSER_VOICE_CALL_AUDIO_MODE_T* audio_mode) |
| 267 | { |
| 268 | return lynq_get_voice_audio_mode((LYNQ_Audio_Mode*) audio_mode ); |
| 269 | } |
| 270 | |
l.yang | 59a9c66 | 2025-02-27 16:28:02 +0800 | [diff] [blame] | 271 | int qser_voice_set_mic_volume(const int volume) |
| 272 | { |
| 273 | if(volume < MIN_VOLUME || volume > MAX_VOLUME) |
| 274 | { |
| 275 | LYERRLOG("Illeage inpu volume"); |
| 276 | return RESULT_ERROR; |
| 277 | } |
| 278 | return lynq_set_mic_input_volume(volume); |
| 279 | } |
| 280 | |
| 281 | |
| 282 | int qser_voice_get_mic_volume(int *volume) |
| 283 | { |
| 284 | return lynq_get_mic_input_volume(volume); |
| 285 | } |
| 286 | |
q.huang | 846ba97 | 2024-09-20 12:00:44 +0800 | [diff] [blame] | 287 | |
l.yang | b0559f5 | 2025-03-18 15:21:40 +0800 | [diff] [blame] | 288 | int qser_voice_get_current_state(const int call_id,int *voice_state) |
| 289 | { |
| 290 | int ret = -1; |
| 291 | int call_state = -1; |
| 292 | int toa = -1; |
| 293 | int direction = -1; |
| 294 | char addr[64] = {0}; |
| 295 | |
| 296 | |
| 297 | if(voice_state == NULL) |
| 298 | { |
| 299 | LYERRLOG("Invalid input pointer. call_id or voice_state is NULL"); |
| 300 | return RESULT_ERROR; |
| 301 | } |
| 302 | |
| 303 | if(call_id <= 0) |
| 304 | { |
| 305 | LYERRLOG(" Invalid call id %d",call_id); |
| 306 | return RESULT_ERROR; |
| 307 | } |
| 308 | |
| 309 | ret = lynq_get_current_call_state(&call_id,&call_state,&toa,&direction,addr); |
| 310 | if(ret != 0) |
| 311 | { |
| 312 | LYERRLOG("qser_get_current_call_state ret is %d",ret); |
| 313 | return RESULT_ERROR; |
| 314 | } |
| 315 | |
| 316 | if (call_state == LYNQ_CALL_ACTIVE) |
| 317 | { |
| 318 | *voice_state = E_QSER_VOICE_CALL_STATE_ACTIVE; |
| 319 | } |
| 320 | else if(call_state == LYNQ_CALL_HOLDING) |
| 321 | { |
| 322 | *voice_state = E_QSER_VOICE_CALL_STATE_HOLDING; |
| 323 | } |
| 324 | else if(call_state == LYNQ_CALL_DIALING) |
| 325 | { |
| 326 | *voice_state = E_QSER_VOICE_CALL_STATE_DIALING; |
| 327 | } |
| 328 | else if(call_state == LYNQ_CALL_ALERTING) |
| 329 | { |
| 330 | *voice_state = E_QSER_VOICE_CALL_STATE_ALERTING; |
| 331 | } |
| 332 | else if(call_state == LYNQ_CALL_INCOMING) |
| 333 | { |
| 334 | *voice_state = E_QSER_VOICE_CALL_STATE_INCOMING; |
| 335 | } |
| 336 | else if(call_state == LYNQ_CALL_WAITING) |
| 337 | { |
| 338 | *voice_state = E_QSER_VOICE_CALL_STATE_WAITING; |
| 339 | } |
| 340 | else if(call_state == LYNQ_CALL_END) |
| 341 | { |
| 342 | *voice_state = E_QSER_VOICE_CALL_STATE_END; |
| 343 | } |
| 344 | |
| 345 | return ret; |
| 346 | } |
| 347 | |
q.huang | 846ba97 | 2024-09-20 12:00:44 +0800 | [diff] [blame] | 348 | |
q.huang | 0d2cbed | 2024-03-28 10:50:55 +0800 | [diff] [blame] | 349 | #ifdef ECALL_SUPPORT |
| 350 | int qser_voice_fast_ecall(voice_client_handle_type* h_voice, |
| 351 | int *call_id, |
| 352 | E_QSER_VOICE_ECALL_CATEGORY_T cat, |
| 353 | E_QSER_VOICE_ECALL_VARIANT_T variant, |
| 354 | const char *addr, |
| 355 | int addr_length, |
| 356 | const unsigned char *msd_data, |
| 357 | int msd_length) |
| 358 | { |
| 359 | if(h_voice == NULL || (*h_voice) == 0 ) |
| 360 | { |
| 361 | LYERRLOG("%s input error", __func__); |
| 362 | return RESULT_ERROR; |
| 363 | } |
| 364 | |
| 365 | return lynq_fast_ecall(call_id,(LYNQ_ECall_Category) cat,(LYNQ_ECall_Variant) variant,addr,addr_length,msd_data,msd_length); |
| 366 | } |
| 367 | |
| 368 | int qser_voice_set_test_num(voice_client_handle_type* h_voice,E_QSER_VOICE_ECALL_SET_TYPE_T type, const char *test_num, int test_num_length) |
| 369 | { |
| 370 | if(h_voice == NULL || (*h_voice) == 0 ) |
| 371 | { |
| 372 | LYERRLOG("%s input error", __func__); |
| 373 | return RESULT_ERROR; |
| 374 | } |
| 375 | |
| 376 | return lynq_set_test_num((LYNQ_ECall_Set_Type) type, test_num, test_num_length); |
| 377 | } |
| 378 | |
| 379 | int qser_voice_set_msd(int callid, const unsigned char *msd_data, int msd_length) |
| 380 | { |
q.huang | 61de79a | 2024-08-27 21:54:12 +0800 | [diff] [blame] | 381 | return lynq_set_msd(&callid, msd_data, msd_length); |
q.huang | 0d2cbed | 2024-03-28 10:50:55 +0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void *ecall_thread_recv(void *context) |
| 385 | { |
| 386 | int handle = 0; |
| 387 | LYNQ_ECall_Indication eCall_Indication; |
| 388 | while (s_ecall_thread_status) |
| 389 | { |
| 390 | lynq_wait_ecall_indication(&handle, &eCall_Indication); |
| 391 | if(s_ecall_thread_status == 0) |
| 392 | { |
| 393 | return NULL; |
| 394 | } |
| 395 | |
| 396 | if (s_ecall_cb != NULL) |
| 397 | { |
q.huang | da55a99 | 2024-04-17 18:27:57 +0800 | [diff] [blame] | 398 | s_ecall_cb(handle,(E_QSER_VOICE_ECALL_INDICATION_T) eCall_Indication,context); |
q.huang | 0d2cbed | 2024-03-28 10:50:55 +0800 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | return NULL; |
| 402 | } |
| 403 | |
| 404 | int qser_voice_add_ecall_indhandler(voice_client_handle_type* h_voice, |
| 405 | QSER_ECall_IndHandlerFunc_t handlerPtr, |
| 406 | void* contextPtr) |
| 407 | { |
| 408 | if(h_voice == NULL || (*h_voice) == 0 || handlerPtr== NULL) |
| 409 | { |
| 410 | LYERRLOG("input error"); |
| 411 | return RESULT_ERROR; |
| 412 | } |
| 413 | if (s_ecall_cb != NULL) |
| 414 | { |
| 415 | LYERRLOG("The existing state handle does not need to be added"); |
| 416 | return RESULT_ERROR; |
| 417 | } |
| 418 | s_ecall_cb = handlerPtr; |
| 419 | s_ecall_thread_status = 1; |
| 420 | int rt = pthread_create(&s_lynq_ecall_tid, NULL, ecall_thread_recv, contextPtr); |
| 421 | if(rt < 0) |
| 422 | { |
| 423 | LYDBGLOG("qser_voice_call_addstatehandler pthread_create error!!!\n"); |
| 424 | s_ecall_cb = NULL; |
| 425 | s_ecall_thread_status = 0; |
| 426 | s_lynq_ecall_tid = -1; |
| 427 | return RESULT_ERROR; |
| 428 | } |
| 429 | return RESULT_OK; |
| 430 | } |
| 431 | #endif |
| 432 | |
you.chen | 21c62b7 | 2023-09-08 09:41:11 +0800 | [diff] [blame] | 433 | DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_CALL) |
| 434 | |