def do_test_EventSequence(self, argDict, tolerance, schedule): """Do a timing test for the rate control component. argDict = arguments passed to VariableRateControl.__init__() tolerance = tolerance of timings for the test (+ or -) this amount acceptable schedule = list of events (in chronological order). Each list item is a tuple: (relative_time, action, actionarg) t, action, arg: t, "receive", List - at time 't' since start of test, expect VariableRateControl to send the items in the list consecutively, nothing more, nothing less this will also test at t + tolerance that nothing else comes out Test will succeed if and only if, all 'expect' events occur (within the timing tolerance specified) and no other events occur at other times """ r = VariableRateControl(**argDict) starttime = time.time() # a positive start time offset r.resetTiming(starttime) chunklist = [] for (reltime, action, arg) in schedule: e = "t=" + str(reltime) + " : " if action == "receive": # # test time fractionally before # chunklist = list( r.getChunksToSend(starttime+reltime-tolerance) ) # self.assert_( [] == chunklist, e+"VariableRateControl emits nothing just before time "+str(reltime)+" in this test (not "+str(chunklist)+")") # now test what we receive at the time itself chunklist = list(r.getChunksToSend(starttime + reltime + 0.001)) self.assert_( arg == chunklist, e + "VariableRateControl emits " + repr(arg) + " at time " + str(reltime) + " in this test (not " + str(chunklist) + ")") # test time fractionally after chunklist = list( r.getChunksToSend(starttime + reltime + tolerance)) self.assert_( [] == chunklist, e + "VariableRateControl emits nothing just after time " + str(reltime) + " in this test (not " + str(chunklist) + ")") elif action == "newrate": r.changeRate(arg, starttime + reltime)
def do_test_EventSequence(self, argDict, tolerance, schedule): """Do a timing test for the rate control component. argDict = arguments passed to VariableRateControl.__init__() tolerance = tolerance of timings for the test (+ or -) this amount acceptable schedule = list of events (in chronological order). Each list item is a tuple: (relative_time, action, actionarg) t, action, arg: t, "receive", List - at time 't' since start of test, expect VariableRateControl to send the items in the list consecutively, nothing more, nothing less this will also test at t + tolerance that nothing else comes out Test will succeed if and only if, all 'expect' events occur (within the timing tolerance specified) and no other events occur at other times """ r=VariableRateControl(**argDict) starttime = time.time() # a positive start time offset r.resetTiming(starttime) chunklist = [] for (reltime, action, arg) in schedule: e = "t="+str(reltime)+" : " if action == "receive": # # test time fractionally before # chunklist = list( r.getChunksToSend(starttime+reltime-tolerance) ) # self.assert_( [] == chunklist, e+"VariableRateControl emits nothing just before time "+str(reltime)+" in this test (not "+str(chunklist)+")") # now test what we receive at the time itself chunklist = list( r.getChunksToSend(starttime+reltime+0.001) ) self.assert_( arg == chunklist, e+"VariableRateControl emits "+repr(arg)+" at time "+str(reltime)+" in this test (not "+str(chunklist)+")") # test time fractionally after chunklist = list( r.getChunksToSend(starttime+reltime+tolerance) ) self.assert_( [] == chunklist, e+"VariableRateControl emits nothing just after time "+str(reltime)+" in this test (not "+str(chunklist)+")") elif action == "newrate": r.changeRate(arg, starttime+reltime)
def __init__(self): super(BitRateExtractor, self).__init__() self.bitrate = None def main(self): while not self.dataReady("control"): yield 1 while self.dataReady("inbox"): frame = self.recv("inbox") if frame.bitrate != self.bitrate: self.bitrate = frame.bitrate self.send(self.bitrate, "bitratechange") self.send(frame, "outbox") self.send(self.recv("control"), "signal") rc = VariableRateControl(rate=4096, chunksize=1024) rfa = ReadFileAdapter(filename=filepath, readmode="bytes") be = BitRateExtractor() p = pipeline(rc, rfa, AudioDecoder(extn), be, AudioFrameMarshaller(), AudioFrameDeMarshaller(), SoundOutput()) rc.link((be, "bitratechange"), (rc, "inbox")) p.link((p, "signal"), (p, "control")) # loopback for shutdown of RC p.activate() p.run()
super(BitRateExtractor, self).__init__() self.bitrate = None def main(self): while not self.dataReady("control"): yield 1 while self.dataReady("inbox"): frame = self.recv("inbox") if frame.bitrate != self.bitrate: self.bitrate = frame.bitrate self.send( self.bitrate, "bitratechange" ) self.send( frame, "outbox" ) self.send( self.recv("control"), "signal") rc = VariableRateControl(rate=4096, chunksize=1024) rfa = ReadFileAdapter(filename=filepath, readmode="bytes") be = BitRateExtractor() p=pipeline(rc, rfa, AudioDecoder(extn), be, AudioFrameMarshaller(), AudioFrameDeMarshaller(), SoundOutput() ) rc.link( (be, "bitratechange"), (rc, "inbox") ) p.link( (p, "signal"), (p, "control") ) # loopback for shutdown of RC