Windows Sender Demo
This is a simplified demo of the Windows Host sender for DisplayFlow.
It demonstrates:
- Screen Capture using Desktop Duplication API (DXGI).
- Hardware/Software H.264 Encoding using FFmpeg (switched from Media Foundation for better compatibility).
- Network Transmission using UDP.
Prerequisites
- Windows 10/11
- Visual Studio 2022 or later (with C++ Desktop Development)
- CMake 3.10+
- FFmpeg Development Libraries (Shared)
- Ensure you have the
includeandlibdirectories. - Example path:
D:\tools\ffmpeg-8.0.1-full_build-shared
- Ensure you have the
Build
-
Open a terminal (Developer Command Prompt for VS or PowerShell).
-
Navigate to this directory:
cd demo\windows_sender -
Create a build directory:
mkdir build cd build -
Configure and Build (Replace path with your FFmpeg location):
cmake .. -DFFMPEG_ROOT="D:/tools/ffmpeg-8.0.1-full_build-shared" cmake --build . --config ReleaseNote: If your FFmpeg is installed elsewhere, change the path accordingly.
-
Important: Copy FFmpeg DLLs to the executable directory.
- Copy
avcodec-*.dll,avutil-*.dll,swscale-*.dll,avformat-*.dllfrom your FFmpegbindirectory todemo\windows_sender\build\Release.
- Copy
Run
Run the executable with optional arguments: Target IP, Port, and Output File.
.\Release\WindowsSenderDemo.exe [TargetIP] [Port] [OutputFile]
Examples
-
Basic Streaming (Default: 127.0.0.1:8888):
.\Release\WindowsSenderDemo.exe -
Specify Target:
.\Release\WindowsSenderDemo.exe 192.168.1.100 8888 -
Stream and Save to File (for debugging):
.\Release\WindowsSenderDemo.exe 127.0.0.1 8888 debug.h264You can play the saved
debug.h264using VLC player to verify the encoding quality.
Implementation Details
- ScreenCapture: Uses
IDXGIOutputDuplicationto capture desktop frames. - VideoEncoder:
- Uses FFmpeg (libx264) for encoding.
- Performs BGRA to YUV420P color conversion using
libswscale. - Configured for low latency (
zerolatencytune,ultrafastpreset).
- 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.