Esempio n. 1
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);
                    });
                }
            });
        }