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); }); } }); }
public void TestLockAndUnlock() { AtemMockServerWrapper.Each(_output, _pool, UploadJobWorker.LockCommandHandler, DeviceTestCases.MediaPlayerClips, helper => { helper.DisposeSdkClient = true; int clipCount = helper.Helper.BuildLibState().MediaPool.Clips.Count; for (int index = 0; index < clipCount; index++) { IBMDSwitcherClip clip = GetClip(helper, (uint)index); AtemState stateBefore = helper.Helper.BuildLibState(); var cb = new LockCallback(); helper.SendAndWaitForChange(stateBefore, () => { clip.Lock(cb); }); Assert.True(cb.Wait.WaitOne(2000)); helper.Helper.CheckStateChanges(stateBefore); uint timeBefore = helper.Server.CurrentTime; helper.SendAndWaitForChange(stateBefore, () => { clip.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); } }); }
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); }); } }); }
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); }); } }); }
public void TestAbortingAudioUpload() { AbortedUploadJobWorker 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(); uint index = Randomiser.RangeInt((uint)stateBefore.MediaPool.Clips.Count); IBMDSwitcherClip clip = GetClip(helper, index); uint sampleCount = 10000; string name = Guid.NewGuid().ToString(); worker = new AbortedUploadJobWorker(_output); 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 uploadCb = new TransferCallback(); clip.AddCallback(uploadCb); clip.UploadAudio(name, frame); // Short bit of work before the abort helper.HandleUntil(uploadCb.Wait, 1000); clip.CancelTransfer(); helper.HandleUntil(uploadCb.Wait, 1000); Assert.True(uploadCb.Wait.WaitOne(500)); Assert.Equal(_BMDSwitcherMediaPoolEventType.bmdSwitcherMediaPoolEventTypeTransferCancelled, uploadCb.Result); helper.SendAndWaitForChange(stateBefore, () => { clip.Unlock(cb); }); } }); }
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); }); } }); }
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); }); } }); }