- Posts: 4
- Joined: Fri Aug 26, 2016 8:08 pm
Hi,
I'm still trying to get a preview video stream in C#, but am in the same place with the DirectX PreviewHelper (IDeckLinkDX9ScreenPreviewHelper) as I am with the GL Helper (viewtopic.php?f=12&t=51423&sid=a7550db6d8f9f8ae3712923afa9f67bb#p297128).
I've got a DX9 sample together (using SharpDX), but it just shows a black window. The sample for that is below.
Interestingly, however, if I draw a white triangle on the dx scene, then it will show both the target rect and the triangle with a color that's currently in the feed (image attached) which will change as the source changes, though is still only a single color from the feed. Can attach code for that too, in case it's helpful.
Would be very appreciative of any pointers on this path or to see any functional video output from the card through C# (the DirectShow example crashes the system it's run on, so that path unfortunately isn't open). If it just won't work in C# though, knowing that would help me too.
Thanks,
Andrew
I'm still trying to get a preview video stream in C#, but am in the same place with the DirectX PreviewHelper (IDeckLinkDX9ScreenPreviewHelper) as I am with the GL Helper (viewtopic.php?f=12&t=51423&sid=a7550db6d8f9f8ae3712923afa9f67bb#p297128).
I've got a DX9 sample together (using SharpDX), but it just shows a black window. The sample for that is below.
Interestingly, however, if I draw a white triangle on the dx scene, then it will show both the target rect and the triangle with a color that's currently in the feed (image attached) which will change as the source changes, though is still only a single color from the feed. Can attach code for that too, in case it's helpful.
Would be very appreciative of any pointers on this path or to see any functional video output from the card through C# (the DirectShow example crashes the system it's run on, so that path unfortunately isn't open). If it just won't work in C# though, knowing that would help me too.
Thanks,
Andrew
- Code: Select all
class simpleBMDXTest : IDeckLinkInputCallback, IDeckLinkScreenPreviewCallback
{
private IDeckLink m_deckLink;
private IDeckLinkInput m_deckLinkInput;
private Device device;
private RenderForm form;
private Direct3D direct3D;
public static IDeckLinkDX9ScreenPreviewHelper m_DeckLinkDX9ScreenPreviewHelper;
private int frameCount = 0;
private bool dxInitialized;
public unsafe simpleBMDXTest()
{
InitializeBlackMagicDevice();
PresentParameters pp = new PresentParameters()
{
BackBufferFormat = Format.Unknown,
BackBufferCount = 2,
Windowed = true,
SwapEffect = SwapEffect.Discard,
PresentationInterval = PresentInterval.Default
};
m_DeckLinkDX9ScreenPreviewHelper = new CDeckLinkDX9ScreenPreviewHelper();
direct3D = new Direct3D();
form = new RenderForm("BlackMagic DX9 Render Test Form");
form.Size = new Size(650, 650);
device = new Device(direct3D, 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded, pp);
device.Viewport = new RawViewport() { Height = 650, Width = 650, X = 0, Y = 0 };
m_DeckLinkDX9ScreenPreviewHelper.Initialize((IntPtr)device.NativePointer);
var ptr = device.NativePointer;
Console.WriteLine(ptr);
var tagRect = new tagRECT()
{
top = 10,
left = 10,
right = 400,
bottom = 400
};
RenderLoop.Run(form, () =>
{
device.BeginScene();
m_DeckLinkDX9ScreenPreviewHelper.Render(tagRect);
device.EndScene();
device.Present();
});
device.Dispose();
direct3D.Dispose();
}
private void InitializeBlackMagicDevice()
{
IDeckLink m_deckLink;
IDeckLinkIterator deckLinkIterator = new CDeckLinkIterator();
deckLinkIterator.Next(out m_deckLink);
m_deckLinkInput = (IDeckLinkInput)m_deckLink;
m_deckLinkInput.SetScreenPreviewCallback(this);
m_deckLinkInput.EnableVideoInput(_BMDDisplayMode.bmdModeHD720p5994, _BMDPixelFormat.bmdFormat8BitYUV, _BMDVideoInputFlags.bmdVideoInputFlagDefault);
m_deckLinkInput.StartStreams();
}
void IDeckLinkScreenPreviewCallback.DrawFrame(IDeckLinkVideoFrame theFrame)
{
m_DeckLinkDX9ScreenPreviewHelper.SetFrame(theFrame);
System.Runtime.InteropServices.Marshal.ReleaseComObject(theFrame);
}
void IDeckLinkInputCallback.VideoInputFrameArrived(IDeckLinkVideoInputFrame video, IDeckLinkAudioInputPacket audio)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(video);
}
void IDeckLinkInputCallback.VideoInputFormatChanged(_BMDVideoInputFormatChangedEvents e, IDeckLinkDisplayMode m, _BMDDetectedVideoInputFormatFlags f)
{
}
}
- Attachments
-
- blackmagic-directx.png (5.08 KiB) Viewed 4671 times
Andrew Singer