Skip to content

Cast: watch a medialink camera on a TV, with its sound - #4

Merged
bdbarnett merged 1 commit into
mainfrom
medialink-tv
Oct 29, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
medialink-tv

Conversation

@bdbarnett

Copy link
Copy Markdown
Contributor

Adds cast/medialink_tv.py, which finds a medialink camera on the network by name and casts its pictures and sound to a Roku TV or to Windows Wireless Display over Miracast. The board running it needs no screen. It uses medialink's Video, Screen and Intercom, which reached pydevices main in PyDevices/pydevices#326.

Two changes in the cast example make this work on an ESP32-P4:

  • CastDisplay.pcm_out() now works on the P4. Before, it existed only on a desktop. On the board it returns a PCMOutput over the audio pump (castfast.pump_out), because the cast's tap reads the pump and boarddev.pcm_out() is plain I2S, which the cast never hears. The rate has to match audio_format.
  • CastDisplay.blit_rect copies whole rows as a single slice. framebuf's blit goes pixel by pixel and took 60 ms for a 640x480 picture on the P4. The copy takes 11 ms, which brings a decoded picture's show() from about 135 ms down to about 81 ms.

What was measured

The camera side was pydevices' surveillance camera example running on a computer, with a folder of numbered JPEG cards and a file of known speech standing in for the microphone. Sound was scored by recording it and transcribing it.

Watcher TV Pictures shown Sound Words heard
CPython, Linux Roku 10 a second ~100 ms late, 0 underruns all, both models
CPython, Windows Roku 10 a second ~100 ms late, 0 underruns all (one "before noon" missed in 1 of 3 by Moonshine)
ESP32-P4 panel, camera at 5 a second Roku ~4.6 a second 380 ms late, 6 underruns in 100 s all, both models
ESP32-P4 panel, camera at 5 a second Windows Wireless Display ~4.7 a second 34 ms late, 0 underruns all (Whisper), all but one word misheard (Moonshine)

On the Roku, the media player reported state=play, pcm sound and H.264 video. Wireless Display window shots showed the numbered cards.

The rates, and why

Clean sound comes first. With the camera at 10 pictures a second, the P4 showed about 6.5 a second, dropped packets, and sound ran 250–340 ms late. At 5 a second it keeps up with almost no drops. The cast cap (FPS) made no difference to the sound at 30, 15 or 10, since castif only sends when the picture changes, so it is 10. Both rates and the reason are in the docstring.

cast/medialink_tv.py finds a medialink camera by name and casts its pictures
and sound over Miracast to a Roku TV or Windows Wireless Display.

CastDisplay.pcm_out() now works on the ESP32-P4 too: it is the board's
speaker through the audio pump (castfast.pump_out), which the cast hears.
boarddev.pcm_out() there is plain I2S, so its sound never reached the cast.

CastDisplay.blit_rect copies whole rows as one run instead of framebuf's
pixel-by-pixel blit: 11 ms for 640x480 on the P4 instead of 60.
@bdbarnett
bdbarnett merged commit 6f7d476 into main Oct 29, 2026
2 checks passed
@bdbarnett
bdbarnett deleted the medialink-tv branch October 29, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant