Example #1
0
    def __init__(self, mpd, base_url, base_dst, options):
        self.config = Config(mpd, base_url)
        self.quality_rep_map = {}
        self.file_writer = common.FileWriter(base_dst)

        for rep in self.config.reps:
            self.quality_rep_map[rep['bandwidth']] = rep

        self.bitrates = self.quality_rep_map.keys()
        self.bitrates.sort()
        utility_offset = -math.log(self.bitrates[0])
        self.utilities = [math.log(b) + utility_offset for b in self.bitrates]
        self.buffer_size = options.buffer_size * 1000
        self.verbose = options.verbose
        self.segment_time = self.config.reps[0]['dur_s'] * 1000
        self.bandwidth_changerscript_path = options.bandwidth_changerscript_path
        self.player = videoplayer.VideoPlayer(self.segment_time,
                                              self.utilities, self.bitrates)
        self.sess = tf.Session()
        self.quality_switch = 0
        self.actor = a3c.ActorNetwork(self.sess,
                                      state_dim=[S_INFO, S_LEN],
                                      action_dim=A_DIM,
                                      learning_rate=ACTOR_LR_RATE)
        self.critic = a3c.CriticNetwork(self.sess,
                                        state_dim=[S_INFO, S_LEN],
                                        learning_rate=CRITIC_LR_RATE)

        self.sess.run(tf.initialize_all_variables())
        self.saver = tf.train.Saver()

        # restore neural net parameters
        self.nn_model = NN_MODEL
        if self.nn_model is not None:  # nn_model is the path to file
            self.saver.restore(self.sess, self.nn_model)
            print("Model restored.")

        self.init_action = np.zeros(A_DIM)
        self.init_action[DEFAULT_QUALITY] = 1

        self.s_batch = [np.zeros((S_INFO, S_LEN))]
        self.a_batch = [self.init_action]
        self.r_batch = []

        self.last_quality = DEFAULT_QUALITY
        self.last_bit_rate = DEFAULT_QUALITY
        # need this storage, because observation only contains total rebuffering time
        # we compute the difference to get

        self.last_total_rebuf = 0
        self.video_chunk_count = 0
        self.chunk_fetch_time = 0
        self.chunk_size = 0
        self.ptime = 0
Example #2
0
 def __init__(self, mpd, base_url, base_dst, options):
     # config can be the mpd file
     self.config = Config(mpd, base_url)
     self.quality_rep_map = {}
     self.file_writer = common.FileWriter(base_dst)
     for rep in self.config.reps:
         self.quality_rep_map[rep['bandwidth']] = rep
     self.bitrates = self.quality_rep_map.keys()
     self.bitrates.sort()
     utility_offset = -math.log(self.bitrates[0])  # so utilities[0] = 0
     self.utilities = [math.log(b) + utility_offset for b in self.bitrates]
     self.buffer_size = options.buffer_size * 1000
     self.verbose = options.verbose
     self.quality_switch = 0
     # Segment time is in ms
     self.segment_time = self.config.reps[0]['dur_s'] * 1000
     self.player = videoplayer.VideoPlayer(self.segment_time,
                                           self.utilities, self.bitrates)
     self.bandwidth_changerscript_path = options.bandwidth_changerscript_path
Example #3
0
    def __init__(self, mpd, base_url, base_dst, options):
        self.config = Config(mpd, base_url)
        self.quality_rep_map = {}
        self.file_writer = common.FileWriter(base_dst)
        for rep in self.config.reps:
            self.quality_rep_map[rep['bandwidth']] = rep
        self.bitrates = self.quality_rep_map.keys()
        self.bitrates.sort()
        utility_offset = -math.log(self.bitrates[0])  # so utilities[0] = 0
        self.utilities = [math.log(b) + utility_offset for b in self.bitrates]
        self.verbose = options.verbose
        self.gp = options.gp
        self.quality_switch = 0
        # buffer_size is in ms
        self.buffer_size = options.buffer_size * 1000
        print "buffer = ", self.buffer_size, "gp = ", self.gp

        self.bandwidth_changerscript_path = options.bandwidth_changerscript_path
        # Segment time is in ms
        self.segment_time = self.config.reps[0]['dur_s'] * 1000
        self.Vp = (self.buffer_size -
                   self.segment_time) / (self.utilities[-1] + self.gp)
        self.player = videoplayer.VideoPlayer(self.segment_time,
                                              self.utilities, self.bitrates)
        if options.verbose:
            for q in range(len(self.bitrates)):
                b = self.bitrates[q]
                u = self.utilities[q]
                l = self.Vp * (self.gp + u)
                if q == 0:
                    print('%d %d' % (q, l))
                else:
                    qq = q - 1
                    bb = self.bitrates[qq]
                    uu = self.utilities[qq]
                    ll = self.Vp * (self.gp + (b * uu - bb * u) / (b - bb))
                    print('%d %d    <- %d %d' % (q, l, qq, ll))
Example #4
0
 def __init__(self, mpd, base_url, base_dst):
     # config can be the mpd file
     self.config = Config(mpd, base_url)
     self.file_writer = common.FileWriter(base_dst)