Casting to IBMDStreamingDeviceInput throws InvalidCastExcept

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

Masaaki Sato

  • Posts: 2
  • Joined: Tue Dec 29, 2015 7:05 am

Casting to IBMDStreamingDeviceInput throws InvalidCastExcept

PostThu Jan 14, 2016 2:30 am

I'm trying to use H.264ProRecorder and capture image data by using C sharp Form application
But I got InvalidCastExeption when casting IDeckLink instance object to IBMDStreamingDeviceInput as follows.
Could you suggest me what is the proper way to do it?

Here's my minimum code

Code: Select all

using System;
using System.Windows.Forms;
using DeckLinkAPI

namespace Test
{
   public partial class Form1 : Form, IBMDStreamingDeviceNotifiationCallback
   {
      private IDeckLink device;
      private CBMDStreamingDiscovery discovery;

      public Form1()
      {
         InitializeComponent();
         this.discovery = new CBMDStreamingDiscovery();
         this.discovery.InstallDeviceNotification(this);
      }

      private void button_start_Click(object sender, EventArgs e)
      {
         // this line throws InvalidCastException (HRESULT 0x80004002)
         var input = (IBMDStreamingDeviceInput)this.device;
         input.StartCapture();
      }

      public void StreamingDeviceArrived(IDeckLink device)
      {
         this.device = device;
      }

      public void StreamingDeviceModeChanged(IDeckLink device, _BMDStreamingDeviceMode mode)
      {
      }

      public void StreamingDeviceRemoved(IDeckLink device)
      {
      }
   }
}




Somehow starting it by MTA or casting to it by another thread (not main thread) doesn't throw any Exception. Is this a best solution?

Software:::::Visual Studio 2013 Professional, .Net framework 4.5, Visual C# Form Appication
Environment:::::Windows 7 Professional 64bit, Intel(R) Core(TM) i7-4470/3.4GHz, RAN16GB
Offline

Nicholas Gill

Blackmagic Design

  • Posts: 169
  • Joined: Mon May 04, 2015 10:28 pm

Re: Casting to IBMDStreamingDeviceInput throws InvalidCastEx

PostThu Jan 21, 2016 3:46 am

Hi Masaaki,

As you have identified, the DeckLink API requires a multithreaded apartment (MTAThread).

I recommend that the processing be performed on a different thread and the main thread left as STAThread, as WinForms generally requires a single threaded apartment.

Cheers,

-nick

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 33 guests