예제 #1
0
    def download(self):
        # download init segment
        self.download_init_segment(self.config, self.file_writer)
        fetcher = common.Fetcher(self.file_writer)
        os.system('%s &' % self.bandwidth_changerscript_path)
        res_bitrates = [self.bitrates[0] / 1000]
        # Download the first segment
        duration, size = self.download_video_segment(self.config, fetcher, 1)
        res_end_time = [duration]
        last_quality = self.bitrates[0]
        # Add the lowest quality to the buffer for first segment
        self.player.buffer_contents += [0]
        self.player.total_play_time += duration * 1000
        if self.verbose:
            print "Downloaded first segment\n"
        total_segments = self.config.reps[0][
            'periodDuration'] / self.config.reps[0]['dur_s']
        next_seg = 2
        while next_seg <= total_segments:
            #if buffer is full
            bufferOverflow = self.player.get_buffer_level(
            ) + self.segment_time - self.buffer_size
            if bufferOverflow > 0:
                print "bufferoverflow"
                self.player.deplete_buffer(self.config.reps[0]['dur_s'] * 1000)

            quality = self.quality_from_buffer()
            res_bitrates.append(self.bitrates[quality] / 1000)
            #print 'Using quality', quality, 'for segment', next_seg, 'based on quality', quality
            self.quality_switch += abs(last_quality - self.bitrates[quality])
            last_quality = self.bitrates[quality]
            duration, size = fetcher.fetch(
                self.quality_rep_map[self.bitrates[quality]], next_seg)
            res_end_time.append(res_end_time[-1] + duration)
            self.player.deplete_buffer(int(duration * 1000))
            self.player.buffer_contents += [quality]
            next_seg += 1

        self.player.deplete_buffer(self.player.get_buffer_level())
        print("Total play time = %d sec" %
              (self.player.total_play_time / 1000))
        print('total played utility: %f' % self.player.played_utility)
        print('Avg played bitrate: %f' %
              (self.player.played_bitrate / total_segments))
        print('Total played bitrate: %d' % (self.player.played_bitrate))
        print('Rebuffer time = %f sec' % (self.player.rebuffer_time / 1000))
        print('Rebuffer count = %d' % self.player.rebuffer_event_count)
        print res_bitrates
        print res_end_time
        print("QOE metrics")
        bitrate_reward = self.player.played_bitrate / 1000.0
        rebuf_penalty = REBUF_PENALTY * self.player.rebuffer_time / 1000.0
        smooth_penalty = SMOOTH_PENALTY * self.quality_switch / 1000.0
        total_qoe = bitrate_reward - rebuf_penalty - smooth_penalty
        print("Total Bitrate Utility= ", bitrate_reward)
        print("Rebuffer penalty= ", rebuf_penalty)
        print("Smoothness penalty=", smooth_penalty)
        print("Average QOE=", total_qoe / total_segments)
예제 #2
0
    def download_pensieve(self):
        # Download init segment
        self.download_init_segment(self.config, self.file_writer)
        fetcher = common.Fetcher(self.file_writer)
        os.system('%s &' % self.bandwidth_changerscript_path)
        res_bitrates = [self.bitrates[0] / 1000]

        # Download the first segment
        duration, size = self.download_video_segment(self.config, fetcher, 1)
        self.chunk_size = size
        self.chunk_fetch_time = duration
        # Add the lowest quality to the buffer for first segment
        self.player.buffer_contents += [0]
        self.player.total_play_time += duration * 1000
        last_quality = self.bitrates[0]
        res_end_time = [duration]
        if self.verbose:
            print "Downloaded first segment\n"
        self.video_chunk_count += 1

        next_seg = 2
        while next_seg <= TOTAL_VIDEO_CHUNKS:
            bufferOverflow = self.player.get_buffer_level(
            ) + self.segment_time - self.buffer_size
            if bufferOverflow > 0:
                self.player.deplete_buffer(self.segment_time)

            quality = self.get_quality_delay(next_seg)
            self.quality_switch += abs(last_quality - self.bitrates[quality])
            last_quality = self.bitrates[quality]
            res_bitrates.append(self.bitrates[quality] / 1000)
            #print 'Using quality ', quality, 'for segment ', next_seg
            duration, size = fetcher.fetch(
                self.quality_rep_map[self.bitrates[quality]], next_seg)
            res_end_time.append(res_end_time[-1] + duration)
            #res_end_time.append(self.player.total_play_time)
            self.chunk_size = size
            self.chunk_fetch_time = duration
            self.player.deplete_buffer(int(duration * 1000))
            self.player.buffer_contents += [quality]
            next_seg += 1

        self.player.deplete_buffer(self.player.get_buffer_level())
        print("Total play time = %d sec" %
              (self.player.total_play_time / 1000))
        print('Total played utility= %f' % self.player.played_utility)
        print('Avg played bitrate= %f' %
              (self.player.played_bitrate / TOTAL_VIDEO_CHUNKS))
        print('Rebuffer time = %f sec' % (self.player.rebuffer_time / 1000))
        print('Rebuffer count = %d' % self.player.rebuffer_event_count)
        print res_bitrates
        print res_end_time
        print("QOE metrics")
        bitrate_reward = self.player.played_bitrate / 1000.0
        rebuf_penalty = REBUF_PENALTY * self.player.rebuffer_time / 1000.0
        smooth_penalty = SMOOTH_PENALTY * self.quality_switch / 1000.0
        total_qoe = bitrate_reward - rebuf_penalty - smooth_penalty
        print("Total Bitrate Utility= ", bitrate_reward)
        print("Rebuffer penalty= ", rebuf_penalty)
        print("Smoothness penalty=", smooth_penalty)
        print("Average QOE=", total_qoe / TOTAL_VIDEO_CHUNKS)
예제 #3
0
    def download(self):
        throughput = 0
        # download init segment
        duration, size = self.download_init_segment(self.config,
                                                    self.file_writer)
        fetcher = common.Fetcher(self.file_writer)
        res_bitrates = [self.bitrates[0] / 1000]
        startNumber = self.config.reps[0]['startNr']
        os.system('%s &' % self.bandwidth_changerscript_path)
        # Download the first segment with lowest quality
        duration, size = self.download_video_segment(self.config, fetcher,
                                                     startNumber)
        res_end_time = [duration]
        last_quality = self.bitrates[0]
        # Re-calculate throughput and measure latency.
        throughput = size / duration
        #print size, duration, throughput
        # Add the lowest quality to the buffer for first segment
        self.player.buffer_contents += [0]
        self.player.total_play_time += duration * 1000
        if self.verbose:
            print "Downloaded first segment"

        total_segments = self.config.reps[0][
            'periodDuration'] / self.config.reps[0]['dur_s']
        cur_seg = 1
        # Using index 0 - ASSUMPTION - all representation set have same duration and same start number
        # Note - we do not need threads until there are multiple adaptation sets i.e. audio and video separate adaptation sets.
        while cur_seg < total_segments:
            number = startNumber + cur_seg
            #if buffer is full
            bufferOverflow = self.player.get_buffer_level(
            ) + self.segment_time - self.buffer_size
            if bufferOverflow > 0:
                print "Buffer full"
                self.player.deplete_buffer(self.config.reps[0]['dur_s'] * 1000)

            # Call Abr(throughput). It returns the highest quality id that can be fetched.
            bitrateQuality, quality = self.quality_from_throughput(throughput)
            #print 'Using quality', quality, 'for segment', cur_seg, 'based on throughput ', throughput
            self.quality_switch += abs(last_quality - self.bitrates[quality])
            last_quality = self.bitrates[quality]
            # Use the quality as index to fetch the media
            # quality directly corresponds to the index in self.fetches
            duration, size = fetcher.fetch(
                self.quality_rep_map[bitrateQuality], number)
            res_bitrates.append(self.bitrates[quality] / 1000)
            res_end_time.append(res_end_time[-1] + duration)
            self.player.deplete_buffer(int(duration * 1000))
            self.player.buffer_contents += [quality]
            # Recalculate throughput
            throughput = size * 8 / duration
            cur_seg += 1

        self.player.deplete_buffer(self.player.get_buffer_level())
        print("Total play time = %d sec" %
              (self.player.total_play_time / 1000))
        print('Total played utility: %f' % self.player.played_utility)
        print('Avg played bitrate: %f' %
              (self.player.played_bitrate / total_segments))
        print('Rebuffer time = %f sec' % (self.player.rebuffer_time / 1000))
        print('Rebuffer count = %d' % self.player.rebuffer_event_count)
        print res_bitrates
        print res_end_time
        print("QOE metrics")
        bitrate_reward = self.player.played_bitrate / 1000.0
        rebuf_penalty = REBUF_PENALTY * self.player.rebuffer_time / 1000.0
        smooth_penalty = SMOOTH_PENALTY * self.quality_switch / 1000.0
        total_qoe = bitrate_reward - rebuf_penalty - smooth_penalty
        print("Total Bitrate Utility= ", bitrate_reward)
        print("Rebuffer penalty= ", rebuf_penalty)
        print("Smoothness penalty=", smooth_penalty)
        print("Average QOE=", total_qoe / total_segments)