srs_app_config.cpp
132.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
/*
The MIT License (MIT)
Copyright (c) 2013-2015 SRS(ossrs)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_app_config.hpp>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
// file operations.
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <vector>
#include <algorithm>
using namespace std;
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_rtmp_utility.hpp>
#include <srs_core_autofree.hpp>
#include <srs_app_source.hpp>
#include <srs_kernel_file.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_performance.hpp>
#include "../../objs/version.h"
#ifndef __USE_GNU
#define __USE_GNU
#endif
#include<sched.h>
using namespace _srs_internal;
// the version to identify the core.
const char* _srs_version = "XCORE-"RTMP_SIG_SRS_SERVER": "VERSION_STRING;
#define SRS_WIKI_URL_LOG "https://github.com/ossrs/srs/wiki/v1_CN_SrsLog"
// when user config an invalid value, macros to perfer true or false.
#define SRS_CONF_PERFER_FALSE(conf_arg) conf_arg == "on"
#define SRS_CONF_PERFER_TRUE(conf_arg) conf_arg != "off"
///////////////////////////////////////////////////////////
// default consts values
///////////////////////////////////////////////////////////
#define SRS_CONF_DEFAULT_PID_FILE "./objs/srs.pid"
#define SRS_CONF_DEFAULT_LOG_FILE "./objs/srs.log"
#define SRS_CONF_DEFAULT_LOG_LEVEL "trace"
#define SRS_CONF_DEFAULT_LOG_TANK_CONSOLE "console"
#define SRS_CONF_DEFAULT_COFNIG_FILE "conf/srs.conf"
#define SRS_CONF_DEFAULT_FF_LOG_DIR "./objs"
#define SRS_CONF_DEFAULT_UTC_TIME false
#define SRS_CONF_DEFAULT_MAX_CONNECTIONS 1000
#define SRS_CONF_DEFAULT_HLS_PATH "./objs/nginx/html"
#define SRS_CONF_DEFAULT_HLS_M3U8_FILE "[app]/[stream].m3u8"
#define SRS_CONF_DEFAULT_HLS_TOTAL_M3U8_FILE ""
#define SRS_CONF_DEFAULT_HLS_TOTAL_FILE ""
#define SRS_CONF_DEFAULT_HLS_TS_FILE "[app]/[stream]-[seq].ts"
#define SRS_CONF_DEFAULT_HLS_TS_FLOOR false
#define SRS_CONF_DEFAULT_HLS_FRAGMENT 10
#define SRS_CONF_DEFAULT_HLS_TD_RATIO 1.5
#define SRS_CONF_DEFAULT_HLS_AOF_RATIO 2.0
#define SRS_CONF_DEFAULT_HLS_WINDOW 60
#define SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE "continue"
#define SRS_CONF_DEFAULT_HLS_ON_ERROR_DISCONNECT "disconnect"
#define SRS_CONF_DEFAULT_HLS_ON_ERROR_CONTINUE "continue"
#define SRS_CONF_DEFAULT_HLS_ON_ERROR SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE
#define SRS_CONF_DEFAULT_HLS_ACODEC "aac"
#define SRS_CONF_DEFAULT_HLS_VCODEC "h264"
#define SRS_CONF_DEFAULT_HLS_CLEANUP true
#define SRS_CONF_DEFAULT_HLS_WAIT_KEYFRAME true
#define SRS_CONF_DEFAULT_HLS_NB_NOTIFY 64
#define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html/[app]/[stream].[timestamp].flv"
#define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session"
#define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment"
#define SRS_CONF_DEFAULT_DVR_PLAN_APPEND "append"
#define SRS_CONF_DEFAULT_DVR_PLAN SRS_CONF_DEFAULT_DVR_PLAN_SESSION
#define SRS_CONF_DEFAULT_DVR_DURATION 30
#define SRS_CONF_DEFAULT_TIME_JITTER "full"
#define SRS_CONF_DEFAULT_ATC_AUTO true
#define SRS_CONF_DEFAULT_MIX_CORRECT false
// in seconds, the paused queue length.
#define SRS_CONF_DEFAULT_PAUSED_LENGTH 10
// the interval in seconds for bandwidth check
#define SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL 30
// the interval in seconds for bandwidth check
#define SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS 1000
#define SRS_CONF_DEFAULT_HTTP_MOUNT "[vhost]/"
#define SRS_CONF_DEFAULT_HTTP_REMUX_MOUNT "[vhost]/[app]/[stream].flv"
#define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH
#define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 0
#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT "8080"
#define SRS_CONF_DEFAULT_HTTP_API_PORT "1985"
#define SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN true
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED false
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INTERVAL 9.9
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_URL "http://"SRS_CONSTS_LOCALHOST":8085/api/v1/servers"
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_SUMMARIES false
#define SRS_CONF_DEFAULT_SECURITY_ENABLED false
#define SRS_CONF_DEFAULT_STREAM_CASTER_ENABLED false
#define SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP "mpegts_over_udp"
#define SRS_CONF_DEFAULT_STREAM_CASTER_RTSP "rtsp"
#define SRS_CONF_DEFAULT_STREAM_CASTER_FLV "flv"
#define SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX 0
#define SRS_CONF_DEFAULT_PITHY_PRINT_MS 10000
#define SRS_CONF_DEFAULT_INGEST_TYPE_FILE "file"
#define SRS_CONF_DEFAULT_INGEST_TYPE_STREAM "stream"
#define SRS_CONF_DEFAULT_TRANSCODE_IFORMAT "flv"
#define SRS_CONF_DEFAULT_TRANSCODE_OFORMAT "flv"
#define SRS_CONF_DEFAULT_EDGE_TOKEN_TRAVERSE false
#define SRS_CONF_DEFAULT_EDGE_TRANSFORM_VHOST "[vhost]"
// hds default value
#define SRS_CONF_DEFAULT_HDS_PATH "./objs/nginx/html"
#define SRS_CONF_DEFAULT_HDS_WINDOW (60)
#define SRS_CONF_DEFAULT_HDS_FRAGMENT (10)
// '\n'
#define SRS_LF (char)SRS_CONSTS_LF
// '\r'
#define SRS_CR (char)SRS_CONSTS_CR
bool is_common_space(char ch)
{
return (ch == ' ' || ch == '\t' || ch == SRS_CR || ch == SRS_LF);
}
SrsConfDirective::SrsConfDirective()
{
}
SrsConfDirective::~SrsConfDirective()
{
std::vector<SrsConfDirective*>::iterator it;
for (it = directives.begin(); it != directives.end(); ++it) {
SrsConfDirective* directive = *it;
srs_freep(directive);
}
directives.clear();
}
string SrsConfDirective::arg0()
{
if (args.size() > 0) {
return args.at(0);
}
return "";
}
string SrsConfDirective::arg1()
{
if (args.size() > 1) {
return args.at(1);
}
return "";
}
string SrsConfDirective::arg2()
{
if (args.size() > 2) {
return args.at(2);
}
return "";
}
SrsConfDirective* SrsConfDirective::at(int index)
{
srs_assert(index < (int)directives.size());
return directives.at(index);
}
SrsConfDirective* SrsConfDirective::get(string _name)
{
std::vector<SrsConfDirective*>::iterator it;
for (it = directives.begin(); it != directives.end(); ++it) {
SrsConfDirective* directive = *it;
if (directive->name == _name) {
return directive;
}
}
return NULL;
}
SrsConfDirective* SrsConfDirective::get(string _name, string _arg0)
{
std::vector<SrsConfDirective*>::iterator it;
for (it = directives.begin(); it != directives.end(); ++it) {
SrsConfDirective* directive = *it;
if (directive->name == _name && directive->arg0() == _arg0) {
return directive;
}
}
return NULL;
}
bool SrsConfDirective::is_vhost()
{
return name == "vhost";
}
bool SrsConfDirective::is_stream_caster()
{
return name == "stream_caster";
}
int SrsConfDirective::parse(SrsConfigBuffer* buffer)
{
return parse_conf(buffer, parse_file);
}
// see: ngx_conf_parse
int SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveType type)
{
int ret = ERROR_SUCCESS;
while (true) {
std::vector<string> args;
int line_start = 0;
ret = read_token(buffer, args, line_start);
/**
* ret maybe:
* ERROR_SYSTEM_CONFIG_INVALID error.
* ERROR_SYSTEM_CONFIG_DIRECTIVE directive terminated by ';' found
* ERROR_SYSTEM_CONFIG_BLOCK_START token terminated by '{' found
* ERROR_SYSTEM_CONFIG_BLOCK_END the '}' found
* ERROR_SYSTEM_CONFIG_EOF the config file is done
*/
if (ret == ERROR_SYSTEM_CONFIG_INVALID) {
return ret;
}
if (ret == ERROR_SYSTEM_CONFIG_BLOCK_END) {
if (type != parse_block) {
srs_error("line %d: unexpected \"}\", ret=%d", buffer->line, ret);
return ret;
}
return ERROR_SUCCESS;
}
if (ret == ERROR_SYSTEM_CONFIG_EOF) {
if (type == parse_block) {
srs_error("line %d: unexpected end of file, expecting \"}\", ret=%d", conf_line, ret);
return ret;
}
return ERROR_SUCCESS;
}
if (args.empty()) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("line %d: empty directive. ret=%d", conf_line, ret);
return ret;
}
// build directive tree.
SrsConfDirective* directive = new SrsConfDirective();
directive->conf_line = line_start;
directive->name = args[0];
args.erase(args.begin());
directive->args.swap(args);
directives.push_back(directive);
if (ret == ERROR_SYSTEM_CONFIG_BLOCK_START) {
if ((ret = directive->parse_conf(buffer, parse_block)) != ERROR_SUCCESS) {
return ret;
}
}
}
return ret;
}
// see: ngx_conf_read_token
int SrsConfDirective::read_token(SrsConfigBuffer* buffer, vector<string>& args, int& line_start)
{
int ret = ERROR_SUCCESS;
char* pstart = buffer->pos;
bool sharp_comment = false;
bool d_quoted = false;
bool s_quoted = false;
bool need_space = false;
bool last_space = true;
while (true) {
if (buffer->empty()) {
ret = ERROR_SYSTEM_CONFIG_EOF;
if (!args.empty() || !last_space) {
srs_error("line %d: unexpected end of file, expecting ; or \"}\"", buffer->line);
return ERROR_SYSTEM_CONFIG_INVALID;
}
srs_trace("config parse complete");
return ret;
}
char ch = *buffer->pos++;
if (ch == SRS_LF) {
buffer->line++;
sharp_comment = false;
}
if (sharp_comment) {
continue;
}
if (need_space) {
if (is_common_space(ch)) {
last_space = true;
need_space = false;
continue;
}
if (ch == ';') {
return ERROR_SYSTEM_CONFIG_DIRECTIVE;
}
if (ch == '{') {
return ERROR_SYSTEM_CONFIG_BLOCK_START;
}
srs_error("line %d: unexpected '%c'", buffer->line, ch);
return ERROR_SYSTEM_CONFIG_INVALID;
}
// last charecter is space.
if (last_space) {
if (is_common_space(ch)) {
continue;
}
pstart = buffer->pos - 1;
switch (ch) {
case ';':
if (args.size() == 0) {
srs_error("line %d: unexpected ';'", buffer->line);
return ERROR_SYSTEM_CONFIG_INVALID;
}
return ERROR_SYSTEM_CONFIG_DIRECTIVE;
case '{':
if (args.size() == 0) {
srs_error("line %d: unexpected '{'", buffer->line);
return ERROR_SYSTEM_CONFIG_INVALID;
}
return ERROR_SYSTEM_CONFIG_BLOCK_START;
case '}':
if (args.size() != 0) {
srs_error("line %d: unexpected '}'", buffer->line);
return ERROR_SYSTEM_CONFIG_INVALID;
}
return ERROR_SYSTEM_CONFIG_BLOCK_END;
case '#':
sharp_comment = 1;
continue;
case '"':
pstart++;
d_quoted = true;
last_space = 0;
continue;
case '\'':
pstart++;
s_quoted = true;
last_space = 0;
continue;
default:
last_space = 0;
continue;
}
} else {
// last charecter is not space
if (line_start == 0) {
line_start = buffer->line;
}
bool found = false;
if (d_quoted) {
if (ch == '"') {
d_quoted = false;
need_space = true;
found = true;
}
} else if (s_quoted) {
if (ch == '\'') {
s_quoted = false;
need_space = true;
found = true;
}
} else if (is_common_space(ch) || ch == ';' || ch == '{') {
last_space = true;
found = 1;
}
if (found) {
int len = (int)(buffer->pos - pstart);
char* aword = new char[len];
memcpy(aword, pstart, len);
aword[len - 1] = 0;
string word_str = aword;
if (!word_str.empty()) {
args.push_back(word_str);
}
srs_freepa(aword);
if (ch == ';') {
return ERROR_SYSTEM_CONFIG_DIRECTIVE;
}
if (ch == '{') {
return ERROR_SYSTEM_CONFIG_BLOCK_START;
}
}
}
}
return ret;
}
SrsConfig::SrsConfig()
{
dolphin = false;
show_help = false;
show_version = false;
test_conf = false;
root = new SrsConfDirective();
root->conf_line = 0;
root->name = "root";
_speex2aac = false;
}
SrsConfig::~SrsConfig()
{
srs_freep(root);
}
bool SrsConfig::is_dolphin()
{
return dolphin;
}
void SrsConfig::set_config_directive(SrsConfDirective* parent, string dir, string value)
{
SrsConfDirective* d = parent->get(dir);
if (!d) {
d = new SrsConfDirective();
if (!dir.empty()) {
d->name = dir;
}
parent->directives.push_back(d);
}
d->args.clear();
if (!value.empty()) {
d->args.push_back(value);
}
}
void SrsConfig::subscribe(ISrsReloadHandler* handler)
{
std::vector<ISrsReloadHandler*>::iterator it;
it = std::find(subscribes.begin(), subscribes.end(), handler);
if (it != subscribes.end()) {
return;
}
subscribes.push_back(handler);
}
void SrsConfig::unsubscribe(ISrsReloadHandler* handler)
{
std::vector<ISrsReloadHandler*>::iterator it;
it = std::find(subscribes.begin(), subscribes.end(), handler);
if (it == subscribes.end()) {
return;
}
subscribes.erase(it);
}
int SrsConfig::reload()
{
int ret = ERROR_SUCCESS;
SrsConfig conf;
if ((ret = conf.parse_file(config_file.c_str())) != ERROR_SUCCESS) {
srs_error("ignore config reloader parse file failed. ret=%d", ret);
ret = ERROR_SUCCESS;
return ret;
}
srs_info("config reloader parse file success.");
if ((ret = conf.check_config()) != ERROR_SUCCESS) {
srs_error("ignore config reloader check config failed. ret=%d", ret);
ret = ERROR_SUCCESS;
return ret;
}
return reload_conf(&conf);
}
int SrsConfig::reload_vhost(SrsConfDirective* old_root)
{
int ret = ERROR_SUCCESS;
// merge config.
std::vector<ISrsReloadHandler*>::iterator it;
// state graph
// old_vhost new_vhost
// DISABLED => ENABLED
// ENABLED => DISABLED
// ENABLED => ENABLED (modified)
// collect all vhost names
std::vector<std::string> vhosts;
for (int i = 0; i < (int)root->directives.size(); i++) {
SrsConfDirective* vhost = root->at(i);
if (vhost->name != "vhost") {
continue;
}
vhosts.push_back(vhost->arg0());
}
for (int i = 0; i < (int)old_root->directives.size(); i++) {
SrsConfDirective* vhost = old_root->at(i);
if (vhost->name != "vhost") {
continue;
}
if (root->get("vhost", vhost->arg0())) {
continue;
}
vhosts.push_back(vhost->arg0());
}
// process each vhost
for (int i = 0; i < (int)vhosts.size(); i++) {
std::string vhost = vhosts.at(i);
SrsConfDirective* old_vhost = old_root->get("vhost", vhost);
SrsConfDirective* new_vhost = root->get("vhost", vhost);
// DISABLED => ENABLED
if (!get_vhost_enabled(old_vhost) && get_vhost_enabled(new_vhost)) {
srs_trace("vhost %s added, reload it.", vhost.c_str());
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_added(vhost)) != ERROR_SUCCESS) {
srs_error("notify subscribes added "
"vhost %s failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("reload new vhost %s success.", vhost.c_str());
continue;
}
// ENABLED => DISABLED
if (get_vhost_enabled(old_vhost) && !get_vhost_enabled(new_vhost)) {
srs_trace("vhost %s removed, reload it.", vhost.c_str());
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_removed(vhost)) != ERROR_SUCCESS) {
srs_error("notify subscribes removed "
"vhost %s failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("reload removed vhost %s success.", vhost.c_str());
continue;
}
// mode, never supports reload.
// first, for the origin and edge role change is too complex.
// second, the vhosts in origin device group normally are all origin,
// they never change to edge sometimes.
// third, the origin or upnode device can always be restart,
// edge will retry and the users connected to edge are ok.
// it's ok to add or remove edge/origin vhost.
if (get_vhost_is_edge(old_vhost) != get_vhost_is_edge(new_vhost)) {
ret = ERROR_RTMP_EDGE_RELOAD;
srs_error("reload never supports mode changed. ret=%d", ret);
return ret;
}
// the auto reload configs:
// publish.parse_sps
// ENABLED => ENABLED (modified)
if (get_vhost_enabled(new_vhost) && get_vhost_enabled(old_vhost)) {
srs_trace("vhost %s maybe modified, reload its detail.", vhost.c_str());
// atc, only one per vhost
if (!srs_directive_equals(new_vhost->get("atc"), old_vhost->get("atc"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_atc(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes atc failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload atc success.", vhost.c_str());
}
// gop_cache, only one per vhost
if (!srs_directive_equals(new_vhost->get("gop_cache"), old_vhost->get("gop_cache"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_gop_cache(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes gop_cache failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload gop_cache success.", vhost.c_str());
}
// queue_length, only one per vhost
if (!srs_directive_equals(new_vhost->get("queue_length"), old_vhost->get("queue_length"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_queue_length(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes queue_length failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload queue_length success.", vhost.c_str());
}
// time_jitter, only one per vhost
if (!srs_directive_equals(new_vhost->get("time_jitter"), old_vhost->get("time_jitter"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_time_jitter(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes time_jitter failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload time_jitter success.", vhost.c_str());
}
// mix_correct, only one per vhost
if (!srs_directive_equals(new_vhost->get("mix_correct"), old_vhost->get("mix_correct"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_mix_correct(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes mix_correct failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload mix_correct success.", vhost.c_str());
}
// forward, only one per vhost
if (!srs_directive_equals(new_vhost->get("forward"), old_vhost->get("forward"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_forward(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes forward failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload forward success.", vhost.c_str());
}
// hls, only one per vhost
// @remark, the hls_on_error directly support reload.
if (!srs_directive_equals(new_vhost->get("hls"), old_vhost->get("hls"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_hls(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes hls failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload hls success.", vhost.c_str());
}
// hds reload
if (!srs_directive_equals(new_vhost->get("hds"), old_vhost->get("hds"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_hds(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes hds failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload hds success.", vhost.c_str());
}
// dvr, only one per vhost
if (!srs_directive_equals(new_vhost->get("dvr"), old_vhost->get("dvr"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_dvr(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes dvr failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload hlsdvrsuccess.", vhost.c_str());
}
// mr, only one per vhost
if (!srs_directive_equals(new_vhost->get("mr"), old_vhost->get("mr"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_mr(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes mr failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload mr success.", vhost.c_str());
}
// chunk_size, only one per vhost.
if (!srs_directive_equals(new_vhost->get("chunk_size"), old_vhost->get("chunk_size"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_chunk_size(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes chunk_size failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload chunk_size success.", vhost.c_str());
}
// mw, only one per vhost
if (!srs_directive_equals(new_vhost->get("mw_latency"), old_vhost->get("mw_latency"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_mw(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes mw failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload mw success.", vhost.c_str());
}
// smi(send_min_interval), only one per vhost
if (!srs_directive_equals(new_vhost->get("send_min_interval"), old_vhost->get("send_min_interval"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_smi(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes smi failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload smi success.", vhost.c_str());
}
// tcp_nodelay, only one per vhost
if (!srs_directive_equals(new_vhost->get("tcp_nodelay"), old_vhost->get("tcp_nodelay"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_tcp_nodelay(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes tcp_nodelay failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload tcp_nodelay success.", vhost.c_str());
}
// publish_1stpkt_timeout, only one per vhost
if (!srs_directive_equals(new_vhost->get("publish_1stpkt_timeout"), old_vhost->get("publish_1stpkt_timeout"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_p1stpt(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes p1stpt failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload p1stpt success.", vhost.c_str());
}
// publish_normal_timeout, only one per vhost
if (!srs_directive_equals(new_vhost->get("publish_normal_timeout"), old_vhost->get("publish_normal_timeout"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_pnt(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes pnt failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload pnt success.", vhost.c_str());
}
// min_latency, only one per vhost
if (!srs_directive_equals(new_vhost->get("min_latency"), old_vhost->get("min_latency"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_realtime(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes min_latency failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload min_latency success.", vhost.c_str());
}
// http, only one per vhost.
if (!srs_directive_equals(new_vhost->get("http"), old_vhost->get("http"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_http_updated()) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes http failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload http success.", vhost.c_str());
}
// http_static, only one per vhost.
// @remark, http_static introduced as alias of http.
if (!srs_directive_equals(new_vhost->get("http_static"), old_vhost->get("http_static"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_http_updated()) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes http_static failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload http_static success.", vhost.c_str());
}
// http_remux, only one per vhost.
if (!srs_directive_equals(new_vhost->get("http_remux"), old_vhost->get("http_remux"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_http_remux_updated(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes http_remux failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload http_remux success.", vhost.c_str());
}
// transcode, many per vhost.
if ((ret = reload_transcode(new_vhost, old_vhost)) != ERROR_SUCCESS) {
return ret;
}
// ingest, many per vhost.
if ((ret = reload_ingest(new_vhost, old_vhost)) != ERROR_SUCCESS) {
return ret;
}
continue;
}
srs_trace("ignore reload vhost, enabled old: %d, new: %d",
get_vhost_enabled(old_vhost), get_vhost_enabled(new_vhost));
}
return ret;
}
int SrsConfig::reload_conf(SrsConfig* conf)
{
int ret = ERROR_SUCCESS;
SrsConfDirective* old_root = root;
SrsAutoFree(SrsConfDirective, old_root);
root = conf->root;
conf->root = NULL;
// merge config.
std::vector<ISrsReloadHandler*>::iterator it;
// never support reload:
// daemon
//
// always support reload without additional code:
// chunk_size, ff_log_dir,
// bandcheck, http_hooks, heartbeat,
// token_traverse, debug_srs_upnode,
// security
// merge config: max_connections
if (!srs_directive_equals(root->get("max_connections"), old_root->get("max_connections"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_max_conns()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload max_connections failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload max_connections success.");
}
// merge config: listen
if (!srs_directive_equals(root->get("listen"), old_root->get("listen"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_listen()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload listen failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload listen success.");
}
// merge config: pid
if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_pid()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload pid failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload pid success.");
}
// merge config: srs_log_tank
if (!srs_directive_equals(root->get("srs_log_tank"), old_root->get("srs_log_tank"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_log_tank()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload srs_log_tank failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload srs_log_tank success.");
}
// merge config: srs_log_level
if (!srs_directive_equals(root->get("srs_log_level"), old_root->get("srs_log_level"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_log_level()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload srs_log_level failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload srs_log_level success.");
}
// merge config: srs_log_file
if (!srs_directive_equals(root->get("srs_log_file"), old_root->get("srs_log_file"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_log_file()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload srs_log_file failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload srs_log_file success.");
}
// merge config: utc_time
if (!srs_directive_equals(root->get("utc_time"), old_root->get("utc_time"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_utc_time()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload utc_time failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload utc_time success.");
}
// merge config: pithy_print_ms
if (!srs_directive_equals(root->get("pithy_print_ms"), old_root->get("pithy_print_ms"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_pithy_print()) != ERROR_SUCCESS) {
srs_error("notify subscribes pithy_print_ms failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload pithy_print_ms success.");
}
// merge config: http_api
if ((ret = reload_http_api(old_root)) != ERROR_SUCCESS) {
return ret;
}
// merge config: http_stream
if ((ret = reload_http_stream(old_root)) != ERROR_SUCCESS) {
return ret;
}
// TODO: FIXME: support reload stream_caster.
// merge config: vhost
if ((ret = reload_vhost(old_root)) != ERROR_SUCCESS) {
return ret;
}
set_config_static();
return ret;
}
int SrsConfig::reload_http_api(SrsConfDirective* old_root)
{
int ret = ERROR_SUCCESS;
// merge config.
std::vector<ISrsReloadHandler*>::iterator it;
// state graph
// old_http_api new_http_api
// DISABLED => ENABLED
// ENABLED => DISABLED
// ENABLED => ENABLED (modified)
SrsConfDirective* new_http_api = root->get("http_api");
SrsConfDirective* old_http_api = old_root->get("http_api");
// DISABLED => ENABLED
if (!get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {
srs_error("notify subscribes http_api disabled=>enabled failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload disabled=>enabled http_api success.");
return ret;
}
// ENABLED => DISABLED
if (get_http_api_enabled(old_http_api) && !get_http_api_enabled(new_http_api)) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_http_api_disabled()) != ERROR_SUCCESS) {
srs_error("notify subscribes http_api enabled=>disabled failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload enabled=>disabled http_api success.");
return ret;
}
// ENABLED => ENABLED (modified)
if (get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)
&& !srs_directive_equals(old_http_api, new_http_api)
) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {
srs_error("notify subscribes http_api enabled modified failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload enabled modified http_api success.");
return ret;
}
srs_trace("reload http_api not changed success.");
return ret;
}
int SrsConfig::reload_http_stream(SrsConfDirective* old_root)
{
int ret = ERROR_SUCCESS;
// merge config.
std::vector<ISrsReloadHandler*>::iterator it;
// state graph
// old_http_stream new_http_stream
// DISABLED => ENABLED
// ENABLED => DISABLED
// ENABLED => ENABLED (modified)
SrsConfDirective* new_http_stream = root->get("http_stream");
// http_stream rename to http_server in SRS2.
if (!new_http_stream) {
new_http_stream = root->get("http_server");
}
SrsConfDirective* old_http_stream = old_root->get("http_stream");
// http_stream rename to http_server in SRS2.
if (!old_http_stream) {
old_http_stream = root->get("http_server");
}
// DISABLED => ENABLED
if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_http_stream_enabled()) != ERROR_SUCCESS) {
srs_error("notify subscribes http_stream disabled=>enabled failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload disabled=>enabled http_stream success.");
return ret;
}
// ENABLED => DISABLED
if (get_http_stream_enabled(old_http_stream) && !get_http_stream_enabled(new_http_stream)) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_http_stream_disabled()) != ERROR_SUCCESS) {
srs_error("notify subscribes http_stream enabled=>disabled failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload enabled=>disabled http_stream success.");
return ret;
}
// ENABLED => ENABLED (modified)
if (get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)
&& !srs_directive_equals(old_http_stream, new_http_stream)
) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_http_stream_updated()) != ERROR_SUCCESS) {
srs_error("notify subscribes http_stream enabled modified failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload enabled modified http_stream success.");
return ret;
}
srs_trace("reload http_stream not changed success.");
return ret;
}
int SrsConfig::reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost)
{
int ret = ERROR_SUCCESS;
std::vector<SrsConfDirective*> old_transcoders;
for (int i = 0; i < (int)old_vhost->directives.size(); i++) {
SrsConfDirective* conf = old_vhost->at(i);
if (conf->name == "transcode") {
old_transcoders.push_back(conf);
}
}
std::vector<SrsConfDirective*> new_transcoders;
for (int i = 0; i < (int)new_vhost->directives.size(); i++) {
SrsConfDirective* conf = new_vhost->at(i);
if (conf->name == "transcode") {
new_transcoders.push_back(conf);
}
}
std::vector<ISrsReloadHandler*>::iterator it;
std::string vhost = new_vhost->arg0();
// to be simple:
// whatever, once tiny changed of transcode,
// restart all ffmpeg of vhost.
bool changed = false;
// discovery the removed ffmpeg.
for (int i = 0; !changed && i < (int)old_transcoders.size(); i++) {
SrsConfDirective* old_transcoder = old_transcoders.at(i);
std::string transcoder_id = old_transcoder->arg0();
// if transcoder exists in new vhost, not removed, ignore.
if (new_vhost->get("transcode", transcoder_id)) {
continue;
}
changed = true;
}
// discovery the added ffmpeg.
for (int i = 0; !changed && i < (int)new_transcoders.size(); i++) {
SrsConfDirective* new_transcoder = new_transcoders.at(i);
std::string transcoder_id = new_transcoder->arg0();
// if transcoder exists in old vhost, not added, ignore.
if (old_vhost->get("transcode", transcoder_id)) {
continue;
}
changed = true;
}
// for updated transcoders, restart them.
for (int i = 0; !changed && i < (int)new_transcoders.size(); i++) {
SrsConfDirective* new_transcoder = new_transcoders.at(i);
std::string transcoder_id = new_transcoder->arg0();
SrsConfDirective* old_transcoder = old_vhost->get("transcode", transcoder_id);
srs_assert(old_transcoder);
if (srs_directive_equals(new_transcoder, old_transcoder)) {
continue;
}
changed = true;
}
// transcode, many per vhost
if (changed) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_transcode(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes transcode failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload transcode success.", vhost.c_str());
}
return ret;
}
int SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost)
{
int ret = ERROR_SUCCESS;
std::vector<SrsConfDirective*> old_ingesters;
for (int i = 0; i < (int)old_vhost->directives.size(); i++) {
SrsConfDirective* conf = old_vhost->at(i);
if (conf->name == "ingest") {
old_ingesters.push_back(conf);
}
}
std::vector<SrsConfDirective*> new_ingesters;
for (int i = 0; i < (int)new_vhost->directives.size(); i++) {
SrsConfDirective* conf = new_vhost->at(i);
if (conf->name == "ingest") {
new_ingesters.push_back(conf);
}
}
std::vector<ISrsReloadHandler*>::iterator it;
std::string vhost = new_vhost->arg0();
// for removed ingesters, stop them.
for (int i = 0; i < (int)old_ingesters.size(); i++) {
SrsConfDirective* old_ingester = old_ingesters.at(i);
std::string ingest_id = old_ingester->arg0();
SrsConfDirective* new_ingester = new_vhost->get("ingest", ingest_id);
// ENABLED => DISABLED
if (get_ingest_enabled(old_ingester) && !get_ingest_enabled(new_ingester)) {
// notice handler ingester removed.
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_ingest_removed(vhost, ingest_id)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes ingest=%s removed failed. ret=%d",
vhost.c_str(), ingest_id.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload ingest=%s removed success.", vhost.c_str(), ingest_id.c_str());
}
}
// for added ingesters, start them.
for (int i = 0; i < (int)new_ingesters.size(); i++) {
SrsConfDirective* new_ingester = new_ingesters.at(i);
std::string ingest_id = new_ingester->arg0();
SrsConfDirective* old_ingester = old_vhost->get("ingest", ingest_id);
// DISABLED => ENABLED
if (!get_ingest_enabled(old_ingester) && get_ingest_enabled(new_ingester)) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_ingest_added(vhost, ingest_id)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes ingest=%s added failed. ret=%d",
vhost.c_str(), ingest_id.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload ingest=%s added success.", vhost.c_str(), ingest_id.c_str());
}
}
// for updated ingesters, restart them.
for (int i = 0; i < (int)new_ingesters.size(); i++) {
SrsConfDirective* new_ingester = new_ingesters.at(i);
std::string ingest_id = new_ingester->arg0();
SrsConfDirective* old_ingester = old_vhost->get("ingest", ingest_id);
// ENABLED => ENABLED
if (get_ingest_enabled(old_ingester) && get_ingest_enabled(new_ingester)) {
if (srs_directive_equals(new_ingester, old_ingester)) {
continue;
}
// notice handler ingester removed.
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_ingest_updated(vhost, ingest_id)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes ingest=%s updated failed. ret=%d",
vhost.c_str(), ingest_id.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload ingest=%s updated success.", vhost.c_str(), ingest_id.c_str());
}
}
srs_trace("ingest not changed for vhost=%s", vhost.c_str());
return ret;
}
// see: ngx_get_options
int SrsConfig::parse_options(int argc, char** argv)
{
int ret = ERROR_SUCCESS;
// argv
for (int i = 0; i < argc; i++) {
_argv.append(argv[i]);
if (i < argc - 1) {
_argv.append(" ");
}
}
// config
show_help = true;
for (int i = 1; i < argc; i++) {
if ((ret = parse_argv(i, argv)) != ERROR_SUCCESS) {
return ret;
}
}
if (show_help) {
fprintf(stderr, "%s\n", VERSION_STRING);
print_help(argv);
exit(0);
}
if (show_version) {
fprintf(stderr, "%s\n%s\n", RTMP_SIG_SRS_VERSION, VERSION_STRING);
exit(0);
}
// first hello message.
srs_trace(_srs_version);
if (config_file.empty()) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("config file not specified, see help: %s -h, ret=%d", argv[0], ret);
return ret;
}
ret = parse_file(config_file.c_str());
if (test_conf) {
// the parse_file never check the config,
// we check it when user requires check config file.
if (ret == ERROR_SUCCESS) {
ret = check_config();
}
if (ret == ERROR_SUCCESS) {
srs_trace("config file is ok");
exit(0);
} else {
srs_error("config file is invalid");
exit(ret);
}
}
////////////////////////////////////////////////////////////////////////
// check log name and level
////////////////////////////////////////////////////////////////////////
if (true) {
std::string log_filename = this->get_log_file();
if (get_log_tank_file() && log_filename.empty()) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("must specifies the file to write log to. ret=%d", ret);
return ret;
}
if (get_log_tank_file()) {
srs_trace("write log to file %s", log_filename.c_str());
srs_trace("you can: tailf %s", log_filename.c_str());
srs_trace("@see: %s", SRS_WIKI_URL_LOG);
} else {
srs_trace("write log to console");
}
}
return ret;
}
int SrsConfig::initialize_cwd()
{
int ret = ERROR_SUCCESS;
// cwd
char cwd[256];
getcwd(cwd, sizeof(cwd));
_cwd = cwd;
return ret;
}
string SrsConfig::config()
{
return config_file;
}
int SrsConfig::parse_argv(int& i, char** argv)
{
int ret = ERROR_SUCCESS;
char* p = argv[i];
if (*p++ != '-') {
show_help = true;
return ret;
}
while (*p) {
switch (*p++) {
case '?':
case 'h':
show_help = true;
break;
case 't':
show_help = false;
test_conf = true;
break;
case 'p':
dolphin = true;
if (*p) {
dolphin_rtmp_port = p;
continue;
}
if (argv[++i]) {
dolphin_rtmp_port = argv[i];
continue;
}
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("option \"-p\" requires params, ret=%d", ret);
return ret;
case 'x':
dolphin = true;
if (*p) {
dolphin_http_port = p;
continue;
}
if (argv[++i]) {
dolphin_http_port = argv[i];
continue;
}
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("option \"-x\" requires params, ret=%d", ret);
return ret;
case 'v':
case 'V':
show_help = false;
show_version = true;
break;
case 'c':
show_help = false;
if (*p) {
config_file = p;
continue;
}
if (argv[++i]) {
config_file = argv[i];
continue;
}
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("option \"-c\" requires parameter, ret=%d", ret);
return ret;
default:
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("invalid option: \"%c\", see help: %s -h, ret=%d", *(p - 1), argv[0], ret);
return ret;
}
}
return ret;
}
void SrsConfig::print_help(char** argv)
{
printf(
RTMP_SIG_SRS_SERVER" "RTMP_SIG_SRS_COPYRIGHT"\n"
"License: "RTMP_SIG_SRS_LICENSE"\n"
"Primary: "RTMP_SIG_SRS_PRIMARY"\n"
"Authors: "RTMP_SIG_SRS_AUTHROS"\n"
"Build: "SRS_AUTO_BUILD_DATE" Configuration:"SRS_AUTO_USER_CONFIGURE"\n"
"Features:"SRS_AUTO_CONFIGURE"\n""\n"
"Usage: %s [-h?vV] [[-t] -c <filename>]\n"
"\n"
"Options:\n"
" -?, -h : show this help and exit(0)\n"
" -v, -V : show version and exit(0)\n"
" -t : test configuration file, exit(error_code).\n"
" -c filename : use configuration file for SRS\n"
"For srs-dolphin:\n"
" -p rtmp-port : the rtmp port to listen.\n"
" -x http-port : the http port to listen.\n"
"\n"
RTMP_SIG_SRS_WEB"\n"
RTMP_SIG_SRS_URL"\n"
"Email: "RTMP_SIG_SRS_EMAIL"\n"
"\n"
"For example:\n"
" %s -v\n"
" %s -t -c "SRS_CONF_DEFAULT_COFNIG_FILE"\n"
" %s -c "SRS_CONF_DEFAULT_COFNIG_FILE"\n",
argv[0], argv[0], argv[0], argv[0]);
}
int SrsConfig::parse_file(const char* filename)
{
int ret = ERROR_SUCCESS;
config_file = filename;
if (config_file.empty()) {
return ERROR_SYSTEM_CONFIG_INVALID;
}
SrsConfigBuffer buffer;
if ((ret = buffer.fullfill(config_file.c_str())) != ERROR_SUCCESS) {
return ret;
}
return parse_buffer(&buffer);
}
int SrsConfig::check_config()
{
int ret = ERROR_SUCCESS;
//output _srs_version to log
srs_trace(_srs_version);
srs_trace("srs checking config...");
////////////////////////////////////////////////////////////////////////
// check empty
////////////////////////////////////////////////////////////////////////
if (root->directives.size() == 0) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("conf is empty, ret=%d", ret);
return ret;
}
////////////////////////////////////////////////////////////////////////
// check root directives.
////////////////////////////////////////////////////////////////////////
for (int i = 0; i < (int)root->directives.size(); i++) {
SrsConfDirective* conf = root->at(i);
std::string n = conf->name;
if (n != "listen" && n != "pid" && n != "chunk_size" && n != "ff_log_dir"
&& n != "srs_log_tank" && n != "srs_log_level" && n != "srs_log_file"
&& n != "max_connections" && n != "daemon" && n != "heartbeat"
&& n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
&& n != "http_stream" && n != "http_server" && n != "stream_caster"
&& n != "utc_time" && n != "work_dir" && n != "asprocess" && n != "speex2aac"
&& n != "cpu_affinity"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported directive %s, ret=%d", n.c_str(), ret);
return ret;
}
}
if (true) {
SrsConfDirective* conf = get_http_api();
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
string n = conf->at(i)->name;
if (n != "enabled" && n != "listen" && n != "crossdomain") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported http_api directive %s, ret=%d", n.c_str(), ret);
return ret;
}
}
}
if (true) {
SrsConfDirective* conf = get_http_stream();
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
string n = conf->at(i)->name;
if (n != "enabled" && n != "listen" && n != "dir") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported http_stream directive %s, ret=%d", n.c_str(), ret);
return ret;
}
}
}
if (true) {
SrsConfDirective* conf = get_heartbeart();
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
string n = conf->at(i)->name;
if (n != "enabled" && n != "interval" && n != "url"
&& n != "device_id" && n != "summaries"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported heartbeat directive %s, ret=%d", n.c_str(), ret);
return ret;
}
}
}
if (true) {
SrsConfDirective* conf = get_stats();
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
string n = conf->at(i)->name;
if (n != "network" && n != "disk") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported stats directive %s, ret=%d", n.c_str(), ret);
return ret;
}
}
}
////////////////////////////////////////////////////////////////////////
// check listen for rtmp.
////////////////////////////////////////////////////////////////////////
if (true) {
vector<string> listens = get_listens();
if (listens.size() <= 0) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("directive \"listen\" is empty, ret=%d", ret);
return ret;
}
for (int i = 0; i < (int)listens.size(); i++) {
string port = listens[i];
if (port.empty() || ::atoi(port.c_str()) <= 0) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("directive listen invalid, port=%s, ret=%d", port.c_str(), ret);
return ret;
}
}
}
////////////////////////////////////////////////////////////////////////
// check max connections
////////////////////////////////////////////////////////////////////////
if (get_max_connections() <= 0) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("directive max_connections invalid, max_connections=%d, ret=%d", get_max_connections(), ret);
return ret;
}
// check max connections of system limits
if (true) {
int nb_consumed_fds = (int)get_listens().size();
if (!get_http_api_listen().empty()) {
nb_consumed_fds++;
}
if (!get_http_stream_listen().empty()) {
nb_consumed_fds++;
}
if (get_log_tank_file()) {
nb_consumed_fds++;
}
// 0, 1, 2 for stdin, stdout and stderr.
nb_consumed_fds += 3;
int nb_connections = get_max_connections();
int nb_total = nb_connections + nb_consumed_fds;
int max_open_files = (int)sysconf(_SC_OPEN_MAX);
int nb_canbe = max_open_files - nb_consumed_fds - 1;
// for each play connections, we open a pipe(2fds) to convert SrsConsumver to io,
// refine performance, @see: https://github.com/ossrs/srs/issues/194
if (nb_total >= max_open_files) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("invalid max_connections=%d, required=%d, system limit to %d, "
"total=%d(max_connections=%d, nb_consumed_fds=%d), ret=%d. "
"you can change max_connections from %d to %d, or "
"you can login as root and set the limit: ulimit -HSn %d",
nb_connections, nb_total + 1, max_open_files,
nb_total, nb_connections, nb_consumed_fds,
ret, nb_connections, nb_canbe, nb_total + 1);
return ret;
}
}
////////////////////////////////////////////////////////////////////////
// check heartbeat
////////////////////////////////////////////////////////////////////////
if (get_heartbeat_interval() <= 0) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("directive heartbeat interval invalid, interval=%"PRId64", ret=%d",
get_heartbeat_interval(), ret);
return ret;
}
////////////////////////////////////////////////////////////////////////
// check stats
////////////////////////////////////////////////////////////////////////
if (get_stats_network() < 0) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("directive stats network invalid, network=%d, ret=%d",
get_stats_network(), ret);
return ret;
}
if (true) {
vector<std::string> ips = srs_get_local_ipv4_ips();
int index = get_stats_network();
if (index >= (int)ips.size()) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("stats network invalid, total local ip count=%d, index=%d, ret=%d",
(int)ips.size(), index, ret);
return ret;
}
srs_warn("stats network use index=%d, ip=%s", index, ips.at(index).c_str());
}
if (true) {
SrsConfDirective* conf = get_stats_disk_device();
if (conf == NULL || (int)conf->args.size() <= 0) {
srs_warn("stats disk not configed, disk iops disabled.");
} else {
string disks;
for (int i = 0; i < (int)conf->args.size(); i++) {
disks += conf->args.at(i);
disks += " ";
}
srs_warn("stats disk list: %s", disks.c_str());
}
}
////////////////////////////////////////////////////////////////////////
// check http api
////////////////////////////////////////////////////////////////////////
if (get_http_api_listen().empty()) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("directive http_api listen invalid, listen=%s, ret=%d",
get_http_api_listen().c_str(), ret);
return ret;
}
////////////////////////////////////////////////////////////////////////
// check http stream
////////////////////////////////////////////////////////////////////////
if (get_http_stream_listen().empty()) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("directive http_stream listen invalid, listen=%s, ret=%d",
get_http_stream_listen().c_str(), ret);
return ret;
}
////////////////////////////////////////////////////////////////////////
// check log name and level
////////////////////////////////////////////////////////////////////////
if (true) {
std::string log_filename = this->get_log_file();
if (get_log_tank_file() && log_filename.empty()) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("must specifies the file to write log to. ret=%d", ret);
return ret;
}
if (get_log_tank_file()) {
srs_trace("write log to file %s", log_filename.c_str());
srs_trace("you can: tailf %s", log_filename.c_str());
srs_trace("@see: %s", SRS_WIKI_URL_LOG);
} else {
srs_trace("write log to console");
}
}
////////////////////////////////////////////////////////////////////////
// check features
////////////////////////////////////////////////////////////////////////
#ifndef SRS_AUTO_HTTP_SERVER
if (get_http_stream_enabled()) {
srs_warn("http_stream is disabled by configure");
}
#endif
#ifndef SRS_AUTO_HTTP_API
if (get_http_api_enabled()) {
srs_warn("http_api is disabled by configure");
}
#endif
vector<SrsConfDirective*> stream_casters = get_stream_casters();
for (int n = 0; n < (int)stream_casters.size(); n++) {
SrsConfDirective* stream_caster = stream_casters[n];
for (int i = 0; stream_caster && i < (int)stream_caster->directives.size(); i++) {
SrsConfDirective* conf = stream_caster->at(i);
string n = conf->name;
if (n != "enabled" && n != "caster" && n != "output"
&& n != "listen" && n != "rtp_port_min" && n != "rtp_port_max"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported stream_caster directive %s, ret=%d", n.c_str(), ret);
return ret;
}
}
}
vector<SrsConfDirective*> vhosts;
get_vhosts(vhosts);
for (int n = 0; n < (int)vhosts.size(); n++) {
SrsConfDirective* vhost = vhosts[n];
for (int i = 0; vhost && i < (int)vhost->directives.size(); i++) {
SrsConfDirective* conf = vhost->at(i);
string n = conf->name;
if (n != "enabled" && n != "chunk_size"
&& n != "mode" && n != "origin" && n != "token_traverse" && n != "vhost"
&& n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks"
&& n != "gop_cache" && n != "queue_length"
&& n != "refer" && n != "refer_publish" && n != "refer_play"
&& n != "forward" && n != "transcode" && n != "bandcheck"
&& n != "forward_server_other" && n != "forward_in_turn" && n != "forward_peer" && n != "forward_append_stream_name"
&& n != "time_jitter" && n != "mix_correct"
&& n != "atc" && n != "atc_auto"
&& n != "debug_srs_upnode"
&& n != "mr" && n != "mw_latency" && n != "min_latency" && n != "publish"
&& n != "tcp_nodelay" && n != "send_min_interval" && n != "reduce_sequence_header"
&& n != "publish_1stpkt_timeout" && n != "publish_normal_timeout"
&& n != "security" && n != "http_remux"
&& n != "http" && n != "http_static"
&& n != "hds"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost directive %s, ret=%d", n.c_str(), ret);
return ret;
}
// for each sub directives of vhost.
if (n == "dvr") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "dvr_path" && m != "dvr_plan"
&& m != "dvr_duration" && m != "dvr_wait_keyframe" && m != "time_jitter"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost dvr directive %s, ret=%d", m.c_str(), ret);
return ret;
}
}
} else if (n == "mr") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "latency"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost mr directive %s, ret=%d", m.c_str(), ret);
return ret;
}
}
} else if (n == "publish") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "parse_sps"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost publish directive %s, ret=%d", m.c_str(), ret);
return ret;
}
}
} else if (n == "ingest") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "input" && m != "ffmpeg"
&& m != "engine"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost ingest directive %s, ret=%d", m.c_str(), ret);
return ret;
}
}
} else if (n == "http" || n == "http_static") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "mount" && m != "dir") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost http directive %s, ret=%d", m.c_str(), ret);
return ret;
}
}
} else if (n == "http_remux") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "mount" && m != "fast_cache" && m != "hstrs") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost http_remux directive %s, ret=%d", m.c_str(), ret);
return ret;
}
}
} else if (n == "hls") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error"
&& m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec"
&& m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify"
&& m != "hls_wait_keyframe" && m != "hls_dispose" && m != "hls_total_m3u8_file" && m != "hls_total_file"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret);
return ret;
}
// TODO: FIXME: remove it in future.
if (m == "hls_storage" || m == "hls_mount") {
srs_warn("HLS RAM is removed from SRS2 to SRS3+, please read https://github.com/ossrs/srs/issues/513.");
}
}
} else if (n == "http_hooks") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "on_connect" && m != "on_close" && m != "on_publish"
&& m != "on_unpublish" && m != "on_play" && m != "on_stop"
&& m != "on_dvr" && m != "on_hls" && m != "on_hls_notify"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost http_hooks directive %s, ret=%d", m.c_str(), ret);
return ret;
}
}
} else if (n == "forward") {
// TODO: FIXME: implements it.
/*for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "vhost" && m != "refer") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost forward directive %s, ret=%d", m.c_str(), ret);
return ret;
}
}*/
}
else if (n == "security") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
SrsConfDirective* security = conf->at(j);
string m = security->name.c_str();
if (m != "enabled" && m != "deny" && m != "allow") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost security directive %s, ret=%d", m.c_str(), ret);
return ret;
}
}
} else if (n == "transcode") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
SrsConfDirective* trans = conf->at(j);
string m = trans->name.c_str();
if (m != "enabled" && m != "ffmpeg" && m != "engine") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost transcode directive %s, ret=%d", m.c_str(), ret);
return ret;
}
if (m == "engine") {
for (int k = 0; k < (int)trans->directives.size(); k++) {
string e = trans->at(k)->name;
if (e != "enabled" && e != "vfilter" && e != "vcodec"
&& e != "vbitrate" && e != "vfps" && e != "vwidth" && e != "vheight"
&& e != "vthreads" && e != "vprofile" && e != "vpreset" && e != "vparams"
&& e != "acodec" && e != "abitrate" && e != "asample_rate" && e != "achannels"
&& e != "aparams" && e != "output"
&& e != "iformat" && e != "oformat"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost transcode engine directive %s, ret=%d", e.c_str(), ret);
return ret;
}
}
}
}
} else if (n == "bandcheck") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "key" && m != "interval" && m != "limit_kbps") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost bandcheck directive %s, ret=%d", m.c_str(), ret);
return ret;
}
}
}
}
}
// check ingest id unique.
for (int i = 0; i < (int)vhosts.size(); i++) {
SrsConfDirective* vhost = vhosts[i];
std::vector<std::string> ids;
for (int j = 0; j < (int)vhost->directives.size(); j++) {
SrsConfDirective* conf = vhost->at(j);
if (conf->name != "ingest") {
continue;
}
std::string id = conf->arg0();
for (int k = 0; k < (int)ids.size(); k++) {
if (id == ids.at(k)) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("directive \"ingest\" id duplicated, vhost=%s, id=%s, ret=%d",
vhost->name.c_str(), id.c_str(), ret);
return ret;
}
}
ids.push_back(id);
}
}
////////////////////////////////////////////////////////////////////////
// check chunk size
////////////////////////////////////////////////////////////////////////
if (get_global_chunk_size() < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE
|| get_global_chunk_size() > SRS_CONSTS_RTMP_MAX_CHUNK_SIZE
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("directive chunk_size invalid, chunk_size=%d, must in [%d, %d], ret=%d",
get_global_chunk_size(), SRS_CONSTS_RTMP_MIN_CHUNK_SIZE,
SRS_CONSTS_RTMP_MAX_CHUNK_SIZE, ret);
return ret;
}
for (int i = 0; i < (int)vhosts.size(); i++) {
SrsConfDirective* vhost = vhosts[i];
if (get_chunk_size(vhost->arg0()) < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE
|| get_chunk_size(vhost->arg0()) > SRS_CONSTS_RTMP_MAX_CHUNK_SIZE
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("directive vhost %s chunk_size invalid, chunk_size=%d, must in [%d, %d], ret=%d",
vhost->arg0().c_str(), get_chunk_size(vhost->arg0()), SRS_CONSTS_RTMP_MIN_CHUNK_SIZE,
SRS_CONSTS_RTMP_MAX_CHUNK_SIZE, ret);
return ret;
}
}
for (int i = 0; i < (int)vhosts.size(); i++) {
SrsConfDirective* vhost = vhosts[i];
srs_assert(vhost != NULL);
#ifndef SRS_AUTO_DVR
if (get_dvr_enabled(vhost->arg0())) {
srs_warn("dvr of vhost %s is disabled by configure", vhost->arg0().c_str());
}
#endif
#ifndef SRS_AUTO_HLS
if (get_hls_enabled(vhost->arg0())) {
srs_warn("hls of vhost %s is disabled by configure", vhost->arg0().c_str());
}
#endif
#ifndef SRS_AUTO_HTTP_CALLBACK
if (get_vhost_http_hooks_enabled(vhost->arg0())) {
srs_warn("http_hooks of vhost %s is disabled by configure", vhost->arg0().c_str());
}
#endif
#ifndef SRS_AUTO_TRANSCODE
if (get_transcode_enabled(get_transcode(vhost->arg0(), ""))) {
srs_warn("transcode of vhost %s is disabled by configure", vhost->arg0().c_str());
}
#endif
#ifndef SRS_AUTO_INGEST
vector<SrsConfDirective*> ingesters = get_ingesters(vhost->arg0());
for (int j = 0; j < (int)ingesters.size(); j++) {
SrsConfDirective* ingest = ingesters[j];
if (get_ingest_enabled(ingest)) {
srs_warn("ingest %s of vhost %s is disabled by configure",
ingest->arg0().c_str(), vhost->arg0().c_str()
);
}
}
#endif
// TODO: FIXME: required http server when hls storage is ram or both.
}
// asprocess conflict with daemon
if (get_asprocess() && get_deamon()) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("daemon conflict with asprocess, ret=%d", ret);
return ret;
}
set_config_static();
return ret;
}
void SrsConfig::set_config_static()
{
if(this != _srs_config){
return;
}
SrsConfDirective* conf = root->get("speex2aac");
if(conf){
if(conf->arg0() == "on"){
_speex2aac = true;
}
else
_speex2aac = false;
}
else
_speex2aac = false;
conf = root->get("cpu_affinity");
int cpu_index = -1;
if(conf){
cpu_index = atoi(conf->arg0().c_str());
}
if(cpu_index >= 0){
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(cpu_index, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask) == -1){
srs_error("error when set cpu affinity to CPU:%d",cpu_index);
}
else{
srs_trace("success in set cpu affinity to CPU:%d",cpu_index);
}
}
}
int SrsConfig::parse_buffer(SrsConfigBuffer* buffer)
{
int ret = ERROR_SUCCESS;
if ((ret = root->parse(buffer)) != ERROR_SUCCESS) {
return ret;
}
// mock by dolphin mode.
// for the dolphin will start srs with specified params.
if (dolphin) {
// for RTMP.
set_config_directive(root, "listen", dolphin_rtmp_port);
// for HTTP
set_config_directive(root, "http_server", "");
SrsConfDirective* http_server = root->get("http_server");
set_config_directive(http_server, "enabled", "on");
set_config_directive(http_server, "listen", dolphin_http_port);
// others.
set_config_directive(root, "daemon", "off");
set_config_directive(root, "srs_log_tank", "console");
}
return ret;
}
string SrsConfig::cwd()
{
return _cwd;
}
string SrsConfig::argv()
{
return _argv;
}
bool SrsConfig::get_deamon()
{
srs_assert(root);
SrsConfDirective* conf = root->get("daemon");
if (!conf || conf->arg0().empty()) {
return true;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
SrsConfDirective* SrsConfig::get_root()
{
return root;
}
int SrsConfig::get_max_connections()
{
srs_assert(root);
SrsConfDirective* conf = root->get("max_connections");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_MAX_CONNECTIONS;
}
return ::atoi(conf->arg0().c_str());
}
vector<string> SrsConfig::get_listens()
{
std::vector<string> ports;
SrsConfDirective* conf = root->get("listen");
if (!conf) {
return ports;
}
for (int i = 0; i < (int)conf->args.size(); i++) {
ports.push_back(conf->args.at(i));
}
return ports;
}
string SrsConfig::get_pid_file()
{
SrsConfDirective* conf = root->get("pid");
if (!conf) {
return SRS_CONF_DEFAULT_PID_FILE;
}
return conf->arg0();
}
int SrsConfig::get_pithy_print_ms()
{
SrsConfDirective* pithy = root->get("pithy_print_ms");
if (!pithy || pithy->arg0().empty()) {
return SRS_CONF_DEFAULT_PITHY_PRINT_MS;
}
return ::atoi(pithy->arg0().c_str());
}
bool SrsConfig::get_utc_time()
{
SrsConfDirective* conf = root->get("utc_time");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_UTC_TIME;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_work_dir() {
static string DEFAULT = "./";
SrsConfDirective* conf = root->get("work_dir");
if( !conf || conf->arg0().empty()) {
return DEFAULT;
}
return conf->arg0();
}
bool SrsConfig::get_asprocess()
{
static bool DEFAULT = false;
SrsConfDirective* conf = root->get("asprocess");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
vector<SrsConfDirective*> SrsConfig::get_stream_casters()
{
srs_assert(root);
std::vector<SrsConfDirective*> stream_casters;
for (int i = 0; i < (int)root->directives.size(); i++) {
SrsConfDirective* conf = root->at(i);
if (!conf->is_stream_caster()) {
continue;
}
stream_casters.push_back(conf);
}
return stream_casters;
}
bool SrsConfig::get_stream_caster_enabled(SrsConfDirective* sc)
{
srs_assert(sc);
SrsConfDirective* conf = sc->get("enabled");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_STREAM_CASTER_ENABLED;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_stream_caster_engine(SrsConfDirective* sc)
{
srs_assert(sc);
SrsConfDirective* conf = sc->get("caster");
if (!conf || conf->arg0().empty()) {
return "";
}
return conf->arg0();
}
string SrsConfig::get_stream_caster_output(SrsConfDirective* sc)
{
srs_assert(sc);
SrsConfDirective* conf = sc->get("output");
if (!conf || conf->arg0().empty()) {
return "";
}
return conf->arg0();
}
int SrsConfig::get_stream_caster_listen(SrsConfDirective* sc)
{
srs_assert(sc);
SrsConfDirective* conf = sc->get("listen");
if (!conf || conf->arg0().empty()) {
return 0;
}
return ::atoi(conf->arg0().c_str());
}
int SrsConfig::get_stream_caster_rtp_port_min(SrsConfDirective* sc)
{
srs_assert(sc);
SrsConfDirective* conf = sc->get("rtp_port_min");
if (!conf || conf->arg0().empty()) {
return 0;
}
return ::atoi(conf->arg0().c_str());
}
int SrsConfig::get_stream_caster_rtp_port_max(SrsConfDirective* sc)
{
srs_assert(sc);
SrsConfDirective* conf = sc->get("rtp_port_max");
if (!conf || conf->arg0().empty()) {
return 0;
}
return ::atoi(conf->arg0().c_str());
}
SrsConfDirective* SrsConfig::get_vhost(string vhost)
{
srs_assert(root);
for (int i = 0; i < (int)root->directives.size(); i++) {
SrsConfDirective* conf = root->at(i);
if (!conf->is_vhost()) {
continue;
}
if (conf->arg0() == vhost) {
return conf;
}
}
if (vhost != SRS_CONSTS_RTMP_DEFAULT_VHOST) {
return get_vhost(SRS_CONSTS_RTMP_DEFAULT_VHOST);
}
return NULL;
}
void SrsConfig::get_vhosts(vector<SrsConfDirective*>& vhosts)
{
srs_assert(root);
for (int i = 0; i < (int)root->directives.size(); i++) {
SrsConfDirective* conf = root->at(i);
if (!conf->is_vhost()) {
continue;
}
vhosts.push_back(conf);
}
}
bool SrsConfig::get_vhost_enabled(string vhost)
{
SrsConfDirective* vhost_conf = get_vhost(vhost);
return get_vhost_enabled(vhost_conf);
}
bool SrsConfig::get_vhost_enabled(SrsConfDirective* vhost)
{
if (!vhost) {
return false;
}
SrsConfDirective* conf = vhost->get("enabled");
if (!conf || conf->arg0().empty()) {
return true;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
bool SrsConfig::get_gop_cache(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_PERF_GOP_CACHE;
}
conf = conf->get("gop_cache");
if (!conf || conf->arg0().empty()) {
return SRS_PERF_GOP_CACHE;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
bool SrsConfig::get_debug_srs_upnode(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return true;
}
conf = conf->get("debug_srs_upnode");
if (!conf || conf->arg0().empty()) {
return true;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
bool SrsConfig::get_atc(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return false;
}
conf = conf->get("atc");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
bool SrsConfig::get_atc_auto(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_CONF_DEFAULT_ATC_AUTO;
}
conf = conf->get("atc_auto");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_ATC_AUTO;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
int SrsConfig::get_time_jitter(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
std::string time_jitter = SRS_CONF_DEFAULT_TIME_JITTER;
if (conf) {
conf = conf->get("time_jitter");
if (conf && !conf->arg0().empty()) {
time_jitter = conf->arg0();
}
}
return _srs_time_jitter_string2int(time_jitter);
}
bool SrsConfig::get_mix_correct(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_CONF_DEFAULT_MIX_CORRECT;
}
conf = conf->get("mix_correct");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_MIX_CORRECT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
double SrsConfig::get_queue_length(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_PERF_PLAY_QUEUE;
}
conf = conf->get("queue_length");
if (!conf || conf->arg0().empty()) {
return SRS_PERF_PLAY_QUEUE;
}
return ::atoi(conf->arg0().c_str());
}
SrsConfDirective* SrsConfig::get_refer(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("refer");
}
SrsConfDirective* SrsConfig::get_refer_play(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("refer_play");
}
SrsConfDirective* SrsConfig::get_refer_publish(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("refer_publish");
}
int SrsConfig::get_chunk_size(string vhost)
{
if (vhost.empty()) {
return get_global_chunk_size();
}
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
// vhost does not specify the chunk size,
// use the global instead.
return get_global_chunk_size();
}
conf = conf->get("chunk_size");
if (!conf || conf->arg0().empty()) {
// vhost does not specify the chunk size,
// use the global instead.
return get_global_chunk_size();
}
return ::atoi(conf->arg0().c_str());
}
bool SrsConfig::get_parse_sps(string vhost)
{
static bool DEFAULT = true;
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("publish");
if (!conf) {
return DEFAULT;
}
conf = conf->get("parse_sps");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
bool SrsConfig::get_mr_enabled(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_PERF_MR_ENABLED;
}
conf = conf->get("mr");
if (!conf) {
return SRS_PERF_MR_ENABLED;
}
conf = conf->get("enabled");
if (!conf || conf->arg0().empty()) {
return SRS_PERF_MR_ENABLED;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
int SrsConfig::get_mr_sleep_ms(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_PERF_MR_SLEEP;
}
conf = conf->get("mr");
if (!conf) {
return SRS_PERF_MR_SLEEP;
}
conf = conf->get("latency");
if (!conf || conf->arg0().empty()) {
return SRS_PERF_MR_SLEEP;
}
return ::atoi(conf->arg0().c_str());
}
int SrsConfig::get_mw_sleep_ms(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_PERF_MW_SLEEP;
}
conf = conf->get("mw_latency");
if (!conf || conf->arg0().empty()) {
return SRS_PERF_MW_SLEEP;
}
return ::atoi(conf->arg0().c_str());
}
bool SrsConfig::get_realtime_enabled(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_PERF_MIN_LATENCY_ENABLED;
}
conf = conf->get("min_latency");
if (!conf || conf->arg0().empty()) {
return SRS_PERF_MIN_LATENCY_ENABLED;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
bool SrsConfig::get_tcp_nodelay(string vhost)
{
static bool DEFAULT = false;
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("tcp_nodelay");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
double SrsConfig::get_send_min_interval(string vhost)
{
static double DEFAULT = 0.0;
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("send_min_interval");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atof(conf->arg0().c_str());
}
bool SrsConfig::get_reduce_sequence_header(string vhost)
{
static bool DEFAULT = false;
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("reduce_sequence_header");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
int SrsConfig::get_publish_1stpkt_timeout(string vhost)
{
// when no msg recevied for publisher, use larger timeout.
static int DEFAULT = 20000;
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("publish_1stpkt_timeout");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
int SrsConfig::get_publish_normal_timeout(string vhost)
{
// the timeout for publish recv.
// we must use more smaller timeout, for the recv never know the status
// of underlayer socket.
static int DEFAULT = 5000;
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("publish_normal_timeout");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
int SrsConfig::get_global_chunk_size()
{
SrsConfDirective* conf = root->get("chunk_size");
if (!conf || conf->arg0().empty()) {
return SRS_CONSTS_RTMP_SRS_CHUNK_SIZE;
}
return ::atoi(conf->arg0().c_str());
}
SrsConfDirective* SrsConfig::get_forward(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("forward");
}
SrsConfDirective* SrsConfig::get_forward_server_other(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("forward_server_other");
}
SrsConfDirective* SrsConfig::get_forward_in_turn(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("forward_in_turn");
}
SrsConfDirective* SrsConfig::get_forward_append_stream_name(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("forward_append_stream_name");
}
SrsConfDirective* SrsConfig::get_forward_peer(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("forward_peer");
}
SrsConfDirective* SrsConfig::get_vhost_http_hooks(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("http_hooks");
}
bool SrsConfig::get_vhost_http_hooks_enabled(string vhost)
{
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
if (!conf) {
return false;
}
conf = conf->get("enabled");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
SrsConfDirective* SrsConfig::get_vhost_on_connect(string vhost)
{
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
if (!conf) {
return NULL;
}
return conf->get("on_connect");
}
SrsConfDirective* SrsConfig::get_vhost_on_close(string vhost)
{
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
if (!conf) {
return NULL;
}
return conf->get("on_close");
}
SrsConfDirective* SrsConfig::get_vhost_on_publish(string vhost)
{
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
if (!conf) {
return NULL;
}
return conf->get("on_publish");
}
SrsConfDirective* SrsConfig::get_vhost_on_unpublish(string vhost)
{
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
if (!conf) {
return NULL;
}
return conf->get("on_unpublish");
}
SrsConfDirective* SrsConfig::get_vhost_on_play(string vhost)
{
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
if (!conf) {
return NULL;
}
return conf->get("on_play");
}
SrsConfDirective* SrsConfig::get_vhost_on_stop(string vhost)
{
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
if (!conf) {
return NULL;
}
return conf->get("on_stop");
}
SrsConfDirective* SrsConfig::get_vhost_on_dvr(string vhost)
{
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
if (!conf) {
return NULL;
}
return conf->get("on_dvr");
}
SrsConfDirective* SrsConfig::get_vhost_on_hls(string vhost)
{
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
if (!conf) {
return NULL;
}
return conf->get("on_hls");
}
SrsConfDirective* SrsConfig::get_vhost_on_hls_notify(string vhost)
{
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
if (!conf) {
return NULL;
}
return conf->get("on_hls_notify");
}
bool SrsConfig::get_bw_check_enabled(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return false;
}
conf = conf->get("bandcheck");
if (!conf) {
return false;
}
conf = conf->get("enabled");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_bw_check_key(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return "";
}
conf = conf->get("bandcheck");
if (!conf) {
return "";
}
conf = conf->get("key");
if (!conf) {
return "";
}
return conf->arg0();
}
int SrsConfig::get_bw_check_interval_ms(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL * 1000;
}
conf = conf->get("bandcheck");
if (!conf) {
return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL * 1000;
}
conf = conf->get("interval");
if (!conf) {
return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL * 1000;
}
return (int)(::atof(conf->arg0().c_str()) * 1000);
}
int SrsConfig::get_bw_check_limit_kbps(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS;
}
conf = conf->get("bandcheck");
if (!conf) {
return SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS;
}
conf = conf->get("limit_kbps");
if (!conf) {
return SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS;
}
return ::atoi(conf->arg0().c_str());
}
bool SrsConfig::get_vhost_is_edge(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
return get_vhost_is_edge(conf);
}
bool SrsConfig::get_vhost_is_edge(SrsConfDirective* vhost)
{
static bool DEFAULT = false;
SrsConfDirective* conf = vhost;
if (!conf) {
return DEFAULT;
}
conf = conf->get("mode");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return "remote" == conf->arg0();
}
SrsConfDirective* SrsConfig::get_vhost_edge_origin(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("origin");
}
bool SrsConfig::get_vhost_edge_token_traverse(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_CONF_DEFAULT_EDGE_TOKEN_TRAVERSE;
}
conf = conf->get("token_traverse");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_EDGE_TOKEN_TRAVERSE;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_vhost_edge_transform_vhost(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_CONF_DEFAULT_EDGE_TRANSFORM_VHOST;
}
conf = conf->get("vhost");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_EDGE_TRANSFORM_VHOST;
}
return conf->arg0();
}
bool SrsConfig::get_security_enabled(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_CONF_DEFAULT_SECURITY_ENABLED;
}
SrsConfDirective* security = conf->get("security");
if (!security) {
return SRS_CONF_DEFAULT_SECURITY_ENABLED;
}
conf = security->get("enabled");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_SECURITY_ENABLED;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
SrsConfDirective* SrsConfig::get_security_rules(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
SrsConfDirective* security = conf->get("security");
if (!security) {
return NULL;
}
return security;
}
SrsConfDirective* SrsConfig::get_transcode(string vhost, string scope)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
SrsConfDirective* transcode = conf->get("transcode");
if (!transcode) {
return NULL;
}
if (transcode->arg0() == scope) {
return transcode;
}
return NULL;
}
bool SrsConfig::get_transcode_enabled(SrsConfDirective* transcode)
{
if (!transcode) {
return false;
}
SrsConfDirective* conf = transcode->get("enabled");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_transcode_ffmpeg(SrsConfDirective* transcode)
{
if (!transcode) {
return "";
}
SrsConfDirective* conf = transcode->get("ffmpeg");
if (!conf) {
return "";
}
return conf->arg0();
}
vector<SrsConfDirective*> SrsConfig::get_transcode_engines(SrsConfDirective* transcode)
{
vector<SrsConfDirective*> engines;
if (!transcode) {
return engines;
}
for (int i = 0; i < (int)transcode->directives.size(); i++) {
SrsConfDirective* conf = transcode->directives[i];
if (conf->name == "engine") {
engines.push_back(conf);
}
}
return engines;
}
bool SrsConfig::get_engine_enabled(SrsConfDirective* engine)
{
if (!engine) {
return false;
}
SrsConfDirective* conf = engine->get("enabled");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_engine_iformat(SrsConfDirective* engine)
{
if (!engine) {
return SRS_CONF_DEFAULT_TRANSCODE_IFORMAT;
}
SrsConfDirective* conf = engine->get("iformat");
if (!conf) {
return SRS_CONF_DEFAULT_TRANSCODE_IFORMAT;
}
return conf->arg0();
}
vector<string> SrsConfig::get_engine_vfilter(SrsConfDirective* engine)
{
vector<string> vfilter;
if (!engine) {
return vfilter;
}
SrsConfDirective* conf = engine->get("vfilter");
if (!conf) {
return vfilter;
}
for (int i = 0; i < (int)conf->directives.size(); i++) {
SrsConfDirective* p = conf->directives[i];
if (!p) {
continue;
}
vfilter.push_back("-" + p->name);
vfilter.push_back(p->arg0());
}
return vfilter;
}
string SrsConfig::get_engine_vcodec(SrsConfDirective* engine)
{
static string DEFAULT = "";
if (!engine) {
return DEFAULT;
}
SrsConfDirective* conf = engine->get("vcodec");
if (!conf) {
return DEFAULT;
}
return conf->arg0();
}
int SrsConfig::get_engine_vbitrate(SrsConfDirective* engine)
{
static int DEFAULT = 0;
if (!engine) {
return DEFAULT;
}
SrsConfDirective* conf = engine->get("vbitrate");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
double SrsConfig::get_engine_vfps(SrsConfDirective* engine)
{
static double DEFAULT = 0;
if (!engine) {
return DEFAULT;
}
SrsConfDirective* conf = engine->get("vfps");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atof(conf->arg0().c_str());
}
int SrsConfig::get_engine_vwidth(SrsConfDirective* engine)
{
static int DEFAULT = 0;
if (!engine) {
return DEFAULT;
}
SrsConfDirective* conf = engine->get("vwidth");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
int SrsConfig::get_engine_vheight(SrsConfDirective* engine)
{
static int DEFAULT = 0;
if (!engine) {
return DEFAULT;
}
SrsConfDirective* conf = engine->get("vheight");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
int SrsConfig::get_engine_vthreads(SrsConfDirective* engine)
{
static int DEFAULT = 1;
if (!engine) {
return DEFAULT;
}
SrsConfDirective* conf = engine->get("vthreads");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
string SrsConfig::get_engine_vprofile(SrsConfDirective* engine)
{
if (!engine) {
return "";
}
SrsConfDirective* conf = engine->get("vprofile");
if (!conf) {
return "";
}
return conf->arg0();
}
string SrsConfig::get_engine_vpreset(SrsConfDirective* engine)
{
if (!engine) {
return "";
}
SrsConfDirective* conf = engine->get("vpreset");
if (!conf) {
return "";
}
return conf->arg0();
}
vector<string> SrsConfig::get_engine_vparams(SrsConfDirective* engine)
{
vector<string> vparams;
if (!engine) {
return vparams;
}
SrsConfDirective* conf = engine->get("vparams");
if (!conf) {
return vparams;
}
for (int i = 0; i < (int)conf->directives.size(); i++) {
SrsConfDirective* p = conf->directives[i];
if (!p) {
continue;
}
vparams.push_back("-" + p->name);
vparams.push_back(p->arg0());
}
return vparams;
}
string SrsConfig::get_engine_acodec(SrsConfDirective* engine)
{
static string DEFAULT = "";
if (!engine) {
return DEFAULT;
}
SrsConfDirective* conf = engine->get("acodec");
if (!conf) {
return DEFAULT;
}
return conf->arg0();
}
int SrsConfig::get_engine_abitrate(SrsConfDirective* engine)
{
static int DEFAULT = 0;
if (!engine) {
return DEFAULT;
}
SrsConfDirective* conf = engine->get("abitrate");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
int SrsConfig::get_engine_asample_rate(SrsConfDirective* engine)
{
static int DEFAULT = 0;
if (!engine) {
return DEFAULT;
}
SrsConfDirective* conf = engine->get("asample_rate");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
int SrsConfig::get_engine_achannels(SrsConfDirective* engine)
{
static int DEFAULT = 0;
if (!engine) {
return DEFAULT;
}
SrsConfDirective* conf = engine->get("achannels");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
vector<string> SrsConfig::get_engine_aparams(SrsConfDirective* engine)
{
vector<string> aparams;
if (!engine) {
return aparams;
}
SrsConfDirective* conf = engine->get("aparams");
if (!conf) {
return aparams;
}
for (int i = 0; i < (int)conf->directives.size(); i++) {
SrsConfDirective* p = conf->directives[i];
if (!p) {
continue;
}
aparams.push_back("-" + p->name);
aparams.push_back(p->arg0());
}
return aparams;
}
string SrsConfig::get_engine_oformat(SrsConfDirective* engine)
{
if (!engine) {
return SRS_CONF_DEFAULT_TRANSCODE_OFORMAT;
}
SrsConfDirective* conf = engine->get("oformat");
if (!conf) {
return SRS_CONF_DEFAULT_TRANSCODE_OFORMAT;
}
return conf->arg0();
}
string SrsConfig::get_engine_output(SrsConfDirective* engine)
{
if (!engine) {
return "";
}
SrsConfDirective* conf = engine->get("output");
if (!conf) {
return "";
}
return conf->arg0();
}
vector<SrsConfDirective*> SrsConfig::get_ingesters(string vhost)
{
vector<SrsConfDirective*> ingeters;
SrsConfDirective* vhost_conf = get_vhost(vhost);
if (!vhost_conf) {
return ingeters;
}
for (int i = 0; i < (int)vhost_conf->directives.size(); i++) {
SrsConfDirective* conf = vhost_conf->directives[i];
if (conf->name == "ingest") {
ingeters.push_back(conf);
}
}
return ingeters;
}
SrsConfDirective* SrsConfig::get_ingest_by_id(string vhost, string ingest_id)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
conf = conf->get("ingest", ingest_id);
return conf;
}
bool SrsConfig::get_ingest_enabled(SrsConfDirective* ingest)
{
if (!ingest) {
return false;
}
SrsConfDirective* conf = ingest->get("enabled");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_ingest_ffmpeg(SrsConfDirective* ingest)
{
if (!ingest) {
return "";
}
SrsConfDirective* conf = ingest->get("ffmpeg");
if (!conf) {
return "";
}
return conf->arg0();
}
string SrsConfig::get_ingest_input_type(SrsConfDirective* ingest)
{
if (!ingest) {
return SRS_CONF_DEFAULT_INGEST_TYPE_FILE;
}
SrsConfDirective* conf = ingest->get("input");
if (!conf) {
return SRS_CONF_DEFAULT_INGEST_TYPE_FILE;
}
conf = conf->get("type");
if (!conf) {
return SRS_CONF_DEFAULT_INGEST_TYPE_FILE;
}
return conf->arg0();
}
string SrsConfig::get_ingest_input_url(SrsConfDirective* ingest)
{
if (!ingest) {
return "";
}
SrsConfDirective* conf = ingest->get("input");
if (!conf) {
return "";
}
conf = conf->get("url");
if (!conf) {
return "";
}
return conf->arg0();
}
bool SrsConfig::get_log_tank_file()
{
srs_assert(root);
SrsConfDirective* conf = root->get("srs_log_tank");
if (!conf || conf->arg0().empty()) {
return true;
}
return conf->arg0() != SRS_CONF_DEFAULT_LOG_TANK_CONSOLE;
}
string SrsConfig::get_log_level()
{
srs_assert(root);
SrsConfDirective* conf = root->get("srs_log_level");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_LOG_LEVEL;
}
return conf->arg0();
}
string SrsConfig::get_log_file()
{
srs_assert(root);
SrsConfDirective* conf = root->get("srs_log_file");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_LOG_FILE;
}
return conf->arg0();
}
bool SrsConfig::get_ffmpeg_log_enabled()
{
string log = get_ffmpeg_log_dir();
return log != SRS_CONSTS_NULL_FILE;
}
string SrsConfig::get_ffmpeg_log_dir()
{
srs_assert(root);
SrsConfDirective* conf = root->get("ff_log_dir");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_FF_LOG_DIR;
}
return conf->arg0();
}
SrsConfDirective* SrsConfig::get_hls(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("hls");
}
bool SrsConfig::get_hls_enabled(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return false;
}
SrsConfDirective* conf = hls->get("enabled");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_hls_entry_prefix(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return "";
}
SrsConfDirective* conf = hls->get("hls_entry_prefix");
if (!conf) {
return "";
}
return conf->arg0();
}
string SrsConfig::get_hls_path(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_PATH;
}
SrsConfDirective* conf = hls->get("hls_path");
if (!conf) {
return SRS_CONF_DEFAULT_HLS_PATH;
}
return conf->arg0();
}
string SrsConfig::get_hls_m3u8_file(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_M3U8_FILE;
}
SrsConfDirective* conf = hls->get("hls_m3u8_file");
if (!conf) {
return SRS_CONF_DEFAULT_HLS_M3U8_FILE;
}
return conf->arg0();
}
string SrsConfig::get_hls_total_m3u8_file(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_TOTAL_M3U8_FILE;
}
SrsConfDirective* conf = hls->get("hls_total_m3u8_file");
if (!conf) {
return SRS_CONF_DEFAULT_HLS_TOTAL_M3U8_FILE;
}
return conf->arg0();
}
string SrsConfig::get_hls_total_file(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_TOTAL_FILE;
}
SrsConfDirective* conf = hls->get("hls_total_file");
if (!conf) {
return SRS_CONF_DEFAULT_HLS_TOTAL_FILE;
}
return conf->arg0();
}
string SrsConfig::get_hls_ts_file(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_TS_FILE;
}
SrsConfDirective* conf = hls->get("hls_ts_file");
if (!conf) {
return SRS_CONF_DEFAULT_HLS_TS_FILE;
}
return conf->arg0();
}
bool SrsConfig::get_hls_ts_floor(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_TS_FLOOR;
}
SrsConfDirective* conf = hls->get("hls_ts_floor");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HLS_TS_FLOOR;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
double SrsConfig::get_hls_fragment(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_FRAGMENT;
}
SrsConfDirective* conf = hls->get("hls_fragment");
if (!conf) {
return SRS_CONF_DEFAULT_HLS_FRAGMENT;
}
return ::atof(conf->arg0().c_str());
}
double SrsConfig::get_hls_td_ratio(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_TD_RATIO;
}
SrsConfDirective* conf = hls->get("hls_td_ratio");
if (!conf) {
return SRS_CONF_DEFAULT_HLS_TD_RATIO;
}
return ::atof(conf->arg0().c_str());
}
double SrsConfig::get_hls_aof_ratio(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_AOF_RATIO;
}
SrsConfDirective* conf = hls->get("hls_aof_ratio");
if (!conf) {
return SRS_CONF_DEFAULT_HLS_AOF_RATIO;
}
return ::atof(conf->arg0().c_str());
}
double SrsConfig::get_hls_window(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_WINDOW;
}
SrsConfDirective* conf = hls->get("hls_window");
if (!conf) {
return SRS_CONF_DEFAULT_HLS_WINDOW;
}
return ::atof(conf->arg0().c_str());
}
string SrsConfig::get_hls_on_error(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_ON_ERROR;
}
SrsConfDirective* conf = hls->get("hls_on_error");
if (!conf) {
return SRS_CONF_DEFAULT_HLS_ON_ERROR;
}
return conf->arg0();
}
string SrsConfig::get_hls_acodec(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_ACODEC;
}
SrsConfDirective* conf = hls->get("hls_acodec");
if (!conf) {
return SRS_CONF_DEFAULT_HLS_ACODEC;
}
return conf->arg0();
}
string SrsConfig::get_hls_vcodec(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_VCODEC;
}
SrsConfDirective* conf = hls->get("hls_vcodec");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HLS_VCODEC;
}
return conf->arg0();
}
int SrsConfig::get_vhost_hls_nb_notify(string vhost)
{
SrsConfDirective* conf = get_hls(vhost);
if (!conf) {
return SRS_CONF_DEFAULT_HLS_NB_NOTIFY;
}
conf = conf->get("hls_nb_notify");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HLS_NB_NOTIFY;
}
return ::atoi(conf->arg0().c_str());
}
bool SrsConfig::get_hls_cleanup(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_CLEANUP;
}
SrsConfDirective* conf = hls->get("hls_cleanup");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HLS_CLEANUP;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
int SrsConfig::get_hls_dispose(string vhost)
{
SrsConfDirective* conf = get_hls(vhost);
int DEFAULT = 0;
if (!conf) {
return DEFAULT;
}
conf = conf->get("hls_dispose");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
bool SrsConfig::get_hls_wait_keyframe(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_WAIT_KEYFRAME;
}
SrsConfDirective* conf = hls->get("hls_wait_keyframe");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HLS_WAIT_KEYFRAME;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
SrsConfDirective *SrsConfig::get_hds(const string &vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("hds");
}
bool SrsConfig::get_hds_enabled(const string &vhost)
{
SrsConfDirective* hds = get_hds(vhost);
if (!hds) {
return false;
}
SrsConfDirective* conf = hds->get("enabled");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_hds_path(const string &vhost)
{
SrsConfDirective* hds = get_hds(vhost);
if (!hds) {
return SRS_CONF_DEFAULT_HDS_PATH;
}
SrsConfDirective* conf = hds->get("hds_path");
if (!conf) {
return SRS_CONF_DEFAULT_HDS_PATH;
}
return conf->arg0();
}
double SrsConfig::get_hds_fragment(const string &vhost)
{
SrsConfDirective* hds = get_hds(vhost);
if (!hds) {
return SRS_CONF_DEFAULT_HDS_FRAGMENT;
}
SrsConfDirective* conf = hds->get("hds_fragment");
if (!conf) {
return SRS_CONF_DEFAULT_HDS_FRAGMENT;
}
return ::atof(conf->arg0().c_str());
}
double SrsConfig::get_hds_window(const string &vhost)
{
SrsConfDirective* hds = get_hds(vhost);
if (!hds) {
return SRS_CONF_DEFAULT_HDS_WINDOW;
}
SrsConfDirective* conf = hds->get("hds_window");
if (!conf) {
return SRS_CONF_DEFAULT_HDS_WINDOW;
}
return ::atof(conf->arg0().c_str());
}
SrsConfDirective* SrsConfig::get_dvr(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("dvr");
}
bool SrsConfig::get_dvr_enabled(string vhost)
{
SrsConfDirective* dvr = get_dvr(vhost);
if (!dvr) {
return false;
}
SrsConfDirective* conf = dvr->get("enabled");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_dvr_path(string vhost)
{
SrsConfDirective* dvr = get_dvr(vhost);
if (!dvr) {
return SRS_CONF_DEFAULT_DVR_PATH;
}
SrsConfDirective* conf = dvr->get("dvr_path");
if (!conf) {
return SRS_CONF_DEFAULT_DVR_PATH;
}
return conf->arg0();
}
string SrsConfig::get_dvr_plan(string vhost)
{
SrsConfDirective* dvr = get_dvr(vhost);
if (!dvr) {
return SRS_CONF_DEFAULT_DVR_PLAN;
}
SrsConfDirective* conf = dvr->get("dvr_plan");
if (!conf) {
return SRS_CONF_DEFAULT_DVR_PLAN;
}
return conf->arg0();
}
int SrsConfig::get_dvr_duration(string vhost)
{
SrsConfDirective* dvr = get_dvr(vhost);
if (!dvr) {
return SRS_CONF_DEFAULT_DVR_DURATION;
}
SrsConfDirective* conf = dvr->get("dvr_duration");
if (!conf) {
return SRS_CONF_DEFAULT_DVR_DURATION;
}
return ::atoi(conf->arg0().c_str());
}
bool SrsConfig::get_dvr_wait_keyframe(string vhost)
{
SrsConfDirective* dvr = get_dvr(vhost);
if (!dvr) {
return true;
}
SrsConfDirective* conf = dvr->get("dvr_wait_keyframe");
if (!conf || conf->arg0().empty()) {
return true;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
int SrsConfig::get_dvr_time_jitter(string vhost)
{
SrsConfDirective* dvr = get_dvr(vhost);
std::string time_jitter = SRS_CONF_DEFAULT_TIME_JITTER;
if (dvr) {
SrsConfDirective* conf = dvr->get("time_jitter");
if (conf) {
time_jitter = conf->arg0();
}
}
return _srs_time_jitter_string2int(time_jitter);
}
bool SrsConfig::get_http_api_enabled()
{
SrsConfDirective* conf = get_http_api();
return get_http_api_enabled(conf);
}
SrsConfDirective* SrsConfig::get_http_api()
{
return root->get("http_api");
}
bool SrsConfig::get_http_api_enabled(SrsConfDirective* conf)
{
if (!conf) {
return false;
}
conf = conf->get("enabled");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_http_api_listen()
{
SrsConfDirective* conf = get_http_api();
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_API_PORT;
}
conf = conf->get("listen");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HTTP_API_PORT;
}
return conf->arg0();
}
bool SrsConfig::get_http_api_crossdomain()
{
SrsConfDirective* conf = get_http_api();
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN;
}
conf = conf->get("crossdomain");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
bool SrsConfig::get_http_stream_enabled()
{
SrsConfDirective* conf = get_http_stream();
return get_http_stream_enabled(conf);
}
SrsConfDirective* SrsConfig::get_http_stream()
{
SrsConfDirective* conf = root->get("http_stream");
// http_stream renamed to http_server in SRS2.
if (!conf) {
conf = root->get("http_server");
}
return conf;
}
bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf)
{
if (!conf) {
return false;
}
conf = conf->get("enabled");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_http_stream_listen()
{
SrsConfDirective* conf = get_http_stream();
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_STREAM_PORT;
}
conf = conf->get("listen");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HTTP_STREAM_PORT;
}
return conf->arg0();
}
string SrsConfig::get_http_stream_dir()
{
SrsConfDirective* conf = get_http_stream();
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_DIR;
}
conf = conf->get("dir");
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_DIR;
}
if (conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HTTP_DIR;
}
return conf->arg0();
}
bool SrsConfig::get_vhost_http_enabled(string vhost)
{
SrsConfDirective* vconf = get_vhost(vhost);
if (!vconf) {
return false;
}
SrsConfDirective* conf = vconf->get("http");
if (!conf) {
conf = vconf->get("http_static");
}
if (!conf) {
return false;
}
conf = conf->get("enabled");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
string SrsConfig::get_vhost_http_mount(string vhost)
{
SrsConfDirective* vconf = get_vhost(vhost);
if (!vconf) {
return SRS_CONF_DEFAULT_HTTP_MOUNT;
}
SrsConfDirective* conf = vconf->get("http");
if (!conf) {
conf = vconf->get("http_static");
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_MOUNT;
}
}
conf = conf->get("mount");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HTTP_MOUNT;
}
return conf->arg0();
}
string SrsConfig::get_vhost_http_dir(string vhost)
{
SrsConfDirective* vconf = get_vhost(vhost);
if (!vconf) {
return SRS_CONF_DEFAULT_HTTP_DIR;
}
SrsConfDirective* conf = vconf->get("http");
if (!conf) {
conf = vconf->get("http_static");
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_DIR;
}
}
conf = conf->get("dir");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HTTP_DIR;
}
return conf->arg0();
}
bool SrsConfig::get_vhost_http_remux_enabled(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return false;
}
conf = conf->get("http_remux");
if (!conf) {
return false;
}
conf = conf->get("enabled");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
double SrsConfig::get_vhost_http_remux_fast_cache(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE;
}
conf = conf->get("http_remux");
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE;
}
conf = conf->get("fast_cache");
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE;
}
if (conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE;
}
return ::atof(conf->arg0().c_str());
}
string SrsConfig::get_vhost_http_remux_mount(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_REMUX_MOUNT;
}
conf = conf->get("http_remux");
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_REMUX_MOUNT;
}
conf = conf->get("mount");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HTTP_REMUX_MOUNT;
}
return conf->arg0();
}
bool SrsConfig::get_vhost_http_remux_hstrs(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return false;
}
conf = conf->get("http_remux");
if (!conf) {
return false;
}
conf = conf->get("hstrs");
if (!conf || conf->arg0().empty()) {
return false;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
SrsConfDirective* SrsConfig::get_heartbeart()
{
return root->get("heartbeat");
}
bool SrsConfig::get_heartbeat_enabled()
{
SrsConfDirective* conf = get_heartbeart();
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED;
}
conf = conf->get("enabled");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
int64_t SrsConfig::get_heartbeat_interval()
{
SrsConfDirective* conf = get_heartbeart();
if (!conf) {
return (int64_t)(SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INTERVAL * 1000);
}
conf = conf->get("interval");
if (!conf || conf->arg0().empty()) {
return (int64_t)(SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INTERVAL * 1000);
}
return (int64_t)(::atof(conf->arg0().c_str()) * 1000);
}
string SrsConfig::get_heartbeat_url()
{
SrsConfDirective* conf = get_heartbeart();
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_HEAETBEAT_URL;
}
conf = conf->get("url");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HTTP_HEAETBEAT_URL;
}
return conf->arg0();
}
string SrsConfig::get_heartbeat_device_id()
{
SrsConfDirective* conf = get_heartbeart();
if (!conf) {
return "";
}
conf = conf->get("device_id");
if (!conf || conf->arg0().empty()) {
return "";
}
return conf->arg0();
}
bool SrsConfig::get_heartbeat_summaries()
{
SrsConfDirective* conf = get_heartbeart();
if (!conf) {
return SRS_CONF_DEFAULT_HTTP_HEAETBEAT_SUMMARIES;
}
conf = conf->get("summaries");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HTTP_HEAETBEAT_SUMMARIES;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
SrsConfDirective* SrsConfig::get_stats()
{
return root->get("stats");
}
int SrsConfig::get_stats_network()
{
SrsConfDirective* conf = get_stats();
if (!conf) {
return SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX;
}
conf = conf->get("network");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX;
}
return ::atoi(conf->arg0().c_str());
}
SrsConfDirective* SrsConfig::get_stats_disk_device()
{
SrsConfDirective* conf = get_stats();
if (!conf) {
return NULL;
}
conf = conf->get("disk");
if (!conf || conf->args.size() == 0) {
return NULL;
}
return conf;
}
namespace _srs_internal
{
SrsConfigBuffer::SrsConfigBuffer()
{
line = 1;
pos = last = start = NULL;
end = start;
}
SrsConfigBuffer::~SrsConfigBuffer()
{
srs_freepa(start);
}
int SrsConfigBuffer::fullfill(const char* filename)
{
int ret = ERROR_SUCCESS;
SrsFileReader reader;
// open file reader.
if ((ret = reader.open(filename)) != ERROR_SUCCESS) {
srs_error("open conf file error. ret=%d", ret);
return ret;
}
// read all.
int filesize = (int)reader.filesize();
// create buffer
srs_freepa(start);
pos = last = start = new char[filesize];
end = start + filesize;
// read total content from file.
ssize_t nread = 0;
if ((ret = reader.read(start, filesize, &nread)) != ERROR_SUCCESS) {
srs_error("read file read error. expect %d, actual %d bytes, ret=%d",
filesize, nread, ret);
return ret;
}
return ret;
}
bool SrsConfigBuffer::empty()
{
return pos >= end;
}
};
bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b)
{
// both NULL, equal.
if (!a && !b) {
return true;
}
if (!a || !b) {
return false;
}
if (a->name != b->name) {
return false;
}
if (a->args.size() != b->args.size()) {
return false;
}
for (int i = 0; i < (int)a->args.size(); i++) {
if (a->args.at(i) != b->args.at(i)) {
return false;
}
}
if (a->directives.size() != b->directives.size()) {
return false;
}
for (int i = 0; i < (int)a->directives.size(); i++) {
SrsConfDirective* a0 = a->at(i);
SrsConfDirective* b0 = b->at(i);
if (!srs_directive_equals(a0, b0)) {
return false;
}
}
return true;
}
bool srs_config_hls_is_on_error_ignore(string strategy)
{
return strategy == SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE;
}
bool srs_config_hls_is_on_error_continue(string strategy)
{
return strategy == SRS_CONF_DEFAULT_HLS_ON_ERROR_CONTINUE;
}
bool srs_config_ingest_is_file(string type)
{
return type == SRS_CONF_DEFAULT_INGEST_TYPE_FILE;
}
bool srs_config_ingest_is_stream(string type)
{
return type == SRS_CONF_DEFAULT_INGEST_TYPE_STREAM;
}
bool srs_config_dvr_is_plan_segment(string plan)
{
return plan == SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT;
}
bool srs_config_dvr_is_plan_session(string plan)
{
return plan == SRS_CONF_DEFAULT_DVR_PLAN_SESSION;
}
bool srs_config_dvr_is_plan_append(string plan)
{
return plan == SRS_CONF_DEFAULT_DVR_PLAN_APPEND;
}
bool srs_stream_caster_is_udp(string caster)
{
return caster == SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP;
}
bool srs_stream_caster_is_rtsp(string caster)
{
return caster == SRS_CONF_DEFAULT_STREAM_CASTER_RTSP;
}
bool srs_stream_caster_is_flv(string caster)
{
return caster == SRS_CONF_DEFAULT_STREAM_CASTER_FLV;
}