Пример #1
0
        /*
         * private static void SetOneLedToColor(byte[] buffer, int ledIndex, Color color)
         * {
         *  int bufferIndex = colorBits * ledIndex + headerBits;
         *  SetBufferColorAt(buffer, bufferIndex, color);
         * }
         *
         * private static void SetAllLedsToColor(byte[] buffer, Color color)
         * {
         *
         *  for (int bufferIndex = headerBits; bufferIndex < buffer.Length; bufferIndex += colorBits)
         *  {
         *      SetBufferColorAt(buffer, bufferIndex, color);
         *  }
         *
         * }
         *
         *
         * private static void SetBufferColorAt(byte[] buffer, int bufferIndex, Color color)
         * {
         *  buffer[bufferIndex++] = gammaTable[color.G];
         *  buffer[bufferIndex++] = gammaTable[color.R];
         *  buffer[bufferIndex++] = gammaTable[color.B];
         * }
         */



        private static void ConnectMirrorDriver()
        {
            if (_mirror.Load())
            {
                _mirror.Connect();
            }
            else
            {
                Debug.WriteLine("Error Loading Ambience.");
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            DesktopMirror _mirror = new DesktopMirror();

            _mirror.Load();
            _mirror.Connect();
            long now = System.DateTime.Now.Ticks / 10000;

            while (true)
            {
                now = System.DateTime.Now.Ticks / 10000;
                List <Bitmap> changes = _mirror.getDifference();
                // List<Bitmap> changes= new List<Bitmap>();
                //  changes.Add(_mirror.GetScreen());
                foreach (Bitmap change in changes)
                {
                    System.IO.MemoryStream m = new System.IO.MemoryStream();
                    change.Save(m, System.Drawing.Imaging.ImageFormat.Png);
                    change.Save("d:\\abc.png", System.Drawing.Imaging.ImageFormat.Png);
                }
                //if(changes.Count>0)
                //changes[0].Save("d:\\abc.png", System.Drawing.Imaging.ImageFormat.Png);
                //Console.WriteLine("changes count:"+changes.Count);

                //Bitmap screen = _mirror.GetScreen();

                //System.IO.MemoryStream m = new System.IO.MemoryStream();

                //screen.Save(m, System.Drawing.Imaging.ImageFormat.Png);

                Console.WriteLine((System.DateTime.Now.Ticks / 10000 - now) + "ms");
            }

            _mirror.Disconnect();
            _mirror.Unload();
        }
Пример #3
0
        static void Main()
        {
            // Catchall for all uncaught exceptions !!
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyDefaultHandler);

            // Catch hibernation event so that we can reload the driver
            SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(DesktopMirror.SystemEvents_PowerModeChanged);

            // Setting some garbage collector parameters
            GCSettings.LatencyMode = GCLatencyMode.LowLatency;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // First load the mirror driver
            try {
                _mirror.Load();
            } catch (System.Security.SecurityException se) {
                MessageBox.Show(se.Message + ". You need to run this program as an administrator",
                                "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                System.Environment.Exit(1);
            } catch (Exception ex) {
                MessageBox.Show("FATAL: Loading mirror driver failed. Check http://displaycast.fxpal.net/ for further instructions " + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // _mirror.Dispose();
                System.Environment.Exit(1);
            }

            // Nest, create a TCP port to listen for new Player connections
            TcpListener serverAddr = new TcpListener(new IPEndPoint(IPAddress.Any, 0));

            serverAddr.Start();

            // Now create a thread to process new client requests
            streamer = new streamThread(_mirror);
            serverThread nt = new serverThread(serverAddr, _mirror, streamer);

            Thread netThread = new Thread(new ThreadStart(nt.process));

            netThread.Name = "processNewClient";
            netThread.Start();

            // Create a thread to send data to the connected clients
            Thread strmThread = new Thread(new ThreadStart(streamer.process));

            strmThread.Name = "dataStreamer";
            // strmThread.Priority = ThreadPriority.Highest;
            strmThread.Start();

            // Now create a listener for snapshots - hardwired to port 9854
            try {
                HttpListener imageListener = new HttpListener();

                imageListener.Prefixes.Add("http://+:9854/");
                imageListener.Start();
                imageListener.BeginGetContext(_mirror.sendScreenShot, imageListener);

                if (imageListener.IsListening)
                {
                    TXTrecords.Add("imagePort", "9854");
                }
            } catch (Exception e) {
                MessageBox.Show("Oops " + e.Message);
            }

            maskX      = maskY = 0;
            maskWidth  = DesktopMirror._bitmapWidth;
            maskHeight = DesktopMirror._bitmapHeight;

            // Now listen for mask requests - perhaps I could've reused the imageport also
            TcpListener ctrlAddr = new TcpListener(IPAddress.Any, 0);   // Used for accepting MASK command

            ctrlAddr.Start();
            IPEndPoint sep = (IPEndPoint)ctrlAddr.LocalEndpoint;

            Debug.Assert(sep.Port != 0);
            TXTrecords.Add("maskPort", sep.Port.ToString());
            ctrlAddr.BeginAcceptTcpClient(ctrlBeginAcceptTcpClient, ctrlAddr);

            /* Fill TXT RECORD */
            TXTrecords.Add("screen", "0x0 " + DesktopMirror._bitmapWidth.ToString() + "x" + DesktopMirror._bitmapHeight.ToString());
            TXTrecords.Add("machineName", System.Environment.MachineName);
            TXTrecords.Add("osVersion", System.Environment.OSVersion.VersionString);
            TXTrecords.Add("version", Shared.DisplayCastGlobals.DISPLAYCAST_VERSION.ToString());
            TXTrecords.Add("userid", System.Environment.UserName);

#if USE_BLUETOOTH
            if (BluetoothRadio.IsSupported)
            {
                try {
                    TXTrecords.Add("bluetooth", BluetoothRadio.PrimaryRadio.LocalAddress.ToString("C").Replace(":", "-").ToLower());
                } catch {
                    TXTrecords.Add("bluetooth", "NotSupported");
                }
            }
            else
#endif
            TXTrecords.Add("bluetooth", "NotSupported");
            TXTrecords.Add("nearby", "UNKNOWN");

            String myName = null, id;
            using (RegistryKey dcs = Registry.CurrentUser.CreateSubKey("Software").CreateSubKey("FXPAL").CreateSubKey("DisplayCast").CreateSubKey("Streamer")) {
                if (dcs.GetValue("uid") == null)
                {
                    dcs.SetValue("uid", System.Guid.NewGuid().ToString("D"));
                }
                id = dcs.GetValue("uid").ToString();

                if (dcs.GetValue("Name") == null)
                {
                    dcs.SetValue("Name", System.Environment.UserName);
                }
                myName = dcs.GetValue("Name").ToString();
                TXTrecords.Add("name", myName);
            }

            try {
                // Now, publish my info via Bonjour
                IPEndPoint serv = (IPEndPoint)serverAddr.LocalEndpoint;

                publishService = new NetService(Shared.DisplayCastGlobals.BONJOURDOMAIN, Shared.DisplayCastGlobals.STREAMER, id, serv.Port);
                publishService.DidPublishService    += new NetService.ServicePublished(publishService_DidPublishService);
                publishService.DidNotPublishService += new NetService.ServiceNotPublished(publishService_DidNotPublishService);
                publishService.TXTRecordData         = NetService.DataFromTXTRecordDictionary(TXTrecords);
                publishService.Publish();
            } catch (Exception e) {
                Trace.WriteLine(e.StackTrace);
                MessageBox.Show("Apple Bonjour not installed. Pick up a local copy from http://displaycast.fxpal.net/",
                                "FATAL", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
            }

            _mirror.DesktopChange += _DesktopChange;
            try {
                Application.Run(new Console(publishService, TXTrecords, id));
            } catch (Exception e) {
                MessageBox.Show("FATAL: " + e.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #4
0
 private void initialDriver()
 {
     _mirror.Load();
     _mirror.Connect();
     _mirror.Start();
 }