# giselle-nana/distributed_camera architecture

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

- Interactive diagram: https://gitdiagram.com/giselle-nana/distributed_camera
- Repository: https://github.com/giselle-nana/distributed_camera

## Overview

##### Project Type and Purpose
- This is a C++ component of the OpenHarmony distributed-hardware subsystem that provides “distributed camera” capabilities.
- It does not include a user-facing UI; instead it offers C++ interfaces to the distributed hardware framework, enabling one device (source) to control and use another device’s (sink) camera as if it were local.

##### High-Level Architectural Components
a. DistributedCameraSDK (Interfaces)
- The C++ API layer exposed to the distributed hardware management framework.
- Enables/disable virtual cameras and reports camera status.
b. DistributedCameraSourceMgr (Source Manager)
- State-machine–based lifecycle manager on the source side.
- Negotiates parameters, creates/destroys source-side objects, initiates camera commands.
c. DistributedCameraSinkMgr (Sink Manager)
- State-machine–based lifecycle manager on the sink side.
- Negotiates parameters, creates/destroys sink-side objects, receives commands, obtains local camera data.
d. Channel Module (SoftBus)
- Bi-directional IPC/transport layer between source and sink.
- Carries control commands (source→sink) and image/stream data (sink→source).
e. DataProcess Module
f. CameraClient & VirtualCameraHdf
- Sink side: CameraClient calls local multimedia APIs to open/close camera and obtain raw frames.
- VirtualCameraHdf implements a virtual HDF camera driver so that the media framework discovers and uses the distributed camera as if it were local.
g. Common & Interfaces (Inner Kits)
- Utility code (data buffers, tracing, errors) in `common/`.
- IPC stubs, proxies, load callbacks in `interfaces/inner_kits/native_cpp/{camera_source, camera_sink}`.
h. SA Profile
- Configuration files and build scripts under `sa_profile/`.

##### Relationships and Data Flows
- The distributed-hardware framework calls DistributedCameraSDK APIs → SourceMgr.
- SourceMgr sends control commands over Channel → SinkMgr.
- SinkMgr invokes CameraClient → local camera driver → raw frames → DataProcess → Channel → SourceMgr.
- SourceMgr or VirtualCameraHdf publishes frames into the local multimedia framework → application.

##### Architectural Patterns and Principles
- State-machine for lifecycle management (source and sink managers)
- Layered separation: SDK interface → managers → channel/process → hardware driver
- IPC decoupling via SoftBus Channel module
- Plugin-style virtual driver in HDF

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Framework
    DHF["DistributedHardware Framework"]:::external
    %% API Layer
    SDK["DistributedCameraSDK (C++ API Layer)"]:::api
    %% Managers
    subgraph "Source Side"
        SCM["DistributedCameraSourceMgr\n(state machine)"]:::core
        VCH["VirtualCameraHdf (HDF Plugin)"]:::driver
    end
    subgraph "Sink Side"
        SKM["DistributedCameraSinkMgr\n(state machine)"]:::core
        CC["CameraClient"]:::driver
        DP["DataProcess Module"]:::process
    end
    %% Transport
    SB["SoftBus Channel\n(IPC Transport)"]:::transport
    %% Media & App
    MF["Media Framework"]:::media
    APP["Application"]:::media
    %% Utilities and Interfaces
    CU["Common Utilities"]:::util
    IK["Inner Kits Interfaces"]:::api
    %% Configuration
    SA["SA Profile (Config & Build)"]:::config

    %% Connections
    DHF -->|"calls APIs"| SDK
    SDK -->|"Enable/Configure/CaptureCommand"| SCM
    SCM -->|"control"| SB
    SB -->|"control"| SKM
    SKM -->|"invoke"| CC
    CC -->|"raw frames"| DP
    DP -->|"processed frames"| SB
    SB -->|"stream data"| SCM
    SCM -->|"publish frames"| VCH
    VCH -->|"virtual camera"| MF
    MF -->|"feeds"| APP
    CU --> SCM
    CU --> SKM
    IK --> SCM
    IK --> SKM

    %% Click Events
    click SDK "https://github.com/giselle-nana/distributed_camera/tree/main/interfaces/inner_kits/native_cpp"
    click SCM "https://github.com/giselle-nana/distributed_camera/tree/main/services/cameraservice/sourceservice"
    click SKM "https://github.com/giselle-nana/distributed_camera/tree/main/services/cameraservice/sinkservice"
    click SB "https://github.com/giselle-nana/distributed_camera/blob/main/interfaces/inner_kits/native_cpp/camera_source/src/dcamera_source_handler_ipc.cpp"
    click SB "https://github.com/giselle-nana/distributed_camera/blob/main/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler_ipc.cpp"
    click DP "https://github.com/giselle-nana/distributed_camera/blob/main/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp"
    click VCH "https://github.com/giselle-nana/distributed_camera/blob/main/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerahdf/dcamera_hdf_operate.cpp"
    click CC "https://github.com/giselle-nana/distributed_camera/tree/main/services/cameraservice/cameraoperator/client"
    click CU "https://github.com/giselle-nana/distributed_camera/tree/main/common/src/utils"
    click IK "https://github.com/giselle-nana/distributed_camera/tree/main/interfaces/inner_kits/native_cpp/camera_source"
    click IK "https://github.com/giselle-nana/distributed_camera/tree/main/interfaces/inner_kits/native_cpp/camera_sink"
    click SA "https://github.com/giselle-nana/distributed_camera/tree/main/sa_profile"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef api fill:#8f8,stroke:#333,stroke-width:1px
    classDef core fill:#88f,stroke:#333,stroke-width:1px
    classDef transport fill:#f96,stroke:#333,stroke-width:1px
    classDef process fill:#fa3,stroke:#333,stroke-width:1px
    classDef driver fill:#f90,stroke:#333,stroke-width:1px
    classDef media fill:#6cf,stroke:#333,stroke-width:1px
    classDef util fill:#c9f,stroke:#333,stroke-width:1px
    classDef config fill:#cfc,stroke:#333,stroke-width:1px
```
