Skip to content

Commit b1a646d

Browse files
committed
update publish_hue
1 parent 0994e75 commit b1a646d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

examples/publish_hue/room.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,23 @@ async def publish_frames(source: livekit.VideoSource):
2424

2525
rgb = colorsys.hsv_to_rgb(hue, 1.0, 1.0)
2626
rgb = [int(x * 255) for x in rgb]
27-
argb_color = rgb + [255]
2827

29-
for i in range(0, len(arr), 4):
30-
arr[i:i+4] = argb_color
28+
argb_color = np.array(rgb + [255], dtype=np.uint8)
29+
arr.flat[::4] = argb_color[0]
30+
arr.flat[1::4] = argb_color[1]
31+
arr.flat[2::4] = argb_color[2]
32+
arr.flat[3::4] = argb_color[3]
3133

3234
source.capture_frame(frame)
3335

34-
hue += framerate/2 # 3s for a full cycle
36+
hue += framerate/3 # 3s for a full cycle
3537
if hue >= 1.0:
36-
hue -= 1.0
38+
hue = 0.0
3739

38-
await asyncio.sleep(framerate)
40+
try:
41+
await asyncio.sleep(framerate)
42+
except asyncio.CancelledError:
43+
break
3944

4045

4146
async def main():
@@ -63,6 +68,8 @@ async def main():
6368
await room.run()
6469
except asyncio.CancelledError:
6570
logging.info("closing the room")
71+
source_task.cancel()
72+
await source_task
6673
await room.close()
6774

6875

0 commit comments

Comments
 (0)