diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index c0154d31..17701f44 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -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 */ \ No newline at end of file diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index b431d314..3dd1fa87 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -145,6 +145,9 @@ public: static void findAsync(const MediaInfo &info, const std::shared_ptr &session, const function &cb); // 遍历所有流 static void for_each_media(const function &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() ; diff --git a/src/Record/MP4Reader.cpp b/src/Record/MP4Reader.cpp index c1b4acb0..25c46dbd 100644 --- a/src/Record/MP4Reader.cpp +++ b/src/Record/MP4Reader.cpp @@ -167,31 +167,4 @@ 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 +#endif //ENABLE_MP4 \ No newline at end of file diff --git a/src/Record/MP4Reader.h b/src/Record/MP4Reader.h index 3473a984..faf6e850 100644 --- a/src/Record/MP4Reader.h +++ b/src/Record/MP4Reader.h @@ -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_ */ diff --git a/tests/test_pusherMp4.cpp b/tests/test_pusherMp4.cpp index aad80493..cef7ab49 100644 --- a/tests/test_pusherMp4.cpp +++ b/tests/test_pusherMp4.cpp @@ -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;