Mobile Development 22 min read

USB Wired Screen Casting for iOS and Android on Windows

The article details a USB‑based wired screen‑casting solution for iOS and Android on Windows, explaining how to replace wireless LAN casting with driver‑installed USB communication, using libimobiledevice and libusbK to capture, encode (H.264/AAC), package into FLV, transfer via a custom header, and restore original device drivers after use.

Bilibili Tech
Bilibili Tech
Bilibili Tech
USB Wired Screen Casting for iOS and Android on Windows

The article introduces a USB‑based wired screen‑casting solution that allows mobile devices (iOS or Android) to stream their screen, microphone, and audio to a PC running the "PC Live‑caster" software. Wired casting overcomes the instability and network‑segmentation issues of wireless Wi‑Fi casting.

Background : The original live‑caster only supported wireless casting via LAN. The article explains how to replace this with a USB data‑exchange method on Windows.

Prerequisite knowledge : Basic understanding of USB architecture, Vendor ID (VID) and Product ID (PID), and how Windows associates drivers with USB devices.

iOS wired casting – Windows side :

Uses the open‑source libimobiledevice library (LGPL‑2.1) and the Apple Mobile Device Service (AMDS) that ships with iTunes.

AMDS creates a Windows service that bridges communication between the PC and the iOS device.

Device enumeration is performed via idevice_get_device_list() , connection via idevice_connect() , and data transfer with idevice_connection_send() / idevice_connection_receive_timeout() .

The data packets follow a custom header defined as:

struct TransferFrame {
    uint32_t version;
    uint32_t type;
    uint32_t tag;
    uint32_t payload_size;
    uint32_t identifier;
};

After a handshake (a packet with the above header and no payload), the iOS side encodes video/audio into an FLV stream, prepends the header, and sends it to the Windows receiver, which demuxes and decodes the stream.

iOS wired casting – iOS side :

Uses ReplayKit to capture screen, microphone, and device audio.

Audio/VideoToolbox encodes video to H.264 and audio to AAC, then packages them into FLV.

Data is transmitted over the private usbmux protocol via a TCP‑like socket created by the Broadcast Upload Extension.

Android wired casting – Windows side :

Relies on libusb (LGPL‑2.1) and the libusbK driver.

Device enumeration is performed with Windows SetupAPI (SetupDiGetClassDevsW, SetupDiEnumDeviceInfo) to locate portable devices (WPD) and filter by VID/PID.

After selecting a device, a custom libusbK driver INF is generated (VID/PID substituted) and installed via dpinst64.exe .

The device is switched to Android Open Accessory (AOA) mode; its VID/PID change to Google’s reserved IDs (0x18D1/0x2D00 or 0x2D01 if USB debugging is enabled).

Communication then proceeds with libusb_bulk_transfer() , using the same TransferFrame header as the iOS path.

Android wired casting – Android side :

From Android 3.1 onward, devices support both host and accessory modes. In accessory mode, the PC acts as the USB host.

The app declares an <intent-filter> and <meta-data> for hardware.usb.action.USB_ACCESSORY_ATTACHED and provides an accessory_filter.xml matching the PC’s accessory description.

When the accessory connects, the system notifies the app, which obtains a UsbAccessory via UsbManager , opens a ParcelFileDescriptor , and reads/writes the FLV stream.

Screen capture uses MediaProjection , audio capture uses AudioRecord , and encoding uses MediaCodec (H.264 for video, AAC for audio) before FLV packaging.

Driver uninstall :

To restore original device functionality, the custom libusbK driver can be removed using SetupAPI calls (SetupDiCallClassInstaller with DIF_REMOVE ) and SetupUninstallOEMInfW to delete the INF.

Conclusion : Wired USB casting provides a stable, low‑latency alternative to wireless LAN casting, requiring only a decent USB cable. The implementation involves driver installation, USB enumeration, and media encoding on both iOS and Android, with similar data‑transfer protocols on the Windows side.

iOSAndroidwindowslibimobiledevicelibusbscreen castingusb
Bilibili Tech
Written by

Bilibili Tech

Provides introductions and tutorials on Bilibili-related technologies.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.