Пример #1
0
        private void Run()
        {
            while (true)
            {
                var srsDeviceIdList = SystemApis.GetAllSrsManagerDeviceId();
                if (srsDeviceIdList == null || srsDeviceIdList.Count == 0)
                {
                    continue;
                }
                foreach (var deviceId in srsDeviceIdList)
                {
                    ReqGetDvrPlan rgdp = new ReqGetDvrPlan();
                    rgdp.DeviceId = deviceId;

                    var dvrPlanList = DvrPlanApis.GetDvrPlanList(rgdp, out ResponseStruct rs);
                    if (dvrPlanList == null || dvrPlanList.Count == 0)
                    {
                        continue;
                    }
                    foreach (var dvrPlan in dvrPlanList)
                    {
                        if (dvrPlan == null)
                        {
                            continue;
                        }
                        execDvrDeletePlan(dvrPlan);
                        execDvrOnOrOffPlan(dvrPlan);
                    }
                }

                Thread.Sleep(interval);
            }
        }
Пример #2
0
        private void doThing(string deviceId, string vhostDomain, Ingest ingest)
        {
            LogWriter.WriteLog("重启设备ID" + deviceId + "下的" + vhostDomain + "下的" + ingest.IngestName + " Ingest");

            lock (SrsManageCommon.Common.LockDbObjForOnlineClient)
            {
                OrmService.Db.Delete <OnlineClient>().Where(x => x.RtspUrl == ingest.Input !.Url).ExecuteAffrows();
            }

            var retInt = foundProcess(ingest);

            if (retInt > -1)
            {
                try
                {
                    string cmd = "kill -9 " + retInt.ToString();
                    LinuxShell.Run(cmd, 1000);
                }
                catch (Exception ex)
                {
                    LogWriter.WriteLog(
                        "重启设备ID" + deviceId + "下的" + vhostDomain + "下的" + ingest.IngestName + " Ingest失败",
                        ex.Message + "\r\n" + ex.StackTrace, ConsoleColor.Yellow);
                }
            }

            ResponseStruct rs = null !;

            VhostIngestApis.OnOrOffIngest(deviceId, vhostDomain, ingest.IngestName !, false, out rs);
            SystemApis.RefreshSrsObject(deviceId, out rs);
            Thread.Sleep(1000);
            VhostIngestApis.OnOrOffIngest(deviceId, vhostDomain, ingest.IngestName !, true, out rs);
            SystemApis.RefreshSrsObject(deviceId, out rs);
        }
Пример #3
0
        private void setDvrOnorOff(StreamDvrPlan sdp, bool eanble)
        {
            var dvr = VhostDvrApis.GetVhostDvr(sdp.DeviceId, sdp.VhostDomain, out ResponseStruct rs);

            if (dvr != null)
            {
                string?       dvrApply   = dvr.Dvr_apply !;
                List <string> dvrStreams = new List <string>();
                if (!string.IsNullOrEmpty(dvrApply))
                {
                    dvrStreams = Regex.Split(dvrApply, @"[\s]+").ToList();
                }


                if (dvrStreams.Count == 0)
                {
                    dvrStreams.Add("");
                }

                for (int i = 0; i <= dvrStreams.Count - 1; i++)
                {
                    dvrStreams[i] = dvrStreams[i].TrimEnd(';').Trim();
                }

                bool needWrite = false;
                switch (eanble)
                {
                case true:
                    if (!dvrStreams.Contains((sdp.App + "/" + sdp.Stream).Trim()))
                    {
                        dvrStreams.Add((sdp.App + "/" + sdp.Stream).Trim());
                        needWrite = true;
                    }

                    break;

                case false:
                    if (dvrStreams.Contains((sdp.App + "/" + sdp.Stream).Trim()))
                    {
                        dvrStreams.Remove((sdp.App + "/" + sdp.Stream).Trim());
                        needWrite = true;
                    }

                    break;
                }

                if (needWrite)
                {
                    dvr.Dvr_apply = "";
                    foreach (var str in dvrStreams)
                    {
                        dvr.Dvr_apply += str + "\t";
                    }

                    dvr.Dvr_apply = dvr.Dvr_apply.TrimEnd('\t');
                    VhostDvrApis.SetVhostDvr(sdp.DeviceId, sdp.VhostDomain, dvr, out rs);
                    SystemApis.RefreshSrsObject(sdp.DeviceId, out rs);
                }
            }
        }
Пример #4
0
        private void Run()
        {
            while (true)
            {
                try
                {
                    var retDeviceList = SystemApis.GetAllSrsManagerDeviceId();
                    if (retDeviceList != null && retDeviceList.Count > 0)
                    {
                        foreach (var dev in retDeviceList)
                        {
                            if (string.IsNullOrEmpty(dev))
                            {
                                continue;
                            }
                            var retSrsManager = SystemApis.GetSrsManagerInstanceByDeviceId(dev);
                            if (retSrsManager == null || retSrsManager.Srs == null || !retSrsManager.IsRunning)
                            {
                                continue;
                            }
                            var retSrsVhostList =
                                VhostApis.GetVhostList(retSrsManager.SrsDeviceId, out ResponseStruct rs);
                            if (retSrsVhostList == null || retSrsVhostList.Count == 0)
                            {
                                continue;
                            }
                            foreach (var vhost in retSrsVhostList)
                            {
                                if (vhost == null || vhost.Vingests == null || vhost.Vingests.Count == 0)
                                {
                                    continue;
                                }
                                foreach (var ingest in vhost.Vingests)
                                {
                                    if (ingest.Enabled == false)
                                    {
                                        continue;
                                    }
                                    if (ingestIsDead(dev, ingest))
                                    {
                                        LogWriter.WriteLog(
                                            "监控到设备ID" + dev + "下的" + vhost.VhostDomain + "下的" + ingest.IngestName +
                                            " 处于异常状态,立即重启ingest", "", ConsoleColor.Red);
                                        doThing(dev, vhost.VhostDomain !, ingest);
                                    }

                                    Thread.Sleep(30);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogWriter.WriteLog("Ingest守护异常...", ex.Message + "\r\n" + ex.StackTrace);
                }

                Thread.Sleep(interval);
            }
        }
Пример #5
0
        public JsonResult RefreshSrsObject(string deviceId)
        {
            ResponseStruct rss = CommonFunctions.CheckParams(new object[] { deviceId });

            if (rss.Code != ErrorNumber.None)
            {
                return(Program.CommonFunctions.DelApisResult(null !, rss));
            }

            var rt = SystemApis.RefreshSrsObject(deviceId, out ResponseStruct rs);

            return(Program.CommonFunctions.DelApisResult(rt, rs));
        }
Пример #6
0
        //删除所有空的目录,用于dvr目录
        private void clearNofileDir(string deviceId)
        {
            var srs = SystemApis.GetSrsManagerInstanceByDeviceId(deviceId);

            if (srs != null)
            {
                string dvrPath = srs.SrsWorkPath + srs.SrsDeviceId + "/wwwroot/dvr";
                if (Directory.Exists(dvrPath))
                {
                    DirectoryInfo   dir     = new DirectoryInfo(dvrPath);
                    DirectoryInfo[] subdirs = dir.GetDirectories("*.*", SearchOption.AllDirectories);
                    foreach (DirectoryInfo subdir in subdirs)
                    {
                        FileSystemInfo[] subFiles = subdir.GetFileSystemInfos();
                        if (subFiles.Length == 0)
                        {
                            LogWriter.WriteLog("监控发现有空目录需要删除...", subdir.FullName);
                            subdir.Delete();
                        }
                    }
                }
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            string stream =
                "{\"code\":0,\"server\":87846,\"data\":{\"ok\":true,\"now_ms\":1591068638439,\"self\":{\"version\":\"4.0.23\",\"pid\":29282,\"ppid\":1,\"argv\":\"/root/StreamNode/srs -c /root/StreamNode/22364bc4-5134-494d-8249-51d06777fb7f.conf\",\"cwd\":\"/root/StreamNode\",\"mem_kbyte\":71448,\"mem_percent\":0.00,\"cpu_percent\":0.09,\"srs_uptime\":214},\"system\":{\"cpu_percent\":0.02,\"disk_read_KBps\":0,\"disk_write_KBps\":0,\"disk_busy_percent\":0.00,\"mem_ram_kbyte\":16266040,\"mem_ram_percent\":0.06,\"mem_swap_kbyte\":8257532,\"mem_swap_percent\":0.00,\"cpus\":8,\"cpus_online\":8,\"uptime\":162062.71,\"ilde_time\":1275660.46,\"load_1m\":0.12,\"load_5m\":0.22,\"load_15m\":0.19,\"net_sample_time\":1591068632439,\"net_recv_bytes\":0,\"net_send_bytes\":0,\"net_recvi_bytes\":458866896997,\"net_sendi_bytes\":218579639053,\"srs_sample_time\":1591068638439,\"srs_recv_bytes\":447805521,\"srs_send_bytes\":33944,\"conn_sys\":55,\"conn_sys_et\":29,\"conn_sys_tw\":10,\"conn_sys_udp\":4,\"conn_srs\":10}}}";
            var a = JsonHelper.FromJson <SrsSystemInfo>(stream);

            Console.WriteLine(a.ToString());
            Console.WriteLine("Hello World!");
            Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
            Console.WriteLine(JsonHelper.ToJson(SystemApis.GetSystemInfo()));
            Common.init_SrsServer();
            Common.startServers();
            List <string> srsdevidlist = SystemApis.GetAllSrsManagerDeviceId();

            Console.WriteLine(JsonHelper.ToJson(srsdevidlist));
            foreach (var s in srsdevidlist)
            {
                Console.WriteLine(JsonHelper.ToJson(SystemApis.GetSrsManagerInstanceByDeviceId(s)));
            }

            if (srsdevidlist.Count > 0)
            {
                SrsManager srsm = SystemApis.GetSrsManagerInstanceByDeviceId(srsdevidlist[0]);

                string d = "www.test1cn.tyz";

                Console.WriteLine("pid:" + srsm.IsRunning);
                ResponseStruct    rs;
                SrsvHostConfClass vhost = VhostApis.GetVhostTemplate(VhostIngestInputType.Stream, out rs);
                vhost.VhostDomain = d;
                VhostApis.SetVhost(srsm.SrsDeviceId, vhost, out rs);
                Rtc rtc = new Rtc();
                rtc.Bframe  = "known";
                rtc.Enabled = true;
                VhostRtcApis.SetVhostRtc(srsm.SrsDeviceId, d, rtc, out rs);
                Dvr dvr = new Dvr();
                dvr.Enabled  = true;
                dvr.Dvr_path = "/dvr/path/";
                VhostDvrApis.SetVhostDvr(srsm.SrsDeviceId, d, dvr, out rs);
                Hds hds = new Hds();
                hds.Enabled    = true;
                hds.Hds_window = 50;

                VhostHdsApis.SetVhostHds(srsm.SrsDeviceId, d, hds, out rs);
                SrtServerApis.DeleteSrtServer(srsm.SrsDeviceId, out rs);
                SrsSrtServerConfClass srt = new SrsSrtServerConfClass();
                srt = SrtServerApis.GetSrtServerTemplate(out rs);

                srt.Enabled = true;
                SrtServerApis.SetSrtServer(srsm.SrsDeviceId, srt, out rs);

                VhostApis.DeleteVhostByDomain(srsm.SrsDeviceId, "__defaultvhost__", out rs);
                VhostRtcApis.DeleteVhostRtc(srsm.SrsDeviceId, d, out rs);
                VhostHdsApis.DeleteVhostHds(srsm.SrsDeviceId, d, out rs);

                SrsConfigBuild.Build(srsm.Srs, srsm.SrsConfigPath);
                if (srsm.IsRunning)
                {
                    bool ret = srsm.Reload(out rs);
                }
            }
        }