正在显示
4 个修改的文件
包含
27 行增加
和
0 行删除
@@ -41,6 +41,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -41,6 +41,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
41 | #define SRS_PULSE_TIMEOUT_MS 100 | 41 | #define SRS_PULSE_TIMEOUT_MS 100 |
42 | #define SRS_SEND_TIMEOUT_MS 5000000L | 42 | #define SRS_SEND_TIMEOUT_MS 5000000L |
43 | #define SRS_RECV_TIMEOUT_MS SRS_SEND_TIMEOUT_MS | 43 | #define SRS_RECV_TIMEOUT_MS SRS_SEND_TIMEOUT_MS |
44 | +#define SRS_STREAM_BUSY_SLEEP_MS 2000 | ||
44 | 45 | ||
45 | SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd) | 46 | SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd) |
46 | : SrsConnection(srs_server, client_stfd) | 47 | : SrsConnection(srs_server, client_stfd) |
@@ -152,6 +153,16 @@ int SrsClient::do_cycle() | @@ -152,6 +153,16 @@ int SrsClient::do_cycle() | ||
152 | SrsSource* source = SrsSource::find(req->get_stream_url()); | 153 | SrsSource* source = SrsSource::find(req->get_stream_url()); |
153 | srs_assert(source != NULL); | 154 | srs_assert(source != NULL); |
154 | 155 | ||
156 | + // check publish available. | ||
157 | + if (type != SrsClientPlay && !source->can_publish()) { | ||
158 | + ret = ERROR_SYSTEM_STREAM_BUSY; | ||
159 | + srs_warn("stream %s is already publishing. ret=%d", | ||
160 | + req->get_stream_url().c_str(), ret); | ||
161 | + // to delay request | ||
162 | + st_usleep(SRS_STREAM_BUSY_SLEEP_MS * 1000); | ||
163 | + return ret; | ||
164 | + } | ||
165 | + | ||
155 | bool enabled_cache = true; | 166 | bool enabled_cache = true; |
156 | conf = config->get_gop_cache(req->vhost); | 167 | conf = config->get_gop_cache(req->vhost); |
157 | if (conf && conf->arg0() == "off") { | 168 | if (conf && conf->arg0() == "off") { |
@@ -78,6 +78,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -78,6 +78,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
78 | #define ERROR_SYSTEM_CONFIG_BLOCK_START 407 | 78 | #define ERROR_SYSTEM_CONFIG_BLOCK_START 407 |
79 | #define ERROR_SYSTEM_CONFIG_BLOCK_END 408 | 79 | #define ERROR_SYSTEM_CONFIG_BLOCK_END 408 |
80 | #define ERROR_SYSTEM_CONFIG_EOF 409 | 80 | #define ERROR_SYSTEM_CONFIG_EOF 409 |
81 | +#define ERROR_SYSTEM_STREAM_BUSY 410 | ||
81 | 82 | ||
82 | // see librtmp. | 83 | // see librtmp. |
83 | // failed when open ssl create the dh | 84 | // failed when open ssl create the dh |
@@ -268,6 +268,7 @@ SrsSource::SrsSource(std::string _stream_url) | @@ -268,6 +268,7 @@ SrsSource::SrsSource(std::string _stream_url) | ||
268 | enable_gop_cache = true; | 268 | enable_gop_cache = true; |
269 | 269 | ||
270 | video_frame_rate = audio_sample_rate = 0; | 270 | video_frame_rate = audio_sample_rate = 0; |
271 | + _can_publish = true; | ||
271 | } | 272 | } |
272 | 273 | ||
273 | SrsSource::~SrsSource() | 274 | SrsSource::~SrsSource() |
@@ -290,6 +291,11 @@ SrsSource::~SrsSource() | @@ -290,6 +291,11 @@ SrsSource::~SrsSource() | ||
290 | #endif | 291 | #endif |
291 | } | 292 | } |
292 | 293 | ||
294 | +bool SrsSource::can_publish() | ||
295 | +{ | ||
296 | + return _can_publish; | ||
297 | +} | ||
298 | + | ||
293 | int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata) | 299 | int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata) |
294 | { | 300 | { |
295 | int ret = ERROR_SUCCESS; | 301 | int ret = ERROR_SUCCESS; |
@@ -465,11 +471,13 @@ int SrsSource::on_video(SrsCommonMessage* video) | @@ -465,11 +471,13 @@ int SrsSource::on_video(SrsCommonMessage* video) | ||
465 | #ifdef SRS_HLS | 471 | #ifdef SRS_HLS |
466 | int SrsSource::on_publish(std::string vhost, std::string app, std::string stream) | 472 | int SrsSource::on_publish(std::string vhost, std::string app, std::string stream) |
467 | { | 473 | { |
474 | + _can_publish = false; | ||
468 | return hls->on_publish(vhost, app, stream); | 475 | return hls->on_publish(vhost, app, stream); |
469 | } | 476 | } |
470 | #else | 477 | #else |
471 | int SrsSource::on_publish(std::string /*vhost*/, std::string /*app*/, std::string /*stream*/) | 478 | int SrsSource::on_publish(std::string /*vhost*/, std::string /*app*/, std::string /*stream*/) |
472 | { | 479 | { |
480 | + _can_publish = false; | ||
473 | return ERROR_SUCCESS; | 481 | return ERROR_SUCCESS; |
474 | } | 482 | } |
475 | #endif | 483 | #endif |
@@ -489,6 +497,8 @@ void SrsSource::on_unpublish() | @@ -489,6 +497,8 @@ void SrsSource::on_unpublish() | ||
489 | srs_freep(cache_sh_audio); | 497 | srs_freep(cache_sh_audio); |
490 | 498 | ||
491 | srs_trace("clear cache/metadata/sequence-headers when unpublish."); | 499 | srs_trace("clear cache/metadata/sequence-headers when unpublish."); |
500 | + | ||
501 | + _can_publish = true; | ||
492 | } | 502 | } |
493 | 503 | ||
494 | int SrsSource::create_consumer(SrsConsumer*& consumer) | 504 | int SrsSource::create_consumer(SrsConsumer*& consumer) |
@@ -157,6 +157,10 @@ private: | @@ -157,6 +157,10 @@ private: | ||
157 | * the video frame rate in metadata. | 157 | * the video frame rate in metadata. |
158 | */ | 158 | */ |
159 | int video_frame_rate; | 159 | int video_frame_rate; |
160 | + /** | ||
161 | + * can publish, true when is not streaming | ||
162 | + */ | ||
163 | + bool _can_publish; | ||
160 | private: | 164 | private: |
161 | SrsSharedPtrMessage* cache_metadata; | 165 | SrsSharedPtrMessage* cache_metadata; |
162 | // the cached video sequence header. | 166 | // the cached video sequence header. |
@@ -167,6 +171,7 @@ public: | @@ -167,6 +171,7 @@ public: | ||
167 | SrsSource(std::string _stream_url); | 171 | SrsSource(std::string _stream_url); |
168 | virtual ~SrsSource(); | 172 | virtual ~SrsSource(); |
169 | public: | 173 | public: |
174 | + virtual bool can_publish(); | ||
170 | virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata); | 175 | virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata); |
171 | virtual int on_audio(SrsCommonMessage* audio); | 176 | virtual int on_audio(SrsCommonMessage* audio); |
172 | virtual int on_video(SrsCommonMessage* video); | 177 | virtual int on_video(SrsCommonMessage* video); |
-
请 注册 或 登录 后发表评论