Skip to content

Commit 517eec8

Browse files
Merge pull request #5 from YimingZhanshen/copilot/fix-screen-mirroring-sound
Fix screen mirroring audio: native FDK-AAC decoder, buffer overflow fix, CI packaging
2 parents 9f5a45a + b8ad2ed commit 517eec8

14 files changed

Lines changed: 1211 additions & 478 deletions

File tree

.github/workflows/build.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,47 @@ jobs:
3131
- name: Publish
3232
run: dotnet publish AirPlay/AirPlay.csproj --configuration Release --runtime win-x64 --self-contained true --output ./publish/win-x64
3333

34+
- name: Download FFmpeg
35+
shell: pwsh
36+
run: |
37+
$ffmpegUrl = "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
38+
Invoke-WebRequest -Uri $ffmpegUrl -OutFile ffmpeg.zip
39+
Expand-Archive -Path ffmpeg.zip -DestinationPath ffmpeg-tmp
40+
# Copy ffmpeg.exe and ffplay.exe to publish directory
41+
$binDir = Get-ChildItem -Path ffmpeg-tmp -Recurse -Directory -Filter "bin" | Select-Object -First 1
42+
Copy-Item "$($binDir.FullName)\ffmpeg.exe" -Destination ./publish/win-x64/
43+
Copy-Item "$($binDir.FullName)\ffplay.exe" -Destination ./publish/win-x64/
44+
45+
- name: Build libfdk-aac from source
46+
shell: bash
47+
run: |
48+
# Build FDK-AAC from official source using MSYS2 (pre-installed on windows-latest)
49+
export MSYSTEM=MINGW64
50+
export PATH="/c/msys64/mingw64/bin:/c/msys64/usr/bin:$PATH"
51+
52+
# Install build dependencies
53+
pacman -S --noconfirm --needed mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake make
54+
55+
# Clone and build fdk-aac
56+
git clone --depth 1 https://github.com/mstorsjo/fdk-aac.git fdk-aac-src
57+
cd fdk-aac-src
58+
59+
# Use CMake for a simpler build
60+
mkdir build && cd build
61+
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON ..
62+
cmake --build . --config Release
63+
64+
# Find and copy the DLL
65+
echo "Built files:"
66+
find . -name "*.dll" -type f
67+
DLL_PATH=$(find . -name "fdk-aac*.dll" -o -name "libfdk-aac*.dll" | head -1)
68+
if [ -z "$DLL_PATH" ]; then
69+
echo "ERROR: No FDK-AAC DLL found after build"
70+
exit 1
71+
fi
72+
cp -v "$DLL_PATH" ../../publish/win-x64/libfdk-aac-2.dll
73+
echo "Successfully built and copied libfdk-aac-2.dll"
74+
3475
- name: Upload build artifacts
3576
uses: actions/upload-artifact@v4
3677
with:

AirPlay/AirPlayService.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,21 @@ public async Task StartAsync(CancellationToken cancellationToken)
147147
};
148148

149149
_audiobuf = new List<byte>();
150+
int pcmReceivedCount = 0;
150151
_airPlayReceiver.OnPCMDataReceived += (s, e) =>
151152
{
153+
pcmReceivedCount++;
154+
if (pcmReceivedCount <= 5 || pcmReceivedCount % 500 == 0)
155+
{
156+
bool allZeros = true;
157+
int checkLen = Math.Min(e.Length, 100);
158+
for (int i = 0; i < checkLen; i++)
159+
{
160+
if (e.Data[i] != 0) { allZeros = false; break; }
161+
}
162+
Console.WriteLine($"[DEBUG-PCM] OnPCMDataReceived #{pcmReceivedCount}: len={e.Length}, allZeros={allZeros}");
163+
}
164+
152165
// Play audio through speakers
153166
lock (_audioOutputLock)
154167
{

0 commit comments

Comments
 (0)