xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /**
|
| 2 | * @file voice_api.c
|
| 3 | * @brief Implementation of the public APIs of libvoice.
|
| 4 | *
|
| 5 | * Copyright (C) 2023 Sanechips Technology Co., Ltd.
|
| 6 | * @author
|
| 7 | *
|
| 8 | * This program is free software; you can redistribute it and/or modify
|
| 9 | * it under the terms of the GNU General Public License version 2 as
|
| 10 | * published by the Free Software Foundation. £¨±ØÑ¡£ºGPLv2 Licence£©
|
| 11 | *
|
| 12 | */
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 | #include <stdio.h>
|
| 17 | #include <unistd.h>
|
| 18 | #include <string.h>
|
| 19 | #include <stdlib.h>
|
| 20 |
|
| 21 | #include <stdint.h>
|
| 22 | //#include "volte_drv.h"
|
| 23 | #include <linux/volte_drv.h>
|
| 24 |
|
| 25 | #include <sys/ioctl.h>
|
| 26 | #include <fcntl.h>
|
| 27 | #include <tinyalsa/audio_mixer_ctrl.h>
|
| 28 | #include "voice_lib.h"
|
| 29 |
|
| 30 | #define VOCIE_SND_CARD_NUM 0
|
| 31 |
|
| 32 |
|
| 33 | extern int mix_set_voice_vol(struct mixer *mixer, int volume);
|
| 34 | extern int mix_get_voice_vol(struct mixer *mixer, int *volume);
|
| 35 | extern int mix_set_tx_voice_vol(struct mixer *mixer, int volume);
|
| 36 | extern int mix_get_tx_voice_vol(struct mixer *mixer, int *volume);
|
| 37 | extern int mix_set_voice_mute(struct mixer *mixer, bool enable);
|
| 38 | extern int mix_get_voice_mute(struct mixer *mixer, int *enable);
|
| 39 | extern int mix_set_rx_voice_mute(struct mixer *mixer, bool enable);
|
| 40 | extern int mix_get_rx_voice_mute(struct mixer *mixer, int *enable);
|
| 41 | extern int mix_set_voice_path(struct mixer *mixer, int path);
|
| 42 | extern int mix_set_vp_path(struct mixer *mixer, char path);
|
| 43 | extern int mix_get_vp_path(struct mixer *mixer, int *path);
|
| 44 | extern int mix_get_voice_path(struct mixer *mixer, int *path);
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 | #define VOCIE_SND_CARD_NUM 0
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 | //设置voiceé³é¢è®¾å¤æ¨¡å¼ dev_modeï¼handset,speaker,headset 0 表示æåï¼?å
¶å®è¡¨ç¤ºæéè¯?
|
| 53 | int set_voice_device_mode(int dev_mode)
|
| 54 | {
|
| 55 |
|
| 56 | struct mixer *voice_mixer = NULL;
|
| 57 | printf("%s: start dev_mode=%d!\n",__func__, dev_mode);
|
| 58 |
|
| 59 | if ((dev_mode < T_OUTPUT_HANDSET ) ||(dev_mode >= T_OUTPUT_MAX)){
|
| 60 | printf("%s: dev_mode not support, dev_mode=%d!\n",__func__, dev_mode);
|
| 61 | return -1;
|
| 62 | }
|
| 63 |
|
| 64 | //open mixer dev for control
|
| 65 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 66 | if (!voice_mixer) {
|
| 67 | printf("voice_mixer open failed!\n");
|
| 68 | return -1;
|
| 69 | }
|
| 70 |
|
| 71 | //config mixer dev
|
| 72 | mix_set_voice_path(voice_mixer, dev_mode);
|
| 73 |
|
| 74 | //close mixer
|
| 75 | mixer_close(voice_mixer);
|
| 76 | voice_mixer = NULL;
|
| 77 |
|
| 78 |
|
| 79 | return 0;
|
| 80 |
|
| 81 |
|
| 82 | }
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 | int sc_audio_set_voice_device_mode(int dev_mode)
|
| 87 | {
|
| 88 |
|
| 89 | struct mixer *voice_mixer = NULL;
|
| 90 | printf("%s: start dev_mode=%d!\n",__func__, dev_mode);
|
| 91 |
|
| 92 | if ((dev_mode < T_OUTPUT_HANDSET ) ||(dev_mode >= T_OUTPUT_MAX)){
|
| 93 | printf("%s: dev_mode not support, dev_mode=%d!\n",__func__, dev_mode);
|
| 94 | return -1;
|
| 95 | }
|
| 96 |
|
| 97 | //open mixer dev for control
|
| 98 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 99 | if (!voice_mixer) {
|
| 100 | printf("voice_mixer open failed!\n");
|
| 101 | return -1;
|
| 102 | }
|
| 103 | #ifdef _ALSA_CODEC_IN_CAP
|
| 104 | mix_set_vp_path(voice_mixer,dev_mode);
|
| 105 |
|
| 106 | #else
|
| 107 | //config mixer dev
|
| 108 | mix_set_voice_path(voice_mixer, dev_mode);
|
| 109 | #endif
|
| 110 |
|
| 111 |
|
| 112 | //close mixer
|
| 113 | mixer_close(voice_mixer);
|
| 114 | voice_mixer = NULL;
|
| 115 |
|
| 116 |
|
| 117 | return 0;
|
| 118 |
|
| 119 |
|
| 120 | }
|
| 121 |
|
| 122 |
|
| 123 | int sc_audio_get_voice_device_mode(int *p_dev_mode)
|
| 124 | {
|
| 125 | struct mixer *voice_mixer = NULL;
|
| 126 | printf("%s: start!\n",__func__);
|
| 127 |
|
| 128 | //open mixer dev for control
|
| 129 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 130 | if (!voice_mixer) {
|
| 131 | printf("voice_mixer open failed!\n");
|
| 132 | return -1;
|
| 133 | }
|
| 134 |
|
| 135 | //config mixer dev
|
| 136 | mix_get_vp_path(voice_mixer, p_dev_mode);
|
| 137 |
|
| 138 |
|
| 139 | if((*p_dev_mode < T_OUTPUT_HANDSET ) ||(*p_dev_mode >= T_OUTPUT_MAX)){
|
| 140 | printf("%s: dev_mode not support, *p_dev_mode=%d!\n",__func__, *p_dev_mode);
|
| 141 | //return -1;
|
| 142 | }
|
| 143 | printf("%s: start *p_dev_mode=%d!\n",__func__, *p_dev_mode);
|
| 144 |
|
| 145 | //close mixer
|
| 146 | mixer_close(voice_mixer);
|
| 147 | voice_mixer = NULL;
|
| 148 |
|
| 149 | return 0;
|
| 150 |
|
| 151 | }
|
| 152 |
|
| 153 |
|
| 154 | int sc_audio_set_rx_voice_vol(int vol)
|
| 155 | {
|
| 156 | struct mixer *voice_mixer = NULL;
|
| 157 | printf("%s: start vol=%d!\n",__func__, vol);
|
| 158 |
|
| 159 | if ((vol < 0 ) ||(vol > 11)){
|
| 160 | printf("%s: vol not support, vol=%d!\n",__func__, vol);
|
| 161 | return -1;
|
| 162 | }
|
| 163 |
|
| 164 | //open mixer dev for control
|
| 165 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 166 | if (!voice_mixer) {
|
| 167 | printf("voice_mixer open failed!\n");
|
| 168 | return -1;
|
| 169 | }
|
| 170 |
|
| 171 | //config mixer dev
|
| 172 | mix_set_voice_vol(voice_mixer, vol);
|
| 173 |
|
| 174 | //close mixer
|
| 175 | mixer_close(voice_mixer);
|
| 176 | voice_mixer = NULL;
|
| 177 |
|
| 178 |
|
| 179 | return 0;
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 | }
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 | int sc_audio_get_rx_voice_vol(int * p_vol)
|
| 189 | {
|
| 190 | struct mixer *voice_mixer = NULL;
|
| 191 |
|
| 192 | printf("%s: start!\n",__func__);
|
| 193 |
|
| 194 | //open mixer dev for control
|
| 195 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 196 | if (!voice_mixer) {
|
| 197 | printf("voice_mixer open failed!\n");
|
| 198 | return -1;
|
| 199 | }
|
| 200 |
|
| 201 | //config mixer dev
|
| 202 | mix_get_voice_vol(voice_mixer, p_vol);
|
| 203 |
|
| 204 |
|
| 205 | if ((*p_vol < 0 ) ||(*p_vol > 11)){
|
| 206 | printf("%s: vol not support, *p_vol=%d!\n",__func__, *p_vol);
|
| 207 | //return -1;
|
| 208 | }
|
| 209 | printf("%s: *p_vol=%d!\n",__func__, *p_vol);
|
| 210 |
|
| 211 | //close mixer
|
| 212 | mixer_close(voice_mixer);
|
| 213 | voice_mixer = NULL;
|
| 214 |
|
| 215 |
|
| 216 | return 0;
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 | }
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 | int sc_audio_set_tx_voice_vol(int vol)
|
| 225 | {
|
| 226 | struct mixer *voice_mixer = NULL;
|
| 227 | printf("%s: start vol=%d!\n",__func__, vol);
|
| 228 |
|
| 229 | if ((vol < 0 ) ||(vol > 11)){
|
| 230 | printf("%s: vol not support, vol=%d!\n",__func__, vol);
|
| 231 | return -1;
|
| 232 | }
|
| 233 |
|
| 234 | //open mixer dev for control
|
| 235 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 236 | if (!voice_mixer) {
|
| 237 | printf("voice_mixer open failed!\n");
|
| 238 | return -1;
|
| 239 | }
|
| 240 |
|
| 241 | //config mixer dev
|
| 242 | mix_set_tx_voice_vol(voice_mixer, vol);
|
| 243 |
|
| 244 | //close mixer
|
| 245 | mixer_close(voice_mixer);
|
| 246 | voice_mixer = NULL;
|
| 247 |
|
| 248 |
|
| 249 | return 0;
|
| 250 |
|
| 251 |
|
| 252 | }
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 | int sc_audio_get_tx_voice_vol(int *p_vol)
|
| 257 | {
|
| 258 | struct mixer *voice_mixer = NULL;
|
| 259 | printf("%s: start!\n",__func__);
|
| 260 |
|
| 261 |
|
| 262 | //open mixer dev for control
|
| 263 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 264 | if (!voice_mixer) {
|
| 265 | printf("voice_mixer open failed!\n");
|
| 266 | return -1;
|
| 267 | }
|
| 268 |
|
| 269 | //config mixer dev
|
| 270 | mix_get_tx_voice_vol(voice_mixer, p_vol);
|
| 271 |
|
| 272 |
|
| 273 | if((*p_vol < 0 ) ||(*p_vol > 5)){
|
| 274 | printf("%s: vol not support, *p_vol=%d!\n",__func__, *p_vol);
|
| 275 | //return -1;
|
| 276 | }
|
| 277 | printf("%s: *p_vol=%d!\n",__func__, *p_vol);
|
| 278 |
|
| 279 | //close mixer
|
| 280 | mixer_close(voice_mixer);
|
| 281 | voice_mixer = NULL;
|
| 282 | return 0;
|
| 283 | }
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 | int sc_audio_set_tx_voice_mute_state(int mute )
|
| 288 | {
|
| 289 | struct mixer *voice_mixer = NULL;
|
| 290 | printf("%s: start mute=%d!\n",__func__, mute);
|
| 291 |
|
| 292 | if((mute != 0 ) &&(mute != 1)) {
|
| 293 | printf("%s: mute not support, mute=%d!\n",__func__, mute);
|
| 294 | return -1;
|
| 295 | }
|
| 296 |
|
| 297 | //open mixer dev for control
|
| 298 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 299 | if (!voice_mixer) {
|
| 300 | printf("voice_mixer open failed!\n");
|
| 301 | return -1;
|
| 302 | }
|
| 303 |
|
| 304 | //config mixer dev
|
| 305 | mix_set_voice_mute(voice_mixer, mute);
|
| 306 |
|
| 307 | //close mixer
|
| 308 | mixer_close(voice_mixer);
|
| 309 | voice_mixer = NULL;
|
| 310 | return 0;
|
| 311 |
|
| 312 | }
|
| 313 |
|
| 314 | int sc_audio_get_tx_voice_mute_state(int *p_mute)
|
| 315 | {
|
| 316 | struct mixer *voice_mixer = NULL;
|
| 317 |
|
| 318 | printf("%s: start!\n",__func__);
|
| 319 |
|
| 320 | //open mixer dev for control
|
| 321 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 322 | if (!voice_mixer) {
|
| 323 | printf("voice_mixer open failed!\n");
|
| 324 | return -1;
|
| 325 | }
|
| 326 |
|
| 327 | //config mixer dev
|
| 328 | mix_get_voice_mute(voice_mixer, p_mute);
|
| 329 |
|
| 330 |
|
| 331 | if((*p_mute != 0 ) &&(*p_mute != 1)) {
|
| 332 | printf("%s: *p_mute not support, *p_mute=%d!\n",__func__, *p_mute);
|
| 333 | //close mixer
|
| 334 | mixer_close(voice_mixer);
|
| 335 | voice_mixer = NULL;
|
| 336 | return -1;
|
| 337 | }
|
| 338 | printf("%s: *p_mute=%d!\n",__func__, *p_mute);
|
| 339 |
|
| 340 | //close mixer
|
| 341 | mixer_close(voice_mixer);
|
| 342 | voice_mixer = NULL;
|
| 343 |
|
| 344 | return 0;
|
| 345 | }
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 | int sc_audio_set_rx_voice_mute_state(int mute)
|
| 354 | {
|
| 355 | struct mixer *voice_mixer = NULL;
|
| 356 | printf("%s: start mute=%d!\n",__func__, mute);
|
| 357 |
|
| 358 | if((mute != 0 ) &&(mute != 1)) {
|
| 359 | printf("%s: mute not support, mute=%d!\n",__func__, mute);
|
| 360 | return -1;
|
| 361 | }
|
| 362 |
|
| 363 | //open mixer dev for control
|
| 364 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 365 | if (!voice_mixer) {
|
| 366 | printf("voice_mixer open failed!\n");
|
| 367 | return -1;
|
| 368 | }
|
| 369 |
|
| 370 | //config mixer dev
|
| 371 | mix_set_rx_voice_mute(voice_mixer, mute);
|
| 372 |
|
| 373 | //close mixer
|
| 374 | mixer_close(voice_mixer);
|
| 375 | voice_mixer = NULL;
|
| 376 | return 0;
|
| 377 |
|
| 378 | }
|
| 379 |
|
| 380 |
|
| 381 | int sc_audio_get_rx_voice_mute_state(int *p_mute){
|
| 382 | struct mixer *voice_mixer = NULL;
|
| 383 |
|
| 384 | printf("%s: start!\n",__func__);
|
| 385 |
|
| 386 | //open mixer dev for control
|
| 387 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 388 | if (!voice_mixer) {
|
| 389 | printf("voice_mixer open failed!\n");
|
| 390 | return -1;
|
| 391 | }
|
| 392 |
|
| 393 | //config mixer dev
|
| 394 | mix_get_rx_voice_mute(voice_mixer, p_mute);
|
| 395 |
|
| 396 | if((*p_mute != 0 ) &&(*p_mute != 1)) {
|
| 397 |
|
| 398 | printf("%s: *p_mute not support, *p_mute=%d!\n",__func__, *p_mute);
|
| 399 | //close mixer
|
| 400 | mixer_close(voice_mixer);
|
| 401 | voice_mixer = NULL;
|
| 402 | return -1;
|
| 403 | }
|
| 404 | printf("%s: *p_mute=%d!\n",__func__, *p_mute);
|
| 405 |
|
| 406 | //close mixer
|
| 407 | mixer_close(voice_mixer);
|
| 408 | voice_mixer = NULL;
|
| 409 |
|
| 410 | return 0;
|
| 411 |
|
| 412 | }
|
| 413 |
|
| 414 | int sc_audio_set_loopback_enable_state(int enable)
|
| 415 | {
|
| 416 | return 0;
|
| 417 | }
|
| 418 |
|
| 419 | int sc_audio_get_loopback_enable_state(int *p_enable)
|
| 420 | {
|
| 421 | return 0;
|
| 422 | }
|
| 423 |
|