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 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); }); } }); }