Esempio n. 1
0
    def startDownload(self, url, byterange=''):
        '''
        Starts the segment download and set the timestamp of start segment download

        :param url: segment url
        :param byterange: segment byterange (logical segmentation of video level)
        '''
        debug(DEBUG + 1, '%s startDownload %s (byterange %s)', self, url,
              byterange)
        # start download
        if self.use_persistent_connection:
            # start a new connection
            if not self.connection:
                self._initConnection(url)
                return
            if not self.connection.client:
                return
            _, _, path = parse_url(url)
            self.connection.makeRequest(path, byterange)
        else:
            if byterange == '':
                d = getPage(url, agent=USER_AGENT)
            else:
                d = getPage(url,
                            agent=USER_AGENT,
                            headers=dict(range='bytes=' + byterange))
            d.deferred.addCallback(self.playNextGotRequest, d)
            d.deferred.addErrback(self.playNextGotError, d)
        self.start_segment_request = time.time()
Esempio n. 2
0
    def startDownload(self, url, byterange=''):
        '''
        Starts the segment download and set the timestamp of start segment download

        :param url: segment url
        :param byterange: segment byterange (logical segmentation of video level)
        '''
        debug(DEBUG+1, '%s startDownload %s (byterange %s)', self, url, byterange)
        # start download
        if self.use_persistent_connection:
            # start a new connection
            if not self.connection:
                self._initConnection(url)
                return
            if not self.connection.client:
                return
            _, _, path = parse_url(url)
            self.connection.makeRequest(path, byterange)
        else:
            if byterange == '':
                d = getPage(url, agent=USER_AGENT)
            else:
                d = getPage(url, agent=USER_AGENT, headers=dict(range='bytes='+byterange))
            d.deferred.addCallback(self.playNextGotRequest, d)
            d.deferred.addErrback(self.playNextGotError, d)
        self.start_segment_request = time.time()
Esempio n. 3
0
 def _urlRedirect(self, connection, url):
     # print '_urlRedirect called with url: ' + url
     self.connection.redirect = True
     host, port, path = parse_url(url)
     print('Redirect host ' + host)
     self.last_redirect_host = host
     # self.connection.stop()
     self._initConnection(url, True)
Esempio n. 4
0
 def startDownload(self, url, byterange, level):
     # start download
     debug(DEBUG+1, '%s startDownload %s %s', self, url, byterange)
     # start a new connection
     if not self.connection_list[level]:
         self.init_connection(url, byterange, level)
         return
     if not self.connection_list[level].client:
         return
     _, _, path = parse_url(url)
     self.connection_list[level].makeRequest(path, byterange)
Esempio n. 5
0
 def startDownload(self, url, byterange, level):
     # start download
     debug(DEBUG+1, '%s startDownload %s %s', self, url, byterange)
     # start a new connection
     if not self.connection_list[level]:
         self.init_connection(url, byterange, level)
         return
     if not self.connection_list[level].client:
         return
     _, _, path = parse_url(url)
     self.connection_list[level].makeRequest(path, byterange)
Esempio n. 6
0
    def startDownload(self, url, byterange=''):
        '''
        Starts the segment download and set the timestamp of start segment download

        :param url: segment url
        :param byterange: segment byterange (logical segmentation of video level)
        '''
        debug(DEBUG + 1, '%s startDownload %s (byterange %s)', self, url,
              byterange)
        # start download
        if self.use_persistent_connection:
            # start a new connection
            if not self.connection:
                self._initConnection(url)
                return
            if not self.connection.client:
                return

            _, _, path = parse_url(url)
            print("~~~> now requesting new segment")
            self.connection.makeRequest(path, byterange)

        else:
            if byterange == '':
                d = getPage(url, agent=USER_AGENT)
            else:
                d = getPage(url,
                            agent=USER_AGENT,
                            headers=dict(range='bytes=' + byterange))
            d.deferred.addCallback(self.playNextGotRequest, d)
            d.deferred.addErrback(self.playNextGotError, d)
        self.start_segment_request = time.time()
        print colored("in startDownload", 'red')
        print colored("[5] get request performed", 'blue')
        print colored(
            "current buffer: " + str(self.media_engine.getQueuedTime()),
            'yellow')
        print colored(
            '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...Downloading...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~',
            'yellow')
Esempio n. 7
0
    def startDownload(self, url, byterange=''):
        '''
        Starts the segment download and set the timestamp of start segment download

        :param url: segment url
        :param byterange: segment byterange (logical segmentation of video level)
        '''
        debug(DEBUG + 1, '%s startDownload %s (byterange %s)', self, url,
              byterange)
        # start download
        if self.use_persistent_connection:
            # start a new connection
            if not self.connection:
                self._initConnection(url)
                return
            if not self.connection.client:
                return

            _, _, path = parse_url(url)
            segSize = float(float(self.getLastFragmentBytes() * 8)) / 1000
            self.connection.makeRequest(
                path + "?buffer=" + str(self.media_engine.getQueuedTime()) +
                "?bwestim=" + str(self.getBandwidth()) + "?SegmentDur=" +
                str(self.parser.getFragmentDuration()) + "?SegmentSizeLa=" +
                str(segSize) + "?quali=" + str(self.getCurrentRate()) +
                "?pid=" + str(os.getpid()), byterange)

        else:
            if byterange == '':
                d = getPage(url, agent=USER_AGENT)
            else:
                d = getPage(url,
                            agent=USER_AGENT,
                            headers=dict(range='bytes=' + byterange))
            d.deferred.addCallback(self.playNextGotRequest, d)
            d.deferred.addErrback(self.playNextGotError, d)
        print("CURRENT BUFFER IS " + str(self.media_engine.getQueuedTime()))
        self.start_segment_request = time.time()
Esempio n. 8
0
    def fetchNextSegment(self):
        '''
        Schedules the download of the next segment at current level and view
        '''
        playlist = self.parser.getSinglePlaylist(self.getCurrentLevel(),
                                                 self.getCurrentView())
        debug(
            DEBUG + 1,
            '%s fetchNextSegment level: %d angles: %d view: %d cur_index: %d',
            self.getCurrentLevel(),
            self.getCurrentAngles()[0], self.getCurrentView(),
            self.getCurrentSegmentIndex())
        #
        #print str("self.getCurrentSegmentIndex = {}, playlist = {}".format(self.getCurrentSegmentIndex(), playlist['start_index']))

        if self.getCurrentSegmentIndex() < playlist['start_index']:
            self.setCurrentSegmentIndex(playlist['start_index'])

        if self.getCurrentSegmentIndex() > playlist['end_index']:
            # else live video (ONLY HLS!!)
            if playlist['is_live'] and self.parser.getPlaylistType() == 'HLS':
                print("playlist['is_live'] :" + str(playlist['is_live']))
                debug(DEBUG, '%s fetchNextSegment cur_index %d', self,
                      self.getCurrentSegmentIndex())
                self.parser.updateLevelSegmentsList(
                    self.getCurrentLevel(), self.getCurrentView()).addCallback(
                        self._updatePlaylistDone)
            # if video is vod
            else:
                debug(DEBUG, '%s fetchNextSegment last index', self)

            # set max video duration for stopping media_engine
            self.media_engine.setVideoDuration(playlist['duration'])
            #print("STOP PLAYING.")
            return

        cur_index = self.getCurrentSegmentIndex()
        levels = self.parser.getLevels()
        url_segment = playlist['segments'][cur_index]['url']
        byterange = playlist['segments'][cur_index]['byterange']
        if byterange != '':
            debug(
                DEBUG,
                '%s fetchNextSegment level: %d (%s/s) %d/%d : %s (byterange=%s) angles:%d view: %d',
                self, self.getCurrentLevel(),
                format_bytes(float(levels[self.getCurrentLevel()]['rate'])),
                self.getCurrentSegmentIndex(), playlist['end_index'],
                url_segment, byterange, self.getCurrentAngles(),
                self.getCurrentView())
        else:
            debug(
                DEBUG,
                '%s fetchNextSegment level: %d (%s/s) %d/%d angles:%d view %d: %s',
                self, self.getCurrentLevel(),
                format_bytes(float(levels[self.getCurrentLevel()]['rate'])),
                self.getCurrentSegmentIndex(), playlist['end_index'],
                self.getCurrentAngles()[0], self.getCurrentView(), url_segment)

        if self.controller.isBuffering():
            idle_duration = 0.0  #fetch segment after the last segment download is completed
        else:
            idle_duration = self.controller.getIdleDuration()
        # load the next segment
        if self.last_redirect_host:
            host, port, path = parse_url(url_segment)
            url_segment = 'http://' + self.last_redirect_host + path

        reactor.callLater(idle_duration, self.startDownload, url_segment,
                          byterange)