示例#1
0
 /// <summary>
 /// 单实例
 /// </summary>
 /// <returns></returns>
 static public VideoPipeManage Instance()
 {
     if (videoPipeManage == null)
     {
         lock (instanceLocker)
         {
             videoPipeManage = new VideoPipeManage();
         }
     }
     return(videoPipeManage);
 }
示例#2
0
        //private FileStream fs = new FileStream(@"D:\cgwVideoAfter3.264", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
        //private int wCount = 0;

        void namePipeDataCheck_Elapsed(object sender, ElapsedEventArgs e)
        {
            //namedPipeHasVideoDataTimer.Enabled = false;
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            try
            {
                //uint compareSize = mediaData.Size;
                uint compareSize = mediaDataSize;
                Thread.Sleep(1500);
                //uint size = mediaData.Size;

                uint size = mediaDataSize;

                //if (compareSize != size && mediaData.Size != 0)
                if (compareSize != size && size != 0)
                {
                    iCount = 0;
                }
                else
                {
                    iCount++;
                }
                if (iCount == iNullCount)
                {
                    logEx.Debug("VideoPipe.Timer Data end,iCount={0},cameraNo={1}.", iCount, cameraNo);
                    namedPipeHasVideoDataTimer.Enabled = false;
                    logEx.Info("STOP namedPipeHasVideoDataTimer.");
                    VideoPipeManage.Instance().DeleteVideoPipe(cameraNo);
                    Stop();
                    VideoPipeManage.Instance().DeleteNoDataVideoPipe(cameraNo);
                }
                //else
                //{
                //    namedPipeHasVideoDataTimer.Enabled = true;
                //}
            }
            catch (System.Exception ex)
            {
                logEx.Error("VideoPipe.Timer.delete(cameraNo{0}) catch() failed ,ex={1}", cameraNo, ex.ToString());
            }
        }
示例#3
0
        /// <summary>
        /// 开始读取 码流数据
        /// </summary>
        /// <param name="str"></param>
        public void ReadData(Common.DataCallBack dataCallBack)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);

            Thread th = new Thread(new ThreadStart(() =>
            {
                while (!shouldStop)
                {
                    try
                    {
                        if (pipedStream != null && pipedStream.IsConnected)
                        {
                            byte[] byteArray     = new byte[4]; //unit字节长度
                            pipedStream.ReadMode = PipeTransmissionMode.Byte;

                            MediaData mediaData = new MediaData();

                            pipedStream.Read(byteArray, 0, 4);
                            mediaData.Size = (uint)BitConverter.ToInt32(byteArray, 0);
                            if (mediaData.Size == 0)
                            {
                                continue;
                            }
                            pipedStream.Read(byteArray, 0, 4);
                            mediaData.StreamType = (StreamType)BitConverter.ToInt32(byteArray, 0);
                            pipedStream.Read(byteArray, 0, 4);
                            mediaData.DataType = (MediaDataType)BitConverter.ToInt32(byteArray, 0);
                            pipedStream.Read(byteArray, 0, 4);
                            mediaData.FrameType = (FrameDataType)BitConverter.ToInt32(byteArray, 0);

                            byte[] dataByteArray = new byte[mediaData.Size];
                            //读取管道中的流
                            pipedStream.Read(dataByteArray, 0, (int)mediaData.Size);
                            mediaData.Data = dataByteArray;

                            mediaDataSize = mediaData.Size;

                            //if (wCount < 1200)
                            //{
                            //    fs.Write(mediaData.Data, 0, (int)mediaData.Size);
                            //    wCount++;
                            //}

                            //回调函数
                            dataCallBack(cameraNo, mediaData, cameraNo.Substring(0, cameraNo.IndexOf("#")));
                        }
                    }
                    catch (Exception ex)
                    {
                        logEx.Error("VideoPipe.ReadData is error,ex={0}", ex.ToString());
                        if (pipedStream != null && !pipedStream.IsConnected)
                        {
                            VideoPipeManage.Instance().DeleteVideoPipe(cameraNo);
                            Stop();
                        }
                    }
                }
            }));

            th.IsBackground = true;
            th.Start();
        }
示例#4
0
 /// <summary>
 /// 单实例
 /// </summary>
 /// <returns></returns>
 public static VideoPipeManage Instance()
 {
     if (videoPipeManage == null)
     {
         lock (instanceLocker)
         {
             videoPipeManage = new VideoPipeManage();
         }
     }
     return videoPipeManage;
 }