Skip to content

c4software/hdmi-wifi-hackathon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HDMI WiFi – Wayland Screencopy Edition

High-performance virtual display output and network streaming for Wayland.

This project was created during a Playmodays (company hackathon), where the goal was to build a proof of concept using a vibe-code approach: rapid ideation, fast iteration, and pragmatic engineering.

HDMI WiFi duplicate the screen of a Wayland compositor (e.g. Sway, Hyprland, Niri, etc.) using the Wayland Screencopy protocol, then streams it in real time over the local network using HTTP and raw H.264.

✨ Features

⚡ Native Wayland Support

  • Built on the wlr-screencopy-unstable-v1 protocol
  • Compatible with Sway, Hyprland, and any wlroots-based compositor

🚀 High Performance Pipeline

  • Zero-copy capture (DMA-BUF / shared memory)
  • Optimized H.264 encoding
    • x264 encoder
    • SIMD-accelerated colorspace conversion
  • Low-latency streaming of raw H.264 via HTTP chunked transfer

🧠 Smart & Efficient

  • On-demand pipeline
    Capture and encoding automatically pause when no clients are connected
    (idle CPU usage < 1%)
  • Automatic downscaling
    High-resolution sources (e.g. 2880×1920) are scaled down to 1080p for maximum compatibility

🕸️ Universal Web Client

  • Built-in H.264 web player (powered by jMuxer)
  • Decodes raw H.264 stream in real-time
  • Works on all modern browsers (desktop, tablet, mobile)

📋 Requirements

  • Linux with a Wayland session
  • Supported compositors Sway, Hyprland, Wayfire, River (any compositor supporting wlr-screencopy-unstable-v1)
  • System dependencies
    • libx264
    • ffmpeg (libavutil, libswscale)
    • clang (for compilation)

🚀 Installation & Usage

1. Clone and Build

git clone https://github.com/your-repo/hdmi-wifi
cd hdmi-wifi
cargo build --release

2. Start the Server

Run the executable from a terminal inside your Wayland session:

# Utilisation basique (configuration par défaut : 1080p@30fps)
./target/release/hdmi-wifi

# 🔋 Mode économie de batterie (recommandé pour laptops)
./target/release/hdmi-wifi --battery-saver

# Avec un preset de qualité
./target/release/hdmi-wifi --quality medium   # 720p@30fps
./target/release/hdmi-wifi --quality ultra    # 1440p@30fps

# 🎯 Sélection codec pour économie d'énergie
./target/release/hdmi-wifi --codec vaapi-hevc  # H.265 hardware (Intel/AMD)
./target/release/hdmi-wifi --codec vaapi-h264  # H.264 hardware (Intel/AMD)
./target/release/hdmi-wifi --codec x265        # H.265 software (meilleure compression)

# Personnalisation avancée
./target/release/hdmi-wifi --fps 60 --resolution hd720
./target/release/hdmi-wifi --resolution qhd1440 --bitrate 7000

# Override d'un preset avec flags individuels
./target/release/hdmi-wifi --quality high --fps 60  # 1080p@60fps au lieu de 30fps

# Changer l'adresse d'écoute
./target/release/hdmi-wifi --bind 127.0.0.1:9000

# 💡 Optimisation batterie maximale (720p, HEVC, 24fps)
./target/release/hdmi-wifi --battery-saver --resolution hd720 --fps 24

📖 Guide complet d'optimisation batterie : voir BATTERY_OPTIMIZATION.md

The server listens by default on:

0.0.0.0:8080

3. Connect a Client

From any device on the same local network (laptop, tablet, phone), open:

http://YOUR_PC_IP:8080

The video stream starts automatically.

⚙️ Configuration

Arguments en Ligne de Commande

Le serveur supporte plusieurs options pour adapter la qualité du streaming à votre réseau WiFi :

hdmi-wifi [OPTIONS]

Options:
  --quality <QUALITY>              Preset de qualité global [low|medium|high|ultra]
  --resolution <RESOLUTION>        Résolution de sortie [sd480|hd720|hd1080|qhd1440|uhd4k]
  --custom-resolution <WxH>        Résolution personnalisée (ex: 1280x1024)
  --fps <FPS>                      FPS (1-120) - Images par seconde
  --bitrate <BITRATE>              Bitrate en kbps (override automatique)
  --bind <BIND>                    Adresse d'écoute [default: 0.0.0.0:8080]
  --codec <CODEC>                  Codec [x264|x265|vaapi-h264|vaapi-hevc|vaapi-av1|vaapi-vp9|amf-h264|amf-hevc|auto]
  --battery-saver                  Mode économie de batterie (AV1/HEVC hardware prioritaire)
  -h, --help                       Afficher l'aide
  -V, --version                    Afficher la version

Note: --resolution et --custom-resolution sont mutuellement exclusifs.

Codecs Disponibles

Codec Type Avantages Consommation CPU/GPU
auto Auto Détection automatique (défaut) Variable
vaapi-av1 Hardware AV1 Intel/AMD, compression ultime ⚡ Très faible (GPU)
vaapi-hevc Hardware H.265/HEVC Intel/AMD, meilleure compression ⚡ Très faible (GPU)
vaapi-vp9 Hardware VP9 Intel/AMD ⚡ Très faible (GPU)
vaapi-h264 Hardware H.264 Intel/AMD ⚡ Faible (GPU)
amf-hevc Hardware H.265/HEVC AMD (optimisé) ⚡ Très faible (GPU AMD)
amf-h264 Hardware H.264 AMD (optimisé) ⚡ Faible (GPU AMD)
x265 Software H.265/HEVC, excellente compression 🔥 Moyenne (30-40% CPU)
x264 Software H.264, compatible universel 🔥 Élevée (40-60% CPU)

Presets de Qualité

Preset Résolution FPS Bitrate Usage
low 480p 20 800 kbps WiFi faible / Mobile 4G
medium 720p 30 1500 kbps WiFi standard / Tablette
high 1080p 30 3000 kbps WiFi performant (par défaut)
ultra 1440p 30 5500 kbps WiFi excellent / Réseau local

Presets de Résolution

Résolution Dimensions Bitrate recommandé Description
sd480 854×480 1000 kbps Connexion limitée
hd720 1280×720 1500 kbps HD standard
hd1080 1920×1080 3000 kbps Full HD (par défaut)
qhd1440 2560×1440 5500 kbps QHD - Haute résolution
uhd4k 3840×2160 9000 kbps 4K Ultra HD

Exemples d'Utilisation

# WiFi faible : streaming optimisé basse latence
./target/release/hdmi-wifi --quality low

# WiFi performant : augmenter le FPS pour plus de fluidité
./target/release/hdmi-wifi --quality high --fps 60

# Réseau local : qualité maximale
./target/release/hdmi-wifi --quality ultra

# Personnalisation complète
./target/release/hdmi-wifi --resolution hd720 --fps 60 --bitrate 2500

# Capture 4K (nécessite CPU puissant et WiFi 6)
./target/release/hdmi-wifi --resolution uhd4k

Résolutions Personnalisées

Pour des résolutions non-standard (moniteurs ultra-wide, ratios spécifiques, etc.), utilisez --custom-resolution :

# Écran 4:3 classique
./target/release/hdmi-wifi --custom-resolution 1280x1024

# Ultra-wide 21:9
./target/release/hdmi-wifi --custom-resolution 2560x1080

# Format carré
./target/release/hdmi-wifi --custom-resolution 1920x1920

# Avec FPS et bitrate personnalisés
./target/release/hdmi-wifi --custom-resolution 1680x1050 --fps 60 --bitrate 3500

Contraintes :

  • Largeur et hauteur doivent être des multiples de 2 (requis pour l'encodage YUV420)
  • Largeur : 320-7680 pixels
  • Hauteur : 240-4320 pixels
  • Le bitrate est calculé automatiquement (~0.0015 kbps/pixel) si non spécifié

Priorité des Options

Les flags individuels overrident le preset de qualité :

# Équivalent à high (1080p@30fps@3000kbps)
./target/release/hdmi-wifi --quality high

# Override du FPS seulement (1080p@60fps@3000kbps)
./target/release/hdmi-wifi --quality high --fps 60

# Override de la résolution (720p@30fps@1500kbps)
./target/release/hdmi-wifi --quality high --resolution hd720

# Override manuel complet
./target/release/hdmi-wifi --resolution hd1080 --fps 30 --bitrate 4000

Note : Les résolutions supérieures à celle de votre écran seront automatiquement downscalées par le pipeline de capture.

📊 Monitoring & Stats

A JSON endpoint is available for real-time monitoring:

curl http://localhost:8080/stats

Example response:

{
  "active_clients": 1,
  "frames_captured": 1250,
  "frames_encoded": 1250,
  "frames_dropped": 0,
  "total_bytes_sent": 45021000
}

🐛 Troubleshooting

Black Screen or “No Stream”

  • Ensure you are running under Wayland:

    echo $XDG_SESSION_TYPE

    Expected output: wayland

  • Verify that your compositor supports wlr-screencopy

    • GNOME (Mutter) is NOT supported GNOME uses a proprietary D-Bus API for screencasting

High Latency

  • Prefer wired Ethernet when possible
  • On Wi-Fi, use 5 GHz networks

📄 License

MIT

About

This project was created during a Playmodays (company hackathon), where the goal was to build a POC using a vibe-code only approach.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors