skip existence check when counting segment views on /stream.mp4

このコミットが含まれているのは:
n9k 2021-04-12 04:52:20 +00:00
コミット 717b033791
1個のファイルの変更3行の追加3行の削除

6
app.py
ファイルの表示

@ -173,13 +173,13 @@ def segment_arbitrary(n):
response.set_cookie('token', token) response.set_cookie('token', token)
return response return response
def _view_segment(n, token=None): def _view_segment(n, token=None, check_exists=True):
# n is None if segment_hook is called in ConcatenatedSegments and the current segment is init.mp4 # n is None if segment_hook is called in ConcatenatedSegments and the current segment is init.mp4
if n == None: if n == None:
return return
# technically this is a race condition # technically this is a race condition
if not os.path.isfile(os.path.join(SEGMENTS_DIR, f'stream{n}.m4s')): if check_exists and not os.path.isfile(os.path.join(SEGMENTS_DIR, f'stream{n}.m4s')):
return return
with lock: with lock:
@ -194,7 +194,7 @@ def stream():
segments_cache=SEGMENTS_CACHE, segments_cache=SEGMENTS_CACHE,
segment_offset=max(VIEWS_PERIOD // HLS_TIME, 2), segment_offset=max(VIEWS_PERIOD // HLS_TIME, 2),
stream_timeout=HLS_TIME + 2, stream_timeout=HLS_TIME + 2,
segment_hook=lambda n: _view_segment(n, token)) segment_hook=lambda n: _view_segment(n, token, check_exists=False))
file_wrapper = werkzeug.wrap_file(request.environ, concatenated_segments) file_wrapper = werkzeug.wrap_file(request.environ, concatenated_segments)
response = Response(file_wrapper, mimetype='video/mp4') response = Response(file_wrapper, mimetype='video/mp4')
response.headers['Cache-Control'] = 'no-cache' response.headers['Cache-Control'] = 'no-cache'