From fbc6eebe1833562ef259579411ed1a61133fe0e1 Mon Sep 17 00:00:00 2001 From: hondaxiao Date: Mon, 30 May 2022 20:03:11 +0800 Subject: [PATCH] SRT: remove rtmp_to_srt --- trunk/conf/full.conf | 1 - trunk/conf/srt.conf | 1 - trunk/src/app/srs_app_config.cpp | 20 +----- trunk/src/app/srs_app_config.hpp | 1 - trunk/src/app/srs_app_rtmp_conn.cpp | 25 -------- trunk/src/app/srs_app_srt_source.cpp | 92 ---------------------------- trunk/src/app/srs_app_srt_source.hpp | 24 -------- 7 files changed, 1 insertion(+), 163 deletions(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index d62004ff4..7d45cc7e5 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -412,7 +412,6 @@ vhost srt.vhost.srs.com { srt { enabled on; srt_to_rtmp on; - rtmp_to_srt on; } } diff --git a/trunk/conf/srt.conf b/trunk/conf/srt.conf index f9cc63f50..582bc0056 100644 --- a/trunk/conf/srt.conf +++ b/trunk/conf/srt.conf @@ -35,7 +35,6 @@ vhost __defaultVhost__ { srt { enabled on; srt_to_rtmp on; - rtmp_to_srt on; } http_remux { diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 46b5d1fec..96afd544c 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -2883,7 +2883,7 @@ srs_error_t SrsConfig::check_normal_config() } else if (n == "srt") { for (int j = 0; j < (int)conf->directives.size(); j++) { string m = conf->at(j)->name; - if (m != "enabled" && m != "rtmp_to_srt" && m != "srt_to_rtmp") { + if (m != "enabled" && m != "srt_to_rtmp") { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.srt.%s of %s", m.c_str(), vhost->arg0().c_str()); } } @@ -7019,24 +7019,6 @@ bool SrsConfig::get_srt_to_rtmp(std::string vhost) return SRS_CONF_PERFER_FALSE(conf->arg0()); } -bool SrsConfig::get_srt_from_rtmp(std::string vhost) -{ - static bool DEFAULT = false; - - SrsConfDirective* conf = get_srt(vhost); - - if (!conf) { - return DEFAULT; - } - - conf = conf->get("rtmp_to_srt"); - if (!conf || conf->arg0().empty()) { - return DEFAULT; - } - - return SRS_CONF_PERFER_FALSE(conf->arg0()); -} - bool SrsConfig::get_http_stream_enabled() { SrsConfDirective* conf = root->get("http_server"); diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index d9bd6b47c..1f59332c9 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -665,7 +665,6 @@ private: public: bool get_srt_enabled(std::string vhost); bool get_srt_to_rtmp(std::string vhost); - bool get_srt_from_rtmp(std::string vhost); // http_hooks section private: diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 69b135190..687644968 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -952,31 +952,6 @@ srs_error_t SrsRtmpConn::acquire_publish(SrsLiveSource* source) return srs_error_new(ERROR_SYSTEM_STREAM_BUSY, "rtmp: stream %s is busy", req->get_stream_url().c_str()); } -#ifdef SRS_SRT - if (_srs_config->get_rtc_from_rtmp(req->vhost)) { - SrsSrtSource *srt = NULL; - if (!info->edge) { - if ((err = _srs_srt_sources->fetch_or_create(req, &srt)) != srs_success) { - return srs_error_wrap(err, "create source"); - } - - if (!srt->can_publish()) { - return srs_error_new(ERROR_SYSTEM_STREAM_BUSY, "srt stream %s busy", req->get_stream_url().c_str()); - } - } - - if (srt) { - SrsSrtFromRtmpBridge *bridger = new SrsSrtFromRtmpBridge(srt); - if ((err = bridger->initialize(req)) != srs_success) { - srs_freep(bridger); - return srs_error_wrap(err, "bridger init"); - } - - source->set_bridger(bridger); - } - } -#endif - // Check whether RTC stream is busy. #ifdef SRS_RTC SrsRtcSource *rtc = NULL; diff --git a/trunk/src/app/srs_app_srt_source.cpp b/trunk/src/app/srs_app_srt_source.cpp index 0f03ac820..78b1d7054 100644 --- a/trunk/src/app/srs_app_srt_source.cpp +++ b/trunk/src/app/srs_app_srt_source.cpp @@ -815,95 +815,3 @@ srs_error_t SrsSrtSource::on_packet(SrsSrtPacket* packet) return err; } -SrsSrtFromRtmpBridge::SrsSrtFromRtmpBridge(SrsSrtSource* source) - : ISrsLiveSourceBridger(SrsBridgeDestTypeSRT) -{ - srt_source_ = source; - ts_muxer_ = NULL; - offset_ = 0; -} - -SrsSrtFromRtmpBridge::~SrsSrtFromRtmpBridge() -{ - srs_freep(ts_muxer_); -} - -srs_error_t SrsSrtFromRtmpBridge::initialize(SrsRequest* r) -{ - srs_error_t err = srs_success; - - // TODO: FIXME: check config. - req_ = r; - - ts_muxer_ = new SrsTsTransmuxer(); - if ((err = ts_muxer_->initialize(this)) != srs_success) { - return srs_error_wrap(err, "init ts muxer"); - } - - return err; -} - -srs_error_t SrsSrtFromRtmpBridge::on_publish() -{ - srs_error_t err = srs_success; - - // TODO: FIXME: check if enable rtmp_to_srt - - if ((err = srt_source_->on_publish()) != srs_success) { - return srs_error_wrap(err, "source publish"); - } - - return err; -} - -void SrsSrtFromRtmpBridge::on_unpublish() -{ - // TODO: FIXME: check if enable rtmp_to_srt - srt_source_->on_unpublish(); -} - -srs_error_t SrsSrtFromRtmpBridge::on_audio(SrsSharedPtrMessage* msg) -{ - srs_error_t err = srs_success; - - if ((err = ts_muxer_->write_audio(msg->timestamp, msg->payload, msg->size)) != srs_success) { - return srs_error_wrap(err, "rtmp to srt, ts mux audio"); - } - - return err; -} - -srs_error_t SrsSrtFromRtmpBridge::on_video(SrsSharedPtrMessage* msg) -{ - srs_error_t err = srs_success; - - if ((err = ts_muxer_->write_video(msg->timestamp, msg->payload, msg->size)) != srs_success) { - return srs_error_wrap(err, "rtmp to srt, ts mux video"); - } - - return err; -} - -srs_error_t SrsSrtFromRtmpBridge::write(void* buf, size_t size, ssize_t* nwrite) -{ - srs_error_t err = srs_success; - - if (size % SRS_TS_PACKET_SIZE != 0) { - return srs_error_new(ERROR_RTMP_TO_SRT, "invalid ts size=%u", size); - } - - for (int i = 0; i < size; i += SRS_TS_PACKET_SIZE) { - memcpy(ts_buf_ + offset_, (const char*)buf + i, SRS_TS_PACKET_SIZE); - offset_ += SRS_TS_PACKET_SIZE; - if (offset_ >= 1316) { - offset_ = 0; - SrsSrtPacket* packet = new SrsSrtPacket(); - SrsAutoFree(SrsSrtPacket, packet); - packet->wrap(ts_buf_, 1316); - - srt_source_->on_packet(packet); - } - } - - return err; -} diff --git a/trunk/src/app/srs_app_srt_source.hpp b/trunk/src/app/srs_app_srt_source.hpp index 14c2a5517..7a4b06b3b 100644 --- a/trunk/src/app/srs_app_srt_source.hpp +++ b/trunk/src/app/srs_app_srt_source.hpp @@ -182,29 +182,5 @@ private: std::vector bridgers_; }; -class SrsSrtFromRtmpBridge : public ISrsLiveSourceBridger, public ISrsStreamWriter -{ -public: - SrsSrtFromRtmpBridge(SrsSrtSource* source); - virtual ~SrsSrtFromRtmpBridge(); -public: - virtual srs_error_t initialize(SrsRequest* r); -// Interface for ISrsLiveSourceBridger -public: - virtual srs_error_t on_publish(); - virtual void on_unpublish(); - virtual srs_error_t on_audio(SrsSharedPtrMessage* msg); - virtual srs_error_t on_video(SrsSharedPtrMessage* msg); -// Interface for ISrsStreamWriter -public: - virtual srs_error_t write(void* buf, size_t size, ssize_t* nwrite); -private: - SrsRequest* req_; - SrsSrtSource* srt_source_; - SrsTsTransmuxer* ts_muxer_; - char ts_buf_[1316]; - int offset_; -}; - #endif