xref: /OK3568_Linux_fs/external/rk_pcba_test/echo_audio_play_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 <sys/time.h>
29 
30 #include "audio_test.h"
31 
32 #define LOG_TAG "audio_play_test"
33 #include "common.h"
34 #define AUDIO_EVENT_TIMEOUT -85
35 #define AUDIO_TIME 5
36 
37 //*Audio test
audio_play_test(void * argv)38 void *audio_play_test(void *argv)
39 {
40     char cmd[128];
41     memset(cmd, 0, sizeof(cmd));
42 
43     fprintf(stderr,"=========function :%s start=============\n",__func__);
44     //* 1���ȷ���
45     fprintf(stderr,"Start test audio record and play.\n");
46 #ifdef PCBA_PX3SE
47     sprintf(cmd,"aplay -d %d %s/%s",AUDIO_TIME,PCBA_TEST_PATH,AUDIO_PLAY_FILE);
48 #endif
49 
50 #ifdef PCBA_3308
51     sprintf(cmd,"aplay %s/%s",PCBA_TEST_PATH,AUDIO_PLAY_FILE);
52 #endif
53 #ifdef PCBA_3229GVA
54     sprintf(cmd,"aplay %s/%s",PCBA_TEST_PATH,AUDIO_PLAY_FILE);
55 #endif
56 
57 #ifdef PCBA_1808
58     sprintf(cmd,"aplay -D default:CARD=rockchiprk809co %s/%s",PCBA_TEST_PATH,AUDIO_PLAY_FILE);
59 #endif
60 
61     if (cmd[0] != '\0')
62         system(cmd);
63     else {
64         fprintf(stderr,"====CMD is null, Pls check PCBA platform====\n",__func__);
65         return (void*)-1;
66     }
67     fprintf(stderr,"=========function :%s finish=============\n",__func__);
68     return 0;
69 }
70 
71 /*���������*/
main(int argc,char * argv[])72 int main(int argc, char *argv[])
73 {
74     int delay_t = 0,err_code = 0;
75 	struct timeval t1, t2;
76 	char buf[COMMAND_VALUESIZE] = "audio_play_test";
77     char result[COMMAND_VALUESIZE] = RESULT_VERIFY;
78 
79 #ifdef PCBA_3308
80     system("amixer cset numid=4 26");
81 #endif
82 #ifdef PCBA_3308
83     system("amixer set Master Playback 30%");
84 #endif
85 #ifdef PCBA_3229GVA
86     system("amixer cset numid=4 26");
87 #endif
88 	log_info("audio play test start...\n");
89 	gettimeofday(&t1, NULL);
90 
91     int ret;
92     while(1)
93     {
94         ret = (int)audio_play_test(argv[0]);
95         if (ret) {
96             err_code = AUDIO_PLAY_ERR;
97             break;
98         }
99 
100         gettimeofday(&t2, NULL);
101 		delay_t = (t2.tv_sec - t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
102 		if (delay_t > MANUAL_TEST_TIMEOUT) {
103 			log_warn("audio play test end, timeout 60s\n");
104 			err_code = AUDIO_EVENT_TIMEOUT;
105 			break;
106 		}
107     }
108     if (err_code)
109 		strcpy(result, RESULT_FAIL);
110     send_msg_to_server(buf, result, err_code);
111     return 0;
112 }
113