Esempio n. 1
0
        static void Main()
        {
            MediaToolkitManager.Startup();

            //DwmApi.DisableAero(true);
            Shcore.SetProcessPerMonitorDpiAwareness();

            WinMM.timeBeginPeriod(1);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form2());

            WinMM.timeEndPeriod(1);
        }
Esempio n. 2
0
        protected override void OnClosed(EventArgs e)
        {
            if (deckLinkInput != null)
            {
                deckLinkInput.AudioDataArrived -= CurrentDevice_AudioDataArrived;
                deckLinkInput.VideoDataArrived -= CurrentDevice_VideoDataArrived;

                deckLinkInput.StopCapture();
            }

            if (renderSession != null)
            {
                renderSession.Close();
                renderSession = null;
            }

            MediaToolkitManager.Shutdown();

            base.OnClosed(e);
        }
Esempio n. 3
0
        public static int Main(string[] args)
        {
            int exitCode = 0;

            InitLogger();

            logger.Info("============================ START ============================");

            bool  createdNew = false;
            Mutex mutex      = null;

            try
            {
                mutex = new Mutex(true, AppConsts.ApplicationId, out createdNew);
                if (!createdNew)
                {
                    logger.Info("Another instance is already running...");
                    if (!Models.AppModel.AllowMutipleInstance)
                    {
                        var res = Services.WndProcService.ShowAnotherInstance();
                        return(0);

                        //return -1;
                        //...
                    }
                }

                StartupParams = StartupParameters.Create(args);

                logger.Info(StartupParams.GetSysInfo());

                try
                {
                    MediaToolkitManager.Startup();

                    Shcore.SetProcessPerMonitorDpiAwareness();

                    var application = new App();
                    application.DispatcherUnhandledException += Application_DispatcherUnhandledException;
                    application.InitializeComponent();

                    logger.Info("============================ RUN ============================");
                    application.Run();
                }
                finally
                {
                    MediaToolkitManager.Shutdown();
                }
            }
            catch (Exception ex)
            {
                ProcessError(ex);
            }
            finally
            {
                if (mutex != null)
                {
                    if (createdNew)
                    {
                        mutex.ReleaseMutex();
                    }
                    mutex.Dispose();
                }

                logger.Info("============================ THE END ============================");
            }


            return(exitCode);
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            MediaToolkitManager.Startup();


            var _flags = DeviceCreationFlags.VideoSupport |
                         DeviceCreationFlags.BgraSupport |
                         DeviceCreationFlags.Debug;

            var _device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, _flags);


            using (var multiThread = _device.QueryInterface <SharpDX.Direct3D11.Multithread>())
            {
                multiThread.SetMultithreadProtected(true);
            }
            var featureLevel = _device.FeatureLevel;

            using (var dxgiDevice = _device.QueryInterface <SharpDX.DXGI.Device>())
            {
                using (var adapter = dxgiDevice.Adapter)
                {
                    var descr = adapter.Description;
                    Console.WriteLine(string.Join(" ", descr.Description));
                }
            }

            Console.WriteLine(DxTool.LogDxInfo());

            Console.ReadKey();
            return;

            // NewMethod1();



            ////DxTool.FindAdapter1(4313);

            var videoEncoders = MfTool.FindVideoEncoders();

            foreach (var enc in videoEncoders)
            {
                Console.WriteLine(enc.ToString());
            }


            foreach (var enc in videoEncoders)
            {
                if (enc.Format == VideoCodingFormat.H264 && enc.Activatable)
                {
                    Console.WriteLine(enc.Name + " " + enc.ClsId + " isHardware: " + enc.IsHardware);
                }
            }

            Console.ReadKey();
            Console.WriteLine("-------------------------------");
            return;


            //NewMethod();


            //return;



            //MarshalHelper.ToArray(ppOutputTypes, (int)inputTypesNum, out MFTRegisterTypeInfo[] outputTypes);

            //MediaAttributes mediaAttributes = new MediaAttributes(ppAttributes);


            //Console.WriteLine(MfTool.LogMediaAttributes(mediaAttributes));



            //Guid VideoProcessorMFT = new Guid("88753B26-5B24-49BD-B2E7-0C445C78C982");

            //SharpDX.MediaFoundation.MediaFactory.TGetInfo(VideoProcessorMFT, IntPtr.Zero,
            //	null, out int cInputTypesRef,
            //	null, out int cOutputTypesRef,
            //	out SharpDX.MediaFoundation.MediaAttributes attrs);


            //var transformFlags = TransformEnumFlag.All | // TransformEnumFlag.All |
            //		 TransformEnumFlag.SortAndFilter;

            //var outputType = new TRegisterTypeInformation
            //{
            //	GuidMajorType = MediaTypeGuids.Video,
            //	GuidSubtype = VideoFormatGuids.H264
            //	// GuidSubtype = VideoFormatGuids.Hevc
            //};
            //var category = SharpDX.MediaFoundation.TransformCategoryGuids.VideoDecoder;
            //MediaAttributes mediaAttributes = new MediaAttributes();
            //Activate[] activates = new Activate[1024];

            //SharpDX.MediaFoundation.MediaFactory.TEnum2(category, (int)transformFlags, null, outputType, mediaAttributes, activates, out int activatesNum);



            var flags = DeviceCreationFlags.VideoSupport |
                        DeviceCreationFlags.BgraSupport |
                        DeviceCreationFlags.Debug;

            var device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, flags);

            using (var multiThread = device.QueryInterface <SharpDX.Direct3D11.Multithread>())
            {
                multiThread.SetMultithreadProtected(true);
            }


            //var descr = new SharpDX.Direct3D11.Texture2DDescription
            //{
            //	Width = 1920,
            //	Height = 1080,
            //	MipLevels = 1,
            //	ArraySize = 1,
            //	SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
            //	Usage = SharpDX.Direct3D11.ResourceUsage.Default,
            //	Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
            //	BindFlags = SharpDX.Direct3D11.BindFlags.ShaderResource,
            //	CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None,
            //	OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None,

            //};

            //var texture = new SharpDX.Direct3D11.Texture2D(device, descr);


            var bmp     = new System.Drawing.Bitmap(@"D:\Temp\4.bmp");
            var texture = DxTool.GetTexture(bmp, device);

            //Texture2D stagingTexture = null;
            //try
            //{
            //    // Create Staging texture CPU-accessible
            //    stagingTexture = new Texture2D(device,
            //        new Texture2DDescription
            //        {
            //            CpuAccessFlags = CpuAccessFlags.Read,
            //            BindFlags = BindFlags.None,
            //            Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
            //            Width = 1920,
            //            Height = 1080,
            //            MipLevels = 1,
            //            ArraySize = 1,
            //            SampleDescription = { Count = 1, Quality = 0 },
            //            Usage = ResourceUsage.Staging,
            //            OptionFlags = ResourceOptionFlags.None,
            //        });

            //    device.ImmediateContext.CopyResource(texture, stagingTexture);
            //    device.ImmediateContext.Flush();

            //    //var destBmp = new System.Drawing.Bitmap(1920, 1080, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            //    System.Drawing.Bitmap destBmp = null;
            //    int count = 10;

            //    byte[] bytes = null;
            //    while (count-- > 0)
            //    {
            //        DxTool.TextureToBitmap(stagingTexture, ref destBmp);

            //        bytes = DxTool.GetTextureBytes(stagingTexture);



            //        Thread.Sleep(10);
            //    }

            //    File.WriteAllBytes("d:\\test_argb32.raw", bytes);

            //    destBmp.Save("d:\\test.bmp");

            //    destBmp.Dispose();

            //}
            //finally
            //{
            //    stagingTexture?.Dispose();
            //}

            //texture.Dispose();
            //device.Dispose();
            //bmp.Dispose();

            //var report = SharpDX.Diagnostics.ObjectTracker.ReportActiveObjects();
            //Console.WriteLine(report);
            //Console.ReadKey();


            //return;



            //var flags = DeviceCreationFlags.VideoSupport |
            //     DeviceCreationFlags.BgraSupport;
            ////DeviceCreationFlags.Debug;

            //var device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, flags);
            //using (var multiThread = device.QueryInterface<SharpDX.Direct3D11.Multithread>())
            //{
            //    multiThread.SetMultithreadProtected(true);
            //}



            do
            {
                // var videoSource = new ScreenSource();
                // ScreenCaptureDeviceDescription captureParams = new ScreenCaptureDeviceDescription
                // {
                //     CaptureRegion = new System.Drawing.Rectangle(0, 0, 1920, 1080),
                //     Resolution = new System.Drawing.Size(1920, 1080),
                // };

                // captureParams.CaptureType = VideoCaptureType.DXGIDeskDupl;
                // captureParams.Fps = 10;
                // captureParams.CaptureMouse = true;

                // videoSource.Setup(captureParams);

                // VideoEncoderSettings encodingParams = new VideoEncoderSettings
                // {
                //     //Width = destSize.Width, // options.Width,
                //     //Height = destSize.Height, // options.Height,
                //     Resolution = new System.Drawing.Size(1920, 1080),
                //     FrameRate = 10,


                // };

                // //var videoEncoder = new VideoEncoder(videoSource);
                // //videoEncoder.Open(encodingParams);
                // var hwBuffer = videoSource.SharedTexture;
                // var hwDevice = hwBuffer.Device;

                // using (var dxgiDevice = hwDevice.QueryInterface<SharpDX.DXGI.Device>())
                // {
                //     using (var adapter = dxgiDevice.Adapter)
                //     {
                //         var adapterLuid = adapter.Description.Luid;
                //     }
                // }
                //// hwDevice.Dispose();
                // // Marshal.Release(hwDevice.NativePointer);

                // //ComObject comObject = new ComObject();
                // //comObject.

                //var flags = DeviceCreationFlags.VideoSupport |
                //    DeviceCreationFlags.BgraSupport;
                ////DeviceCreationFlags.Debug;

                //var device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, flags);
                //using (var multiThread = device.QueryInterface<SharpDX.Direct3D11.Multithread>())
                //{
                //    multiThread.SetMultithreadProtected(true);
                //}


                var encoder = new MfH264Encoder(null);
                encoder.Setup(new MfVideoArgs
                {
                    Width     = 1920,
                    Height    = 1080,
                    FrameRate = 30,
                    Format    = SharpDX.MediaFoundation.VideoFormatGuids.Argb32,
                });

                var encDevice = encoder.device;


                var bufTexture = new Texture2D(encDevice,
                                               new Texture2DDescription
                {
                    // Format = Format.NV12,
                    Format            = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                    Width             = 1920,
                    Height            = 1080,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    SampleDescription = { Count = 1 },
                });



                //var processor = new MfVideoProcessor(encDevice);
                //var inProcArgs = new MfVideoArgs
                //{
                //    Width = 1920,
                //    Height = 1080,
                //    Format = SharpDX.MediaFoundation.VideoFormatGuids.Argb32,
                //};

                //var outProcArgs = new MfVideoArgs
                //{
                //    Width = 1920,
                //    Height = 1080,
                //    Format = SharpDX.MediaFoundation.VideoFormatGuids.NV12,//.Argb32,
                //};

                //processor.Setup(inProcArgs, outProcArgs);
                //processor.Start();

                encoder.Start();

                int count = 3;
                while (count-- > 0)
                {
                    //encDevice.ImmediateContext.CopyResource(texture, bufTexture);

                    //encoder.WriteTexture(texture);

                    Thread.Sleep(100);

                    Console.WriteLine("Try next " + count);
                }

                encoder.Stop();


                //processor.Stop();
                //processor.Close();

                bufTexture.Dispose();
                texture.Dispose();
                // videoEncoder.Close();



                //videoSource.Close();
                //hwDevice.Dispose();

                //Console.WriteLine(MfTool.GetActiveObjectsReport());

                Thread.Sleep(300);
                //encoder.Close();
                GC.Collect();

                Console.WriteLine("----------------------------------------\r\n" + MfTool.GetActiveObjectsReport());
                Console.WriteLine("Spacebar to next...");
                var key = Console.ReadKey();

                if (key.Key == ConsoleKey.Spacebar)
                {
                    continue;
                }
                else
                {
                    break;
                }
            } while (true);

            Console.WriteLine("Any key to exit...");
            Console.ReadKey();

            MediaToolkitManager.Shutdown();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            InitLogger();

            logger.Info("========== START ============");
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            StartupParams = StartupParameters.Create(args);

            //if (StartupParams.RunAsSystem)
            //{
            //    if (StartupParams.IsElevated)
            //    {
            //        if (RestartAsSystem() > 0)
            //        {
            //            return;
            //        }
            //        logger.Warn("Restart failed...");
            //    }
            //    else
            //    {
            //        RunAsSystem();
            //    }
            //}

            if (StartupParams.IsElevated)
            {
                if (!StartupParams.NoRestart)
                {//Restart application with system permissions...
                    if (RestartAsSystem() > 0)
                    {
                        return;
                    }
                    logger.Warn("Restart failed...");
                    // открываем процесс как обычно...
                    //TODO:...
                }
            }



            bool  createdNew = false;
            Mutex mutex      = null;

            try
            {
                mutex = new Mutex(true, AppConsts.ApplicationId, out createdNew);
                if (!createdNew)
                {
                    logger.Info("Another instance is already running...");
                    //...
                }



                bool tempMode = !createdNew;
                Config.Initialize(tempMode);

                MediaToolkitManager.Startup();


                //DwmApi.DisableAero(true);
                Shcore.SetProcessPerMonitorDpiAwareness();

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                MainForm form = new MainForm();

                logger.Info("========== RUN ============");
                Application.Run(form);
            }
            finally
            {
                Config.Shutdown();

                MediaToolkitManager.Shutdown();

                if (mutex != null)
                {
                    if (createdNew)
                    {
                        mutex.ReleaseMutex();
                    }
                    mutex.Dispose();
                }

                logger.Info("========== THE END ============");
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            //Console.Title = "App started...";

            logger = LogManager.GetCurrentClassLogger();

            logger.Info("========== START ============");
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            bool  createdNew = false;
            Mutex mutex      = null;

            try
            {
                //mutex = new Mutex(true, AppConsts.ApplicationId, out createdNew);
                //if (!createdNew)
                //{
                //    logger.Info("Another instance is already running...");
                //    //...
                //}

                if (args != null && args.Length > 0)
                {//...
                }

                bool tempMode = !createdNew;
                //ScreenStreamer.WinForms.App.Config.Initialize(tempMode);

                MediaToolkitManager.Startup();

                //DwmApi.DisableAero(true);
                Shcore.SetProcessPerMonitorDpiAwareness();

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);



                //var screen0 =  Screen.AllScreens[0];
                ////var bound0 = SystemInformation.VirtualScreen;//screen0.Bounds;//new System.Drawing.Rectangle(10, 10, 100, 100); //
                ////var bound0 = screen0.Bounds;//new System.Drawing.Rectangle(10, 10, 100, 100); //

                //var bound0 = new System.Drawing.Rectangle(10, 10, 100, 100); //
                //var src0 = new ScreenSource();
                //var capture0 = new ScreenCaptureDevice
                //{
                //    CaptureRegion = bound0,
                //    Resolution = bound0.Size,
                //    Name = screen0.DeviceName,
                //    DisplayRegion = bound0,
                //    Properties = new ScreenCaptureProperties
                //    {
                //        UseHardware = true,
                //        CaptureType = VideoCaptureType.DXGIDeskDupl,
                //        AspectRatio = true,
                //        Fps = 30,

                //    }
                //};

                //src0.Setup(capture0);
                //src0.Start();


                //var screen1 = Screen.AllScreens[1];

                ////var bound1 = screen1.Bounds;//new System.Drawing.Rectangle(-1920, 10, 10, 10); //

                //var bound1 = new System.Drawing.Rectangle(-1920, 10, 10, 10); //
                //var capture1 = new ScreenCaptureDevice
                //{
                //    CaptureRegion = bound1,
                //    Resolution = bound1.Size,
                //    Name = screen1.DeviceName,
                //    DisplayRegion = bound1,
                //    Properties = new ScreenCaptureProperties
                //    {
                //        UseHardware = true,
                //        CaptureType = VideoCaptureType.DXGIDeskDupl,
                //        AspectRatio = true,
                //        Fps = 30,

                //    }
                //};

                //var src1 = new ScreenSource();
                //src1.Setup(capture1);
                //src1.Start();



                //ScreenStreamer.WinForms.App.MainForm form = new ScreenStreamer.WinForms.App.MainForm();

                MainForm form = new MainForm();



                Application.Run(form);
            }
            finally
            {
                // ScreenStreamer.WinForms.App.Config.Shutdown();

                MediaToolkitManager.Shutdown();

                if (mutex != null)
                {
                    if (createdNew)
                    {
                        mutex.ReleaseMutex();
                    }
                    mutex.Dispose();
                }



                logger.Info("========== THE END ============");
            }
        }