mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-04 09:47:33 +08:00
基本完成hls相关的主要事件
This commit is contained in:
@@ -362,9 +362,9 @@ void MediaInfo::parse(const string &url){
|
||||
if(pos != string::npos){
|
||||
_streamid = steamid.substr(0,pos);
|
||||
_param_strs = steamid.substr(pos + 1);
|
||||
_params = Parser::parseArgs(_param_strs);
|
||||
if(_params.find(VHOST_KEY) != _params.end()){
|
||||
_vhost = _params[VHOST_KEY];
|
||||
auto params = Parser::parseArgs(_param_strs);
|
||||
if(params.find(VHOST_KEY) != params.end()){
|
||||
_vhost = params[VHOST_KEY];
|
||||
}
|
||||
} else{
|
||||
_streamid = steamid;
|
||||
|
||||
@@ -72,19 +72,15 @@ public:
|
||||
virtual int totalReaderCount(MediaSource &sender) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* 解析url获取媒体相关信息
|
||||
*/
|
||||
class MediaInfo{
|
||||
public:
|
||||
MediaInfo(){}
|
||||
MediaInfo(const string &url){
|
||||
parse(url);
|
||||
}
|
||||
~MediaInfo(){}
|
||||
|
||||
MediaInfo(const string &url){ parse(url); }
|
||||
void parse(const string &url);
|
||||
|
||||
string &operator[](const string &key){
|
||||
return _params[key];
|
||||
}
|
||||
public:
|
||||
string _schema;
|
||||
string _host;
|
||||
@@ -92,7 +88,6 @@ public:
|
||||
string _vhost;
|
||||
string _app;
|
||||
string _streamid;
|
||||
StrCaseMap _params;
|
||||
string _param_strs;
|
||||
};
|
||||
|
||||
@@ -118,21 +113,27 @@ public:
|
||||
const string& getApp() const;
|
||||
// 流id
|
||||
const string& getId() const;
|
||||
// 获取所有Track
|
||||
vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
||||
// 获取监听者
|
||||
const std::weak_ptr<MediaSourceEvent>& getListener() const;
|
||||
|
||||
// 设置TrackSource
|
||||
void setTrackSource(const std::weak_ptr<TrackSource> &track_src);
|
||||
// 获取所有Track
|
||||
vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
||||
|
||||
// 设置监听者
|
||||
virtual void setListener(const std::weak_ptr<MediaSourceEvent> &listener);
|
||||
// 获取监听者
|
||||
const std::weak_ptr<MediaSourceEvent>& getListener() const;
|
||||
|
||||
|
||||
// 本协议获取观看者个数,可能返回本协议的观看人数,也可能返回总人数
|
||||
virtual int readerCount() = 0;
|
||||
// 观看者个数,包括(hls/rtsp/rtmp)
|
||||
virtual int totalReaderCount();
|
||||
|
||||
// 获取流当前时间戳
|
||||
virtual uint32_t getTimeStamp(TrackType trackType) { return 0; };
|
||||
// 设置时间戳
|
||||
virtual void setTimeStamp(uint32_t uiStamp) {};
|
||||
|
||||
// 拖动进度条
|
||||
bool seekTo(uint32_t ui32Stamp);
|
||||
@@ -147,12 +148,10 @@ public:
|
||||
static void findAsync(const MediaInfo &info, const std::shared_ptr<TcpSession> &session, const function<void(const Ptr &src)> &cb);
|
||||
// 遍历所有流
|
||||
static void for_each_media(const function<void(const Ptr &src)> &cb);
|
||||
|
||||
protected:
|
||||
void regist() ;
|
||||
bool unregist() ;
|
||||
void unregisted();
|
||||
|
||||
private:
|
||||
string _strSchema;
|
||||
string _strVhost;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "Rtmp/RtmpMediaSourceMuxer.h"
|
||||
#include "Record/Recorder.h"
|
||||
#include "Record/HlsMediaSource.h"
|
||||
#include "Record/HlsRecorder.h"
|
||||
|
||||
class MultiMediaSourceMuxer : public MediaSink , public std::enable_shared_from_this<MultiMediaSourceMuxer>{
|
||||
public:
|
||||
@@ -42,32 +43,29 @@ public:
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<MultiMediaSourceMuxer> Ptr;
|
||||
MultiMediaSourceMuxer(const string &vhost,
|
||||
const string &strApp,
|
||||
const string &strId,
|
||||
float dur_sec = 0.0,
|
||||
bool bEanbleRtsp = true,
|
||||
bool bEanbleRtmp = true,
|
||||
bool bEanbleHls = true,
|
||||
bool bEnableMp4 = false){
|
||||
if (bEanbleRtmp) {
|
||||
_rtmp = std::make_shared<RtmpMediaSourceMuxer>(vhost, strApp, strId, std::make_shared<TitleMeta>(dur_sec));
|
||||
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){
|
||||
if (enable_rtmp) {
|
||||
_rtmp = std::make_shared<RtmpMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleMeta>(dur_sec));
|
||||
}
|
||||
if (bEanbleRtsp) {
|
||||
_rtsp = std::make_shared<RtspMediaSourceMuxer>(vhost, strApp, strId, std::make_shared<TitleSdp>(dur_sec));
|
||||
if (enable_rtsp) {
|
||||
_rtsp = std::make_shared<RtspMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleSdp>(dur_sec));
|
||||
}
|
||||
|
||||
if(bEanbleHls){
|
||||
Recorder::startRecord(Recorder::type_hls,vhost, strApp, strId, true, false);
|
||||
if(enable_hls){
|
||||
Recorder::startRecord(Recorder::type_hls,vhost, app, stream, true, false);
|
||||
}
|
||||
|
||||
if(bEnableMp4){
|
||||
Recorder::startRecord(Recorder::type_mp4,vhost, strApp, strId, true, false);
|
||||
if(enable_mp4){
|
||||
Recorder::startRecord(Recorder::type_mp4,vhost, app, stream, true, false);
|
||||
}
|
||||
|
||||
_get_hls_player = [vhost,strApp,strId](){
|
||||
auto src = MediaSource::find(HLS_SCHEMA,vhost,strApp,strId);
|
||||
return src ? src->readerCount() : 0;
|
||||
_get_hls_media_source = [vhost,app,stream](){
|
||||
auto recorder = dynamic_pointer_cast<HlsRecorder>(Recorder::getRecorder(Recorder::type_hls,vhost,app,stream));
|
||||
if(recorder){
|
||||
return recorder->getMediaSource();
|
||||
}
|
||||
return MediaSource::Ptr();
|
||||
};
|
||||
}
|
||||
virtual ~MultiMediaSourceMuxer(){}
|
||||
@@ -92,9 +90,15 @@ public:
|
||||
if(_rtmp) {
|
||||
_rtmp->setListener(listener);
|
||||
}
|
||||
|
||||
if(_rtsp) {
|
||||
_rtsp->setListener(listener);
|
||||
}
|
||||
|
||||
auto hls_src = _get_hls_media_source();
|
||||
if(hls_src){
|
||||
hls_src->setListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,10 +106,15 @@ public:
|
||||
* @return
|
||||
*/
|
||||
int totalReaderCount() const{
|
||||
return (_rtsp ? _rtsp->readerCount() : 0) + (_rtmp ? _rtmp->readerCount() : 0) + _get_hls_player();
|
||||
auto hls_src = _get_hls_media_source();
|
||||
return (_rtsp ? _rtsp->readerCount() : 0) + (_rtmp ? _rtmp->readerCount() : 0) + (hls_src ? hls_src->readerCount() : 0);
|
||||
}
|
||||
|
||||
void setTimeStamp(uint32_t stamp){
|
||||
if(_rtmp){
|
||||
_rtmp->setTimeStamp(stamp);
|
||||
}
|
||||
|
||||
if(_rtsp){
|
||||
_rtsp->setTimeStamp(stamp);
|
||||
}
|
||||
@@ -154,6 +163,11 @@ protected:
|
||||
_rtsp->onAllTrackReady();
|
||||
}
|
||||
|
||||
auto hls_src = _get_hls_media_source();
|
||||
if(hls_src){
|
||||
hls_src->setTrackSource(shared_from_this());
|
||||
}
|
||||
|
||||
if(_listener){
|
||||
_listener->onAllTrackReady();
|
||||
}
|
||||
@@ -162,7 +176,7 @@ private:
|
||||
RtmpMediaSourceMuxer::Ptr _rtmp;
|
||||
RtspMediaSourceMuxer::Ptr _rtsp;
|
||||
Listener *_listener = nullptr;
|
||||
function<int()> _get_hls_player;
|
||||
function<MediaSource::Ptr ()> _get_hls_media_source;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user