2019-08-08 19:01:45 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
2019-04-01 12:57:33 +08:00
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2019-04-01 12:57:33 +08:00
|
|
|
|
*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Use of this source code is governed by MIT license that can be found in the
|
|
|
|
|
* LICENSE file in the root of the source tree. All contributing project authors
|
|
|
|
|
* may be found in the AUTHORS file in the root of the source tree.
|
2019-04-01 12:57:33 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2019-12-04 10:45:38 +08:00
|
|
|
|
#ifndef SRC_MEDIAFILE_RECORDER_H_
|
|
|
|
|
#define SRC_MEDIAFILE_RECORDER_H_
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
using namespace std;
|
2019-04-01 12:57:33 +08:00
|
|
|
|
namespace mediakit {
|
2019-12-04 10:45:38 +08:00
|
|
|
|
class MediaSinkInterface;
|
|
|
|
|
|
2020-09-20 11:40:42 +08:00
|
|
|
|
class RecordInfo {
|
|
|
|
|
public:
|
|
|
|
|
time_t start_time; // GMT 标准时间,单位秒
|
|
|
|
|
float time_len; // 录像长度,单位秒
|
|
|
|
|
off_t file_size; // 文件大小,单位 BYTE
|
|
|
|
|
string file_path; // 文件路径
|
|
|
|
|
string file_name; // 文件名称
|
|
|
|
|
string folder; // 文件夹路径
|
|
|
|
|
string url; // 播放路径
|
|
|
|
|
string app; // 应用名称
|
|
|
|
|
string stream; // 流 ID
|
|
|
|
|
string vhost; // 虚拟主机
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-04 10:45:38 +08:00
|
|
|
|
class Recorder{
|
2019-04-01 12:57:33 +08:00
|
|
|
|
public:
|
2020-03-20 11:51:24 +08:00
|
|
|
|
typedef enum {
|
|
|
|
|
// 录制hls
|
|
|
|
|
type_hls = 0,
|
|
|
|
|
// 录制MP4
|
|
|
|
|
type_mp4 = 1
|
|
|
|
|
} type;
|
2019-12-04 18:36:30 +08:00
|
|
|
|
|
2020-03-20 11:51:24 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取录制文件绝对路径
|
|
|
|
|
* @param type hls还是MP4录制
|
2020-02-01 22:58:58 +08:00
|
|
|
|
* @param vhost 虚拟主机
|
|
|
|
|
* @param app 应用名
|
|
|
|
|
* @param stream_id 流id
|
2020-10-01 14:55:34 +08:00
|
|
|
|
* @param customized_path 录像文件保存自定义根目录,为空则采用配置文件设置
|
2020-03-20 11:51:24 +08:00
|
|
|
|
* @return 录制文件绝对路径
|
|
|
|
|
*/
|
|
|
|
|
static string getRecordPath(type type, const string &vhost, const string &app, const string &stream_id,const string &customized_path = "");
|
2020-02-01 22:58:58 +08:00
|
|
|
|
|
2020-03-20 11:51:24 +08:00
|
|
|
|
/**
|
|
|
|
|
* 创建录制器对象
|
|
|
|
|
* @param type hls还是MP4录制
|
2020-02-01 22:58:58 +08:00
|
|
|
|
* @param vhost 虚拟主机
|
|
|
|
|
* @param app 应用名
|
|
|
|
|
* @param stream_id 流id
|
2020-10-01 14:55:34 +08:00
|
|
|
|
* @param customized_path 录像文件保存自定义根目录,为空则采用配置文件设置
|
2020-03-20 11:51:24 +08:00
|
|
|
|
* @return 对象指针,可能为nullptr
|
|
|
|
|
*/
|
2020-04-04 14:33:12 +08:00
|
|
|
|
static std::shared_ptr<MediaSinkInterface> createRecorder(type type, const string &vhost, const string &app, const string &stream_id, const string &customized_path = "");
|
2020-04-05 09:26:29 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取录制状态
|
|
|
|
|
* @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
|
2020-10-01 14:55:34 +08:00
|
|
|
|
* @param customized_path 录像文件保存自定义根目录,为空则采用配置文件设置
|
2020-04-05 09:26:29 +08:00
|
|
|
|
* @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);
|
|
|
|
|
|
2019-12-04 10:45:38 +08:00
|
|
|
|
private:
|
2020-03-20 11:51:24 +08:00
|
|
|
|
Recorder() = delete;
|
|
|
|
|
~Recorder() = delete;
|
2019-04-01 12:57:33 +08:00
|
|
|
|
};
|
|
|
|
|
|
2019-12-04 10:45:38 +08:00
|
|
|
|
} /* namespace mediakit */
|
|
|
|
|
#endif /* SRC_MEDIAFILE_RECORDER_H_ */
|