diff options
Diffstat (limited to 'pjsip-apps/src/test-pjsua/mod_media_playrec.py')
-rw-r--r-- | pjsip-apps/src/test-pjsua/mod_media_playrec.py | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/pjsip-apps/src/test-pjsua/mod_media_playrec.py b/pjsip-apps/src/test-pjsua/mod_media_playrec.py new file mode 100644 index 00000000..8d8a60fe --- /dev/null +++ b/pjsip-apps/src/test-pjsua/mod_media_playrec.py @@ -0,0 +1,86 @@ +# $Id$ + +# PLAYFILE -> RECFILE: +# input file is played and is recorded to output, then compare them. +# null-audio +# port 1: wav file input xxxxxx.clock_rate.wav, e.g: test1.8.wav +# port 2: wav file ouput xxxxxx.clock_rate.wav, e.g: res1.8.wav +# wav input more than 3 seconds + +import time +import imp +import sys +import re +import subprocess +import inc_const as const + +# Load configuration +cfg_file = imp.load_source("cfg_file", sys.argv[2]) + +# WAV similarity calculator +COMPARE_WAV_EXE = "tools/cmp_wav.exe" + +# UserData +class mod_media_playrec_user_data: + input_filename = "" + output_filename = "" + +# Test body function +def test_func(t, ud): + endpt = t.process[0] + + # Get input file name + endpt.sync_stdout() + endpt.send("dc") + line = endpt.expect(const.MEDIA_PLAY_FILE) + ud.input_filename = re.compile(const.MEDIA_PLAY_FILE).match(line).group(1) + endpt.trace("Input file = " + ud.input_filename) + + # Get output file name + endpt.sync_stdout() + endpt.send("dc") + line = endpt.expect(const.MEDIA_REC_FILE) + ud.output_filename = re.compile(const.MEDIA_REC_FILE).match(line).group(1) + endpt.trace("Output file = " + ud.output_filename) + + # Find appropriate clock rate for the input file + clock_rate = re.compile(".+(\.\d+\.wav)$").match(ud.output_filename).group(1) + if (clock_rate==None): + endpt.trace("Cannot compare input & output, incorrect output filename format") + return + ud.input_filename = re.sub("\.\d+\.wav$", clock_rate, ud.input_filename) + endpt.trace("WAV file to be compared with output = " + ud.input_filename) + + # Connect input-output file + endpt.sync_stdout() + + endpt.send("cc 1 2") + endpt.expect(const.MEDIA_CONN_PORT_SUCCESS) + + # Wait + time.sleep(3) + + endpt.sync_stdout() + + # Disconnect input-output file + endpt.send("cd 1 2") + endpt.expect(const.MEDIA_DISCONN_PORT_SUCCESS) + + +# Post body function +def post_func(t, ud): + endpt = t.process[0] + + # Check WAV similarity + fullcmd = COMPARE_WAV_EXE + " " + ud.input_filename + " " + ud.output_filename + " " + "3000" + endpt.trace("Popen " + fullcmd) + cmp_proc = subprocess.Popen(fullcmd, stdout=subprocess.PIPE, universal_newlines=True) + line = cmp_proc.stdout.readline() + endpt.trace("WAV similarity = " + line) + + +# Here where it all comes together +test = cfg_file.test_param +test.test_func = test_func +test.post_func = post_func +test.user_data = mod_media_playrec_user_data() |