# barry-ran/qtscrcpycore architecture

> Architecture diagram of the GitHub repository barry-ran/qtscrcpycore, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/barry-ran/qtscrcpycore
- Repository: https://github.com/barry-ran/qtscrcpycore

## Overview

##### Project type and purpose
- This is a C++ “core” library for Android real-time display and control (used by QtScrcpy).
- It wraps ADB, launches a server on the device, captures H.264 video over TCP, decodes it via FFmpeg, and forwards user input back to the device.

##### File structure to extract major components
- Top-level files:
– CMakeLists.txt – build configuration
– include/*.h – public API surface (QtScrcpyCore.h, adbprocess)
- src/adb – manages ADB process and forwarding
- src/devicemanage – device enumeration and lifecycle
- src/device – core device interaction, subdivided into:
– server (starts scrcpy-server on the device, handles sockets)
– demuxer → decoder → frame conversion → fps counting
– controller (input conversion pipelines + message sending)
– filehandler (pull/push files)
– recorder (record local copy of the stream)
- src/common – shared events & types
- src/third_party – embedded ADB binaries, FFmpeg headers/libs, scrcpy-server JAR

##### README for technical stack
- External dependencies: Android platform via ADB, FFmpeg for media processing, scrcpy-server code on the device.
- Build target: a static or shared C++ library exposing a simple API to Qt UI or other clients.

a. Host-side modules (QtScrcpyCore library)
1. ADB Manager
2. Device Manager
3. Server Launcher
4. TCP Video Socket & Control Socket
5. Demuxer → Decoder → Frame Converter → FPS Counter
6. Input Controller (event queue, converter, sender)
7. File Handler
8. Recorder
b. Device-side component
– scrcpy-server (runs on Android, listens on sockets)
c. External services/dependencies
– ADB binary (platform tool)
– FFmpeg libs (libavformat, libavcodec, etc.)

##### Relationships and data flows
- ADB Manager → launches scrcpy-server on device, sets up port forwarding
- TCP sockets:
– Video data socket: scrcpy-server → host → Demuxer
– Control socket: host Input Controller → scrcpy-server
- Demuxer hands elementary streams to Decoder → produces raw frames → Frame Converter → hands bitmaps to UI/rendering (in Qt layer)
- File Handler uses ADB channels to pull/push files
- Recorder taps decoded frames stream and writes to disk
- Device Manager notifies library clients of connect/disconnect events

##### Architectural patterns
- Pipeline pattern in media processing (demuxer→decoder→converter)
- Adapter pattern in Input Controller (generic events → device-specific control messages)
- Facade in public API (QtScrcpyCore.h exposes simple interface over all submodules)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Host-side QtScrcpyCore"
        subgraph "Public API Facade"
            API1["QtScrcpyCore.h"]:::host
            API2["QtScrcpyCoreDef.h"]:::host
        end
        subgraph "ADB Manager"
            ADBP["ADB Process"]:::host
        end
        subgraph "Device Manager"
            DM["Device Manager"]:::host
        end
        subgraph "Server & TCP Sockets"
            SL["Server Launcher"]:::host
            VS["Video Socket"]:::host
            CS["Control Socket"]:::host
        end
        subgraph "Media Pipeline"
            DEM["Demuxer"]:::host
            DEC["Decoder"]:::host
            FC["Frame Converter"]:::host
            FPS["FPS Counter"]:::host
        end
        subgraph "Input Controller"
            IC["Input Controller"]:::host
        end
        FH["File Handler"]:::host
        REC["Recorder"]:::host
        CE["Common Events & Types"]:::host
    end

    DEV["scrcpy-server"]:::device
    ADBBIN["ADB Binaries"]:::third
    FFMPEG["FFmpeg Libs/Headers"]:::third

    API1 --> DM
    API1 --> ADBP
    DM --> SL
    ADBP --> SL
    SL --> DEV
    ADBBIN --> ADBP
    DEV --> VS
    VS --> DEM
    DEM --> DEC
    DEC --> FC
    FC --> FPS
    REC --> FC
    IC --> CS
    CS --> DEV
    FH --> ADBP
    CE --> API1

    click API1 "https://github.com/barry-ran/qtscrcpycore/blob/main/include/QtScrcpyCore.h"
    click API2 "https://github.com/barry-ran/qtscrcpycore/blob/main/include/QtScrcpyCoreDef.h"
    click ADBP "https://github.com/barry-ran/qtscrcpycore/blob/main/include/adbprocess.h"
    click ADBP "https://github.com/barry-ran/qtscrcpycore/blob/main/src/adb/adbprocess.cpp"
    click ADBP "https://github.com/barry-ran/qtscrcpycore/blob/main/src/adb/adbprocessimpl.cpp"
    click ADBP "https://github.com/barry-ran/qtscrcpycore/blob/main/src/adb/adbprocessimpl.h"
    click DM "https://github.com/barry-ran/qtscrcpycore/blob/main/src/devicemanage/devicemanage.cpp"
    click DM "https://github.com/barry-ran/qtscrcpycore/blob/main/src/devicemanage/devicemanage.h"
    click SL "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/server/server.cpp"
    click SL "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/server/server.h"
    click SL "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/server/tcpserver.cpp"
    click SL "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/server/tcpserver.h"
    click SL "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/server/videosocket.cpp"
    click SL "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/server/videosocket.h"
    click DEM "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/demuxer/demuxer.cpp"
    click DEM "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/demuxer/demuxer.h"
    click DEC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/decoder/decoder.cpp"
    click DEC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/decoder/decoder.h"
    click DEC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/decoder/videobuffer.cpp"
    click DEC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/decoder/videobuffer.h"
    click FC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/decoder/avframeconvert.cpp"
    click FC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/decoder/avframeconvert.h"
    click FPS "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/decoder/fpscounter.cpp"
    click FPS "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/decoder/fpscounter.h"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/controller.cpp"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/controller.h"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/bufferutil.cpp"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/bufferutil.h"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/inputconvert/controlmsg.cpp"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/inputconvert/controlmsg.h"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/inputconvert/inputconvertbase.cpp"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/inputconvert/inputconvertbase.h"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/inputconvert/inputconvertgame.cpp"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/inputconvert/inputconvertgame.h"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/inputconvert/inputconvertnormal.cpp"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/inputconvert/inputconvertnormal.h"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/inputconvert/keymap/keymap.cpp"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/inputconvert/keymap/keymap.h"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/receiver/receiver.cpp"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/receiver/receiver.h"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/receiver/devicemsg.cpp"
    click IC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/controller/receiver/devicemsg.h"
    click FH "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/filehandler/filehandler.cpp"
    click FH "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/filehandler/filehandler.h"
    click REC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/recorder/recorder.cpp"
    click REC "https://github.com/barry-ran/qtscrcpycore/blob/main/src/device/recorder/recorder.h"
    click CE "https://github.com/barry-ran/qtscrcpycore/blob/main/src/common/qscrcpyevent.h"
    click DEV "https://github.com/barry-ran/qtscrcpycore/tree/main/src/third_party/scrcpy-server"
    click ADBBIN "https://github.com/barry-ran/qtscrcpycore/tree/main/src/third_party/adb"
    click FFMPEG "https://github.com/barry-ran/qtscrcpycore/tree/main/src/third_party/ffmpeg/include"
    click FFMPEG "https://github.com/barry-ran/qtscrcpycore/tree/main/src/third_party/ffmpeg/lib"

    classDef host fill:#ADD8E6,stroke:#000,color:#000;
    classDef device fill:#90EE90,stroke:#000,color:#000;
    classDef third fill:#D3D3D3,stroke:#000,color:#000;
```
