Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
35791aac
Commit
35791aac
authored
Aug 08, 2022
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码,去除编译警告,修复拼写错误
parent
9c3b8a6a
显示空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
57 行增加
和
44 行删除
+57
-44
server/Process.h
+4
-2
src/Codec/Transcode.cpp
+1
-1
src/Extension/AAC.cpp
+7
-4
src/Extension/H265Rtmp.cpp
+4
-2
src/Http/HttpCookieManager.cpp
+14
-14
src/Http/HttpCookieManager.h
+4
-4
src/Record/MP4Demuxer.cpp
+11
-8
src/Record/MP4Muxer.cpp
+4
-2
srt/PacketQueue.cpp
+3
-3
srt/PacketSendQueue.cpp
+3
-3
tests/test_rtp.cpp
+2
-1
没有找到文件。
server/Process.h
查看文件 @
35791aac
...
...
@@ -29,10 +29,12 @@ public:
bool
wait
(
bool
block
=
true
);
int
exit_code
();
private
:
int
_exit_code
=
0
;
pid_t
_pid
=
-
1
;
void
*
_handle
=
nullptr
;
void
*
_process_stack
=
nullptr
;
int
_exit_code
=
0
;
#if (defined(__linux) || defined(__linux__))
void
*
_process_stack
=
nullptr
;
#endif
};
...
...
src/Codec/Transcode.cpp
查看文件 @
35791aac
...
...
@@ -386,7 +386,7 @@ FFmpegDecoder::FFmpegDecoder(const Track::Ptr &track, int thread_num) {
if
(
thread_num
<=
0
)
{
av_dict_set
(
&
dict
,
"threads"
,
"auto"
,
0
);
}
else
{
av_dict_set
(
&
dict
,
"threads"
,
to_string
(
MIN
(
thread_num
,
thread
::
hardware_concurrency
())).
data
(),
0
);
av_dict_set
(
&
dict
,
"threads"
,
to_string
(
MIN
(
(
unsigned
int
)
thread_num
,
thread
::
hardware_concurrency
())).
data
(),
0
);
}
av_dict_set
(
&
dict
,
"zerolatency"
,
"1"
,
0
);
av_dict_set
(
&
dict
,
"strict"
,
"-2"
,
0
);
...
...
src/Extension/AAC.cpp
查看文件 @
35791aac
...
...
@@ -132,7 +132,8 @@ string makeAacConfig(const uint8_t *hex, size_t length){
audioSpecificConfig
[
1
]
=
(
sampling_frequency_index
<<
7
)
|
(
channel_configuration
<<
3
);
return
string
((
char
*
)
audioSpecificConfig
,
2
);
#else
struct
mpeg4_aac_t
aac
=
{
0
};
struct
mpeg4_aac_t
aac
;
memset
(
&
aac
,
0
,
sizeof
(
aac
));
if
(
mpeg4_aac_adts_load
(
hex
,
length
,
&
aac
)
>
0
)
{
char
buf
[
32
]
=
{
0
};
int
len
=
mpeg4_aac_audio_specific_config_save
(
&
aac
,
(
uint8_t
*
)
buf
,
sizeof
(
buf
));
...
...
@@ -153,7 +154,8 @@ int dumpAacConfig(const string &config, size_t length, uint8_t *out, size_t out_
dumpAdtsHeader
(
header
,
out
);
return
ADTS_HEADER_LEN
;
#else
struct
mpeg4_aac_t
aac
=
{
0
};
struct
mpeg4_aac_t
aac
;
memset
(
&
aac
,
0
,
sizeof
(
aac
));
int
ret
=
mpeg4_aac_audio_specific_config_load
((
uint8_t
*
)
config
.
data
(),
config
.
size
(),
&
aac
);
if
(
ret
>
0
)
{
ret
=
mpeg4_aac_adts_save
(
&
aac
,
length
,
out
,
out_size
);
...
...
@@ -174,7 +176,8 @@ bool parseAacConfig(const string &config, int &samplerate, int &channels){
channels
=
header
.
channel_configuration
;
return
true
;
#else
struct
mpeg4_aac_t
aac
=
{
0
};
struct
mpeg4_aac_t
aac
;
memset
(
&
aac
,
0
,
sizeof
(
aac
));
int
ret
=
mpeg4_aac_audio_specific_config_load
((
uint8_t
*
)
config
.
data
(),
config
.
size
(),
&
aac
);
if
(
ret
>
0
)
{
samplerate
=
aac
.
sampling_frequency
;
...
...
@@ -284,7 +287,7 @@ bool AACTrack::inputFrame(const Frame::Ptr &frame) {
if
(
frame_len
<
ADTS_HEADER_LEN
)
{
break
;
}
if
(
frame_len
==
frame
->
size
())
{
if
(
frame_len
==
(
int
)
frame
->
size
())
{
return
inputFrame_l
(
frame
);
}
auto
sub_frame
=
std
::
make_shared
<
FrameTSInternal
<
FrameFromPtr
>
>
(
frame
,
(
char
*
)
ptr
,
frame_len
,
ADTS_HEADER_LEN
,
dts
,
pts
);
...
...
src/Extension/H265Rtmp.cpp
查看文件 @
35791aac
...
...
@@ -49,7 +49,8 @@ static bool getH265ConfigFrame(const RtmpPacket &thiz,string &frame) {
auto
extra
=
thiz
.
buffer
.
data
()
+
5
;
auto
bytes
=
thiz
.
buffer
.
size
()
-
5
;
struct
mpeg4_hevc_t
hevc
=
{
0
};
struct
mpeg4_hevc_t
hevc
;
memset
(
&
hevc
,
0
,
sizeof
(
hevc
));
if
(
mpeg4_hevc_decoder_configuration_record_load
((
uint8_t
*
)
extra
,
bytes
,
&
hevc
)
>
0
)
{
uint8_t
*
config
=
new
uint8_t
[
bytes
*
2
];
int
size
=
mpeg4_hevc_to_nalu
(
&
hevc
,
config
,
bytes
*
2
);
...
...
@@ -207,7 +208,8 @@ void H265RtmpEncoder::makeVideoConfigPkt() {
//cts
rtmpPkt
->
buffer
.
append
(
"\x0\x0\x0"
,
3
);
struct
mpeg4_hevc_t
hevc
=
{
0
};
struct
mpeg4_hevc_t
hevc
;
memset
(
&
hevc
,
0
,
sizeof
(
hevc
));
string
vps_sps_pps
=
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
_vps
+
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
_sps
+
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
_pps
;
...
...
src/Http/HttpCookieManager.cpp
查看文件 @
35791aac
...
...
@@ -67,7 +67,7 @@ void HttpServerCookie::setAttach(std::shared_ptr<void> attach) {
string
HttpServerCookie
::
cookieExpireTime
()
const
{
char
buf
[
64
];
time_t
tt
=
time
(
NULL
)
+
_max_elapsed
;
time_t
tt
=
time
(
nullptr
)
+
_max_elapsed
;
strftime
(
buf
,
sizeof
buf
,
"%a, %b %d %Y %H:%M:%S GMT"
,
gmtime
(
&
tt
));
return
buf
;
}
...
...
@@ -105,8 +105,8 @@ void HttpCookieManager::onManager() {
}
if
(
it_name
->
second
.
empty
())
{
//该类型下没有任何cooki记录,移除之
DebugL
<<
"该path下没有任何cooki记录:"
<<
it_name
->
first
;
//该类型下没有任何cooki
e
记录,移除之
DebugL
<<
"该path下没有任何cooki
e
记录:"
<<
it_name
->
first
;
it_name
=
_map_cookie
.
erase
(
it_name
);
continue
;
}
...
...
@@ -117,7 +117,7 @@ void HttpCookieManager::onManager() {
HttpServerCookie
::
Ptr
HttpCookieManager
::
addCookie
(
const
string
&
cookie_name
,
const
string
&
uid_in
,
uint64_t
max_elapsed
,
std
::
shared_ptr
<
void
>
attach
,
int
max_client
)
{
lock_guard
<
recursive_mutex
>
lck
(
_mtx_cookie
);
auto
cookie
=
_geneator
.
obtain
();
auto
cookie
=
_gene
r
ator
.
obtain
();
auto
uid
=
uid_in
.
empty
()
?
cookie
:
uid_in
;
auto
oldCookie
=
getOldestCookie
(
cookie_name
,
uid
,
max_client
);
if
(
!
oldCookie
.
empty
())
{
...
...
@@ -159,13 +159,13 @@ HttpServerCookie::Ptr HttpCookieManager::getCookie(const string &cookie_name, co
return
nullptr
;
}
auto
cookie
=
FindField
(
it
->
second
.
data
(),
(
cookie_name
+
"="
).
data
(),
";"
);
if
(
!
cookie
.
size
())
{
if
(
cookie
.
empty
())
{
cookie
=
FindField
(
it
->
second
.
data
(),
(
cookie_name
+
"="
).
data
(),
nullptr
);
}
if
(
cookie
.
empty
())
{
return
nullptr
;
}
return
HttpCookieManager
::
Instance
().
getCookie
(
cookie_name
,
cookie
);
return
getCookie
(
cookie_name
,
cookie
);
}
HttpServerCookie
::
Ptr
HttpCookieManager
::
getCookieByUid
(
const
string
&
cookie_name
,
const
string
&
uid
)
{
...
...
@@ -205,7 +205,7 @@ void HttpCookieManager::onAddCookie(const string &cookie_name, const string &uid
void
HttpCookieManager
::
onDelCookie
(
const
string
&
cookie_name
,
const
string
&
uid
,
const
string
&
cookie
)
{
lock_guard
<
recursive_mutex
>
lck
(
_mtx_cookie
);
//回收随机字符串
_geneator
.
release
(
cookie
);
_gene
r
ator
.
release
(
cookie
);
auto
it_name
=
_map_uid_to_cookie
.
find
(
cookie_name
);
if
(
it_name
==
_map_uid_to_cookie
.
end
())
{
...
...
@@ -227,14 +227,14 @@ void HttpCookieManager::onDelCookie(const string &cookie_name, const string &uid
//移除该用户名下的某个cookie,这个设备cookie将失效
it_uid
->
second
.
erase
(
it_cookie
);
if
(
it_uid
->
second
.
size
()
!=
0
)
{
if
(
!
it_uid
->
second
.
empty
()
)
{
break
;
}
//该用户名下没有任何设备在线,移除之
it_name
->
second
.
erase
(
it_uid
);
if
(
it_name
->
second
.
size
()
!=
0
)
{
if
(
!
it_name
->
second
.
empty
()
)
{
break
;
}
//该类型下未有任何用户在线,移除之
...
...
@@ -255,7 +255,7 @@ string HttpCookieManager::getOldestCookie(const string &cookie_name, const strin
//该用户从未登录过
return
""
;
}
if
(
it_uid
->
second
.
size
()
<
MAX
(
1
,
max_client
))
{
if
(
(
int
)
it_uid
->
second
.
size
()
<
MAX
(
1
,
max_client
))
{
//同一名用户下,客户端个数还没达到限制个数
return
""
;
}
...
...
@@ -263,8 +263,8 @@ string HttpCookieManager::getOldestCookie(const string &cookie_name, const strin
return
it_uid
->
second
.
begin
()
->
second
;
}
/////////////////////////////////RandStrGeneator////////////////////////////////////
string
RandStrGeneator
::
obtain
()
{
/////////////////////////////////RandStrGene
r
ator////////////////////////////////////
string
RandStrGene
r
ator
::
obtain
()
{
//获取唯一的防膨胀的随机字符串
while
(
true
)
{
auto
str
=
obtain_l
();
...
...
@@ -276,12 +276,12 @@ string RandStrGeneator::obtain() {
}
}
void
RandStrGeneator
::
release
(
const
string
&
str
)
{
void
RandStrGene
r
ator
::
release
(
const
string
&
str
)
{
//从防膨胀库中移除
_obtained
.
erase
(
str
);
}
string
RandStrGeneator
::
obtain_l
()
{
string
RandStrGene
r
ator
::
obtain_l
()
{
// 12个伪随机字节 + 4个递增的整形字节,然后md5即为随机字符串
auto
str
=
makeRandStr
(
12
,
false
);
str
.
append
((
char
*
)
&
_index
,
sizeof
(
_index
));
...
...
src/Http/HttpCookieManager.h
查看文件 @
35791aac
...
...
@@ -111,10 +111,10 @@ private:
/**
* cookie随机字符串生成器
*/
class
RandStrGeneator
{
class
RandStrGene
r
ator
{
public
:
RandStrGeneator
()
=
default
;
~
RandStrGeneator
()
=
default
;
RandStrGene
r
ator
()
=
default
;
~
RandStrGene
r
ator
()
=
default
;
/**
* 获取不碰撞的随机字符串
...
...
@@ -244,7 +244,7 @@ private:
_map_uid_to_cookie
;
std
::
recursive_mutex
_mtx_cookie
;
toolkit
::
Timer
::
Ptr
_timer
;
RandStrGene
ator
_gene
ator
;
RandStrGene
rator
_gener
ator
;
};
}
// namespace mediakit
...
...
src/Record/MP4Demuxer.cpp
查看文件 @
35791aac
...
...
@@ -96,7 +96,8 @@ void MP4Demuxer::onVideoTrack(uint32_t track, uint8_t object, int width, int hei
auto
video
=
std
::
make_shared
<
H264Track
>
();
_track_to_codec
.
emplace
(
track
,
video
);
struct
mpeg4_avc_t
avc
=
{
0
};
struct
mpeg4_avc_t
avc
;
memset
(
&
avc
,
0
,
sizeof
(
avc
));
if
(
mpeg4_avc_decoder_configuration_record_load
((
uint8_t
*
)
extra
,
bytes
,
&
avc
)
>
0
)
{
uint8_t
config
[
1024
*
10
]
=
{
0
};
int
size
=
mpeg4_avc_to_nalu
(
&
avc
,
config
,
sizeof
(
config
));
...
...
@@ -110,7 +111,8 @@ void MP4Demuxer::onVideoTrack(uint32_t track, uint8_t object, int width, int hei
auto
video
=
std
::
make_shared
<
H265Track
>
();
_track_to_codec
.
emplace
(
track
,
video
);
struct
mpeg4_hevc_t
hevc
=
{
0
};
struct
mpeg4_hevc_t
hevc
;
memset
(
&
hevc
,
0
,
sizeof
(
hevc
));
if
(
mpeg4_hevc_decoder_configuration_record_load
((
uint8_t
*
)
extra
,
bytes
,
&
hevc
)
>
0
)
{
uint8_t
config
[
1024
*
10
]
=
{
0
};
int
size
=
mpeg4_hevc_to_nalu
(
&
hevc
,
config
,
sizeof
(
config
));
...
...
@@ -160,12 +162,13 @@ int64_t MP4Demuxer::seekTo(int64_t stamp_ms) {
return
stamp_ms
;
}
struct
Context
{
struct
Context
{
Context
(
MP4Demuxer
*
ptr
)
:
thiz
(
ptr
)
{}
MP4Demuxer
*
thiz
;
int
flags
;
int64_t
pts
;
int64_t
dts
;
uint32_t
track_id
;
int
flags
=
0
;
int64_t
pts
=
0
;
int64_t
dts
=
0
;
uint32_t
track_id
=
0
;
BufferRaw
::
Ptr
buffer
;
};
...
...
@@ -188,7 +191,7 @@ Frame::Ptr MP4Demuxer::readFrame(bool &keyFrame, bool &eof) {
return
ctx
->
buffer
->
data
()
+
DATA_OFFSET
;
};
Context
ctx
=
{
this
,
0
}
;
Context
ctx
(
this
)
;
auto
ret
=
mov_reader_read2
(
_mov_reader
.
get
(),
mov_onalloc
,
&
ctx
);
switch
(
ret
)
{
case
0
:
{
...
...
src/Record/MP4Muxer.cpp
查看文件 @
35791aac
...
...
@@ -221,7 +221,8 @@ bool MP4MuxerInterface::addTrack(const Track::Ptr &track) {
return
false
;
}
struct
mpeg4_avc_t
avc
=
{
0
};
struct
mpeg4_avc_t
avc
;
memset
(
&
avc
,
0
,
sizeof
(
avc
));
string
sps_pps
=
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
h264_track
->
getSps
()
+
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
h264_track
->
getPps
();
h264_annexbtomp4
(
&
avc
,
sps_pps
.
data
(),
(
int
)
sps_pps
.
size
(),
NULL
,
0
,
NULL
,
NULL
);
...
...
@@ -256,7 +257,8 @@ bool MP4MuxerInterface::addTrack(const Track::Ptr &track) {
return
false
;
}
struct
mpeg4_hevc_t
hevc
=
{
0
};
struct
mpeg4_hevc_t
hevc
;
memset
(
&
hevc
,
0
,
sizeof
(
hevc
));
string
vps_sps_pps
=
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
h265_track
->
getVps
()
+
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
h265_track
->
getSps
()
+
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
h265_track
->
getPps
();
...
...
srt/PacketQueue.cpp
查看文件 @
35791aac
...
...
@@ -237,12 +237,12 @@ std::string PacketQueue::dump() {
//////////////////// PacketRecvQueue //////////////////////////////////
PacketRecvQueue
::
PacketRecvQueue
(
uint32_t
max_size
,
uint32_t
init_seq
,
uint32_t
latency
,
uint32_t
flag
)
PacketRecvQueue
::
PacketRecvQueue
(
uint32_t
max_size
,
uint32_t
init_seq
,
uint32_t
latency
,
uint32_t
flag
)
:
_pkt_cap
(
max_size
)
,
_pkt_latency
(
latency
)
,
_pkt_expected_seq
(
init_seq
)
,
_
pkt_buf
(
max_size
)
,
_
srt_flag
(
flag
)
{}
,
_
srt_flag
(
flag
)
,
_
pkt_buf
(
max_size
)
{}
bool
PacketRecvQueue
::
TLPKTDrop
(){
return
(
_srt_flag
&
HSExtMessage
::
HS_EXT_MSG_TLPKTDROP
)
&&
(
_srt_flag
&
HSExtMessage
::
HS_EXT_MSG_TSBPDRCV
);
...
...
srt/PacketSendQueue.cpp
查看文件 @
35791aac
...
...
@@ -3,9 +3,9 @@
namespace
SRT
{
PacketSendQueue
::
PacketSendQueue
(
uint32_t
max_size
,
uint32_t
latency
,
uint32_t
flag
)
:
_
pkt_cap
(
max_size
)
,
_pkt_
latency
(
latency
)
,
_
srt_flag
(
flag
)
{}
:
_
srt_flag
(
flag
)
,
_pkt_
cap
(
max_size
)
,
_
pkt_latency
(
latency
)
{}
bool
PacketSendQueue
::
drop
(
uint32_t
num
)
{
decltype
(
_pkt_cache
.
begin
())
it
;
...
...
tests/test_rtp.cpp
查看文件 @
35791aac
...
...
@@ -37,7 +37,8 @@ static bool loadFile(const char *path){
uint64_t
timeStamp_last
=
0
;
uint16_t
len
;
char
rtp
[
0xFFFF
];
struct
sockaddr_storage
addr
=
{
0
};
struct
sockaddr_storage
addr
;
memset
(
&
addr
,
0
,
sizeof
(
addr
));
addr
.
ss_family
=
AF_INET
;
auto
sock
=
Socket
::
createSocket
();
size_t
total_size
=
0
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论