check publish streaming available

pull/133/head
winlin 11 years ago
parent ec5cb39b96
commit 62a2384a35

@ -41,6 +41,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define SRS_PULSE_TIMEOUT_MS 100 #define SRS_PULSE_TIMEOUT_MS 100
#define SRS_SEND_TIMEOUT_MS 5000000L #define SRS_SEND_TIMEOUT_MS 5000000L
#define SRS_RECV_TIMEOUT_MS SRS_SEND_TIMEOUT_MS #define SRS_RECV_TIMEOUT_MS SRS_SEND_TIMEOUT_MS
#define SRS_STREAM_BUSY_SLEEP_MS 2000
SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd) SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd)
: SrsConnection(srs_server, client_stfd) : SrsConnection(srs_server, client_stfd)
@ -152,6 +153,16 @@ int SrsClient::do_cycle()
SrsSource* source = SrsSource::find(req->get_stream_url()); SrsSource* source = SrsSource::find(req->get_stream_url());
srs_assert(source != NULL); srs_assert(source != NULL);
// check publish available.
if (type != SrsClientPlay && !source->can_publish()) {
ret = ERROR_SYSTEM_STREAM_BUSY;
srs_warn("stream %s is already publishing. ret=%d",
req->get_stream_url().c_str(), ret);
// to delay request
st_usleep(SRS_STREAM_BUSY_SLEEP_MS * 1000);
return ret;
}
bool enabled_cache = true; bool enabled_cache = true;
conf = config->get_gop_cache(req->vhost); conf = config->get_gop_cache(req->vhost);
if (conf && conf->arg0() == "off") { if (conf && conf->arg0() == "off") {

@ -78,6 +78,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define ERROR_SYSTEM_CONFIG_BLOCK_START 407 #define ERROR_SYSTEM_CONFIG_BLOCK_START 407
#define ERROR_SYSTEM_CONFIG_BLOCK_END 408 #define ERROR_SYSTEM_CONFIG_BLOCK_END 408
#define ERROR_SYSTEM_CONFIG_EOF 409 #define ERROR_SYSTEM_CONFIG_EOF 409
#define ERROR_SYSTEM_STREAM_BUSY 410
// see librtmp. // see librtmp.
// failed when open ssl create the dh // failed when open ssl create the dh

@ -268,6 +268,7 @@ SrsSource::SrsSource(std::string _stream_url)
enable_gop_cache = true; enable_gop_cache = true;
video_frame_rate = audio_sample_rate = 0; video_frame_rate = audio_sample_rate = 0;
_can_publish = true;
} }
SrsSource::~SrsSource() SrsSource::~SrsSource()
@ -290,6 +291,11 @@ SrsSource::~SrsSource()
#endif #endif
} }
bool SrsSource::can_publish()
{
return _can_publish;
}
int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata) int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
@ -465,11 +471,13 @@ int SrsSource::on_video(SrsCommonMessage* video)
#ifdef SRS_HLS #ifdef SRS_HLS
int SrsSource::on_publish(std::string vhost, std::string app, std::string stream) int SrsSource::on_publish(std::string vhost, std::string app, std::string stream)
{ {
_can_publish = false;
return hls->on_publish(vhost, app, stream); return hls->on_publish(vhost, app, stream);
} }
#else #else
int SrsSource::on_publish(std::string /*vhost*/, std::string /*app*/, std::string /*stream*/) int SrsSource::on_publish(std::string /*vhost*/, std::string /*app*/, std::string /*stream*/)
{ {
_can_publish = false;
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
#endif #endif
@ -489,6 +497,8 @@ void SrsSource::on_unpublish()
srs_freep(cache_sh_audio); srs_freep(cache_sh_audio);
srs_trace("clear cache/metadata/sequence-headers when unpublish."); srs_trace("clear cache/metadata/sequence-headers when unpublish.");
_can_publish = true;
} }
int SrsSource::create_consumer(SrsConsumer*& consumer) int SrsSource::create_consumer(SrsConsumer*& consumer)

@ -157,6 +157,10 @@ private:
* the video frame rate in metadata. * the video frame rate in metadata.
*/ */
int video_frame_rate; int video_frame_rate;
/**
* can publish, true when is not streaming
*/
bool _can_publish;
private: private:
SrsSharedPtrMessage* cache_metadata; SrsSharedPtrMessage* cache_metadata;
// the cached video sequence header. // the cached video sequence header.
@ -167,6 +171,7 @@ public:
SrsSource(std::string _stream_url); SrsSource(std::string _stream_url);
virtual ~SrsSource(); virtual ~SrsSource();
public: public:
virtual bool can_publish();
virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata); virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata);
virtual int on_audio(SrsCommonMessage* audio); virtual int on_audio(SrsCommonMessage* audio);
virtual int on_video(SrsCommonMessage* video); virtual int on_video(SrsCommonMessage* video);

Loading…
Cancel
Save