xref: /OK3568_Linux_fs/external/rk_pcba_test/echo_audio_record_test.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *  audio_test.c  --  audio test application
3  *
4  *  Copyright (c) 2017 Rockchip Electronics Co. Ltd.
5  *  Author: Panzhenzhuan Wang <randy.wang@rock-chips.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * 	 http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <fcntl.h>
28 #include <signal.h>
29 #include <sys/time.h>
30 
31 #include "audio_test.h"
32 
33 #define LOG_TAG "audio_record_test"
34 #include "common.h"
35 #define RECORD_TIME 5
36 #define AUDIO_EVENT_TIMEOUT -85
37 
38 //*Audio test
audio_record_test(void * argv)39 void *audio_record_test(void *argv)
40 {
41     char cmd[128];
42 
43     fprintf(stderr,"=========function :%s start=============\n",__func__);
44     //ָ��Card 3��device 0��¼��3��
45 #ifdef PCBA_3308
46     sprintf(cmd,"arecord -D hw:3,0 -f S16_LE -c 2 -r 16000 -d %d %s/%s",RECORD_TIME,TEST_RESULT_SAVE_PATH,AUDIO_RECORD_FILE);
47 #endif
48 
49 #ifdef PCBA_PX3SE
50     sprintf(cmd,"arecord -D MainMicCapture -f S16_LE -c 2 -r 16000 -d %d %s/%s",RECORD_TIME,TEST_RESULT_SAVE_PATH,AUDIO_RECORD_FILE);
51 #endif
52 
53 #ifdef PCBA_3229GVA
54 //TODO:
55 
56 #endif
57     system(cmd);
58     fprintf(stderr,"recording\n ");
59     //sprintf(cmd,"aplay -f S16_LE -c 2 -r 16000 -d %d %s/%s",RECORD_TIME,TEST_RESULT_SAVE_PATH,AUDIO_RECORD_FILE); //����
60     sprintf(cmd,"aplay -f S16_LE -c 2 -r 16000 -d %d %s/%s",RECORD_TIME,TEST_RESULT_SAVE_PATH,AUDIO_RECORD_FILE); //����
61     system(cmd);
62     fprintf(stderr,"playing\n ");
63     //remove(cmd);
64     sprintf(cmd,"rm %s/%s",TEST_RESULT_SAVE_PATH,AUDIO_RECORD_FILE);
65     system(cmd);
66     fprintf(stderr,"=========Audio record test finished=============\n");
67 }
68 
69 //* �źŴ��������ڽ�������ǰ��ɾ��¼����pcm�ļ�
del_record_pcm(int sign_no)70 static int del_record_pcm(int sign_no)
71 {
72     char cmd[128];
73 
74     printf("====================function : %s start =================\n",__func__);
75 
76     sprintf(cmd,"%s/%s",TEST_RESULT_SAVE_PATH,AUDIO_RECORD_FILE);
77     if(0 == access(cmd,F_OK)){
78        remove(cmd);
79     }
80 
81     printf("====================function : %s finished =================\n",__func__);
82     exit(0);
83 }
84 
85 /*���������*/
main(int argc,char * argv[])86 int main(int argc, char *argv[])
87 {
88     int delay_t = 0,err_code = 0;
89 	struct timeval t1, t2;
90 	char buf[COMMAND_VALUESIZE] = "audio_record_test";
91     char result[COMMAND_VALUESIZE] = RESULT_PASS;
92 
93     system("amixer set Playback 30%");
94 	log_info("audio record test start...\n");
95 
96 	//* ע���źŴ�����
97 	signal(SIGTERM,(__sighandler_t)del_record_pcm);
98 
99 	gettimeofday(&t1, NULL);
100     while(1)
101     {
102         audio_record_test(argv[0]);
103         gettimeofday(&t2, NULL);
104 		delay_t = (t2.tv_sec - t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
105 		if (delay_t > MANUAL_TEST_TIMEOUT) {
106 			log_warn("audio record test end, timeout 60s\n");
107 			err_code = AUDIO_EVENT_TIMEOUT;
108 			break;
109 		}
110     }
111     if (err_code)
112 		strcpy(result, RESULT_FAIL);
113     send_msg_to_server(buf, result, err_code);
114     return 0;
115 }
116