Exemplo n.º 1
0
 public int GetJpegImage(ref byte[] imageBuf)
 {
     Damany.Cameras.SanyoNetCamera oCamera = new Damany.Cameras.SanyoNetCamera();
     oCamera.UserName = _deviceInfo.login;
     oCamera.PassWord = _deviceInfo.pwd;
     oCamera.Uri      = new Uri(string.Format("http://{0}", _deviceInfo.source));
     try
     {
         oCamera.Connect();
         imageBuf = oCamera.CaptureImageBytes();
         return(0);
     }
     catch (Exception ex)
     {
         return(-1);
     }
 }
Exemplo n.º 2
0
        // Thread entry point
        public void WorkerThread()
        {
            byte[]			buffer = new byte[bufSize];	// buffer to read stream
            HttpWebRequest	req = null;
            WebResponse		resp = null;
            Stream			stream = null;
            Random			rnd = new Random((int) DateTime.Now.Ticks);
            DateTime		start;
            TimeSpan		span;

            Damany.Cameras.SanyoNetCamera oCamera = new Damany.Cameras.SanyoNetCamera();
            oCamera.UserName =_deviceInfo.login;
            oCamera.PassWord = _deviceInfo.pwd;
            oCamera.Uri = new Uri(string.Format("http://{0}",_deviceInfo.source));
            try
            {
                oCamera.Connect();
            }
            catch (Exception ex)
            {
                return;
            }

            while (true)
            {
                int	read, total = 0;

                try
                {
                     start = DateTime.Now;
                     buffer = oCamera.CaptureImageBytes();

                    if (!stopEvent.WaitOne(0, true))
                    {
                        // increment frames counter
                        framesReceived++;

                        // image at stop
                        if (NewFrame != null)
                        {
                            Bitmap bmp = (Bitmap)Bitmap.FromStream(new MemoryStream(buffer, 0, buffer.Length));
                            // notify client
                            NewFrame(this, new CameraEventArgs(bmp));
                            // release the image
                            bmp.Dispose();
                            bmp = null;
                        }
                    }

                    // wait for a while ?
                    if (_cameraInfo.frameInterval > 0)
                    {
                        // times span
                        span = DateTime.Now.Subtract(start);
                        // miliseconds to sleep
                        int msec = _cameraInfo.frameInterval - (int)span.TotalMilliseconds;

                        while ((msec > 0) && (stopEvent.WaitOne(0, true) == false))
                        {
                            // sleeping ...
                            Thread.Sleep((msec < 100) ? msec : 100);
                            msec -= 100;
                        }
                    }
                }
                catch (WebException ex)
                {
                    System.Diagnostics.Debug.WriteLine("=============: " + ex.Message);
                    // wait for a while before the next try
                    Thread.Sleep(250);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("=============: " + ex.Message);
                }
                finally
                {
                    // abort request
                    if (req != null)
                    {
                        req.Abort();
                        req = null;
                    }
                    // close response stream
                    if (stream != null)
                    {
                        stream.Close();
                        stream = null;
                    }
                    // close response
                    if (resp != null)
                    {
                        resp.Close();
                        resp = null;
                    }
                }

                // need to stop ?
                if (stopEvent.WaitOne(0, true))
                    break;
            }
        }
Exemplo n.º 3
0
 public int GetJpegImage(ref byte[] imageBuf)
 {
     Damany.Cameras.SanyoNetCamera oCamera = new Damany.Cameras.SanyoNetCamera();
     oCamera.UserName = _deviceInfo.login;
     oCamera.PassWord = _deviceInfo.pwd;
     oCamera.Uri = new Uri(string.Format("http://{0}", _deviceInfo.source));
     try
     {
         oCamera.Connect();
         imageBuf = oCamera.CaptureImageBytes();
         return 0;
     }
     catch (Exception ex)
     {
         return -1;
     }
 }
Exemplo n.º 4
0
        // Thread entry point
        public void WorkerThread()
        {
            byte[]         buffer = new byte[bufSize];                          // buffer to read stream
            HttpWebRequest req    = null;
            WebResponse    resp   = null;
            Stream         stream = null;
            Random         rnd    = new Random((int)DateTime.Now.Ticks);
            DateTime       start;
            TimeSpan       span;

            Damany.Cameras.SanyoNetCamera oCamera = new Damany.Cameras.SanyoNetCamera();
            oCamera.UserName = _deviceInfo.login;
            oCamera.PassWord = _deviceInfo.pwd;
            oCamera.Uri      = new Uri(string.Format("http://{0}", _deviceInfo.source));
            try
            {
                oCamera.Connect();
            }
            catch (Exception ex)
            {
                return;
            }

            while (true)
            {
                int read, total = 0;

                try
                {
                    start  = DateTime.Now;
                    buffer = oCamera.CaptureImageBytes();

                    if (!stopEvent.WaitOne(0, true))
                    {
                        // increment frames counter
                        framesReceived++;

                        // image at stop
                        if (NewFrame != null)
                        {
                            Bitmap bmp = (Bitmap)Bitmap.FromStream(new MemoryStream(buffer, 0, buffer.Length));
                            // notify client
                            NewFrame(this, new CameraEventArgs(bmp));
                            // release the image
                            bmp.Dispose();
                            bmp = null;
                        }
                    }

                    // wait for a while ?
                    if (_cameraInfo.frameInterval > 0)
                    {
                        // times span
                        span = DateTime.Now.Subtract(start);
                        // miliseconds to sleep
                        int msec = _cameraInfo.frameInterval - (int)span.TotalMilliseconds;

                        while ((msec > 0) && (stopEvent.WaitOne(0, true) == false))
                        {
                            // sleeping ...
                            Thread.Sleep((msec < 100) ? msec : 100);
                            msec -= 100;
                        }
                    }
                }
                catch (WebException ex)
                {
                    System.Diagnostics.Debug.WriteLine("=============: " + ex.Message);
                    // wait for a while before the next try
                    Thread.Sleep(250);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("=============: " + ex.Message);
                }
                finally
                {
                    // abort request
                    if (req != null)
                    {
                        req.Abort();
                        req = null;
                    }
                    // close response stream
                    if (stream != null)
                    {
                        stream.Close();
                        stream = null;
                    }
                    // close response
                    if (resp != null)
                    {
                        resp.Close();
                        resp = null;
                    }
                }

                // need to stop ?
                if (stopEvent.WaitOne(0, true))
                {
                    break;
                }
            }
        }