diff --git a/src/Http/HttpTSPlayer.cpp b/src/Http/HttpTSPlayer.cpp index 706e1df3..cd6d6fb0 100644 --- a/src/Http/HttpTSPlayer.cpp +++ b/src/Http/HttpTSPlayer.cpp @@ -20,6 +20,7 @@ HttpTSPlayer::HttpTSPlayer(const EventPoller::Ptr &poller, bool split_ts){ HttpTSPlayer::~HttpTSPlayer() {} int64_t HttpTSPlayer::onResponseHeader(const string &status, const HttpClient::HttpHeader &headers) { + _status = status; if (status != "200" && status != "206") { //http状态码不符合预期 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) { + if (_status != "200" && _status != "206") { + return; + } if (recvedSize == size) { //开始接收数据 if (buf[0] == TS_SYNC_BYTE) { @@ -78,4 +82,4 @@ void HttpTSPlayer::setOnPacket(const TSSegment::onSegment &cb) { _on_segment = cb; } -}//namespace mediakit \ No newline at end of file +}//namespace mediakit diff --git a/src/Http/HttpTSPlayer.h b/src/Http/HttpTSPlayer.h index 6b12a453..7dc985f0 100644 --- a/src/Http/HttpTSPlayer.h +++ b/src/Http/HttpTSPlayer.h @@ -48,6 +48,7 @@ private: bool _is_first_packet_ts = false; //是否判断是否是ts并split bool _split_ts; + string _status; TSSegment _segment; onShutdown _on_disconnect; TSSegment::onSegment _on_segment; diff --git a/src/Record/MP4Recorder.cpp b/src/Record/MP4Recorder.cpp index b9922b17..431ed8ca 100644 --- a/src/Record/MP4Recorder.cpp +++ b/src/Record/MP4Recorder.cpp @@ -11,6 +11,7 @@ #ifdef ENABLE_MP4 #include #include +#include "Util/File.h" #include "Common/config.h" #include "MP4Recorder.h" #include "Thread/WorkThreadPool.h" @@ -77,12 +78,19 @@ void MP4Recorder::asyncClose() { const_cast(info).time_len = ::time(NULL) - info.start_time; //关闭mp4非常耗时,所以要放在后台线程执行 muxer->closeMP4(); - //临时文件名改成正式文件名,防止mp4未完成时被访问 - rename(strFileTmp.data(),strFile.data()); + //获取文件大小 struct stat fileData; - stat(strFile.data(), &fileData); - const_cast(info).file_size = fileData.st_size; + stat(strFileTmp.data(), &fileData); + const_cast(info).file_size = fileData.st_size; + if (fileData.st_size < 1024) { + //录像文件太小,删除之 + File::delete_file(strFileTmp.data()); + return; + } + //临时文件名改成正式文件名,防止mp4未完成时被访问 + rename(strFileTmp.data(),strFile.data()); + /////record 业务逻辑////// NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordMP4,info); });