mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
RTC: Use event notify for stream source
This commit is contained in:
parent
2b47b42213
commit
fb6c2fdf80
4 changed files with 50 additions and 18 deletions
|
@ -1431,11 +1431,6 @@ srs_error_t SrsRtcPublishStream::do_request_keyframe(uint32_t ssrc, SrsContextId
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcPublishStream::on_consumers_finished()
|
|
||||||
{
|
|
||||||
session_->on_consumers_finished(req->get_stream_url());
|
|
||||||
}
|
|
||||||
|
|
||||||
srs_error_t SrsRtcPublishStream::notify(int type, srs_utime_t interval, srs_utime_t tick)
|
srs_error_t SrsRtcPublishStream::notify(int type, srs_utime_t interval, srs_utime_t tick)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
@ -2067,13 +2062,6 @@ srs_error_t SrsRtcConnection::on_rtcp_feedback_remb(SrsRtcpPsfbCommon *rtcp)
|
||||||
return srs_success;
|
return srs_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcConnection::on_consumers_finished(std::string url)
|
|
||||||
{
|
|
||||||
if (hijacker_) {
|
|
||||||
hijacker_->on_consumers_finished(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SrsRtcConnection::set_hijacker(ISrsRtcConnectionHijacker* h)
|
void SrsRtcConnection::set_hijacker(ISrsRtcConnectionHijacker* h)
|
||||||
{
|
{
|
||||||
hijacker_ = h;
|
hijacker_ = h;
|
||||||
|
|
|
@ -370,7 +370,6 @@ private:
|
||||||
public:
|
public:
|
||||||
void request_keyframe(uint32_t ssrc);
|
void request_keyframe(uint32_t ssrc);
|
||||||
virtual srs_error_t do_request_keyframe(uint32_t ssrc, SrsContextId cid);
|
virtual srs_error_t do_request_keyframe(uint32_t ssrc, SrsContextId cid);
|
||||||
void on_consumers_finished();
|
|
||||||
// interface ISrsHourGlass
|
// interface ISrsHourGlass
|
||||||
public:
|
public:
|
||||||
virtual srs_error_t notify(int type, srs_utime_t interval, srs_utime_t tick);
|
virtual srs_error_t notify(int type, srs_utime_t interval, srs_utime_t tick);
|
||||||
|
@ -412,8 +411,6 @@ public:
|
||||||
virtual ~ISrsRtcConnectionHijacker();
|
virtual ~ISrsRtcConnectionHijacker();
|
||||||
public:
|
public:
|
||||||
virtual srs_error_t on_dtls_done() = 0;
|
virtual srs_error_t on_dtls_done() = 0;
|
||||||
// Notify when all consumers of publisher(specified by url) is finished.
|
|
||||||
virtual void on_consumers_finished(std::string url) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// A RTC Peer Connection, SDP level object.
|
// A RTC Peer Connection, SDP level object.
|
||||||
|
@ -516,7 +513,6 @@ public:
|
||||||
srs_error_t on_rtcp_feedback_twcc(char* buf, int nb_buf);
|
srs_error_t on_rtcp_feedback_twcc(char* buf, int nb_buf);
|
||||||
srs_error_t on_rtcp_feedback_remb(SrsRtcpPsfbCommon *rtcp);
|
srs_error_t on_rtcp_feedback_remb(SrsRtcpPsfbCommon *rtcp);
|
||||||
public:
|
public:
|
||||||
void on_consumers_finished(std::string url);
|
|
||||||
void set_hijacker(ISrsRtcConnectionHijacker* h);
|
void set_hijacker(ISrsRtcConnectionHijacker* h);
|
||||||
public:
|
public:
|
||||||
srs_error_t on_connection_established();
|
srs_error_t on_connection_established();
|
||||||
|
|
|
@ -290,6 +290,14 @@ ISrsRtcPublishStream::~ISrsRtcPublishStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ISrsRtcStreamEventHandler::ISrsRtcStreamEventHandler()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ISrsRtcStreamEventHandler::~ISrsRtcStreamEventHandler()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
SrsRtcStream::SrsRtcStream()
|
SrsRtcStream::SrsRtcStream()
|
||||||
{
|
{
|
||||||
is_created_ = false;
|
is_created_ = false;
|
||||||
|
@ -411,7 +419,10 @@ void SrsRtcStream::on_consumer_destroy(SrsRtcConsumer* consumer)
|
||||||
|
|
||||||
// When all consumers finished, notify publisher to handle it.
|
// When all consumers finished, notify publisher to handle it.
|
||||||
if (publish_stream_ && consumers.empty()) {
|
if (publish_stream_ && consumers.empty()) {
|
||||||
publish_stream_->on_consumers_finished();
|
for (size_t i = 0; i < event_handlers_.size(); i++) {
|
||||||
|
ISrsRtcStreamEventHandler* h = event_handlers_.at(i);
|
||||||
|
h->on_consumers_finished();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,9 +474,30 @@ void SrsRtcStream::on_unpublish()
|
||||||
|
|
||||||
_source_id = SrsContextId();
|
_source_id = SrsContextId();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < event_handlers_.size(); i++) {
|
||||||
|
ISrsRtcStreamEventHandler* h = event_handlers_.at(i);
|
||||||
|
h->on_unpublish();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: FIXME: Handle by statistic.
|
// TODO: FIXME: Handle by statistic.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SrsRtcStream::subscribe(ISrsRtcStreamEventHandler* h)
|
||||||
|
{
|
||||||
|
if (std::find(event_handlers_.begin(), event_handlers_.end(), h) == event_handlers_.end()) {
|
||||||
|
event_handlers_.push_back(h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SrsRtcStream::unsubscribe(ISrsRtcStreamEventHandler* h)
|
||||||
|
{
|
||||||
|
std::vector<ISrsRtcStreamEventHandler*>::iterator it;
|
||||||
|
it = std::find(event_handlers_.begin(), event_handlers_.end(), h);
|
||||||
|
if (it != event_handlers_.end()) {
|
||||||
|
event_handlers_.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ISrsRtcPublishStream* SrsRtcStream::publish_stream()
|
ISrsRtcPublishStream* SrsRtcStream::publish_stream()
|
||||||
{
|
{
|
||||||
return publish_stream_;
|
return publish_stream_;
|
||||||
|
|
|
@ -132,7 +132,17 @@ public:
|
||||||
public:
|
public:
|
||||||
// Request keyframe(PLI) from publisher, for fresh consumer.
|
// Request keyframe(PLI) from publisher, for fresh consumer.
|
||||||
virtual void request_keyframe(uint32_t ssrc) = 0;
|
virtual void request_keyframe(uint32_t ssrc) = 0;
|
||||||
// Notify publisher that all consumers is finished.
|
};
|
||||||
|
|
||||||
|
class ISrsRtcStreamEventHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ISrsRtcStreamEventHandler();
|
||||||
|
virtual ~ISrsRtcStreamEventHandler();
|
||||||
|
public:
|
||||||
|
// stream unpublish, sync API.
|
||||||
|
virtual void on_unpublish() = 0;
|
||||||
|
// no player subscribe this stream, sync API
|
||||||
virtual void on_consumers_finished() = 0;
|
virtual void on_consumers_finished() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -160,6 +170,8 @@ private:
|
||||||
bool is_created_;
|
bool is_created_;
|
||||||
// Whether stream is delivering data, that is, DTLS is done.
|
// Whether stream is delivering data, that is, DTLS is done.
|
||||||
bool is_delivering_packets_;
|
bool is_delivering_packets_;
|
||||||
|
// Notify stream event to event handler
|
||||||
|
std::vector<ISrsRtcStreamEventHandler*> event_handlers_;
|
||||||
public:
|
public:
|
||||||
SrsRtcStream();
|
SrsRtcStream();
|
||||||
virtual ~SrsRtcStream();
|
virtual ~SrsRtcStream();
|
||||||
|
@ -193,6 +205,10 @@ public:
|
||||||
virtual srs_error_t on_publish();
|
virtual srs_error_t on_publish();
|
||||||
// When stop publish stream.
|
// When stop publish stream.
|
||||||
virtual void on_unpublish();
|
virtual void on_unpublish();
|
||||||
|
public:
|
||||||
|
// For event handler
|
||||||
|
void subscribe(ISrsRtcStreamEventHandler* h);
|
||||||
|
void unsubscribe(ISrsRtcStreamEventHandler* h);
|
||||||
public:
|
public:
|
||||||
// Get and set the publisher, passed to consumer to process requests such as PLI.
|
// Get and set the publisher, passed to consumer to process requests such as PLI.
|
||||||
ISrsRtcPublishStream* publish_stream();
|
ISrsRtcPublishStream* publish_stream();
|
||||||
|
|
Loading…
Reference in a new issue