blob: 2fc257037aa96b540b57ee96d22498acfcf0bf53 [file] [log] [blame]
Nanang Izzuddinf810f952008-06-18 21:04:14 +00001# $Id$
2
3# PLAYFILE -> RECFILE:
Nanang Izzuddine6f85fb2008-06-20 17:43:55 +00004# Input file is played and is recorded to output, then compare them.
5# Useful to tes clock rates compatibility and resample quality
Nanang Izzuddinf810f952008-06-18 21:04:14 +00006# null-audio
7# port 1: wav file input xxxxxx.clock_rate.wav, e.g: test1.8.wav
8# port 2: wav file ouput xxxxxx.clock_rate.wav, e.g: res1.8.wav
Nanang Izzuddine6f85fb2008-06-20 17:43:55 +00009# wav input must be more than 3 seconds long
Nanang Izzuddinf810f952008-06-18 21:04:14 +000010
11import time
12import imp
13import sys
14import re
15import subprocess
16import inc_const as const
17
18# Load configuration
19cfg_file = imp.load_source("cfg_file", sys.argv[2])
20
21# WAV similarity calculator
22COMPARE_WAV_EXE = "tools/cmp_wav.exe"
23
Nanang Izzuddinb40e2872008-06-25 15:05:21 +000024# Threshold to declare degradation is too high when result is lower than this value
25COMPARE_THRESHOLD = 2
26
Nanang Izzuddinf810f952008-06-18 21:04:14 +000027# UserData
28class mod_media_playrec_user_data:
29 input_filename = ""
30 output_filename = ""
31
32# Test body function
33def test_func(t, ud):
34 endpt = t.process[0]
35
36 # Get input file name
Nanang Izzuddinacb3e322008-06-25 18:18:32 +000037 ud.input_filename = re.compile(const.MEDIA_PLAY_FILE).search(endpt.inst_param.arg).group(1)
Nanang Izzuddinf810f952008-06-18 21:04:14 +000038 endpt.trace("Input file = " + ud.input_filename)
39
40 # Get output file name
Nanang Izzuddinacb3e322008-06-25 18:18:32 +000041 ud.output_filename = re.compile(const.MEDIA_REC_FILE).search(endpt.inst_param.arg).group(1)
Nanang Izzuddinf810f952008-06-18 21:04:14 +000042 endpt.trace("Output file = " + ud.output_filename)
43
44 # Find appropriate clock rate for the input file
45 clock_rate = re.compile(".+(\.\d+\.wav)$").match(ud.output_filename).group(1)
46 if (clock_rate==None):
47 endpt.trace("Cannot compare input & output, incorrect output filename format")
48 return
49 ud.input_filename = re.sub("\.\d+\.wav$", clock_rate, ud.input_filename)
50 endpt.trace("WAV file to be compared with output = " + ud.input_filename)
51
52 # Connect input-output file
53 endpt.sync_stdout()
54
55 endpt.send("cc 1 2")
56 endpt.expect(const.MEDIA_CONN_PORT_SUCCESS)
57
58 # Wait
59 time.sleep(3)
60
61 endpt.sync_stdout()
62
63 # Disconnect input-output file
64 endpt.send("cd 1 2")
65 endpt.expect(const.MEDIA_DISCONN_PORT_SUCCESS)
66
67
68# Post body function
69def post_func(t, ud):
70 endpt = t.process[0]
71
72 # Check WAV similarity
73 fullcmd = COMPARE_WAV_EXE + " " + ud.input_filename + " " + ud.output_filename + " " + "3000"
74 endpt.trace("Popen " + fullcmd)
75 cmp_proc = subprocess.Popen(fullcmd, stdout=subprocess.PIPE, universal_newlines=True)
Nanang Izzuddine6f85fb2008-06-20 17:43:55 +000076
77 # Parse similarity ouput
Nanang Izzuddinf810f952008-06-18 21:04:14 +000078 line = cmp_proc.stdout.readline()
Nanang Izzuddine6f85fb2008-06-20 17:43:55 +000079 mo_sim_val = re.match(".+=\s+(\d+)", line)
80 if (mo_sim_val == None):
81 raise TestError("Error comparing WAV files")
82 return
83
84 # Evaluate the similarity value
85 sim_val = mo_sim_val.group(1)
Nanang Izzuddinb40e2872008-06-25 15:05:21 +000086 if (sim_val >= COMPARE_THRESHOLD):
Nanang Izzuddine6f85fb2008-06-20 17:43:55 +000087 endpt.trace("WAV similarity = " + sim_val)
88 else:
Nanang Izzuddinb40e2872008-06-25 15:05:21 +000089 raise TestError("WAV degraded heavily, similarity = " + sim_val)
Nanang Izzuddinf810f952008-06-18 21:04:14 +000090
91
92# Here where it all comes together
93test = cfg_file.test_param
94test.test_func = test_func
95test.post_func = post_func
96test.user_data = mod_media_playrec_user_data()