mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 03:10:04 +08:00
MultiMediaSourceMuxer默认能处理大部分事件
This commit is contained in:
parent
b3f048f194
commit
f23e117751
@ -106,6 +106,7 @@ void MediaSource::onNoneReader(){
|
||||
bool MediaSource::setupRecord(Recorder::type type, bool start, const string &custom_path){
|
||||
auto listener = _listener.lock();
|
||||
if (!listener) {
|
||||
WarnL << "未设置MediaSource的事件监听者,setupRecord失败:" << getSchema() << "/" << getVhost() << "/" << getApp() << "/" << getId();
|
||||
return false;
|
||||
}
|
||||
return listener->setupRecord(*this, type, start, custom_path);
|
||||
|
@ -231,6 +231,7 @@ MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost,
|
||||
bool enable_hls,
|
||||
bool enable_mp4) {
|
||||
_muxer.reset(new MultiMuxerPrivate(vhost, app, stream, dur_sec, enable_rtsp, enable_rtmp, enable_hls, enable_mp4));
|
||||
_muxer->setTrackListener(this);
|
||||
}
|
||||
|
||||
void MultiMediaSourceMuxer::setMediaListener(const std::weak_ptr<MediaSourceEvent> &listener) {
|
||||
@ -238,6 +239,10 @@ void MultiMediaSourceMuxer::setMediaListener(const std::weak_ptr<MediaSourceEven
|
||||
_listener = listener;
|
||||
}
|
||||
|
||||
void MultiMediaSourceMuxer::setTrackListener(const std::weak_ptr<MultiMuxerPrivate::Listener> &listener) {
|
||||
_track_listener = listener;
|
||||
}
|
||||
|
||||
int MultiMediaSourceMuxer::totalReaderCount() const {
|
||||
return _muxer->totalReaderCount();
|
||||
}
|
||||
@ -246,10 +251,6 @@ void MultiMediaSourceMuxer::setTimeStamp(uint32_t stamp) {
|
||||
_muxer->setTimeStamp(stamp);
|
||||
}
|
||||
|
||||
void MultiMediaSourceMuxer::setTrackListener(Listener *listener) {
|
||||
_muxer->setTrackListener(listener);
|
||||
}
|
||||
|
||||
vector<Track::Ptr> MultiMediaSourceMuxer::getTracks(bool trackReady) const {
|
||||
return _muxer->getTracks(trackReady);
|
||||
}
|
||||
@ -310,6 +311,14 @@ void MultiMediaSourceMuxer::addTrackCompleted() {
|
||||
_muxer->addTrackCompleted();
|
||||
}
|
||||
|
||||
void MultiMediaSourceMuxer::onAllTrackReady(){
|
||||
_muxer->setMediaListener(shared_from_this());
|
||||
auto track_listener = _track_listener.lock();
|
||||
if(track_listener){
|
||||
track_listener->onAllTrackReady();
|
||||
}
|
||||
}
|
||||
|
||||
void MultiMediaSourceMuxer::resetTracks() {
|
||||
_muxer->resetTracks();
|
||||
}
|
||||
|
@ -27,17 +27,12 @@ public:
|
||||
virtual ~Listener() = default;
|
||||
virtual void onAllTrackReady() = 0;
|
||||
};
|
||||
~MultiMuxerPrivate() override ;
|
||||
private:
|
||||
MultiMuxerPrivate(const string &vhost,
|
||||
const string &app,
|
||||
const string &stream,
|
||||
float dur_sec,
|
||||
bool enable_rtsp,
|
||||
bool enable_rtmp,
|
||||
bool enable_hls,
|
||||
bool enable_mp4);
|
||||
|
||||
~MultiMuxerPrivate() override;
|
||||
|
||||
private:
|
||||
MultiMuxerPrivate(const string &vhost,const string &app, const string &stream,float dur_sec,
|
||||
bool enable_rtsp, bool enable_rtmp, bool enable_hls, bool enable_mp4);
|
||||
void resetTracks() override;
|
||||
void setMediaListener(const std::weak_ptr<MediaSourceEvent> &listener);
|
||||
int totalReaderCount() const;
|
||||
@ -46,11 +41,11 @@ private:
|
||||
bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path);
|
||||
bool isRecording(MediaSource &sender, Recorder::type type);
|
||||
bool isEnabled();
|
||||
private:
|
||||
void onTrackReady(const Track::Ptr & track) override;
|
||||
void onTrackFrame(const Frame::Ptr &frame) override;
|
||||
void onAllTrackReady() override;
|
||||
MediaSource::Ptr getHlsMediaSource() const;
|
||||
|
||||
private:
|
||||
RtmpMediaSourceMuxer::Ptr _rtmp;
|
||||
RtspMediaSourceMuxer::Ptr _rtsp;
|
||||
@ -62,30 +57,29 @@ private:
|
||||
bool _enable_record = false;
|
||||
};
|
||||
|
||||
class MultiMediaSourceMuxer : public MediaSourceEvent, public MediaSinkInterface, public TrackSource, public std::enable_shared_from_this<MultiMediaSourceMuxer>{
|
||||
class MultiMediaSourceMuxer : public MediaSourceEvent, public MediaSinkInterface, public TrackSource, public MultiMuxerPrivate::Listener, public std::enable_shared_from_this<MultiMediaSourceMuxer>{
|
||||
public:
|
||||
typedef MultiMuxerPrivate::Listener Listener;
|
||||
typedef std::shared_ptr<MultiMediaSourceMuxer> Ptr;
|
||||
|
||||
~MultiMediaSourceMuxer() override;
|
||||
MultiMediaSourceMuxer(const string &vhost,
|
||||
const string &app,
|
||||
const string &stream,
|
||||
float dur_sec = 0.0,
|
||||
bool enable_rtsp = true,
|
||||
bool enable_rtmp = true,
|
||||
bool enable_hls = true,
|
||||
bool enable_mp4 = false);
|
||||
MultiMediaSourceMuxer(const string &vhost, const string &app, const string &stream, float dur_sec = 0.0,
|
||||
bool enable_rtsp = true, bool enable_rtmp = true, bool enable_hls = true, bool enable_mp4 = false);
|
||||
|
||||
/**
|
||||
* 设置事件监听器
|
||||
* @param listener
|
||||
* @param listener 监听器
|
||||
*/
|
||||
void setMediaListener(const std::weak_ptr<MediaSourceEvent> &listener);
|
||||
|
||||
/**
|
||||
* 随着Track就绪事件监听器
|
||||
* @param listener 事件监听器
|
||||
*/
|
||||
void setTrackListener(const std::weak_ptr<MultiMuxerPrivate::Listener> &listener);
|
||||
|
||||
/**
|
||||
* 返回总的消费者个数
|
||||
* @return
|
||||
*/
|
||||
int totalReaderCount() const;
|
||||
|
||||
@ -95,12 +89,6 @@ public:
|
||||
*/
|
||||
void setTimeStamp(uint32_t stamp);
|
||||
|
||||
/**
|
||||
* 随着Track就绪事件监听器
|
||||
* @param listener 事件监听器
|
||||
*/
|
||||
void setTrackListener(Listener *listener);
|
||||
|
||||
/**
|
||||
* 获取所有Track
|
||||
* @param trackReady 是否筛选过滤未就绪的track
|
||||
@ -163,16 +151,20 @@ public:
|
||||
/**
|
||||
* 添加track,内部会调用Track的clone方法
|
||||
* 只会克隆sps pps这些信息 ,而不会克隆Delegate相关关系
|
||||
* @param track
|
||||
* @param track 添加音频或视频轨道
|
||||
*/
|
||||
void addTrack(const Track::Ptr & track) override;
|
||||
|
||||
/**
|
||||
* 添加track完毕
|
||||
* @param track
|
||||
*/
|
||||
void addTrackCompleted();
|
||||
|
||||
/**
|
||||
* 所有track全部就绪
|
||||
*/
|
||||
void onAllTrackReady() override;
|
||||
|
||||
/**
|
||||
* 重置track
|
||||
*/
|
||||
@ -188,9 +180,11 @@ public:
|
||||
* 判断是否生效(是否正在转其他协议)
|
||||
*/
|
||||
bool isEnabled();
|
||||
|
||||
private:
|
||||
MultiMuxerPrivate::Ptr _muxer;
|
||||
std::weak_ptr<MediaSourceEvent> _listener;
|
||||
std::weak_ptr<MultiMuxerPrivate::Listener> _track_listener;
|
||||
Stamp _stamp[2];
|
||||
};
|
||||
|
||||
|
@ -97,10 +97,11 @@ bool Recorder::isRecording(type type, const string &vhost, const string &app, co
|
||||
|
||||
bool Recorder::startRecord(type type, const string &vhost, const string &app, const string &stream_id,const string &customized_path){
|
||||
auto src = getMediaSource(vhost, app, stream_id);
|
||||
if(!src){
|
||||
if (!src) {
|
||||
WarnL << "未找到相关的MediaSource,startRecord失败:" << vhost << "/" << app << "/" << stream_id;
|
||||
return false;
|
||||
}
|
||||
return src->setupRecord(type,true,customized_path);
|
||||
return src->setupRecord(type, true, customized_path);
|
||||
}
|
||||
|
||||
bool Recorder::stopRecord(type type, const string &vhost, const string &app, const string &stream_id){
|
||||
|
@ -127,7 +127,7 @@ public:
|
||||
//不重复生成rtmp
|
||||
_muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(), getApp(), getId(), _demuxer->getDuration(), enableRtsp, false, enableHls, enableMP4);
|
||||
_muxer->setMediaListener(getListener());
|
||||
_muxer->setTrackListener(this);
|
||||
_muxer->setTrackListener(static_pointer_cast<RtmpMediaSourceImp>(shared_from_this()));
|
||||
for(auto &track : _demuxer->getTracks(false)){
|
||||
_muxer->addTrack(track);
|
||||
track->addDelegate(_muxer);
|
||||
|
@ -114,7 +114,7 @@ public:
|
||||
//不重复生成rtsp
|
||||
_muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(), getApp(), getId(), _demuxer->getDuration(), false, enableRtmp, enableHls, enableMP4);
|
||||
_muxer->setMediaListener(getListener());
|
||||
_muxer->setTrackListener(this);
|
||||
_muxer->setTrackListener(static_pointer_cast<RtspMediaSourceImp>(shared_from_this()));
|
||||
for(auto &track : _demuxer->getTracks(false)){
|
||||
_muxer->addTrack(track);
|
||||
track->addDelegate(_muxer);
|
||||
|
Loading…
Reference in New Issue
Block a user