Beispiel #1
0
        public Form1()
        {
            InitializeComponent();

            liveData = new NetworkDataAccess(true, "Video", "Siz");
            liveData.setListenerSettings(AppSettingsController.GetAppSetting("receiveFromAddress", "127.0.0.1"), AppSettingsController.GetAppSetting("ListenPort", 11000));

            recordedData = new NetworkDataAccess(false, "DB_Video", "DB_Siz");
            recordedData.setListenerSettings(AppSettingsController.GetAppSetting("receiveFromAddressDB", "127.0.0.1"), AppSettingsController.GetAppSetting("ListenPortDB", 11001));

            displaying = new Thread(this.Display);
            buffering  = new Thread(this.FillBuffer);

            this.resetProgress(1, 1);

            displayingDB = new Thread(this.DisplayDB);
            bufferingDB  = new Thread(this.FillBufferDB);

            this.resetProgressDB(1, 1);

            CheckForIllegalCrossThreadCalls = false;


            SetDoubleBuffered(pbFrame);
            SetDoubleBuffered(pbFrameDB);
        }
Beispiel #2
0
        private void stopbutton_Click(object sender, EventArgs e)
        {
            byte[] send_buffer;
            string ip   = AppSettingsController.GetAppSetting("sendToAddress", "127.0.0.1");
            int    port = AppSettingsController.GetAppSetting("sendToPort", 12000);

            Console.WriteLine(dayPicker.Value.Date);
            Console.WriteLine(hourCombo.SelectedItem);
            Console.WriteLine(mincombo.SelectedItem);
            sendingSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            sendToAddress = IPAddress.Parse(ip);
            UTF8Encoding encoding = new UTF8Encoding();

            sendingEndPoint = new IPEndPoint(sendToAddress, port);
            send_buffer     = encoding.GetBytes("sender->" + sendToAddress.ToString());
            sendingSocket.SendTo(send_buffer, sendingEndPoint);
            send_buffer = encoding.GetBytes("date->" + dayPicker.Value.Date.ToString());
            sendingSocket.SendTo(send_buffer, sendingEndPoint);
            send_buffer = encoding.GetBytes("hour->" + hourCombo.SelectedItem.ToString());
            sendingSocket.SendTo(send_buffer, sendingEndPoint);
            send_buffer = encoding.GetBytes("min->" + mincombo.SelectedItem.ToString());
            sendingSocket.SendTo(send_buffer, sendingEndPoint);
            send_buffer = encoding.GetBytes("status->stop");
            sendingSocket.SendTo(send_buffer, sendingEndPoint);

            recordedData.clearData();
            this.resetProgressDB(1, 1);
            bufferingDB.Abort();
            displayingDB.Abort();
            pbFrameDB.Image = null;
        }
Beispiel #3
0
        public void deleteAllFiles()
        {
            int max = AppSettingsController.GetAppSetting("BufferFilesLimit", 20);

            for (int oldFileCount = 1; oldFileCount <= max; oldFileCount++)
            {
                String oldvidFilename  = videoFilePrefix + oldFileCount.ToString() + ".dat";
                String oldsizeFilename = sizeFilePrefix + oldFileCount.ToString() + ".dat";

                if (File.Exists(oldsizeFilename))
                {
                    File.Delete(oldvidFilename);
                    File.Delete(oldsizeFilename);
                }
            }
        }
Beispiel #4
0
        public void FillBuffer()
        {
            int max       = AppSettingsController.GetAppSetting("BufferFilesLimit", 20);
            int maxFrames = AppSettingsController.GetAppSetting("FramesInFileLimit", 40);

            Console.WriteLine("filling...");

            while (true)
            {
                try
                {
                    receiveByteArray = listener.Receive(ref groupEP);
                    saveByteArray.Add(receiveByteArray);
                    saveFrameSize.Add(receiveByteArray.Length);

                    if (saveByteArray.Count >= maxFrames)
                    {
                        fileCount++;

                        if (fileCount > max)
                        {
                            fileCount = 1;
                        }

                        String       vidFilename    = videoFilePrefix + fileCount.ToString() + ".dat";
                        String       sizeFilename   = sizeFilePrefix + fileCount.ToString() + ".dat";
                        FileStream   vidFileStream  = new FileStream(vidFilename, FileMode.Create, FileAccess.Write);
                        StreamWriter sizeFileStream = new StreamWriter(sizeFilename);
                        try
                        {
                            foreach (byte[] byteArrayElement in saveByteArray)
                            {
                                vidFileStream.Write(byteArrayElement, 0, byteArrayElement.Length);
                            }


                            foreach (int sizeArrayElement in saveFrameSize)
                            {
                                sizeFileStream.WriteLine(sizeArrayElement);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        finally
                        {
                            saveByteArray.Clear();
                            saveFrameSize.Clear();
                            filesBuffered = filesBuffered > 5 ? 5 : filesBuffered + 1;
                            vidFileStream.Close();
                            sizeFileStream.Close();
                        }
                    }

                    if (isLive)
                    {
                        Program.f.updateProgress();
                    }
                    else
                    {
                        Program.f.updateProgressDB();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Buffer " + ex.Message);
                }
            }
        }
Beispiel #5
0
        public void Display()
        {
            String vidFilename;
            String sizeFilename;
            String s;
            int    size;

            byte[]       frameData;
            MemoryStream frameStream;
            Bitmap       frame;
            int          fileCount        = 1;
            int          maxForDisplay    = AppSettingsController.GetAppSetting("BufferLimitForDisplay", 3);
            int          max              = AppSettingsController.GetAppSetting("BufferFilesLimit", 20);
            int          displayDelay     = AppSettingsController.GetAppSetting("DisplayDelay", 300);
            int          waitForFileDelay = AppSettingsController.GetAppSetting("WaitForFileDelay", 300);

            Console.WriteLine("Display...");


            while (true)
            {
                try
                {
                    if (filesBuffered > maxForDisplay)
                    {
                        vidFilename  = videoFilePrefix + fileCount.ToString() + ".dat";
                        sizeFilename = sizeFilePrefix + fileCount.ToString() + ".dat";
                        FileStream   vidFileStream = new FileStream(vidFilename, FileMode.Open, FileAccess.Read);
                        StreamReader sizeReader    = new StreamReader(sizeFilename);
                        try
                        {
                            s    = sizeReader.ReadLine();
                            size = int.Parse(s);

                            /*int oldFileCount = fileCount > 10 ? fileCount - 10 : (20 + fileCount - 10);
                             * String oldvidFilename = "Video" + oldFileCount.ToString() + ".dat";
                             * String oldsizeFilename = "Siz" + oldFileCount.ToString() + ".dat";
                             *
                             * if (File.Exists(oldsizeFilename))
                             * {
                             *  File.Delete(oldvidFilename);
                             *  File.Delete(oldsizeFilename);
                             * }*/

                            fileCount++;
                            if (fileCount > max)
                            {
                                fileCount = 1;
                            }

                            while (s != null)
                            {
                                frameData = new byte[size];
                                vidFileStream.Read(frameData, 0, size);
                                frameStream = new MemoryStream(frameData);
                                frame       = new Bitmap(frameStream);
                                frameStream.Close();
                                if (isLive)
                                {
                                    Program.f.pbFrame.Image = frame;
                                    Program.f.pbFrame.Refresh();
                                    Thread.Sleep(displayDelay);
                                    Program.f.updateProgressDisplay();
                                }
                                else
                                {
                                    Program.f.pbFrameDB.Image = frame;
                                    Program.f.pbFrameDB.Refresh();
                                    Thread.Sleep(displayDelay);
                                    Program.f.updateProgressDisplayDB();
                                }

                                s = sizeReader.ReadLine();
                                try
                                {
                                    size = int.Parse(s);
                                }
                                catch {; }
                            }
                            vidFileStream.Close();
                            sizeReader.Close();

                            try
                            {
                                File.Delete(vidFilename);
                                File.Delete(sizeFilename);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("File Delete Error: " + ex.Message);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        finally
                        {
                            vidFileStream.Close();
                            sizeReader.Close();
                        }
                    }
                }
                catch (FileNotFoundException) { Thread.Sleep(waitForFileDelay); }
                catch (Exception ex)
                {
                    Console.WriteLine("Display " + ex.Message);
                }
            }
        }