private void ShowVideoForm(string title) { if (testForm == null || testForm.IsDisposed) { testForm = new VideoForm { StartPosition = FormStartPosition.CenterParent, Width = 1280, Height = 720, Text = title, }; imageProvider?.Close(true); imageProvider = new D3DImageRenderer(); var reciver = remoteClient.VideoReceiver; imageProvider.Setup(reciver.sharedTexture); imageProvider.Start(); var video = testForm.userControl11; video.DataContext = imageProvider; testForm.FormClosed += TestForm_FormClosed; } testForm.Visible = true; }
static void Main(string[] args) { Console.WriteLine("==============START============="); try { MediaToolkitManager.Startup(); //SharpDX.MediaFoundation.DirectX.VideoProcessorService videoProcessorService = new SharpDX.MediaFoundation.DirectX.VideoProcessorService(IntPtr.Zero); //videoProcessorService.GetVideoProcessorCaps() //EnumerateCaptureSources(); //Console.ReadKey(); //return; var device = GetVideoCaptureDevices(); var d = device[0]; VideoCaptureSource videoCaptureSource = new VideoCaptureSource(); UvcDevice captureParams = new UvcDevice { Resolution = new GDI.Size(1920, 1080), DeviceId = d.SymLink, }; videoCaptureSource.Setup(captureParams); PreviewForm previewForm = null; D3DImageRenderer provider = null; var uiThread = new Thread(() => { provider = new D3DImageRenderer(); provider.Setup(videoCaptureSource.SharedTexture); previewForm = new PreviewForm(); previewForm.d3DImageControl1.DataContext = provider; previewForm.Show(); provider.Start(); Application.Run(); }); uiThread.IsBackground = true; uiThread.SetApartmentState(ApartmentState.STA); Console.WriteLine("Any key to start..."); Console.ReadKey(); uiThread.Start(); videoCaptureSource.BufferUpdated += () => { provider?.Update(); }; videoCaptureSource.Start(); Console.ReadKey(); Console.WriteLine("Any key to stop..."); videoCaptureSource.Stop(); videoCaptureSource.Close(); Console.WriteLine(SharpDX.Diagnostics.ObjectTracker.ReportActiveObjects()); MediaToolkitManager.Shutdown(); //MediaManager.Shutdown(); //previewForm?.Close(); } catch (Exception ex) { Console.WriteLine(ex); } Console.WriteLine("==============THE END============="); Console.WriteLine("Any key to quit..."); Console.ReadKey(); }