Files
DisplayFlow/demo/windows_sender/README.md

82 lines
2.6 KiB
Markdown
Raw Normal View History

2025-12-18 23:07:14 +08:00
# Windows Sender Demo
This is a simplified demo of the Windows Host sender for DisplayFlow.
2025-12-18 23:07:14 +08:00
It demonstrates:
1. Screen Capture using Desktop Duplication API (DXGI).
2. Hardware/Software H.264 Encoding using **FFmpeg** (switched from Media Foundation for better compatibility).
2025-12-18 23:07:14 +08:00
3. Network Transmission using UDP.
## Prerequisites
- Windows 10/11
- Visual Studio 2022 or later (with C++ Desktop Development)
2025-12-18 23:07:14 +08:00
- CMake 3.10+
- **FFmpeg Development Libraries** (Shared)
- Ensure you have the `include` and `lib` directories.
- Example path: `D:\tools\ffmpeg-8.0.1-full_build-shared`
2025-12-18 23:07:14 +08:00
## Build
1. Open a terminal (Developer Command Prompt for VS or PowerShell).
2025-12-18 23:07:14 +08:00
2. Navigate to this directory:
```cmd
cd demo\windows_sender
```
3. Create a build directory:
```cmd
mkdir build
cd build
```
4. Configure and Build (Replace path with your FFmpeg location):
2025-12-18 23:07:14 +08:00
```cmd
cmake .. -DFFMPEG_ROOT="D:/tools/ffmpeg-8.0.1-full_build-shared"
2025-12-18 23:07:14 +08:00
cmake --build . --config Release
```
*Note: If your FFmpeg is installed elsewhere, change the path accordingly.*
5. **Important**: Copy FFmpeg DLLs to the executable directory.
- Copy `avcodec-*.dll`, `avutil-*.dll`, `swscale-*.dll`, `avformat-*.dll` from your FFmpeg `bin` directory to `demo\windows_sender\build\Release`.
2025-12-18 23:07:14 +08:00
## Run
Run the executable with optional arguments: Target IP, Port, and Output File.
2025-12-18 23:07:14 +08:00
```cmd
.\Release\WindowsSenderDemo.exe [TargetIP] [Port] [OutputFile]
2025-12-18 23:07:14 +08:00
```
### Examples
1. **Basic Streaming** (Default: 127.0.0.1:8888):
```cmd
.\Release\WindowsSenderDemo.exe
```
2. **Specify Target**:
```cmd
.\Release\WindowsSenderDemo.exe 192.168.1.100 8888
```
3. **Stream and Save to File** (for debugging):
```cmd
.\Release\WindowsSenderDemo.exe 127.0.0.1 8888 debug.h264
```
You can play the saved `debug.h264` using VLC player to verify the encoding quality.
2025-12-18 23:07:14 +08:00
## Implementation Details
- **ScreenCapture**: Uses `IDXGIOutputDuplication` to capture desktop frames.
- **VideoEncoder**:
- Uses **FFmpeg (libx264)** for encoding.
- Performs **BGRA to YUV420P** color conversion using `libswscale`.
- Configured for low latency (`zerolatency` tune, `ultrafast` preset).
2025-12-18 23:07:14 +08:00
- **NetworkSender**: Fragments the H.264 stream into UDP packets (MTU ~1400 bytes) and sends them to the target.
## Protocol
The demo uses a simple custom protocol for feasibility verification:
- **Packet Header** (Network Layer): `FrameID` (4B), `FragID` (2B), `TotalFrags` (2B).
- **Frame Header** (Application Layer, in first fragment/reassembled): `Timestamp` (8B), `Width` (4B), `Height` (4B), `Type` (4B), `Size` (4B).
- **Payload**: H.264 NAL units.