public void TestJog()
        {
            var expectedCmd = new HyperDeckPlayerSetCommand
            {
                Mask = HyperDeckPlayerSetCommand.MaskFlags.Jog,
            };
            var handler = CommandGenerator.MatchCommand(expectedCmd, true);

            AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.HyperDecks, helper =>
            {
                foreach (IBMDSwitcherHyperDeck deck in GetHyperDecks(helper))
                {
                    deck.GetId(out long id);
                    expectedCmd.Id = (uint)id;

                    expectedCmd.Jog = Randomiser.RangeInt(-100, 100);

                    AtemState stateBefore = helper.Helper.BuildLibState();
                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        deck.Jog(expectedCmd.Jog);
                    });
                }
            });
        }
        public void TestGetSelection()
        {
            bool tested = false;

            AtemMockServerWrapper.Each(Output, Pool, null, DeviceTestCases.All, helper =>
            {
                EachMixEffect <IBMDSwitcherTransitionParameters>(helper, (stateBefore, meBefore, sdk, meId, i) =>
                {
                    tested = true;

                    uint maxSelectionValue = (uint)1 << meBefore.Keyers.Count;
                    uint maxSelection      = (maxSelectionValue << 1) - 1;
                    uint target            = 1 + Randomiser.RangeInt(maxSelection - 1);
                    meBefore.Transition.Properties.Selection = (TransitionLayer)target;
                    helper.SendAndWaitForChange(stateBefore, () => {
                        helper.Server.SendCommands(new TransitionPropertiesGetCommand
                        {
                            Index         = meId,
                            NextStyle     = meBefore.Transition.Properties.NextStyle,
                            Style         = meBefore.Transition.Properties.Style,
                            NextSelection = meBefore.Transition.Properties.NextSelection,
                            Selection     = (TransitionLayer)target,
                        });
                    });
                });
            });
            Assert.True(tested);
        }
        public void TestAutoRollFrameDelay()
        {
            var handler =
                CommandGenerator.CreateAutoCommandHandler <HyperDeckSettingsSetCommand, HyperDeckSettingsGetCommand>(
                    "AutoRollFrameDelay");

            AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.HyperDecks, helper =>
            {
                foreach (IBMDSwitcherHyperDeck deck in GetHyperDecks(helper))
                {
                    for (int i = 0; i < 5; i++)
                    {
                        deck.GetId(out long id);
                        AtemState stateBefore = helper.Helper.BuildLibState();

                        HyperdeckState hyperdeckState = stateBefore.Hyperdecks[(int)id];
                        hyperdeckState.Settings.AutoRollFrameDelay = Randomiser.RangeInt(60);

                        helper.SendAndWaitForChange(stateBefore,
                                                    () =>
                        {
                            deck.SetAutoRollOnTakeFrameDelay((ushort)hyperdeckState.Settings.AutoRollFrameDelay);
                        });
                    }
                }
            });
        }
        public void TestDiskRemoval()
        {
            var handler = CommandGenerator.CreateAutoCommandHandler <RecordingStatusSetCommand, RecordingStatusGetCommand>("IsRecording", true);

            AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.Streaming, helper =>
            {
                var switcher = helper.SdkClient.SdkSwitcher as IBMDSwitcherStreamRTMP;
                Assert.NotNull(switcher);

                AtemState stateBefore = helper.Helper.BuildLibState();

                // Init a disk that will persit
                InitDisk(helper, stateBefore, 99);

                for (int i = 0; i < 10; i++)
                {
                    var id  = Randomiser.RangeInt(20);
                    var cmd = InitDisk(helper, stateBefore, id);

                    // Simulate removal
                    cmd.IsDelete = true;
                    stateBefore.Recording.Disks.Remove(id);
                    helper.SendFromServerAndWaitForChange(stateBefore, cmd);
                }
            });
        }
        public void TestStorageMediaCount()
        {
            AtemMockServerWrapper.Each(_output, _pool, null, DeviceTestCases.HyperDecks, helper =>
            {
                List <HyperDeckSettingsGetCommand> settingsCommands = helper.Server.GetParsedDataDump().OfType <HyperDeckSettingsGetCommand>().ToList();

                foreach (IBMDSwitcherHyperDeck deck in GetHyperDecks(helper))
                {
                    deck.GetId(out long id);
                    HyperDeckSettingsGetCommand cmd = settingsCommands.Single(c => c.Id == id);

                    // Force it to be connected
                    AtemState stateBefore = helper.Helper.BuildLibState();
                    cmd.Status            = HyperDeckConnectionStatus.Connected;
                    stateBefore.Hyperdecks[(int)id].Settings.Status = HyperDeckConnectionStatus.Connected;
                    stateBefore.Hyperdecks[(int)id].Player.State    = HyperDeckPlayerState.Idle;
                    helper.SendFromServerAndWaitForChange(stateBefore, cmd);

                    stateBefore = helper.Helper.BuildLibState();
                    HyperdeckState hyperdeckState = stateBefore.Hyperdecks[(int)id];

                    for (int i = 0; i < 5; i++)
                    {
                        hyperdeckState.Settings.StorageMediaCount =
                            cmd.StorageMediaCount = (uint)Randomiser.RangeInt(1, 5);

                        helper.SendFromServerAndWaitForChange(stateBefore, cmd);
                    }
                }
            });
        }
        public void TestAudioInputId()
        {
            var handler = CommandGenerator.CreateAutoCommandHandler <MixMinusOutputSetCommand, MixMinusOutputGetCommand>("Mode");

            AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.MixMinusOutputs, helper =>
            {
                var previousCommands = helper.Server.GetParsedDataDump().OfType <MixMinusOutputGetCommand>().ToList();

                for (int i = 0; i < 10; i++)
                {
                    AtemState stateBefore = helper.Helper.BuildLibState();
                    uint id = Randomiser.RangeInt((uint)stateBefore.Settings.MixMinusOutputs.Count - 1);
                    SettingsState.MixMinusOutputState mixMinusState = stateBefore.Settings.MixMinusOutputs[(int)id];

                    MixMinusOutputGetCommand cmd = previousCommands.Single(c => c.Id == id);
                    uint newValue       = Randomiser.RangeInt(9) + 1;
                    cmd.HasAudioInputId = i % 2 == 0;
                    cmd.AudioInputId    = cmd.HasAudioInputId ? (AudioSource)newValue : 0;

                    mixMinusState.HasAudioInputId = cmd.HasAudioInputId;
                    mixMinusState.AudioInputId    = cmd.AudioInputId;

                    helper.SendFromServerAndWaitForChange(stateBefore, cmd);
                }
            });
        }
Exemple #7
0
        public void TestIsRunning()
        {
            bool tested = false;

            AtemMockServerWrapper.Each(Output, Pool, null, DeviceTestCases.All, helper =>
            {
                SelectionOfKeyers <IBMDSwitcherKeyFlyParameters>(helper, (stateBefore, keyerBefore, sdkKeyer, meId, keyId, i) =>
                {
                    tested = true;

                    var cmd = helper.Server.GetParsedDataDump().OfType <MixEffectKeyFlyPropertiesGetCommand>()
                              .Single(c => c.MixEffectIndex == meId && c.KeyerIndex == keyId);

                    for (int o = 0; o < 5; o++)
                    {
                        var targetFrame = Randomiser.RangeInt(10) > 7
                            ? FlyKeyKeyFrameType.RunToInfinite
                            : Randomiser.EnumValue <FlyKeyKeyFrameType>();
                        var targetInfinite = Randomiser.EnumValue <FlyKeyLocation>();

                        keyerBefore.FlyProperties.RunningToKeyFrame = cmd.RunningToKeyFrame = targetFrame;
                        keyerBefore.FlyProperties.RunningToInfinite = cmd.RunningToInfinite =
                            targetFrame == FlyKeyKeyFrameType.RunToInfinite ? targetInfinite : 0;

                        helper.SendFromServerAndWaitForChange(stateBefore, cmd);
                    }
                });
            });
            Assert.True(tested);
        }
        public void TestShuttle()
        {
            var expectedCmd = new HyperDeckPlayerSetCommand
            {
                Mask  = HyperDeckPlayerSetCommand.MaskFlags.State | HyperDeckPlayerSetCommand.MaskFlags.PlaybackSpeed,
                State = HyperDeckPlayerState.Playing,
            };
            var handler = CommandGenerator.MatchCommand(expectedCmd, true);

            AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.HyperDecks, helper =>
            {
                AtemState stateBefore = helper.Helper.BuildLibState();
                foreach (IBMDSwitcherHyperDeck deck in GetHyperDecks(helper))
                {
                    deck.GetId(out long id);
                    expectedCmd.Id = (uint)id;

                    for (int i = 0; i < 5; i++)
                    {
                        expectedCmd.PlaybackSpeed = Randomiser.RangeInt(-100, 200);
                        helper.SendAndWaitForChange(stateBefore, () =>
                        {
                            deck.Shuttle(expectedCmd.PlaybackSpeed);
                        });
                    }
                }
            });
        }
Exemple #9
0
        public void TestDuration()
        {
            AtemMockServerWrapper.Each(_output, _pool, null, DeviceTestCases.Streaming, helper =>
            {
                var switcher = helper.SdkClient.SdkSwitcher as IBMDSwitcherStreamRTMP;
                Assert.NotNull(switcher);

                AtemState stateBefore = helper.Helper.BuildLibState();

                for (int i = 0; i < 5; i++)
                {
                    var durationCommand = new StreamingDurationCommand
                    {
                        Hour        = Randomiser.RangeInt(23),
                        Minute      = Randomiser.RangeInt(59),
                        Second      = Randomiser.RangeInt(59),
                        Frame       = Randomiser.RangeInt(59),
                        IsDropFrame = i % 2 != 0
                    };

                    stateBefore.Streaming.Status.Duration = new Timecode
                    {
                        Hour      = durationCommand.Hour,
                        Minute    = durationCommand.Minute,
                        Second    = durationCommand.Second,
                        Frame     = durationCommand.Frame,
                        DropFrame = durationCommand.IsDropFrame,
                    };

                    helper.SendFromServerAndWaitForChange(stateBefore, durationCommand);
                }
            });
        }
        public void TestRecordStatus()
        {
            AtemMockServerWrapper.Each(_output, _pool, null, DeviceTestCases.All, helper =>
            {
                var control = helper.SdkClient.SdkSwitcher as IBMDSwitcherMacroControl;
                Assert.NotNull(control);

                AtemState stateBefore = helper.Helper.BuildLibState();

                for (int i = 0; i < 5; i++)
                {
                    uint index     = Randomiser.RangeInt((uint)stateBefore.Macros.Pool.Count);
                    bool recording = Randomiser.RangeInt(1) == 1;

                    stateBefore.Macros.RecordStatus.RecordIndex = index;
                    stateBefore.Macros.RecordStatus.IsRecording = recording;

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        helper.Server.SendCommands(new MacroRecordingStatusGetCommand()
                        {
                            Index       = index,
                            IsRecording = recording,
                        });
                    });
                }
            });
        }
Exemple #11
0
        public void TestClipFrame()
        {
            try
            {
                _pool.StateSettings.TrackMediaClipFrames = true;
                var handler = CommandGenerator.CreateAutoCommandHandler <MediaPlayerClipStatusSetCommand, MediaPlayerClipStatusGetCommand>("ClipFrame");
                AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.MediaPlayerClips, helper =>
                {
                    var tested  = false;
                    var players = GetMediaPlayers(helper);

                    foreach (Tuple <uint, IBMDSwitcherMediaPlayer> player in players)
                    {
                        tested = true;

                        AtemState stateBefore        = helper.Helper.BuildLibState();
                        MediaPlayerState playerState = stateBefore.MediaPlayers[(int)player.Item1];

                        for (int i = 0; i < 5; i++)
                        {
                            uint frame = playerState.ClipStatus.ClipFrame = Randomiser.RangeInt(40);

                            helper.SendAndWaitForChange(stateBefore, () => { player.Item2.SetClipFrame(frame); });
                        }
                    }

                    Assert.True(tested);
                });
            }
            finally
            {
                _pool.StateSettings.TrackMediaClipFrames = false;
            }
        }
Exemple #12
0
        public void TestSource()
        {
            AtemMockServerWrapper.Each(_output, _pool, SourceCommandHandler, DeviceTestCases.MediaPlayer, helper =>
            {
                var tested  = false;
                var players = GetMediaPlayers(helper);

                foreach (Tuple <uint, IBMDSwitcherMediaPlayer> player in players)
                {
                    tested = true;

                    AtemState stateBefore        = helper.Helper.BuildLibState();
                    MediaPlayerState playerState = stateBefore.MediaPlayers[(int)player.Item1];

                    for (int i = 0; i < 5; i++)
                    {
                        MediaPlayerSource type = playerState.Source.SourceType = stateBefore.MediaPool.Clips.Count > 0
                            ? Randomiser.EnumValue <MediaPlayerSource>()
                            : MediaPlayerSource.Still;
                        uint index = playerState.Source.SourceIndex = Randomiser.RangeInt(20) + 1;

                        helper.SendAndWaitForChange(stateBefore,
                                                    () => { player.Item2.SetSource(AtemEnumMaps.MediaPlayerSourceMap[type], index); });
                    }
                }
                Assert.True(tested);
            });
        }
Exemple #13
0
        public void TestSetInvalid()
        {
            AtemMockServerWrapper.Each(_output, _pool, ClearCommandHandler, DeviceTestCases.MediaPlayer, helper =>
            {
                IBMDSwitcherStills stills = GetStillsPool(helper);

                ImmutableList <ICommand> previousCommands = helper.Server.GetParsedDataDump();

                for (int i = 0; i < 5; i++)
                {
                    AtemState stateBefore = helper.Helper.BuildLibState();

                    uint index = Randomiser.RangeInt((uint)stateBefore.MediaPool.Stills.Count);
                    MediaPoolFrameDescriptionCommand cmd = previousCommands.OfType <MediaPoolFrameDescriptionCommand>().Single(c => c.Index == index && c.Bank == MediaPoolFileType.Still);
                    cmd.IsUsed = true;

                    // Set it to true first
                    stateBefore.MediaPool.Stills[(int)index].IsUsed = true;
                    helper.SendFromServerAndWaitForChange(stateBefore, cmd);

                    // Now set invalid
                    stateBefore.MediaPool.Stills[(int)index].IsUsed   = false;
                    stateBefore.MediaPool.Stills[(int)index].Filename = "";
                    stateBefore.MediaPool.Stills[(int)index].Hash     = new byte[16];
                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        stills.SetInvalid(index);
                    });
                }
            });
        }
Exemple #14
0
        public void TestClipSetValid()
        {
            AtemMockServerWrapper.Each(_output, _pool, SetValidCommandHandler, DeviceTestCases.MediaPlayerClips, helper =>
            {
                for (int i = 0; i < 3; i++)
                {
                    AtemState stateBefore = helper.Helper.BuildLibState();
                    uint index            = Randomiser.RangeInt((uint)stateBefore.MediaPool.Clips.Count);
                    IBMDSwitcherClip clip = GetClip(helper, index);

                    string name     = Guid.NewGuid().ToString();
                    uint frameCount = Randomiser.RangeInt(5) + 3;

                    var cb = new LockCallback();
                    helper.SendAndWaitForChange(stateBefore, () => { clip.Lock(cb); });
                    Assert.True(cb.Wait.WaitOne(2000));

                    var clipState        = stateBefore.MediaPool.Clips[(int)index];
                    clipState.IsUsed     = true;
                    clipState.Name       = name;
                    clipState.FrameCount = frameCount;

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        clip.SetValid(name, frameCount);
                    });

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        clip.Unlock(cb);
                    });
                }
            });
        }
Exemple #15
0
        public void TestTransitionFramesRemaining()
        {
            bool tested = false;

            AtemMockServerWrapper.Each(Output, Pool, null, DeviceTestCases.All, helper =>
            {
                EachMixEffect <IBMDSwitcherMixEffectBlock>(helper, (stateBefore, meBefore, sdk, meId, i) =>
                {
                    tested = true;

                    uint target = Randomiser.RangeInt(250);
                    meBefore.Transition.Position.RemainingFrames = target;
                    helper.SendAndWaitForChange(stateBefore, () => {
                        helper.Server.SendCommands(new TransitionPositionGetCommand
                        {
                            Index           = meId,
                            RemainingFrames = target,
                            InTransition    = meBefore.Transition.Position.InTransition,
                            HandlePosition  = meBefore.Transition.Position.HandlePosition
                        });
                    });
                });
            });
            Assert.True(tested);
        }
        public void TestTally()
        {
            AtemMockServerWrapper.Each(_output, _pool, null, DeviceTestCases.All, helper =>
            {
                List <VideoSource> inputIds = helper.Helper.BuildLibState().Settings.Inputs
                                              .Where(i => i.Value.Properties.InternalPortType == InternalPortType.External).Select(i => i.Key)
                                              .ToList();
                TallyBySourceCommand tallyCmd = helper.Server.GetParsedDataDump().OfType <TallyBySourceCommand>().Single();

                foreach (VideoSource id in Randomiser.SelectionOfGroup(inputIds))
                {
                    AtemState stateBefore            = helper.Helper.BuildLibState();
                    InputState.TallyState tallyState = stateBefore.Settings.Inputs[id].Tally;

                    for (int i = 0; i < 5; i++)
                    {
                        bool isProgram     = tallyState.ProgramTally = Randomiser.RangeInt(10) > 5;
                        bool isPreview     = tallyState.PreviewTally = Randomiser.RangeInt(10) > 5;
                        tallyCmd.Tally[id] = Tuple.Create(isProgram, isPreview);

                        helper.SendFromServerAndWaitForChange(stateBefore, tallyCmd);
                    }
                }
            });
        }
        public void TestCurrentClipId()
        {
            var handler =
                CommandGenerator.CreateAutoCommandHandler <HyperDeckStorageSetCommand, HyperDeckStorageGetCommand>(
                    "CurrentClipId");

            AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.HyperDecks, helper =>
            {
                foreach (IBMDSwitcherHyperDeck deck in GetHyperDecks(helper))
                {
                    deck.GetId(out long id);

                    AtemState stateBefore    = helper.Helper.BuildLibState();
                    HyperdeckState deckState = stateBefore.Hyperdecks[(int)id];

                    for (int i = 0; i < 5; i++)
                    {
                        deckState.Storage.CurrentClipId = Randomiser.RangeInt(-1, 3);

                        helper.SendAndWaitForChange(stateBefore,
                                                    () => { deck.SetCurrentClip(deckState.Storage.CurrentClipId); });
                    }
                }
            });
        }
Exemple #18
0
        public void TestHasUnsupportedOps()
        {
            AtemMockServerWrapper.Each(_output, _pool, null, DeviceTestCases.MacroTransfer, helper =>
            {
                var pool = helper.SdkClient.SdkSwitcher as IBMDSwitcherMacroPool;
                Assert.NotNull(pool);

                ImmutableList <ICommand> previousCommands = helper.Server.GetParsedDataDump();

                for (int i = 0; i < 10; i++)
                {
                    AtemState stateBefore = helper.Helper.BuildLibState();

                    uint index = Randomiser.RangeInt((uint)stateBefore.Macros.Pool.Count);
                    MacroPropertiesGetCommand cmd = previousCommands.OfType <MacroPropertiesGetCommand>().Single(c => c.Index == index);
                    cmd.HasUnsupportedOps         = i % 2 == 0;

                    stateBefore.Macros.Pool[(int)index].HasUnsupportedOps = cmd.HasUnsupportedOps;

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        helper.Server.SendCommands(cmd);
                    });
                }
            });
        }
Exemple #19
0
        public void TestCacheUsed()
        {
            AtemMockServerWrapper.Each(_output, _pool, null, DeviceTestCases.Streaming, helper =>
            {
                var switcher = helper.SdkClient.SdkSwitcher as IBMDSwitcherStreamRTMP;
                Assert.NotNull(switcher);

                AtemState stateBefore = helper.Helper.BuildLibState();

                // Set streaming
                var streamCmd = new StreamingStatusGetCommand {
                    Status = StreamingStatus.Streaming, Error = StreamingError.None
                };
                stateBefore.Streaming.Status.State = StreamingStatus.Streaming;
                helper.SendFromServerAndWaitForChange(stateBefore, streamCmd);

                for (int i = 0; i < 5; i++)
                {
                    var cmd = new StreamingStatsCommand
                    {
                        CacheUsed = (uint)Randomiser.RangeInt(0, 100)
                    };
                    stateBefore.Streaming.Stats.CacheUsed = cmd.CacheUsed;

                    helper.SendFromServerAndWaitForChange(stateBefore, cmd);
                }
            });
        }
        public void TestRunStatus()
        {
            AtemMockServerWrapper.Each(_output, _pool, null, DeviceTestCases.All, helper =>
            {
                var control = helper.SdkClient.SdkSwitcher as IBMDSwitcherMacroControl;
                Assert.NotNull(control);

                AtemState stateBefore = helper.Helper.BuildLibState();

                for (int i = 0; i < 5; i++)
                {
                    uint index = Randomiser.RangeInt((uint)stateBefore.Macros.Pool.Count);
                    var status = Randomiser.EnumValue <MacroState.MacroRunStatus>();

                    stateBefore.Macros.RunStatus.RunIndex  = index;
                    stateBefore.Macros.RunStatus.RunStatus = status;

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        helper.Server.SendCommands(new MacroRunStatusGetCommand
                        {
                            Index     = index,
                            IsWaiting = status == MacroState.MacroRunStatus.UserWait,
                            IsRunning = status == MacroState.MacroRunStatus.Running,
                            Loop      = stateBefore.Macros.RunStatus.Loop,
                        });
                    });
                }
            });
        }
        public void TestPeriodicFlushInterval()
        {
            var handler =
                CommandGenerator.CreateAutoCommandHandler <CameraControlSettingsSetCommand, CameraControlSettingsGetCommand>("Interval", true);

            AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.CameraControl, helper =>
            {
                helper.Helper.StateSettings.IgnoreUnknownCameraControlProperties = true;
                IBMDSwitcherCameraControl camera = helper.SdkClient.SdkSwitcher as IBMDSwitcherCameraControl;
                Assert.NotNull(camera);

                for (int i = 0; i < 5; i++)
                {
                    AtemState stateBefore = helper.Helper.BuildLibState();

                    uint interval = Randomiser.RangeInt(int.MaxValue);
                    stateBefore.CameraControl.PeriodicFlushInterval = interval;

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        camera.SetPeriodicFlushInterval(interval);
                    });
                }
            });
        }
        public void TestRecordPause()
        {
            var expectedCommand = new MacroAddTimedPauseCommand();
            var handler         = CommandGenerator.MatchCommand(expectedCommand);

            AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.All, helper =>
            {
                var control = helper.SdkClient.SdkSwitcher as IBMDSwitcherMacroControl;
                Assert.NotNull(control);

                AtemState stateBefore = helper.Helper.BuildLibState();

                for (int i = 0; i < 5; i++)
                {
                    uint frames = Randomiser.RangeInt(2500);

                    expectedCommand.Frames = frames;

                    uint timeBefore = helper.Server.CurrentTime;

                    helper.SendAndWaitForChange(stateBefore, () => { control.RecordPause(frames); });

                    // It should have sent a response, but we dont expect any comparable data
                    Assert.NotEqual(timeBefore, helper.Server.CurrentTime);
                }
            });
        }
        public void TestRun()
        {
            var expectedCommand = RunThroughSerialize(new MacroActionCommand
            {
                Action = MacroActionCommand.MacroAction.Run
            });
            var handler = CommandGenerator.MatchCommand(expectedCommand);

            AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.All, helper =>
            {
                var control = helper.SdkClient.SdkSwitcher as IBMDSwitcherMacroControl;
                Assert.NotNull(control);

                AtemState stateBefore = helper.Helper.BuildLibState();

                for (int i = 0; i < 5; i++)
                {
                    uint index            = Randomiser.RangeInt((uint)stateBefore.Macros.Pool.Count);
                    expectedCommand.Index = index;

                    uint timeBefore = helper.Server.CurrentTime;

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        control.Run(index);
                    });

                    // It should have sent a response, but we dont expect any comparable data
                    Assert.NotEqual(timeBefore, helper.Server.CurrentTime);
                }
            });
        }
Exemple #24
0
        public void TestAudioUpload()
        {
            UploadJobWorker worker = null;

            AtemMockServerWrapper.Each(_output, _pool, (a, b) => worker?.HandleCommand(a, b), DeviceTestCases.MediaPlayerClips, helper =>
            {
                helper.DisposeSdkClient = true;

                var pidCmd = helper.Server.GetParsedDataDump().OfType <ProductIdentifierCommand>().Single();

                IBMDSwitcherMediaPool pool = GetMediaPool(helper);

                for (int i = 0; i < 3; i++)
                {
                    AtemState stateBefore = helper.Helper.BuildLibState();
                    uint index            = Randomiser.RangeInt((uint)stateBefore.MediaPool.Clips.Count);
                    IBMDSwitcherClip clip = GetClip(helper, index);

                    uint sampleCount = 10000;

                    string name = Guid.NewGuid().ToString();
                    worker      = new UploadJobWorker(sampleCount * 4, _output,
                                                      index + 1, 0, DataTransferUploadRequestCommand.TransferMode.Write2, false);

                    var cb = new LockCallback();
                    helper.SendAndWaitForChange(stateBefore, () => { clip.Lock(cb); });
                    Assert.True(cb.Wait.WaitOne(2000));

                    byte[] bytes = MediaPoolUtil.RandomFrame(sampleCount);
                    pool.CreateAudio((uint)bytes.Length, out IBMDSwitcherAudio frame);
                    MediaPoolUtil.FillSdkAudio(frame, bytes);

                    var clipState          = stateBefore.MediaPool.Clips[(int)index];
                    clipState.Audio.IsUsed = true;
                    clipState.Audio.Name   = name;

                    var uploadCb = new TransferCallback();
                    clip.AddCallback(uploadCb);
                    clip.UploadAudio(name, frame);

                    helper.HandleUntil(uploadCb.Wait, 5000);
                    Assert.True(uploadCb.Wait.WaitOne(500));
                    Assert.Equal(_BMDSwitcherMediaPoolEventType.bmdSwitcherMediaPoolEventTypeTransferCompleted,
                                 uploadCb.Result);

                    // TODO - this needs a better rule that can be properly exposed via the lib
                    byte[] flippedBytes = pidCmd.Model >= ModelId.PS4K
                        ? MediaPoolUtil.FlipAudio(bytes)
                        : bytes;
                    Assert.Equal(BitConverter.ToString(flippedBytes), BitConverter.ToString(worker.Buffer));

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        clip.Unlock(cb);
                    });
                }
            });
        }
 private static byte[] RandomIP()
 {
     return(new[]
     {
         (byte)Randomiser.RangeInt(255),
         (byte)Randomiser.RangeInt(255),
         (byte)Randomiser.RangeInt(255),
         (byte)Randomiser.RangeInt(255),
     });
 }
Exemple #26
0
        public void TestUpload()
        {
            UploadJobWorker worker = null;

            AtemMockServerWrapper.Each(_output, _pool, (a, b) => worker?.HandleCommand(a, b), DeviceTestCases.MacroTransfer, helper =>
            {
                helper.DisposeSdkClient = true;

                var pool = helper.SdkClient.SdkSwitcher as IBMDSwitcherMacroPool;
                Assert.NotNull(pool);

                for (int i = 0; i < 5; i++)
                {
                    AtemState stateBefore = helper.Helper.BuildLibState();

                    uint index  = Randomiser.RangeInt((uint)stateBefore.Macros.Pool.Count);
                    string name = Guid.NewGuid().ToString();

                    byte[] op = new CutTransitionMacroOp {
                        Index = MixEffectBlockId.One
                    }.ToByteArray();
                    byte[] fakeOp   = { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                    byte[] combined = op.Concat(fakeOp).ToArray();
                    worker          = new UploadJobWorker((uint)combined.Length, _output, 0xffff, index,
                                                          DataTransferUploadRequestCommand.TransferMode.Write2 |
                                                          DataTransferUploadRequestCommand.TransferMode.Clear2);

                    // var cb = new TestMediaPoolStills.LockCallback();
                    // helper.SendAndWaitForChange(stateBefore, () => { .Lock(cb); });
                    // Assert.True(cb.Wait.WaitOne(2000));

                    pool.CreateMacro((uint)combined.Length, out IBMDSwitcherMacro macro);
                    macro.GetBytes(out IntPtr buffer);
                    Marshal.Copy(combined, 0, buffer, combined.Length);

                    var uploadCb = new TransferCallback();
                    pool.AddCallback(uploadCb);
                    pool.Upload(index, name, "not now", macro, out IBMDSwitcherTransferMacro transfer);

                    MacroState.ItemState macroState = stateBefore.Macros.Pool[(int)index];
                    macroState.Name              = name;
                    macroState.Description       = "not now";
                    macroState.HasUnsupportedOps = true;
                    macroState.IsUsed            = true;

                    helper.HandleUntil(uploadCb.Wait, 1000);
                    Assert.True(uploadCb.Wait.WaitOne(500));
                    Assert.Equal(_BMDSwitcherMacroPoolEventType.bmdSwitcherMacroPoolEventTypeTransferCompleted,
                                 uploadCb.Result);
                    Assert.Equal(BitConverter.ToString(combined), BitConverter.ToString(worker.Buffer));

                    helper.Helper.CheckStateChanges(stateBefore);
                }
            });
        }
Exemple #27
0
        private void DoUpload(int iterations, int timeout, Func <uint, uint, byte[]> frameBytes)
        {
            UploadJobWorker worker = null;

            AtemMockServerWrapper.Each(_output, _pool, (a, b) => worker?.HandleCommand(a, b), DeviceTestCases.MediaPlayer, helper =>
            {
                helper.DisposeSdkClient = true;

                IBMDSwitcherMediaPool pool = GetMediaPool(helper);
                IBMDSwitcherStills stills  = GetStillsPool(helper);

                for (int i = 0; i < iterations; i++)
                {
                    AtemState stateBefore         = helper.Helper.BuildLibState();
                    Tuple <uint, uint> resolution = stateBefore.Settings.VideoMode.GetResolution().GetSize();

                    uint index  = Randomiser.RangeInt((uint)stateBefore.MediaPool.Stills.Count);
                    string name = Guid.NewGuid().ToString();
                    worker      = new UploadJobWorker(resolution.Item1 * resolution.Item2 * 4, _output,
                                                      (uint)MediaPoolFileType.Still, index, DataTransferUploadRequestCommand.TransferMode.Write);

                    var cb = new LockCallback();
                    helper.SendAndWaitForChange(stateBefore, () => { stills.Lock(cb); });
                    Assert.True(cb.Wait.WaitOne(2000));

                    pool.CreateFrame(_BMDSwitcherPixelFormat.bmdSwitcherPixelFormat10BitYUVA, resolution.Item1,
                                     resolution.Item2, out IBMDSwitcherFrame frame);
                    byte[] bytes = frameBytes(resolution.Item1, resolution.Item2);
                    if (bytes.Length > 0)
                    {
                        MediaPoolUtil.FillSdkFrame(frame, bytes);
                    }

                    var stillState      = stateBefore.MediaPool.Stills[(int)index];
                    stillState.IsUsed   = true;
                    stillState.Filename = name;

                    var uploadCb = new TransferCallback();
                    stills.AddCallback(uploadCb);
                    stills.Upload(index, name, frame);

                    helper.HandleUntil(uploadCb.Wait, timeout);
                    Assert.True(uploadCb.Wait.WaitOne(500));
                    Assert.Equal(_BMDSwitcherMediaPoolEventType.bmdSwitcherMediaPoolEventTypeTransferCompleted,
                                 uploadCb.Result);
                    Assert.Equal(BitConverter.ToString(bytes), BitConverter.ToString(worker.Buffer));

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        stills.Unlock(cb);
                    });
                }
            });
        }
        private static void FillRandomData(CameraControlGetCommand cmd, params CameraControlDataType[] omitTypes)
        {
            cmd.Input     = (VideoSource)(Randomiser.RangeInt(20) + 50);
            cmd.Category  = Randomiser.RangeInt(10) + 20;
            cmd.Parameter = Randomiser.RangeInt(10) + 15;

            cmd.Type = Randomiser.EnumValue <CameraControlDataType>(omitTypes);
            switch (cmd.Type)
            {
            case CameraControlDataType.Bool:
                cmd.BoolData = Enumerable.Range(0, Randomiser.RangeInt(8, 8))     // TODO - higher has issues
                               .Select(i => Randomiser.Range(0, 10) >= 5)
                               .ToArray();
                break;

            case CameraControlDataType.SInt8:
                cmd.IntData = Enumerable.Range(0, Randomiser.RangeInt(1, 8))     // TODO - higher has issues
                              .Select(i => Randomiser.RangeInt(sbyte.MinValue, sbyte.MaxValue))
                              .ToArray();
                break;

            case CameraControlDataType.SInt16:
                cmd.IntData = Enumerable.Range(0, Randomiser.RangeInt(1, 4))
                              .Select(i => Randomiser.RangeInt(short.MinValue, short.MaxValue))
                              .ToArray();
                break;

            case CameraControlDataType.SInt32:
                cmd.IntData = Enumerable.Range(0, Randomiser.RangeInt(1, 2))
                              .Select(i => Randomiser.RangeInt(-500000, 500000))
                              .ToArray();
                break;

            case CameraControlDataType.SInt64:
                cmd.LongData = Enumerable.Range(0, 1)
                               .Select(i => (long)Randomiser.RangeInt(-5000000, 5000000))
                               .ToArray();
                break;

            case CameraControlDataType.String:
                cmd.StringData = Randomiser.String(32);
                break;

            case CameraControlDataType.Float:
                cmd.FloatData = Enumerable.Range(0, Randomiser.RangeInt(1, 4))
                                .Select(i => Randomiser.Range(0, 1))
                                .ToArray();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #29
0
        public void TestClipFrameUpload()
        {
            UploadJobWorker worker = null;

            AtemMockServerWrapper.Each(_output, _pool, (a, b) => worker?.HandleCommand(a, b), DeviceTestCases.MediaPlayerClips, helper =>
            {
                helper.DisposeSdkClient = true;

                IBMDSwitcherMediaPool pool = GetMediaPool(helper);

                for (int i = 0; i < 3; i++)
                {
                    AtemState stateBefore         = helper.Helper.BuildLibState();
                    Tuple <uint, uint> resolution = stateBefore.Settings.VideoMode.GetResolution().GetSize();
                    uint index            = Randomiser.RangeInt((uint)stateBefore.MediaPool.Clips.Count);
                    uint frameIndex       = Randomiser.RangeInt(stateBefore.MediaPool.Clips[(int)index].MaxFrames);
                    IBMDSwitcherClip clip = GetClip(helper, index);

                    worker = new UploadJobWorker(resolution.Item1 * resolution.Item2 * 4, _output,
                                                 index + 1, frameIndex, DataTransferUploadRequestCommand.TransferMode.Write);

                    var cb = new LockCallback();
                    helper.SendAndWaitForChange(stateBefore, () => { clip.Lock(cb); });
                    Assert.True(cb.Wait.WaitOne(2000));

                    pool.CreateFrame(_BMDSwitcherPixelFormat.bmdSwitcherPixelFormat10BitYUVA, resolution.Item1,
                                     resolution.Item2, out IBMDSwitcherFrame frame);
                    byte[] bytes = MediaPoolUtil.SolidColour(resolution.Item1 * resolution.Item2, 100, 0, 0, 255);
                    MediaPoolUtil.FillSdkFrame(frame, bytes);

                    var clipState = stateBefore.MediaPool.Clips[(int)index];
                    clipState.Frames[(int)frameIndex].IsUsed = true;
                    //clipState.Audio.Name = name;

                    var uploadCb = new TransferCallback();
                    clip.AddCallback(uploadCb);
                    clip.UploadFrame(frameIndex, frame);

                    helper.HandleUntil(uploadCb.Wait, 5000);
                    Assert.True(uploadCb.Wait.WaitOne(500));
                    Assert.Equal(_BMDSwitcherMediaPoolEventType.bmdSwitcherMediaPoolEventTypeTransferCompleted,
                                 uploadCb.Result);
                    Assert.Equal(BitConverter.ToString(bytes), BitConverter.ToString(worker.Buffer));

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        clip.Unlock(cb);
                    });
                }
            });
        }
Exemple #30
0
        public void TestRate()
        {
            var handler = CommandGenerator.CreateAutoCommandHandler <DownstreamKeyRateSetCommand, DownstreamKeyPropertiesGetCommand>("Rate", true);

            AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.All, helper =>
            {
                EachKeyer(helper, (stateBefore, state, props, id, i) =>
                {
                    uint target           = Randomiser.RangeInt(250);
                    state.Properties.Rate = target;
                    helper.SendAndWaitForChange(stateBefore, () => { props.SetRate(target); });
                });
            });
        }