mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
优化点播相关代码
This commit is contained in:
parent
ecf3847482
commit
6e5cd0345d
@ -276,7 +276,7 @@ MediaSource::Ptr MediaSource::find(const string &schema, const string &vhost_tmp
|
||||
|
||||
if(!ret && bMake){
|
||||
//未查找媒体源,则创建一个
|
||||
ret = onMakeMediaSource(schema, vhost,app,id);
|
||||
ret = createFromMP4(schema, vhost, app, id);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -427,5 +427,24 @@ void MediaSourceEvent::onNoneReader(MediaSource &sender){
|
||||
}, nullptr);
|
||||
}
|
||||
|
||||
MediaSource::Ptr MediaSource::createFromMP4(const string &schema, const string &vhost, const string &app, const string &stream, const string &filePath , bool checkApp){
|
||||
#ifdef ENABLE_MP4
|
||||
GET_CONFIG(string, appName, Record::kAppName);
|
||||
if (checkApp && app != appName) {
|
||||
return nullptr;
|
||||
}
|
||||
try {
|
||||
MP4Reader::Ptr pReader(new MP4Reader(vhost, app, stream, filePath));
|
||||
pReader->startReadMP4();
|
||||
return MediaSource::find(schema, vhost, app, stream, false);
|
||||
} catch (std::exception &ex) {
|
||||
WarnL << ex.what();
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
WarnL << "创建MP4点播失败,请编译时打开\"ENABLE_MP4\"选项";
|
||||
return nullptr;
|
||||
#endif //ENABLE_MP4
|
||||
}
|
||||
|
||||
} /* namespace mediakit */
|
@ -145,6 +145,9 @@ 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);
|
||||
|
||||
// 从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() ;
|
||||
|
@ -168,30 +168,3 @@ int MP4Reader::totalReaderCount(MediaSource &sender) {
|
||||
|
||||
} /* namespace mediakit */
|
||||
#endif //ENABLE_MP4
|
||||
|
||||
|
||||
namespace mediakit {
|
||||
MediaSource::Ptr onMakeMediaSource(const string &strSchema,
|
||||
const string &strVhost,
|
||||
const string &strApp,
|
||||
const string &strId,
|
||||
const string &filePath,
|
||||
bool checkApp) {
|
||||
#ifdef ENABLE_MP4
|
||||
GET_CONFIG(string, appName, Record::kAppName);
|
||||
if (checkApp && strApp != appName) {
|
||||
return nullptr;
|
||||
}
|
||||
try {
|
||||
MP4Reader::Ptr pReader(new MP4Reader(strVhost, strApp, strId, filePath));
|
||||
pReader->startReadMP4();
|
||||
return MediaSource::find(strSchema, strVhost, strApp, strId, false);
|
||||
} catch (std::exception &ex) {
|
||||
WarnL << ex.what();
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
return nullptr;
|
||||
#endif //ENABLE_MP4
|
||||
}
|
||||
}//namespace mediakit
|
||||
|
@ -73,25 +73,5 @@ private:
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
#endif //ENABLE_MP4
|
||||
|
||||
namespace mediakit {
|
||||
/**
|
||||
* 自动生成MP4Reader对象然后查找相关的MediaSource对象
|
||||
* @param strSchema 协议名
|
||||
* @param strVhost 虚拟主机
|
||||
* @param strApp 应用名
|
||||
* @param strId 流id
|
||||
* @param filePath 文件路径,如果为空则根据配置文件和上面参数自动生成,否则使用指定的文件
|
||||
* @param checkApp 是否检查app,防止服务器上文件被乱访问
|
||||
* @return MediaSource
|
||||
*/
|
||||
MediaSource::Ptr onMakeMediaSource(const string &strSchema,
|
||||
const string &strVhost,
|
||||
const string &strApp,
|
||||
const string &strId,
|
||||
const string &filePath = "",
|
||||
bool checkApp = true);
|
||||
} /* namespace mediakit */
|
||||
#endif /* SRC_MEDIAFILE_MEDIAREADER_H_ */
|
||||
|
@ -63,7 +63,7 @@ void createPusher(const EventPoller::Ptr &poller,
|
||||
const string &filePath,
|
||||
const string &url) {
|
||||
//不限制APP名,并且指定文件绝对路径
|
||||
auto src = onMakeMediaSource(schema,vhost,app,stream,filePath, false);
|
||||
auto src = MediaSource::createFromMP4(schema,vhost,app,stream,filePath, false);
|
||||
if(!src){
|
||||
//文件不存在
|
||||
WarnL << "MP4文件不存在:" << filePath;
|
||||
|
Loading…
Reference in New Issue
Block a user