コード例 #1
0
ファイル: Program.cs プロジェクト: yuka800/SimpleUnityBrowser
        /// <summary>
        /// App constructor
        /// </summary>
        /// <param name="worker">Main CEF worker</param>
        /// <param name="memServer">Shared memory file</param>
        /// <param name="commServer">TCP server</param>
        // public App(CefWorker worker, SharedMemServer memServer, SocketServer commServer,bool enableWebRtc)
        public App(CefWorker worker, SharedMemServer memServer, SharedCommServer inServer, SharedCommServer outServer, bool enableWebRtc)
        {
            //    _renderProcessHandler = new WorkerCefRenderProcessHandler();
            _enableWebRtc = enableWebRtc;

            _memServer  = memServer;
            _mainWorker = worker;
            //init SharedMem comms
            _inCommServer  = inServer;
            _outCommServer = outServer;

            _mainWorker.SetMemServer(_memServer);

            //attach dialogs and queries
            _mainWorker.OnJSDialog       += _mainWorker_OnJSDialog;
            _mainWorker.OnBrowserJSQuery += _mainWorker_OnBrowserJSQuery;

            //attach page events
            _mainWorker.OnPageLoaded += _mainWorker_OnPageLoaded;



            IsRunning = true;

            _exitTimer          = new Timer();
            _exitTimer.Interval = 10000;
            _exitTimer.Tick    += _exitTimer_Tick;
            _exitTimer.Start();
        }
コード例 #2
0
 public void SetMemServer(SharedMemServer memServer)
 {
     _renderHandler._memServer = memServer;
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: yuka800/SimpleUnityBrowser
        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);
        }
コード例 #4
0
 public void SetMemServer(SharedMemServer memServer)
 {
     _client.SetMemServer(memServer);
 }