コード例 #1
0
ファイル: Switcher.cs プロジェクト: cleitet/atemlib
        public void Connect()
        {
            if (this.connected)
            {
                return;
            }

            IBMDSwitcherDiscovery        switcherDiscovery = new CBMDSwitcherDiscovery();
            _BMDSwitcherConnectToFailure failReason        = 0;

            try
            {
                switcherDiscovery.ConnectTo(this.deviceAddress, out this.switcher, out failReason);
                this.connected = true;
            }
            catch (COMException ex)
            {
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    throw new SwitcherLibException("Incompatible firmware");

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    throw new SwitcherLibException(String.Format("No response from {0}", this.deviceAddress));

                default:
                    throw new SwitcherLibException(String.Format("Unknown Error: {0}", ex.Message));
                }
            }
            catch (Exception ex)
            {
                throw new SwitcherLibException(String.Format("Unable to connect to switcher: {0}", ex.Message));
            }
        }
コード例 #2
0
        public void ConnectTo(String address)
        {
            IBMDSwitcherDiscovery discovery = new CBMDSwitcherDiscovery();

            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                IBMDSwitcher switcher;
                // Note that ConnectTo() can take several seconds to return, both for success or failure,
                // depending upon hostname resolution and network response times, so it may be best to
                // do this in a separate thread to prevent the main GUI thread blocking.
                discovery.ConnectTo(address, out switcher, out failReason);
                Switcher = switcher;
            }
            catch (COMException ex)
            {
                Switcher = null;
                // An exception will be thrown if ConnectTo fails. For more information, see failReason.
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    throw new Exception("No response from Switcher", ex);

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    throw new Exception("Switcher has incompatible firmware", ex);

                default:
                    throw new Exception("Connection failed for unknown reason", ex);
                }
            }
        }
コード例 #3
0
        public AtemSdkClientWrapper(string address, AtemStateBuilderSettings updateSettings, int id)
        {
            var logRepository = LogManager.GetRepository(Assembly.GetExecutingAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
            if (!logRepository.Configured) // Default to all on the console
            {
                BasicConfigurator.Configure(logRepository);
            }

            Id = id;

            _updateSettings = updateSettings;

            _switcherDiscovery = new CBMDSwitcherDiscovery();
            Assert.NotNull(_switcherDiscovery);

            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                _switcherDiscovery.ConnectTo(address, out _sdkSwitcher, out failReason);
            }
            catch (COMException)
            {
                throw new Exception($"SDK Connection failure: {failReason}");
            }

            //_sdkSwitcher.AddCallback(new SwitcherConnectionMonitor()); // TODO - make this monitor work better!

            _sdkState = new AtemSDKStateMonitor(_sdkSwitcher);
            _sdkState.OnStateChange += (s) => OnSdkStateChange?.Invoke(s);
        }
コード例 #4
0
ファイル: SwitcherControl.cs プロジェクト: Gustice/SimpleCut
        public void ConnectToIp(string ipAddress)
        {
            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                m_switcherDiscovery.ConnectTo(ipAddress, out m_switcher, out failReason);
            }
            catch (COMException)
            {
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    MessageBox.Show("No response from Switcher", "Error");
                    break;

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    MessageBox.Show("Switcher has incompatible firmware", "Error");
                    break;

                default:
                    MessageBox.Show("Connection failed for unknown reason", "Error");
                    break;
                }
                return;
            }

            SwitcherConnected();
        }
コード例 #5
0
        public void Discover()
        {
            this.m_switcherDiscovery = new CBMDSwitcherDiscovery();
            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                this.m_switcherDiscovery.ConnectTo(this.BMDDeviceAddress, out this.m_switcher, out failReason);
                this.IsConnected = true;
            }
            catch (COMException exception1)
            {
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    throw new BMDSwitcherLibExeption("Incompatible firmware");

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    throw new BMDSwitcherLibExeption(string.Format("No response from {0}", this.BMDDeviceAddress));

                default:
                    throw new BMDSwitcherLibExeption(string.Format("Unknown Error: {0}", exception1.Message));
                }
            }
            catch (Exception exception2)
            {
                throw new BMDSwitcherLibExeption(string.Format("Unable to connect to switcher: {0}", exception2.Message));
            }
        }
コード例 #6
0
        public void Connect(string address)
        {
            this.AtemIPAddress = address;

            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                // Note that ConnectTo() can take several seconds to return, both for success or failure,
                // depending upon hostname resolution and network response times, so it may be best to
                // do this in a separate thread to prevent the main GUI thread blocking.
                m_switcherDiscovery.ConnectTo(address, out m_switcher, out failReason);
            }
            catch (COMException comEx)
            {
                // An exception will be thrown if ConnectTo fails. For more information, see failReason.
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    // MessageBox.Show("No response from Switcher", "Error");
                    throw new ConnectFailureNoResponseException(string.Format("Cannot connect to switcher at address: {0}", address));

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    // MessageBox.Show("Switcher has incompatible firmware", "Error");
                    throw new ConnectFailureIncompatibleFirmwareException(string.Format("Switcher at address {0} has incompatible firmware.  Either rebuild this library to the switcher version or upgrade the switcher firmware to match.", address));

                default:
                    throw new Exception(string.Format("Cannot connect to switcher at address {0}.  See inner exception for more information", address), comEx);
                }
                throw new Exception(string.Format("Cannot connect to switcher at address {0}.  See inner exception for more information", address), comEx);
            }

            SwitcherConnected();
        }
コード例 #7
0
        public VisionService(String IP)
        {
            if (!MainForm.IGNORE_VISION)
            {
                _BMDSwitcherConnectToFailure failReason = 0;

                CBMDSwitcherDiscovery switcher_discovery = new CBMDSwitcherDiscovery();
                if (switcher_discovery == null)
                {
                    throw new Exception("ATEM Switcher Software not installed");
                }

                try
                {
                    switcher_discovery.ConnectTo(IP, out this.Switcher, out failReason);
                }
                catch (COMException)
                {
                    switch (failReason)
                    {
                    case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                        throw new Exception("No response from Switcher at " + IP);

                    case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                        throw new Exception("Switcher at " + IP + " has incompatible firmware");

                    default:
                        throw new Exception("Connection to " + IP + " failed for unknown reason");
                    }
                }

                if (this.Switcher != null)
                {
                    IntPtr input_iterator_ptr;
                    this.Switcher.CreateIterator(typeof(IBMDSwitcherInputIterator).GUID, out input_iterator_ptr);
                    if (input_iterator_ptr != null)
                    {
                        this.InputIterator = (IBMDSwitcherInputIterator)Marshal.GetObjectForIUnknown(input_iterator_ptr);
                    }
                    else
                    {
                        this.Switcher = null;
                    }
                }
            }
        }
コード例 #8
0
        public void connect()
        {
            if (is_connecting || is_connected)
            {
                return;
            }

            // Connect to switcher
            _BMDSwitcherConnectToFailure failureReason = 0;

            is_connecting = true;
            try
            {
                CBMDSwitcherDiscovery atem_discovery = new CBMDSwitcherDiscovery();
                atem_discovery.ConnectTo(atem_ip, out atem_switcher, out failureReason);
                Log.Debug("Connected to ATEM");
            }
            catch (COMException comEx)
            {
                Log.Error("Failed to connect to ATM, got error: " + comEx.Message);
                atem_switcher = null;
            }
            finally
            {
                if (failureReason == 0 && atem_switcher != null)
                {
                    switcherConnected();
                    if (inputs != null && inputs[0] != null && inputs[1] != null && inputs[2] != null && inputs[3] != null)
                    {
                        is_connected = true;
                    }
                    else
                    {
                        is_connected = false;
                    }
                }
                else
                {
                    is_connected = false;
                }
                is_connecting = false;
            }
        }
コード例 #9
0
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            _BMDSwitcherConnectToFailure failReason = 0;
            string address = textBoxIP.Text;

            new Thread(() =>
            {
                try
                {
                    // Note that ConnectTo() can take several seconds to return, both for success or failure,
                    // depending upon hostname resolution and network response times, so it may be best to
                    // do this in a separate thread to prevent the main GUI thread blocking.
                    // Good news, now it's in a background thread
                    m_switcherDiscovery.ConnectTo(address, out m_switcher, out failReason);
                    SwitcherConnected();
                }
                catch (COMException)
                {
                    // An exception will be thrown if ConnectTo fails. For more information, see failReason.
                    this.Invoke((Action)(() =>
                    {
                        switch (failReason)
                        {
                        case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                            MessageBox.Show("No response from Switcher", "Error");
                            break;

                        case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                            MessageBox.Show("Switcher has incompatible firmware", "Error");
                            break;

                        default:
                            MessageBox.Show("Connection failed for unknown reason", "Error");
                            break;
                        }
                    }));
                    return;
                }
            }).Start();
        }
コード例 #10
0
        private void ButtonConnect_Click(object sender, RoutedEventArgs e)
        {
            bSwitcherDiscovery = new CBMDSwitcherDiscovery();
            if (bSwitcherDiscovery == null)
            {
                MessageBox.Show("Could not create Switcher Discovery Instance.\n"
                                + "ATEM Switcher Software may not be installed.", "Error");
                return;
            }

            string deviceAddress = TextBoxSwitcherIPAddress.Text;
            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                bSwitcherDiscovery.ConnectTo(deviceAddress, out bSwitcher, out failReason);
            }
            catch (COMException)
            {
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    MessageBox.Show("No response from Switcher", "Error");
                    break;

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    MessageBox.Show("Switcher has incompatible firmware", "Error");
                    break;

                default:
                    MessageBox.Show("Connection failed for unknown reason", "Error");
                    break;
                }
                return;
            }

            OnSwitcherConnected();
        }
コード例 #11
0
        IBMDSwitcher ConnectImpl()
        {
            if (string.IsNullOrEmpty(_ipaddress))
            {
                Console.WriteLine("Warning: IP address has not been initialized. I do not like your chances.");
            }

            if (_switcher == null || !_isConnected)
            {
                var discovery = new CBMDSwitcherDiscovery();
                _BMDSwitcherConnectToFailure failure = 0;
                try
                {
                    discovery.ConnectTo(_ipaddress, out _switcher, out failure);
                }
                catch (System.Runtime.InteropServices.COMException e)
                {
                    _logger.LogWarning(e, $"Could not connect: {failure}");
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Could not connect");
                }
                if (failure == 0)
                {
                    _isConnected = true;
                    _switcher.AddCallback(this);
                    _switcher.GetProductName(out string productName);
                    _logger.LogInformation($"Happy Days... connected to {productName}@{_ipaddress}!");
                }
                else
                {
                    _logger.LogWarning(failure.ToString());
                }
            }

            return(_switcher);
        }
コード例 #12
0
    private void ConnectAtem(string connectIp)
    {
        m_switcherDiscovery = new CBMDSwitcherDiscovery();
        if (m_switcherDiscovery == null)
        {
            Debug.LogError("Could not create Switcher Discovery Instance.\nATEM Switcher Software may not be installed.");
        }

        _BMDSwitcherConnectToFailure failReason = 0;
        string address = connectIp;

        try
        {
            // Note that ConnectTo() can take several seconds to return, both for success or failure,
            // depending upon hostname resolution and network response times, so it may be best to
            // do this in a separate thread to prevent the main GUI thread blocking.
            m_switcherDiscovery.ConnectTo(address, out m_switcher, out failReason);
        }
        catch (COMException)
        {
            // An exception will be thrown if ConnectTo fails. For more information, see failReason.
            switch (failReason)
            {
            case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                Debug.LogError("No response from Switcher");
                break;

            case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                Debug.LogError("Switcher has incompatible firmware");
                break;

            default:
                Debug.LogError("Connection failed for unknown reason");
                break;
            }
            return;
        }
    }
コード例 #13
0
        public void Connect()
        {
            if (IsConnected)
            {
                throw new InvalidOperationException("Already connected");
            }

            _BMDSwitcherConnectToFailure failed = 0;

            try
            {
                switcherDiscovery.ConnectTo(ipAddress.ToString(), out switcher, out failed);
                switcher.GetProductName(out name);
                switcher.AddCallback(switcherMonitor);

                inputs.Clear();
                foreach (var item in GetInputs())
                {
                    inputs.Add(new Input(this, item));
                }
            }
            catch (COMException)
            {
                switch (failed)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    throw new Exception("No response from Switcher");

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    throw new Exception("Switcher has incompatible firmware");

                default:
                    throw new Exception("Connection failed for unknown reason");
                }
            }
        }
コード例 #14
0
		public virtual extern void ConnectTo([In] string deviceAddress, out IBMDSwitcher switcherDevice, out _BMDSwitcherConnectToFailure failReason);
コード例 #15
0
        public MainWindow()
        {
            InitializeComponent();

            m_switcherMonitor = new SwitcherMonitor();

            m_audioInputMonitor     = new AudioInputMonitor();
            m_mixEffectBlockMonitor = new MixEffectBlockMonitor();
            m_transitionMonitor     = new TransitionMonitor();
            m_dkeyMonitor           = new DownStreamKeyMonitor();

            m_switcherDiscovery = new CBMDSwitcherDiscovery();
            if (m_switcherDiscovery == null)
            {
                MessageBox.Show("Could not create Switcher Discovery Instance.\nATEM Switcher Software may not be installed.", "Error");
                Environment.Exit(1);
            }

            SwitcherDisconnected();             // start with switcher disconnected

            _BMDSwitcherConnectToFailure failReason = 0;
            string address = "192.168.30.8";

            try
            {
                // Note that ConnectTo() can take several seconds to return, both for success or failure,
                // depending upon hostname resolution and network response times, so it may be best to
                // do this in a separate thread to prevent the main GUI thread blocking.
                m_switcherDiscovery.ConnectTo(address, out m_switcher, out failReason);
            }
            catch (COMException)
            {
                // An exception will be thrown if ConnectTo fails. For more information, see failReason.
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    MessageBox.Show("No response from Switcher", "Error");
                    break;

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    MessageBox.Show("Switcher has incompatible firmware", "Error");
                    break;

                default:
                    MessageBox.Show("Connection failed for unknown reason", "Error");
                    break;
                }
                return;
            }

            m_mixEffectBlockMonitor.ProgramInputChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => UpdateProgramButtonSelection())));
            m_mixEffectBlockMonitor.PreviewInputChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => UpdatePreviewButtonSelection())));
            m_mixEffectBlockMonitor.TransitionFramesRemainingChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => UpdateTransitionFramesRemaining())));
            m_mixEffectBlockMonitor.TransitionPositionChanged        += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => UpdateSliderPosition())));
            m_mixEffectBlockMonitor.InTransitionChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => OnInTransitionChanged())));

            m_audioMixerMonitor = new AudioMixerMonitor();
            //m_audioMixerMonitor.ProgramOutBalanceChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioProgramOutBalanceChanged())));
            //m_audioMixerMonitor.ProgramOutGainChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioProgramOutGainChanged())));
            //m_audioMixerMonitor.ProgramOutLevelNotificationChanged += new SwitcherEventHandler((s, a) => this.Invoke((Action)(() => AudioProgramOutLevelNotificationChanged())));

            m_audioOutputMonitor = new AudioMixerMonitorOutputMonitor();
            //m_audioOutputMonitor.DimChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioOutputMonitor.DimLevelChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioOutputMonitor.GainChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioOutputMonitor.LevelNotificationChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioOutputMonitor.MonitorEnableChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioOutputMonitor.MuteChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioOutputMonitor.SoloInputChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloInputChanged())));

            m_audioInputMonitor = new AudioInputMonitor();
            //m_audioInputMonitor.IsMixedInChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloInputChanged())));
            //m_audioInputMonitor.MixOptionChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioInputMonitor.BalanceChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloInputChanged())));
            //m_audioInputMonitor.GainChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioInputMonitor.IsMixedInChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioInputMonitor.LevelNotificationChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));
            //m_audioInputMonitor.MixOptionChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => AudioOutputSoloChanged())));


            //m_transitionMonitor.TransitionStyleChanged += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => OnNextTransitionStyleChanged())));
            //m_dkeyMonitor. += new SwitcherEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => OnNextTransitionStyleChanged())));

            SwitcherConnected();
        }
コード例 #16
0
        public MainWindow()
        {
            InitializeComponent();
            _BMDSwitcherConnectToFailure failReason = 0;

            switcherDiscovery = new CBMDSwitcherDiscovery();
            try
            {
                switcherDiscovery.ConnectTo("10.11.12.21", out switcher, out failReason);
            }
            catch (COMException)
            {
                // An exception will be thrown if ConnectTo fails. For more information, see failReason.
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    MessageBox.Show("No response from Switcher", "Error");
                    break;

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    MessageBox.Show("Switcher has incompatible firmware", "Error");
                    break;

                default:
                    MessageBox.Show("Connection failed for unknown reason", "Error");
                    break;
                }
            }

            mixEffectBlock1 = null;

            IBMDSwitcherMixEffectBlockIterator meIterator = null;
            IntPtr meIteratorPtr;
            Guid   meIteratorIID = typeof(IBMDSwitcherMixEffectBlockIterator).GUID;

            switcher.CreateIterator(ref meIteratorIID, out meIteratorPtr);
            if (meIteratorPtr != null)
            {
                meIterator = (IBMDSwitcherMixEffectBlockIterator)Marshal.GetObjectForIUnknown(meIteratorPtr);
            }

            if (meIterator != null)
            {
                meIterator.Next(out mixEffectBlock1);
            }

            if (mixEffectBlock1 == null)
            {
                MessageBox.Show("Unexpected: Could not get first mix effect block", "Error");
            }

            IBMDSwitcherInput         currentInput  = null;
            IBMDSwitcherInputIterator inputIterator = null;
            IntPtr inputIteratorPtr;
            Guid   inputIteratorIID = typeof(IBMDSwitcherInputIterator).GUID;

            switcher.CreateIterator(ref inputIteratorIID, out inputIteratorPtr);
            if (inputIteratorPtr != null)
            {
                inputIterator = (IBMDSwitcherInputIterator)Marshal.GetObjectForIUnknown(inputIteratorPtr);
            }

            if (inputIterator != null)
            {
                inputIterator.Next(out currentInput);
                while (currentInput != null)
                {
                    MixerInput input = new MixerInput(currentInput);
                    inputList.Add(input);
                    inputIterator.Next(out currentInput);
                }
            }

            mixEffectBlock1.AddCallback(monitor);
            monitor.InTransitionChanged += new MixerMonitorEventHandler((s, a) => this.Dispatcher.Invoke((Action)(() => InTransitionChanged(s, a))));

            indev = new Sanford.Multimedia.Midi.InputDevice(3);
            indev.ChannelMessageReceived += Indev_ChannelMessageReceived;
            indev.StartRecording();

            mappingList.ItemsSource = inputList;
        }
コード例 #17
0
        public void Connect()
        {
            if (this.connected)
            {
                return;
            }

            IBMDSwitcherDiscovery        switcherDiscovery = new CBMDSwitcherDiscovery();
            _BMDSwitcherConnectToFailure failReason        = 0;

            try
            {
                switcherDiscovery.ConnectTo(this.deviceAddress, out this.switcher, out failReason);
                this.connected = true;

                // Get the first Mix Effect block (ME 1).
                m_mixEffectBlock1 = null;

                IBMDSwitcherMixEffectBlockIterator meIterator = null;
                IntPtr meIteratorPtr;
                Guid   meIteratorIID = typeof(IBMDSwitcherMixEffectBlockIterator).GUID;
                switcher.CreateIterator(ref meIteratorIID, out meIteratorPtr);
                if (meIteratorPtr != null)
                {
                    meIterator = (IBMDSwitcherMixEffectBlockIterator)Marshal.GetObjectForIUnknown(meIteratorPtr);
                }

                if (meIterator == null)
                {
                    return;
                }

                if (meIterator != null)
                {
                    meIterator.Next(out m_mixEffectBlock1);
                }

                if (m_mixEffectBlock1 == null)
                {
                    throw new SwitcherLibException("Unexpected: Could not get first mix effect block");
                }

                // Get the second Mix Effect block (ME 2).
                m_mixEffectBlock2 = null;
                if (meIterator != null)
                {
                    meIterator.Next(out m_mixEffectBlock2);
                }
            }
            catch (COMException ex)
            {
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    throw new SwitcherLibException("Incompatible firmware");

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    throw new SwitcherLibException(String.Format("No response from {0}", this.deviceAddress));

                default:
                    throw new SwitcherLibException(String.Format("Unknown Error: {0}", ex.Message));
                }
            }
            catch (Exception ex)
            {
                throw new SwitcherLibException(String.Format("Unable to connect to switcher: {0}", ex.Message));
            }
        }
コード例 #18
0
        public BMDSwitcherManagement(string address)
        {
            //_synchContext = System.Threading.SynchronizationContext.Current;

            m_switcherMonitor = new SwitcherMonitor();
            m_switcherMonitor.SwitcherDisconnected += OnSwitcherDisconnected;


            m_mixEffectBlockMonitor = new MixEffectBlockMonitor();
            m_mixEffectBlockMonitor.ProgramInputChanged += OnProgramInputChanged;

            m_switcherDiscovery = new CBMDSwitcherDiscovery();

            if (m_switcherDiscovery == null)
            {
                return;
            }

            _BMDSwitcherConnectToFailure failReason = 0;

            try
            {
                // Note that ConnectTo() can take several seconds to return, both for success or failure,
                // depending upon hostname resolution and network response times, so it may be best to
                // do this in a separate thread to prevent the main GUI thread blocking.
                m_switcherDiscovery.ConnectTo(address, out m_switcher, out failReason);
            }
            catch (COMException)
            {
                // An exception will be thrown if ConnectTo fails. For more information, see failReason.
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    //MessageBox.Show("No response from Switcher", "Error");
                    break;

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    //MessageBox.Show("Switcher has incompatible firmware", "Error");
                    break;

                default:
                    //MessageBox.Show("Connection failed for unknown reason", "Error");
                    break;
                }
                return;
            }

            // Get the switcher name:
            string switcherName;

            m_switcher.GetProductName(out switcherName);
            _switcherName = switcherName;


            // Install SwitcherMonitor callbacks:
            m_switcher.AddCallback(m_switcherMonitor);

            m_switcher.IterateInput((i) =>
            {
                InputMonitor newInputMonitor = new InputMonitor(i);

                i.AddCallback(newInputMonitor);
                newInputMonitor.LongNameChanged += new SwitcherEventHandler(OnInputLongNameChanged);
                m_inputMonitors.Add(newInputMonitor);
            });

            // We want to get the first Mix Effect block (ME 1). We create a ME iterator,
            // and then get the first one:
            m_mixEffectBlock1 = m_switcher.GetFirstMixEffectBlock();

            if (m_mixEffectBlock1 != null)
            {
                m_mixEffectBlock1.AddCallback(m_mixEffectBlockMonitor);
                UpdatePrograms();
                this.Connected = true;
            }

            m_audioMixer = m_switcher.GetBMDSwitcherAudioMixer();

            m_audioMixer.IterateAudioInput(i => { _audioInputs.Add(i); });
        }
コード例 #19
0
        private void Run()
        {
            m_switcherDiscovery = new CBMDSwitcherDiscovery();
            if (m_switcherDiscovery == null)
            {
                WaitForExit("Could not create Switcher Discovery Instance.\nATEM Switcher Software may not be installed.");
                return;
            }

            _BMDSwitcherConnectToFailure failReason = 0;
            string address = "10.42.13.99";

            try
            {
                // Note that ConnectTo() can take several seconds to return, both for success or failure,
                // depending upon hostname resolution and network response times, so it may be best to
                // do this in a separate thread to prevent the main GUI thread blocking.
                m_switcherDiscovery.ConnectTo(address, out m_switcher, out failReason);
            }
            catch (COMException)
            {
                // An exception will be thrown if ConnectTo fails. For more information, see failReason.
                switch (failReason)
                {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    WaitForExit("No response from Switcher");
                    break;

                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    WaitForExit("Switcher has incompatible firmware");
                    break;

                default:
                    WaitForExit("Connection failed for unknown reason");
                    break;
                }
                return;
            }

            Console.WriteLine("Connected");


            m_mediaPool = m_switcher as IBMDSwitcherMediaPool;
            if (m_mediaPool == null)
            {
                WaitForExit("Failed to cast to media pool");
                return;
            }


            m_mediaPool.CreateFrame(_BMDSwitcherPixelFormat.bmdSwitcherPixelFormat10BitYUVA, 1920, 1080, out IBMDSwitcherFrame frame);
            if (frame == null)
            {
                WaitForExit("Failed to create frame");
                return;
            }

            frame.GetBytes(out IntPtr buffer);
            byte[] frameData = RandomFrame();
            Marshal.Copy(frameData, 0, buffer, 1920 * 1080 * 4);

            Stopwatch sw = new Stopwatch();

            uint max_index = 32;
            uint index     = 0;

            while (true)
            {
                sw.Restart();
                UploadStillSdk(index % max_index, "frame " + index, frame);
                sw.Stop();

                Console.WriteLine("Upload outer #{0} took {1}ms", index, sw.ElapsedMilliseconds);

                Thread.Sleep(100);

                index++;
            }


            // End
            WaitForExit();
        }