skip existence check when counting segment views on /stream.mp4
このコミットが含まれているのは:
コミット
717b033791
6
app.py
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'
|
||||||
|
|
読み込み中…
新しいイシューから参照