正在显示
2 个修改的文件
包含
411 行增加
和
406 行删除
| @@ -765,6 +765,91 @@ void SrsConfig::print_help(char** argv) | @@ -765,6 +765,91 @@ void SrsConfig::print_help(char** argv) | ||
| 765 | argv[0]); | 765 | argv[0]); |
| 766 | } | 766 | } |
| 767 | 767 | ||
| 768 | +bool SrsConfig::get_deamon() | ||
| 769 | +{ | ||
| 770 | + srs_assert(root); | ||
| 771 | + | ||
| 772 | + SrsConfDirective* conf = root->get("daemon"); | ||
| 773 | + if (conf && conf->arg0() == "off") { | ||
| 774 | + return false; | ||
| 775 | + } | ||
| 776 | + | ||
| 777 | + return true; | ||
| 778 | +} | ||
| 779 | + | ||
| 780 | +int SrsConfig::get_max_connections() | ||
| 781 | +{ | ||
| 782 | + srs_assert(root); | ||
| 783 | + | ||
| 784 | + SrsConfDirective* conf = root->get("max_connections"); | ||
| 785 | + if (!conf || conf->arg0().empty()) { | ||
| 786 | + return 2000; | ||
| 787 | + } | ||
| 788 | + | ||
| 789 | + return ::atoi(conf->arg0().c_str()); | ||
| 790 | +} | ||
| 791 | + | ||
| 792 | +SrsConfDirective* SrsConfig::get_listen() | ||
| 793 | +{ | ||
| 794 | + return root->get("listen"); | ||
| 795 | +} | ||
| 796 | + | ||
| 797 | +string SrsConfig::get_pid_file() | ||
| 798 | +{ | ||
| 799 | + SrsConfDirective* conf = root->get("pid"); | ||
| 800 | + | ||
| 801 | + if (!conf) { | ||
| 802 | + return SRS_CONF_DEFAULT_PID_FILE; | ||
| 803 | + } | ||
| 804 | + | ||
| 805 | + return conf->arg0(); | ||
| 806 | +} | ||
| 807 | + | ||
| 808 | +int SrsConfig::get_pithy_print_publish() | ||
| 809 | +{ | ||
| 810 | + SrsConfDirective* pithy = root->get("pithy_print"); | ||
| 811 | + if (!pithy) { | ||
| 812 | + return SRS_STAGE_PUBLISH_USER_INTERVAL_MS; | ||
| 813 | + } | ||
| 814 | + | ||
| 815 | + pithy = pithy->get("publish"); | ||
| 816 | + if (!pithy) { | ||
| 817 | + return SRS_STAGE_PUBLISH_USER_INTERVAL_MS; | ||
| 818 | + } | ||
| 819 | + | ||
| 820 | + return ::atoi(pithy->arg0().c_str()); | ||
| 821 | +} | ||
| 822 | + | ||
| 823 | +int SrsConfig::get_pithy_print_forwarder() | ||
| 824 | +{ | ||
| 825 | + SrsConfDirective* pithy = root->get("pithy_print"); | ||
| 826 | + if (!pithy) { | ||
| 827 | + return SRS_STAGE_FORWARDER_INTERVAL_MS; | ||
| 828 | + } | ||
| 829 | + | ||
| 830 | + pithy = pithy->get("forwarder"); | ||
| 831 | + if (!pithy) { | ||
| 832 | + return SRS_STAGE_FORWARDER_INTERVAL_MS; | ||
| 833 | + } | ||
| 834 | + | ||
| 835 | + return ::atoi(pithy->arg0().c_str()); | ||
| 836 | +} | ||
| 837 | + | ||
| 838 | +int SrsConfig::get_pithy_print_hls() | ||
| 839 | +{ | ||
| 840 | + SrsConfDirective* pithy = root->get("pithy_print"); | ||
| 841 | + if (!pithy) { | ||
| 842 | + return SRS_STAGE_HLS_INTERVAL_MS; | ||
| 843 | + } | ||
| 844 | + | ||
| 845 | + pithy = pithy->get("hls"); | ||
| 846 | + if (!pithy) { | ||
| 847 | + return SRS_STAGE_HLS_INTERVAL_MS; | ||
| 848 | + } | ||
| 849 | + | ||
| 850 | + return ::atoi(pithy->arg0().c_str()); | ||
| 851 | +} | ||
| 852 | + | ||
| 768 | SrsConfDirective* SrsConfig::get_vhost(string vhost) | 853 | SrsConfDirective* SrsConfig::get_vhost(string vhost) |
| 769 | { | 854 | { |
| 770 | srs_assert(root); | 855 | srs_assert(root); |
| @@ -939,167 +1024,366 @@ bool SrsConfig::get_vhost_enabled(SrsConfDirective* vhost) | @@ -939,167 +1024,366 @@ bool SrsConfig::get_vhost_enabled(SrsConfDirective* vhost) | ||
| 939 | return true; | 1024 | return true; |
| 940 | } | 1025 | } |
| 941 | 1026 | ||
| 942 | -SrsConfDirective* SrsConfig::get_transcode(string vhost, string scope) | 1027 | +bool SrsConfig::get_gop_cache(string vhost) |
| 943 | { | 1028 | { |
| 944 | SrsConfDirective* conf = get_vhost(vhost); | 1029 | SrsConfDirective* conf = get_vhost(vhost); |
| 945 | 1030 | ||
| 946 | if (!conf) { | 1031 | if (!conf) { |
| 947 | - return NULL; | ||
| 948 | - } | ||
| 949 | - | ||
| 950 | - SrsConfDirective* transcode = conf->get("transcode"); | ||
| 951 | - if (!transcode) { | ||
| 952 | - return NULL; | ||
| 953 | - } | ||
| 954 | - | ||
| 955 | - if (transcode->arg0() == scope) { | ||
| 956 | - return transcode; | ||
| 957 | - } | ||
| 958 | - | ||
| 959 | - return NULL; | ||
| 960 | -} | ||
| 961 | - | ||
| 962 | -bool SrsConfig::get_transcode_enabled(SrsConfDirective* transcode) | ||
| 963 | -{ | ||
| 964 | - if (!transcode) { | ||
| 965 | - return false; | 1032 | + return true; |
| 966 | } | 1033 | } |
| 967 | 1034 | ||
| 968 | - SrsConfDirective* conf = transcode->get("enabled"); | ||
| 969 | - if (!conf || conf->arg0() != "on") { | 1035 | + conf = conf->get("gop_cache"); |
| 1036 | + if (conf && conf->arg0() == "off") { | ||
| 970 | return false; | 1037 | return false; |
| 971 | } | 1038 | } |
| 972 | 1039 | ||
| 973 | return true; | 1040 | return true; |
| 974 | } | 1041 | } |
| 975 | 1042 | ||
| 976 | -string SrsConfig::get_transcode_ffmpeg(SrsConfDirective* transcode) | 1043 | +bool SrsConfig::get_atc(string vhost) |
| 977 | { | 1044 | { |
| 978 | - if (!transcode) { | ||
| 979 | - return ""; | ||
| 980 | - } | ||
| 981 | - | ||
| 982 | - SrsConfDirective* conf = transcode->get("ffmpeg"); | ||
| 983 | - if (!conf) { | ||
| 984 | - return ""; | ||
| 985 | - } | ||
| 986 | - | ||
| 987 | - return conf->arg0(); | ||
| 988 | -} | 1045 | + SrsConfDirective* conf = get_vhost(vhost); |
| 989 | 1046 | ||
| 990 | -void SrsConfig::get_transcode_engines(SrsConfDirective* transcode, std::vector<SrsConfDirective*>& engines) | ||
| 991 | -{ | ||
| 992 | - if (!transcode) { | ||
| 993 | - return; | 1047 | + if (!conf) { |
| 1048 | + return true; | ||
| 994 | } | 1049 | } |
| 995 | 1050 | ||
| 996 | - for (int i = 0; i < (int)transcode->directives.size(); i++) { | ||
| 997 | - SrsConfDirective* conf = transcode->directives[i]; | ||
| 998 | - | ||
| 999 | - if (conf->name == "engine") { | ||
| 1000 | - engines.push_back(conf); | ||
| 1001 | - } | 1051 | + conf = conf->get("atc"); |
| 1052 | + if (conf && conf->arg0() == "on") { | ||
| 1053 | + return true; | ||
| 1002 | } | 1054 | } |
| 1003 | 1055 | ||
| 1004 | - return; | 1056 | + return false; |
| 1005 | } | 1057 | } |
| 1006 | 1058 | ||
| 1007 | -bool SrsConfig::get_engine_enabled(SrsConfDirective* engine) | 1059 | +double SrsConfig::get_queue_length(string vhost) |
| 1008 | { | 1060 | { |
| 1009 | - if (!engine) { | ||
| 1010 | - return false; | 1061 | + SrsConfDirective* conf = get_vhost(vhost); |
| 1062 | + | ||
| 1063 | + if (!conf) { | ||
| 1064 | + return SRS_CONF_DEFAULT_QUEUE_LENGTH; | ||
| 1011 | } | 1065 | } |
| 1012 | 1066 | ||
| 1013 | - SrsConfDirective* conf = engine->get("enabled"); | ||
| 1014 | - if (!conf || conf->arg0() != "on") { | ||
| 1015 | - return false; | 1067 | + conf = conf->get("queue_length"); |
| 1068 | + if (!conf || conf->arg0().empty()) { | ||
| 1069 | + return SRS_CONF_DEFAULT_QUEUE_LENGTH; | ||
| 1016 | } | 1070 | } |
| 1017 | 1071 | ||
| 1018 | - return true; | 1072 | + return ::atoi(conf->arg0().c_str()); |
| 1019 | } | 1073 | } |
| 1020 | 1074 | ||
| 1021 | -string SrsConfig::get_engine_vcodec(SrsConfDirective* engine) | 1075 | +SrsConfDirective* SrsConfig::get_forward(string vhost) |
| 1022 | { | 1076 | { |
| 1023 | - if (!engine) { | ||
| 1024 | - return ""; | ||
| 1025 | - } | ||
| 1026 | - | ||
| 1027 | - SrsConfDirective* conf = engine->get("vcodec"); | 1077 | + SrsConfDirective* conf = get_vhost(vhost); |
| 1078 | + | ||
| 1028 | if (!conf) { | 1079 | if (!conf) { |
| 1029 | - return ""; | 1080 | + return NULL; |
| 1030 | } | 1081 | } |
| 1031 | 1082 | ||
| 1032 | - return conf->arg0(); | 1083 | + return conf->get("forward"); |
| 1033 | } | 1084 | } |
| 1034 | 1085 | ||
| 1035 | -int SrsConfig::get_engine_vbitrate(SrsConfDirective* engine) | 1086 | +SrsConfDirective* SrsConfig::get_refer(string vhost) |
| 1036 | { | 1087 | { |
| 1037 | - if (!engine) { | ||
| 1038 | - return 0; | ||
| 1039 | - } | ||
| 1040 | - | ||
| 1041 | - SrsConfDirective* conf = engine->get("vbitrate"); | 1088 | + SrsConfDirective* conf = get_vhost(vhost); |
| 1089 | + | ||
| 1042 | if (!conf) { | 1090 | if (!conf) { |
| 1043 | - return 0; | 1091 | + return NULL; |
| 1044 | } | 1092 | } |
| 1045 | 1093 | ||
| 1046 | - return ::atoi(conf->arg0().c_str()); | 1094 | + return conf->get("refer"); |
| 1047 | } | 1095 | } |
| 1048 | 1096 | ||
| 1049 | -double SrsConfig::get_engine_vfps(SrsConfDirective* engine) | 1097 | +SrsConfDirective* SrsConfig::get_refer_play(string vhost) |
| 1050 | { | 1098 | { |
| 1051 | - if (!engine) { | ||
| 1052 | - return 0; | ||
| 1053 | - } | ||
| 1054 | - | ||
| 1055 | - SrsConfDirective* conf = engine->get("vfps"); | 1099 | + SrsConfDirective* conf = get_vhost(vhost); |
| 1100 | + | ||
| 1056 | if (!conf) { | 1101 | if (!conf) { |
| 1057 | - return 0; | 1102 | + return NULL; |
| 1058 | } | 1103 | } |
| 1059 | 1104 | ||
| 1060 | - return ::atof(conf->arg0().c_str()); | 1105 | + return conf->get("refer_play"); |
| 1061 | } | 1106 | } |
| 1062 | 1107 | ||
| 1063 | -int SrsConfig::get_engine_vwidth(SrsConfDirective* engine) | 1108 | +SrsConfDirective* SrsConfig::get_refer_publish(string vhost) |
| 1064 | { | 1109 | { |
| 1065 | - if (!engine) { | ||
| 1066 | - return 0; | ||
| 1067 | - } | ||
| 1068 | - | ||
| 1069 | - SrsConfDirective* conf = engine->get("vwidth"); | 1110 | + SrsConfDirective* conf = get_vhost(vhost); |
| 1111 | + | ||
| 1070 | if (!conf) { | 1112 | if (!conf) { |
| 1071 | - return 0; | 1113 | + return NULL; |
| 1072 | } | 1114 | } |
| 1073 | 1115 | ||
| 1074 | - return ::atoi(conf->arg0().c_str()); | 1116 | + return conf->get("refer_publish"); |
| 1075 | } | 1117 | } |
| 1076 | 1118 | ||
| 1077 | -int SrsConfig::get_engine_vheight(SrsConfDirective* engine) | 1119 | +int SrsConfig::get_chunk_size(const std::string &vhost) |
| 1078 | { | 1120 | { |
| 1079 | - if (!engine) { | ||
| 1080 | - return 0; | 1121 | + SrsConfDirective* conf = get_vhost(vhost); |
| 1122 | + | ||
| 1123 | + if (!conf) { | ||
| 1124 | + return SRS_CONF_DEFAULT_CHUNK_SIZE; | ||
| 1081 | } | 1125 | } |
| 1082 | - | ||
| 1083 | - SrsConfDirective* conf = engine->get("vheight"); | 1126 | + |
| 1127 | + conf = conf->get("chunk_size"); | ||
| 1084 | if (!conf) { | 1128 | if (!conf) { |
| 1085 | - return 0; | 1129 | + // vhost does not specify the chunk size, |
| 1130 | + // use the global instead. | ||
| 1131 | + conf = root->get("chunk_size"); | ||
| 1132 | + if (!conf) { | ||
| 1133 | + return SRS_CONF_DEFAULT_CHUNK_SIZE; | ||
| 1134 | + } | ||
| 1135 | + | ||
| 1136 | + return ::atoi(conf->arg0().c_str()); | ||
| 1086 | } | 1137 | } |
| 1087 | - | 1138 | + |
| 1088 | return ::atoi(conf->arg0().c_str()); | 1139 | return ::atoi(conf->arg0().c_str()); |
| 1089 | } | 1140 | } |
| 1090 | 1141 | ||
| 1091 | -int SrsConfig::get_engine_vthreads(SrsConfDirective* engine) | 1142 | +bool SrsConfig::get_bw_check_enabled(const string &vhost) |
| 1092 | { | 1143 | { |
| 1093 | - if (!engine) { | ||
| 1094 | - return 0; | 1144 | + SrsConfDirective* conf = get_vhost(vhost); |
| 1145 | + | ||
| 1146 | + if (!conf) { | ||
| 1147 | + return false; | ||
| 1095 | } | 1148 | } |
| 1096 | - | ||
| 1097 | - SrsConfDirective* conf = engine->get("vthreads"); | 1149 | + |
| 1150 | + conf = conf->get("bandcheck"); | ||
| 1098 | if (!conf) { | 1151 | if (!conf) { |
| 1099 | - return 0; | 1152 | + return false; |
| 1100 | } | 1153 | } |
| 1101 | - | ||
| 1102 | - return ::atoi(conf->arg0().c_str()); | 1154 | + |
| 1155 | + conf = conf->get("enabled"); | ||
| 1156 | + if (!conf || conf->arg0() != "on") { | ||
| 1157 | + return false; | ||
| 1158 | + } | ||
| 1159 | + | ||
| 1160 | + return true; | ||
| 1161 | +} | ||
| 1162 | + | ||
| 1163 | +string SrsConfig::get_bw_check_key(const string &vhost) | ||
| 1164 | +{ | ||
| 1165 | + SrsConfDirective* conf = get_vhost(vhost); | ||
| 1166 | + | ||
| 1167 | + if (!conf) { | ||
| 1168 | + return ""; | ||
| 1169 | + } | ||
| 1170 | + | ||
| 1171 | + conf = conf->get("bandcheck"); | ||
| 1172 | + if (!conf) { | ||
| 1173 | + return ""; | ||
| 1174 | + } | ||
| 1175 | + | ||
| 1176 | + conf = conf->get("key"); | ||
| 1177 | + if (!conf) { | ||
| 1178 | + return ""; | ||
| 1179 | + } | ||
| 1180 | + | ||
| 1181 | + return conf->arg0(); | ||
| 1182 | +} | ||
| 1183 | + | ||
| 1184 | +int SrsConfig::get_bw_check_interval_ms(const string &vhost) | ||
| 1185 | +{ | ||
| 1186 | + SrsConfDirective* conf = get_vhost(vhost); | ||
| 1187 | + | ||
| 1188 | + if (!conf) { | ||
| 1189 | + return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL; | ||
| 1190 | + } | ||
| 1191 | + | ||
| 1192 | + conf = conf->get("bandcheck"); | ||
| 1193 | + if (!conf) { | ||
| 1194 | + return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL; | ||
| 1195 | + } | ||
| 1196 | + | ||
| 1197 | + conf = conf->get("interval_ms"); | ||
| 1198 | + if (!conf) { | ||
| 1199 | + return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL; | ||
| 1200 | + } | ||
| 1201 | + | ||
| 1202 | + return ::atoi(conf->arg0().c_str()) * 1000; | ||
| 1203 | +} | ||
| 1204 | + | ||
| 1205 | +int SrsConfig::get_bw_check_limit_kbps(const string &vhost) | ||
| 1206 | +{ | ||
| 1207 | + SrsConfDirective* conf = get_vhost(vhost); | ||
| 1208 | + | ||
| 1209 | + if (!conf) { | ||
| 1210 | + return SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS; | ||
| 1211 | + } | ||
| 1212 | + | ||
| 1213 | + conf = conf->get("bandcheck"); | ||
| 1214 | + if (!conf) { | ||
| 1215 | + return SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS; | ||
| 1216 | + } | ||
| 1217 | + | ||
| 1218 | + conf = conf->get("limit_kbps"); | ||
| 1219 | + if (!conf) { | ||
| 1220 | + return SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS; | ||
| 1221 | + } | ||
| 1222 | + | ||
| 1223 | + return ::atoi(conf->arg0().c_str()); | ||
| 1224 | +} | ||
| 1225 | + | ||
| 1226 | +SrsConfDirective* SrsConfig::get_transcode(string vhost, string scope) | ||
| 1227 | +{ | ||
| 1228 | + SrsConfDirective* conf = get_vhost(vhost); | ||
| 1229 | + | ||
| 1230 | + if (!conf) { | ||
| 1231 | + return NULL; | ||
| 1232 | + } | ||
| 1233 | + | ||
| 1234 | + SrsConfDirective* transcode = conf->get("transcode"); | ||
| 1235 | + if (!transcode) { | ||
| 1236 | + return NULL; | ||
| 1237 | + } | ||
| 1238 | + | ||
| 1239 | + if (transcode->arg0() == scope) { | ||
| 1240 | + return transcode; | ||
| 1241 | + } | ||
| 1242 | + | ||
| 1243 | + return NULL; | ||
| 1244 | +} | ||
| 1245 | + | ||
| 1246 | +bool SrsConfig::get_transcode_enabled(SrsConfDirective* transcode) | ||
| 1247 | +{ | ||
| 1248 | + if (!transcode) { | ||
| 1249 | + return false; | ||
| 1250 | + } | ||
| 1251 | + | ||
| 1252 | + SrsConfDirective* conf = transcode->get("enabled"); | ||
| 1253 | + if (!conf || conf->arg0() != "on") { | ||
| 1254 | + return false; | ||
| 1255 | + } | ||
| 1256 | + | ||
| 1257 | + return true; | ||
| 1258 | +} | ||
| 1259 | + | ||
| 1260 | +string SrsConfig::get_transcode_ffmpeg(SrsConfDirective* transcode) | ||
| 1261 | +{ | ||
| 1262 | + if (!transcode) { | ||
| 1263 | + return ""; | ||
| 1264 | + } | ||
| 1265 | + | ||
| 1266 | + SrsConfDirective* conf = transcode->get("ffmpeg"); | ||
| 1267 | + if (!conf) { | ||
| 1268 | + return ""; | ||
| 1269 | + } | ||
| 1270 | + | ||
| 1271 | + return conf->arg0(); | ||
| 1272 | +} | ||
| 1273 | + | ||
| 1274 | +void SrsConfig::get_transcode_engines(SrsConfDirective* transcode, std::vector<SrsConfDirective*>& engines) | ||
| 1275 | +{ | ||
| 1276 | + if (!transcode) { | ||
| 1277 | + return; | ||
| 1278 | + } | ||
| 1279 | + | ||
| 1280 | + for (int i = 0; i < (int)transcode->directives.size(); i++) { | ||
| 1281 | + SrsConfDirective* conf = transcode->directives[i]; | ||
| 1282 | + | ||
| 1283 | + if (conf->name == "engine") { | ||
| 1284 | + engines.push_back(conf); | ||
| 1285 | + } | ||
| 1286 | + } | ||
| 1287 | + | ||
| 1288 | + return; | ||
| 1289 | +} | ||
| 1290 | + | ||
| 1291 | +bool SrsConfig::get_engine_enabled(SrsConfDirective* engine) | ||
| 1292 | +{ | ||
| 1293 | + if (!engine) { | ||
| 1294 | + return false; | ||
| 1295 | + } | ||
| 1296 | + | ||
| 1297 | + SrsConfDirective* conf = engine->get("enabled"); | ||
| 1298 | + if (!conf || conf->arg0() != "on") { | ||
| 1299 | + return false; | ||
| 1300 | + } | ||
| 1301 | + | ||
| 1302 | + return true; | ||
| 1303 | +} | ||
| 1304 | + | ||
| 1305 | +string SrsConfig::get_engine_vcodec(SrsConfDirective* engine) | ||
| 1306 | +{ | ||
| 1307 | + if (!engine) { | ||
| 1308 | + return ""; | ||
| 1309 | + } | ||
| 1310 | + | ||
| 1311 | + SrsConfDirective* conf = engine->get("vcodec"); | ||
| 1312 | + if (!conf) { | ||
| 1313 | + return ""; | ||
| 1314 | + } | ||
| 1315 | + | ||
| 1316 | + return conf->arg0(); | ||
| 1317 | +} | ||
| 1318 | + | ||
| 1319 | +int SrsConfig::get_engine_vbitrate(SrsConfDirective* engine) | ||
| 1320 | +{ | ||
| 1321 | + if (!engine) { | ||
| 1322 | + return 0; | ||
| 1323 | + } | ||
| 1324 | + | ||
| 1325 | + SrsConfDirective* conf = engine->get("vbitrate"); | ||
| 1326 | + if (!conf) { | ||
| 1327 | + return 0; | ||
| 1328 | + } | ||
| 1329 | + | ||
| 1330 | + return ::atoi(conf->arg0().c_str()); | ||
| 1331 | +} | ||
| 1332 | + | ||
| 1333 | +double SrsConfig::get_engine_vfps(SrsConfDirective* engine) | ||
| 1334 | +{ | ||
| 1335 | + if (!engine) { | ||
| 1336 | + return 0; | ||
| 1337 | + } | ||
| 1338 | + | ||
| 1339 | + SrsConfDirective* conf = engine->get("vfps"); | ||
| 1340 | + if (!conf) { | ||
| 1341 | + return 0; | ||
| 1342 | + } | ||
| 1343 | + | ||
| 1344 | + return ::atof(conf->arg0().c_str()); | ||
| 1345 | +} | ||
| 1346 | + | ||
| 1347 | +int SrsConfig::get_engine_vwidth(SrsConfDirective* engine) | ||
| 1348 | +{ | ||
| 1349 | + if (!engine) { | ||
| 1350 | + return 0; | ||
| 1351 | + } | ||
| 1352 | + | ||
| 1353 | + SrsConfDirective* conf = engine->get("vwidth"); | ||
| 1354 | + if (!conf) { | ||
| 1355 | + return 0; | ||
| 1356 | + } | ||
| 1357 | + | ||
| 1358 | + return ::atoi(conf->arg0().c_str()); | ||
| 1359 | +} | ||
| 1360 | + | ||
| 1361 | +int SrsConfig::get_engine_vheight(SrsConfDirective* engine) | ||
| 1362 | +{ | ||
| 1363 | + if (!engine) { | ||
| 1364 | + return 0; | ||
| 1365 | + } | ||
| 1366 | + | ||
| 1367 | + SrsConfDirective* conf = engine->get("vheight"); | ||
| 1368 | + if (!conf) { | ||
| 1369 | + return 0; | ||
| 1370 | + } | ||
| 1371 | + | ||
| 1372 | + return ::atoi(conf->arg0().c_str()); | ||
| 1373 | +} | ||
| 1374 | + | ||
| 1375 | +int SrsConfig::get_engine_vthreads(SrsConfDirective* engine) | ||
| 1376 | +{ | ||
| 1377 | + if (!engine) { | ||
| 1378 | + return 0; | ||
| 1379 | + } | ||
| 1380 | + | ||
| 1381 | + SrsConfDirective* conf = engine->get("vthreads"); | ||
| 1382 | + if (!conf) { | ||
| 1383 | + return 0; | ||
| 1384 | + } | ||
| 1385 | + | ||
| 1386 | + return ::atoi(conf->arg0().c_str()); | ||
| 1103 | } | 1387 | } |
| 1104 | 1388 | ||
| 1105 | string SrsConfig::get_engine_vprofile(SrsConfDirective* engine) | 1389 | string SrsConfig::get_engine_vprofile(SrsConfDirective* engine) |
| @@ -1266,89 +1550,6 @@ string SrsConfig::get_engine_output(SrsConfDirective* engine) | @@ -1266,89 +1550,6 @@ string SrsConfig::get_engine_output(SrsConfDirective* engine) | ||
| 1266 | return conf->arg0(); | 1550 | return conf->arg0(); |
| 1267 | } | 1551 | } |
| 1268 | 1552 | ||
| 1269 | -bool SrsConfig::get_deamon() | ||
| 1270 | -{ | ||
| 1271 | - srs_assert(root); | ||
| 1272 | - | ||
| 1273 | - SrsConfDirective* conf = root->get("daemon"); | ||
| 1274 | - if (conf && conf->arg0() == "off") { | ||
| 1275 | - return false; | ||
| 1276 | - } | ||
| 1277 | - | ||
| 1278 | - return true; | ||
| 1279 | -} | ||
| 1280 | - | ||
| 1281 | -int SrsConfig::get_max_connections() | ||
| 1282 | -{ | ||
| 1283 | - srs_assert(root); | ||
| 1284 | - | ||
| 1285 | - SrsConfDirective* conf = root->get("max_connections"); | ||
| 1286 | - if (!conf || conf->arg0().empty()) { | ||
| 1287 | - return 2000; | ||
| 1288 | - } | ||
| 1289 | - | ||
| 1290 | - return ::atoi(conf->arg0().c_str()); | ||
| 1291 | -} | ||
| 1292 | - | ||
| 1293 | -bool SrsConfig::get_gop_cache(string vhost) | ||
| 1294 | -{ | ||
| 1295 | - SrsConfDirective* conf = get_vhost(vhost); | ||
| 1296 | - | ||
| 1297 | - if (!conf) { | ||
| 1298 | - return true; | ||
| 1299 | - } | ||
| 1300 | - | ||
| 1301 | - conf = conf->get("gop_cache"); | ||
| 1302 | - if (conf && conf->arg0() == "off") { | ||
| 1303 | - return false; | ||
| 1304 | - } | ||
| 1305 | - | ||
| 1306 | - return true; | ||
| 1307 | -} | ||
| 1308 | - | ||
| 1309 | -bool SrsConfig::get_atc(string vhost) | ||
| 1310 | -{ | ||
| 1311 | - SrsConfDirective* conf = get_vhost(vhost); | ||
| 1312 | - | ||
| 1313 | - if (!conf) { | ||
| 1314 | - return true; | ||
| 1315 | - } | ||
| 1316 | - | ||
| 1317 | - conf = conf->get("atc"); | ||
| 1318 | - if (conf && conf->arg0() == "on") { | ||
| 1319 | - return true; | ||
| 1320 | - } | ||
| 1321 | - | ||
| 1322 | - return false; | ||
| 1323 | -} | ||
| 1324 | - | ||
| 1325 | -double SrsConfig::get_queue_length(string vhost) | ||
| 1326 | -{ | ||
| 1327 | - SrsConfDirective* conf = get_vhost(vhost); | ||
| 1328 | - | ||
| 1329 | - if (!conf) { | ||
| 1330 | - return SRS_CONF_DEFAULT_QUEUE_LENGTH; | ||
| 1331 | - } | ||
| 1332 | - | ||
| 1333 | - conf = conf->get("queue_length"); | ||
| 1334 | - if (!conf || conf->arg0().empty()) { | ||
| 1335 | - return SRS_CONF_DEFAULT_QUEUE_LENGTH; | ||
| 1336 | - } | ||
| 1337 | - | ||
| 1338 | - return ::atoi(conf->arg0().c_str()); | ||
| 1339 | -} | ||
| 1340 | - | ||
| 1341 | -SrsConfDirective* SrsConfig::get_forward(string vhost) | ||
| 1342 | -{ | ||
| 1343 | - SrsConfDirective* conf = get_vhost(vhost); | ||
| 1344 | - | ||
| 1345 | - if (!conf) { | ||
| 1346 | - return NULL; | ||
| 1347 | - } | ||
| 1348 | - | ||
| 1349 | - return conf->get("forward"); | ||
| 1350 | -} | ||
| 1351 | - | ||
| 1352 | string SrsConfig::get_srs_log_file() | 1553 | string SrsConfig::get_srs_log_file() |
| 1353 | { | 1554 | { |
| 1354 | srs_assert(root); | 1555 | srs_assert(root); |
| @@ -1553,207 +1754,6 @@ int SrsConfig::get_http_stream_listen() | @@ -1553,207 +1754,6 @@ int SrsConfig::get_http_stream_listen() | ||
| 1553 | return 8080; | 1754 | return 8080; |
| 1554 | } | 1755 | } |
| 1555 | 1756 | ||
| 1556 | -SrsConfDirective* SrsConfig::get_refer(string vhost) | ||
| 1557 | -{ | ||
| 1558 | - SrsConfDirective* conf = get_vhost(vhost); | ||
| 1559 | - | ||
| 1560 | - if (!conf) { | ||
| 1561 | - return NULL; | ||
| 1562 | - } | ||
| 1563 | - | ||
| 1564 | - return conf->get("refer"); | ||
| 1565 | -} | ||
| 1566 | - | ||
| 1567 | -SrsConfDirective* SrsConfig::get_refer_play(string vhost) | ||
| 1568 | -{ | ||
| 1569 | - SrsConfDirective* conf = get_vhost(vhost); | ||
| 1570 | - | ||
| 1571 | - if (!conf) { | ||
| 1572 | - return NULL; | ||
| 1573 | - } | ||
| 1574 | - | ||
| 1575 | - return conf->get("refer_play"); | ||
| 1576 | -} | ||
| 1577 | - | ||
| 1578 | -SrsConfDirective* SrsConfig::get_refer_publish(string vhost) | ||
| 1579 | -{ | ||
| 1580 | - SrsConfDirective* conf = get_vhost(vhost); | ||
| 1581 | - | ||
| 1582 | - if (!conf) { | ||
| 1583 | - return NULL; | ||
| 1584 | - } | ||
| 1585 | - | ||
| 1586 | - return conf->get("refer_publish"); | ||
| 1587 | -} | ||
| 1588 | - | ||
| 1589 | -SrsConfDirective* SrsConfig::get_listen() | ||
| 1590 | -{ | ||
| 1591 | - return root->get("listen"); | ||
| 1592 | -} | ||
| 1593 | - | ||
| 1594 | -string SrsConfig::get_pid_file() | ||
| 1595 | -{ | ||
| 1596 | - SrsConfDirective* conf = root->get("pid"); | ||
| 1597 | - | ||
| 1598 | - if (!conf) { | ||
| 1599 | - return SRS_CONF_DEFAULT_PID_FILE; | ||
| 1600 | - } | ||
| 1601 | - | ||
| 1602 | - return conf->arg0(); | ||
| 1603 | -} | ||
| 1604 | - | ||
| 1605 | -int SrsConfig::get_chunk_size(const std::string &vhost) | ||
| 1606 | -{ | ||
| 1607 | - SrsConfDirective* conf = get_vhost(vhost); | ||
| 1608 | - | ||
| 1609 | - if (!conf) { | ||
| 1610 | - return SRS_CONF_DEFAULT_CHUNK_SIZE; | ||
| 1611 | - } | ||
| 1612 | - | ||
| 1613 | - conf = conf->get("chunk_size"); | ||
| 1614 | - if (!conf) { | ||
| 1615 | - // vhost does not specify the chunk size, | ||
| 1616 | - // use the global instead. | ||
| 1617 | - conf = root->get("chunk_size"); | ||
| 1618 | - if (!conf) { | ||
| 1619 | - return SRS_CONF_DEFAULT_CHUNK_SIZE; | ||
| 1620 | - } | ||
| 1621 | - | ||
| 1622 | - return ::atoi(conf->arg0().c_str()); | ||
| 1623 | - } | ||
| 1624 | - | ||
| 1625 | - return ::atoi(conf->arg0().c_str()); | ||
| 1626 | -} | ||
| 1627 | - | ||
| 1628 | -int SrsConfig::get_pithy_print_publish() | ||
| 1629 | -{ | ||
| 1630 | - SrsConfDirective* pithy = root->get("pithy_print"); | ||
| 1631 | - if (!pithy) { | ||
| 1632 | - return SRS_STAGE_PUBLISH_USER_INTERVAL_MS; | ||
| 1633 | - } | ||
| 1634 | - | ||
| 1635 | - pithy = pithy->get("publish"); | ||
| 1636 | - if (!pithy) { | ||
| 1637 | - return SRS_STAGE_PUBLISH_USER_INTERVAL_MS; | ||
| 1638 | - } | ||
| 1639 | - | ||
| 1640 | - return ::atoi(pithy->arg0().c_str()); | ||
| 1641 | -} | ||
| 1642 | - | ||
| 1643 | -int SrsConfig::get_pithy_print_forwarder() | ||
| 1644 | -{ | ||
| 1645 | - SrsConfDirective* pithy = root->get("pithy_print"); | ||
| 1646 | - if (!pithy) { | ||
| 1647 | - return SRS_STAGE_FORWARDER_INTERVAL_MS; | ||
| 1648 | - } | ||
| 1649 | - | ||
| 1650 | - pithy = pithy->get("forwarder"); | ||
| 1651 | - if (!pithy) { | ||
| 1652 | - return SRS_STAGE_FORWARDER_INTERVAL_MS; | ||
| 1653 | - } | ||
| 1654 | - | ||
| 1655 | - return ::atoi(pithy->arg0().c_str()); | ||
| 1656 | -} | ||
| 1657 | - | ||
| 1658 | -int SrsConfig::get_pithy_print_hls() | ||
| 1659 | -{ | ||
| 1660 | - SrsConfDirective* pithy = root->get("pithy_print"); | ||
| 1661 | - if (!pithy) { | ||
| 1662 | - return SRS_STAGE_HLS_INTERVAL_MS; | ||
| 1663 | - } | ||
| 1664 | - | ||
| 1665 | - pithy = pithy->get("hls"); | ||
| 1666 | - if (!pithy) { | ||
| 1667 | - return SRS_STAGE_HLS_INTERVAL_MS; | ||
| 1668 | - } | ||
| 1669 | - | ||
| 1670 | - return ::atoi(pithy->arg0().c_str()); | ||
| 1671 | -} | ||
| 1672 | - | ||
| 1673 | -bool SrsConfig::get_bw_check_enabled(const string &vhost) | ||
| 1674 | -{ | ||
| 1675 | - SrsConfDirective* conf = get_vhost(vhost); | ||
| 1676 | - | ||
| 1677 | - if (!conf) { | ||
| 1678 | - return false; | ||
| 1679 | - } | ||
| 1680 | - | ||
| 1681 | - conf = conf->get("bandcheck"); | ||
| 1682 | - if (!conf) { | ||
| 1683 | - return false; | ||
| 1684 | - } | ||
| 1685 | - | ||
| 1686 | - conf = conf->get("enabled"); | ||
| 1687 | - if (!conf || conf->arg0() != "on") { | ||
| 1688 | - return false; | ||
| 1689 | - } | ||
| 1690 | - | ||
| 1691 | - return true; | ||
| 1692 | -} | ||
| 1693 | - | ||
| 1694 | -string SrsConfig::get_bw_check_key(const string &vhost) | ||
| 1695 | -{ | ||
| 1696 | - SrsConfDirective* conf = get_vhost(vhost); | ||
| 1697 | - | ||
| 1698 | - if (!conf) { | ||
| 1699 | - return ""; | ||
| 1700 | - } | ||
| 1701 | - | ||
| 1702 | - conf = conf->get("bandcheck"); | ||
| 1703 | - if (!conf) { | ||
| 1704 | - return ""; | ||
| 1705 | - } | ||
| 1706 | - | ||
| 1707 | - conf = conf->get("key"); | ||
| 1708 | - if (!conf) { | ||
| 1709 | - return ""; | ||
| 1710 | - } | ||
| 1711 | - | ||
| 1712 | - return conf->arg0(); | ||
| 1713 | -} | ||
| 1714 | - | ||
| 1715 | -int SrsConfig::get_bw_check_interval_ms(const string &vhost) | ||
| 1716 | -{ | ||
| 1717 | - SrsConfDirective* conf = get_vhost(vhost); | ||
| 1718 | - | ||
| 1719 | - if (!conf) { | ||
| 1720 | - return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL; | ||
| 1721 | - } | ||
| 1722 | - | ||
| 1723 | - conf = conf->get("bandcheck"); | ||
| 1724 | - if (!conf) { | ||
| 1725 | - return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL; | ||
| 1726 | - } | ||
| 1727 | - | ||
| 1728 | - conf = conf->get("interval_ms"); | ||
| 1729 | - if (!conf) { | ||
| 1730 | - return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL; | ||
| 1731 | - } | ||
| 1732 | - | ||
| 1733 | - return ::atoi(conf->arg0().c_str()) * 1000; | ||
| 1734 | -} | ||
| 1735 | - | ||
| 1736 | -int SrsConfig::get_bw_check_limit_kbps(const string &vhost) | ||
| 1737 | -{ | ||
| 1738 | - SrsConfDirective* conf = get_vhost(vhost); | ||
| 1739 | - | ||
| 1740 | - if (!conf) { | ||
| 1741 | - return SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS; | ||
| 1742 | - } | ||
| 1743 | - | ||
| 1744 | - conf = conf->get("bandcheck"); | ||
| 1745 | - if (!conf) { | ||
| 1746 | - return SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS; | ||
| 1747 | - } | ||
| 1748 | - | ||
| 1749 | - conf = conf->get("limit_kbps"); | ||
| 1750 | - if (!conf) { | ||
| 1751 | - return SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS; | ||
| 1752 | - } | ||
| 1753 | - | ||
| 1754 | - return ::atoi(conf->arg0().c_str()); | ||
| 1755 | -} | ||
| 1756 | - | ||
| 1757 | int SrsConfig::get_pithy_print_encoder() | 1757 | int SrsConfig::get_pithy_print_encoder() |
| 1758 | { | 1758 | { |
| 1759 | SrsConfDirective* pithy = root->get("encoder"); | 1759 | SrsConfDirective* pithy = root->get("encoder"); |
| @@ -116,6 +116,18 @@ private: | @@ -116,6 +116,18 @@ private: | ||
| 116 | virtual int parse_file(const char* filename); | 116 | virtual int parse_file(const char* filename); |
| 117 | virtual int parse_argv(int& i, char** argv); | 117 | virtual int parse_argv(int& i, char** argv); |
| 118 | virtual void print_help(char** argv); | 118 | virtual void print_help(char** argv); |
| 119 | +// global section | ||
| 120 | +public: | ||
| 121 | + virtual bool get_deamon(); | ||
| 122 | + virtual int get_max_connections(); | ||
| 123 | + virtual SrsConfDirective* get_listen(); | ||
| 124 | + virtual std::string get_pid_file(); | ||
| 125 | + virtual int get_pithy_print_publish(); | ||
| 126 | + virtual int get_pithy_print_forwarder(); | ||
| 127 | + virtual int get_pithy_print_encoder(); | ||
| 128 | + virtual int get_pithy_print_hls(); | ||
| 129 | + virtual int get_pithy_print_play(); | ||
| 130 | +// vhost section | ||
| 119 | public: | 131 | public: |
| 120 | virtual SrsConfDirective* get_vhost(std::string vhost); | 132 | virtual SrsConfDirective* get_vhost(std::string vhost); |
| 121 | virtual bool get_vhost_enabled(std::string vhost); | 133 | virtual bool get_vhost_enabled(std::string vhost); |
| @@ -126,6 +138,22 @@ public: | @@ -126,6 +138,22 @@ public: | ||
| 126 | virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost); | 138 | virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost); |
| 127 | virtual SrsConfDirective* get_vhost_on_play(std::string vhost); | 139 | virtual SrsConfDirective* get_vhost_on_play(std::string vhost); |
| 128 | virtual SrsConfDirective* get_vhost_on_stop(std::string vhost); | 140 | virtual SrsConfDirective* get_vhost_on_stop(std::string vhost); |
| 141 | + virtual bool get_gop_cache(std::string vhost); | ||
| 142 | + virtual bool get_atc(std::string vhost); | ||
| 143 | + virtual double get_queue_length(std::string vhost); | ||
| 144 | + virtual SrsConfDirective* get_forward(std::string vhost); | ||
| 145 | + virtual SrsConfDirective* get_refer(std::string vhost); | ||
| 146 | + virtual SrsConfDirective* get_refer_play(std::string vhost); | ||
| 147 | + virtual SrsConfDirective* get_refer_publish(std::string vhost); | ||
| 148 | + virtual int get_chunk_size(const std::string& vhost); | ||
| 149 | +// bwct(bandwidth check tool) section | ||
| 150 | +public: | ||
| 151 | + virtual bool get_bw_check_enabled(const std::string& vhost); | ||
| 152 | + virtual std::string get_bw_check_key(const std::string& vhost); | ||
| 153 | + virtual int get_bw_check_interval_ms(const std::string& vhost); | ||
| 154 | + virtual int get_bw_check_limit_kbps(const std::string& vhost); | ||
| 155 | +// vhost transcode section | ||
| 156 | +public: | ||
| 129 | virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope); | 157 | virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope); |
| 130 | virtual bool get_transcode_enabled(SrsConfDirective* transcode); | 158 | virtual bool get_transcode_enabled(SrsConfDirective* transcode); |
| 131 | virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode); | 159 | virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode); |
| @@ -147,12 +175,6 @@ public: | @@ -147,12 +175,6 @@ public: | ||
| 147 | virtual int get_engine_achannels(SrsConfDirective* engine); | 175 | virtual int get_engine_achannels(SrsConfDirective* engine); |
| 148 | virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams); | 176 | virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams); |
| 149 | virtual std::string get_engine_output(SrsConfDirective* engine); | 177 | virtual std::string get_engine_output(SrsConfDirective* engine); |
| 150 | - virtual bool get_deamon(); | ||
| 151 | - virtual int get_max_connections(); | ||
| 152 | - virtual bool get_gop_cache(std::string vhost); | ||
| 153 | - virtual bool get_atc(std::string vhost); | ||
| 154 | - virtual double get_queue_length(std::string vhost); | ||
| 155 | - virtual SrsConfDirective* get_forward(std::string vhost); | ||
| 156 | // log section | 178 | // log section |
| 157 | public: | 179 | public: |
| 158 | virtual bool get_srs_log_tank_file(); | 180 | virtual bool get_srs_log_tank_file(); |
| @@ -179,23 +201,6 @@ private: | @@ -179,23 +201,6 @@ private: | ||
| 179 | public: | 201 | public: |
| 180 | virtual bool get_http_stream_enabled(); | 202 | virtual bool get_http_stream_enabled(); |
| 181 | virtual int get_http_stream_listen(); | 203 | virtual int get_http_stream_listen(); |
| 182 | -// others | ||
| 183 | -public: | ||
| 184 | - virtual SrsConfDirective* get_refer(std::string vhost); | ||
| 185 | - virtual SrsConfDirective* get_refer_play(std::string vhost); | ||
| 186 | - virtual SrsConfDirective* get_refer_publish(std::string vhost); | ||
| 187 | - virtual SrsConfDirective* get_listen(); | ||
| 188 | - virtual std::string get_pid_file(); | ||
| 189 | - virtual int get_chunk_size(const std::string& vhost); | ||
| 190 | - virtual int get_pithy_print_publish(); | ||
| 191 | - virtual int get_pithy_print_forwarder(); | ||
| 192 | - virtual int get_pithy_print_encoder(); | ||
| 193 | - virtual int get_pithy_print_hls(); | ||
| 194 | - virtual int get_pithy_print_play(); | ||
| 195 | - virtual bool get_bw_check_enabled(const std::string& vhost); | ||
| 196 | - virtual std::string get_bw_check_key(const std::string& vhost); | ||
| 197 | - virtual int get_bw_check_interval_ms(const std::string& vhost); | ||
| 198 | - virtual int get_bw_check_limit_kbps(const std::string& vhost); | ||
| 199 | }; | 204 | }; |
| 200 | 205 | ||
| 201 | /** | 206 | /** |
-
请 注册 或 登录 后发表评论