Streaming is working fairly well now.

This commit is contained in:
SergeantPanda 2025-03-13 15:56:04 -05:00
parent 317874b5b8
commit 69f4ceb137
2 changed files with 7 additions and 3 deletions

View file

@ -29,7 +29,7 @@ class TSConfig(BaseConfig):
MAX_RETRIES = 3 # maximum connection retry attempts
# Buffer settings
INITIAL_BEHIND_CHUNKS = 100 # How many chunks behind to start a client
INITIAL_BEHIND_CHUNKS = 4 # How many chunks behind to start a client
CHUNK_BATCH_SIZE = 5 # How many chunks to fetch in one batch
KEEPALIVE_INTERVAL = 0.5 # Seconds between keepalive packets when at buffer head
@ -52,5 +52,5 @@ class TSConfig(BaseConfig):
# TS packets are 188 bytes
# Make chunk size a multiple of TS packet size for perfect alignment
# ~1MB is ideal for streaming (matches typical media buffer sizes)
BUFFER_CHUNK_SIZE = 188 * 5644 # ~1MB (exactly 1,061,072 bytes)
BUFFER_CHUNK_SIZE = 188 * 1361 # ~256KB

View file

@ -243,7 +243,11 @@ def stream_ts(request, channel_id):
return
# Client state tracking - use config for initial position
local_index = max(0, buffer.index - Config.INITIAL_BEHIND_CHUNKS)
initial_behind = getattr(Config, 'INITIAL_BEHIND_CHUNKS', 10)
current_buffer_index = buffer.index
local_index = max(0, current_buffer_index - initial_behind)
logger.debug(f"[{client_id}] Buffer at {current_buffer_index}, starting {initial_behind} chunks behind at index {local_index}")
initial_position = local_index
last_yield_time = time.time()
empty_reads = 0