CastBayCastBay Download 中文

How CastBay works

What happens between your phone and the TV, and why CastBay behaves the way it does.

Contents
  1. What are AirPlay and AirPlay 2?
  2. How it works, in brief
  3. What is DLNA, and how does it relate to UPnP?
  4. How it works, in brief
  5. Three ways to cast, and what travels where
  6. Casting from a computer: CastBay for PC
  7. How your phone finds the TV
  8. Why music starts about two seconds late, and why that's a good thing
  9. Mirroring quality, and reading the stats
  10. Who can cast to your TV
  11. The remote and the connection
  12. What isn't supported, and why
  13. Built on open source

What are AirPlay and AirPlay 2?

AirPlay is Apple’s wireless media-sharing technology for sending music, video or a screen image to compatible receivers. AirPlay 2 extends the audio experience with multi-room playback, enhanced buffering and multi-device control. It is not simply higher-resolution mirroring, nor does it mean every stream uses lossless encoding.

How it works, in brief

  1. Discover: in CastBay’s local-network setup, the receiver advertises services through Bonjour (mDNS/DNS-SD). The sender finds it and reads its capabilities.
  2. Connect: the devices negotiate the playback mode, media format and any required verification, then establish control and media connections.
  3. Play: mirroring sends an encoded screen stream; music sends an audio stream; some video casting modes let the receiver fetch and play a media URL.
  4. Buffer and synchronize: timing information schedules playback, while buffering absorbs brief network interruptions. AirPlay 2 multi-room audio additionally coordinates compatible receivers so they play together, rather than each playing audio immediately on arrival.

Protocol capabilities are not a CastBay feature checklist. Built on UxPlay, CastBay provides AirPlay screen mirroring, music reception and compatible video casting. It does not currently provide AirPlay 2 multi-room grouping and synchronized playback, and should not be treated as a complete AirPlay 2 implementation. Compatibility depends on the sender, app, content and CastBay version.

Official resources: Apple AirPlay · Apple WWDC: Introducing AirPlay 2 (PDF). These describe Apple’s technology and ecosystem, not Apple certification or endorsement of CastBay.

What is DLNA, and how does it relate to UPnP?

DLNA (Digital Living Network Alliance) developed interoperability guidelines for sharing media between different manufacturers’ devices on a home network. It is not an audio or video codec: it builds on technologies such as UPnP and specifies how discovery, control, media formats and transport work together. UPnP supplies the underlying mechanisms; DLNA adds media interoperability requirements. They are not synonyms.

How it works, in brief

A typical app-to-CastBay media session works like this:

  1. Discover: the phone app searches for UPnP AV devices using SSDP and reads their device descriptions.
  2. Control: the app acts as a Control Point, sending a media URL and playback commands to a MediaRenderer such as CastBay. The media may come from a phone, NAS or internet service.
  3. Fetch: the renderer typically retrieves the media over HTTP and decodes it. Media data need not pass through the Control Point; the phone can also act as a MediaServer.
  4. Interact: UPnP services carry playback, pause, seek or volume commands and status queries or subscriptions. Available operations depend on both implementations and the media.

DLNA media casting is therefore not screen mirroring. If the phone serves the content, leaving the network or stopping its server interrupts playback. Independent playback requires the media source to remain reachable. Not every app’s cast button supports DLNA, and Google Cast is a different technology.

CastBay acts as the media renderer in this setup. Protocol compatibility does not imply that CastBay is DLNA Certified.

Official resources: DLNA · DLNA FAQ and certification · OCF: UPnP AV architecture and MediaServer / MediaRenderer specifications.

Three ways to cast, and what travels where

Casting from a computer: CastBay for PC

A Windows or Linux computer has no AirPlay to offer, so CastBay for PC uses a connection of CastBay's own, which only CastBay receivers understand. The receiver announces itself on the network (_castbay._tcp, much as AirPlay does), and the two sides open one TLS connection in which each proves who it is with its own key. The first time, the receiver shows a 6-digit code, built from both keys, to type on the computer; after that the receiver is remembered and a changed key is refused. Over it travel H.264 video, encoded by the graphics card where it can be (AMD, NVIDIA) and by the CPU (x264) otherwise, with a full picture (a key frame) every 2 seconds so that the damage after a dropped picture does not last (it is one TCP connection, so nothing is lost on the way; the sender drops the pictures the link cannot take, and those that build on them, and sends a key frame at once), and AAC sound. The TV decodes the video in hardware, as it does for mirroring. The protocol is written down in the source.

How your phone finds the TV

AirPlay discovers CastBay through Bonjour (mDNS/DNS-SD); DLNA uses SSDP. These are separate discovery mechanisms. With CastBay, the phone and receiver need a shared local network that allows them to communicate. Guest networks, AP isolation or multicast restrictions can prevent discovery. Also check that the receiver service is running, along with app permissions and firewall settings.

Why music starts about two seconds late, and why that's a good thing

An iPhone doesn't send music "as it plays". It sends each piece about two seconds ahead, stamped with the moment it should be heard, and keeps the TV's clock in step with its own. CastBay plays every piece at exactly that moment, the way an Apple TV or HomePod does. That short wait buys a lot:

Apps pause differently, and CastBay follows each, as an Apple TV does. Apple Music stops the TV at once. NetEase Cloud Music just stops sending, so what the TV already has plays out for a couple of seconds; when you resume, it carries on without a gap.

CastBay includes Apple’s open-source ALAC decoder to receive and decode ALAC audio without depending on a device-provided decoder. ALAC is lossless encoding, but the source may already have been lossily encoded or resampled, and the transport format depends on the sender and playback mode. Android audio processing and the output path also affect the result. ALAC support therefore does not guarantee end-to-end lossless playback in every scenario.

Mirroring quality, and reading the stats

On a 4K TV with a hardware H.265 decoder, CastBay offers the phone H.265 up to 4K at up to 60 frames per second; otherwise H.264 up to 1080p. The phone chooses what it actually sends within that.

Turn on Show stats (Settings → Playback, or the quick menu while playing) to see what's going on. While mirroring, the phone also reports on itself:

So a stutter can be traced: packet loss or a bandwidth close to its limit points to Wi-Fi; the phone sending fewer frames than its target points to the phone being busy; the TV dropping frames points to the TV.

Who can cast to your TV

Settings → Connection → Casting verification offers four choices:

Whichever you choose, every device that has cast is listed there, and any of them can be blocked. Removing them all makes every device new again; if any had paired with a PIN, the TV also takes a new identity, so phones pair again instead of failing to connect.

The remote and the connection

What isn't supported, and why

Built on open source

CastBay is open source under GPL-3.0. It builds on UxPlay for the AirPlay protocol, libplist, Apple's ALAC decoder and Media3 ExoPlayer, with Android's hardware video decoding. CastBay for PC also builds on FFmpeg and x264 for video encoding and Tauri for its window. The full source is on GitHub.