合并主分支

This commit is contained in:
monktan
2020-09-21 11:01:02 +08:00
48 changed files with 1679 additions and 463 deletions

View File

@@ -8,6 +8,8 @@
* may be found in the AUTHORS file in the root of the source tree.
*/
#include <ctime>
#include <sys/stat.h>
#include "HlsMakerImp.h"
#include "Util/util.h"
#include "Util/uv_errno.h"
@@ -27,7 +29,9 @@ HlsMakerImp::HlsMakerImp(const string &m3u8_file,
_file_buf.reset(new char[bufSize],[](char *ptr){
delete[] ptr;
});
_ui64StartedTime = ::time(nullptr);
_info.folder = _path_prefix;
}
HlsMakerImp::~HlsMakerImp() {
@@ -70,14 +74,22 @@ string HlsMakerImp::onOpenSegment(int index) {
_segment_file_paths.emplace(index,segment_path);
}
}
_file = makeFile(segment_path, true);
if(!_file){
//保存本切片的元数据
_info.start_time = ::time(NULL);
_info.file_name = segment_name;
_info.file_path = segment_path;
_info.url = _info.app + "/" + _info.stream + "/" + segment_name;
if (!_file) {
WarnL << "create file failed," << segment_path << " " << get_uv_errmsg();
}
if(_params.empty()){
return std::move(segment_name);
if (_params.empty()) {
return segment_name;
}
return std::move(segment_name + "?" + _params);
return segment_name + "?" + _params;
}
void HlsMakerImp::onDelSegment(int index) {
@@ -122,7 +134,6 @@ std::shared_ptr<FILE> HlsMakerImp::makeFile(const string &file,bool setbuf) {
return ret;
}
void HlsMakerImp::onWriteRecordM3u8(const char *header, int hlen,const char *body,int blen){
bool exist = true;
string mode = "r+";
@@ -154,6 +165,18 @@ void HlsMakerImp::onWriteRecordM3u8(const char *header, int hlen,const char *bod
DebugL << "_path_hls " << _path_hls;
}
void HlsMakerImp::onFlushLastSegment(uint32_t duration_ms) {
GET_CONFIG(bool, broadcastRecordTs, Hls::kBroadcastRecordTs);
if (broadcastRecordTs) {
//关闭ts文件以便获取正确的文件大小
_file = nullptr;
_info.time_len = duration_ms / 1000.0;
struct stat fileData;
stat(_info.file_path.data(), &fileData);
_info.file_size = fileData.st_size;
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordTs, _info);
}
}
std::shared_ptr<FILE> HlsMakerImp::makeRecordM3u8(const string &file,const string &mode,bool setbuf) {
auto file_buf = _file_buf;
@@ -169,10 +192,11 @@ std::shared_ptr<FILE> HlsMakerImp::makeRecordM3u8(const string &file,const strin
return ret;
}
void HlsMakerImp::setMediaSource(const string &vhost, const string &app, const string &stream_id) {
_media_src = std::make_shared<HlsMediaSource>(vhost, app, stream_id);
_info.app = app;
_info.stream = stream_id;
_info.vhost = vhost;
}
HlsMediaSource::Ptr HlsMakerImp::getMediaSource() const {