return else: self.last_sortchange = time self.samplerate = self.ewma(self.samplerate, multiply * streaktime, 256) if self.samplerate > self.alg.SAMPLE_MAX: self.samplerate = self.alg.SAMPLE_MAX def report_normal(self, time, status): Louis.Rate.report_normal(self, time, status) self.samplerate = self.alg.SAMPLE_NORMAL def __repr__(self): return "<Rate {} p={:.3f} sr={:.3f}>".format( self.mbps, self.probability, self.samplerate / 1e9) def process_feedback(self, status, timestamp, delay, tries): rix, _ = tries[0] rate = self.RATES[rix] oldpos = self.rates_sorted.index(rate) Louis.process_feedback(self, status, timestamp, delay, tries) newpos = self.rates_sorted.index(rate) change = newpos - oldpos rate.report_sortchange(timestamp, oldpos, change) initialize, apply_rate, process_feedback = bits.methods(Armstrong)
from armstrong import Louis import bits initialize, apply_rate, process_feedback = bits.methods(Louis)
import bits import rates import os RATE=float(os.environ["RATE"]) if "RATE" in os.environ else 1 # Read the rate as a Mbps value and convert it to an index try: IDX = [i for i, r in enumerate(rates.RATES) if r.mbps == RATE][0] except IndexError: opts = [str(rate.mbps) for rate in rates.RATES] print("Invalid rate. Options are: {}".format(", ".join(opts))) exit() else: print("Running at rate %r Mbps..." % RATE) class Constant(bits.BitrateAlgorithm): def apply_rate(self, timestamp): return [(IDX, 1)] initialize, apply_rate, process_feedback = bits.methods(Constant)
self.samplerate = self.ewma(self.samplerate, multiply * streaktime, 256) elif delta == 0: return else: self.last_sortchange = time self.samplerate = self.ewma(self.samplerate, multiply * streaktime, 256) if self.samplerate > self.alg.SAMPLE_MAX: self.samplerate = self.alg.SAMPLE_MAX def report_normal(self, time, status): Louis.Rate.report_normal(self, time, status) self.samplerate = self.alg.SAMPLE_NORMAL def __repr__(self): return "<Rate {} p={:.3f} sr={:.3f}>".format( self.mbps, self.probability, self.samplerate/1e9) def process_feedback(self, status, timestamp, delay, tries): rix, _ = tries[0] rate = self.RATES[rix] oldpos = self.rates_sorted.index(rate) Louis.process_feedback(self, status, timestamp, delay, tries) newpos = self.rates_sorted.index(rate) change = newpos - oldpos rate.report_sortchange(timestamp, oldpos, change) initialize, apply_rate, process_feedback = bits.methods(Armstrong)