Example #1
0
        // ---------------------------------------------------------------
        // stop encoder
        public override void StopRecord()
        {
            if (vsEncoder != null && vsEncoder.Recording)
            {
                // stop timer
                timer.Stop();
                stimer.Stop();

                try
                {
                    // stop encoder
                    vsEncoder.StopRecord();

                    // already write and can be accessed by another?
                    // convert avi file to wmv
                    VsEncode vsEnc = new VsEncode(rawName, aviName);
                    EncodeOut(this, new VsEncodeEventArgs(vsEnc));
                    vsEnc.Dispose(); vsEnc = null;

                    // send data to database server
                    DataAlert();
                }
                catch (Exception err)
                {
                    // error log
                    logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace);;

                    // if can't stop
                    // try to free memory
                    if (vsEncoder != null)
                    {
                        vsEncoder.Dispose();
                        vsEncoder = null;
                    }

                    // and create new encoder
                    if (vsEncoder == null)
                    {
                        try
                        {
                            vsEncoder = new AviEncoder();
                        }
                        catch (Exception err1)
                        {
                            if (vsEncoder != null)
                            {
                                vsEncoder.Dispose();
                                vsEncoder = null;
                            }
                            logger.Log(LogLevel.Error, err1.Message + " " + err1.Source + " " + err1.StackTrace);;
                        }
                    }
                }

                // start timer
                timer.Start();
            }
        }
Example #2
0
        // Thread entry point
        public void ConverterThread()
        {
            VsEncode lastEnc = null;

            while (true)
            {
                // free memory
                if (lastEnc != null)
                {
                    lastEnc.Dispose(); lastEnc = null;
                }

                // get new conversion if there is
                // or waiting if not
                if (encBuffer.Count > 0)
                {
                    lastEnc = (VsEncode)encBuffer.Dequeue();
                }
                else
                {
                    waitEvent.WaitOne();
                }

                if (lastEnc != null)
                {
                    string fileInput = lastEnc.FileFrom; string fileOutput = lastEnc.FileTo;

                    try
                    {
                        // check file input
                        FileInfo fileIn = new FileInfo(fileInput);

                        if (fileIn.Length > 0)
                        {
                            // convert to wmv
                            AviConverter aviConvert = new AviConverter(fileInput, fileOutput, "wmv3");

                            try
                            {
                                // convert
                                aviConvert.StartConvert();
                            }
                            catch (Exception err)
                            {
                                logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace);
                            }
                            finally
                            {
                                aviConvert.Dispose();
                                aviConvert = null;
                            }

                            // check file output and delete file input
                            FileInfo fileOut = new FileInfo(fileOutput);

                            if (fileOut.Length > 0)
                            {
                                fileIn.Delete();
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace);
                    }
                }

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

                Thread.Sleep(100);
            }
        }