Fasilul Rahman C.K
Fasilul Rahman C.KFull-Stack Software EngineerMalappuram, Kerala, India
Live4Cast icon

Systems Engineering • Real-Time Media Streaming

Live4Cast

A private, zero-cloud Android-to-Windows real-time screen and 4K camera streaming system utilizing native MediaProjection, hardware MediaCodec H.264/HEVC encoding, low-latency SRT transport, and an Electron companion receiver.

Shipped v1.0.0 (Android APK & Windows Desktop Companion)
Role
Lead Architect & Systems Developer
Period
Shipped v1.0.0 (Android & Desktop)
Outcome
Achieved sub-300ms glass-to-glass latency over local Wi-Fi and USB reverse-tethering with hardware MediaCodec encoding, lock-free PCM audio mixing, bidirectional handshake protocol, and zero cloud routing or account dependency.
< 300msGlass-to-Glass Latency1080p/30fps hardware pipe
4K / 60fpsHardware PipelineMediaCodec H.264 / HEVC

The Operational Friction: Latency, Privacy, and Cloud Lock-In

Mobile screen mirroring and studio streaming tools suffer from three widespread operational compromises:

  1. High Latency & Audio Tearing: Generic casting protocols (such as Miracast or Google Cast) introduce 800ms to 2,000ms of lag, rendering them completely unusable for live demos, interactive mobile gameplay, or tutorial recording.
  2. Invasive Cloud Intermediaries: Commercial tools often route video data through remote cloud relay servers, mandate account creation, or introduce monthly SaaS subscriptions simply to display a local device on an adjacent monitor.
  3. Audio Capture Restrictions: Prior to Android 10, capturing internal system audio alongside microphone input was blocked by operating system sandboxes. Even on modern Android versions, mixing low-latency PCM audio without race conditions or buffer underruns remains a severe technical hurdle.

I engineered Live4Cast (originally *Staremer*) to solve this: an account-free, ultra-low-latency, dual-component streaming engine connecting an Android mobile device to a trusted Windows PC over local Wi-Fi or USB reverse-tethering with sub-300ms glass-to-glass latency.

Hardware-Accelerated Video Pipeline & Dynamic Rotation

Capturing raw display frames at 1080p60 generates gigabytes of uncompressed YUV data per second, which cannot be copied through user-space memory buffers without overwhelming the mobile CPU and thermal throttling.

I configured MediaProjection to render directly onto an OpenGL input surface provided by MediaCodec:

  • Zero-Copy Video Pipeline: The display hardware blits frames directly to the GPU video encoder surface. The CPU only handles lightweight packet headers and SRT network packetization.
  • Dynamic Orientation Recovery (VirtualDisplayResizer): Rotating a mobile phone between portrait and landscape fundamentally alters the frame width and height (e.g., $1080 \times 1920$ to $1920 \times 1080$). Hardware MediaCodec instances cannot dynamically resize their input surfaces without a re-init.
  • I engineered an automated lifecycle coordinator (EncoderLifecycle.kt and WarmRestartValidator.kt): upon receiving display configuration change events, the service renegotiates resolution headers, flushes active SRT network buffers, and re-binds the virtual display in under 120 milliseconds, preventing receiver crash loops.

Lock-Free Audio Ring Buffer & PCM Stream Mixing

Capturing crisp audio during mobile screencasting requires combining two distinct audio sources:

  1. Device Internal Playback: Captured via Android’s AudioPlaybackCaptureConfiguration API (game audio, music, app sound effects).
  2. Microphone Voiceover: Sampled from the mobile microphone (AudioRecord).

Synchronizing these two asynchronous audio streams without audio pops or thread contention required a custom concurrent architecture:

kotlin
// encoder/LockFreeAudioRingBuffer.kt - Lock-Free Circular Audio Buffer
class LockFreeAudioRingBuffer(private val capacity: Int) {
    private val buffer = ByteArray(capacity)
    private val writeIndex = AtomicInteger(0)
    private val readIndex = AtomicInteger(0)

    fun write(data: ByteArray, offset: Int, length: Int): Boolean {
        val currentWrite = writeIndex.get()
        val currentRead = readIndex.get()
        val available = capacity - (currentWrite - currentRead)

        if (length > available) return false // Prevent overflow buffer tearing

        val bufferOffset = currentWrite % capacity
        val firstChunk = minOf(length, capacity - bufferOffset)
        System.arraycopy(data, offset, buffer, bufferOffset, firstChunk)

        if (length > firstChunk) {
            System.arraycopy(data, offset + firstChunk, buffer, 0, length - firstChunk)
        }

        writeIndex.addAndGet(length)
        return true
    }
}
  • Thread-Isolated Ring Buffer: A lock-free atomic circular ring buffer (LockFreeAudioRingBuffer.kt) decouples the high-priority real-time audio thread from network transmission delays.
  • PCM Software Mixer (PcmAudioMixer.kt): Implements dynamic range compression and soft clipping, mathematically summing 16-bit linear PCM audio samples from internal playback and microphone streams without digital clipping distortion.

Desktop-Authoritative Connection Protocol (V3)

To ensure privacy on shared Wi-Fi networks (such as offices, university campuses, or coffee shops), Live4Cast enforces a Desktop-Authoritative Trust Protocol:

  1. Discovery: Android and Desktop discover each other locally using UDP mDNS broadcasts.
  2. Handshake & Mutual Consent: Android initiates a TCP connection to Desktop port 8888 sending a HELLO {uuid, device_name} payload.
  3. The ACT Security Gate: If the device UUID is unrecognized, the Desktop client presents an interactive Actionable Consent Trust (ACT) dialog. If the user approves, the desktop cryptographically persists the device UUID in its trusted store and replies with WELCOME {srt_port}.
  4. Resilient Reconnection: If the Wi-Fi connection hiccups or changes IP subnets, the Android client initiates an exponential backoff reconnect attempt using the last verified desktop signature, resuming video within 2 seconds.

Production Outcomes

  • Shipped Desktop & Mobile Binaries: Packaged and distributed standalone Windows installers (Live4Cast-Setup-1.0.0.exe, portable ZIP) and signed Android APKs (Live4Cast-Android-v1.0.0.apk) with automated NSIS packaging.
  • Sub-300ms Glass-to-Glass Latency: Measured median latency under 300ms at 1080p/30fps over standard 5GHz Wi-Fi, dropping to sub-100ms over USB reverse-tethering (adb reverse).
  • Complete Zero-Cloud Sovereignty: 100% of video frames, audio samples, and device identifiers remain confined to the local physical network.

Key Achievements & Metrics

Architected a dual-platform streaming system: a native Android Kotlin sender service and a signed Windows Electron receiver companion.

Engineered a low-latency video pipeline using Android MediaProjection and hardware MediaCodec (H.264/HEVC) streaming over the SRT protocol.

Designed a lock-free PCM audio ring buffer mixing internal device audio (AudioPlaybackCapture) and microphone inputs without tearing.

Built a desktop-authoritative TCP handshake protocol (V3) with mDNS discovery, ACT consent verification, and automatic network reconnection.

Technologies Used

  • Kotlin
  • Android
  • Electron
  • TypeScript
  • React
  • MediaCodec
  • SRT Protocol
  • FFmpeg
  • TailwindCSS