Replace the tuple (vhost/app/stream) with MediaTuple. (#2560)

This commit is contained in:
johzzy
2023-06-17 10:28:01 +08:00
committed by GitHub
parent c0a7a4ab70
commit 03770ff409
11 changed files with 37 additions and 76 deletions

View File

@@ -131,23 +131,6 @@ MediaSource::~MediaSource() {
}
}
const string& MediaSource::getSchema() const {
return _schema;
}
const string& MediaSource::getVhost() const {
return _tuple.vhost;
}
const string& MediaSource::getApp() const {
//获取该源的id
return _tuple.app;
}
const string& MediaSource::getId() const {
return _tuple.stream;
}
std::shared_ptr<void> MediaSource::getOwnership() {
if (_owned.test_and_set()) {
//已经被所有
@@ -460,9 +443,7 @@ static void findAsync_l(const MediaInfo &info, const std::shared_ptr<Session> &s
auto on_register = [weak_session, info, cb_once, cancel_all, poller](BroadcastMediaChangedArgs) {
if (!bRegist ||
sender.getSchema() != info.schema ||
sender.getVhost() != info.vhost ||
sender.getApp() != info.app ||
sender.getId() != info.stream) {
!equalMediaTuple(sender.getMediaTuple(), info)) {
//不是自己感兴趣的事件,忽略之
return;
}
@@ -579,6 +560,9 @@ bool MediaSource::unregist() {
return ret;
}
bool equalMediaTuple(const MediaTuple& a, const MediaTuple& b) {
return a.vhost == b.vhost && a.app == b.app && a.stream == b.stream;
}
/////////////////////////////////////MediaInfo//////////////////////////////////////
void MediaInfo::parse(const std::string &url_in){
@@ -663,7 +647,7 @@ void MediaSourceEvent::onReaderChanged(MediaSource &sender, int size){
GET_CONFIG(string, record_app, Record::kAppName);
GET_CONFIG(int, stream_none_reader_delay, General::kStreamNoneReaderDelayMS);
//如果mp4点播, 无人观看时我们强制关闭点播
bool is_mp4_vod = sender.getApp() == record_app;
bool is_mp4_vod = sender.getMediaTuple().app == record_app;
weak_ptr<MediaSource> weak_sender = sender.shared_from_this();
_async_close_timer = std::make_shared<Timer>(stream_none_reader_delay / 1000.0f, [weak_sender, is_mp4_vod]() {

View File

@@ -274,6 +274,8 @@ public:
std::string param_strs;
};
bool equalMediaTuple(const MediaTuple& a, const MediaTuple& b);
/**
* 媒体源任何rtsp/rtmp的直播流都源自该对象
*/
@@ -288,21 +290,15 @@ public:
////////////////获取MediaSource相关信息////////////////
// 获取协议类型
const std::string& getSchema() const;
// 虚拟主机
const std::string& getVhost() const;
// 应用名
const std::string& getApp() const;
// 流id
const std::string& getId() const;
const std::string& getSchema() const {
return _schema;
}
const MediaTuple& getMediaTuple() const {
return _tuple;
}
std::string shortUrl() const { return _tuple.shortUrl(); }
std::string getUrl() const { return _schema + "://" + shortUrl(); }
std::string getUrl() const { return _schema + "://" + _tuple.shortUrl(); }
//获取对象所有权
std::shared_ptr<void> getOwnership();

View File

@@ -70,18 +70,6 @@ static string getTrackInfoStr(const TrackSource *track_src){
return std::move(codec_info);
}
const std::string &MultiMediaSourceMuxer::getVhost() const {
return _tuple.vhost;
}
const std::string &MultiMediaSourceMuxer::getApp() const {
return _tuple.app;
}
const std::string &MultiMediaSourceMuxer::getStreamId() const {
return _tuple.stream;
}
std::string MultiMediaSourceMuxer::shortUrl() const {
auto ret = getOriginUrl(MediaSource::NullMediaSource());
if (!ret.empty()) {

View File

@@ -126,9 +126,6 @@ public:
*/
toolkit::EventPoller::Ptr getOwnerPoller(MediaSource &sender) override;
const std::string& getVhost() const;
const std::string& getApp() const;
const std::string& getStreamId() const;
const MediaTuple& getMediaTuple() const {
return _tuple;
}