Merge remote-tracking branch 'origin/master'

This commit is contained in:
ziyue 2020-12-07 10:24:28 +08:00
commit 43164d3670
3 changed files with 18 additions and 5 deletions

View File

@ -20,6 +20,7 @@ HttpTSPlayer::HttpTSPlayer(const EventPoller::Ptr &poller, bool split_ts){
HttpTSPlayer::~HttpTSPlayer() {} HttpTSPlayer::~HttpTSPlayer() {}
int64_t HttpTSPlayer::onResponseHeader(const string &status, const HttpClient::HttpHeader &headers) { int64_t HttpTSPlayer::onResponseHeader(const string &status, const HttpClient::HttpHeader &headers) {
_status = status;
if (status != "200" && status != "206") { if (status != "200" && status != "206") {
//http状态码不符合预期 //http状态码不符合预期
shutdown(SockException(Err_other, StrPrinter << "bad http status code:" + status)); shutdown(SockException(Err_other, StrPrinter << "bad http status code:" + status));
@ -35,6 +36,9 @@ int64_t HttpTSPlayer::onResponseHeader(const string &status, const HttpClient::H
} }
void HttpTSPlayer::onResponseBody(const char *buf, int64_t size, int64_t recvedSize, int64_t totalSize) { void HttpTSPlayer::onResponseBody(const char *buf, int64_t size, int64_t recvedSize, int64_t totalSize) {
if (_status != "200" && _status != "206") {
return;
}
if (recvedSize == size) { if (recvedSize == size) {
//开始接收数据 //开始接收数据
if (buf[0] == TS_SYNC_BYTE) { if (buf[0] == TS_SYNC_BYTE) {

View File

@ -48,6 +48,7 @@ private:
bool _is_first_packet_ts = false; bool _is_first_packet_ts = false;
//是否判断是否是ts并split //是否判断是否是ts并split
bool _split_ts; bool _split_ts;
string _status;
TSSegment _segment; TSSegment _segment;
onShutdown _on_disconnect; onShutdown _on_disconnect;
TSSegment::onSegment _on_segment; TSSegment::onSegment _on_segment;

View File

@ -11,6 +11,7 @@
#ifdef ENABLE_MP4 #ifdef ENABLE_MP4
#include <ctime> #include <ctime>
#include <sys/stat.h> #include <sys/stat.h>
#include "Util/File.h"
#include "Common/config.h" #include "Common/config.h"
#include "MP4Recorder.h" #include "MP4Recorder.h"
#include "Thread/WorkThreadPool.h" #include "Thread/WorkThreadPool.h"
@ -77,12 +78,19 @@ void MP4Recorder::asyncClose() {
const_cast<RecordInfo&>(info).time_len = ::time(NULL) - info.start_time; const_cast<RecordInfo&>(info).time_len = ::time(NULL) - info.start_time;
//关闭mp4非常耗时所以要放在后台线程执行 //关闭mp4非常耗时所以要放在后台线程执行
muxer->closeMP4(); muxer->closeMP4();
//临时文件名改成正式文件名防止mp4未完成时被访问
rename(strFileTmp.data(),strFile.data());
//获取文件大小 //获取文件大小
struct stat fileData; struct stat fileData;
stat(strFile.data(), &fileData); stat(strFileTmp.data(), &fileData);
const_cast<RecordInfo&>(info).file_size = fileData.st_size; const_cast<RecordInfo &>(info).file_size = fileData.st_size;
if (fileData.st_size < 1024) {
//录像文件太小,删除之
File::delete_file(strFileTmp.data());
return;
}
//临时文件名改成正式文件名防止mp4未完成时被访问
rename(strFileTmp.data(),strFile.data());
/////record 业务逻辑////// /////record 业务逻辑//////
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordMP4,info); NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordMP4,info);
}); });