Accessing IBMDSwitcherInputAux using c#

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

guzewski

  • Posts: 15
  • Joined: Mon Jul 15, 2019 2:30 pm
  • Real Name: Mark Guzewski

Accessing IBMDSwitcherInputAux using c#

PostThu Oct 24, 2019 12:20 am

So far my C# work with the ATEM SDK has been going well. And now I'm a bit stuck.

The problem seems simple enough: I need to route any input or Program to AUX6.

The May 2019 SDK doc presents the IBMDSwitcherInputAux interface, but there is no sample code showing how to obtain the object.

The doc states:
An IBMDSwitcherInputAux object interface can be obtained with IBMDSwitcherInput::QueryInterface.

And so I look up IBMDSwitcherInput, and it says:
An IBMDSwitcherInput object will be returned after a successful call to the IBMDSwitcherInputDiscovery::ConnectTo method

And finally, there doesn't not seem to be any information at all about IBMDSwitcherInputDiscovery.

I was wondering if someone might be able to provide a quick C# example or some pointers on how to accomplish my stated aim.

Thanks and regards,
-Mark Guzewski
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 443
  • Joined: Mon Sep 04, 2017 4:05 am

Re: Accessing IBMDSwitcherInputAux using c#

PostThu Oct 24, 2019 3:50 am

Hi Mark,

The following C# code sample, tested with ATEM TV Studio HD, switches the AUX output between SDI 5, Color Generator and Color Bars:
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

using BMDSwitcherAPI;

namespace AuxOutput
{
   class Program
   {
      static long GetInputId(IBMDSwitcherInput input)
      {
         input.GetInputId(out long id);
         return id;
      }

      static void Main(string[] args)
      {
         // Create switcher discovery object
         IBMDSwitcherDiscovery discovery = new CBMDSwitcherDiscovery();

         // Connect to switcher
         discovery.ConnectTo("192.168.10.240", out IBMDSwitcher switcher, out _BMDSwitcherConnectToFailure failureReason);
         Console.WriteLine("Connected to switcher");

         var atem = new AtemSwitcher(switcher);

         // Get reference to various inputs
         IBMDSwitcherInput input5 = atem.SwitcherInputs
                                 .Where((i, ret) => {
                                    i.GetPortType(out _BMDSwitcherPortType type);
                                    return type == _BMDSwitcherPortType.bmdSwitcherPortTypeExternal;
                                 })
                                 .ElementAt(4); // zero-based index
         IBMDSwitcherInput colorgen1 = atem.SwitcherInputs
                                 .Where((i, ret) => {
                                    i.GetPortType(out _BMDSwitcherPortType type);
                                    return type == _BMDSwitcherPortType.bmdSwitcherPortTypeColorGenerator;
                                 })
                                 .ElementAt(0);
         IBMDSwitcherInput colorbars = atem.SwitcherInputs
                                 .Where((i, ret) => {
                                    i.GetPortType(out _BMDSwitcherPortType type);
                                    return type == _BMDSwitcherPortType.bmdSwitcherPortTypeColorBars;
                                 })
                                 .First();
         IBMDSwitcherInputAux auxoutput = atem.SwitcherInputs
                                 .Where((i, ret) => {
                                    i.GetPortType(out _BMDSwitcherPortType type);
                                    return type == _BMDSwitcherPortType.bmdSwitcherPortTypeAuxOutput;
                                 })
                                 .ElementAt(0) as IBMDSwitcherInputAux;

         // Set AUX to SDI external input
         Console.WriteLine("Setting AUX to SDI 5");
         auxoutput.SetInputSource(GetInputId(input5));
         System.Threading.Thread.Sleep(2000);

         // Set AUX to Color Generator 1 input
         Console.WriteLine("Setting AUX to Color Generator 1");
         auxoutput.SetInputSource(GetInputId(colorgen1));
         System.Threading.Thread.Sleep(2000);

         // Set AUX to Color Bars input
         Console.WriteLine("Setting AUX to Color bars");
         auxoutput.SetInputSource(GetInputId(colorbars));
         System.Threading.Thread.Sleep(2000);

         Console.Write("Press ENTER to exit...");
         Console.ReadLine();
      }
   }

   internal class AtemSwitcher
   {
      private IBMDSwitcher switcher;

      public AtemSwitcher(IBMDSwitcher switcher)
      {
         this.switcher = switcher;
      }

      public IEnumerable<IBMDSwitcherInput> SwitcherInputs
      {
         get
         {
            // Create an input iterator
            switcher.CreateIterator(typeof(IBMDSwitcherInputIterator).GUID, out IntPtr inputIteratorPtr);
            IBMDSwitcherInputIterator inputIterator = Marshal.GetObjectForIUnknown(inputIteratorPtr) as IBMDSwitcherInputIterator;
            if (inputIterator == null)
               yield break;

            // Scan through all inputs
            while (true)
            {
               inputIterator.Next(out IBMDSwitcherInput input);

               if (input != null)
                  yield return input;
               else
                  yield break;
            }
         }
      }
   }
}

To get PGM routed to AUX, you will need to feedback the output to another SDI input.

We will update the SDK Manual to replace the incorrect reference to IBMDSwitcherInputDiscovery interface with IBMDSwitcherInputIterator - thanks for raising this!

Regards
Cameron
Offline

guzewski

  • Posts: 15
  • Joined: Mon Jul 15, 2019 2:30 pm
  • Real Name: Mark Guzewski

Re: Accessing IBMDSwitcherInputAux using c#

PostFri Oct 25, 2019 1:23 am

OK, so far so good. Thanks for the detailed sample code. That saved me a ton of work :)
I found all 6 AUX inputs. I assume that index 5 is AUX 6, which is the one I'm interested in.

IBMDSwitcherInputIterator makes sense and is consistent with the other interfaces. I probably should have guessed that.

To get PGM routed to AUX, you will need to feedback the output to another SDI input

Would it not be sufficient to set the aux input source to the input whose type is bmdSwitcherPortTypeMixEffectBlockOutput? I'm a bit unclear on this part. Any addition hints you can provide would be greatly appreciated.

Thanks for the help.
-Mark
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 443
  • Joined: Mon Sep 04, 2017 4:05 am

Re: Accessing IBMDSwitcherInputAux using c#

PostFri Oct 25, 2019 3:50 am

Hi Mark,

The issue of using bmdSwitcherPortTypeMixEffectBlockOutput, is that you will bypass Downstream Keyers and Fade to Black, so it's not equivalent to PGM output. If you are not using either DSK or FTB, then this flow would be OK.

Regards
Cameron
Offline

guzewski

  • Posts: 15
  • Joined: Mon Jul 15, 2019 2:30 pm
  • Real Name: Mark Guzewski

Re: Accessing IBMDSwitcherInputAux using c#

PostFri Oct 25, 2019 3:55 am

I'll ask the client if they're using DSK or FTB. If so then I'll figure out the "proper" way to use PGM output.

Thanks again for all your help. It's been very useful.
-Mark

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 20 guests