# alexeyvasilyev/rtsp-client-android architecture

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

- Interactive diagram: https://gitdiagram.com/alexeyvasilyev/rtsp-client-android
- Repository: https://github.com/alexeyvasilyev/rtsp-client-android

## Overview

##### Project Type Analysis
This is a specialized Android library project focused on real-time RTSP video streaming with an emphasis on low latency. The project consists of two main components:
- A demo application (app/)
- The core RTSP client library (library-client-rtsp/)

##### Main Components

A. Core Components:
##### RTSP Client Core
- RtspClient (main entry point)
- Authentication Handler
- Network Layer (TCP/SSL)

##### Media Processing Pipeline
- RTP Parsers
- Video (H.264/H.265)
- Audio (AAC)
- Application Data
- Decoder Components
- Video Decoder Thread
- Audio Decoder Thread
- Frame Processing
- Frame Queue

##### UI Components
- RtspSurfaceView
- RtspImageView
- RTSP Processor

##### External Interfaces
- Android MediaCodec
- Network Socket
- Surface/Bitmap Output

Design Guidelines:

**┌─────────────────────────────────────┐**
- UI Components             │
- (RtspSurfaceView/RtspImageView)   │
- ┬───────────────────┘
- ↓
**┌─────────────────────────────────────┐**
- RTSP Processor              │
- ┬───────────────────┘
- ↓
**┌─────────────────────────────────────┐**
- RTSP Client Core           │
- ┬───────────────────┘
- ↓
**┌─────────────────────────────────────┐**
- Media Processing             │
- ┌─────────────┐  ┌─────────────┐  │
- RTP Parser │  │   Decoder   │  │
- ┘  └─────────────┘  │
- ┘

##### Connection Types
- Double lines: API boundaries

##### Important Elements to Highlight
- Low latency optimization paths
- Authentication flow
- Media codec integration
- Frame processing pipeline

##### Technical Details
- Supported protocols (RTSP/RTSPS)
- Codec support (H.264/H.265, AAC)
- Authentication methods (Basic/Digest)
- Performance optimization points

##### Notes for
- Minimum API level (24)
- Low-latency MediaCodec usage
- Hardware/Software decoder options
- SPS frame rewriting capability

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef processor fill:#2ecc71,stroke:#27ae60,color:white
    classDef core fill:#f1c40f,stroke:#f39c12,color:white
    classDef media fill:#9b59b6,stroke:#8e44ad,color:white
    classDef parser fill:#e74c3c,stroke:#c0392b,color:white
    classDef decoder fill:#1abc9c,stroke:#16a085,color:white
    classDef frame fill:#34495e,stroke:#2c3e50,color:white

    %% UI Layer
    subgraph UI
        SurfaceView["RtspSurfaceView"]:::ui
        ImageView["RtspImageView"]:::ui
    end
    click SurfaceView "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/widget/RtspSurfaceView.kt"
    click ImageView "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/widget/RtspImageView.kt"

    %% Processor Layer
    RtspProcessor["RTSP Processor"]:::processor
    click RtspProcessor "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/widget/RtspProcessor.kt"

    %% Core Layer
    RtspClient["RTSP Client"]:::core
    click RtspClient "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/RtspClient.java"

    %% Media Processing Layer
    subgraph MediaProcessing["Media Processing Pipeline"]
        %% RTP Parsers
        subgraph Parsers["RTP Parsers"]
            H264Parser["H.264 Parser"]:::parser
            H265Parser["H.265 Parser"]:::parser
            AACParser["AAC Parser"]:::parser
        end
        click H264Parser "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/parser/RtpH264Parser.kt"
        click H265Parser "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/parser/RtpH265Parser.kt"
        click AACParser "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/parser/AacParser.java"

        %% Decoders
        subgraph Decoders["Decoder Components"]
            VideoDecoder["Video Decoder Thread"]:::decoder
            AudioDecoder["Audio Decoder Thread"]:::decoder
            BitmapDecoder["Video Decoder Bitmap"]:::decoder
            SurfaceDecoder["Video Decoder Surface"]:::decoder
        end
        click VideoDecoder "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/codec/VideoDecodeThread.kt"
        click AudioDecoder "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/codec/AudioDecodeThread.kt"
        click BitmapDecoder "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/codec/VideoDecoderBitmapThread.kt"
        click SurfaceDecoder "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/codec/VideoDecoderSurfaceThread.kt"

        %% Frame Processing
        subgraph FrameProc["Frame Processing"]
            FrameQueue["Frame Queue"]:::frame
            ColorConv["Color Converter"]:::frame
            ColorConvImg["Color Converter Image"]:::frame
        end
        click FrameQueue "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/codec/FrameQueue.kt"
        click ColorConv "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/codec/color/ColorConverter.kt"
        click ColorConvImg "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/rtsp/codec/color/ColorConverterImage.kt"
    end

    %% External Interfaces
    MediaCodec["Android MediaCodec"]
    MediaCodecUtils["MediaCodec Utils"]
    VideoCodecUtils["Video Codec Utils"]
    NetUtils["Network Utils"]
    click MediaCodecUtils "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/utils/MediaCodecUtils.kt"
    click VideoCodecUtils "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/utils/VideoCodecUtils.kt"
    click NetUtils "https://github.com/alexeyvasilyev/rtsp-client-android/blob/master/library-client-rtsp/src/main/java/com/alexvas/utils/NetUtils.java"

    %% Connections
    SurfaceView --> RtspProcessor
    ImageView --> RtspProcessor
    RtspProcessor --> RtspClient
    RtspClient --> Parsers
    Parsers --> Decoders
    Decoders --> FrameProc
    FrameProc --> SurfaceView
    FrameProc --> ImageView
    Decoders --> MediaCodec
    RtspClient -.-> NetUtils
    Decoders -.-> MediaCodecUtils
    Decoders -.-> VideoCodecUtils

    %% Legend
    subgraph Legend
        UI_L["UI Components"]:::ui
        Proc_L["Processors"]:::processor
        Core_L["Core Components"]:::core
        Parser_L["Parsers"]:::parser
        Decoder_L["Decoders"]:::decoder
        Frame_L["Frame Processing"]:::frame
    end
```
