# nikit6000/qdplay architecture

> Architecture diagram of the GitHub repository nikit6000/qdplay, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nikit6000/qdplay
- Repository: https://github.com/nikit6000/qdplay

## Overview

QDPlay bridges a phone-side video/control interface to a QDLink car head unit over USB accessory protocol. The main runtime starts the video receiver and messaging service, creates the USB gadget, then waits for a video connection and a USB accessory start request before activating the accessory session. The active session handles head-unit protocol traffic, with v1 and v2 processors and message codecs. README documents the sender and event-receiver client interfaces. Several internal dispatch details are not excerpted, so those links are omitted or marked unverified.

Main entry points: [`src/main.c`](https://github.com/nikit6000/qdplay/blob/develop/src/main.c) (Runtime entry), [`src/usb_accessory/message_processor/v1/message_processor_v1.c`](https://github.com/nikit6000/qdplay/blob/develop/src/usb_accessory/message_processor/v1/message_processor_v1.c) (Protocol v1 processor), [`src/usb_accessory/usb_active_accessory.c`](https://github.com/nikit6000/qdplay/blob/develop/src/usb_accessory/usb_active_accessory.c) (Active accessory), [`src/services/video_receiver/video_receiver.c`](https://github.com/nikit6000/qdplay/blob/develop/src/services/video_receiver/video_receiver.c) (Video receiver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime orchestration"]
  node_main["Runtime entry<br/>[main.c]"]
  node_usb_worker["USB session worker"]
  node_usb_accessory["USB gadget<br/>[usb_accessory.c]"]
  node_active_accessory["Active accessory"]
end

subgraph group_protocol["Head-unit protocols"]
  node_processor_v1["Protocol v1 processor"]
  node_processor_v2["Protocol v2 processor"]
  node_messages_v1["V1 message codecs<br/>[screen_header.c]"]
  node_messages_v2["V2 message codecs"]
end

subgraph group_interfaces["Local interfaces"]
  node_video_receiver["Video receiver<br/>[video_receiver.c]"]
  node_messaging_service["Messaging service"]
  node_video_sender["Video sender client<br/>[qd_video_sender.c]"]
  node_control_receiver["Control receiver client"]
end

subgraph group_support["Message support"]
  node_hu_message["HU message codec<br/>[hu_message.c]"]
  node_json["JSON parser<br/>[cJSON.c]"]
end

node_phone(("Phone / QDLink"))
node_head_unit(("Car head unit"))

node_main -->|"starts"| node_video_receiver
node_main -->|"initializes"| node_messaging_service
node_main -->|"creates gadget"| node_usb_accessory
node_main -->|"starts worker"| node_usb_worker
node_usb_worker -->|"awaits connection"| node_video_receiver
node_usb_worker -->|"starts session"| node_active_accessory
node_video_sender -.->|"sends frames"| node_video_receiver
node_control_receiver -.->|"uses events"| node_messaging_service
node_phone -.->|"connects USB"| node_usb_accessory
node_active_accessory -.->|"dispatches protocol"| node_processor_v1
node_active_accessory -.->|"dispatches protocol"| node_processor_v2
node_processor_v1 -->|"writes responses"| node_head_unit
node_processor_v1 -->|"uses codecs"| node_messages_v1
node_processor_v1 -->|"encodes messages"| node_hu_message
node_processor_v2 -->|"uses codecs"| node_messages_v2
node_processor_v2 -->|"parses JSON"| node_json
node_video_receiver -.->|"coordinates session"| node_active_accessory

click node_main "https://github.com/nikit6000/qdplay/blob/develop/src/main.c"
click node_video_receiver "https://github.com/nikit6000/qdplay/blob/develop/src/services/video_receiver/video_receiver.c"
click node_messaging_service "https://github.com/nikit6000/qdplay/blob/develop/src/services/messaging_service/messaging_service.c"
click node_usb_worker "https://github.com/nikit6000/qdplay/blob/develop/src/usb_accessory/usb_accessory_worker.c"
click node_usb_accessory "https://github.com/nikit6000/qdplay/blob/develop/src/usb_accessory/usb_accessory.c"
click node_active_accessory "https://github.com/nikit6000/qdplay/blob/develop/src/usb_accessory/usb_active_accessory.c"
click node_processor_v1 "https://github.com/nikit6000/qdplay/blob/develop/src/usb_accessory/message_processor/v1/message_processor_v1.c"
click node_processor_v2 "https://github.com/nikit6000/qdplay/blob/develop/src/usb_accessory/message_processor/v2/message_processor_v2.c"
click node_messages_v1 "https://github.com/nikit6000/qdplay/blob/develop/src/messages/v1/screen_header.c"
click node_messages_v2 "https://github.com/nikit6000/qdplay/blob/develop/src/messages/v2/message_phone_info_v2.c"
click node_hu_message "https://github.com/nikit6000/qdplay/blob/develop/src/hu_message.c"
click node_json "https://github.com/nikit6000/qdplay/blob/develop/src/utils/cJSON.c"
click node_video_sender "https://github.com/nikit6000/qdplay/blob/develop/video-sender/qd_video_sender.c"
click node_control_receiver "https://github.com/nikit6000/qdplay/blob/develop/control-receiver/qd_control_receiver.c"

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_main,node_usb_worker,node_usb_accessory,node_active_accessory toneBlue
class node_processor_v1,node_processor_v2,node_messages_v1,node_messages_v2 toneAmber
class node_video_receiver,node_messaging_service,node_video_sender,node_control_receiver toneMint
class node_hu_message,node_json toneRose
class node_phone,node_head_unit toneIndigo
```

## Components

### Runtime orchestration

- [Runtime entry](https://github.com/nikit6000/qdplay/blob/develop/src/main.c): `src/main.c`
- [USB session worker](https://github.com/nikit6000/qdplay/blob/develop/src/usb_accessory/usb_accessory_worker.c): `src/usb_accessory/usb_accessory_worker.c`
- [USB gadget](https://github.com/nikit6000/qdplay/blob/develop/src/usb_accessory/usb_accessory.c): `src/usb_accessory/usb_accessory.c`
- [Active accessory](https://github.com/nikit6000/qdplay/blob/develop/src/usb_accessory/usb_active_accessory.c): `src/usb_accessory/usb_active_accessory.c`

### Head-unit protocols

- [Protocol v1 processor](https://github.com/nikit6000/qdplay/blob/develop/src/usb_accessory/message_processor/v1/message_processor_v1.c): `src/usb_accessory/message_processor/v1/message_processor_v1.c`
- [Protocol v2 processor](https://github.com/nikit6000/qdplay/blob/develop/src/usb_accessory/message_processor/v2/message_processor_v2.c): `src/usb_accessory/message_processor/v2/message_processor_v2.c`
- [V1 message codecs](https://github.com/nikit6000/qdplay/blob/develop/src/messages/v1/screen_header.c): `src/messages/v1/screen_header.c`
- [V2 message codecs](https://github.com/nikit6000/qdplay/blob/develop/src/messages/v2/message_phone_info_v2.c): `src/messages/v2/message_phone_info_v2.c`

### Local interfaces

- [Video receiver](https://github.com/nikit6000/qdplay/blob/develop/src/services/video_receiver/video_receiver.c): `src/services/video_receiver/video_receiver.c`
- [Messaging service](https://github.com/nikit6000/qdplay/blob/develop/src/services/messaging_service/messaging_service.c): `src/services/messaging_service/messaging_service.c`
- [Video sender client](https://github.com/nikit6000/qdplay/blob/develop/video-sender/qd_video_sender.c): `video-sender/qd_video_sender.c`
- [Control receiver client](https://github.com/nikit6000/qdplay/blob/develop/control-receiver/qd_control_receiver.c): `control-receiver/qd_control_receiver.c`

### Message support

- [HU message codec](https://github.com/nikit6000/qdplay/blob/develop/src/hu_message.c): `src/hu_message.c`
- [JSON parser](https://github.com/nikit6000/qdplay/blob/develop/src/utils/cJSON.c): `src/utils/cJSON.c`

### Other components

- **Phone / QDLink**
- **Car head unit**

## Connections

- Runtime entry → Video receiver: starts (evidence: `src/main.c`)
- Runtime entry → Messaging service: initializes (evidence: `src/main.c`)
- Runtime entry → USB gadget: creates gadget (evidence: `src/main.c`)
- Runtime entry → USB session worker: starts worker (evidence: `src/main.c`)
- USB session worker → Video receiver: awaits connection (evidence: `src/usb_accessory/usb_accessory_worker.c`)
- USB session worker → Active accessory: starts session (evidence: `src/usb_accessory/usb_accessory_worker.c`)
- Video sender client → Video receiver: sends frames
- Control receiver client → Messaging service: uses events
- Phone / QDLink → USB gadget: connects USB
- Active accessory → Protocol v1 processor: dispatches protocol
- Active accessory → Protocol v2 processor: dispatches protocol
- Protocol v1 processor → Car head unit: writes responses (evidence: `src/usb_accessory/message_processor/v1/message_processor_v1.c`)
- Protocol v1 processor → V1 message codecs: uses codecs (evidence: `src/usb_accessory/message_processor/v1/message_processor_v1.c`)
- Protocol v1 processor → HU message codec: encodes messages (evidence: `src/usb_accessory/message_processor/v1/message_processor_v1.c`)
- Protocol v2 processor → V2 message codecs: uses codecs (evidence: `src/usb_accessory/message_processor/v2/message_processor_v2.c`)
- Protocol v2 processor → JSON parser: parses JSON (evidence: `src/usb_accessory/message_processor/v2/message_processor_v2.c`)
- Video receiver → Active accessory: coordinates session
