xref: /OK3568_Linux_fs/external/rk_pcba_test/pcba_minui/audio_record_test.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *  audio_play_test.c  --  audio play test application
3  *
4  *  Copyright (c) 2018 Rockchip Electronics Co. Ltd.
5  *  Author: chad.ma <chad.ma@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 <pthread.h>
23 
24 #include <linux/input.h>
25 #include <fcntl.h>
26 #include <dirent.h>
27 #include "common.h"
28 #include "key_test.h"
29 #include "test_case.h"
30 #include "language.h"
31 
32 #include <unistd.h>
33 #include "audio_record_test.h"
34 
35 #define LOG_TAG	    "PCBA [audio record]: "
36 #define LOG(x...)	printf(LOG_TAG x)
37 
38 #define TEST_RESULT_SAVE_PATH "/tmp"
39 #define RECORD_TIME 5
40 
audio_record_test(void * argv)41 void *audio_record_test(void *argv)
42 {
43     int ret, y;
44     char cmd[128];
45 	struct testcase_info *tc_info = (struct testcase_info *)argv;
46 
47 	if (tc_info->y <= 0)
48 		tc_info->y = get_cur_print_y();
49 	y = tc_info->y;
50 
51     LOG("=========function :%s start=============\n",__func__);
52 	ui_print_xy_rgba(0, y, 255, 255, 0, 255, "%s:[%s..]\n", PCBA_CODEC_RECORD,
53 			 PCBA_TESTING);
54 
55     //ָ��Card 3��device 0��¼��3��
56 #ifdef PCBA_3308
57     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);
58 #endif
59 
60 #ifdef PCBA_PX3SE
61     sprintf(cmd,"arecord -f S16_LE -c 2 -r 16000 -d %d %s/%s",RECORD_TIME,TEST_RESULT_SAVE_PATH,AUDIO_RECORD_FILE);
62 #endif
63 
64 #ifdef PCBA_3229GVA
65 //TODO:
66 
67 #endif
68 
69     //arecord file
70     ret = run_test_item_cmd(cmd);
71     if (ret != 0) {//run cmd fail, do'nt go ahead ,return.
72         ui_print_xy_rgba(0, y, 225, 0, 0, 255, "%s:[%s] { %s }\n", PCBA_CODEC_RECORD,
73                  PCBA_FAILED, "record test fail....... ");
74         tc_info->result = -1;
75         LOG("audio record failed.\n");
76         return NULL;
77     }
78     LOG("\trecording\n ");
79 
80     //aplay file
81     //sprintf(cmd,"aplay -f S16_LE -c 2 -r 16000 -d %d %s/%s",RECORD_TIME,TEST_RESULT_SAVE_PATH,AUDIO_RECORD_FILE); //����
82     sprintf(cmd,"aplay -f S16_LE -c 2 -r 16000 -d %d %s/%s",RECORD_TIME,TEST_RESULT_SAVE_PATH,AUDIO_RECORD_FILE); //����
83     ret = run_test_item_cmd(cmd);
84     if (ret != 0) {//run cmd fail, do'nt go ahead ,return.
85         ui_print_xy_rgba(0, y, 225, 0, 0, 255, "%s:[%s] { %s }\n", PCBA_CODEC_RECORD,
86                  PCBA_FAILED, "record test fail....... ");
87         tc_info->result = -1;
88         LOG("audio record failed.\n");
89         return NULL;
90     }
91     LOG("\tplaying\n ");
92 
93     //remove(cmd);
94     sprintf(cmd,"rm %s/%s",TEST_RESULT_SAVE_PATH,AUDIO_RECORD_FILE);
95     ret = run_test_item_cmd(cmd);
96 
97     if(ret == 0) {
98         ui_print_xy_rgba(0, y, 0, 255, 0, 255, "%s:[%s] { %s }\n", PCBA_CODEC_RECORD,
99                  PCBA_SECCESS, "record test success.");
100         tc_info->result = 0;
101         LOG("audio record success.\n");
102     }else  {
103         //ret < 0
104         ui_print_xy_rgba(0, y, 225, 0, 0, 255, "%s:[%s] { %s }\n", PCBA_CODEC_RECORD,
105                  PCBA_FAILED, "record test fail....... ");
106         tc_info->result = -1;
107         LOG("audio record failed.\n");
108         return NULL;
109     }
110 
111     LOG("=========Audio record test finished=============\n");
112 }
113 
114 
115