# yunlou-inc/airplay-tv-receiver architecture

> Architecture diagram of the GitHub repository yunlou-inc/airplay-tv-receiver, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yunlou-inc/airplay-tv-receiver
- Repository: https://github.com/yunlou-inc/airplay-tv-receiver

## Overview

Yunlou AirPlay TV is an Android AirPlay receiver: senders discover the receiver, establish mirroring/audio or HLS playback, and the app renders media and exposes playback controls. The service coordinates the native protocol bridge, discovery, renderers, and playback state; audio proceeds through native decode, timing/buffering, and output. README documents PIN, media-session controls, downloads, diagnostics, PiP, and TV navigation. Edges are limited to calls shown in excerpts or file references in the SOURCE INDEX; README capability links are documented, and unsampled service wiring is not inferred beyond those references.

Main entry points: [`app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt`](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt) (AirPlay service), [`app/src/main/kotlin/io/github/jqssun/airplay/ui/MainScreen.kt`](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/ui/MainScreen.kt) (Receiver UI), [`app/src/main/kotlin/io/github/jqssun/airplay/MainActivity.kt`](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/MainActivity.kt) (Activity and lifecycle), [`app/src/main/cpp/audio_engine.cpp`](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/cpp/audio_engine.cpp) (Audio engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App and controls"]
  node_activity["Activity and lifecycle<br/>[MainActivity.kt]"]
  node_preferences[("Settings preferences<br/>[Prefs.kt]")]
  node_viewmodel["UI state and logs<br/>[MainViewModel.kt]"]
  node_screens["Receiver UI<br/>[MainScreen.kt]"]
  node_settings["Settings and logs<br/>[SettingsScreen.kt]"]
end

subgraph group_protocol["Receiver and discovery"]
  node_service["AirPlay service<br/>[AirPlayService.kt]"]
  node_nativebridge["JNI bridge<br/>[NativeBridge.kt]"]
  node_callbacks["RAOP callbacks"]
  node_mdns["Service advertising"]
  node_usbmdns["USB mDNS advertising"]
  node_dacp["DACP remote control<br/>[DacpController.kt]"]
  node_track["Track metadata<br/>[TrackInfo.kt]"]
  node_dacpplayer["Media session controls<br/>[DacpPlayer.kt]"]
end

subgraph group_media["Media pipelines"]
  node_video["Video renderer<br/>[VideoRenderer.kt]"]
  node_decoder["Decoder selection<br/>[DecoderSelector.kt]"]
  node_pipeline["Video surface pipeline<br/>[VideoPipeline.kt]"]
  node_egl["EGL context<br/>[EglCore.kt]"]
  node_airplayplayer["HLS playback"]
  node_downloader["Video download<br/>[VideoDownloader.kt]"]
  node_audiorenderer["Audio renderer<br/>[AudioRenderer.kt]"]
end

subgraph group_native["Native audio engine"]
  node_audioengine["Audio engine<br/>[audio_engine.cpp]"]
  node_audiodecoder["Codec decoding<br/>[audio_decoder.h]"]
  node_timeline["Timing buffer<br/>[timeline_buffer.h]"]
  node_audiooutput["PCM output<br/>[audio_output.h]"]
end

node_sender(("iOS/macOS sender"))

node_sender -.->|"sends AirPlay"| node_service
node_activity -->|"binds service"| node_service
node_activity -->|"updates state"| node_viewmodel
node_activity -->|"shows UI"| node_screens
node_screens -->|"reads state"| node_viewmodel
node_screens -->|"opens settings"| node_settings
node_screens -->|"reads settings"| node_preferences
node_settings -->|"reads settings"| node_preferences
node_settings -->|"updates state"| node_viewmodel
node_service -->|"starts engine"| node_nativebridge
node_service -.->|"registers services"| node_mdns
node_service -.->|"advertises services"| node_usbmdns
node_nativebridge -->|"dispatches events"| node_callbacks
node_service -->|"configures renderer"| node_video
node_video -->|"selects decoder"| node_decoder
node_video -->|"renders frames"| node_pipeline
node_pipeline -->|"uses EGL"| node_egl
node_service -->|"controls playback"| node_airplayplayer
node_service -->|"starts download"| node_downloader
node_service -->|"configures audio"| node_audiorenderer
node_audiorenderer -->|"sends audio"| node_nativebridge
node_audioengine -->|"decodes packets"| node_audiodecoder
node_audioengine -->|"buffers timing"| node_timeline
node_audioengine -->|"outputs PCM"| node_audiooutput
node_service -->|"sends remote commands"| node_dacp
node_service -->|"updates session"| node_dacpplayer
node_dacpplayer -->|"uses controller"| node_dacp
node_dacpplayer -->|"reads track"| node_track

click node_activity "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/MainActivity.kt"
click node_preferences "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/Prefs.kt"
click node_viewmodel "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/viewmodel/MainViewModel.kt"
click node_screens "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/ui/MainScreen.kt"
click node_settings "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/ui/SettingsScreen.kt"
click node_service "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt"
click node_nativebridge "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/bridge/NativeBridge.kt"
click node_callbacks "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/bridge/RaopCallbackHandler.kt"
click node_mdns "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/discovery/NsdServiceManager.kt"
click node_usbmdns "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/discovery/UsbMdnsAdvertiser.kt"
click node_video "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/renderer/VideoRenderer.kt"
click node_decoder "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/renderer/DecoderSelector.kt"
click node_pipeline "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/renderer/VideoPipeline.kt"
click node_egl "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/renderer/EglCore.kt"
click node_airplayplayer "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/renderer/AirPlayVideoPlayer.kt"
click node_downloader "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/download/VideoDownloader.kt"
click node_audiorenderer "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/renderer/AudioRenderer.kt"
click node_audioengine "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/cpp/audio_engine.cpp"
click node_audiodecoder "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/cpp/audio_decoder.h"
click node_timeline "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/cpp/timeline_buffer.h"
click node_audiooutput "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/cpp/audio_output.h"
click node_dacp "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/audio/DacpController.kt"
click node_track "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/audio/TrackInfo.kt"
click node_dacpplayer "https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/audio/DacpPlayer.kt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_activity,node_preferences,node_viewmodel,node_screens,node_settings toneBlue
class node_service,node_nativebridge,node_callbacks,node_mdns,node_usbmdns,node_dacp,node_track,node_dacpplayer toneAmber
class node_video,node_decoder,node_pipeline,node_egl,node_airplayplayer,node_downloader,node_audiorenderer toneMint
class node_audioengine,node_audiodecoder,node_timeline,node_audiooutput toneRose
class node_sender toneIndigo
```

## Components

### App and controls

- [Activity and lifecycle](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/MainActivity.kt): `app/src/main/kotlin/io/github/jqssun/airplay/MainActivity.kt`
- [Settings preferences](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/Prefs.kt): `app/src/main/kotlin/io/github/jqssun/airplay/Prefs.kt`
- [UI state and logs](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/viewmodel/MainViewModel.kt): `app/src/main/kotlin/io/github/jqssun/airplay/viewmodel/MainViewModel.kt`
- [Receiver UI](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/ui/MainScreen.kt): `app/src/main/kotlin/io/github/jqssun/airplay/ui/MainScreen.kt`
- [Settings and logs](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/ui/SettingsScreen.kt): `app/src/main/kotlin/io/github/jqssun/airplay/ui/SettingsScreen.kt`

### Receiver and discovery

- [AirPlay service](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt): `app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt`
- [JNI bridge](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/bridge/NativeBridge.kt): `app/src/main/kotlin/io/github/jqssun/airplay/bridge/NativeBridge.kt`
- [RAOP callbacks](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/bridge/RaopCallbackHandler.kt): `app/src/main/kotlin/io/github/jqssun/airplay/bridge/RaopCallbackHandler.kt`
- [Service advertising](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/discovery/NsdServiceManager.kt): `app/src/main/kotlin/io/github/jqssun/airplay/discovery/NsdServiceManager.kt`
- [USB mDNS advertising](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/discovery/UsbMdnsAdvertiser.kt): `app/src/main/kotlin/io/github/jqssun/airplay/discovery/UsbMdnsAdvertiser.kt`
- [DACP remote control](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/audio/DacpController.kt): `app/src/main/kotlin/io/github/jqssun/airplay/audio/DacpController.kt`
- [Track metadata](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/audio/TrackInfo.kt): `app/src/main/kotlin/io/github/jqssun/airplay/audio/TrackInfo.kt`
- [Media session controls](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/audio/DacpPlayer.kt): `app/src/main/kotlin/io/github/jqssun/airplay/audio/DacpPlayer.kt`

### Media pipelines

- [Video renderer](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/renderer/VideoRenderer.kt): `app/src/main/kotlin/io/github/jqssun/airplay/renderer/VideoRenderer.kt`
- [Decoder selection](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/renderer/DecoderSelector.kt): `app/src/main/kotlin/io/github/jqssun/airplay/renderer/DecoderSelector.kt`
- [Video surface pipeline](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/renderer/VideoPipeline.kt): `app/src/main/kotlin/io/github/jqssun/airplay/renderer/VideoPipeline.kt`
- [EGL context](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/renderer/EglCore.kt): `app/src/main/kotlin/io/github/jqssun/airplay/renderer/EglCore.kt`
- [HLS playback](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/renderer/AirPlayVideoPlayer.kt): `app/src/main/kotlin/io/github/jqssun/airplay/renderer/AirPlayVideoPlayer.kt`
- [Video download](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/download/VideoDownloader.kt): `app/src/main/kotlin/io/github/jqssun/airplay/download/VideoDownloader.kt`
- [Audio renderer](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/kotlin/io/github/jqssun/airplay/renderer/AudioRenderer.kt): `app/src/main/kotlin/io/github/jqssun/airplay/renderer/AudioRenderer.kt`

### Native audio engine

- [Audio engine](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/cpp/audio_engine.cpp): `app/src/main/cpp/audio_engine.cpp`
- [Codec decoding](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/cpp/audio_decoder.h): `app/src/main/cpp/audio_decoder.h`
- [Timing buffer](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/cpp/timeline_buffer.h): `app/src/main/cpp/timeline_buffer.h`
- [PCM output](https://github.com/yunlou-inc/airplay-tv-receiver/blob/master/app/src/main/cpp/audio_output.h): `app/src/main/cpp/audio_output.h`

### Other components

- **iOS/macOS sender**

## Connections

- iOS/macOS sender → AirPlay service: sends AirPlay
- Activity and lifecycle → AirPlay service: binds service (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/MainActivity.kt`)
- Activity and lifecycle → UI state and logs: updates state (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/MainActivity.kt`)
- Activity and lifecycle → Receiver UI: shows UI (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/MainActivity.kt`)
- Receiver UI → UI state and logs: reads state (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/ui/MainScreen.kt`)
- Receiver UI → Settings and logs: opens settings (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/ui/MainScreen.kt`)
- Receiver UI → Settings preferences: reads settings (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/ui/MainScreen.kt`)
- Settings and logs → Settings preferences: reads settings (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/ui/SettingsScreen.kt`)
- Settings and logs → UI state and logs: updates state (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/ui/SettingsScreen.kt`)
- AirPlay service → JNI bridge: starts engine (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt`)
- AirPlay service → Service advertising: registers services (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt`)
- AirPlay service → USB mDNS advertising: advertises services (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt`)
- JNI bridge → RAOP callbacks: dispatches events (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/bridge/NativeBridge.kt`)
- AirPlay service → Video renderer: configures renderer (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt`)
- Video renderer → Decoder selection: selects decoder (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/renderer/VideoRenderer.kt`)
- Video renderer → Video surface pipeline: renders frames (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/renderer/VideoRenderer.kt`)
- Video surface pipeline → EGL context: uses EGL (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/renderer/VideoPipeline.kt`)
- AirPlay service → HLS playback: controls playback (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt`)
- AirPlay service → Video download: starts download (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt`)
- AirPlay service → Audio renderer: configures audio (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt`)
- Audio renderer → JNI bridge: sends audio (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/renderer/AudioRenderer.kt`)
- Audio engine → Codec decoding: decodes packets (evidence: `app/src/main/cpp/audio_engine.cpp`)
- Audio engine → Timing buffer: buffers timing (evidence: `app/src/main/cpp/audio_engine.cpp`)
- Audio engine → PCM output: outputs PCM (evidence: `app/src/main/cpp/audio_engine.cpp`)
- AirPlay service → DACP remote control: sends remote commands (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt`)
- AirPlay service → Media session controls: updates session (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/service/AirPlayService.kt`)
- Media session controls → DACP remote control: uses controller (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/audio/DacpPlayer.kt`)
- Media session controls → Track metadata: reads track (evidence: `app/src/main/kotlin/io/github/jqssun/airplay/audio/DacpPlayer.kt`)
