优化MultiMediaSourceMuxer相关代码

This commit is contained in:
xiongziliang 2022-11-05 20:47:33 +08:00
parent 7e95bd2078
commit 0053148139
2 changed files with 13 additions and 12 deletions

View File

@ -89,6 +89,14 @@ const std::string &MultiMediaSourceMuxer::getStreamId() const {
return _stream_id; return _stream_id;
} }
std::string MultiMediaSourceMuxer::shortUrl() const {
auto ret = getOriginUrl(MediaSource::NullMediaSource());
if (!ret.empty()) {
return ret;
}
return _vhost + "/" + _app + "/" + _stream_id;
}
MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost, const string &app, const string &stream, float dur_sec, const ProtocolOption &option) { MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost, const string &app, const string &stream, float dur_sec, const ProtocolOption &option) {
_poller = EventPollerPool::Instance().getPoller(); _poller = EventPollerPool::Instance().getPoller();
_create_in_poller = _poller->isCurrentThread(); _create_in_poller = _poller->isCurrentThread();
@ -96,13 +104,6 @@ MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost, const string &
_app = app; _app = app;
_stream_id = stream; _stream_id = stream;
_option = option; _option = option;
_get_origin_url = [this, vhost, app, stream]() {
auto ret = getOriginUrl(MediaSource::NullMediaSource());
if (!ret.empty()) {
return ret;
}
return vhost + "/" + app + "/" + stream;
};
if (option.enable_rtmp) { if (option.enable_rtmp) {
_rtmp = std::make_shared<RtmpMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleMeta>(dur_sec)); _rtmp = std::make_shared<RtmpMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleMeta>(dur_sec));
@ -267,7 +268,7 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &sender, const MediaSourceE
auto ssrc = args.ssrc; auto ssrc = args.ssrc;
rtp_sender->setOnClose([weak_self, ssrc](const toolkit::SockException &ex) { rtp_sender->setOnClose([weak_self, ssrc](const toolkit::SockException &ex) {
if (auto strong_self = weak_self.lock()) { if (auto strong_self = weak_self.lock()) {
WarnL << "stream:" << strong_self->_get_origin_url() << " stop send rtp:" << ssrc << ", reason:" << ex.what(); WarnL << "stream:" << strong_self->shortUrl() << " stop send rtp:" << ssrc << ", reason:" << ex.what();
strong_self->_rtp_sender.erase(ssrc); strong_self->_rtp_sender.erase(ssrc);
//触发观看人数统计 //触发观看人数统计
strong_self->onReaderChanged(MediaSource::NullMediaSource(), strong_self->totalReaderCount()); strong_self->onReaderChanged(MediaSource::NullMediaSource(), strong_self->totalReaderCount());
@ -313,7 +314,7 @@ EventPoller::Ptr MultiMediaSourceMuxer::getOwnerPoller(MediaSource &sender) {
try { try {
auto ret = listener->getOwnerPoller(sender); auto ret = listener->getOwnerPoller(sender);
if (ret != _poller) { if (ret != _poller) {
WarnL << "OwnerPoller changed:" << _get_origin_url(); WarnL << "OwnerPoller changed:" << shortUrl();
_poller = ret; _poller = ret;
} }
return ret; return ret;
@ -372,7 +373,7 @@ void MultiMediaSourceMuxer::onAllTrackReady() {
if (listener) { if (listener) {
listener->onAllTrackReady(); listener->onAllTrackReady();
} }
InfoL << "stream: " << _get_origin_url() << " , codec info: " << getTrackInfoStr(this); InfoL << "stream: " << shortUrl() << " , codec info: " << getTrackInfoStr(this);
} }
void MultiMediaSourceMuxer::resetTracks() { void MultiMediaSourceMuxer::resetTracks() {

View File

@ -94,7 +94,7 @@ class MultiMediaSourceMuxer : public MediaSourceEventInterceptor, public MediaSi
public: public:
typedef std::shared_ptr<MultiMediaSourceMuxer> Ptr; typedef std::shared_ptr<MultiMediaSourceMuxer> Ptr;
class Listener{ class Listener {
public: public:
Listener() = default; Listener() = default;
virtual ~Listener() = default; virtual ~Listener() = default;
@ -193,6 +193,7 @@ public:
const std::string& getVhost() const; const std::string& getVhost() const;
const std::string& getApp() const; const std::string& getApp() const;
const std::string& getStreamId() const; const std::string& getStreamId() const;
std::string shortUrl() const;
protected: protected:
/////////////////////////////////MediaSink override///////////////////////////////// /////////////////////////////////MediaSink override/////////////////////////////////
@ -225,7 +226,6 @@ private:
toolkit::Ticker _last_check; toolkit::Ticker _last_check;
Stamp _stamp[2]; Stamp _stamp[2];
std::weak_ptr<Listener> _track_listener; std::weak_ptr<Listener> _track_listener;
std::function<std::string()> _get_origin_url;
#if defined(ENABLE_RTPPROXY) #if defined(ENABLE_RTPPROXY)
std::unordered_map<std::string, RtpSender::Ptr> _rtp_sender; std::unordered_map<std::string, RtpSender::Ptr> _rtp_sender;
#endif //ENABLE_RTPPROXY #endif //ENABLE_RTPPROXY