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 | |
| 22 | |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 23 | static pthread_t s_lynq_voice_tid = -1; |
| 24 | static QSER_VoiceCall_StateHandlerFunc_t s_voice_cb = NULL; |
| 25 | static int s_voice_thread_status = 0; |
| 26 | |
| 27 | typedef enum { |
| 28 | LYNQ_CALL_ACTIVE = 0, |
| 29 | LYNQ_CALL_HOLDING = 1, |
| 30 | LYNQ_CALL_DIALING = 2, /* MO call only */ |
| 31 | LYNQ_CALL_ALERTING = 3, /* MO call only */ |
| 32 | LYNQ_CALL_INCOMING = 4, /* MT call only */ |
| 33 | LYNQ_CALL_WAITING = 5, /* MT call only */ |
| 34 | /*warren add for T800 platform 2022/04/26 start*/ |
| 35 | LYNQ_CALL_END = 6, /*CALL END*/ |
| 36 | /*warren add for T800 platform 2022/04/26 end*/ |
| 37 | }lynq_call_state_t; |
| 38 | |
| 39 | |
| 40 | void *voice_thread_recv(void *context) |
| 41 | { |
| 42 | int handle = 0; |
| 43 | int call_state; |
| 44 | int toa; |
| 45 | int direction; |
| 46 | char addr[64]; |
| 47 | E_QSER_VOICE_CALL_STATE_T voice_state; |
| 48 | while (s_voice_thread_status) |
| 49 | { |
| 50 | lynq_wait_call_state_change(&handle); |
l.yang | 3025489 | 2023-09-18 10:35:05 +0800 | [diff] [blame] | 51 | if(s_voice_thread_status == 0) |
| 52 | { |
| 53 | return NULL; |
| 54 | } |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 55 | lynq_get_current_call_state(&handle,&call_state,&toa,&direction,addr); |
| 56 | if (call_state == LYNQ_CALL_ACTIVE) |
| 57 | { |
| 58 | voice_state = E_QSER_VOICE_CALL_STATE_ACTIVE; |
| 59 | } |
| 60 | else if(call_state == LYNQ_CALL_HOLDING) |
| 61 | { |
| 62 | voice_state = E_QSER_VOICE_CALL_STATE_HOLDING; |
| 63 | } |
| 64 | else if(call_state == LYNQ_CALL_DIALING) |
| 65 | { |
| 66 | voice_state = E_QSER_VOICE_CALL_STATE_DIALING; |
| 67 | } |
| 68 | else if(call_state == LYNQ_CALL_ALERTING) |
| 69 | { |
| 70 | voice_state = E_QSER_VOICE_CALL_STATE_ALERTING; |
| 71 | } |
| 72 | else if(call_state == LYNQ_CALL_INCOMING) |
| 73 | { |
| 74 | voice_state = E_QSER_VOICE_CALL_STATE_INCOMING; |
| 75 | } |
| 76 | else if(call_state == LYNQ_CALL_WAITING) |
| 77 | { |
| 78 | voice_state = E_QSER_VOICE_CALL_STATE_WAITING; |
| 79 | } |
| 80 | else if(call_state == LYNQ_CALL_END) |
| 81 | { |
| 82 | voice_state = E_QSER_VOICE_CALL_STATE_END; |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | LYERRLOG("unknow call state"); |
| 87 | continue; |
| 88 | } |
| 89 | if (s_voice_cb != NULL) |
| 90 | { |
| 91 | s_voice_cb(handle,addr,voice_state,context); |
| 92 | } |
| 93 | } |
| 94 | return NULL; |
| 95 | } |
| 96 | |
| 97 | int qser_voice_call_client_init(voice_client_handle_type *ph_voice) |
| 98 | { |
| 99 | if(NULL == ph_voice) |
| 100 | { |
| 101 | LYERRLOG("input error"); |
| 102 | return RESULT_ERROR; |
| 103 | } |
| 104 | *ph_voice = (voice_client_handle_type)getpid(); |
| 105 | return lynq_init_call(*ph_voice); |
| 106 | } |
| 107 | |
| 108 | int qser_voice_call_client_deinit(voice_client_handle_type h_voice) |
| 109 | { |
l.yang | 6f13136 | 2023-07-25 09:45:37 +0800 | [diff] [blame] | 110 | if (0 == h_voice) |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 111 | { |
| 112 | LYERRLOG("init first"); |
| 113 | return RESULT_ERROR; |
| 114 | } |
| 115 | return lynq_deinit_call(); |
| 116 | } |
| 117 | |
| 118 | int qser_voice_call_addstatehandler(voice_client_handle_type h_voice, |
| 119 | QSER_VoiceCall_StateHandlerFunc_t handlerPtr, |
| 120 | void* contextPtr) |
| 121 | { |
| 122 | if(h_voice == 0 || handlerPtr== NULL) |
| 123 | { |
| 124 | LYERRLOG("input error"); |
| 125 | return RESULT_ERROR; |
| 126 | } |
| 127 | if (s_voice_cb != NULL) |
| 128 | { |
| 129 | LYERRLOG("The existing state handle does not need to be added"); |
| 130 | return RESULT_ERROR; |
| 131 | } |
| 132 | s_voice_cb = handlerPtr; |
| 133 | s_voice_thread_status = 1; |
| 134 | int rt = pthread_create(&s_lynq_voice_tid, NULL, voice_thread_recv, contextPtr); |
| 135 | if(rt < 0) |
| 136 | { |
| 137 | LYDBGLOG("qser_voice_call_addstatehandler pthread_create error!!!\n"); |
| 138 | s_voice_cb = NULL; |
| 139 | s_voice_thread_status = 0; |
| 140 | s_lynq_voice_tid = -1; |
| 141 | return RESULT_ERROR; |
| 142 | } |
| 143 | return RESULT_OK; |
| 144 | } |
| 145 | |
| 146 | int qser_voice_call_removestatehandle(voice_client_handle_type h_voice) |
| 147 | { |
l.yang | 3025489 | 2023-09-18 10:35:05 +0800 | [diff] [blame] | 148 | |
| 149 | LYINFLOG("Enter removestatehandle !!!"); |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 150 | s_voice_thread_status = 0; |
l.yang | 3025489 | 2023-09-18 10:35:05 +0800 | [diff] [blame] | 151 | if(s_lynq_voice_tid != -1) |
| 152 | { |
| 153 | lynq_release_wait_call(); |
| 154 | } |
| 155 | |
l.yang | 6f13136 | 2023-07-25 09:45:37 +0800 | [diff] [blame] | 156 | s_voice_cb = NULL; |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 157 | return RESULT_OK; |
| 158 | } |
| 159 | |
| 160 | int qser_voice_call_start(voice_client_handle_type h_voice, |
| 161 | E_QSER_VCALL_ID_T simId, |
| 162 | char* phone_number, |
| 163 | int *call_id) |
| 164 | { |
| 165 | if(h_voice == 0 || NULL == phone_number || NULL == call_id) |
| 166 | { |
| 167 | LYERRLOG("qser_voice_call_start input error"); |
| 168 | return RESULT_ERROR; |
| 169 | } |
| 170 | return lynq_call(call_id,phone_number); |
| 171 | } |
| 172 | |
| 173 | int qser_voice_call_end(voice_client_handle_type h_voice,int call_id) |
| 174 | { |
| 175 | if(h_voice == 0 || call_id <= 0) |
| 176 | { |
| 177 | LYERRLOG("qser_voice_call_end input error"); |
| 178 | return RESULT_ERROR; |
| 179 | } |
| 180 | return lynq_call_hungup(&call_id); |
| 181 | } |
| 182 | |
| 183 | int qser_voice_call_answer(voice_client_handle_type h_voice,int call_id) |
| 184 | { |
| 185 | if(h_voice == 0 || call_id <= 0) |
| 186 | { |
| 187 | LYERRLOG("qser_voice_call_answer input error"); |
| 188 | return RESULT_ERROR; |
| 189 | } |
| 190 | return lynq_call_answer(); |
| 191 | } |
| 192 | |
l.yang | 6f13136 | 2023-07-25 09:45:37 +0800 | [diff] [blame] | 193 | 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] | 194 | { |
| 195 | LYINFLOG("To be completed"); |
| 196 | return RESULT_OK; |
| 197 | } |
| 198 | |
| 199 | int qser_voice_call_setwaiting(int h_voice, qser_voice_call_waiting_service_t e_service) |
| 200 | { |
| 201 | LYINFLOG("To be completed"); |
| 202 | return RESULT_OK; |
| 203 | } |
| 204 | |
l.yang | 8e8d528 | 2023-06-15 10:48:26 +0800 | [diff] [blame] | 205 | |
l.yang | 6f13136 | 2023-07-25 09:45:37 +0800 | [diff] [blame] | 206 | 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] | 207 | { |
| 208 | if (h_voice == 0) |
| 209 | { |
| 210 | LYERRLOG("init first"); |
| 211 | return RESULT_ERROR; |
| 212 | } |
| 213 | return lynq_switch_waiting_or_holding_and_active(); |
you.chen | 21c62b7 | 2023-09-08 09:41:11 +0800 | [diff] [blame] | 214 | } |
| 215 | |
l.yang | 6f3f70b | 2023-09-08 13:33:58 +0800 | [diff] [blame] | 216 | int qser_voice_set_speech_volume(const int volume) |
| 217 | { |
| 218 | if(volume < MIN_VOLUME || volume > MAX_VOLUME) |
| 219 | { |
| 220 | LYERRLOG("Illeage input volume"); |
| 221 | return RESULT_ERROR; |
| 222 | } |
| 223 | return lynq_set_speech_volume(volume); |
| 224 | } |
| 225 | |
| 226 | |
| 227 | int qser_voice_get_speech_volume(int *volume) |
| 228 | { |
| 229 | return lynq_get_speech_volume(volume); |
| 230 | } |
| 231 | |
you.chen | 21c62b7 | 2023-09-08 09:41:11 +0800 | [diff] [blame] | 232 | DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_CALL) |
| 233 | |