优化点播相关代码

This commit is contained in:
xiongziliang 2020-04-03 23:27:16 +08:00
parent ecf3847482
commit 6e5cd0345d
5 changed files with 25 additions and 50 deletions

View File

@ -276,7 +276,7 @@ MediaSource::Ptr MediaSource::find(const string &schema, const string &vhost_tmp
if(!ret && bMake){ if(!ret && bMake){
//未查找媒体源,则创建一个 //未查找媒体源,则创建一个
ret = onMakeMediaSource(schema, vhost,app,id); ret = createFromMP4(schema, vhost, app, id);
} }
return ret; return ret;
} }
@ -427,5 +427,24 @@ void MediaSourceEvent::onNoneReader(MediaSource &sender){
}, nullptr); }, 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 */ } /* namespace mediakit */

View File

@ -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 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); 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: protected:
void regist() ; void regist() ;
bool unregist() ; bool unregist() ;

View File

@ -168,30 +168,3 @@ int MP4Reader::totalReaderCount(MediaSource &sender) {
} /* namespace mediakit */ } /* namespace mediakit */
#endif //ENABLE_MP4 #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

View File

@ -73,25 +73,5 @@ private:
}; };
} /* namespace mediakit */ } /* namespace mediakit */
#endif //ENABLE_MP4 #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_ */ #endif /* SRC_MEDIAFILE_MEDIAREADER_H_ */

View File

@ -63,7 +63,7 @@ void createPusher(const EventPoller::Ptr &poller,
const string &filePath, const string &filePath,
const string &url) { const string &url) {
//不限制APP名并且指定文件绝对路径 //不限制APP名并且指定文件绝对路径
auto src = onMakeMediaSource(schema,vhost,app,stream,filePath, false); auto src = MediaSource::createFromMP4(schema,vhost,app,stream,filePath, false);
if(!src){ if(!src){
//文件不存在 //文件不存在
WarnL << "MP4文件不存在:" << filePath; WarnL << "MP4文件不存在:" << filePath;