正在显示
11 个修改的文件
包含
180 行增加
和
118 行删除
| @@ -55,11 +55,98 @@ using namespace _srs_internal; | @@ -55,11 +55,98 @@ using namespace _srs_internal; | ||
| 55 | #define SRS_CONF_PERFER_FALSE(conf_arg) conf_arg == "on" | 55 | #define SRS_CONF_PERFER_FALSE(conf_arg) conf_arg == "on" |
| 56 | #define SRS_CONF_PERFER_TRUE(conf_arg) conf_arg != "off" | 56 | #define SRS_CONF_PERFER_TRUE(conf_arg) conf_arg != "off" |
| 57 | 57 | ||
| 58 | +/////////////////////////////////////////////////////////// | ||
| 59 | +// default consts values | ||
| 60 | +/////////////////////////////////////////////////////////// | ||
| 61 | +#define SRS_CONF_DEFAULT_PID_FILE "./objs/srs.pid" | ||
| 62 | +#define SRS_CONF_DEFAULT_LOG_FILE "./objs/srs.log" | ||
| 63 | +#define SRS_CONF_DEFAULT_LOG_LEVEL "trace" | ||
| 64 | +#define SRS_CONF_DEFAULT_LOG_TANK_CONSOLE "console" | ||
| 65 | +#define SRS_CONF_DEFAULT_COFNIG_FILE "conf/srs.conf" | ||
| 66 | +#define SRS_CONF_DEFAULT_FF_LOG_DIR "./objs" | ||
| 67 | +#define SRS_CONF_DEFAULT_UTC_TIME false | ||
| 68 | + | ||
| 69 | +#define SRS_CONF_DEFAULT_MAX_CONNECTIONS 1000 | ||
| 70 | +#define SRS_CONF_DEFAULT_HLS_PATH "./objs/nginx/html" | ||
| 71 | +#define SRS_CONF_DEFAULT_HLS_M3U8_FILE "[app]/[stream].m3u8" | ||
| 72 | +#define SRS_CONF_DEFAULT_HLS_TS_FILE "[app]/[stream]-[seq].ts" | ||
| 73 | +#define SRS_CONF_DEFAULT_HLS_TS_FLOOR false | ||
| 74 | +#define SRS_CONF_DEFAULT_HLS_FRAGMENT 10 | ||
| 75 | +#define SRS_CONF_DEFAULT_HLS_TD_RATIO 1.5 | ||
| 76 | +#define SRS_CONF_DEFAULT_HLS_AOF_RATIO 2.0 | ||
| 77 | +#define SRS_CONF_DEFAULT_HLS_WINDOW 60 | ||
| 78 | +#define SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE "ignore" | ||
| 79 | +#define SRS_CONF_DEFAULT_HLS_ON_ERROR_DISCONNECT "disconnect" | ||
| 80 | +#define SRS_CONF_DEFAULT_HLS_ON_ERROR_CONTINUE "continue" | ||
| 81 | +#define SRS_CONF_DEFAULT_HLS_ON_ERROR SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE | ||
| 82 | +#define SRS_CONF_DEFAULT_HLS_STORAGE "disk" | ||
| 83 | +#define SRS_CONF_DEFAULT_HLS_MOUNT "[vhost]/[app]/[stream].m3u8" | ||
| 84 | +#define SRS_CONF_DEFAULT_HLS_ACODEC "aac" | ||
| 85 | +#define SRS_CONF_DEFAULT_HLS_VCODEC "h264" | ||
| 86 | +#define SRS_CONF_DEFAULT_HLS_CLEANUP true | ||
| 87 | +#define SRS_CONF_DEFAULT_HLS_WAIT_KEYFRAME true | ||
| 88 | +#define SRS_CONF_DEFAULT_HLS_NB_NOTIFY 64 | ||
| 89 | +#define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html/[app]/[stream].[timestamp].flv" | ||
| 90 | +#define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session" | ||
| 91 | +#define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment" | ||
| 92 | +#define SRS_CONF_DEFAULT_DVR_PLAN_APPEND "append" | ||
| 93 | +#define SRS_CONF_DEFAULT_DVR_PLAN SRS_CONF_DEFAULT_DVR_PLAN_SESSION | ||
| 94 | +#define SRS_CONF_DEFAULT_DVR_DURATION 30 | ||
| 95 | +#define SRS_CONF_DEFAULT_TIME_JITTER "full" | ||
| 96 | +#define SRS_CONF_DEFAULT_ATC_AUTO true | ||
| 97 | +#define SRS_CONF_DEFAULT_MIX_CORRECT false | ||
| 98 | +// in seconds, the paused queue length. | ||
| 99 | +#define SRS_CONF_DEFAULT_PAUSED_LENGTH 10 | ||
| 100 | +// the interval in seconds for bandwidth check | ||
| 101 | +#define SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL 30 | ||
| 102 | +// the interval in seconds for bandwidth check | ||
| 103 | +#define SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS 1000 | ||
| 104 | + | ||
| 105 | +#define SRS_CONF_DEFAULT_HTTP_MOUNT "[vhost]/" | ||
| 106 | +#define SRS_CONF_DEFAULT_HTTP_REMUX_MOUNT "[vhost]/[app]/[stream].flv" | ||
| 107 | +#define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH | ||
| 108 | +#define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 0 | ||
| 109 | + | ||
| 110 | +#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT "8080" | ||
| 111 | +#define SRS_CONF_DEFAULT_HTTP_API_PORT "1985" | ||
| 112 | +#define SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN true | ||
| 113 | + | ||
| 114 | +#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED false | ||
| 115 | +#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INTERVAL 9.9 | ||
| 116 | +#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_URL "http://"SRS_CONSTS_LOCALHOST":8085/api/v1/servers" | ||
| 117 | +#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_SUMMARIES false | ||
| 118 | + | ||
| 119 | +#define SRS_CONF_DEFAULT_SECURITY_ENABLED false | ||
| 120 | + | ||
| 121 | +#define SRS_CONF_DEFAULT_STREAM_CASTER_ENABLED false | ||
| 122 | +#define SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP "mpegts_over_udp" | ||
| 123 | +#define SRS_CONF_DEFAULT_STREAM_CASTER_RTSP "rtsp" | ||
| 124 | +#define SRS_CONF_DEFAULT_STREAM_CASTER_FLV "flv" | ||
| 125 | + | ||
| 126 | +#define SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX 0 | ||
| 127 | + | ||
| 128 | +#define SRS_CONF_DEFAULT_PITHY_PRINT_MS 10000 | ||
| 129 | + | ||
| 130 | +#define SRS_CONF_DEFAULT_INGEST_TYPE_FILE "file" | ||
| 131 | +#define SRS_CONF_DEFAULT_INGEST_TYPE_STREAM "stream" | ||
| 132 | + | ||
| 133 | +#define SRS_CONF_DEFAULT_TRANSCODE_IFORMAT "flv" | ||
| 134 | +#define SRS_CONF_DEFAULT_TRANSCODE_OFORMAT "flv" | ||
| 135 | + | ||
| 136 | +#define SRS_CONF_DEFAULT_EDGE_MODE false | ||
| 137 | +#define SRS_CONF_DEFAULT_EDGE_TOKEN_TRAVERSE false | ||
| 138 | +#define SRS_CONF_DEFAULT_EDGE_TRANSFORM_VHOST "[vhost]" | ||
| 139 | + | ||
| 140 | +// hds default value | ||
| 141 | +#define SRS_CONF_DEFAULT_HDS_PATH "./objs/nginx/html" | ||
| 142 | +#define SRS_CONF_DEFAULT_HDS_WINDOW (60) | ||
| 143 | +#define SRS_CONF_DEFAULT_HDS_FRAGMENT (10) | ||
| 144 | + | ||
| 58 | // '\n' | 145 | // '\n' |
| 59 | -#define SRS_LF (char)0x0a | 146 | +#define SRS_LF (char)SRS_CONSTS_LF |
| 60 | 147 | ||
| 61 | // '\r' | 148 | // '\r' |
| 62 | -#define SRS_CR (char)0x0d | 149 | +#define SRS_CR (char)SRS_CONSTS_CR |
| 63 | 150 | ||
| 64 | bool is_common_space(char ch) | 151 | bool is_common_space(char ch) |
| 65 | { | 152 | { |
| @@ -4284,3 +4371,37 @@ bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b) | @@ -4284,3 +4371,37 @@ bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b) | ||
| 4284 | return true; | 4371 | return true; |
| 4285 | } | 4372 | } |
| 4286 | 4373 | ||
| 4374 | +bool srs_config_hls_is_on_error_ignore(string strategy) | ||
| 4375 | +{ | ||
| 4376 | + return strategy == SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE; | ||
| 4377 | +} | ||
| 4378 | + | ||
| 4379 | +bool srs_config_hls_is_on_error_continue(string strategy) | ||
| 4380 | +{ | ||
| 4381 | + return strategy == SRS_CONF_DEFAULT_HLS_ON_ERROR_CONTINUE; | ||
| 4382 | +} | ||
| 4383 | + | ||
| 4384 | +bool srs_config_ingest_is_file(string type) | ||
| 4385 | +{ | ||
| 4386 | + return type == SRS_CONF_DEFAULT_INGEST_TYPE_FILE; | ||
| 4387 | +} | ||
| 4388 | + | ||
| 4389 | +bool srs_config_ingest_is_stream(string type) | ||
| 4390 | +{ | ||
| 4391 | + return type == SRS_CONF_DEFAULT_INGEST_TYPE_STREAM; | ||
| 4392 | +} | ||
| 4393 | + | ||
| 4394 | +bool srs_config_dvr_is_plan_segment(string plan) | ||
| 4395 | +{ | ||
| 4396 | + return plan == SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT; | ||
| 4397 | +} | ||
| 4398 | + | ||
| 4399 | +bool srs_config_dvr_is_plan_session(string plan) | ||
| 4400 | +{ | ||
| 4401 | + return plan == SRS_CONF_DEFAULT_DVR_PLAN_SESSION; | ||
| 4402 | +} | ||
| 4403 | + | ||
| 4404 | +bool srs_config_dvr_is_plan_append(string plan) | ||
| 4405 | +{ | ||
| 4406 | + return plan == SRS_CONF_DEFAULT_DVR_PLAN_APPEND; | ||
| 4407 | +} |
| @@ -34,93 +34,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -34,93 +34,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 34 | 34 | ||
| 35 | #include <srs_app_reload.hpp> | 35 | #include <srs_app_reload.hpp> |
| 36 | 36 | ||
| 37 | -/////////////////////////////////////////////////////////// | ||
| 38 | -// default consts values | ||
| 39 | -/////////////////////////////////////////////////////////// | ||
| 40 | -#define SRS_CONF_DEFAULT_PID_FILE "./objs/srs.pid" | ||
| 41 | -#define SRS_CONF_DEFAULT_LOG_FILE "./objs/srs.log" | ||
| 42 | -#define SRS_CONF_DEFAULT_LOG_LEVEL "trace" | ||
| 43 | -#define SRS_CONF_DEFAULT_LOG_TANK_CONSOLE "console" | ||
| 44 | -#define SRS_CONF_DEFAULT_COFNIG_FILE "conf/srs.conf" | ||
| 45 | -#define SRS_CONF_DEFAULT_FF_LOG_DIR "./objs" | ||
| 46 | -#define SRS_CONF_DEFAULT_UTC_TIME false | ||
| 47 | - | ||
| 48 | -#define SRS_CONF_DEFAULT_MAX_CONNECTIONS 1000 | ||
| 49 | -#define SRS_CONF_DEFAULT_HLS_PATH "./objs/nginx/html" | ||
| 50 | -#define SRS_CONF_DEFAULT_HLS_M3U8_FILE "[app]/[stream].m3u8" | ||
| 51 | -#define SRS_CONF_DEFAULT_HLS_TS_FILE "[app]/[stream]-[seq].ts" | ||
| 52 | -#define SRS_CONF_DEFAULT_HLS_TS_FLOOR false | ||
| 53 | -#define SRS_CONF_DEFAULT_HLS_FRAGMENT 10 | ||
| 54 | -#define SRS_CONF_DEFAULT_HLS_TD_RATIO 1.5 | ||
| 55 | -#define SRS_CONF_DEFAULT_HLS_AOF_RATIO 2.0 | ||
| 56 | -#define SRS_CONF_DEFAULT_HLS_WINDOW 60 | ||
| 57 | -#define SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE "ignore" | ||
| 58 | -#define SRS_CONF_DEFAULT_HLS_ON_ERROR_DISCONNECT "disconnect" | ||
| 59 | -#define SRS_CONF_DEFAULT_HLS_ON_ERROR_CONTINUE "continue" | ||
| 60 | -#define SRS_CONF_DEFAULT_HLS_ON_ERROR SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE | ||
| 61 | -#define SRS_CONF_DEFAULT_HLS_STORAGE "disk" | ||
| 62 | -#define SRS_CONF_DEFAULT_HLS_MOUNT "[vhost]/[app]/[stream].m3u8" | ||
| 63 | -#define SRS_CONF_DEFAULT_HLS_ACODEC "aac" | ||
| 64 | -#define SRS_CONF_DEFAULT_HLS_VCODEC "h264" | ||
| 65 | -#define SRS_CONF_DEFAULT_HLS_CLEANUP true | ||
| 66 | -#define SRS_CONF_DEFAULT_HLS_WAIT_KEYFRAME true | ||
| 67 | -#define SRS_CONF_DEFAULT_HLS_NB_NOTIFY 64 | ||
| 68 | -#define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html/[app]/[stream].[timestamp].flv" | ||
| 69 | -#define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session" | ||
| 70 | -#define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment" | ||
| 71 | -#define SRS_CONF_DEFAULT_DVR_PLAN_APPEND "append" | ||
| 72 | -#define SRS_CONF_DEFAULT_DVR_PLAN SRS_CONF_DEFAULT_DVR_PLAN_SESSION | ||
| 73 | -#define SRS_CONF_DEFAULT_DVR_DURATION 30 | ||
| 74 | -#define SRS_CONF_DEFAULT_TIME_JITTER "full" | ||
| 75 | -#define SRS_CONF_DEFAULT_ATC_AUTO true | ||
| 76 | -#define SRS_CONF_DEFAULT_MIX_CORRECT false | ||
| 77 | -// in seconds, the paused queue length. | ||
| 78 | -#define SRS_CONF_DEFAULT_PAUSED_LENGTH 10 | ||
| 79 | -// the interval in seconds for bandwidth check | ||
| 80 | -#define SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL 30 | ||
| 81 | -// the interval in seconds for bandwidth check | ||
| 82 | -#define SRS_CONF_DEFAULT_BANDWIDTH_LIMIT_KBPS 1000 | ||
| 83 | - | ||
| 84 | -#define SRS_CONF_DEFAULT_HTTP_MOUNT "[vhost]/" | ||
| 85 | -#define SRS_CONF_DEFAULT_HTTP_REMUX_MOUNT "[vhost]/[app]/[stream].flv" | ||
| 86 | -#define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH | ||
| 87 | -#define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 0 | ||
| 88 | - | ||
| 89 | -#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT "8080" | ||
| 90 | -#define SRS_CONF_DEFAULT_HTTP_API_PORT "1985" | ||
| 91 | -#define SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN true | ||
| 92 | - | ||
| 93 | -#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED false | ||
| 94 | -#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INTERVAL 9.9 | ||
| 95 | -#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_URL "http://"SRS_CONSTS_LOCALHOST":8085/api/v1/servers" | ||
| 96 | -#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_SUMMARIES false | ||
| 97 | - | ||
| 98 | -#define SRS_CONF_DEFAULT_SECURITY_ENABLED false | ||
| 99 | - | ||
| 100 | -#define SRS_CONF_DEFAULT_STREAM_CASTER_ENABLED false | ||
| 101 | -#define SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP "mpegts_over_udp" | ||
| 102 | -#define SRS_CONF_DEFAULT_STREAM_CASTER_RTSP "rtsp" | ||
| 103 | -#define SRS_CONF_DEFAULT_STREAM_CASTER_FLV "flv" | ||
| 104 | - | ||
| 105 | -#define SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX 0 | ||
| 106 | - | ||
| 107 | -#define SRS_CONF_DEFAULT_PITHY_PRINT_MS 10000 | ||
| 108 | - | ||
| 109 | -#define SRS_CONF_DEFAULT_INGEST_TYPE_FILE "file" | ||
| 110 | -#define SRS_CONF_DEFAULT_INGEST_TYPE_STREAM "stream" | ||
| 111 | - | ||
| 112 | -#define SRS_CONF_DEFAULT_TRANSCODE_IFORMAT "flv" | ||
| 113 | -#define SRS_CONF_DEFAULT_TRANSCODE_OFORMAT "flv" | ||
| 114 | - | ||
| 115 | -#define SRS_CONF_DEFAULT_EDGE_MODE false | ||
| 116 | -#define SRS_CONF_DEFAULT_EDGE_TOKEN_TRAVERSE false | ||
| 117 | -#define SRS_CONF_DEFAULT_EDGE_TRANSFORM_VHOST "[vhost]" | ||
| 118 | - | ||
| 119 | -// hds default value | ||
| 120 | -#define SRS_CONF_DEFAULT_HDS_PATH "./objs/nginx/html" | ||
| 121 | -#define SRS_CONF_DEFAULT_HDS_WINDOW (60) | ||
| 122 | -#define SRS_CONF_DEFAULT_HDS_FRAGMENT (10) | ||
| 123 | - | ||
| 124 | namespace _srs_internal | 37 | namespace _srs_internal |
| 125 | { | 38 | { |
| 126 | class SrsConfigBuffer; | 39 | class SrsConfigBuffer; |
| @@ -1218,7 +1131,18 @@ namespace _srs_internal | @@ -1218,7 +1131,18 @@ namespace _srs_internal | ||
| 1218 | /** | 1131 | /** |
| 1219 | * deep compare directive. | 1132 | * deep compare directive. |
| 1220 | */ | 1133 | */ |
| 1221 | -bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b); | 1134 | +extern bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b); |
| 1135 | + | ||
| 1136 | +/** | ||
| 1137 | + * helper utilities, used for compare the consts values. | ||
| 1138 | + */ | ||
| 1139 | +extern bool srs_config_hls_is_on_error_ignore(std::string strategy); | ||
| 1140 | +extern bool srs_config_hls_is_on_error_continue(std::string strategy); | ||
| 1141 | +extern bool srs_config_ingest_is_file(std::string type); | ||
| 1142 | +extern bool srs_config_ingest_is_stream(std::string type); | ||
| 1143 | +extern bool srs_config_dvr_is_plan_segment(std::string plan); | ||
| 1144 | +extern bool srs_config_dvr_is_plan_session(std::string plan); | ||
| 1145 | +extern bool srs_config_dvr_is_plan_append(std::string plan); | ||
| 1222 | 1146 | ||
| 1223 | // global config | 1147 | // global config |
| 1224 | extern SrsConfig* _srs_config; | 1148 | extern SrsConfig* _srs_config; |
| @@ -639,11 +639,11 @@ int SrsDvrPlan::on_reap_segment() | @@ -639,11 +639,11 @@ int SrsDvrPlan::on_reap_segment() | ||
| 639 | SrsDvrPlan* SrsDvrPlan::create_plan(string vhost) | 639 | SrsDvrPlan* SrsDvrPlan::create_plan(string vhost) |
| 640 | { | 640 | { |
| 641 | std::string plan = _srs_config->get_dvr_plan(vhost); | 641 | std::string plan = _srs_config->get_dvr_plan(vhost); |
| 642 | - if (plan == SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT) { | 642 | + if (srs_config_dvr_is_plan_segment(plan)) { |
| 643 | return new SrsDvrSegmentPlan(); | 643 | return new SrsDvrSegmentPlan(); |
| 644 | - } else if (plan == SRS_CONF_DEFAULT_DVR_PLAN_SESSION) { | 644 | + } else if (srs_config_dvr_is_plan_session(plan)) { |
| 645 | return new SrsDvrSessionPlan(); | 645 | return new SrsDvrSessionPlan(); |
| 646 | - } else if (plan == SRS_CONF_DEFAULT_DVR_PLAN_APPEND) { | 646 | + } else if (srs_config_dvr_is_plan_append(plan)) { |
| 647 | return new SrsDvrAppendPlan(); | 647 | return new SrsDvrAppendPlan(); |
| 648 | } else { | 648 | } else { |
| 649 | srs_error("invalid dvr plan=%s, vhost=%s", plan.c_str(), vhost.c_str()); | 649 | srs_error("invalid dvr plan=%s, vhost=%s", plan.c_str(), vhost.c_str()); |
trunk/src/app/srs_app_edge.cpp
100644 → 100755
| @@ -94,6 +94,13 @@ int SrsEdgeIngester::initialize(SrsSource* source, SrsPlayEdge* edge, SrsRequest | @@ -94,6 +94,13 @@ int SrsEdgeIngester::initialize(SrsSource* source, SrsPlayEdge* edge, SrsRequest | ||
| 94 | 94 | ||
| 95 | int SrsEdgeIngester::start() | 95 | int SrsEdgeIngester::start() |
| 96 | { | 96 | { |
| 97 | + int ret = ERROR_SUCCESS; | ||
| 98 | + | ||
| 99 | + if ((ret = _source->on_publish()) != ERROR_SUCCESS) { | ||
| 100 | + srs_error("edge pull stream then publish to edge failed. ret=%d", ret); | ||
| 101 | + return ret; | ||
| 102 | + } | ||
| 103 | + | ||
| 97 | return pthread->start(); | 104 | return pthread->start(); |
| 98 | } | 105 | } |
| 99 | 106 | ||
| @@ -114,7 +121,9 @@ void SrsEdgeIngester::stop() | @@ -114,7 +121,9 @@ void SrsEdgeIngester::stop() | ||
| 114 | int SrsEdgeIngester::cycle() | 121 | int SrsEdgeIngester::cycle() |
| 115 | { | 122 | { |
| 116 | int ret = ERROR_SUCCESS; | 123 | int ret = ERROR_SUCCESS; |
| 117 | - | 124 | + |
| 125 | + _source->on_source_id_changed(_srs_context->get_id()); | ||
| 126 | + | ||
| 118 | std::string ep_server, ep_port; | 127 | std::string ep_server, ep_port; |
| 119 | if ((ret = connect_server(ep_server, ep_port)) != ERROR_SUCCESS) { | 128 | if ((ret = connect_server(ep_server, ep_port)) != ERROR_SUCCESS) { |
| 120 | return ret; | 129 | return ret; |
| @@ -144,11 +153,6 @@ int SrsEdgeIngester::cycle() | @@ -144,11 +153,6 @@ int SrsEdgeIngester::cycle() | ||
| 144 | return ret; | 153 | return ret; |
| 145 | } | 154 | } |
| 146 | 155 | ||
| 147 | - if ((ret = _source->on_publish()) != ERROR_SUCCESS) { | ||
| 148 | - srs_error("edge pull stream then publish to edge failed. ret=%d", ret); | ||
| 149 | - return ret; | ||
| 150 | - } | ||
| 151 | - | ||
| 152 | if ((ret = _edge->on_ingest_play()) != ERROR_SUCCESS) { | 156 | if ((ret = _edge->on_ingest_play()) != ERROR_SUCCESS) { |
| 153 | return ret; | 157 | return ret; |
| 154 | } | 158 | } |
| @@ -381,8 +385,8 @@ int SrsEdgeIngester::connect_server(string& ep_server, string& ep_port) | @@ -381,8 +385,8 @@ int SrsEdgeIngester::connect_server(string& ep_server, string& ep_port) | ||
| 381 | 385 | ||
| 382 | kbps->set_io(io, io); | 386 | kbps->set_io(io, io); |
| 383 | 387 | ||
| 384 | - srs_trace("edge pull connected, can_publish=%d, url=%s/%s, server=%s:%d", | ||
| 385 | - _source->can_publish(), _req->tcUrl.c_str(), _req->stream.c_str(), server.c_str(), port); | 388 | + srs_trace("edge pull connected, url=%s/%s, server=%s:%d", |
| 389 | + _req->tcUrl.c_str(), _req->stream.c_str(), server.c_str(), port); | ||
| 386 | 390 | ||
| 387 | return ret; | 391 | return ret; |
| 388 | } | 392 | } |
| @@ -803,6 +807,11 @@ int SrsPublishEdge::initialize(SrsSource* source, SrsRequest* req) | @@ -803,6 +807,11 @@ int SrsPublishEdge::initialize(SrsSource* source, SrsRequest* req) | ||
| 803 | return ret; | 807 | return ret; |
| 804 | } | 808 | } |
| 805 | 809 | ||
| 810 | +bool SrsPublishEdge::can_publish() | ||
| 811 | +{ | ||
| 812 | + return state != SrsEdgeStatePublish; | ||
| 813 | +} | ||
| 814 | + | ||
| 806 | int SrsPublishEdge::on_client_publish() | 815 | int SrsPublishEdge::on_client_publish() |
| 807 | { | 816 | { |
| 808 | int ret = ERROR_SUCCESS; | 817 | int ret = ERROR_SUCCESS; |
trunk/src/app/srs_app_edge.hpp
100644 → 100755
| @@ -207,6 +207,7 @@ public: | @@ -207,6 +207,7 @@ public: | ||
| 207 | virtual void set_queue_size(double queue_size); | 207 | virtual void set_queue_size(double queue_size); |
| 208 | public: | 208 | public: |
| 209 | virtual int initialize(SrsSource* source, SrsRequest* req); | 209 | virtual int initialize(SrsSource* source, SrsRequest* req); |
| 210 | + virtual bool can_publish(); | ||
| 210 | /** | 211 | /** |
| 211 | * when client publish stream on edge. | 212 | * when client publish stream on edge. |
| 212 | */ | 213 | */ |
| @@ -369,7 +369,7 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S | @@ -369,7 +369,7 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S | ||
| 369 | return ret; | 369 | return ret; |
| 370 | } | 370 | } |
| 371 | 371 | ||
| 372 | - if (input_type == SRS_CONF_DEFAULT_INGEST_TYPE_FILE) { | 372 | + if (srs_config_ingest_is_file(input_type)) { |
| 373 | std::string input_url = _srs_config->get_ingest_input_url(ingest); | 373 | std::string input_url = _srs_config->get_ingest_input_url(ingest); |
| 374 | if (input_url.empty()) { | 374 | if (input_url.empty()) { |
| 375 | ret = ERROR_ENCODER_NO_INPUT; | 375 | ret = ERROR_ENCODER_NO_INPUT; |
| @@ -383,7 +383,7 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S | @@ -383,7 +383,7 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S | ||
| 383 | if ((ret = ffmpeg->initialize(input_url, output, log_file)) != ERROR_SUCCESS) { | 383 | if ((ret = ffmpeg->initialize(input_url, output, log_file)) != ERROR_SUCCESS) { |
| 384 | return ret; | 384 | return ret; |
| 385 | } | 385 | } |
| 386 | - } else if (input_type == SRS_CONF_DEFAULT_INGEST_TYPE_STREAM) { | 386 | + } else if (srs_config_ingest_is_stream(input_type)) { |
| 387 | std::string input_url = _srs_config->get_ingest_input_url(ingest); | 387 | std::string input_url = _srs_config->get_ingest_input_url(ingest); |
| 388 | if (input_url.empty()) { | 388 | if (input_url.empty()) { |
| 389 | ret = ERROR_ENCODER_NO_INPUT; | 389 | ret = ERROR_ENCODER_NO_INPUT; |
| @@ -206,6 +206,7 @@ int SrsRtmpConn::do_cycle() | @@ -206,6 +206,7 @@ int SrsRtmpConn::do_cycle() | ||
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | ret = service_cycle(); | 208 | ret = service_cycle(); |
| 209 | + | ||
| 209 | http_hooks_on_close(); | 210 | http_hooks_on_close(); |
| 210 | SrsStatistic* stat = SrsStatistic::instance(); | 211 | SrsStatistic* stat = SrsStatistic::instance(); |
| 211 | stat->on_disconnect(_srs_context->get_id()); | 212 | stat->on_disconnect(_srs_context->get_id()); |
| @@ -432,10 +433,9 @@ int SrsRtmpConn::stream_service_cycle() | @@ -432,10 +433,9 @@ int SrsRtmpConn::stream_service_cycle() | ||
| 432 | } | 433 | } |
| 433 | 434 | ||
| 434 | // check ASAP, to fail it faster if invalid. | 435 | // check ASAP, to fail it faster if invalid. |
| 435 | - if (type != SrsRtmpConnPlay && !vhost_is_edge) { | 436 | + if (type != SrsRtmpConnPlay) { |
| 436 | // check publish available | 437 | // check publish available |
| 437 | - // for edge, never check it, for edge use proxy mode. | ||
| 438 | - if (!source->can_publish()) { | 438 | + if (!source->can_publish(vhost_is_edge)) { |
| 439 | ret = ERROR_SYSTEM_STREAM_BUSY; | 439 | ret = ERROR_SYSTEM_STREAM_BUSY; |
| 440 | srs_warn("stream %s is already publishing. ret=%d", | 440 | srs_warn("stream %s is already publishing. ret=%d", |
| 441 | req->get_stream_url().c_str(), ret); | 441 | req->get_stream_url().c_str(), ret); |
trunk/src/app/srs_app_rtmp_conn.hpp
100644 → 100755
| @@ -1350,8 +1350,12 @@ int SrsSource::source_id() | @@ -1350,8 +1350,12 @@ int SrsSource::source_id() | ||
| 1350 | return _source_id; | 1350 | return _source_id; |
| 1351 | } | 1351 | } |
| 1352 | 1352 | ||
| 1353 | -bool SrsSource::can_publish() | 1353 | +bool SrsSource::can_publish(bool is_edge) |
| 1354 | { | 1354 | { |
| 1355 | + if (is_edge) { | ||
| 1356 | + return publish_edge->can_publish(); | ||
| 1357 | + } | ||
| 1358 | + | ||
| 1355 | return _can_publish; | 1359 | return _can_publish; |
| 1356 | } | 1360 | } |
| 1357 | 1361 | ||
| @@ -1522,7 +1526,7 @@ int SrsSource::on_audio_imp(SrsSharedPtrMessage* msg) | @@ -1522,7 +1526,7 @@ int SrsSource::on_audio_imp(SrsSharedPtrMessage* msg) | ||
| 1522 | // apply the error strategy for hls. | 1526 | // apply the error strategy for hls. |
| 1523 | // @see https://github.com/simple-rtmp-server/srs/issues/264 | 1527 | // @see https://github.com/simple-rtmp-server/srs/issues/264 |
| 1524 | std::string hls_error_strategy = _srs_config->get_hls_on_error(_req->vhost); | 1528 | std::string hls_error_strategy = _srs_config->get_hls_on_error(_req->vhost); |
| 1525 | - if (hls_error_strategy == SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE) { | 1529 | + if (srs_config_hls_is_on_error_ignore(hls_error_strategy)) { |
| 1526 | srs_warn("hls process audio message failed, ignore and disable hls. ret=%d", ret); | 1530 | srs_warn("hls process audio message failed, ignore and disable hls. ret=%d", ret); |
| 1527 | 1531 | ||
| 1528 | // unpublish, ignore ret. | 1532 | // unpublish, ignore ret. |
| @@ -1530,7 +1534,7 @@ int SrsSource::on_audio_imp(SrsSharedPtrMessage* msg) | @@ -1530,7 +1534,7 @@ int SrsSource::on_audio_imp(SrsSharedPtrMessage* msg) | ||
| 1530 | 1534 | ||
| 1531 | // ignore. | 1535 | // ignore. |
| 1532 | ret = ERROR_SUCCESS; | 1536 | ret = ERROR_SUCCESS; |
| 1533 | - } else if (hls_error_strategy == SRS_CONF_DEFAULT_HLS_ON_ERROR_CONTINUE) { | 1537 | + } else if (srs_config_hls_is_on_error_continue(hls_error_strategy)) { |
| 1534 | // compare the sequence header with audio, continue when it's actually an sequence header. | 1538 | // compare the sequence header with audio, continue when it's actually an sequence header. |
| 1535 | if (ret == ERROR_HLS_DECODE_ERROR && cache_sh_audio && cache_sh_audio->size == msg->size) { | 1539 | if (ret == ERROR_HLS_DECODE_ERROR && cache_sh_audio && cache_sh_audio->size == msg->size) { |
| 1536 | srs_warn("the audio is actually a sequence header, ignore this packet."); | 1540 | srs_warn("the audio is actually a sequence header, ignore this packet."); |
| @@ -1726,7 +1730,7 @@ int SrsSource::on_video_imp(SrsSharedPtrMessage* msg) | @@ -1726,7 +1730,7 @@ int SrsSource::on_video_imp(SrsSharedPtrMessage* msg) | ||
| 1726 | // apply the error strategy for hls. | 1730 | // apply the error strategy for hls. |
| 1727 | // @see https://github.com/simple-rtmp-server/srs/issues/264 | 1731 | // @see https://github.com/simple-rtmp-server/srs/issues/264 |
| 1728 | std::string hls_error_strategy = _srs_config->get_hls_on_error(_req->vhost); | 1732 | std::string hls_error_strategy = _srs_config->get_hls_on_error(_req->vhost); |
| 1729 | - if (hls_error_strategy == SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE) { | 1733 | + if (srs_config_hls_is_on_error_ignore(hls_error_strategy)) { |
| 1730 | srs_warn("hls process video message failed, ignore and disable hls. ret=%d", ret); | 1734 | srs_warn("hls process video message failed, ignore and disable hls. ret=%d", ret); |
| 1731 | 1735 | ||
| 1732 | // unpublish, ignore ret. | 1736 | // unpublish, ignore ret. |
| @@ -1734,7 +1738,7 @@ int SrsSource::on_video_imp(SrsSharedPtrMessage* msg) | @@ -1734,7 +1738,7 @@ int SrsSource::on_video_imp(SrsSharedPtrMessage* msg) | ||
| 1734 | 1738 | ||
| 1735 | // ignore. | 1739 | // ignore. |
| 1736 | ret = ERROR_SUCCESS; | 1740 | ret = ERROR_SUCCESS; |
| 1737 | - } else if (hls_error_strategy == SRS_CONF_DEFAULT_HLS_ON_ERROR_CONTINUE) { | 1741 | + } else if (srs_config_hls_is_on_error_continue(hls_error_strategy)) { |
| 1738 | // compare the sequence header with video, continue when it's actually an sequence header. | 1742 | // compare the sequence header with video, continue when it's actually an sequence header. |
| 1739 | if (ret == ERROR_HLS_DECODE_ERROR && cache_sh_video && cache_sh_video->size == msg->size) { | 1743 | if (ret == ERROR_HLS_DECODE_ERROR && cache_sh_video && cache_sh_video->size == msg->size) { |
| 1740 | srs_warn("the video is actually a sequence header, ignore this packet."); | 1744 | srs_warn("the video is actually a sequence header, ignore this packet."); |
trunk/src/app/srs_app_source.hpp
100644 → 100755
| @@ -537,7 +537,7 @@ public: | @@ -537,7 +537,7 @@ public: | ||
| 537 | virtual int source_id(); | 537 | virtual int source_id(); |
| 538 | // logic data methods | 538 | // logic data methods |
| 539 | public: | 539 | public: |
| 540 | - virtual bool can_publish(); | 540 | + virtual bool can_publish(bool is_edge); |
| 541 | virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata); | 541 | virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata); |
| 542 | public: | 542 | public: |
| 543 | virtual int on_audio(SrsCommonMessage* audio); | 543 | virtual int on_audio(SrsCommonMessage* audio); |
| @@ -154,14 +154,17 @@ public: | @@ -154,14 +154,17 @@ public: | ||
| 154 | virtual void on_stream_close(SrsRequest* req); | 154 | virtual void on_stream_close(SrsRequest* req); |
| 155 | public: | 155 | public: |
| 156 | /** | 156 | /** |
| 157 | - * when got a client to publish/play stream, | ||
| 158 | - * @param id, the client srs id. | ||
| 159 | - * @param req, the client request object. | ||
| 160 | - */ | 157 | + * when got a client to publish/play stream, |
| 158 | + * @param id, the client srs id. | ||
| 159 | + * @param req, the client request object. | ||
| 160 | + */ | ||
| 161 | virtual int on_client(int id, SrsRequest* req); | 161 | virtual int on_client(int id, SrsRequest* req); |
| 162 | /** | 162 | /** |
| 163 | - * client disconnect | ||
| 164 | - */ | 163 | + * client disconnect |
| 164 | + * @remark the on_disconnect always call, while the on_client is call when | ||
| 165 | + * only got the request object, so the client specified by id maybe not | ||
| 166 | + * exists in stat. | ||
| 167 | + */ | ||
| 165 | virtual void on_disconnect(int id); | 168 | virtual void on_disconnect(int id); |
| 166 | /** | 169 | /** |
| 167 | * sample the kbps, add delta bytes of conn. | 170 | * sample the kbps, add delta bytes of conn. |
-
请 注册 或 登录 后发表评论