From 748bb8e488f4a1032538676ce96611f5dcd62490 Mon Sep 17 00:00:00 2001 From: wxf Date: Tue, 15 Sep 2020 19:09:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=20mp4=20=E5=8F=8A=20ts=20?= =?UTF-8?q?=E5=BD=95=E5=83=8F=E4=BF=A1=E6=81=AF=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/source/mk_events_objects.cpp | 22 ++++++++++----------- src/Common/config.h | 4 ++-- src/Record/HlsMakerImp.cpp | 2 +- src/Record/HlsMakerImp.h | 4 +++- src/Record/MP4Recorder.cpp | 4 ++-- src/Record/MP4Recorder.h | 18 +++-------------- src/Record/RecordInfo.h | 34 ++++++++++++++++++++++++++++++++ 7 files changed, 56 insertions(+), 32 deletions(-) create mode 100644 src/Record/RecordInfo.h diff --git a/api/source/mk_events_objects.cpp b/api/source/mk_events_objects.cpp index 72c30ed2..85f0c9df 100644 --- a/api/source/mk_events_objects.cpp +++ b/api/source/mk_events_objects.cpp @@ -18,64 +18,64 @@ #include "Rtsp/RtspSession.h" using namespace mediakit; -///////////////////////////////////////////MP4Info///////////////////////////////////////////// +///////////////////////////////////////////RecordInfo///////////////////////////////////////////// API_EXPORT uint64_t API_CALL mk_mp4_info_get_start_time(const mk_mp4_info ctx){ assert(ctx); - MP4Info *info = (MP4Info *)ctx; + RecordInfo *info = (RecordInfo *)ctx; return info->ui64StartedTime; } API_EXPORT uint64_t API_CALL mk_mp4_info_get_time_len(const mk_mp4_info ctx){ assert(ctx); - MP4Info *info = (MP4Info *)ctx; + RecordInfo *info = (RecordInfo *)ctx; return info->ui64TimeLen; } API_EXPORT uint64_t API_CALL mk_mp4_info_get_file_size(const mk_mp4_info ctx){ assert(ctx); - MP4Info *info = (MP4Info *)ctx; + RecordInfo *info = (RecordInfo *)ctx; return info->ui64FileSize; } API_EXPORT const char* API_CALL mk_mp4_info_get_file_path(const mk_mp4_info ctx){ assert(ctx); - MP4Info *info = (MP4Info *)ctx; + RecordInfo *info = (RecordInfo *)ctx; return info->strFilePath.c_str(); } API_EXPORT const char* API_CALL mk_mp4_info_get_file_name(const mk_mp4_info ctx){ assert(ctx); - MP4Info *info = (MP4Info *)ctx; + RecordInfo *info = (RecordInfo *)ctx; return info->strFileName.c_str(); } API_EXPORT const char* API_CALL mk_mp4_info_get_folder(const mk_mp4_info ctx){ assert(ctx); - MP4Info *info = (MP4Info *)ctx; + RecordInfo *info = (RecordInfo *)ctx; return info->strFolder.c_str(); } API_EXPORT const char* API_CALL mk_mp4_info_get_url(const mk_mp4_info ctx){ assert(ctx); - MP4Info *info = (MP4Info *)ctx; + RecordInfo *info = (RecordInfo *)ctx; return info->strUrl.c_str(); } API_EXPORT const char* API_CALL mk_mp4_info_get_vhost(const mk_mp4_info ctx){ assert(ctx); - MP4Info *info = (MP4Info *)ctx; + RecordInfo *info = (RecordInfo *)ctx; return info->strVhost.c_str(); } API_EXPORT const char* API_CALL mk_mp4_info_get_app(const mk_mp4_info ctx){ assert(ctx); - MP4Info *info = (MP4Info *)ctx; + RecordInfo *info = (RecordInfo *)ctx; return info->strAppName.c_str(); } API_EXPORT const char* API_CALL mk_mp4_info_get_stream(const mk_mp4_info ctx){ assert(ctx); - MP4Info *info = (MP4Info *)ctx; + RecordInfo *info = (RecordInfo *)ctx; return info->strStreamId.c_str(); } diff --git a/src/Common/config.h b/src/Common/config.h index 3f9869a8..7038ad40 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -58,11 +58,11 @@ extern const string kBroadcastMediaChanged; //录制mp4文件成功后广播 extern const string kBroadcastRecordMP4; -#define BroadcastRecordMP4Args const MP4Info &info +#define BroadcastRecordMP4Args const RecordInfo &info // 录制 ts 文件后广播 extern const string kBroadcastRecordTs; -#define BroadcastRecordTsArgs const TsInfo &info +#define BroadcastRecordTsArgs const RecordInfo &info //收到http api请求广播 extern const string kBroadcastHttpRequest; diff --git a/src/Record/HlsMakerImp.cpp b/src/Record/HlsMakerImp.cpp index 0ea5048a..e20658d5 100644 --- a/src/Record/HlsMakerImp.cpp +++ b/src/Record/HlsMakerImp.cpp @@ -117,7 +117,7 @@ void HlsMakerImp::onFlushLastSegment(uint32_t duration) { WorkThreadPool::Instance().getExecutor()->async([info]() { struct stat fileData; stat(info.strFilePath.data(), &fileData); - const_cast(info).ui64FileSize = fileData.st_size; + const_cast(info).ui64FileSize = fileData.st_size; NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordTs, info); }); } diff --git a/src/Record/HlsMakerImp.h b/src/Record/HlsMakerImp.h index c914b89f..cc0b3d31 100644 --- a/src/Record/HlsMakerImp.h +++ b/src/Record/HlsMakerImp.h @@ -16,6 +16,8 @@ #include #include "HlsMaker.h" #include "HlsMediaSource.h" +#include "RecordInfo.h" + using namespace std; namespace mediakit { @@ -67,7 +69,7 @@ private: std::shared_ptr _file; std::shared_ptr _file_buf; HlsMediaSource::Ptr _media_src; - TsInfo _info; + RecordInfo _info; map _segment_file_paths; }; diff --git a/src/Record/MP4Recorder.cpp b/src/Record/MP4Recorder.cpp index 1f247354..a8118333 100644 --- a/src/Record/MP4Recorder.cpp +++ b/src/Record/MP4Recorder.cpp @@ -73,7 +73,7 @@ void MP4Recorder::asyncClose() { auto info = _info; WorkThreadPool::Instance().getExecutor()->async([muxer,strFileTmp,strFile,info]() { //获取文件录制时间,放在关闭mp4之前是为了忽略关闭mp4执行时间 - const_cast(info).ui64TimeLen = ::time(NULL) - info.ui64StartedTime; + const_cast(info).ui64TimeLen = ::time(NULL) - info.ui64StartedTime; //关闭mp4非常耗时,所以要放在后台线程执行 muxer->closeMP4(); //临时文件名改成正式文件名,防止mp4未完成时被访问 @@ -81,7 +81,7 @@ void MP4Recorder::asyncClose() { //获取文件大小 struct stat fileData; stat(strFile.data(), &fileData); - const_cast(info).ui64FileSize = fileData.st_size; + const_cast(info).ui64FileSize = fileData.st_size; /////record 业务逻辑////// NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordMP4,info); }); diff --git a/src/Record/MP4Recorder.h b/src/Record/MP4Recorder.h index 60f3c561..cc73363d 100644 --- a/src/Record/MP4Recorder.h +++ b/src/Record/MP4Recorder.h @@ -20,24 +20,12 @@ #include "Util/TimeTicker.h" #include "Common/MediaSink.h" #include "MP4Muxer.h" +#include "RecordInfo.h" + using namespace toolkit; namespace mediakit { -class MP4Info { -public: - time_t ui64StartedTime; //GMT标准时间,单位秒 - time_t ui64TimeLen;//录像长度,单位秒 - off_t ui64FileSize;//文件大小,单位BYTE - string strFilePath;//文件路径 - string strFileName;//文件名称 - string strFolder;//文件夹路径 - string strUrl;//播放路径 - string strAppName;//应用名称 - string strStreamId;//流ID - string strVhost;//vhost -}; - #ifdef ENABLE_MP4 class MP4Recorder : public MediaSinkInterface{ public: @@ -72,7 +60,7 @@ private: string _strFile; string _strFileTmp; Ticker _createFileTicker; - MP4Info _info; + RecordInfo _info; bool _haveVideo = false; MP4Muxer::Ptr _muxer; list _tracks; diff --git a/src/Record/RecordInfo.h b/src/Record/RecordInfo.h new file mode 100644 index 00000000..30184a6a --- /dev/null +++ b/src/Record/RecordInfo.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved. + * + * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). + * + * 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. + */ + +#ifndef RECORDINFO_H_ +#define RECORDINFO_H_ + +#include "Common/config.h" + +namespace mediakit { + +class RecordInfo { +public: + time_t ui64StartedTime; // GMT 标准时间,单位秒 + time_t ui64TimeLen; // 录像长度,需要注意 mp4 单位是秒,而 hls ts 单位是毫秒 + off_t ui64FileSize; // 文件大小,单位 BYTE + string strFilePath; // 文件路径 + string strFileName; // 文件名称 + string strFolder; // 文件夹路径 + string strUrl; // 播放路径 + string strAppName; // 应用名称 + string strStreamId; // 流 ID + string strVhost; // vhost +}; + +} // namespace mediakit + +#endif // RECORDINFO_H_