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
a97b7ce7
Commit
a97b7ce7
authored
7 years ago
by
771730766@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化http服务器性能
parent
ddd4f57f
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
42 行增加
和
12 行删除
+42
-12
src/Http/HttpSession.cpp
+40
-11
src/Http/HttpSession.h
+1
-0
tests/test_rtmpPusher.cpp
+1
-1
没有找到文件。
src/Http/HttpSession.cpp
查看文件 @
a97b7ce7
...
...
@@ -355,7 +355,7 @@ inline HttpSession::HttpCode HttpSession::Handle_Req_GET() {
//send completed!
//FatalL << "send completed!";
if
(
iRead
>
0
)
{
strongSelf
->
s
end
(
pacSendBuf
.
get
(),
iRead
);
strongSelf
->
s
ock
->
send
(
pacSendBuf
.
get
(),
iRead
,
SOCKET_DEFAULE_FLAGS
|
FLAG_MORE
);
}
if
(
bClose
)
{
strongSelf
->
shutdown
();
...
...
@@ -363,7 +363,7 @@ inline HttpSession::HttpCode HttpSession::Handle_Req_GET() {
return
false
;
}
int
iSent
=
strongSelf
->
send
(
pacSendBuf
.
get
(),
iRead
);
int
iSent
=
strongSelf
->
sock
->
send
(
pacSendBuf
.
get
(),
iRead
,
SOCKET_DEFAULE_FLAGS
|
FLAG_MORE
);
if
(
iSent
==
-
1
)
{
//send error
//FatalL << "send error";
...
...
@@ -378,6 +378,8 @@ inline HttpSession::HttpCode HttpSession::Handle_Req_GET() {
}
return
false
;
};
//关闭tcp_nodelay ,优化性能
SockUtil
::
setNoDelay
(
sock
->
rawFD
(),
false
);
onFlush
();
sock
->
setOnFlush
(
onFlush
);
return
Http_success
;
...
...
@@ -594,7 +596,7 @@ void HttpSession::onSendMedia(const RtmpPacket::Ptr &pkt) {
CLEAR_ARR
(
m_aui32FirstStamp
);
modifiedStamp
=
0
;
}
sendRtmp
(
pkt
->
typeId
,
pkt
->
strBuf
,
modifiedStamp
);
sendRtmp
(
pkt
,
modifiedStamp
);
}
#if defined(_WIN32)
...
...
@@ -614,22 +616,49 @@ public:
#pragma pack(pop)
#endif // defined(_WIN32)
void
HttpSession
::
sendRtmp
(
uint8_t
ui8Type
,
const
std
::
string
&
strBuf
,
uint32_t
ui32TimeStamp
)
{
class
BufferRtmp
:
public
Socket
::
Buffer
{
public
:
typedef
std
::
shared_ptr
<
BufferRtmp
>
Ptr
;
BufferRtmp
(
const
RtmpPacket
::
Ptr
&
pkt
)
:
_rtmp
(
pkt
){}
virtual
~
BufferRtmp
(){}
char
*
data
()
override
{
return
(
char
*
)
_rtmp
->
strBuf
.
data
();
}
uint32_t
size
()
const
override
{
return
_rtmp
->
strBuf
.
size
();
}
private
:
RtmpPacket
::
Ptr
_rtmp
;
};
void
HttpSession
::
sendRtmp
(
const
RtmpPacket
::
Ptr
&
pkt
,
uint32_t
ui32TimeStamp
)
{
auto
size
=
htonl
(
m_previousTagSize
);
send
((
char
*
)
&
size
,
4
);
//send PreviousTagSize
RtmpTagHeader
header
;
header
.
type
=
ui8Type
;
set_be24
(
header
.
data_size
,
strBuf
.
size
());
header
.
type
=
pkt
->
typeId
;
set_be24
(
header
.
data_size
,
pkt
->
strBuf
.
size
());
header
.
timestamp_ex
=
(
uint8_t
)
((
ui32TimeStamp
>>
24
)
&
0xff
);
set_be24
(
header
.
timestamp
,
ui32TimeStamp
&
0xFFFFFF
);
send
((
char
*
)
&
header
,
sizeof
(
header
));
//send tag header
send
(
st
rBuf
);
//send tag data
m_previousTagSize
+=
(
strBuf
.
size
()
+
sizeof
(
header
)
+
4
);
send
(
st
d
::
make_shared
<
BufferRtmp
>
(
pkt
)
);
//send tag data
m_previousTagSize
+=
(
pkt
->
strBuf
.
size
()
+
sizeof
(
header
)
+
4
);
m_ticker
.
resetTime
();
}
void
HttpSession
::
sendRtmp
(
uint8_t
ui8Type
,
const
std
::
string
&
strBuf
,
uint32_t
ui32TimeStamp
)
{
auto
size
=
htonl
(
m_previousTagSize
);
send
((
char
*
)
&
size
,
4
);
//send PreviousTagSize
RtmpTagHeader
header
;
header
.
type
=
ui8Type
;
set_be24
(
header
.
data_size
,
strBuf
.
size
());
header
.
timestamp_ex
=
(
uint8_t
)
((
ui32TimeStamp
>>
24
)
&
0xff
);
set_be24
(
header
.
timestamp
,
ui32TimeStamp
&
0xFFFFFF
);
send
((
char
*
)
&
header
,
sizeof
(
header
));
//send tag header
send
(
strBuf
);
//send tag data
m_previousTagSize
+=
(
strBuf
.
size
()
+
sizeof
(
header
)
+
4
);
m_ticker
.
resetTime
();
}
}
/* namespace Http */
}
/* namespace ZL */
This diff is collapsed.
Click to expand it.
src/Http/HttpSession.h
查看文件 @
a97b7ce7
...
...
@@ -78,6 +78,7 @@ private:
uint32_t
m_previousTagSize
=
0
;
RingBuffer
<
RtmpPacket
::
Ptr
>::
RingReader
::
Ptr
m_pRingReader
;
void
onSendMedia
(
const
RtmpPacket
::
Ptr
&
pkt
);
void
sendRtmp
(
const
RtmpPacket
::
Ptr
&
pkt
,
uint32_t
ui32TimeStamp
);
void
sendRtmp
(
uint8_t
ui8Type
,
const
std
::
string
&
strBuf
,
uint32_t
ui32TimeStamp
);
inline
HttpCode
parserHttpReq
(
const
string
&
);
...
...
This diff is collapsed.
Click to expand it.
tests/test_rtmpPusher.cpp
查看文件 @
a97b7ce7
...
...
@@ -121,7 +121,7 @@ int domain(int argc, const char *argv[]) {
int
main
(
int
argc
,
char
*
argv
[]){
const
char
*
argList
[]
=
{
argv
[
0
],
"rtmp://live.hkstv.hk.lxdns.com/live/hks"
,
"rtmp://jizan.iok.la/live/test"
};
const
char
*
argList
[]
=
{
argv
[
0
],
"rtmp://live.hkstv.hk.lxdns.com/live/hks"
,
argv
[
1
]
};
return
domain
(
3
,
argList
);
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论