Esempio n. 1
0
        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);
                    });
                }
            });
        }
Esempio n. 2
0
        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);
                    });
                }
            });
        }