部分恢复录制相关接口

This commit is contained in:
xiongziliang
2020-04-05 09:26:29 +08:00
parent c040f472fa
commit e5d5cabf89
15 changed files with 612 additions and 165 deletions

View File

@@ -73,7 +73,7 @@ bool MP4Reader::readSample() {
void MP4Reader::startReadMP4() {
GET_CONFIG(uint32_t, sampleMS, Record::kSampleMS);
auto strongSelf = shared_from_this();
_mediaMuxer->setListener(strongSelf);
_mediaMuxer->setMediaListener(strongSelf);
//先获取关键帧
seekTo(0);

View File

@@ -79,4 +79,36 @@ 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);
if(src){
return src;
}
return MediaSource::find(RTSP_SCHEMA, vhost, app, stream_id, false);
}
bool Recorder::isRecording(type type, const string &vhost, const string &app, const string &stream_id){
auto src = getMediaSource(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){
auto src = getMediaSource(vhost, app, stream_id);
if(!src){
return false;
}
return src->setupRecord(type,true,customized_path);
}
bool Recorder::stopRecord(type type, const string &vhost, const string &app, const string &stream_id){
auto src = getMediaSource(vhost, app, stream_id);
if(!src){
return false;
}
return src->setupRecord(type, false, "");
}
} /* namespace mediakit */

View File

@@ -46,6 +46,37 @@ public:
* @return 对象指针可能为nullptr
*/
static std::shared_ptr<MediaSinkInterface> createRecorder(type type, const string &vhost, const string &app, const string &stream_id, const string &customized_path = "");
/**
* 获取录制状态
* @param type hls还是MP4录制
* @param vhost 虚拟主机
* @param app 应用名
* @param stream_id 流id
* @return 是否真正录制
*/
static bool isRecording(type type, const string &vhost, const string &app, const 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 string &vhost, const string &app, const string &stream_id,const string &customized_path);
/**
* 停止录制
* @param type hls还是MP4录制
* @param vhost 虚拟主机
* @param app 应用名
* @param stream_id 流id
*/
static bool stopRecord(type type, const string &vhost, const string &app, const string &stream_id);
private:
Recorder() = delete;
~Recorder() = delete;