2019-12-04 10:45:38 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
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-12-04 10:45:38 +08:00
|
|
|
|
|
|
|
|
|
#include "Recorder.h"
|
|
|
|
|
#include "Common/config.h"
|
2019-12-05 10:47:23 +08:00
|
|
|
|
#include "Common/MediaSource.h"
|
2019-12-04 10:45:38 +08:00
|
|
|
|
#include "MP4Recorder.h"
|
|
|
|
|
#include "HlsRecorder.h"
|
|
|
|
|
|
2022-02-02 20:34:50 +08:00
|
|
|
|
using namespace std;
|
2019-12-04 10:45:38 +08:00
|
|
|
|
using namespace toolkit;
|
|
|
|
|
|
|
|
|
|
namespace mediakit {
|
|
|
|
|
|
2020-02-01 22:58:58 +08:00
|
|
|
|
string Recorder::getRecordPath(Recorder::type type, const string &vhost, const string &app, const string &stream_id, const string &customized_path) {
|
2019-12-04 10:45:38 +08:00
|
|
|
|
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
|
2020-02-01 22:58:58 +08:00
|
|
|
|
switch (type) {
|
|
|
|
|
case Recorder::type_hls: {
|
2022-11-12 23:54:35 +08:00
|
|
|
|
GET_CONFIG(string, hlsPath, Protocol::kHlsSavePath);
|
2020-02-01 22:58:58 +08:00
|
|
|
|
string m3u8FilePath;
|
|
|
|
|
if (enableVhost) {
|
|
|
|
|
m3u8FilePath = vhost + "/" + app + "/" + stream_id + "/hls.m3u8";
|
|
|
|
|
} else {
|
|
|
|
|
m3u8FilePath = app + "/" + stream_id + "/hls.m3u8";
|
|
|
|
|
}
|
|
|
|
|
//Here we use the customized file path.
|
|
|
|
|
if (!customized_path.empty()) {
|
2020-10-01 14:55:34 +08:00
|
|
|
|
return File::absolutePath(m3u8FilePath, customized_path);
|
2020-02-01 22:58:58 +08:00
|
|
|
|
}
|
|
|
|
|
return File::absolutePath(m3u8FilePath, hlsPath);
|
|
|
|
|
}
|
|
|
|
|
case Recorder::type_mp4: {
|
2022-11-12 23:54:35 +08:00
|
|
|
|
GET_CONFIG(string, recordPath, Protocol::kMP4SavePath);
|
2020-02-01 22:58:58 +08:00
|
|
|
|
GET_CONFIG(string, recordAppName, Record::kAppName);
|
|
|
|
|
string mp4FilePath;
|
|
|
|
|
if (enableVhost) {
|
|
|
|
|
mp4FilePath = vhost + "/" + recordAppName + "/" + app + "/" + stream_id + "/";
|
|
|
|
|
} else {
|
|
|
|
|
mp4FilePath = recordAppName + "/" + app + "/" + stream_id + "/";
|
|
|
|
|
}
|
|
|
|
|
//Here we use the customized file path.
|
|
|
|
|
if (!customized_path.empty()) {
|
2020-10-01 14:55:34 +08:00
|
|
|
|
return File::absolutePath(mp4FilePath, customized_path);
|
2020-02-01 22:58:58 +08:00
|
|
|
|
}
|
|
|
|
|
return File::absolutePath(mp4FilePath, recordPath);
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return "";
|
2020-01-02 12:47:12 +08:00
|
|
|
|
}
|
2019-12-04 10:45:38 +08:00
|
|
|
|
}
|
2019-12-29 10:49:04 +08:00
|
|
|
|
|
2022-11-12 23:54:35 +08:00
|
|
|
|
std::shared_ptr<MediaSinkInterface> Recorder::createRecorder(type type, const string &vhost, const string &app, const string &stream_id, const ProtocolOption &option){
|
2020-02-01 22:58:58 +08:00
|
|
|
|
switch (type) {
|
|
|
|
|
case Recorder::type_hls: {
|
|
|
|
|
#if defined(ENABLE_HLS)
|
2022-11-12 23:54:35 +08:00
|
|
|
|
auto path = Recorder::getRecordPath(type, vhost, app, stream_id, option.hls_save_path);
|
2020-11-21 21:54:12 +08:00
|
|
|
|
GET_CONFIG(bool, enable_vhost, General::kEnableVhost);
|
2022-11-12 23:54:35 +08:00
|
|
|
|
auto ret = std::make_shared<HlsRecorder>(path, enable_vhost ? string(VHOST_KEY) + "=" + vhost : "", option);
|
2020-02-01 22:58:58 +08:00
|
|
|
|
ret->setMediaSource(vhost, app, stream_id);
|
|
|
|
|
return ret;
|
2021-02-03 15:32:08 +08:00
|
|
|
|
#else
|
|
|
|
|
throw std::invalid_argument("hls相关功能未打开,请开启ENABLE_HLS宏后编译再测试");
|
2020-02-01 22:58:58 +08:00
|
|
|
|
#endif
|
2021-02-03 15:32:08 +08:00
|
|
|
|
|
2020-02-01 22:58:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case Recorder::type_mp4: {
|
2020-04-03 20:45:58 +08:00
|
|
|
|
#if defined(ENABLE_MP4)
|
2022-11-12 23:54:35 +08:00
|
|
|
|
auto path = Recorder::getRecordPath(type, vhost, app, stream_id, option.mp4_save_path);
|
|
|
|
|
return std::make_shared<MP4Recorder>(path, vhost, app, stream_id, option.mp4_max_second);
|
2021-02-03 15:32:08 +08:00
|
|
|
|
#else
|
|
|
|
|
throw std::invalid_argument("mp4相关功能未打开,请开启ENABLE_MP4宏后编译再测试");
|
2020-02-01 22:58:58 +08:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-03 15:32:08 +08:00
|
|
|
|
default: throw std::invalid_argument("未知的录制类型");
|
2020-02-01 22:58:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-29 10:49:04 +08:00
|
|
|
|
|
2019-12-04 10:45:38 +08:00
|
|
|
|
} /* namespace mediakit */
|