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 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 TestSetAudioInvalid() { AtemMockServerWrapper.Each(_output, _pool, ClearAudioCommandHandler, DeviceTestCases.MediaPlayerClips, helper => { ImmutableList <ICommand> previousCommands = helper.Server.GetParsedDataDump(); int clipCount = helper.Helper.BuildLibState().MediaPool.Clips.Count; for (int index = 0; index < clipCount; index++) { AtemState stateBefore = helper.Helper.BuildLibState(); IBMDSwitcherClip clip = GetClip(helper, (uint)index); for (int i = 0; i < 5; i++) { MediaPoolAudioDescriptionCommand cmd = previousCommands .OfType <MediaPoolAudioDescriptionCommand>().Single(c => c.Index == index + 1); cmd.IsUsed = true; // Set it to true first stateBefore.MediaPool.Clips[index].Audio.IsUsed = true; helper.SendFromServerAndWaitForChange(stateBefore, cmd); // Now set invalid stateBefore.MediaPool.Clips[index].Audio.IsUsed = false; helper.SendAndWaitForChange(stateBefore, () => { clip.SetAudioInvalid(); }); } } }); }
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 MediaSlot(IBMDSwitcherClip clip, uint index) { BMDSwitcherHash hash; // Only getting the hash of the first frame clip.GetFrameHash(0, out hash); this.Hash = String.Join("", BitConverter.ToString(hash.data).Split('-')); clip.GetName(out this.Name); this.Slot = (int)index + 1; this.Type = "Clip"; }
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 TestName() { AtemMockServerWrapper.Each(_output, _pool, NameCommandHandler, DeviceTestCases.MediaPlayerClips, helper => { int clipCount = helper.Helper.BuildLibState().MediaPool.Clips.Count; for (int index = 0; index < clipCount; index++) { IBMDSwitcherClip clip = GetClip(helper, (uint)index); for (int i = 0; i < 5; i++) { AtemState stateBefore = helper.Helper.BuildLibState(); string name = (Guid.NewGuid().ToString() + Guid.NewGuid()).Substring(0, 44); stateBefore.MediaPool.Clips[index].IsUsed = true; stateBefore.MediaPool.Clips[index].Name = name; helper.SendAndWaitForChange(stateBefore, () => { clip.SetName(name); }); } } }); }
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); }); } }); }
internal SwitcherClipCallback(IBMDSwitcherClip clip, int index) { this._indexnr = index; this.Clip = clip; }
public Upload(Switcher switcher, String path, uint uploadSlot) { this.isClip = false; this.switcher = switcher; this.path = path; this.uploadSlot = uploadSlot; this.switcher.Connect(); this.switcherMediaPool = (IBMDSwitcherMediaPool)this.switcher.GetSwitcher(); // Is a directory of clips if (Directory.Exists(path)) { this.isClip = true; this.framepaths = (Array)Directory.GetFiles(path, "*.bmp").OrderBy(f => f).ToArray(); if (this.framepaths.Length < 1) { this.framepaths = (Array)Directory.GetFiles(path, "*.jpg").OrderBy(f => f).ToArray(); } if (this.framepaths.Length < 1) { this.framepaths = (Array)Directory.GetFiles(path, "*.jpeg").OrderBy(f => f).ToArray(); } if (this.framepaths.Length < 1) { this.framepaths = (Array)Directory.GetFiles(path, "*.gif").OrderBy(f => f).ToArray(); } if (this.framepaths.Length < 1) { this.framepaths = (Array)Directory.GetFiles(path, "*.png").OrderBy(f => f).ToArray(); } if (this.framepaths.Length < 1) { this.framepaths = (Array)Directory.GetFiles(path, "*.tiff").OrderBy(f => f).ToArray(); } if (this.framepaths.Length < 1) { this.framepaths = (Array)Directory.GetFiles(path, "*.tif").OrderBy(f => f).ToArray(); } if (this.framepaths.Length < 1) { throw new SwitcherLibException(String.Format("No bmp, jpg, jpeg, gif, png, tiff or tif files found in {0}", path)); } Log.Debug(String.Format("Found {0} media files in {1}", this.framepaths.Length, path)); this.clip = this.GetClip(); UInt32 maxclips; this.switcherMediaPool.GetFrameTotalForClips(out maxclips); // Checking whether the files can fit if (maxclips < this.framepaths.Length) { throw new SwitcherLibException(String.Format("The clip pool can contain up to {0} clips, but there are {1} files found in {2}", maxclips, this.framepaths.Length, this.path)); } } // Is a file with a still else if (File.Exists(path)) { this.currentframepath = path; this.stills = this.GetStills(); } else { throw new SwitcherLibException(String.Format("The file or directory {0} could not be found", path)); } }