mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-27 04:20:13 +08:00
添加媒体注册回调事件:#373
This commit is contained in:
parent
5195475116
commit
3c858a8351
@ -12,6 +12,7 @@
|
||||
#define MK_MEDIA_H_
|
||||
|
||||
#include "mk_common.h"
|
||||
#include "mk_events_objects.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -158,6 +159,22 @@ API_EXPORT void API_CALL mk_media_set_on_seek(mk_media ctx, on_mk_media_seek cb,
|
||||
*/
|
||||
API_EXPORT int API_CALL mk_media_total_reader_count(mk_media ctx);
|
||||
|
||||
/**
|
||||
* 生成的MediaSource注册或注销事件
|
||||
* @param user_data 设置回调时的用户数据指针
|
||||
* @param sender 生成的MediaSource对象
|
||||
* @param regist 1为注册事件,0为注销事件
|
||||
*/
|
||||
typedef void(API_CALL *on_mk_media_source_regist)(void *user_data, mk_media_source sender, int regist);
|
||||
|
||||
/**
|
||||
* 设置MediaSource注册或注销事件回调函数
|
||||
* @param ctx 对象指针
|
||||
* @param cb 回调指针
|
||||
* @param user_data 用户数据指针
|
||||
*/
|
||||
API_EXPORT void API_CALL mk_media_set_on_regist(mk_media ctx, on_mk_media_source_regist cb, void *user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -42,6 +42,12 @@ public:
|
||||
_on_seek = cb;
|
||||
_on_seek_data = user_data;
|
||||
}
|
||||
|
||||
void setOnRegist(on_mk_media_source_regist cb, void *user_data){
|
||||
_on_regist = cb;
|
||||
_on_regist_data = user_data;
|
||||
}
|
||||
|
||||
protected:
|
||||
// 通知其停止推流
|
||||
bool close(MediaSource &sender,bool force) override{
|
||||
@ -70,12 +76,21 @@ protected:
|
||||
int totalReaderCount(MediaSource &sender) override{
|
||||
return _channel->totalReaderCount();
|
||||
}
|
||||
|
||||
void onRegist(MediaSource &sender, bool regist) override{
|
||||
if (_on_regist) {
|
||||
_on_regist(_on_regist_data, &sender, regist);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
DevChannel::Ptr _channel;
|
||||
on_mk_media_close _on_close = nullptr;
|
||||
on_mk_media_seek _on_seek = nullptr;
|
||||
on_mk_media_source_regist _on_regist = nullptr;
|
||||
void *_on_seek_data;
|
||||
void *_on_close_data;
|
||||
void *_on_regist_data;
|
||||
};
|
||||
|
||||
API_EXPORT void API_CALL mk_media_set_on_close(mk_media ctx, on_mk_media_close cb, void *user_data){
|
||||
@ -90,6 +105,12 @@ API_EXPORT void API_CALL mk_media_set_on_seek(mk_media ctx, on_mk_media_seek cb,
|
||||
(*obj)->setOnSeek(cb, user_data);
|
||||
}
|
||||
|
||||
API_EXPORT void API_CALL mk_media_set_on_regist(mk_media ctx, on_mk_media_source_regist cb, void *user_data){
|
||||
assert(ctx);
|
||||
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
|
||||
(*obj)->setOnRegist(cb, user_data);
|
||||
}
|
||||
|
||||
API_EXPORT int API_CALL mk_media_total_reader_count(mk_media ctx){
|
||||
assert(ctx);
|
||||
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
|
||||
|
@ -249,6 +249,13 @@ void FFmpegSource::onNoneReader(MediaSource &sender){
|
||||
MediaSourceEvent::onNoneReader(sender);
|
||||
}
|
||||
|
||||
void FFmpegSource::onRegist(MediaSource &sender, bool regist){
|
||||
auto listener = _listener.lock();
|
||||
if(listener){
|
||||
listener->onRegist(sender, regist);
|
||||
}
|
||||
}
|
||||
|
||||
void FFmpegSource::onGetMediaSource(const MediaSource::Ptr &src) {
|
||||
_listener = src->getListener();
|
||||
src->setListener(shared_from_this());
|
||||
|
@ -62,6 +62,7 @@ private:
|
||||
bool close(MediaSource &sender,bool force) override;
|
||||
int totalReaderCount(MediaSource &sender) override;
|
||||
void onNoneReader(MediaSource &sender) override;
|
||||
void onRegist(MediaSource &sender, bool regist) override;
|
||||
|
||||
private:
|
||||
Process _process;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -137,6 +137,13 @@ public:
|
||||
*/
|
||||
void onNoneReader(MediaSource &sender) override;
|
||||
|
||||
/**
|
||||
* 媒体注册注销事件
|
||||
* @param sender 触发者
|
||||
* @param regist 是否为注册事件
|
||||
*/
|
||||
void onRegist(MediaSource &sender, bool regist) override;
|
||||
|
||||
/**
|
||||
* 设置录制状态
|
||||
* @param type 录制类型
|
||||
|
Loading…
Reference in New Issue
Block a user