mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Move source to play stream
This commit is contained in:
parent
994c53b6c1
commit
b070e5aa05
2 changed files with 32 additions and 24 deletions
|
@ -200,6 +200,9 @@ SrsRtcPlayStream::SrsRtcPlayStream(SrsRtcConnection* s, SrsContextId parent_cid)
|
||||||
_parent_cid = parent_cid;
|
_parent_cid = parent_cid;
|
||||||
trd = new SrsDummyCoroutine();
|
trd = new SrsDummyCoroutine();
|
||||||
|
|
||||||
|
req_ = NULL;
|
||||||
|
source_ = NULL;
|
||||||
|
|
||||||
session_ = s;
|
session_ = s;
|
||||||
|
|
||||||
mw_msgs = 0;
|
mw_msgs = 0;
|
||||||
|
@ -215,6 +218,8 @@ SrsRtcPlayStream::~SrsRtcPlayStream()
|
||||||
{
|
{
|
||||||
_srs_config->unsubscribe(this);
|
_srs_config->unsubscribe(this);
|
||||||
|
|
||||||
|
srs_freep(req_);
|
||||||
|
|
||||||
srs_freep(trd);
|
srs_freep(trd);
|
||||||
srs_freep(timer_);
|
srs_freep(timer_);
|
||||||
|
|
||||||
|
@ -237,6 +242,12 @@ srs_error_t SrsRtcPlayStream::initialize(SrsRequest* req, std::map<uint32_t, Srs
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
req_ = req->copy();
|
||||||
|
|
||||||
|
if ((err = _srs_rtc_sources->fetch_or_create(req_, &source_)) != srs_success) {
|
||||||
|
return srs_error_wrap(err, "rtc fetch source failed");
|
||||||
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
std::map<uint32_t, SrsRtcTrackDescription*>::iterator it = sub_relations.begin();
|
std::map<uint32_t, SrsRtcTrackDescription*>::iterator it = sub_relations.begin();
|
||||||
while (it != sub_relations.end()) {
|
while (it != sub_relations.end()) {
|
||||||
|
@ -262,14 +273,12 @@ srs_error_t SrsRtcPlayStream::initialize(SrsRequest* req, std::map<uint32_t, Srs
|
||||||
|
|
||||||
srs_error_t SrsRtcPlayStream::on_reload_vhost_play(string vhost)
|
srs_error_t SrsRtcPlayStream::on_reload_vhost_play(string vhost)
|
||||||
{
|
{
|
||||||
SrsRequest* req = session_->req;
|
if (req_->vhost != vhost) {
|
||||||
|
|
||||||
if (req->vhost != vhost) {
|
|
||||||
return srs_success;
|
return srs_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
realtime = _srs_config->get_realtime_enabled(req->vhost, true);
|
realtime = _srs_config->get_realtime_enabled(req_->vhost, true);
|
||||||
mw_msgs = _srs_config->get_mw_msgs(req->vhost, realtime, true);
|
mw_msgs = _srs_config->get_mw_msgs(req_->vhost, realtime, true);
|
||||||
|
|
||||||
srs_trace("Reload play realtime=%d, mw_msgs=%d", realtime, mw_msgs);
|
srs_trace("Reload play realtime=%d, mw_msgs=%d", realtime, mw_msgs);
|
||||||
|
|
||||||
|
@ -309,7 +318,7 @@ srs_error_t SrsRtcPlayStream::start()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_srs_rtc_hijacker) {
|
if (_srs_rtc_hijacker) {
|
||||||
if ((err = _srs_rtc_hijacker->on_start_play(session_, this, session_->req)) != srs_success) {
|
if ((err = _srs_rtc_hijacker->on_start_play(session_, this, req_)) != srs_success) {
|
||||||
return srs_error_wrap(err, "on start play");
|
return srs_error_wrap(err, "on start play");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,30 +337,26 @@ srs_error_t SrsRtcPlayStream::cycle()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsRtcStream* source = NULL;
|
SrsRtcStream* source = source_;
|
||||||
SrsRequest* req = session_->req;
|
|
||||||
|
|
||||||
if ((err = _srs_rtc_sources->fetch_or_create(req, &source)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "fetch source");
|
|
||||||
}
|
|
||||||
|
|
||||||
SrsRtcConsumer* consumer = NULL;
|
SrsRtcConsumer* consumer = NULL;
|
||||||
SrsAutoFree(SrsRtcConsumer, consumer);
|
SrsAutoFree(SrsRtcConsumer, consumer);
|
||||||
if ((err = source->create_consumer(consumer)) != srs_success) {
|
if ((err = source->create_consumer(consumer)) != srs_success) {
|
||||||
return srs_error_wrap(err, "create consumer, source=%s", req->get_stream_url().c_str());
|
return srs_error_wrap(err, "create consumer, source=%s", req_->get_stream_url().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: Dumps the SPS/PPS from gop cache, without other frames.
|
// TODO: FIXME: Dumps the SPS/PPS from gop cache, without other frames.
|
||||||
if ((err = source->consumer_dumps(consumer)) != srs_success) {
|
if ((err = source->consumer_dumps(consumer)) != srs_success) {
|
||||||
return srs_error_wrap(err, "dumps consumer, url=%s", req->get_stream_url().c_str());
|
return srs_error_wrap(err, "dumps consumer, url=%s", req_->get_stream_url().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
realtime = _srs_config->get_realtime_enabled(req->vhost, true);
|
realtime = _srs_config->get_realtime_enabled(req_->vhost, true);
|
||||||
mw_msgs = _srs_config->get_mw_msgs(req->vhost, realtime, true);
|
mw_msgs = _srs_config->get_mw_msgs(req_->vhost, realtime, true);
|
||||||
|
|
||||||
// TODO: FIXME: Add cost in ms.
|
// TODO: FIXME: Add cost in ms.
|
||||||
srs_trace("RTC: start play, url=%s, source_id=[%d][%s], encrypt=%d, realtime=%d, mw_msgs=%d", req->get_stream_url().c_str(),
|
SrsContextId cid = source->source_id();
|
||||||
::getpid(), source->source_id().c_str(), session_->encrypt, realtime, mw_msgs);
|
srs_trace("RTC: start play url=%s, source_id=[%d][%s], encrypt=%d, realtime=%d, mw_msgs=%d", req_->get_stream_url().c_str(),
|
||||||
|
::getpid(), cid.c_str(), session_->encrypt, realtime, mw_msgs);
|
||||||
|
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_rtc_play();
|
SrsPithyPrint* pprint = SrsPithyPrint::create_rtc_play();
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
SrsAutoFree(SrsPithyPrint, pprint);
|
||||||
|
@ -363,7 +368,7 @@ srs_error_t SrsRtcPlayStream::cycle()
|
||||||
vector<SrsRtpPacket2*> pkts;
|
vector<SrsRtpPacket2*> pkts;
|
||||||
|
|
||||||
if (_srs_rtc_hijacker) {
|
if (_srs_rtc_hijacker) {
|
||||||
if ((err = _srs_rtc_hijacker->on_start_consume(session_, this, session_->req, consumer)) != srs_success) {
|
if ((err = _srs_rtc_hijacker->on_start_consume(session_, this, req_, consumer)) != srs_success) {
|
||||||
return srs_error_wrap(err, "on start consuming");
|
return srs_error_wrap(err, "on start consuming");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -738,7 +743,7 @@ srs_error_t SrsRtcPlayStream::on_rtcp_ps_feedback(char* buf, int nb_buf)
|
||||||
|
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case kPLI: {
|
case kPLI: {
|
||||||
ISrsRtcPublishStream* publisher = session_->source_->publish_stream();
|
ISrsRtcPublishStream* publisher = source_->publish_stream();
|
||||||
if (publisher) {
|
if (publisher) {
|
||||||
uint32_t ssrc = get_video_publish_ssrc(ssrc_of_media_source);
|
uint32_t ssrc = get_video_publish_ssrc(ssrc_of_media_source);
|
||||||
if (ssrc != 0) {
|
if (ssrc != 0) {
|
||||||
|
@ -1653,7 +1658,6 @@ SrsRtcConnection::SrsRtcConnection(SrsRtcServer* s, SrsContextId context_id)
|
||||||
stat_ = new SrsRtcConnectionStatistic();
|
stat_ = new SrsRtcConnectionStatistic();
|
||||||
timer_ = new SrsHourGlass(this, 1000 * SRS_UTIME_MILLISECONDS);
|
timer_ = new SrsHourGlass(this, 1000 * SRS_UTIME_MILLISECONDS);
|
||||||
|
|
||||||
source_ = NULL;
|
|
||||||
publisher_ = NULL;
|
publisher_ = NULL;
|
||||||
player_ = NULL;
|
player_ = NULL;
|
||||||
sendonly_skt = NULL;
|
sendonly_skt = NULL;
|
||||||
|
@ -1862,14 +1866,17 @@ srs_error_t SrsRtcConnection::add_player2(SrsRequest* req, SrsSdp& local_sdp)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: FIXME: Remove unused source.
|
||||||
srs_error_t SrsRtcConnection::initialize(SrsRtcStream* source, SrsRequest* r, bool is_publisher, string username)
|
srs_error_t SrsRtcConnection::initialize(SrsRtcStream* source, SrsRequest* r, bool is_publisher, string username)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
username_ = username;
|
username_ = username;
|
||||||
req = r->copy();
|
|
||||||
is_publisher_ = is_publisher;
|
is_publisher_ = is_publisher;
|
||||||
source_ = source;
|
|
||||||
|
if (r) { //TODO: FIXME: SrsRequest owner by Stream, not connection
|
||||||
|
req = r->copy();
|
||||||
|
}
|
||||||
|
|
||||||
SrsSessionConfig* cfg = &local_sdp.session_config_;
|
SrsSessionConfig* cfg = &local_sdp.session_config_;
|
||||||
if ((err = transport_->initialize(cfg)) != srs_success) {
|
if ((err = transport_->initialize(cfg)) != srs_success) {
|
||||||
|
|
|
@ -168,6 +168,8 @@ private:
|
||||||
SrsCoroutine* trd;
|
SrsCoroutine* trd;
|
||||||
SrsRtcConnection* session_;
|
SrsRtcConnection* session_;
|
||||||
private:
|
private:
|
||||||
|
SrsRequest* req_;
|
||||||
|
SrsRtcStream* source_;
|
||||||
SrsHourGlass* timer_;
|
SrsHourGlass* timer_;
|
||||||
// key: publish_ssrc, value: send track to process rtp/rtcp
|
// key: publish_ssrc, value: send track to process rtp/rtcp
|
||||||
std::map<uint32_t, SrsRtcAudioSendTrack*> audio_tracks_;
|
std::map<uint32_t, SrsRtcAudioSendTrack*> audio_tracks_;
|
||||||
|
@ -346,7 +348,6 @@ private:
|
||||||
// TODO: FIXME: Support reload.
|
// TODO: FIXME: Support reload.
|
||||||
bool encrypt;
|
bool encrypt;
|
||||||
SrsRequest* req;
|
SrsRequest* req;
|
||||||
SrsRtcStream* source_;
|
|
||||||
SrsSdp remote_sdp;
|
SrsSdp remote_sdp;
|
||||||
SrsSdp local_sdp;
|
SrsSdp local_sdp;
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue