mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
统一 mp4 及 ts 录像信息定义
This commit is contained in:
parent
b22a6e3dbd
commit
748bb8e488
@ -18,64 +18,64 @@
|
|||||||
#include "Rtsp/RtspSession.h"
|
#include "Rtsp/RtspSession.h"
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
///////////////////////////////////////////MP4Info/////////////////////////////////////////////
|
///////////////////////////////////////////RecordInfo/////////////////////////////////////////////
|
||||||
API_EXPORT uint64_t API_CALL mk_mp4_info_get_start_time(const mk_mp4_info ctx){
|
API_EXPORT uint64_t API_CALL mk_mp4_info_get_start_time(const mk_mp4_info ctx){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MP4Info *info = (MP4Info *)ctx;
|
RecordInfo *info = (RecordInfo *)ctx;
|
||||||
return info->ui64StartedTime;
|
return info->ui64StartedTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT uint64_t API_CALL mk_mp4_info_get_time_len(const mk_mp4_info ctx){
|
API_EXPORT uint64_t API_CALL mk_mp4_info_get_time_len(const mk_mp4_info ctx){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MP4Info *info = (MP4Info *)ctx;
|
RecordInfo *info = (RecordInfo *)ctx;
|
||||||
return info->ui64TimeLen;
|
return info->ui64TimeLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT uint64_t API_CALL mk_mp4_info_get_file_size(const mk_mp4_info ctx){
|
API_EXPORT uint64_t API_CALL mk_mp4_info_get_file_size(const mk_mp4_info ctx){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MP4Info *info = (MP4Info *)ctx;
|
RecordInfo *info = (RecordInfo *)ctx;
|
||||||
return info->ui64FileSize;
|
return info->ui64FileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT const char* API_CALL mk_mp4_info_get_file_path(const mk_mp4_info ctx){
|
API_EXPORT const char* API_CALL mk_mp4_info_get_file_path(const mk_mp4_info ctx){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MP4Info *info = (MP4Info *)ctx;
|
RecordInfo *info = (RecordInfo *)ctx;
|
||||||
return info->strFilePath.c_str();
|
return info->strFilePath.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT const char* API_CALL mk_mp4_info_get_file_name(const mk_mp4_info ctx){
|
API_EXPORT const char* API_CALL mk_mp4_info_get_file_name(const mk_mp4_info ctx){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MP4Info *info = (MP4Info *)ctx;
|
RecordInfo *info = (RecordInfo *)ctx;
|
||||||
return info->strFileName.c_str();
|
return info->strFileName.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT const char* API_CALL mk_mp4_info_get_folder(const mk_mp4_info ctx){
|
API_EXPORT const char* API_CALL mk_mp4_info_get_folder(const mk_mp4_info ctx){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MP4Info *info = (MP4Info *)ctx;
|
RecordInfo *info = (RecordInfo *)ctx;
|
||||||
return info->strFolder.c_str();
|
return info->strFolder.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT const char* API_CALL mk_mp4_info_get_url(const mk_mp4_info ctx){
|
API_EXPORT const char* API_CALL mk_mp4_info_get_url(const mk_mp4_info ctx){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MP4Info *info = (MP4Info *)ctx;
|
RecordInfo *info = (RecordInfo *)ctx;
|
||||||
return info->strUrl.c_str();
|
return info->strUrl.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT const char* API_CALL mk_mp4_info_get_vhost(const mk_mp4_info ctx){
|
API_EXPORT const char* API_CALL mk_mp4_info_get_vhost(const mk_mp4_info ctx){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MP4Info *info = (MP4Info *)ctx;
|
RecordInfo *info = (RecordInfo *)ctx;
|
||||||
return info->strVhost.c_str();
|
return info->strVhost.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT const char* API_CALL mk_mp4_info_get_app(const mk_mp4_info ctx){
|
API_EXPORT const char* API_CALL mk_mp4_info_get_app(const mk_mp4_info ctx){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MP4Info *info = (MP4Info *)ctx;
|
RecordInfo *info = (RecordInfo *)ctx;
|
||||||
return info->strAppName.c_str();
|
return info->strAppName.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT const char* API_CALL mk_mp4_info_get_stream(const mk_mp4_info ctx){
|
API_EXPORT const char* API_CALL mk_mp4_info_get_stream(const mk_mp4_info ctx){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MP4Info *info = (MP4Info *)ctx;
|
RecordInfo *info = (RecordInfo *)ctx;
|
||||||
return info->strStreamId.c_str();
|
return info->strStreamId.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,11 +58,11 @@ extern const string kBroadcastMediaChanged;
|
|||||||
|
|
||||||
//录制mp4文件成功后广播
|
//录制mp4文件成功后广播
|
||||||
extern const string kBroadcastRecordMP4;
|
extern const string kBroadcastRecordMP4;
|
||||||
#define BroadcastRecordMP4Args const MP4Info &info
|
#define BroadcastRecordMP4Args const RecordInfo &info
|
||||||
|
|
||||||
// 录制 ts 文件后广播
|
// 录制 ts 文件后广播
|
||||||
extern const string kBroadcastRecordTs;
|
extern const string kBroadcastRecordTs;
|
||||||
#define BroadcastRecordTsArgs const TsInfo &info
|
#define BroadcastRecordTsArgs const RecordInfo &info
|
||||||
|
|
||||||
//收到http api请求广播
|
//收到http api请求广播
|
||||||
extern const string kBroadcastHttpRequest;
|
extern const string kBroadcastHttpRequest;
|
||||||
|
@ -117,7 +117,7 @@ void HlsMakerImp::onFlushLastSegment(uint32_t duration) {
|
|||||||
WorkThreadPool::Instance().getExecutor()->async([info]() {
|
WorkThreadPool::Instance().getExecutor()->async([info]() {
|
||||||
struct stat fileData;
|
struct stat fileData;
|
||||||
stat(info.strFilePath.data(), &fileData);
|
stat(info.strFilePath.data(), &fileData);
|
||||||
const_cast<TsInfo&>(info).ui64FileSize = fileData.st_size;
|
const_cast<RecordInfo&>(info).ui64FileSize = fileData.st_size;
|
||||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordTs, info);
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordTs, info);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "HlsMaker.h"
|
#include "HlsMaker.h"
|
||||||
#include "HlsMediaSource.h"
|
#include "HlsMediaSource.h"
|
||||||
|
#include "RecordInfo.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
@ -67,7 +69,7 @@ private:
|
|||||||
std::shared_ptr<FILE> _file;
|
std::shared_ptr<FILE> _file;
|
||||||
std::shared_ptr<char> _file_buf;
|
std::shared_ptr<char> _file_buf;
|
||||||
HlsMediaSource::Ptr _media_src;
|
HlsMediaSource::Ptr _media_src;
|
||||||
TsInfo _info;
|
RecordInfo _info;
|
||||||
map<int /*index*/,string/*file_path*/> _segment_file_paths;
|
map<int /*index*/,string/*file_path*/> _segment_file_paths;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ void MP4Recorder::asyncClose() {
|
|||||||
auto info = _info;
|
auto info = _info;
|
||||||
WorkThreadPool::Instance().getExecutor()->async([muxer,strFileTmp,strFile,info]() {
|
WorkThreadPool::Instance().getExecutor()->async([muxer,strFileTmp,strFile,info]() {
|
||||||
//获取文件录制时间,放在关闭mp4之前是为了忽略关闭mp4执行时间
|
//获取文件录制时间,放在关闭mp4之前是为了忽略关闭mp4执行时间
|
||||||
const_cast<MP4Info&>(info).ui64TimeLen = ::time(NULL) - info.ui64StartedTime;
|
const_cast<RecordInfo&>(info).ui64TimeLen = ::time(NULL) - info.ui64StartedTime;
|
||||||
//关闭mp4非常耗时,所以要放在后台线程执行
|
//关闭mp4非常耗时,所以要放在后台线程执行
|
||||||
muxer->closeMP4();
|
muxer->closeMP4();
|
||||||
//临时文件名改成正式文件名,防止mp4未完成时被访问
|
//临时文件名改成正式文件名,防止mp4未完成时被访问
|
||||||
@ -81,7 +81,7 @@ void MP4Recorder::asyncClose() {
|
|||||||
//获取文件大小
|
//获取文件大小
|
||||||
struct stat fileData;
|
struct stat fileData;
|
||||||
stat(strFile.data(), &fileData);
|
stat(strFile.data(), &fileData);
|
||||||
const_cast<MP4Info&>(info).ui64FileSize = fileData.st_size;
|
const_cast<RecordInfo&>(info).ui64FileSize = fileData.st_size;
|
||||||
/////record 业务逻辑//////
|
/////record 业务逻辑//////
|
||||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordMP4,info);
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordMP4,info);
|
||||||
});
|
});
|
||||||
|
@ -20,24 +20,12 @@
|
|||||||
#include "Util/TimeTicker.h"
|
#include "Util/TimeTicker.h"
|
||||||
#include "Common/MediaSink.h"
|
#include "Common/MediaSink.h"
|
||||||
#include "MP4Muxer.h"
|
#include "MP4Muxer.h"
|
||||||
|
#include "RecordInfo.h"
|
||||||
|
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
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
|
#ifdef ENABLE_MP4
|
||||||
class MP4Recorder : public MediaSinkInterface{
|
class MP4Recorder : public MediaSinkInterface{
|
||||||
public:
|
public:
|
||||||
@ -72,7 +60,7 @@ private:
|
|||||||
string _strFile;
|
string _strFile;
|
||||||
string _strFileTmp;
|
string _strFileTmp;
|
||||||
Ticker _createFileTicker;
|
Ticker _createFileTicker;
|
||||||
MP4Info _info;
|
RecordInfo _info;
|
||||||
bool _haveVideo = false;
|
bool _haveVideo = false;
|
||||||
MP4Muxer::Ptr _muxer;
|
MP4Muxer::Ptr _muxer;
|
||||||
list<Track::Ptr> _tracks;
|
list<Track::Ptr> _tracks;
|
||||||
|
34
src/Record/RecordInfo.h
Normal file
34
src/Record/RecordInfo.h
Normal file
@ -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_
|
Loading…
Reference in New Issue
Block a user