Skip to content

Commit 1fabb7b

Browse files
Address code review: dispose CTS, flush only on keyframes, include full exception in logs
Co-authored-by: YimingZhanshen <76594627+YimingZhanshen@users.noreply.github.com>
1 parent 7739b41 commit 1fabb7b

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

AirPlay/Listeners/MirroringListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public override async Task OnRawReceivedAsync(TcpClient client, NetworkStream st
130130
}
131131
catch (Exception e)
132132
{
133-
Console.WriteLine($"Mirroring error: {e.Message}");
133+
Console.WriteLine($"Mirroring error: {e}");
134134
}
135135

136136
// Save current session periodically

AirPlay/Services/VideoOutputService.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,22 @@ public void WriteFrame(H264Data data)
175175

176176
try
177177
{
178+
bool isKeyFrame = data.FrameType == 5;
179+
178180
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
179181
{
180182
if (_pipeServer != null && _pipeServer.IsConnected)
181183
{
182184
_pipeServer.Write(data.Data, 0, data.Length);
183-
_pipeServer.Flush();
185+
if (isKeyFrame) _pipeServer.Flush();
184186
}
185187
}
186188
else
187189
{
188190
if (_unixPipeStream != null && _unixPipeStream.CanWrite)
189191
{
190192
_unixPipeStream.Write(data.Data, 0, data.Length);
191-
_unixPipeStream.Flush();
193+
if (isKeyFrame) _unixPipeStream.Flush();
192194
}
193195
}
194196

@@ -250,6 +252,8 @@ public void Dispose()
250252
_disposed = true;
251253

252254
_cts?.Cancel();
255+
_cts?.Dispose();
256+
_cts = null;
253257

254258
try
255259
{

0 commit comments

Comments
 (0)