public void TestRandomStillDownload() { DoDownload(1, 180000, (width, height) => { var bytes = MediaPoolUtil.RandomFrame(width * height); return(Tuple.Create(bytes, FrameEncodingUtil.EncodeRLE(bytes))); }); }
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))); }); }
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 virtual IEnumerable <ICommand> HandleCommand(Lazy <ImmutableList <ICommand> > previousCommands, ICommand cmd) { var lockRes = LockCommandHandler(previousCommands, cmd).ToList(); if (lockRes.Any()) { foreach (LockStateChangedCommand lockCmd in lockRes.OfType <LockStateChangedCommand>()) { _locked = lockCmd.Locked; // _output.WriteLine($"Locked {lockCmd.Locked}"); } return(lockRes); } // _output.WriteLine($"Got cmd: {cmd.GetType().FullName}"); var res = new List <ICommand>(); if (cmd is DataTransferUploadRequestCommand startCmd) { Assert.Equal(_bank != 0xffff, _locked); Assert.False(_isComplete); Assert.Equal(_expectedMode, startCmd.Mode); if (_targetBytes > 0) { Assert.Equal((int)_targetBytes, startCmd.Size); } Assert.Equal(_index, startCmd.TransferIndex); Assert.Equal((uint)_bank, startCmd.TransferStoreId); _transferId = startCmd.TransferId; _pendingAck = 0; _targetBytes = (uint)startCmd.Size; res.Add(new DataTransferUploadContinueCommand { TransferId = startCmd.TransferId, ChunkCount = _chunkCount, ChunkSize = _chunkSize }); } else if (cmd is DataTransferFileDescriptionCommand descCmd) { Assert.NotEqual(0u, _transferId); Assert.Null(_description); Assert.False(_isComplete); Assert.Equal(_transferId, descCmd.TransferId); _description = descCmd; if (_usedBytes >= _targetBytes) { _isComplete = true; res.AddRange(Complete()); } else { res.Add(null); } } else if (cmd is DataTransferDataCommand dataCmd) { Assert.NotEqual(0u, _transferId); Assert.False(_isComplete); Assert.Equal(_transferId, dataCmd.TransferId); Assert.True(dataCmd.Body.Length <= _chunkSize); Tuple <int, byte[]> decoded = _decodeRle ? FrameEncodingUtil.DecodeRLESegment(_targetBytes, dataCmd.Body) : Tuple.Create(dataCmd.Body.Length, dataCmd.Body); if (!_knownTargetBytes) { byte[] newBuffer = new byte[Buffer.Length + decoded.Item1]; Array.Copy(Buffer, 0, newBuffer, 0, Buffer.Length); Buffer = newBuffer; } //long copyLength = Math.Min(decoded.Item1, _targetBytes - _usedBytes); Array.Copy(decoded.Item2, 0, Buffer, _usedBytes, decoded.Item1); _usedBytes += (uint)decoded.Item1; _pendingAck++; if (_pendingAck >= _chunkCount) { //res.Add(new DataTransferAckCommand {TransferId = _transferId}); res.Add(new DataTransferUploadContinueCommand { TransferId = _transferId, ChunkCount = _chunkCount, ChunkSize = _chunkSize }); _pendingAck = 0; } // _output.WriteLine($"Now have {_usedBytes} bytes of {_targetBytes}"); if (_usedBytes >= _targetBytes && _description != null) { _isComplete = true; res.AddRange(Complete()); } if (res.Count == 0) { res.Add(null); } } return(res); }