Skip to content

Commit f357ed3

Browse files
committed
fix.
1 parent 7b70f4b commit f357ed3

1 file changed

Lines changed: 19 additions & 21 deletions

File tree

livekit-rtc/tests/test_video.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,16 @@ async def publish_colors() -> None:
180180
loop = asyncio.get_event_loop()
181181
start = loop.time()
182182
global_idx = 0
183-
for _color_name, rgb in VIDEO_COLOR_SEQUENCE:
184-
frame = _solid_color_rgba_frame(VIDEO_WIDTH, VIDEO_HEIGHT, rgb)
185-
for _ in range(frames_per_color):
186-
source.capture_frame(frame)
187-
global_idx += 1
188-
target = start + global_idx * frame_interval
189-
sleep_for = target - loop.time()
190-
if sleep_for > 0:
191-
await asyncio.sleep(sleep_for)
183+
for _repeat in range(2):
184+
for _color_name, rgb in VIDEO_COLOR_SEQUENCE:
185+
frame = _solid_color_rgba_frame(VIDEO_WIDTH, VIDEO_HEIGHT, rgb)
186+
for _ in range(frames_per_color):
187+
source.capture_frame(frame)
188+
global_idx += 1
189+
target = start + global_idx * frame_interval
190+
sleep_for = target - loop.time()
191+
if sleep_for > 0:
192+
await asyncio.sleep(sleep_for)
192193

193194
async def collect_frames() -> None:
194195
async for event in video_stream:
@@ -204,8 +205,8 @@ async def collect_frames() -> None:
204205
if stop_collecting.is_set():
205206
break
206207

207-
publish_task = asyncio.create_task(publish_colors())
208208
collect_task = asyncio.create_task(collect_frames())
209+
publish_task = asyncio.create_task(publish_colors())
209210

210211
await publish_task
211212
# Allow trailing frames to drain before signaling stop.
@@ -240,17 +241,14 @@ async def collect_frames() -> None:
240241
runs.append((color, 1))
241242
# A stable run has several frames of the same classified color.
242243
stable_run_min = max(3, VIDEO_FPS // 3)
243-
dominant = [c for c, n in runs if n >= stable_run_min]
244-
245-
expected_order = [name for name, _ in VIDEO_COLOR_SEQUENCE]
246-
# Find expected_order as a subsequence of dominant.
247-
seq_idx = 0
248-
for color in dominant:
249-
if seq_idx < len(expected_order) and color == expected_order[seq_idx]:
250-
seq_idx += 1
251-
assert seq_idx == len(expected_order), (
252-
f"Expected color sequence {expected_order} not found in dominant runs "
253-
f"{dominant}. Full classified stream: {classified}"
244+
dominant = {c for c, n in runs if n >= stable_run_min}
245+
246+
expected_colors = {name for name, _ in VIDEO_COLOR_SEQUENCE}
247+
missing_colors = expected_colors - dominant
248+
assert not missing_colors, (
249+
f"Expected colors {expected_colors} not all present in subscribed track; "
250+
f"missing {missing_colors}. Dominant colors: {dominant}. "
251+
f"Full classified stream: {classified}"
254252
)
255253

256254
# Snapshot the first received frame of each expected color to JPEG.

0 commit comments

Comments
 (0)