def setLevel(self, rate): ''' Sets the level corresponding to the rate specified in B/s :param rate: rate in B/s that determines the level. The level is the one whose rate is the highest below ``rate``. ''' if self.getPrio()==1: new_level=0 self.setCurrentLevel(new_level) print("Prio next segment= true ") print("!!!PRIO") return new_level else: print("Prio next segment= false ") print("My socket is "+str(getLocalport())) new_level = self.controller.quantizeRate(rate) if new_level != self.getCurrentLevel(): debug(DEBUG, "%s setLevel: level: %d", self, new_level) self.setCurrentLevel(new_level) #self.onLevelChanged() return new_level
def makeRequest(self): clientInfo = socket.gethostbyname(socket.gethostname()) segSize = float(float(self.getLastFragmentBytes() * 8)) / 1000 if self.first == 1: socket_send_app_param.send_string( "%s %s %s %s %s %s" % ("2", "start", str(clientInfo), str( getLocalport()), str(os.getpid()), "1080p")) self.first = 0 else: socket_send_app_param.send_string( "%s %s %s %s %s %s" % ("2", "client_update", str(clientInfo), str( getLocalport()), str(os.getpid()), "1080p")) print("sent info to zmq-entity")
def connectZMQ(self): context = zmq.Context() socket = context.socket(zmq.SUB) print("Tapas Player connection with zmq-Entity") socket.connect("tcp://192.168.1.2:4444") curr_localPort=getLocalport() listenTo="192.168.1.10:"+str(curr_localPort) if isinstance(listenTo,bytes): listenTo = listenTo.decode('ascii') socket.setsockopt_string(zmq.SUBSCRIBE, listenTo) print('connLost is '+ str(self.connLost)) while self.connLost==False: try: print('connLost is '+ str(self.connLost)) string_received = socket.recv_string() print("=======================================") print('I RECEIVED A MESSAGE') print('IT IS MEANT TO BE FOR '+str(listenTo)) print('MY CURRENT LOCALPORT I HAVE TO LISTEN TO IS '+str(curr_localPort)) print("=======================================") listenTo, priostat = string_received.split() self.setPrio(int(float(priostat))) if not self.connLost: print colored("[_zmq got Answer()] I call fetchNextSegment() from if [1]",'red'); self.fetchNextSegment(curr_localPort) print colored("[_zmq got Answer ()] I called fetchNextSegment() from if [2]",'red'); if self.connLost: print colored('----------------------->>>>> Do not request because connection is lost','green') except KeyboardInterrupt: break
def makeRequest(self): clientInfo = socket.gethostbyname(socket.gethostname()) segSize = float(float(self.getLastFragmentBytes() * 8)) / 1000 if self.first == 1: socket_send_app_param.send_string( "%s %s %s %s %s %s %s %s %s %s" % ("2", "start", str(self.getBandwidth()), str(segSize), str(clientInfo), str(getLocalport()), str( os.getpid()), str(self.resolution), 'empt', 'empt')) self.first = 0 else: print("my idle time is " + str(idle_duration)) print("my dl time is " + str(self.last_downloaded_time)) socket_send_app_param.send_string( "%s %s %s %s %s %s %s %s %s %s" % ("2", "client_update", str(self.getBandwidth()), str(segSize), str(clientInfo), str(getLocalport()), str( os.getpid()), str(self.resolution), str(idle_duration), str(self.last_downloaded_time)))
def _onConnectionMade(self, connection, host): self.connLost=False; ''' Does something when connection with host is established (only with persistent connection). ''' debug(DEBUG+1, '%s _onConnectionMade: %s', self, host) if self.logger: self.logger.log_comment('Host: %s' %host) print colored("[_on Connection Made] I call fetchNextSegment() from if [1]",'red'); reactor.callLater(0.1, self.fetchNextSegment, calledWithPort='') print ("==> MY LOCALPORT IS "+str(getLocalport())) self.test_thread = threading.Thread(target=self.connectZMQ) self.test_thread.daemon = True self.test_thread.start() print colored("==> new thread started",'red')
def fetchNextSegment(self): ''' Schedules the download of the next segment at current level ''' print("FETCH THE NEXT SEGMENT IN LEVEL: " + str(self.getCurrentLevel())) #print ("MY PID IS "+str(os.getpid())) playlist = self.parser.playlists[self.getCurrentLevel()] debug(DEBUG + 1, '%s fetchNextSegment level: %d cur_index: %d', self, self.getCurrentLevel(), self.getCurrentSegmentIndex()) # 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': debug(DEBUG, '%s fetchNextSegment cur_index %d', self, self.getCurrentSegmentIndex()) self.parser.updateLevelSegmentsList( self.getCurrentLevel()).addCallback( self._updatePlaylistDone) # if video is vod else: debug(DEBUG, '%s fetchNextSegment last index', self) 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)', self, self.getCurrentLevel(), format_bytes(float(levels[self.getCurrentLevel()]['rate'])), self.getCurrentSegmentIndex(), playlist['end_index'], url_segment, byterange) else: debug(DEBUG, '%s fetchNextSegment level: %d (%s/s) %d/%d : %s', self, self.getCurrentLevel(), format_bytes(float(levels[self.getCurrentLevel()]['rate'])), self.getCurrentSegmentIndex(), playlist['end_index'], 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 clientInfo = socket.gethostbyname(socket.gethostname()) segSize = float(float(self.getLastFragmentBytes() * 8)) / 1000 print["MESSAGE SEND TO ORCHESTRATOR"] print colored("[delegated level is ]" + str(self.delegatedLevel), 'green') if self.first == 1: socket_send_app_param.send_string( "%s %s %s %s %s %s" % ("2", "start", str(clientInfo), str( getLocalport()), str(os.getpid()), "1080p")) self.first = 0 else: socket_send_app_param.send_string( "%s %s %s %s %s %s" % ("2", "client_update", str(clientInfo), str( getLocalport()), str(os.getpid()), "1080p")) print("sent info to zmq-entity") reactor.callLater(idle_duration, self.startDownload, url_segment, byterange)
def makeRequest(self): clientInfo=socket.gethostbyname(socket.gethostname()) segSize=float(float(self.getLastFragmentBytes()*8))/1000; socket_send_app_param.send_string("%s %f %f %f %f %s %s" %("2", float(self.media_engine.getQueuedTime()), float(segSize), float(self.getCurrentRate()), float(self.parser.getFragmentDuration()), clientInfo+":"+str(getLocalport()),str(os.getpid())))