本文整理汇总了Python中Player.start方法的典型用法代码示例。如果您正苦于以下问题:Python Player.start方法的具体用法?Python Player.start怎么用?Python Player.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Player
的用法示例。
在下文中一共展示了Player.start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: streamMethod1
# 需要导入模块: import Player [as 别名]
# 或者: from Player import start [as 别名]
def streamMethod1(self):
chunkIndex = 1
manifest = Manifest("BunnyManifest_1.xml")
bitrates = manifest.listOfBitrates()
# Compute switch-up epsilon
epsilon = self.computeEpsilon(bitrates)
#start with lowest bitrate
bitrateIndex = 0
numChunks = 99 #manifest.numberOfChunks(bitrates[bitrateIndex])
idleThreadIDs = Set()
startNewRound = False
#threadBandwidth = {}
for thread in self.threads:
if thread.successful:
idleThreadIDs.add(thread.threadID)
#threadBandwidth[thread.threadID] = 0
if len(idleThreadIDs) == NUM_THREADS:
startNewRound = True
finished = False
# Used for recording bitrate frequences for graphing
bitrateFreq = {}
for bitrate in bitrates:
bitrateFreq[bitrate] = 0
# Start Player
p = Player(self.buffer)
p.start()
while not finished:
for thread in self.threads:
if not thread.isAlive():
# Check if we have gotten all the chunks
# If so, we are done
if chunkIndex == numChunks + 1:
finished = True
break
# if threads finish after round of downloads started, record their IDs
if not startNewRound and thread.successful:
idleThreadIDs.add(thread.threadID)
# if all threads finish, start new round of downloads
if len(idleThreadIDs) == NUM_THREADS:
startNewRound = True
# start new round
if startNewRound and self.buffer.size - self.buffer.length >= NUM_THREADS:
# bitrate adaptation based on bandwidth
# do not do for first round
if chunkIndex != 1:
time = 0
min = None
max = None
for currThread in self.threads:
if min == None or currThread.beginTime < min:
min = currThread.beginTime
if max == None or currThread.endTime > max:
max = currThread.endTime
deltaT = max - min
time = deltaT.microseconds + deltaT.seconds * 1000000
u = float(CHUNK_DURATION * NUM_THREADS) / time
print time
print u
if u > 1 + epsilon:
if bitrateIndex != len(bitrates) - 1:
bitrateIndex += 1
elif u < 1:
if bitrateIndex != 0:
bitrateIndex -= 1
#threadBandwidth[thread.threadID] += u
# threads have been assigned to download
idleThreadIDs = Set()
# starting of new round finishes when all threads are downloading
startNewRound = False
# Request urls from server
for currThread in self.threads:
ID = currThread.threadID
# Get url from manifest file based on bitrate and chunk index
videoURL, chunkSize = manifest.read(bitrates[bitrateIndex], chunkIndex)
videoURL = serverURLs[ID] + "/" + videoURL
bitrateFreq[bitrates[bitrateIndex]] += 1
self.buffer.setSize(chunkIndex, chunkSize)
self.threads[ID] = Downloader(ID, [[videoURL, None, None]], self.buffer, [chunkIndex])
self.threads[ID].start()
chunkIndex += 1
self.buffer.length += 1
# at every round, plot figure using existing information
statBitrateFreq = {}
#.........这里部分代码省略.........
示例2: streamMethod3
# 需要导入模块: import Player [as 别名]
# 或者: from Player import start [as 别名]
def streamMethod3(self):
chunkIndex = 1
manifest = Manifest("BunnyManifest_1.xml")
bitrates = manifest.listOfBitrates()
# Compute switch-up epsilon
epsilon = self.computeEpsilon(bitrates)
#start with lowest bitrate
bitrateIndex = 0
numChunks = 99 #manifest.numberOfChunks(bitrates[bitrateIndex])
idleThreadIDs = Set()
startNewRound = False
#threadBandwidth = {}
for thread in self.threads:
if thread.successful:
idleThreadIDs.add(thread.threadID)
#threadBandwidth[thread.threadID] = 0
if len(idleThreadIDs) == NUM_THREADS:
startNewRound = True
finished = False
bitrateFreq = {}
for bitrate in bitrates:
bitrateFreq[bitrate] = 0
# Start Player
p = Player(self.buffer)
p.start()
while not finished:
for thread in self.threads:
if not thread.isAlive():
# Check if we have gotten all the chunks
# If so, we are done
if chunkIndex == numChunks + 1:
finished = True
break
# if thread finishes downloading, look for more work
if not startNewRound and thread.successful:
minProgress = None
work = None
videoURL = None
worstThread = None
canHelpNotHelping = False
for currThread in self.threads:
if (currThread.downloadList[0][1] is 0 or currThread.downloadList[0][1] is None) and currThread.isAlive():
canHelpNotHelping = True
break
for currThread in self.threads:
if currThread.isAlive() and (not canHelpNotHelping or (canHelpNotHelping and (currThread.downloadList[0][1] is 0 or currThread.downloadList[0][1] is None))):
size = self.buffer.getFileSize(currThread.bufferIndices[0], currThread.downloadList[0][1], currThread.downloadList[0][2])
# If -1 returned, don't want to help out; just skip
if size == -1:
continue
progress = float(size) / currThread.downloadSize
if minProgress is None or progress < minProgress:
minProgress = progress
work = (currThread.downloadSize - size) / 2
videoURL = currThread.downloadList[0][0]
worstThread = currThread
# if all threads finish or further work is unnecessary, start new round of downloads
if minProgress is None or work < 15000:
idleThreadIDs.add(thread.threadID)
if len(idleThreadIDs) == NUM_THREADS:
startNewRound = True
else:
#split work
ID = thread.threadID
print "splitting: " + str(ID)
# range request for new thread
videoURL = serverURLs[thread.threadID] + re.findall("[0-9]/.*", videoURL)[0][1:]
size = self.buffer.getFileSize(worstThread.bufferIndices[0], worstThread.downloadList[0][1], worstThread.downloadList[0][2])
# calculate new thread's range
if worstThread.downloadList[0][1] is None:
endByte = worstThread.downloadSize - 1
beginByte = size + ((endByte - size) / 2)
#print "None Case"
#print "(begin, end)", beginByte, endByte
else:
endByte = worstThread.downloadList[0][2]
beginByte = worstThread.downloadList[0][1] + size + ((endByte - (worstThread.downloadList[0][1] + size)) / 2)
#print "Other Case"
#print "(begin, end)", beginByte, endByte
downloadSize = endByte - beginByte + 1
# reduce byte range of helped thread
worstThread.downloadSize -= downloadSize
oldBegin = worstThread.downloadList[0][1]
oldEnd = worstThread.downloadList[0][2]
if oldBegin == None:
newBegin = 0
#.........这里部分代码省略.........