- Posts: 15
- Joined: Mon Jul 15, 2019 2:30 pm
- Real Name: Mark Guzewski
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