Architecture
Fenpo Cast has a native receiver core (C/C++, built with the NDK) and a Kotlin app on top of it.
Flow
iPhone ──mDNS──▶ NsdManager (_airplay._tcp, _raop._tcp) ServiceAdvertiser
│
├─ TCP, dynamic port ─▶ UxPlay httpd / raop libfenpocast.so
│ pairing, FairPlay, /info, SETUP, /feedback, HLS endpoints
├─ mirroring stream (TCP) ─▶ raop_rtp_mirror: AES-CTR decrypt → Annex B
├─ audio (UDP RTP) ─▶ raop_rtp + raop_buffer: decrypt, reorder
└─ time (UDP NTP) ─▶ raop_ntp
│
receiver/receiver.c (JNI)
│ raop callbacks → NativeReceiver.kt
▼
ReceiverController ──▶ VideoDecoder (MediaCodec → SurfaceView)
──▶ AudioRenderer (MediaCodec AAC / PCM → AudioTrack)
──▶ StreamPlayer (Media3 HLS, over localhost)
──▶ CastState (StateFlow) → Compose screens
Repository layout
app/src/main/
├── cpp/
│ ├── CMakeLists.txt BoringSSL + libplist + ALAC + UxPlay core → libfenpocast.so
│ ├── receiver/ JNI bridge, Android mDNS backend, ALAC wrapper
│ └── third_party/ UxPlay lib/, libplist, ALAC, BoringSSL (submodule)
├── kotlin/com/fenpo/cast/
│ ├── receiver/ NativeReceiver (JNI), ReceiverController, NsdManager advertising,
│ │ display profile, low-latency Wi-Fi lock
│ ├── media/ MediaCodec video, AudioTrack audio, Media3 stream player, DMAP
│ ├── settings/ DataStore settings, device identity
│ └── ui/ Compose for TV screens (home, session, settings), theme
└── res/ English and Turkish strings, icons, banner
docs/ architecture, decisions, testing, Play listing
store/ generator for the Play Store graphics
Native layer (app/src/main/cpp)
CMakeLists.txtbuilds four static libraries (BoringSSLcrypto,plist,alac,airplay) and the sharedlibfenpocast.so.airplayis everything in UxPlay'slib/folder exceptdns_sdandmdnsd, plusreceiver/dnssd_android.c.receiver/receiver.cplays the role of UxPlay'suxplay.cpp. It connects the raop callbacks to private methods ofNativeReceiver, runs a small supervisor thread (15-second feedback watchdog, session reset, HTTP server restart) and passes the HLS playback state from Kotlin to/playback-info.receiver/dnssd_android.cis UxPlay'sdnssdbackend for Android. It builds the TXT records and hands the registration toServiceAdvertiser(NsdManager) through JNI.receiver/alac_decoder.cppwraps Apple's ALAC decoder with AirPlay's fixed format (352 frames, 16-bit, 2 channels, 44.1 kHz). ALAC reaches Kotlin as decoded PCM.
JNI method names and signatures must match exactly between cache_methods() in receiver.c and NativeReceiver.kt; the R8 rules are in app/proguard-rules.pro.
Kotlin layer
receiver/NativeReceiver.kt: the JNI boundary. Callbacks arrive on raop's own threads.receiver/ReceiverController.kt: a single object for the life of the process. It restarts the receiver when settings the iPhone can see change (name, code, quality, video), produces the session state (Session.Mirroring,Music,Stream), watches network changes and checks the local network permission on Android 17.media/VideoDecoder.kt: asynchronous MediaCodec; every output frame is shown as soon as it arrives (KEY_LOW_LATENCY). While there is no surface yet, it keeps the frames since the last key frame and replays them when the surface appears, so a still screen does not have to wait for the next key frame. When the parameter sets change (the iPhone was rotated), it recreates the decoder.media/AudioRenderer.kt: a single thread; the blockingAudioTrackwrite paces the stream. It takes audio focus.media/StreamPlayer.kt: Media3 ExoPlayer. The iPhone sends play, pause and seek commands; the state is reported back twice a second, which drives the slider on the iPhone.MainActivitystarts the receiver inonStartand stops it inonStop. If a session (music) is running at that moment, it stops when the session ends. There is no foreground service.
Theme and language
- The color roles match the Material 3 roles of Fenpo for Android, mapped to the TV Material scheme (
ui/theme/Color.kt). - Appearance (System, Light, Dark) is stored in DataStore. Language (system language, Turkish, English) uses AppCompat's per-app language API.
- Strings are in
res/values/strings.xml(English) andres/values-tr/strings.xml(Turkish).
Third-party components
The receiver core comes from these open-source projects. Their sources are under app/src/main/cpp/third_party/, each with its own license file. The app as a whole is distributed under GPL-3.0.
| Component | License | Used for |
|---|---|---|
UxPlay lib/ | GPLv3 (most files LGPL 2.1+, playfair/ GPLv3, llhttp/ MIT) | Receiver protocol: session, pairing, FairPlay handshake, mirroring stream decryption, HLS video handover |
| BoringSSL (git submodule) | Apache 2.0 / ISC / OpenSSL | The libcrypto API UxPlay uses. Linked statically |
| libplist | LGPL 2.1+ | Reading and writing binary and XML property lists |
Apple ALAC codec/ (decoder only) | Apache 2.0 | Decoding ALAC audio in music streams |
AndroidX, Compose for TV and Media3 on the Kotlin side are Apache 2.0 and come in through Gradle. The local changes made to these components are listed in THIRD_PARTY.md in the repository.