优化录制相关代码

This commit is contained in:
xiongziliang 2022-06-11 14:18:55 +08:00
parent 09af12a183
commit f6b4eb418f
3 changed files with 31 additions and 58 deletions

View File

@ -11,6 +11,8 @@
#include "mk_recorder.h" #include "mk_recorder.h"
#include "Rtmp/FlvMuxer.h" #include "Rtmp/FlvMuxer.h"
#include "Record/Recorder.h" #include "Record/Recorder.h"
using namespace std;
using namespace toolkit; using namespace toolkit;
using namespace mediakit; using namespace mediakit;
@ -36,17 +38,43 @@ API_EXPORT int API_CALL mk_flv_recorder_start(mk_flv_recorder ctx, const char *v
} }
///////////////////////////////////////////hls/mp4录制///////////////////////////////////////////// ///////////////////////////////////////////hls/mp4录制/////////////////////////////////////////////
static inline bool isRecording(Recorder::type type, const string &vhost, const string &app, const string &stream_id){
auto src = MediaSource::find(vhost, app, stream_id);
if(!src){
return false;
}
return src->isRecording(type);
}
static inline bool startRecord(Recorder::type type, const string &vhost, const string &app, const string &stream_id,const string &customized_path, size_t max_second){
auto src = MediaSource::find(vhost, app, stream_id);
if (!src) {
WarnL << "未找到相关的MediaSource,startRecord失败:" << vhost << "/" << app << "/" << stream_id;
return false;
}
return src->setupRecord(type, true, customized_path, max_second);
}
static inline bool stopRecord(Recorder::type type, const string &vhost, const string &app, const string &stream_id){
auto src = MediaSource::find(vhost, app, stream_id);
if(!src){
return false;
}
return src->setupRecord(type, false, "", 0);
}
API_EXPORT int API_CALL mk_recorder_is_recording(int type, const char *vhost, const char *app, const char *stream){ API_EXPORT int API_CALL mk_recorder_is_recording(int type, const char *vhost, const char *app, const char *stream){
assert(vhost && app && stream); assert(vhost && app && stream);
return Recorder::isRecording((Recorder::type)type,vhost,app,stream); return isRecording((Recorder::type)type,vhost,app,stream);
} }
API_EXPORT int API_CALL mk_recorder_start(int type, const char *vhost, const char *app, const char *stream,const char *customized_path, size_t max_second){ API_EXPORT int API_CALL mk_recorder_start(int type, const char *vhost, const char *app, const char *stream,const char *customized_path, size_t max_second){
assert(vhost && app && stream); assert(vhost && app && stream);
return Recorder::startRecord((Recorder::type)type,vhost,app,stream,customized_path ? customized_path : "", max_second); return startRecord((Recorder::type)type,vhost,app,stream,customized_path ? customized_path : "", max_second);
} }
API_EXPORT int API_CALL mk_recorder_stop(int type, const char *vhost, const char *app, const char *stream){ API_EXPORT int API_CALL mk_recorder_stop(int type, const char *vhost, const char *app, const char *stream){
assert(vhost && app && stream); assert(vhost && app && stream);
return Recorder::stopRecord((Recorder::type)type,vhost,app,stream); return stopRecord((Recorder::type)type,vhost,app,stream);
} }

View File

@ -83,29 +83,4 @@ std::shared_ptr<MediaSinkInterface> Recorder::createRecorder(type type, const st
} }
} }
bool Recorder::isRecording(type type, const string &vhost, const string &app, const string &stream_id){
auto src = MediaSource::find(vhost, app, stream_id);
if(!src){
return false;
}
return src->isRecording(type);
}
bool Recorder::startRecord(type type, const string &vhost, const string &app, const string &stream_id,const string &customized_path, size_t max_second){
auto src = MediaSource::find(vhost, app, stream_id);
if (!src) {
WarnL << "未找到相关的MediaSource,startRecord失败:" << vhost << "/" << app << "/" << stream_id;
return false;
}
return src->setupRecord(type, true, customized_path, max_second);
}
bool Recorder::stopRecord(type type, const string &vhost, const string &app, const string &stream_id){
auto src = MediaSource::find(vhost, app, stream_id);
if(!src){
return false;
}
return src->setupRecord(type, false, "", 0);
}
} /* namespace mediakit */ } /* namespace mediakit */

View File

@ -62,36 +62,6 @@ public:
*/ */
static std::shared_ptr<MediaSinkInterface> createRecorder(type type, const std::string &vhost, const std::string &app, const std::string &stream_id, const std::string &customized_path = "", size_t max_second = 0); static std::shared_ptr<MediaSinkInterface> createRecorder(type type, const std::string &vhost, const std::string &app, const std::string &stream_id, const std::string &customized_path = "", size_t max_second = 0);
/**
*
* @param type hls还是MP4录制
* @param vhost
* @param app
* @param stream_id id
* @return
*/
static bool isRecording(type type, const std::string &vhost, const std::string &app, const std::string &stream_id);
/**
*
* @param type hls还是MP4录制
* @param vhost
* @param app
* @param stream_id id
* @param customized_path
* @return
*/
static bool startRecord(type type, const std::string &vhost, const std::string &app, const std::string &stream_id,const std::string &customized_path, size_t max_second);
/**
*
* @param type hls还是MP4录制
* @param vhost
* @param app
* @param stream_id id
*/
static bool stopRecord(type type, const std::string &vhost, const std::string &app, const std::string &stream_id);
private: private:
Recorder() = delete; Recorder() = delete;
~Recorder() = delete; ~Recorder() = delete;