/// <summary> /// 通过参数打开一个JFmpeg视频流 /// </summary> /// <param name="password">jsmpeg密码</param> /// <param name="rtspStreamUrl">rtsp流地址</param> /// <param name="rtspUsername">rtsp用户名</param> /// <param name="rtspPsd">rtsp密码</param> private void OpenSelectedJFmpeg(string password, string rtspStreamUrl, string rtspUsername, string rtspPsd) { List <int> inOutPort = GetUnusedInOutPort(); string inPortNum = inOutPort[0].ToString(); string outPortNum = inOutPort[1].ToString(); if (jfmpegMap.ContainsKey(rtspStreamUrl)) { if (jfmpegMap[rtspStreamUrl].Ffmpegpid != 0 || jfmpegMap[rtspStreamUrl].Jsmpegpid != 0) { return; } jfmpegMap[rtspStreamUrl].InPort = int.Parse(inPortNum); jfmpegMap[rtspStreamUrl].OutPort = int.Parse(outPortNum); jfmpegMap[rtspStreamUrl].Password = password; jfmpegMap[rtspStreamUrl].RtspUsername = rtspUsername; jfmpegMap[rtspStreamUrl].RtspPassword = rtspPsd; } else { JFmpeg jfmpegItem = new JFmpeg(int.Parse(inPortNum), int.Parse(outPortNum), rtspStreamUrl, password, rtspUsername, rtspPsd); jfmpegMap.Add(rtspStreamUrl, jfmpegItem); } ManualResetEvent jsmpegManual = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(o => { OpenJsmpeg(rtspStreamUrl, inPortNum, outPortNum, password); jsmpegManual.Set(); }); jsmpegManual.WaitOne(); ManualResetEvent ffmpegManual = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(o => { OpenFFmpeg(rtspStreamUrl, rtspUsername, rtspPsd, inPortNum, password); ffmpegManual.Set(); }); ffmpegManual.WaitOne(); //刷新视频流参数列表 RefreshJfmpegList(); }
/// <summary> /// 通过读取配置文件打开配置的所有视频流 /// </summary> private void OpenConfStream() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(AppDomain.CurrentDomain.BaseDirectory + "configlist.xml"); XmlNodeList monitors = xmlDoc.SelectNodes("Monitors/monitor"); if (monitors != null) { foreach (XmlElement monitor in monitors) { List <int> inOutPort = GetUnusedInOutPort(); string inPortNum = inOutPort[0].ToString(); string outPortNum = inOutPort[1].ToString(); //string inPortNum = monitor.FirstChild.ChildNodes[0].InnerText; //string outPortNum = monitor.FirstChild.ChildNodes[1].InnerText; string password = monitor.FirstChild.ChildNodes[2].InnerText; string rtspStreamUrl = monitor.LastChild.ChildNodes[0].InnerText; string rtspUsername = monitor.LastChild.ChildNodes[1].InnerText; string rtspPsd = monitor.LastChild.ChildNodes[2].InnerText; if (jfmpegMap.ContainsKey(rtspStreamUrl)) { if (jfmpegMap[rtspStreamUrl].Ffmpegpid != 0 || jfmpegMap[rtspStreamUrl].Jsmpegpid != 0) { return; } else { jfmpegMap[rtspStreamUrl].InPort = int.Parse(inPortNum); jfmpegMap[rtspStreamUrl].OutPort = int.Parse(outPortNum); jfmpegMap[rtspStreamUrl].Password = password; jfmpegMap[rtspStreamUrl].RtspUsername = rtspUsername; jfmpegMap[rtspStreamUrl].RtspPassword = rtspPsd; } } else { JFmpeg jfmpegItem = new JFmpeg(int.Parse(inPortNum), int.Parse(outPortNum), rtspStreamUrl, password, rtspUsername, rtspPsd); jfmpegMap.Add(rtspStreamUrl, jfmpegItem); } //按配置项开启视频流 ManualResetEvent jsmpegManual = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(o => { OpenJsmpeg(rtspStreamUrl, inPortNum, outPortNum, password); jsmpegManual.Set(); }); jsmpegManual.WaitOne(); ManualResetEvent ffmpegManual = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(o => { OpenFFmpeg(rtspStreamUrl, rtspUsername, rtspPsd, inPortNum, password); ffmpegManual.Set(); }); ffmpegManual.WaitOne(); } } //刷新视频流参数列表 RefreshJfmpegList(); }