public void TestRandomStillDownload() { DoDownload(1, 180000, (width, height) => { var bytes = MediaPoolUtil.RandomFrame(width * height); return(Tuple.Create(bytes, FrameEncodingUtil.EncodeRLE(bytes))); }); }
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 TestBlankStillDownload() { DoDownload(3, 3000, (width, height) => { var bytes = MediaPoolUtil.SolidColour(width * height, (byte)Randomiser.Range(50, 200), (byte)Randomiser.Range(50, 200), (byte)Randomiser.Range(50, 200), (byte)Randomiser.Range(50, 200)); return(Tuple.Create(bytes, FrameEncodingUtil.EncodeRLE(bytes))); }); }
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); }); } }); }
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 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); }); } }); }
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); }); } }); }
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); }); } }); }
public void TestGeneratedStillUpload() { DoUpload(1, 45000, (width, height) => MediaPoolUtil.RandomFrame(width * height)); }
public void TestBlankStillUpload() { DoUpload(3, 2000, (width, height) => MediaPoolUtil.SolidColour(width * height, (byte)Randomiser.Range(50, 200), (byte)Randomiser.Range(50, 200), (byte)Randomiser.Range(50, 200), (byte)Randomiser.Range(50, 200))); }