Ejemplo n.º 1
0
        public void TestSetInvalid()
        {
            AtemMockServerWrapper.Each(_output, _pool, ClearCommandHandler, DeviceTestCases.MediaPlayer, helper =>
            {
                IBMDSwitcherStills stills = GetStillsPool(helper);

                ImmutableList <ICommand> previousCommands = helper.Server.GetParsedDataDump();

                for (int i = 0; i < 5; i++)
                {
                    AtemState stateBefore = helper.Helper.BuildLibState();

                    uint index = Randomiser.RangeInt((uint)stateBefore.MediaPool.Stills.Count);
                    MediaPoolFrameDescriptionCommand cmd = previousCommands.OfType <MediaPoolFrameDescriptionCommand>().Single(c => c.Index == index && c.Bank == MediaPoolFileType.Still);
                    cmd.IsUsed = true;

                    // Set it to true first
                    stateBefore.MediaPool.Stills[(int)index].IsUsed = true;
                    helper.SendFromServerAndWaitForChange(stateBefore, cmd);

                    // Now set invalid
                    stateBefore.MediaPool.Stills[(int)index].IsUsed   = false;
                    stateBefore.MediaPool.Stills[(int)index].Filename = "";
                    stateBefore.MediaPool.Stills[(int)index].Hash     = new byte[16];
                    helper.SendAndWaitForChange(stateBefore, () =>
                    {
                        stills.SetInvalid(index);
                    });
                }
            });
        }
Ejemplo n.º 2
0
        public void TestStillCapture()
        {
            var handler = CommandGenerator.MatchCommand(new MediaPoolCaptureStillCommand());

            AtemMockServerWrapper.Each(_output, _pool, handler, DeviceTestCases.MediaPlayerStillCapture, helper =>
            {
                IBMDSwitcherStills stills = GetStillsPool(helper);

                IBMDSwitcherStillCapture stillCapture = stills as IBMDSwitcherStillCapture;
                Assert.NotNull(stillCapture);

                stillCapture.IsAvailable(out int available);
                Assert.Equal(1, available);

                for (int i = 0; i < 5; i++)
                {
                    AtemState stateBefore = helper.Helper.BuildLibState();

                    uint timeBefore = helper.Server.CurrentTime;

                    helper.SendAndWaitForChange(stateBefore, () => { stillCapture.CaptureStill(); });

                    // It should have sent a response, but we dont expect any comparable data
                    Assert.NotEqual(timeBefore, helper.Server.CurrentTime);
                }
            });
        }
Ejemplo n.º 3
0
        public void TestLockAndUnlock()
        {
            AtemMockServerWrapper.Each(_output, _pool, UploadJobWorker.LockCommandHandler, DeviceTestCases.MediaPlayer, helper =>
            {
                IBMDSwitcherStills stills = GetStillsPool(helper);

                AtemState stateBefore = helper.Helper.BuildLibState();

                var cb = new LockCallback();
                helper.SendAndWaitForChange(stateBefore, () => { stills.Lock(cb); });
                Assert.True(cb.Wait.WaitOne(2000));

                helper.Helper.CheckStateChanges(stateBefore);

                uint timeBefore = helper.Server.CurrentTime;

                helper.SendAndWaitForChange(stateBefore, () =>
                {
                    stills.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);
            });
        }
Ejemplo n.º 4
0
 public MediaStill(IBMDSwitcherStills stills, uint index)
 {
     BMDSwitcherHash hash;
     stills.GetHash(index, out hash);
     this.Hash = String.Join("", BitConverter.ToString(hash.data).Split('-'));
     stills.GetName(index, out this.Name);
     this.Slot = (int)index + 1;
 }
Ejemplo n.º 5
0
        public MediaStill(IBMDSwitcherStills stills, uint index)
        {
            BMDSwitcherHash hash;

            stills.GetHash(index, out hash);
            this.Hash = String.Join("", BitConverter.ToString(hash.data).Split('-'));
            stills.GetName(index, out this.Name);
            this.Slot = (int)index + 1;
        }
Ejemplo n.º 6
0
        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);
                    });
                }
            });
        }
        private static MediaPoolState.StillState BuildStill(IBMDSwitcherStills props, uint index)
        {
            var state = new MediaPoolState.StillState();

            props.IsValid(index, out int valid);
            state.IsUsed = valid != 0;
            props.GetName(index, out string name);
            state.Filename = name;
            props.GetHash(index, out BMDSwitcherHash hash);
            state.Hash = hash.data;

            return(state);
        }
Ejemplo n.º 8
0
        public Upload(Switcher switcher, String filename, int uploadSlot)
        {
            this.switcher   = switcher;
            this.filename   = filename;
            this.uploadSlot = uploadSlot;

            if (!File.Exists(filename))
            {
                throw new SwitcherLibException(String.Format("{0} does not exist", filename));
            }

            this.switcher.Connect();
            this.stills = this.GetStills();
        }
Ejemplo n.º 9
0
        public Upload(Switcher switcher, String filename, int uploadSlot)
        {
            this.switcher = switcher;
            this.filename = filename;
            this.uploadSlot = uploadSlot;
            //check

            if (!File.Exists(filename))
            {
                throw new SwitcherLibException(String.Format("{0} does not exist", filename));
            }

            this.switcher.Connect();
            this.stills = this.GetStills();
        }
Ejemplo n.º 10
0
        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);
                    });
                }
            });
        }
Ejemplo n.º 11
0
        public Upload(Dispatcher d, IBMDSwitcher switcher, string filename, int uploadSlot)
        {
            this.switcher   = switcher;
            this.filename   = filename;
            this.uploadSlot = uploadSlot;
            this.d          = d;

            if (!File.Exists(filename))
            {
                throw new FileNotFoundException(String.Format("{0} does not exist", filename));
            }

            d.Invoke(() =>
            {
                this.stills = this.GetStills();
            });
        }
Ejemplo n.º 12
0
        public void TestName()
        {
            AtemMockServerWrapper.Each(_output, _pool, NameCommandHandler, DeviceTestCases.MediaPlayer, helper =>
            {
                IBMDSwitcherStills stills = GetStillsPool(helper);

                for (int i = 0; i < 5; i++)
                {
                    AtemState stateBefore = helper.Helper.BuildLibState();

                    uint index  = Randomiser.RangeInt((uint)stateBefore.MediaPool.Stills.Count);
                    string name = (Guid.NewGuid().ToString() + Guid.NewGuid()).Substring(0, 64);

                    stateBefore.MediaPool.Stills[(int)index].IsUsed   = true;
                    stateBefore.MediaPool.Stills[(int)index].Filename = name;

                    helper.SendAndWaitForChange(stateBefore, () => { stills.SetName(index, name); });
                }
            });
        }
Ejemplo n.º 13
0
        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));
            }
        }
Ejemplo n.º 14
0
        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);
                    });
                }
            });
        }
Ejemplo n.º 15
0
 public void Upload(string fn, int s)
 {
     this.filename = fn;
     this.slot     = s;
     this.stills   = this.switcher.BMDSwitcherMediaPool.Stills;
 }
 internal SwitcherStillsCallback(IBMDSwitcherStills stills)
 {
     this.Stills = stills;
 }
Ejemplo n.º 17
0
 internal SwitcherStill(IBMDSwitcherStills stills, int index)
 {
     this._indexnr = index;
     this.Stills   = stills;
 }