Skip to content

Commit

Permalink
Cleanup Capturer services.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Apr 3, 2020
1 parent 7cc2820 commit c613632
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Desktop.Linux/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ private void BuildServices()
});

serviceCollection.AddSingleton<IScreenCaster, ScreenCasterLinux>();
serviceCollection.AddSingleton<IKeyboardMouseInput, X11Input>();
serviceCollection.AddSingleton<IKeyboardMouseInput, KeyboardMouseInputLinux>();
serviceCollection.AddSingleton<IClipboardService, ClipboardServiceLinux>();
serviceCollection.AddSingleton<IAudioCapturer, AudioCapturerLinux>();
serviceCollection.AddSingleton<CasterSocket>();
serviceCollection.AddSingleton<IdleTimer>();
serviceCollection.AddSingleton<Conductor>();
serviceCollection.AddTransient<IScreenCapturer, X11Capture>();
serviceCollection.AddTransient<IScreenCapturer, ScreenCapturerLinux>();


ServiceContainer.Instance = serviceCollection.BuildServiceProvider();
Expand Down
4 changes: 2 additions & 2 deletions ScreenCast.Linux/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ private static void BuildServices()
});

serviceCollection.AddSingleton<IScreenCaster, ScreenCasterLinux>();
serviceCollection.AddSingleton<IKeyboardMouseInput, X11Input>();
serviceCollection.AddSingleton<IKeyboardMouseInput, KeyboardMouseInputLinux>();
serviceCollection.AddSingleton<IClipboardService, ClipboardServiceLinux>();
serviceCollection.AddSingleton<IAudioCapturer, AudioCapturerLinux>();
serviceCollection.AddSingleton<CasterSocket>();
serviceCollection.AddSingleton<IdleTimer>();
serviceCollection.AddSingleton<Conductor>();
serviceCollection.AddSingleton<ChatHostService>();
serviceCollection.AddTransient<IScreenCapturer, X11Capture>();
serviceCollection.AddTransient<IScreenCapturer, ScreenCapturerLinux>();

ServiceContainer.Instance = serviceCollection.BuildServiceProvider();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

namespace Remotely.ScreenCast.Linux.Services
{
public class X11Input : IKeyboardMouseInput
public class KeyboardMouseInputLinux : IKeyboardMouseInput
{
public X11Input()
public KeyboardMouseInputLinux()
{
Display = LibX11.XOpenDisplay(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace Remotely.ScreenCast.Linux.Services
{
public class X11Capture : IScreenCapturer
public class ScreenCapturerLinux : IScreenCapturer
{
private readonly Dictionary<string, int> x11Screens = new Dictionary<string, int>();
public X11Capture()
public ScreenCapturerLinux()
{
Display = LibX11.XOpenDisplay(null);
Init();
Expand Down
27 changes: 17 additions & 10 deletions ScreenCast.Win/Services/ScreenCapturerWin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,14 @@ public ScreenCapturerWin()
public Bitmap PreviousFrame { get; set; }
public string SelectedScreen { get; private set; } = Screen.PrimaryScreen.DeviceName;
private Graphics Graphic { get; set; }

public void Dispose()
{
foreach (var output in directxScreens.Values)
{
output.Dispose();
}
directxScreens.Clear();
device?.Dispose();
adapter?.Dispose();
factory?.Dispose();
DisposeDirectX();

CurrentFrame?.Dispose();
PreviousFrame?.Dispose();
}

public IEnumerable<string> GetDisplayNames() => Screen.AllScreens.Select(x => x.DeviceName);

public void GetNextFrame()
Expand Down Expand Up @@ -146,6 +140,7 @@ public void Init()
InitBitBlt();
InitDirectX();
}

public void SetSelectedScreen(string displayName)
{
if (displayName == SelectedScreen)
Expand All @@ -167,6 +162,17 @@ public void SetSelectedScreen(string displayName)
ScreenChanged?.Invoke(this, CurrentScreenBounds);
}

private void DisposeDirectX()
{
foreach (var output in directxScreens.Values)
{
output.Dispose();
}
directxScreens.Clear();
device?.Dispose();
adapter?.Dispose();
factory?.Dispose();
}
private void GetBitBltFrame()
{
try
Expand Down Expand Up @@ -268,6 +274,7 @@ private void GetDirectXFrame()

private void InitBitBlt()
{
bitBltScreens.Clear();
Graphic = Graphics.FromImage(CurrentFrame);
for (var i = 0; i < Screen.AllScreens.Length; i++)
{
Expand All @@ -276,7 +283,7 @@ private void InitBitBlt()
}
private void InitDirectX()
{
Dispose();
DisposeDirectX();

factory = new Factory1();

Expand Down

0 comments on commit c613632

Please sign in to comment.