mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
修改MediaSource相关接口
This commit is contained in:
parent
eddb5adcb2
commit
ff7914e441
@ -118,8 +118,7 @@ void FFmpegSource::findAsync(int maxWaitMS, const function<void(const MediaSourc
|
||||
auto src = MediaSource::find(_media_info._schema,
|
||||
_media_info._vhost,
|
||||
_media_info._app,
|
||||
_media_info._streamid,
|
||||
false);
|
||||
_media_info._streamid);
|
||||
if(src || !maxWaitMS){
|
||||
cb(src);
|
||||
return;
|
||||
|
@ -439,14 +439,14 @@ void installWebApi() {
|
||||
api_regist1("/index/api/isMediaOnline",[](API_ARGS1){
|
||||
CHECK_SECRET();
|
||||
CHECK_ARGS("schema","vhost","app","stream");
|
||||
val["online"] = (bool) (MediaSource::find(allArgs["schema"],allArgs["vhost"],allArgs["app"],allArgs["stream"],false));
|
||||
val["online"] = (bool) (MediaSource::find(allArgs["schema"],allArgs["vhost"],allArgs["app"],allArgs["stream"]));
|
||||
});
|
||||
|
||||
//测试url http://127.0.0.1/index/api/getMediaInfo?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs
|
||||
api_regist1("/index/api/getMediaInfo",[](API_ARGS1){
|
||||
CHECK_SECRET();
|
||||
CHECK_ARGS("schema","vhost","app","stream");
|
||||
auto src = MediaSource::find(allArgs["schema"],allArgs["vhost"],allArgs["app"],allArgs["stream"],false);
|
||||
auto src = MediaSource::find(allArgs["schema"],allArgs["vhost"],allArgs["app"],allArgs["stream"]);
|
||||
if(!src){
|
||||
val["online"] = false;
|
||||
return;
|
||||
|
@ -180,9 +180,8 @@ static void eraseIfEmpty(MAP &map, IT0 it0, IT1 it1, IT2 it2) {
|
||||
}
|
||||
};
|
||||
|
||||
void findAsync_l(const MediaInfo &info, const std::shared_ptr<TcpSession> &session, bool retry,
|
||||
const function<void(const MediaSource::Ptr &src)> &cb){
|
||||
auto src = MediaSource::find(info._schema, info._vhost, info._app, info._streamid, true);
|
||||
void MediaSource::findAsync_l(const MediaInfo &info, const std::shared_ptr<TcpSession> &session, bool retry, const function<void(const MediaSource::Ptr &src)> &cb){
|
||||
auto src = MediaSource::find_l(info._schema, info._vhost, info._app, info._streamid, true);
|
||||
if(src || !retry){
|
||||
cb(src);
|
||||
return;
|
||||
@ -248,7 +247,11 @@ void MediaSource::findAsync(const MediaInfo &info, const std::shared_ptr<TcpSess
|
||||
return findAsync_l(info, session, true, cb);
|
||||
}
|
||||
|
||||
MediaSource::Ptr MediaSource::find(const string &schema, const string &vhost_tmp, const string &app, const string &id, bool bMake) {
|
||||
MediaSource::Ptr MediaSource::find(const string &schema, const string &vhost, const string &app, const string &id) {
|
||||
return find_l(schema, vhost, app, id, false);
|
||||
}
|
||||
|
||||
MediaSource::Ptr MediaSource::find_l(const string &schema, const string &vhost_tmp, const string &app, const string &id, bool bMake) {
|
||||
string vhost = vhost_tmp;
|
||||
if(vhost.empty()){
|
||||
vhost = DEFAULT_VHOST;
|
||||
@ -419,12 +422,10 @@ void MediaSourceEvent::onNoneReader(MediaSource &sender){
|
||||
|
||||
//如果mp4点播, 无人观看时我们强制关闭点播
|
||||
bool is_mp4_vod = sender.getApp() == recordApp;
|
||||
//无人观看mp4点播时,3秒后自动关闭
|
||||
auto close_delay = is_mp4_vod ? 3.0 : stream_none_reader_delay / 1000.0;
|
||||
|
||||
//没有任何人观看该视频源,表明该源可以关闭了
|
||||
weak_ptr<MediaSource> weakSender = sender.shared_from_this();
|
||||
_async_close_timer = std::make_shared<Timer>(close_delay, [weakSender,is_mp4_vod]() {
|
||||
_async_close_timer = std::make_shared<Timer>(stream_none_reader_delay / 1000.0, [weakSender,is_mp4_vod]() {
|
||||
auto strongSender = weakSender.lock();
|
||||
if (!strongSender) {
|
||||
//对象已经销毁
|
||||
@ -467,7 +468,7 @@ MediaSource::Ptr MediaSource::createFromMP4(const string &schema, const string &
|
||||
try {
|
||||
MP4Reader::Ptr pReader(new MP4Reader(vhost, app, stream, filePath));
|
||||
pReader->startReadMP4();
|
||||
return MediaSource::find(schema, vhost, app, stream, false);
|
||||
return MediaSource::find(schema, vhost, app, stream);
|
||||
} catch (std::exception &ex) {
|
||||
WarnL << ex.what();
|
||||
return nullptr;
|
||||
|
@ -134,7 +134,7 @@ public:
|
||||
virtual bool isRecording(Recorder::type type);
|
||||
|
||||
// 同步查找流
|
||||
static Ptr find(const string &schema, const string &vhost, const string &app, const string &id, bool bMake = true) ;
|
||||
static Ptr find(const string &schema, const string &vhost, const string &app, const string &id);
|
||||
// 异步查找流
|
||||
static void findAsync(const MediaInfo &info, const std::shared_ptr<TcpSession> &session, const function<void(const Ptr &src)> &cb);
|
||||
// 遍历所有流
|
||||
@ -142,9 +142,14 @@ public:
|
||||
|
||||
// 从mp4文件生成MediaSource
|
||||
static MediaSource::Ptr createFromMP4(const string &schema, const string &vhost, const string &app, const string &stream, const string &filePath = "", bool checkApp = true);
|
||||
|
||||
protected:
|
||||
void regist() ;
|
||||
bool unregist();
|
||||
|
||||
private:
|
||||
static Ptr find_l(const string &schema, const string &vhost, const string &app, const string &id, bool bMake);
|
||||
static void findAsync_l(const MediaInfo &info, const std::shared_ptr<TcpSession> &session, bool retry, const function<void(const MediaSource::Ptr &src)> &cb);
|
||||
private:
|
||||
string _strSchema;
|
||||
string _strVhost;
|
||||
|
@ -80,11 +80,11 @@ std::shared_ptr<MediaSinkInterface> Recorder::createRecorder(type type, const st
|
||||
}
|
||||
|
||||
static MediaSource::Ptr getMediaSource(const string &vhost, const string &app, const string &stream_id){
|
||||
auto src = MediaSource::find(RTMP_SCHEMA, vhost, app, stream_id, false);
|
||||
auto src = MediaSource::find(RTMP_SCHEMA, vhost, app, stream_id);
|
||||
if(src){
|
||||
return src;
|
||||
}
|
||||
return MediaSource::find(RTSP_SCHEMA, vhost, app, stream_id, false);
|
||||
return MediaSource::find(RTSP_SCHEMA, vhost, app, stream_id);
|
||||
}
|
||||
|
||||
bool Recorder::isRecording(type type, const string &vhost, const string &app, const string &stream_id){
|
||||
|
@ -167,7 +167,7 @@ void FlvMuxer::stop() {
|
||||
|
||||
///////////////////////////////////////////////////////FlvRecorder/////////////////////////////////////////////////////
|
||||
void FlvRecorder::startRecord(const EventPoller::Ptr &poller,const string &vhost, const string &app, const string &stream,const string &file_path) {
|
||||
startRecord(poller,dynamic_pointer_cast<RtmpMediaSource>(MediaSource::find(RTMP_SCHEMA,vhost,app,stream,false)),file_path);
|
||||
startRecord(poller,dynamic_pointer_cast<RtmpMediaSource>(MediaSource::find(RTMP_SCHEMA,vhost,app,stream)),file_path);
|
||||
}
|
||||
|
||||
void FlvRecorder::startRecord(const EventPoller::Ptr &poller,const RtmpMediaSource::Ptr &media, const string &file_path) {
|
||||
|
@ -130,8 +130,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
|
||||
auto src = dynamic_pointer_cast<RtmpMediaSource>(MediaSource::find(RTMP_SCHEMA,
|
||||
_mediaInfo._vhost,
|
||||
_mediaInfo._app,
|
||||
_mediaInfo._streamid,
|
||||
false));
|
||||
_mediaInfo._streamid));
|
||||
bool authSuccess = err.empty();
|
||||
bool ok = (!src && !_pPublisherSrc && authSuccess);
|
||||
AMFValue status(AMF_OBJECT);
|
||||
|
@ -81,6 +81,7 @@ RtpMultiCaster::~RtpMultiCaster() {
|
||||
_pReader->setDetachCB(nullptr);
|
||||
DebugL;
|
||||
}
|
||||
|
||||
RtpMultiCaster::RtpMultiCaster(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream) {
|
||||
auto src = dynamic_pointer_cast<RtspMediaSource>(MediaSource::find(RTSP_SCHEMA,strVhost,strApp, strStream));
|
||||
if(!src){
|
||||
|
@ -221,8 +221,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
|
||||
auto src = dynamic_pointer_cast<RtmpMediaSource>(MediaSource::find(RTSP_SCHEMA,
|
||||
_mediaInfo._vhost,
|
||||
_mediaInfo._app,
|
||||
_mediaInfo._streamid,
|
||||
false));
|
||||
_mediaInfo._streamid));
|
||||
if(src){
|
||||
sendRtspResponse("406 Not Acceptable", {"Content-Type", "text/plain"}, "Already publishing.");
|
||||
string err = StrPrinter << "ANNOUNCE:"
|
||||
|
Loading…
Reference in New Issue
Block a user