示例#1
0
        public void TestLockAndUnlock()
        {
            AtemMockServerWrapper.Each(_output, _pool, UploadJobWorker.LockCommandHandler, DeviceTestCases.MediaPlayer, helper =>
            {
                IBMDSwitcherStills stills = GetStillsPool(helper);

                AtemState stateBefore = helper.Helper.BuildLibState();

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

                helper.Helper.CheckStateChanges(stateBefore);

                uint timeBefore = helper.Server.CurrentTime;

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

                // It should have sent a response, but we dont expect any comparable data
                Assert.NotEqual(timeBefore, helper.Server.CurrentTime);

                helper.Helper.CheckStateChanges(stateBefore);
            });
        }
示例#2
0
 public void GetLock()
 {
     dispatcher.Invoke(() =>
     {
         m_lockmontior = new SwitcherMediaPoolLockMonitor()
         {
             OnLockObtained = StartUploadWithLock
         };
         m_stills.Lock(m_lockmontior);
     });
 }
示例#3
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);
                    });
                }
            });
        }
示例#4
0
        public void TestAbortingStillUpload()
        {
            AbortedUploadJobWorker worker = null;

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

                IBMDSwitcherMediaPool pool = GetMediaPool(helper);
                IBMDSwitcherStills stills  = GetStillsPool(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.Stills.Count);
                    string name = Guid.NewGuid().ToString();
                    worker      = new AbortedUploadJobWorker(_output);

                    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);
                    MediaPoolUtil.FillSdkFrame(frame, MediaPoolUtil.RandomFrame(resolution.Item1 * resolution.Item2));

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

                    // Short bit of work before the abort
                    helper.HandleUntil(uploadCb.Wait, 1000);
                    stills.CancelTransfer();

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

                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        stills.Unlock(cb);
                    });
                }
            });
        }
示例#5
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);
                    });
                }
            });
        }