public static void Render(SectionBody scbin, SrsSystemConfClass sccout, string instanceName = "") { if (sccout.Stats == null) { sccout.Stats = new SrsStatsConfClass(); } sccout.Stats.SectionsName = "stats"; if (scbin.BodyList != null) { foreach (string s in scbin.BodyList) { if (!s.Trim().EndsWith(";")) { continue; } KeyValuePair <string, string> tmpkv = Common.GetKV(s); if (string.IsNullOrEmpty(tmpkv.Key)) { continue; } string cmd = tmpkv.Key.Trim().ToLower(); switch (cmd) { case "network": sccout.Stats.Network = Common.str2byte(tmpkv.Value); break; case "disk": sccout.Stats.Disk = tmpkv.Value; break; } } } }
public static void Render(SectionBody scbin, SrsSystemConfClass sccout, string instanceName = "") { if (sccout.Srt_server == null) { sccout.Srt_server = new SrsSrtServerConfClass(); } sccout.Srt_server.SectionsName = "srt_server"; if (scbin.BodyList != null) { foreach (string s in scbin.BodyList) { if (!s.Trim().EndsWith(";")) { continue; } KeyValuePair <string, string> tmpkv = Common.GetKV(s); if (string.IsNullOrEmpty(tmpkv.Key)) { continue; } string cmd = tmpkv.Key.Trim().ToLower(); switch (cmd) { case "enabled": sccout.Srt_server.Enabled = Common.str2bool(tmpkv.Value); break; case "listen": sccout.Srt_server.Listen = Common.str2ushort(tmpkv.Value); break; case "maxbw": sccout.Srt_server.Maxbw = Common.str2int(tmpkv.Value); break; case "connect_timeout": sccout.Srt_server.Connect_timeout = Common.str2int(tmpkv.Value); break; case "peerlatency": sccout.Srt_server.Peerlatency = Common.str2int(tmpkv.Value); break; case "recvlatency": sccout.Srt_server.Recvlatency = Common.str2int(tmpkv.Value); break; case "default_app": sccout.Srt_server.Default_app = tmpkv.Value; break; } } } }
public static void Render_RawApi(SectionBody scbin, SrsSystemConfClass sccout, string instanceName = "") { if (sccout.Http_api?.Raw_Api == null) { if (sccout.Http_api != null) { sccout.Http_api.Raw_Api = new RawApi(); } } if (sccout.Http_api != null) { if (sccout.Http_api.Raw_Api != null) { sccout.Http_api.Raw_Api.SectionsName = "raw_api"; if (scbin.BodyList != null) { foreach (string s in scbin.BodyList) { if (!s.Trim().EndsWith(";")) { continue; } KeyValuePair <string, string> tmpkv = Common.GetKV(s); if (string.IsNullOrEmpty(tmpkv.Key)) { continue; } string cmd = tmpkv.Key.Trim().ToLower(); switch (cmd) { case "enabled": sccout.Http_api.Raw_Api.Enabled = Common.str2bool(tmpkv.Value); break; case "allow_reload": sccout.Http_api.Raw_Api.Allow_reload = Common.str2bool(tmpkv.Value); break; case "allow_query": sccout.Http_api.Raw_Api.Allow_query = Common.str2bool(tmpkv.Value); break; case "allow_update": sccout.Http_api.Raw_Api.Allow_update = Common.str2bool(tmpkv.Value); break; } } } } } }
public static void Render(SectionBody scbin, SrsSystemConfClass sccout, string instanceName = "") { if (sccout.Http_api == null) { sccout.Http_api = new SrsHttpApiConfClass(); } sccout.Http_api.SectionsName = "http_api"; if (scbin.BodyList != null) { foreach (string s in scbin.BodyList) { if (!s.Trim().EndsWith(";")) { continue; } KeyValuePair <string, string> tmpkv = Common.GetKV(s); if (string.IsNullOrEmpty(tmpkv.Key)) { continue; } string cmd = tmpkv.Key.Trim().ToLower(); switch (cmd) { case "enabled": sccout.Http_api.Enabled = Common.str2bool(tmpkv.Value); break; case "listen": sccout.Http_api.Listen = Common.str2ushort(tmpkv.Value); break; case "crossdomain": sccout.Http_api.Crossdomain = Common.str2bool(tmpkv.Value); break; case "device_id": break; } } } if (scbin.SubSections != null && scbin.SubSections.Count > 0) { foreach (SectionBody scb in scbin.SubSections) { Render_RawApi(scb, sccout); } } }
static void Main(string[] args) { /*打包发布成单一的可执行文件 手工在项目目录里运行:dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true * win-x64是目标平台,比如可以osx-x64,linux-x64等 * PublishSingleFile true发布成单一文件,PublishTrimmed true ,压缩 可防破解*/ SrsConfigParse.LoadSrsConfObject("/Users/qiuzhouwei/test.conf"); //加载配置文件 SrsConfigParse.Parse(); //分析配置文件 SrsConfigParse.Trim(); //配置去重 SrsSystemConfClass srs = new SrsSystemConfClass(); //创建SRS配置实例 SrsConfigParse.Render(SrsConfigParse.RootSection, srs); //写入SRS配置实例 SrsConfigParse.Render(SrsConfigParse.RootSection, srs); //写入SRS配置实例 Console.WriteLine(SrsConfigBuild.Build(srs, "conf/full1.conf")); //重建配置文件,可输出文件 Console.Read(); Console.WriteLine("end!"); }
public static void Render(SectionBody scbin, SrsSystemConfClass sccout, string instanceName = "") { if (sccout.Heartbeat == null) { sccout.Heartbeat = new SrsHeartbeatConfClass(); } sccout.Heartbeat.SectionsName = "heartbeat"; if (scbin.BodyList != null) { foreach (string s in scbin.BodyList) { if (!s.Trim().EndsWith(";")) { continue; } KeyValuePair <string, string> tmpkv = Common.GetKV(s); if (string.IsNullOrEmpty(tmpkv.Key)) { continue; } string cmd = tmpkv.Key.Trim().ToLower(); switch (cmd) { case "enabled": sccout.Heartbeat.Enabled = Common.str2bool(tmpkv.Value); break; case "interval": sccout.Heartbeat.Interval = Common.str2float(tmpkv.Value); break; case "url": sccout.Heartbeat.Url = tmpkv.Value; break; case "device_id": sccout.Heartbeat.Device_id = tmpkv.Value; break; case "summaries": sccout.Heartbeat.Summaries = Common.str2bool(tmpkv.Value); break; } } } }
public static void Render_BlackHole(SectionBody scbin, SrsSystemConfClass sccout, string instanceName = "") { if (sccout.Rtc_server?.Black_hole == null) { if (sccout.Rtc_server != null) { sccout.Rtc_server.Black_hole = new BlackHole(); } } if (sccout.Rtc_server != null) { if (sccout.Rtc_server.Black_hole != null) { sccout.Rtc_server.Black_hole.SectionsName = "black_hole"; if (scbin.BodyList != null) { foreach (string s in scbin.BodyList) { if (!s.Trim().EndsWith(";")) { continue; } KeyValuePair <string, string> tmpkv = Common.GetKV(s); if (string.IsNullOrEmpty(tmpkv.Key)) { continue; } string cmd = tmpkv.Key.Trim().ToLower(); switch (cmd) { case "enabled": sccout.Rtc_server.Black_hole.Enabled = Common.str2bool(tmpkv.Value); break; case "publisher": sccout.Rtc_server.Black_hole.Publisher = tmpkv.Value; break; } } } } } }
public static void Render(SectionBody scbin, SrsSystemConfClass sccout, string instanceName = "") { if (sccout.Http_server == null) { sccout.Http_server = new SrsHttpServerConfClass(); } sccout.Http_server.SectionsName = "http_server"; if (scbin.BodyList != null) { foreach (string s in scbin.BodyList) { if (!s.Trim().EndsWith(";")) { continue; } KeyValuePair <string, string> tmpkv = Common.GetKV(s); if (string.IsNullOrEmpty(tmpkv.Key)) { continue; } string cmd = tmpkv.Key.Trim().ToLower(); switch (cmd) { case "enabled": sccout.Http_server.Enabled = Common.str2bool(tmpkv.Value); break; case "listen": sccout.Http_server.Listen = Common.str2ushort(tmpkv.Value); break; case "dir": sccout.Http_server.Dir = tmpkv.Value; break; case "crossdomain": sccout.Http_server.Crossdomain = Common.str2bool(tmpkv.Value); break; } } } }
public static void Render(SectionBody scbin, SrsSystemConfClass sccout, string instanceName = "") { if (sccout.Kafka == null) { sccout.Kafka = new SrsKafkaConfClass(); } sccout.Kafka.SectionsName = "kafka"; if (scbin.BodyList != null) { foreach (string s in scbin.BodyList) { if (!s.Trim().EndsWith(";")) { continue; } KeyValuePair <string, string> tmpkv = Common.GetKV(s); if (string.IsNullOrEmpty(tmpkv.Key)) { continue; } string cmd = tmpkv.Key.Trim().ToLower(); switch (cmd) { case "enabled": sccout.Kafka.Enabled = Common.str2bool(tmpkv.Value); break; case "brokers": sccout.Kafka.Brokers = tmpkv.Value; break; case "topic": sccout.Kafka.Topic = tmpkv.Value; break; } } } }
public static string Build(SrsSystemConfClass sccout, string filepath = "") { string output_heartbeat = ""; string output_httpserver = ""; string output_httpapi = ""; string output_kafka = ""; string output_rtcserver = ""; string output_srtserver = ""; string output_stats = ""; string output_streamcaster = ""; string output_vhost = ""; string output = ""; string segmentSpace = paddingSegment(0).Value; foreach (PropertyInfo p in sccout.GetType().GetProperties()) { object?obj = p.GetValue(sccout); if (obj == null) { continue; } if (p.Name.ToLower().Trim() == "sectionsname" || p.Name.ToLower().Trim() == "instancename") { 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?)) { if (obj != null) { if (p.PropertyType == typeof(bool?)) { string s = ""; s = Common.GetBoolStr(p, sccout); string sTmp = segmentSpace + p.Name.ToLower().Trim() + "\t" + s + ";"; output += (sTmp + "\r\n"); } else { string sTmp = segmentSpace + p.Name.ToLower().Trim() + "\t" + obj + ";"; output += (sTmp + "\r\n"); } } } } foreach (PropertyInfo p in sccout.GetType().GetProperties()) //循环非基础类型数据,为了保证基础类型数据在顶上 { object?obj = p.GetValue(sccout); if (obj == null) { continue; } if (p.Name.ToLower().Trim() == "sectionsname" || p.Name.ToLower().Trim() == "instancename") { continue; } if (p.PropertyType == typeof(SrsHeartbeatConfClass)) { write_SubOnly(sccout.Heartbeat, out output_heartbeat, 1); output = output + output_heartbeat; } if (p.PropertyType == typeof(SrsHttpApiConfClass)) { write_HttpApi(sccout.Http_api, out output_httpapi, 1); output = output + output_httpapi; } if (p.PropertyType == typeof(SrsHttpServerConfClass)) { write_SubOnly(sccout.Http_server, out output_httpserver, 1); output = output + output_httpserver; } if (p.PropertyType == typeof(SrsKafkaConfClass)) { write_SubOnly(sccout.Kafka, out output_kafka, 1); output = output + output_kafka; } if (p.PropertyType == typeof(SrsRtcServerConfClass)) { write_RtcServer(sccout.Rtc_server, out output_rtcserver, 1); output = output + output_rtcserver; } if (p.PropertyType == typeof(SrsSrtServerConfClass)) { write_SubOnly(sccout.Srt_server, out output_srtserver, 1); output = output + output_srtserver; } if (p.PropertyType == typeof(SrsStatsConfClass)) { write_SubOnly(sccout.Stats, out output_stats, 1); output = output + output_stats; } if (p.PropertyType == typeof(List <SrsStreamCasterConfClass>)) { if (sccout.Stream_casters != null) { foreach (SrsStreamCasterConfClass s in sccout.Stream_casters) { List <Type> types = new List <Type>(); types.Add(typeof(CasterEnum?)); write_StreamCaster(s, out output_streamcaster, 1, types); output = output + output_streamcaster; } } } if (p.PropertyType == typeof(List <SrsvHostConfClass>)) { if (sccout.Vhosts != null) { foreach (SrsvHostConfClass s in sccout.Vhosts) { write_Vhost(s, out output_vhost, 1); output = output + output_vhost; } } } } if (!string.IsNullOrEmpty(filepath)) { File.WriteAllText(filepath, output); } return(output); }
public static void Render(SectionBody scbin, SrsSystemConfClass sccout, string instanceName = "") { sccout.SectionsName = "root"; if (scbin.BodyList != null) { foreach (string s in scbin.BodyList) { if (!s.Trim().EndsWith(";")) { continue; } KeyValuePair <string, string> tmpkv = Common.GetKV(s); if (string.IsNullOrEmpty(tmpkv.Key)) { continue; } string cmd = tmpkv.Key.Trim().ToLower(); switch (cmd) { /*case "deviceid": * sccout.DeviceId = tmpkv.Value; * break;*/ case "listen": sccout.Listen = Common.str2ushort(tmpkv.Value); break; case "pid": sccout.Pid = tmpkv.Value; break; case "chunk_size": sccout.Chunk_size = Common.str2ushort(tmpkv.Value); break; case "ff_log_dir": sccout.Ff_log_dir = tmpkv.Value; break; case "ff_log_level": sccout.Ff_log_level = tmpkv.Value; break; case "srs_log_tank": sccout.Srs_log_tank = tmpkv.Value; break; case "srs_log_level": sccout.Srs_log_level = tmpkv.Value; break; case "srs_log_file": sccout.Srs_log_file = tmpkv.Value; break; case "max_connections": sccout.Max_connections = Common.str2ushort(tmpkv.Value); break; case "daemon": sccout.Daemon = Common.str2bool(tmpkv.Value); break; case "utc_time": sccout.Utc_time = Common.str2bool(tmpkv.Value); break; case "pithy_print_ms": sccout.Pithy_print_ms = Common.str2int(tmpkv.Value); break; case "work_dir": sccout.Work_dir = tmpkv.Value; break; case "asprocess": sccout.Asprocess = Common.str2bool(tmpkv.Value); break; case "empty_ip_ok": sccout.Empty_ip_ok = Common.str2bool(tmpkv.Value); break; case "grace_start_wait": sccout.Grace_start_wait = Common.str2int(tmpkv.Value); break; case "grace_final_wait": sccout.Grace_final_wait = Common.str2int(tmpkv.Value); break; case "force_grace_quit": sccout.Force_grace_quit = Common.str2bool(tmpkv.Value); break; case "disable_daemon_for_docker": sccout.Disable_daemon_for_docker = Common.str2bool(tmpkv.Value); break; case "inotify_auto_reload": sccout.Inotify_auto_reload = Common.str2bool(tmpkv.Value); break; case "auto_reload_for_docker": sccout.Auto_reload_for_docker = Common.str2bool(tmpkv.Value); break; case "tcmalloc_release_rate": sccout.Tcmalloc_release_rate = Common.str2float(tmpkv.Value); break; } } } }
public static void Render(SectionBody scbin, SrsSystemConfClass sccout, string instanceName = "") { if (sccout.Stream_casters == null) { sccout.Stream_casters = new List <SrsStreamCasterConfClass>(); } if (null != sccout.Stream_casters.Find(s => s.InstanceName == instanceName)) { return; //filter the same streamcaster instance } SrsStreamCasterConfClass sccc = new SrsStreamCasterConfClass(); if (scbin.BodyList != null) { foreach (string s in scbin.BodyList) { if (!s.Trim().EndsWith(";")) { continue; } KeyValuePair <string, string> tmpkv = Common.GetKV(s); if (string.IsNullOrEmpty(tmpkv.Key)) { continue; } sccc.InstanceName = instanceName; sccc.SectionsName = "stream_caster"; string cmd = tmpkv.Key.Trim().ToLower(); switch (cmd) { case "enabled": sccc.Enabled = Common.str2bool(tmpkv.Value); break; case "caster": sccc.Caster = (CasterEnum)Enum.Parse(typeof(CasterEnum), tmpkv.Value); break; case "output": sccc.Output = tmpkv.Value; break; case "listen": sccc.Listen = Common.str2ushort(tmpkv.Value); break; case "rtp_port_min": sccc.Rtp_port_min = Common.str2ushort(tmpkv.Value); break; case "rtp_port_max": sccc.Rtp_port_max = Common.str2ushort(tmpkv.Value); break; case "host": sccc.Host = tmpkv.Value; break; case "audio_enable": sccc.Audio_enable = Common.str2bool(tmpkv.Value); break; case "wait_keyframe": sccc.Wait_keyframe = Common.str2bool(tmpkv.Value); break; case "rtp_idle_timeout": sccc.Rtp_idle_timeout = Common.str2ushort(tmpkv.Value); break; case "auto_create_channel": sccc.Auto_create_channel = Common.str2bool(tmpkv.Value); break; case "jitterbuffer_enable": sccc.Jitterbuffer_Enable = Common.str2bool(tmpkv.Value); break; } } } if (scbin.SubSections != null) { foreach (SectionBody scb in scbin.SubSections) { Render_Sip(scb, sccc); } } sccout.Stream_casters.Add(sccc); }
public static void Render(SectionBody scbin, SrsSystemConfClass sccout, string instanceName = "") { if (sccout.Rtc_server == null) { sccout.Rtc_server = new SrsRtcServerConfClass(); } sccout.Rtc_server.SectionsName = "rtc_server"; if (scbin.BodyList != null) { foreach (string s in scbin.BodyList) { if (!s.Trim().EndsWith(";")) { continue; } KeyValuePair <string, string> tmpkv = Common.GetKV(s); if (string.IsNullOrEmpty(tmpkv.Key)) { continue; } string cmd = tmpkv.Key.Trim().ToLower(); switch (cmd) { case "enabled": sccout.Rtc_server.Enabled = Common.str2bool(tmpkv.Value); break; case "listen": sccout.Rtc_server.Listen = Common.str2ushort(tmpkv.Value); break; case "candidate": sccout.Rtc_server.Candidate = tmpkv.Value; break; case "ecdsa": sccout.Rtc_server.Ecdsa = Common.str2bool(tmpkv.Value); break; case "sendmmsg": sccout.Rtc_server.Sendmmsg = Common.str2ushort(tmpkv.Value); break; case "encrypt": sccout.Rtc_server.Encrypt = Common.str2bool(tmpkv.Value); break; case "reuseport": sccout.Rtc_server.Reuseport = Common.str2ushort(tmpkv.Value); break; case "merge_nalus": sccout.Rtc_server.Merge_nalus = Common.str2bool(tmpkv.Value); break; case "gso": sccout.Rtc_server.Gso = Common.str2bool(tmpkv.Value); break; case "padding": sccout.Rtc_server.Padding = Common.str2ushort(tmpkv.Value); break; case "perf_stat": sccout.Rtc_server.Perf_stat = Common.str2bool(tmpkv.Value); break; case "queue_length": sccout.Rtc_server.Queue_length = Common.str2ushort(tmpkv.Value); break; } } } if (scbin.SubSections != null && scbin.SubSections.Count > 0) { foreach (SectionBody scb in scbin.SubSections) { Render_BlackHole(scb, sccout); } } }