public JsonResult SetVhost(string deviceId, SrsvHostConfClass vhost) { ResponseStruct rss = CommonFunctions.CheckParams(new object[] { deviceId, vhost }); if (rss.Code != ErrorNumber.None) { return(Program.CommonFunctions.DelApisResult(null !, rss)); } var rt = VhostApis.SetVhost(deviceId, vhost, out ResponseStruct rs); return(Program.CommonFunctions.DelApisResult(rt, rs)); }
private static void write_Vhost(SrsvHostConfClass o, out string output, int segmentLevel, List <Type> types = null !) { output = ""; string segmentSpace_head = paddingSegment(segmentLevel).Key; string segmentSpace = paddingSegment(segmentLevel).Value; output += segmentSpace_head + o.SectionsName?.ToLower().Trim() + " " + o.VhostDomain + " { \r\n"; foreach (PropertyInfo p in o.GetType().GetProperties()) { object?obj = p.GetValue(o); if (obj == null) { continue; } if (p.Name.ToLower().Trim() == "sectionsname" || p.Name.ToLower().Trim() == "instancename" || p.Name.ToLower().Trim() == "vhostdomain") { continue; } if ((p.PropertyType == typeof(string) || p.PropertyType == typeof(int?) || p.PropertyType == typeof(ushort?) || p.PropertyType == typeof(byte?) || p.PropertyType == typeof(float?) || p.PropertyType == typeof(bool?)) || ((types != null) && types.Contains(p.PropertyType))) { if (obj != null) { if (p.PropertyType == typeof(bool?)) { string s = ""; s = Common.GetBoolStr(p, o); string sTmp = segmentSpace + p.Name.Trim().ToLower() + "\t" + s + ";"; output += (sTmp + "\r\n"); } else { string sTmp = segmentSpace + p.Name.Trim().ToLower() + "\t" + obj + ";"; output += (sTmp + "\r\n"); } } } } foreach (PropertyInfo p in o.GetType().GetProperties()) //循环非基础类型数据,为了保证基础类型数据在顶上 { object?obj = p.GetValue(o); if (obj == null) { continue; } if (p.Name.ToLower().Trim() == "sectionsname" || p.Name.ToLower().Trim() == "instancename") { continue; } if (p.PropertyType == typeof(Rtc)) { string output_rtc = ""; write_SubOnly(o.Rtc, out output_rtc, 2); output += output_rtc; } if (p.PropertyType == typeof(Cluster)) { string output_cluster = ""; write_SubOnly(o.Vcluster, out output_cluster, 2); output += output_cluster; } if (p.PropertyType == typeof(Forward)) { string output_forward = ""; write_SubOnly(o.Vforward, out output_forward, 2); output += output_forward; } if (p.PropertyType == typeof(Play)) { string output_play = ""; List <Type> types1 = new List <Type>(); types1.Add(typeof(PlayTimeJitter?)); write_SubOnly(o.Vplay, out output_play, 2, types1); output += output_play; } if (p.PropertyType == typeof(Publish)) { string output_publish = ""; write_SubOnly(o.Vpublish, out output_publish, 2); output += output_publish; } if (p.PropertyType == typeof(Refer)) { string output_refer = ""; write_SubOnly(o.Vrefer, out output_refer, 2); output += output_refer; } if (p.PropertyType == typeof(Bandcheck)) { string output_bandcheck = ""; write_SubOnly(o.Vbandcheck, out output_bandcheck, 2); output += output_bandcheck; } if (p.PropertyType == typeof(Security)) { string segmentSpace_head1 = paddingSegment(2).Key; string segmentSpace1 = paddingSegment(2).Value; output += segmentSpace_head1 + "security" + " { \r\n"; if (o.Vsecurity?.Enabled != null) { if (o.Vsecurity.Enabled == true) { output += segmentSpace1 + "enabled\t" + "on;\r\n"; } else { output += segmentSpace1 + "enabled\t" + "off;\r\n"; } } if (o.Vsecurity?.Seo != null) { foreach (SecurityObj s in o.Vsecurity.Seo) { output += segmentSpace1 + s.Sem.ToString() + "\t" + s.Set.ToString() + "\t" + s.Rule + ";\r\n"; } } output += segmentSpace_head1 + "}\r\n"; } if (p.PropertyType == typeof(HttpStatic)) { string output_http_static = ""; write_SubOnly(o.Vhttp_static, out output_http_static, 2); output += output_http_static; } if (p.PropertyType == typeof(HttpRemux)) { string output_http_remux = ""; write_SubOnly(o.Vhttp_remux, out output_http_remux, 2); output += output_http_remux; } if (p.PropertyType == typeof(HttpHooks)) { string output_http_hooks = ""; write_SubOnly(o.Vhttp_hooks, out output_http_hooks, 2); output += output_http_hooks; } if (p.PropertyType == typeof(Exec)) { string output_exec = ""; write_SubOnly(o.Vexec, out output_exec, 2); output += output_exec; } if (p.PropertyType == typeof(Dash)) { string output_dash = ""; write_SubOnly(o.Vdash, out output_dash, 2); output += output_dash; } if (p.PropertyType == typeof(Hls)) { string output_hls = ""; write_SubOnly(o.Vhls, out output_hls, 2); output += output_hls; } if (p.PropertyType == typeof(Hds)) { string output_hds = ""; write_SubOnly(o.Vhds, out output_hds, 2); output += output_hds; } if (p.PropertyType == typeof(Dvr)) { string output_dvr = ""; List <Type> types2 = new List <Type>(); types2.Add(typeof(PlayTimeJitter?)); write_SubOnly(o.Vdvr, out output_dvr, 2, types2); output += output_dvr; } if (p.PropertyType == typeof(Nack)) { string output_nack = ""; write_SubOnly(o.Vnack, out output_nack, 2); output += output_nack; } if (p.PropertyType == typeof(List <Ingest>)) { if (o.Vingests != null) { foreach (Ingest i in o.Vingests) { string s = ""; List <Type> types3 = new List <Type>(); types3.Add(typeof(IngestInputType?)); write_Vhost_Ingest(i, out s, 2, types3); output = output + s; } } } if (p.PropertyType == typeof(List <Transcode>)) { if (o.Vtranscodes != null) { foreach (Transcode i in o.Vtranscodes) { string s = ""; write_Vhost_Transcode(i, out s, 2); output = output + s; } } } } output += segmentSpace_head + "}\r\n"; }
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); } } }