Commit ccbd1d4a by xiongziliang

添加hls.segRetain配置项,修复hls切片等于segNum+1的问题

parent 35c4c05e
...@@ -44,10 +44,12 @@ fileBufSize=65536 ...@@ -44,10 +44,12 @@ fileBufSize=65536
#可以为相对(相对于本可执行程序目录)或绝对路径 #可以为相对(相对于本可执行程序目录)或绝对路径
filePath=./httpRoot filePath=./httpRoot
#hls最大切片时间 #hls最大切片时间
segDur=3 segDur=2
#m3u8索引中,hls保留切片个数(实际保留切片个数大2~3个) #m3u8索引中,hls保留切片个数(实际保留切片个数大2~3个)
#如果设置为0,则不删除切片,而是保存为点播 #如果设置为0,则不删除切片,而是保存为点播
segNum=3 segNum=3
#HLS切片从m3u8文件中移除后,继续保留在磁盘上的个数
segRetain=5
[hook] [hook]
#在推流时,如果url参数匹对admin_params,那么可以不经过hook鉴权直接推流成功,播放时亦然 #在推流时,如果url参数匹对admin_params,那么可以不经过hook鉴权直接推流成功,播放时亦然
......
...@@ -95,57 +95,44 @@ onceToken token([](){ ...@@ -95,57 +95,44 @@ onceToken token([](){
////////////HTTP配置/////////// ////////////HTTP配置///////////
namespace Http { namespace Http {
#define HTTP_FIELD "http." #define HTTP_FIELD "http."
//http 文件发送缓存大小 //http 文件发送缓存大小
#define HTTP_SEND_BUF_SIZE (64 * 1024)
const string kSendBufSize = HTTP_FIELD"sendBufSize"; const string kSendBufSize = HTTP_FIELD"sendBufSize";
//http 最大请求字节数 //http 最大请求字节数
#define HTTP_MAX_REQ_SIZE (4*1024)
const string kMaxReqSize = HTTP_FIELD"maxReqSize"; const string kMaxReqSize = HTTP_FIELD"maxReqSize";
//http keep-alive秒数 //http keep-alive秒数
#define HTTP_KEEP_ALIVE_SECOND 10
const string kKeepAliveSecond = HTTP_FIELD"keepAliveSecond"; const string kKeepAliveSecond = HTTP_FIELD"keepAliveSecond";
//http keep-alive最大请求数 //http keep-alive最大请求数
#define HTTP_MAX_REQ_CNT 100
const string kMaxReqCount = HTTP_FIELD"maxReqCount"; const string kMaxReqCount = HTTP_FIELD"maxReqCount";
//http 字符编码 //http 字符编码
#if defined(_WIN32)
#define HTTP_CHAR_SET "gb2312"
#else
#define HTTP_CHAR_SET "utf-8"
#endif
const string kCharSet = HTTP_FIELD"charSet"; const string kCharSet = HTTP_FIELD"charSet";
//http 服务器根目录 //http 服务器根目录
#define HTTP_ROOT_PATH "./httpRoot"
const string kRootPath = HTTP_FIELD"rootPath"; const string kRootPath = HTTP_FIELD"rootPath";
//http 404错误提示内容 //http 404错误提示内容
#define HTTP_NOT_FOUND "<html>"\
"<head><title>404 Not Found</title></head>"\
"<body bgcolor=\"white\">"\
"<center><h1>您访问的资源不存在!</h1></center>"\
"<hr><center>"\
SERVER_NAME\
"</center>"\
"</body>"\
"</html>"
const string kNotFound = HTTP_FIELD"notFound"; const string kNotFound = HTTP_FIELD"notFound";
onceToken token([](){ onceToken token([](){
mINI::Instance()[kSendBufSize] = HTTP_SEND_BUF_SIZE; mINI::Instance()[kSendBufSize] = 64 * 1024;
mINI::Instance()[kMaxReqSize] = HTTP_MAX_REQ_SIZE; mINI::Instance()[kMaxReqSize] = 4*1024;
mINI::Instance()[kKeepAliveSecond] = HTTP_KEEP_ALIVE_SECOND; mINI::Instance()[kKeepAliveSecond] = 15;
mINI::Instance()[kMaxReqCount] = HTTP_MAX_REQ_CNT; mINI::Instance()[kMaxReqCount] = 100;
mINI::Instance()[kCharSet] = HTTP_CHAR_SET;
mINI::Instance()[kRootPath] = HTTP_ROOT_PATH; #if defined(_WIN32)
mINI::Instance()[kNotFound] = HTTP_NOT_FOUND; mINI::Instance()[kCharSet] = "gb2312";
#else
mINI::Instance()[kCharSet] ="utf-8";
#endif
mINI::Instance()[kRootPath] = "./httpRoot";
mINI::Instance()[kNotFound] =
"<html>"
"<head><title>404 Not Found</title></head>"
"<body bgcolor=\"white\">"
"<center><h1>您访问的资源不存在!</h1></center>"
"<hr><center>"
SERVER_NAME
"</center>"
"</body>"
"</html>";
},nullptr); },nullptr);
}//namespace Http }//namespace Http
...@@ -153,12 +140,10 @@ onceToken token([](){ ...@@ -153,12 +140,10 @@ onceToken token([](){
////////////SHELL配置/////////// ////////////SHELL配置///////////
namespace Shell { namespace Shell {
#define SHELL_FIELD "shell." #define SHELL_FIELD "shell."
#define SHELL_MAX_REQ_SIZE 1024
const string kMaxReqSize = SHELL_FIELD"maxReqSize"; const string kMaxReqSize = SHELL_FIELD"maxReqSize";
onceToken token([](){ onceToken token([](){
mINI::Instance()[kMaxReqSize] = SHELL_MAX_REQ_SIZE; mINI::Instance()[kMaxReqSize] = 1024;
},nullptr); },nullptr);
} //namespace Shell } //namespace Shell
...@@ -179,7 +164,6 @@ onceToken token([](){ ...@@ -179,7 +164,6 @@ onceToken token([](){
mINI::Instance()[kDirectProxy] = 1; mINI::Instance()[kDirectProxy] = 1;
mINI::Instance()[kModifyStamp] = false; mINI::Instance()[kModifyStamp] = false;
},nullptr); },nullptr);
} //namespace Rtsp } //namespace Rtsp
////////////RTMP服务器配置/////////// ////////////RTMP服务器配置///////////
...@@ -194,40 +178,28 @@ onceToken token([](){ ...@@ -194,40 +178,28 @@ onceToken token([](){
mINI::Instance()[kHandshakeSecond] = 15; mINI::Instance()[kHandshakeSecond] = 15;
mINI::Instance()[kKeepAliveSecond] = 15; mINI::Instance()[kKeepAliveSecond] = 15;
},nullptr); },nullptr);
} //namespace RTMP } //namespace RTMP
////////////RTP配置/////////// ////////////RTP配置///////////
namespace Rtp { namespace Rtp {
#define RTP_FIELD "rtp." #define RTP_FIELD "rtp."
//RTP打包最大MTU,公网情况下更小 //RTP打包最大MTU,公网情况下更小
#define RTP_VIDOE_MTU_SIZE 1400
const string kVideoMtuSize = RTP_FIELD"videoMtuSize"; const string kVideoMtuSize = RTP_FIELD"videoMtuSize";
#define RTP_Audio_MTU_SIZE 600
const string kAudioMtuSize = RTP_FIELD"audioMtuSize"; const string kAudioMtuSize = RTP_FIELD"audioMtuSize";
//RTP排序缓存最大个数 //RTP排序缓存最大个数
#define RTP_MAX_RTP_COUNT 50
const string kMaxRtpCount = RTP_FIELD"maxRtpCount"; const string kMaxRtpCount = RTP_FIELD"maxRtpCount";
//如果RTP序列正确次数累计达到该数字就启动清空排序缓存 //如果RTP序列正确次数累计达到该数字就启动清空排序缓存
#define RTP_CLEAR_COUNT 10
const string kClearCount = RTP_FIELD"clearCount"; const string kClearCount = RTP_FIELD"clearCount";
//最大RTP时间为13个小时,每13小时回环一次 //最大RTP时间为13个小时,每13小时回环一次
#define RTP_CYCLE_MS (13*60*60*1000)
const string kCycleMS = RTP_FIELD"cycleMS"; const string kCycleMS = RTP_FIELD"cycleMS";
onceToken token([](){ onceToken token([](){
mINI::Instance()[kVideoMtuSize] = RTP_VIDOE_MTU_SIZE; mINI::Instance()[kVideoMtuSize] = 1400;
mINI::Instance()[kAudioMtuSize] = RTP_Audio_MTU_SIZE; mINI::Instance()[kAudioMtuSize] = 600;
mINI::Instance()[kMaxRtpCount] = RTP_MAX_RTP_COUNT; mINI::Instance()[kMaxRtpCount] = 50;
mINI::Instance()[kClearCount] = RTP_CLEAR_COUNT; mINI::Instance()[kClearCount] = 10;
mINI::Instance()[kCycleMS] = RTP_CYCLE_MS; mINI::Instance()[kCycleMS] = 13*60*60*1000;
},nullptr); },nullptr);
} //namespace Rtsp } //namespace Rtsp
...@@ -239,88 +211,67 @@ const string kAddrMin = MULTI_FIELD"addrMin"; ...@@ -239,88 +211,67 @@ const string kAddrMin = MULTI_FIELD"addrMin";
//组播分配截止地址 //组播分配截止地址
const string kAddrMax = MULTI_FIELD"addrMax"; const string kAddrMax = MULTI_FIELD"addrMax";
//组播TTL //组播TTL
#define MULTI_UDP_TTL 64
const string kUdpTTL = MULTI_FIELD"udpTTL"; const string kUdpTTL = MULTI_FIELD"udpTTL";
onceToken token([](){ onceToken token([](){
mINI::Instance()[kAddrMin] = "239.0.0.0"; mINI::Instance()[kAddrMin] = "239.0.0.0";
mINI::Instance()[kAddrMax] = "239.255.255.255"; mINI::Instance()[kAddrMax] = "239.255.255.255";
mINI::Instance()[kUdpTTL] = MULTI_UDP_TTL; mINI::Instance()[kUdpTTL] = 64;
},nullptr); },nullptr);
} //namespace MultiCast } //namespace MultiCast
////////////录像配置/////////// ////////////录像配置///////////
namespace Record { namespace Record {
#define RECORD_FIELD "record." #define RECORD_FIELD "record."
//查看录像的应用名称 //查看录像的应用名称
#define RECORD_APP_NAME "record"
const string kAppName = RECORD_FIELD"appName"; const string kAppName = RECORD_FIELD"appName";
//每次流化MP4文件的时长,单位毫秒 //每次流化MP4文件的时长,单位毫秒
#define RECORD_SAMPLE_MS 500
const string kSampleMS = RECORD_FIELD"sampleMS"; const string kSampleMS = RECORD_FIELD"sampleMS";
//MP4文件录制大小,默认一个小时 //MP4文件录制大小,默认一个小时
#define RECORD_FILE_SECOND (60*60)
const string kFileSecond = RECORD_FIELD"fileSecond"; const string kFileSecond = RECORD_FIELD"fileSecond";
//录制文件路径 //录制文件路径
#define RECORD_FILE_PATH HTTP_ROOT_PATH
const string kFilePath = RECORD_FIELD"filePath"; const string kFilePath = RECORD_FIELD"filePath";
//mp4文件写缓存大小 //mp4文件写缓存大小
const string kFileBufSize = RECORD_FIELD"fileBufSize"; const string kFileBufSize = RECORD_FIELD"fileBufSize";
//mp4录制完成后是否进行二次关键帧索引写入头部 //mp4录制完成后是否进行二次关键帧索引写入头部
const string kFastStart = RECORD_FIELD"fastStart"; const string kFastStart = RECORD_FIELD"fastStart";
//mp4文件是否重头循环读取 //mp4文件是否重头循环读取
const string kFileRepeat = RECORD_FIELD"fileRepeat"; const string kFileRepeat = RECORD_FIELD"fileRepeat";
onceToken token([](){ onceToken token([](){
mINI::Instance()[kAppName] = RECORD_APP_NAME; mINI::Instance()[kAppName] = "record";
mINI::Instance()[kSampleMS] = RECORD_SAMPLE_MS; mINI::Instance()[kSampleMS] = 500;
mINI::Instance()[kFileSecond] = RECORD_FILE_SECOND; mINI::Instance()[kFileSecond] = 60*60;
mINI::Instance()[kFilePath] = RECORD_FILE_PATH; mINI::Instance()[kFilePath] = "./httpRoot";
mINI::Instance()[kFileBufSize] = 64 * 1024; mINI::Instance()[kFileBufSize] = 64 * 1024;
mINI::Instance()[kFastStart] = false; mINI::Instance()[kFastStart] = false;
mINI::Instance()[kFileRepeat] = false; mINI::Instance()[kFileRepeat] = false;
},nullptr); },nullptr);
} //namespace Record } //namespace Record
////////////HLS相关配置/////////// ////////////HLS相关配置///////////
namespace Hls { namespace Hls {
#define HLS_FIELD "hls." #define HLS_FIELD "hls."
//HLS切片时长,单位秒 //HLS切片时长,单位秒
#define HLS_SEGMENT_DURATION 3
const string kSegmentDuration = HLS_FIELD"segDur"; const string kSegmentDuration = HLS_FIELD"segDur";
//HLS切片个数 //HLS切片个数
#define HLS_SEGMENT_NUM 3
const string kSegmentNum = HLS_FIELD"segNum"; const string kSegmentNum = HLS_FIELD"segNum";
//HLS切片从m3u8文件中移除后,继续保留在磁盘上的个数
const string kSegmentRetain = HLS_FIELD"segRetain";
//HLS文件写缓存大小 //HLS文件写缓存大小
#define HLS_FILE_BUF_SIZE (64 * 1024)
const string kFileBufSize = HLS_FIELD"fileBufSize"; const string kFileBufSize = HLS_FIELD"fileBufSize";
//录制文件路径 //录制文件路径
#define HLS_FILE_PATH (HTTP_ROOT_PATH)
const string kFilePath = HLS_FIELD"filePath"; const string kFilePath = HLS_FIELD"filePath";
onceToken token([](){ onceToken token([](){
mINI::Instance()[kSegmentDuration] = HLS_SEGMENT_DURATION; mINI::Instance()[kSegmentDuration] = 2;
mINI::Instance()[kSegmentNum] = HLS_SEGMENT_NUM; mINI::Instance()[kSegmentNum] = 3;
mINI::Instance()[kFileBufSize] = HLS_FILE_BUF_SIZE; mINI::Instance()[kSegmentRetain] = 5;
mINI::Instance()[kFilePath] = HLS_FILE_PATH; mINI::Instance()[kFileBufSize] = 64 * 1024;
mINI::Instance()[kFilePath] = "./httpRoot";
},nullptr); },nullptr);
} //namespace Hls } //namespace Hls
namespace Client { namespace Client {
const string kNetAdapter = "net_adapter"; const string kNetAdapter = "net_adapter";
const string kRtpType = "rtp_type"; const string kRtpType = "rtp_type";
...@@ -331,7 +282,6 @@ const string kTimeoutMS = "protocol_timeout_ms"; ...@@ -331,7 +282,6 @@ const string kTimeoutMS = "protocol_timeout_ms";
const string kMediaTimeoutMS = "media_timeout_ms"; const string kMediaTimeoutMS = "media_timeout_ms";
const string kBeatIntervalMS = "beat_interval_ms"; const string kBeatIntervalMS = "beat_interval_ms";
const string kMaxAnalysisMS = "max_analysis_ms"; const string kMaxAnalysisMS = "max_analysis_ms";
} }
} // namespace mediakit } // namespace mediakit
......
...@@ -283,8 +283,10 @@ extern const string kFileRepeat; ...@@ -283,8 +283,10 @@ extern const string kFileRepeat;
namespace Hls { namespace Hls {
//HLS切片时长,单位秒 //HLS切片时长,单位秒
extern const string kSegmentDuration; extern const string kSegmentDuration;
//HLS切片个数,如果设置为0,则不删除切片,而是保存为点播 //m3u8文件中HLS切片个数,如果设置为0,则不删除切片,而是保存为点播
extern const string kSegmentNum; extern const string kSegmentNum;
//HLS切片从m3u8文件中移除后,继续保留在磁盘上的个数
extern const string kSegmentRetain;
//HLS文件写缓存大小 //HLS文件写缓存大小
extern const string kFileBufSize; extern const string kFileBufSize;
//录制文件路径 //录制文件路径
......
...@@ -93,13 +93,14 @@ void HlsMaker::delOldSegment() { ...@@ -93,13 +93,14 @@ void HlsMaker::delOldSegment() {
return; return;
} }
//在hls m3u8索引文件中,我们保存的切片个数跟_seg_number相关设置一致 //在hls m3u8索引文件中,我们保存的切片个数跟_seg_number相关设置一致
if (_file_index >= _seg_number + 2) { if (_file_index > _seg_number) {
_seg_dur_list.pop_front(); _seg_dur_list.pop_front();
} }
//但是实际保存的切片个数比m3u8所述多两个,这样做的目的是防止播放器在切片删除前能下载完毕 GET_CONFIG(uint32_t,segRetain,Hls::kSegmentRetain);
if (_file_index >= _seg_number + 4) { //但是实际保存的切片个数比m3u8所述多若干个,这样做的目的是防止播放器在切片删除前能下载完毕
onDelSegment(_file_index - _seg_number - 4); if (_file_index > _seg_number + segRetain) {
onDelSegment(_file_index - _seg_number - segRetain - 1);
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论