Esempio n. 1
0
        public void TestDownload()
        {
            DownloadJobWorker 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 DownloadJobWorker(_output, 0xffff, index, combined);

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

                    var downloadCb = new TransferCallback();
                    pool.AddCallback(downloadCb);
                    pool.Download(index, out IBMDSwitcherTransferMacro transfer);

                    helper.HandleUntil(downloadCb.Wait, 1000);
                    Assert.True(downloadCb.Wait.WaitOne(500));
                    Assert.Equal(_BMDSwitcherMacroPoolEventType.bmdSwitcherMacroPoolEventTypeTransferCompleted,
                                 downloadCb.Result);

                    transfer.GetMacro(out IBMDSwitcherMacro macro);
                    macro.GetBytes(out IntPtr buffer);
                    byte[] bytes = new byte[macro.GetSize()];
                    Marshal.Copy(buffer, bytes, 0, bytes.Length);
                    Assert.Equal(BitConverter.ToString(combined), BitConverter.ToString(bytes));

                    helper.Helper.CheckStateChanges(stateBefore);
                }
            });
        }
Esempio n. 2
0
        public void TestClipFrameDownload()
        {
            DownloadJobWorker 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);

                    {
                        var frameState    = stateBefore.MediaPool.Clips[(int)index].Frames[(int)frameIndex];
                        frameState.IsUsed = true;
                        frameState.Hash   = new byte[16];
                        helper.SendFromServerAndWaitForChange(stateBefore, new MediaPoolFrameDescriptionCommand
                        {
                            Bank     = (MediaPoolFileType)index + 1,
                            Filename = "",
                            Index    = frameIndex,
                            IsUsed   = true
                        });
                    }
                    stateBefore = helper.Helper.BuildLibState();

                    byte[] bytes = new byte[resolution.Item1 * resolution.Item2 * 4];
                    worker       = new DownloadJobWorker(_output, index + 1, frameIndex, FrameEncodingUtil.EncodeRLE(bytes));

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

                    var downloadCb = new TransferCallback();
                    clip.AddCallback(downloadCb);
                    clip.DownloadFrame(frameIndex);

                    helper.HandleUntil(downloadCb.Wait, 5000);
                    Assert.True(downloadCb.Wait.WaitOne(500));

                    Assert.Equal(_BMDSwitcherMediaPoolEventType.bmdSwitcherMediaPoolEventTypeTransferCompleted,
                                 downloadCb.Result);
                    Assert.NotNull(downloadCb.Frame);
                    Assert.Null(downloadCb.Audio);

                    byte[] sdkBytes = MediaPoolUtil.GetSdkFrameBytes(downloadCb.Frame);
                    Assert.Equal(BitConverter.ToString(bytes), BitConverter.ToString(sdkBytes));

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        clip.Unlock(cb);
                    });
                }
            });
        }
Esempio n. 3
0
        public void TestAudioDownload()
        {
            DownloadJobWorker 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();

                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;

                    {
                        var clipState          = stateBefore.MediaPool.Clips[(int)index];
                        clipState.Audio.Name   = "Some file";
                        clipState.Audio.IsUsed = true;
                        clipState.Audio.Hash   = new byte[16];
                        helper.SendFromServerAndWaitForChange(stateBefore, new MediaPoolAudioDescriptionCommand
                        {
                            Name   = "Some file",
                            Index  = index + 1,
                            IsUsed = true
                        });
                    }
                    stateBefore = helper.Helper.BuildLibState();

                    var bytes = MediaPoolUtil.RandomFrame(sampleCount);
                    worker    = new DownloadJobWorker(_output, index + 1, 0, bytes);

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

                    var downloadCb = new TransferCallback();
                    clip.AddCallback(downloadCb);
                    clip.DownloadAudio();

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

                    Assert.Null(downloadCb.Frame);
                    Assert.NotNull(downloadCb.Audio);
                    Assert.Equal((int)(sampleCount * 4), downloadCb.Audio.GetSize());
                    byte[] sdkBytes = MediaPoolUtil.GetSdkAudioBytes(downloadCb.Audio);

                    // 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(sdkBytes));

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        clip.Unlock(cb);
                    });
                }
            });
        }
Esempio n. 4
0
        private void DoDownload(int iterations, int timeout, Func <uint, uint, Tuple <byte[], byte[]> > rawBytesGen)
        {
            DownloadJobWorker worker = null;

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

                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);

                    {
                        var stillState      = stateBefore.MediaPool.Stills[(int)index];
                        stillState.Filename = "Some file";
                        stillState.IsUsed   = true;
                        stillState.Hash     = new byte[16];
                        helper.SendFromServerAndWaitForChange(stateBefore, new MediaPoolFrameDescriptionCommand
                        {
                            Bank     = MediaPoolFileType.Still,
                            Filename = "Some file",
                            Index    = index,
                            IsUsed   = true
                        });
                    }
                    stateBefore = helper.Helper.BuildLibState();

                    Tuple <byte[], byte[]> rawBytes = rawBytesGen(resolution.Item1, resolution.Item2);
                    worker = new DownloadJobWorker(_output, (uint)MediaPoolFileType.Still, index,
                                                   rawBytes.Item2);

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

                    var downloadCb = new TransferCallback();
                    stills.AddCallback(downloadCb);
                    stills.Download(index);

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

                    Assert.NotNull(downloadCb.Frame);
                    Assert.Equal(_BMDSwitcherPixelFormat.bmdSwitcherPixelFormat10BitYUVA,
                                 downloadCb.Frame.GetPixelFormat());
                    Assert.Equal(resolution.Item1, (uint)downloadCb.Frame.GetWidth());
                    Assert.Equal(resolution.Item2, (uint)downloadCb.Frame.GetHeight());
                    byte[] sdkBytes = MediaPoolUtil.GetSdkFrameBytes(downloadCb.Frame);
                    Assert.Equal(BitConverter.ToString(rawBytes.Item1), BitConverter.ToString(sdkBytes));

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        stills.Unlock(cb);
                    });
                }
            });
        }