添加媒体注册回调事件:#373

This commit is contained in:
xiongziliang
2020-07-02 18:14:39 +08:00
parent 5195475116
commit 3c858a8351
8 changed files with 73 additions and 1 deletions

View File

@@ -295,7 +295,7 @@ void MediaSource::regist() {
//注册该源,注册后服务器才能找到该源
{
lock_guard<recursive_mutex> lock(g_mtxMediaSrc);
g_mapMediaSrc[_strSchema][_strVhost][_strApp][_strId] = shared_from_this();
g_mapMediaSrc[_strSchema][_strVhost][_strApp][_strId] = shared_from_this();
}
_StrPrinter codec_info;
auto tracks = getTracks(true);
@@ -326,6 +326,11 @@ void MediaSource::regist() {
InfoL << _strSchema << " " << _strVhost << " " << _strApp << " " << _strId << " " << codec_info;
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaChanged, true, *this);
auto listener = _listener.lock();
if (listener) {
listener->onRegist(*this, true);
}
}
//反注册该源
@@ -352,6 +357,11 @@ bool MediaSource::unregist() {
if(ret){
InfoL << _strSchema << " " << _strVhost << " " << _strApp << " " << _strId;
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaChanged, false, *this);
auto listener = _listener.lock();
if (listener) {
listener->onRegist(*this, false);
}
}
return ret;
}

View File

@@ -55,6 +55,8 @@ public:
virtual bool isRecording(MediaSource &sender, Recorder::type type) { return false; };
// 通知无人观看
virtual void onNoneReader(MediaSource &sender);
//流注册或注销事件
virtual void onRegist(MediaSource &sender, bool regist) {};
private:
Timer::Ptr _async_close_timer;

View File

@@ -287,6 +287,13 @@ void MultiMediaSourceMuxer::onNoneReader(MediaSource &sender){
listener->onNoneReader(sender);
}
void MultiMediaSourceMuxer::onRegist(MediaSource &sender, bool regist){
auto listener = _listener.lock();
if (listener) {
listener->onRegist(sender, regist);
}
}
bool MultiMediaSourceMuxer::setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path) {
return _muxer->setupRecord(sender,type,start,custom_path);
}

View File

@@ -137,6 +137,13 @@ public:
*/
void onNoneReader(MediaSource &sender) override;
/**
* 媒体注册注销事件
* @param sender 触发者
* @param regist 是否为注册事件
*/
void onRegist(MediaSource &sender, bool regist) override;
/**
* 设置录制状态
* @param type 录制类型