$ show Genymobile/scrcpy
scrcpy is a high-performance desktop application that mirrors and controls Android devices over USB or TCP/IP. The client is a native C application using SDL3 for rendering and input, FFmpeg for media decoding, and libusb for USB-OTG mode. The server is a Java service running on the Android device that captures screen and audio via MediaCodec and hidden Android APIs, streaming them over an ADB tunnel. The system supports multiple input modes (SDK injection, UHID, AOA HID), video/audio recording, V4L2 loopback output, and clipboard synchronization. Architecture is client-server with a well-defined protocol, trait-based pipeline for frame/packet processing, and extensive cross-platform support (Linux, Windows, macOS).
The LLM identified 5 files worth highlighting for reuse:
A generic, type-safe ring buffer implemented entirely via C preprocessor macros. Supports push/pop/peek with element copying and capacity management. Fully reusable in any C project needing a fixed-capacity queue, independent of scrcpy internals.
Defines a generic sink interface for video frames (sc_frame_sink) with push and close callbacks. Used throughout scrcpy to chain frame sources (decoder) to sinks (screen, recorder, v4l2). The pattern is a reusable abstraction for building modular stream processing pipelines in C.
Provides static methods to enumerate available MediaCodec encoders and decoders, with filtering by MIME type, name, and capabilities. Includes logging of encoder details for diagnostics. A self-contained utility for any Android project needing codec discovery.
Centralizes all reflection-based workarounds for Android version differences (e.g., AudioRecord foreground behavior, Oculus Quest virtual display bug). Each workaround is a static method with version checks and fallbacks. Demonstrates a clean pattern for isolating platform-specific hacks, extractable for any Android app needing similar compatibility bridges.
Header-only macros and inline functions for reading/writing 16, 32, and 64-bit integers in big-endian and little-endian order. Uses compiler built-ins for optimal code generation. Fully portable and reusable in any C project that needs explicit byte order handling.
The divergent implementation provides a more robust and flexible filter system with explicit thread safety guarantees and clearer separation of concerns. It introduces dedicated functions for async processing management (mp_filter_wakeup, mp_filter_mark_async_progress, mp_filter_internal_mark_progress) that enable better control over filter execution flow and error handling. The struct design with explicit callback function pointers for init, process, reset, and command operations provides a cleaner, more extensible interface than the typical trait-based approach. Additionally, the detailed documentation and explicit safety requirements make the API more maintainable and less error-prone for implementers.