Skip to content

Commit

Permalink
feat: multiview border support
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Aug 28, 2024
1 parent 938fdcf commit 7c5b272
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 10 deletions.
3 changes: 2 additions & 1 deletion LibAtem.MockTests/DeviceTestCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal static class DeviceTestCases
public static readonly ProtocolVersion Version = ProtocolVersion.V8_1_1;
public static readonly string MiniExtremeIso = "mini-extreme-iso-v8.6.1";
public static readonly string Mini = "mini-v8.3";
public static readonly string Constellation = "constellation-v8.2.3";
public static readonly string Constellation = "constellation-8k-v9.4";
public static readonly string Constellation2MEHD = "constellation-2me-hd-v8.7";
public static readonly string TwoME = "2me-v8.3";
public static readonly string TwoME4K = "";
Expand All @@ -50,6 +50,7 @@ internal static class DeviceTestCases
public static readonly string[] MultiviewToggleSafeArea = { TwoME4K, FourME4K, Constellation };
public static readonly string[] MultiviewVuMeters = { TwoME4K, FourME4K, Constellation };
public static readonly string[] MultiviewLabelSample = { TwoME4K, TwoME, Constellation, MiniExtremeIso, Mini };
public static readonly string[] MultiviewBorders = { Constellation };

public static readonly string[] CameraControl = {TwoME, Constellation};
public static readonly string[] SerialPort = { TwoME, Constellation };
Expand Down
6 changes: 6 additions & 0 deletions LibAtem.MockTests/LibAtem.MockTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
<None Update="TestFiles\Handshake\constellation-2me-hd-v8.7.data">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFiles\Handshake\constellation-4me-4k-v9.4.data">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFiles\Handshake\constellation-8k-v9.4.data">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFiles\Handshake\constellation-v8.0.2.data">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
19 changes: 19 additions & 0 deletions LibAtem.MockTests/SdkState/MultiViewerStateBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public static void Build(IBMDSwitcher switcher, AtemState state)
info.CanChangeLayout = canChangeLayout != 0;
props.CanAdjustVuMeterOpacity(out int canChangeVuOpacity);
info.CanChangeVuMeterOpacity = canChangeVuOpacity != 0;

props.CanChangeOverlayProperties(out int canChangeOverlayProperties);
info.SupportsOverlayProperties = canChangeOverlayProperties != 0;

if (info.SupportsOverlayProperties)
{
props.GetBorderColor(out double red, out double green, out double blue, out double alpha);
state.BorderColor = new MultiViewerState.BorderColorState() { Red = red, Green = green, Blue = blue, Alpha = alpha };
}
#endif

props.GetLayout(out _BMDSwitcherMultiViewLayout layout);
Expand Down Expand Up @@ -83,6 +92,16 @@ public static void Build(IBMDSwitcher switcher, AtemState state)
st.VuMeterEnabled = vuEnabled != 0;
}
if (info.SupportsOverlayProperties)
{
// props.CurrentInputSupportsLabelOverlay((uint)window, out int windowSupportsLabel);
// st.SupportsLabelVisible = windowSupportsLabel != 0;
props.GetLabelVisible((uint)window, out int labelVisible);

Check failure on line 99 in LibAtem.MockTests/SdkState/MultiViewerStateBuilder.cs

View workflow job for this annotation

GitHub Actions / test_v8_0_3_-_v8_1_0

'IBMDSwitcherMultiView' does not contain a definition for 'GetLabelVisible' and no accessible extension method 'GetLabelVisible' accepting a first argument of type 'IBMDSwitcherMultiView' could be found (are you missing a using directive or an assembly reference?)
st.LabelVisible = labelVisible != 0;
props.GetBorderVisible((uint)window, out int borderVisible);

Check failure on line 101 in LibAtem.MockTests/SdkState/MultiViewerStateBuilder.cs

View workflow job for this annotation

GitHub Actions / test_v8_0_3_-_v8_1_0

'IBMDSwitcherMultiView' does not contain a definition for 'GetBorderVisible' and no accessible extension method 'GetBorderVisible' accepting a first argument of type 'IBMDSwitcherMultiView' could be found (are you missing a using directive or an assembly reference?)
st.BorderVisible = borderVisible != 0;
}
return st;
}).ToList();

Expand Down
2 changes: 2 additions & 0 deletions LibAtem.MockTests/SdkState/SdkStateBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public static AtemState Build(IBMDSwitcher switcher, AtemStateBuilderSettings up
supportsMultiviewer = false;
}
}
multiviewModes.Sort();

var downConvertModes = new List<VideoMode>();
if (supportsDownConvert)
Expand All @@ -116,6 +117,7 @@ public static AtemState Build(IBMDSwitcher switcher, AtemStateBuilderSettings up
supportsDownConvert = false;
}
}
downConvertModes.Sort();

modes.Add(new VideoModeInfo
{
Expand Down
108 changes: 108 additions & 0 deletions LibAtem.MockTests/TestFiles/Handshake/constellation-8k-v9.4.data

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions LibAtem.MockTests/TestHandshakeState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ private void RunTest(string caseId)

using var server = new AtemMockServer("127.0.0.1", commandData, DeviceTestCases.Version);
var stateSettings = new AtemStateBuilderSettings();
stateSettings.IgnoreUnknownCameraControlProperties = true;
using var helper = new AtemSdkClientWrapper("127.0.0.1", stateSettings, 1);

var libAtemState = AtemTestHelper.SanitiseStateIncompabalities(DeviceTestCases.Version,
Expand Down
132 changes: 124 additions & 8 deletions LibAtem.MockTests/TestMultiview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using BMDSwitcherAPI;
using LibAtem.Commands;
using LibAtem.Commands.Settings.Multiview;
using LibAtem.Commands.SuperSource;
using LibAtem.Common;
using LibAtem.MockTests.SdkState;
using LibAtem.MockTests.Util;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void TestLayout()
stateBefore.Settings.MultiViewers[(int)mv.Item1].Properties.Layout = newValue;
helper.SendAndWaitForChange(stateBefore, () =>
{
mv.Item2.SetLayout((_BMDSwitcherMultiViewLayout) newValue);
mv.Item2.SetLayout((_BMDSwitcherMultiViewLayout)newValue);
});
}
}
Expand All @@ -86,7 +87,7 @@ public void TestSwapProgramPreview()
Assert.Equal(1, supportsSwap);
AtemState stateBefore = helper.Helper.BuildLibState();
MultiViewerState mvState = stateBefore.Settings.MultiViewers[(int) mv.Item1];
MultiViewerState mvState = stateBefore.Settings.MultiViewers[(int)mv.Item1];
for (int i = 0; i < 5; i++)
{
Expand Down Expand Up @@ -123,7 +124,7 @@ public void TestToggleSafeAreaEnabled()
mv.Item2.SupportsQuadrantLayout(out int supportsQuadrant);
int[] windows = supportsQuadrant == 0
? new[] {0, 1}
? new[] { 0, 1 }
: Randomiser.SelectionOfGroup(Enumerable.Range(0, 16).ToList()).ToArray();
foreach (int window in windows)
Expand All @@ -132,10 +133,10 @@ public void TestToggleSafeAreaEnabled()
for (int i = 0; i < 5; i++)
{
bool newValue = i % 2 == 0;
stateBefore.Settings.MultiViewers[(int) mv.Item1].Windows[window].SafeAreaEnabled = newValue;
stateBefore.Settings.MultiViewers[(int)mv.Item1].Windows[window].SafeAreaEnabled = newValue;
helper.SendAndWaitForChange(stateBefore,
() => { mv.Item2.SetSafeAreaEnabled((uint) window, newValue ? 1 : 0); });
() => { mv.Item2.SetSafeAreaEnabled((uint)window, newValue ? 1 : 0); });
}
}
}
Expand Down Expand Up @@ -206,7 +207,7 @@ public void TestVuMeterOpacity()
for (int i = 0; i < 5; i++)
{
double newValue = Randomiser.Range(0, 100);
stateBefore.Settings.MultiViewers[(int) mv.Item1].VuMeterOpacity = newValue;
stateBefore.Settings.MultiViewers[(int)mv.Item1].VuMeterOpacity = newValue;
helper.SendAndWaitForChange(stateBefore,
() => { mv.Item2.SetVuMeterOpacity(newValue / 100); });
Expand Down Expand Up @@ -264,7 +265,7 @@ public void TestWindowSupportsVuMeterEnabled()
foreach (int window in windows)
{
AtemState stateBefore = helper.Helper.BuildLibState();
MultiViewerState.WindowState windowState = stateBefore.Settings.MultiViewers[(int) mv.Item1].Windows[window];
MultiViewerState.WindowState windowState = stateBefore.Settings.MultiViewers[(int)mv.Item1].Windows[window];
MultiviewWindowInputGetCommand cmd = cmds.Single(c => c.WindowIndex == window && c.MultiviewIndex == mv.Item1);
Expand Down Expand Up @@ -368,7 +369,7 @@ public void TestSource()
helper.SendAndWaitForChange(stateBefore, () =>
{
mv.Item2.SetWindowInput((uint) window, (long) src);
mv.Item2.SetWindowInput((uint)window, (long)src);
});
}
}
Expand All @@ -388,5 +389,120 @@ private static IEnumerable<ICommand> SourceCommandHandler(Lazy<ImmutableList<ICo
}
}

[Fact]
public void TestWindowLabelVisible()
{
var handler = CommandGenerator.CreateAutoCommandHandler<MultiviewWindowOverlaySetCommand, MultiviewWindowOverlayGetCommand>("LabelVisible", true);

AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.MultiviewBorders, helper =>
{
foreach (Tuple<uint, IBMDSwitcherMultiView> mv in GetMultiviewers(helper))
{
// TODO: re-enable this
// mv.Item2.CanChangeOverlayProperties(out int supported);
// Assert.Equal(1, supported);
int[] windows = Randomiser
.SelectionOfGroup(Enumerable.Range(0, 16).ToList()).ToArray();
foreach (int window in windows)
{
AtemState stateBefore = helper.Helper.BuildLibState();
MultiViewerState.WindowState windowState = stateBefore.Settings.MultiViewers[(int)mv.Item1].Windows[window];
for (int i = 0; i < 5; i++)
{
bool newValue = i % 2 == 0;
windowState.LabelVisible = newValue;
helper.SendAndWaitForChange(stateBefore, () =>
{
mv.Item2.SetLabelVisible((uint)window, newValue ? 1 : 0);

Check failure on line 420 in LibAtem.MockTests/TestMultiview.cs

View workflow job for this annotation

GitHub Actions / test_v8_0_3_-_v8_1_0

'IBMDSwitcherMultiView' does not contain a definition for 'SetLabelVisible' and no accessible extension method 'SetLabelVisible' accepting a first argument of type 'IBMDSwitcherMultiView' could be found (are you missing a using directive or an assembly reference?)
});
}
}
}
});
}

[Fact]
public void TestWindowBorderVisible()
{
var handler = CommandGenerator.CreateAutoCommandHandler<MultiviewWindowOverlaySetCommand, MultiviewWindowOverlayGetCommand>("BorderVisible", true);

AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.MultiviewBorders, helper =>
{
foreach (Tuple<uint, IBMDSwitcherMultiView> mv in GetMultiviewers(helper))
{
// TODO: re-enable this
// mv.Item2.CanChangeOverlayProperties(out int supported);
// Assert.Equal(1, supported);
int[] windows = Randomiser
.SelectionOfGroup(Enumerable.Range(0, 16).ToList()).ToArray();
foreach (int window in windows)
{
AtemState stateBefore = helper.Helper.BuildLibState();
MultiViewerState.WindowState windowState = stateBefore.Settings.MultiViewers[(int)mv.Item1].Windows[window];
for (int i = 0; i < 5; i++)
{
bool newValue = i % 2 == 0;
windowState.BorderVisible = newValue;
helper.SendAndWaitForChange(stateBefore, () =>
{
mv.Item2.SetBorderVisible((uint)window, newValue ? 1 : 0);

Check failure on line 456 in LibAtem.MockTests/TestMultiview.cs

View workflow job for this annotation

GitHub Actions / test_v8_0_3_-_v8_1_0

'IBMDSwitcherMultiView' does not contain a definition for 'SetBorderVisible' and no accessible extension method 'SetBorderVisible' accepting a first argument of type 'IBMDSwitcherMultiView' could be found (are you missing a using directive or an assembly reference?)
});
}
}
}
});
}

[Fact]
public void TestBorderColor()
{
var expectedCmd = new MultiviewBorderColorGetCommand();
var handler = CommandGenerator.EchoCommand(expectedCmd);

AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.MultiviewBorders, helper =>
{
foreach (Tuple<uint, IBMDSwitcherMultiView> mv in GetMultiviewers(helper))
{
// TODO: re-enable this
// mv.Item2.CanChangeOverlayProperties(out int supported);
// Assert.Equal(1, supported);
AtemState stateBefore = helper.Helper.BuildLibState();
MultiViewerState mvState = stateBefore.Settings.MultiViewers[(int)mv.Item1];
for (int i = 0; i < 5; i++)
{
expectedCmd.MultiviewIndex = mv.Item1;
expectedCmd.Red = Randomiser.Range(0, 1, 100);
expectedCmd.Green = Randomiser.Range(0, 1, 100);
expectedCmd.Blue = Randomiser.Range(0, 1, 100);
expectedCmd.Alpha = Randomiser.Range(0, 1, 100);
mvState.BorderColor = new MultiViewerState.BorderColorState
{
Red = expectedCmd.Red,
Green = expectedCmd.Green,
Blue = expectedCmd.Blue,
Alpha = expectedCmd.Alpha
};
helper.SendAndWaitForChange(stateBefore, () =>
{
mv.Item2.SetBorderColor(expectedCmd.Red, expectedCmd.Green, expectedCmd.Blue, expectedCmd.Alpha);

Check failure on line 500 in LibAtem.MockTests/TestMultiview.cs

View workflow job for this annotation

GitHub Actions / test_v8_0_3_-_v8_1_0

'IBMDSwitcherMultiView' does not contain a definition for 'SetBorderColor' and no accessible extension method 'SetBorderColor' accepting a first argument of type 'IBMDSwitcherMultiView' could be found (are you missing a using directive or an assembly reference?)
});
}
}
});
}
}
}
1 change: 1 addition & 0 deletions LibAtem.MockTests/Util/AtemServerClientPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public AtemServerClientPool()
{
_pool = new Dictionary<string, AtemMockServerPoolItem>();
StateSettings = new AtemStateBuilderSettings();
StateSettings.IgnoreUnknownCameraControlProperties = true;
}

public AtemMockServerPoolItem GetCase(string caseId)
Expand Down

0 comments on commit 7c5b272

Please sign in to comment.