Beispiel #1
0
        private void InitComm()
        {
            //Read
            _inServer = new SharedCommServer(false);
            //Write
            _outServer = new SharedCommServer(true);

            _inServer.InitComm(inCommFileSize, _inSharedCommFile);
            _outServer.InitComm(outCommFileSize, _outSharedCommFile);

            //开启读取线程
            Action serverRead = () =>
            {
                EventPacket ep;
                while (true)
                {
                    ep = _inServer.GetMessage();
                    if (ep != null)
                    {
                        //把获取到的信息直接发送到浏览器中
                        Console.WriteLine("Message From Unity:" + ep.eventValue);
                        _browser.ExecuteScriptAsync("DisplayValue", ep.eventValue);
                    }

                    //Console.WriteLine("serverRead!!");

                    //没那么频繁、可以调节
                    Thread.Sleep(200);
                }
            };


            // ThreadPool.QueueUserWorkItem((o) => { serverWrite(); });
            ThreadPool.QueueUserWorkItem((o) => { serverRead(); });
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            log.Info("===============START================");

            //////// CEF RUNTIME
            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                log.ErrorFormat("{0} error", ex.Message);
            }
            catch (CefRuntimeException ex)
            {
                log.ErrorFormat("{0} error", ex.Message);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("{0} error", ex.Message);
            }



            int    defWidth    = 1280;
            int    defHeight   = 720;
            string defUrl      = "http://test.webrtc.org";
            string defFileName = "MainSharedMem";

            string defInFileName  = "InSharedMem";
            string defOutFileName = "OutSharedMem";

            bool useWebRTC = false;

            bool EnableGPU = false;

            if (args.Length > 0 && args[0] != "--type=renderer")
            {
                if (args.Length > 1)
                {
                    defWidth  = Int32.Parse(args[0]);
                    defHeight = Int32.Parse(args[1]);
                }
                if (args.Length > 2)
                {
                    defUrl = args[2];
                }
                if (args.Length > 3)
                {
                    defFileName = args[3];
                }
                if (args.Length > 4)
                {
                    defInFileName = args[4];
                }
                if (args.Length > 5)
                {
                    defOutFileName = args[5];
                }
                if (args.Length > 6)
                {
                    if (args[6] == "1")
                    {
                        useWebRTC = true;
                    }
                }
                if (args.Length > 7)
                {
                    if (args[7] == "1")
                    {
                        EnableGPU = true;
                    }
                }
            }

            log.InfoFormat("Starting plugin, settings:width:{0},height:{1},url:{2},memfile:{3},inMem:{4},outMem:{5}, WebRtc:{6},Enable GPU:{7}",
                           defWidth, defHeight, defUrl, defFileName, defInFileName, defOutFileName, useWebRTC, EnableGPU);

            try
            {
                CefMainArgs cefMainArgs;
                cefMainArgs = new CefMainArgs(args);
                var cefApp = new WorkerCefApp(useWebRTC, EnableGPU);



                int exit_code = CefRuntime.ExecuteProcess(cefMainArgs, cefApp, IntPtr.Zero);

                if (exit_code >= 0)
                {
                    log.ErrorFormat("CefRuntime return " + exit_code);
                    return(exit_code);
                }
                var cefSettings = new CefSettings
                {
                    SingleProcess              = false,
                    MultiThreadedMessageLoop   = true,
                    WindowlessRenderingEnabled = true,
                    LogSeverity = CefLogSeverity.Info,
                };



                try
                {
                    CefRuntime.Initialize(cefMainArgs, cefSettings, cefApp, IntPtr.Zero);
                }
                catch (CefRuntimeException ex)
                {
                    log.ErrorFormat("{0} error", ex.Message);
                }
                /////////////
            }
            catch (Exception ex)
            {
                log.Info("EXCEPTION ON CEF INITIALIZATION:" + ex.Message + "\n" + ex.StackTrace);
                throw;
            }



            CefWorker worker = new CefWorker();

            worker.Init(defWidth, defHeight, defUrl);

            SharedMemServer server = new SharedMemServer();

            server.Init(defWidth * defHeight * 4, defFileName);



            SharedCommServer inSrv = new SharedCommServer(false);

            //TODO: the sizes may vary, but 10k should be enough?
            inSrv.InitComm(10000, defInFileName);

            SharedCommServer outSrv = new SharedCommServer(true);

            outSrv.InitComm(10000, defOutFileName);

            var app = new App(worker, server, inSrv, outSrv, false);


            while (app.IsRunning)
            {
                Application.DoEvents();
                //check incoming messages and push outcoming
                app.CheckMessage();
            }


            CefRuntime.Shutdown();

            return(0);
        }