| |
| |
| |
| /*============================================================================= |
| ** FileName: audio_test.cpp |
| ** Desc: about function test |
| ** Author: zhouqunchao |
| ** Version: V1.0 |
| ** LastChange: 2021-08-18 |
| ** History: |
| =============================================================================*/ |
| |
| |
| #include "function_common.h" |
| #include <log/log.h> |
| #include "audio_test.h" |
| #include <unistd.h> |
| #include <stdio.h> |
| #include <string.h> |
| #include <stdlib.h> |
| #include <fcntl.h> |
| #include "liblog/liblog.h" |
| #include "liblog/lynq_deflog.h" |
| #ifdef __cplusplus |
| extern "C" { |
| #endif |
| #include "liblynq-media/lynq_medial.h" |
| #include "liblynq-media/lynq_modem_voice.h" |
| #ifdef __cplusplus |
| } |
| #endif |
| void *media_handle = NULL; |
| int check_spk_volume(int volume_level) |
| { |
| if((volume_level>VOLUME_MAX)||(volume_level<VOLUME_MIN)){ |
| // LYVERBLOG("+[audio][spk_volume_set]: error num = %d\n", AUDIO_PRAME_ERROR); |
| return 0; |
| } |
| return 1; |
| } |
| int check_mic_volume(int volume_level) |
| { |
| if((volume_level>VOLUME_MAX)||(volume_level<VOLUME_MIN)){ |
| LYVERBLOG("+[audio][mic_volume_set]: error num = %d\n", AUDIO_PRAME_ERROR); |
| return 0; |
| } |
| return 1; |
| } |
| int audio_test(char *api,char *string) { |
| char *argv[100] = {0}; |
| int spk_volume,mic_volume; |
| parseParameters(string,argv); |
| for(int i = 0;i < 10;i++){ |
| printf("argv[%d] = %s \n", i, argv[i]); |
| } |
| if(!strcmp(api, "spk_volume_set")){ |
| |
| int volume_level = atoi(argv[0]); |
| int ret; |
| if(check_spk_volume(volume_level)) |
| { |
| ret = lynq_set_spk_volume(volume_level); |
| if(ret == 1) |
| LYVERBLOG("+[audio][spk_volume_set][success]\n"); |
| else |
| LYVERBLOG("+[audio][spk_volume_set]: error num = %d\n", AUDIO_PRAME_ERROR); |
| } |
| else |
| { |
| LYVERBLOG("+[audio][spk_volume_set]: error num = %d\n", AUDIO_PRAME_ERROR); |
| return 0; |
| } |
| } |
| else if(!strcmp(api, "spk_volume_get")){ |
| spk_volume = lynq_get_spk_volume(); |
| LYVERBLOG("+[audio][spk_volume_get][success]: data = %d\n",spk_volume); |
| } |
| else if(!strcmp(api,"mic_volume_set")){ |
| int volume_level = atoi(argv[0]); |
| if(check_mic_volume(volume_level)) |
| { |
| lynq_set_spk_volume(volume_level); |
| LYVERBLOG("+[audio][spk_volume_set][success]\n"); |
| } |
| else |
| { |
| LYVERBLOG("+[audio][mic_volume_set]: error num = %d\n", AUDIO_PRAME_ERROR); |
| return 0; |
| } |
| } |
| else if(!strcmp(api, "mic_volume_get")){ |
| mic_volume = lynq_get_spk_volume(); |
| LYVERBLOG("+[audio][mic_volume_get][success]: data = %d\n",mic_volume); |
| } |
| else if(!strcmp(api, "record_start")){ |
| // if((access(argv[0],F_OK))!=-1) |
| //{ |
| lynq_incall_record(argv[0]); |
| LYVERBLOG("+[audio][record_start][success]"); |
| // } |
| // else |
| //{ |
| // LYVERBLOG("+[audio][record_start]: error num = %d\n", AUDIO_PRAME_ERROR); |
| // } |
| } |
| else if(!strcmp(api, "record_stop")){ |
| lynq_stop_record(); |
| LYVERBLOG("+[audio][record_stop][success]"); |
| } |
| else if(!strcmp(api,"play_audio")){ |
| if((access(argv[0],F_OK))!=-1){ |
| media_handle = lynq_media_play_audio(argv[0]); |
| LYVERBLOG("+[audio][play_audio][success]"); |
| } |
| else |
| { |
| LYVERBLOG("+[audio][play_audio]: error num = %d\n", AUDIO_PRAME_ERROR); |
| } |
| } |
| else if(!strcmp(api,"stop_audio")){ |
| lynq_media_stop_audio(media_handle); |
| } |
| else { |
| LYVERBLOG("+[command error]:error num = %d\n", AUDIO_API_ERROR); |
| } |
| return 0; |
| } |