Skip to content

mycrl/hylarana

Repository files navigation

Hylarana


A cross-platform screen casting library implemented by rust.
documentation: docs.rs
examples: rust / android
watch the demo on youtube: link



Unlike implementations such as Miracast, AirPlay, etc. that rely on hardware support (WIFI Direct), this library works on most common hardware.

The project is cross-platform, but the priority platforms supported are Windows and Android, Unlike a solution like DLNA, this project is more akin to airplay, so low latency is the main goal, currently the latency is controlled at around 150-250ms (with some variations on different platforms with different codecs), and maintains a highly easy to use API and very few external dependencies.

Unlike traditional screen casting implementations, this project can work in forwarding mode, in which it can support casting to hundreds or thousands of devices at the same time, which can be useful in some specific scenarios (e.g., all advertising screens in a building).

How was this achieved?

First of all screen capture, this part of the implementation of each platform independently separate, currently windows and android capture the highest efficiency, because the use of hardware-accelerated textures, android uses the virtual display, windows uses the WGC, and linux only uses the x11grab, so the efficiency of linux is poorer.

For audio and video codecs, H264 is used for video and Opus is used for audio, again, hardware accelerated codecs are available for both windows and android. Currently, the hardware codecs on windows are adapted to Qsv and D3D11VA, while android is adapted to Qualcomm, Kirin, and RK series of socs.

Both SRT and UDP multicast schemes are used for the transport layer of the data. The audio and video data transmitted by the transport layer are bare streams and do not contain similar encapsulations such as FLV. For SRT, many parameters have been adjusted in detail to suit the LAN environment, so that when using the SRT transport layer, the delay can be controlled at about 20-40 ms. The UDP multicast scheme has only a receive buffer and no transmit buffer, and the fixed maximum delay of UDP multicast is 40 ms, which is used to sort and wait for packets in the buffer.

The graphics interface also uses both Direct3D11 and WebGPU solutions, WebGPU is a cross-platform graphics interface wrapper library, but on some older devices on windows, WebGPU does not work because WebGPU requires a minimum of Direct3D12 support, so Direct3D11 is provided on windows programme. Similarly, the graphics implementations for windows and android are fully hardware accelerated, in general, a video frame is captured, encoded, decoded and displayed within the GPU, and scaling and format conversion for video frames on windows is also fully hardware accelerated.

Build Instructions

Requirements

  • Git
  • Rust: Rust stable toolchain.
  • C++20 or above compliant compiler. (G++/Clang/MSVC)
  • CMake: CMake 3.16 or above as a build system.
  • Node.js: Node.js 16 or above as a auto build script.
  • Cargo NDK: Cargo NDK is optional and required for Android Studio projects.
Linux (Ubuntu/Debian)

For Linux, you need to install additional dependencies to build SRT and other.

sudo apt-get update
sudo apt-get install tclsh pkg-config cmake libssl-dev build-essential libasound2-dev libsdl2-dev libva-dev v4l-utils
Macos
brew install cmake ffmpeg@7

Build

Examples and SDK library files can be automatically packaged by running an automatic compilation script.

npm run build:release

The Release version is compiled by default. If you need the Debug version, just run npm run build:debug.
For android, there is no need to manually call compilation. You can directly use Android Studio to open android.

License

LGPL Copyright (c) 2024 mycrl.