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
8c50aa6c
Commit
8c50aa6c
authored
Jan 30, 2018
by
771730766@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化性能
parent
28b8e8e0
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
46 行增加
和
26 行删除
+46
-26
CMakeLists.txt
+8
-0
src/Rtmp/RtmpPlayer.h
+3
-4
src/Rtmp/RtmpProtocol.cpp
+19
-8
src/Rtmp/RtmpProtocol.h
+4
-4
src/Rtmp/RtmpPusher.cpp
+2
-2
src/Rtmp/RtmpPusher.h
+2
-2
src/Rtmp/RtmpSession.cpp
+4
-3
src/Rtmp/RtmpSession.h
+2
-2
src/Rtsp/RtspSession.cpp
+1
-0
src/Rtsp/RtspSession.h
+1
-1
没有找到文件。
CMakeLists.txt
查看文件 @
8c50aa6c
...
@@ -87,6 +87,14 @@ if(ZLTOOLKIT_FOUND)
...
@@ -87,6 +87,14 @@ if(ZLTOOLKIT_FOUND)
list
(
APPEND LINK_LIB_LIST
${
ZLTOOLKIT_LIBRARIES
}
)
list
(
APPEND LINK_LIB_LIST
${
ZLTOOLKIT_LIBRARIES
}
)
endif
()
endif
()
#查找ZLToolKit是否安装
find_package
(
JEMALLOC QUIET
)
if
(
JEMALLOC_FOUND
)
message
(
STATUS
"找到JEMALLOC库:
\"
${
JEMALLOC_INCLUDE_DIR
}
\"
"
)
include_directories
(
${
JEMALLOC_INCLUDE_DIR
}
)
list
(
APPEND LINK_LIB_LIST
${
JEMALLOC_LIBRARIES
}
)
endif
()
#打印库文件
#打印库文件
message
(
STATUS
"将链接依赖库:
${
LINK_LIB_LIST
}
"
)
message
(
STATUS
"将链接依赖库:
${
LINK_LIB_LIST
}
"
)
#开启RTSP/RTMP之间的互相转换,开启HLS
#开启RTSP/RTMP之间的互相转换,开启HLS
...
...
src/Rtmp/RtmpPlayer.h
查看文件 @
8c50aa6c
...
@@ -108,10 +108,9 @@ private:
...
@@ -108,10 +108,9 @@ private:
void
onSendRawData
(
const
char
*
pcRawData
,
int
iSize
)
override
{
void
onSendRawData
(
const
char
*
pcRawData
,
int
iSize
)
override
{
send
(
pcRawData
,
iSize
);
send
(
pcRawData
,
iSize
);
}
}
void
onSendRawData
(
string
&&
strData
)
override
{
void
onSendRawData
(
const
Socket
::
Buffer
::
Ptr
&
buffer
,
int
flags
)
override
{
send
(
std
::
move
(
strData
));
m_pSock
->
send
(
buffer
,
flags
);
}
}
template
<
typename
FUN
>
template
<
typename
FUN
>
inline
void
addOnResultCB
(
const
FUN
&
fun
)
{
inline
void
addOnResultCB
(
const
FUN
&
fun
)
{
...
...
src/Rtmp/RtmpProtocol.cpp
查看文件 @
8c50aa6c
...
@@ -187,7 +187,7 @@ void RtmpProtocol::sendRequest(int iCmd, const string& str) {
...
@@ -187,7 +187,7 @@ void RtmpProtocol::sendRequest(int iCmd, const string& str) {
}
}
void
RtmpProtocol
::
sendRtmp
(
uint8_t
ui8Type
,
uint32_t
ui32StreamId
,
void
RtmpProtocol
::
sendRtmp
(
uint8_t
ui8Type
,
uint32_t
ui32StreamId
,
const
std
::
string
&
strBuf
,
uint32_t
ui32TimeStamp
,
int
iChunkId
)
{
const
std
::
string
&
strBuf
,
uint32_t
ui32TimeStamp
,
int
iChunkId
,
bool
msg_more
)
{
if
(
iChunkId
<
2
||
iChunkId
>
63
)
{
if
(
iChunkId
<
2
||
iChunkId
>
63
)
{
auto
strErr
=
StrPrinter
<<
"不支持发送该类型的块流 ID:"
<<
iChunkId
<<
endl
;
auto
strErr
=
StrPrinter
<<
"不支持发送该类型的块流 ID:"
<<
iChunkId
<<
endl
;
throw
std
::
runtime_error
(
strErr
);
throw
std
::
runtime_error
(
strErr
);
...
@@ -200,8 +200,15 @@ void RtmpProtocol::sendRtmp(uint8_t ui8Type, uint32_t ui32StreamId,
...
@@ -200,8 +200,15 @@ void RtmpProtocol::sendRtmp(uint8_t ui8Type, uint32_t ui32StreamId,
set_be24
(
header
.
timeStamp
,
bExtStamp
?
0xFFFFFF
:
ui32TimeStamp
);
set_be24
(
header
.
timeStamp
,
bExtStamp
?
0xFFFFFF
:
ui32TimeStamp
);
set_be24
(
header
.
bodySize
,
strBuf
.
size
());
set_be24
(
header
.
bodySize
,
strBuf
.
size
());
set_le32
(
header
.
streamId
,
ui32StreamId
);
set_le32
(
header
.
streamId
,
ui32StreamId
);
std
::
string
strSend
;
strSend
.
append
((
char
*
)
&
header
,
sizeof
(
header
));
//估算rtmp包数据大小
uint32_t
capacity
=
((
bExtStamp
?
5
:
1
)
*
((
strBuf
.
size
()
/
m_iChunkLenOut
)))
+
strBuf
.
size
()
+
sizeof
(
header
)
+
32
;
uint32_t
totalSize
=
0
;
Socket
::
BufferRaw
::
Ptr
buffer
=
m_bufferPool
.
obtain
();
buffer
->
setCapacity
(
capacity
);
memcpy
(
buffer
->
data
()
+
totalSize
,(
char
*
)
&
header
,
sizeof
(
header
));
totalSize
+=
sizeof
(
header
);
char
acExtStamp
[
4
];
char
acExtStamp
[
4
];
if
(
bExtStamp
)
{
if
(
bExtStamp
)
{
//扩展时间戳
//扩展时间戳
...
@@ -211,18 +218,22 @@ void RtmpProtocol::sendRtmp(uint8_t ui8Type, uint32_t ui32StreamId,
...
@@ -211,18 +218,22 @@ void RtmpProtocol::sendRtmp(uint8_t ui8Type, uint32_t ui32StreamId,
while
(
pos
<
strBuf
.
size
())
{
while
(
pos
<
strBuf
.
size
())
{
if
(
pos
)
{
if
(
pos
)
{
uint8_t
flags
=
(
iChunkId
&
0x3f
)
|
(
3
<<
6
);
uint8_t
flags
=
(
iChunkId
&
0x3f
)
|
(
3
<<
6
);
strSend
+=
char
(
flags
);
memcpy
(
buffer
->
data
()
+
totalSize
,
&
flags
,
1
);
totalSize
+=
1
;
}
}
if
(
bExtStamp
)
{
if
(
bExtStamp
)
{
//扩展时间戳
//扩展时间戳
strSend
.
append
(
acExtStamp
,
4
);
memcpy
(
buffer
->
data
()
+
totalSize
,
acExtStamp
,
4
);
totalSize
+=
4
;
}
}
size_t
chunk
=
min
(
m_iChunkLenOut
,
strBuf
.
size
()
-
pos
);
size_t
chunk
=
min
(
m_iChunkLenOut
,
strBuf
.
size
()
-
pos
);
strSend
.
append
(
strBuf
,
pos
,
chunk
);
memcpy
(
buffer
->
data
()
+
totalSize
,
strBuf
.
data
()
+
pos
,
chunk
);
totalSize
+=
chunk
;
pos
+=
chunk
;
pos
+=
chunk
;
}
}
onSendRawData
(
std
::
move
(
strSend
));
buffer
->
setSize
(
totalSize
);
m_ui32ByteSent
+=
strSend
.
size
();
onSendRawData
(
buffer
,
msg_more
?
SOCKET_DEFAULE_FLAGS
:
(
SOCKET_DEFAULE_FLAGS
|
FLAG_MORE
));
m_ui32ByteSent
+=
totalSize
;
if
(
m_ui32WinSize
>
0
&&
m_ui32ByteSent
-
m_ui32LastSent
>=
m_ui32WinSize
)
{
if
(
m_ui32WinSize
>
0
&&
m_ui32ByteSent
-
m_ui32LastSent
>=
m_ui32WinSize
)
{
m_ui32LastSent
=
m_ui32ByteSent
;
m_ui32LastSent
=
m_ui32ByteSent
;
sendAcknowledgement
(
m_ui32ByteSent
);
sendAcknowledgement
(
m_ui32ByteSent
);
...
...
src/Rtmp/RtmpProtocol.h
查看文件 @
8c50aa6c
...
@@ -36,6 +36,7 @@
...
@@ -36,6 +36,7 @@
#include "Util/logger.h"
#include "Util/logger.h"
#include "Util/TimeTicker.h"
#include "Util/TimeTicker.h"
#include "Network/Socket.h"
#include "Network/Socket.h"
#include "Util/ResourcePool.h"
using
namespace
std
;
using
namespace
std
;
using
namespace
ZL
::
Util
;
using
namespace
ZL
::
Util
;
...
@@ -54,9 +55,7 @@ public:
...
@@ -54,9 +55,7 @@ public:
void
reset
();
void
reset
();
protected
:
protected
:
virtual
void
onSendRawData
(
const
char
*
pcRawData
,
int
iSize
)
=
0
;
virtual
void
onSendRawData
(
const
char
*
pcRawData
,
int
iSize
)
=
0
;
virtual
void
onSendRawData
(
string
&&
strData
)
{
virtual
void
onSendRawData
(
const
Socket
::
Buffer
::
Ptr
&
buffer
,
int
flags
)
=
0
;
onSendRawData
(
strData
.
data
(),
strData
.
size
());
};
virtual
void
onRtmpChunk
(
RtmpPacket
&
chunkData
)
=
0
;
virtual
void
onRtmpChunk
(
RtmpPacket
&
chunkData
)
=
0
;
...
@@ -79,13 +78,14 @@ protected:
...
@@ -79,13 +78,14 @@ protected:
void
sendInvoke
(
const
string
&
strCmd
,
const
AMFValue
&
val
);
void
sendInvoke
(
const
string
&
strCmd
,
const
AMFValue
&
val
);
void
sendRequest
(
int
iCmd
,
const
string
&
str
);
void
sendRequest
(
int
iCmd
,
const
string
&
str
);
void
sendResponse
(
int
iType
,
const
string
&
str
);
void
sendResponse
(
int
iType
,
const
string
&
str
);
void
sendRtmp
(
uint8_t
ui8Type
,
uint32_t
ui32StreamId
,
const
std
::
string
&
strBuf
,
uint32_t
ui32TimeStamp
,
int
iChunkID
);
void
sendRtmp
(
uint8_t
ui8Type
,
uint32_t
ui32StreamId
,
const
std
::
string
&
strBuf
,
uint32_t
ui32TimeStamp
,
int
iChunkID
,
bool
msg_more
=
false
);
protected
:
protected
:
int
m_iReqID
=
0
;
int
m_iReqID
=
0
;
uint32_t
m_ui32StreamId
=
STREAM_CONTROL
;
uint32_t
m_ui32StreamId
=
STREAM_CONTROL
;
int
m_iNowStreamID
=
0
;
int
m_iNowStreamID
=
0
;
int
m_iNowChunkID
=
0
;
int
m_iNowChunkID
=
0
;
bool
m_bDataStarted
=
false
;
bool
m_bDataStarted
=
false
;
ResourcePool
<
Socket
::
BufferRaw
,
MAX_SEND_PKT
>
m_bufferPool
;
private
:
private
:
void
handle_S0S1S2
(
const
function
<
void
()
>
&
cb
);
void
handle_S0S1S2
(
const
function
<
void
()
>
&
cb
);
void
handle_C0C1
();
void
handle_C0C1
();
...
...
src/Rtmp/RtmpPusher.cpp
查看文件 @
8c50aa6c
...
@@ -203,7 +203,7 @@ inline void RtmpPusher::send_metaData(){
...
@@ -203,7 +203,7 @@ inline void RtmpPusher::send_metaData(){
sendRequest
(
MSG_DATA
,
enc
.
data
());
sendRequest
(
MSG_DATA
,
enc
.
data
());
src
->
getConfigFrame
([
&
](
const
RtmpPacket
::
Ptr
&
pkt
){
src
->
getConfigFrame
([
&
](
const
RtmpPacket
::
Ptr
&
pkt
){
sendRtmp
(
pkt
->
typeId
,
m_ui32StreamId
,
pkt
->
strBuf
,
pkt
->
timeStamp
,
pkt
->
chunkId
);
sendRtmp
(
pkt
->
typeId
,
m_ui32StreamId
,
pkt
->
strBuf
,
pkt
->
timeStamp
,
pkt
->
chunkId
,
true
);
});
});
m_pRtmpReader
=
src
->
getRing
()
->
attach
();
m_pRtmpReader
=
src
->
getRing
()
->
attach
();
...
@@ -213,7 +213,7 @@ inline void RtmpPusher::send_metaData(){
...
@@ -213,7 +213,7 @@ inline void RtmpPusher::send_metaData(){
if
(
!
strongSelf
)
{
if
(
!
strongSelf
)
{
return
;
return
;
}
}
strongSelf
->
sendRtmp
(
pkt
->
typeId
,
strongSelf
->
m_ui32StreamId
,
pkt
->
strBuf
,
pkt
->
timeStamp
,
pkt
->
chunkId
);
strongSelf
->
sendRtmp
(
pkt
->
typeId
,
strongSelf
->
m_ui32StreamId
,
pkt
->
strBuf
,
pkt
->
timeStamp
,
pkt
->
chunkId
,
true
);
});
});
m_pRtmpReader
->
setDetachCB
([
weakSelf
](){
m_pRtmpReader
->
setDetachCB
([
weakSelf
](){
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
...
...
src/Rtmp/RtmpPusher.h
查看文件 @
8c50aa6c
...
@@ -65,8 +65,8 @@ protected:
...
@@ -65,8 +65,8 @@ protected:
void
onSendRawData
(
const
char
*
pcRawData
,
int
iSize
)
override
{
void
onSendRawData
(
const
char
*
pcRawData
,
int
iSize
)
override
{
send
(
pcRawData
,
iSize
);
send
(
pcRawData
,
iSize
);
}
}
void
onSendRawData
(
string
&&
strData
)
override
{
void
onSendRawData
(
const
Socket
::
Buffer
::
Ptr
&
buffer
,
int
flags
)
override
{
send
(
std
::
move
(
strData
)
);
m_pSock
->
send
(
buffer
,
flags
);
}
}
private
:
private
:
void
init
(
const
RtmpMediaSource
::
Ptr
&
src
);
void
init
(
const
RtmpMediaSource
::
Ptr
&
src
);
...
...
src/Rtmp/RtmpSession.cpp
查看文件 @
8c50aa6c
...
@@ -91,7 +91,7 @@ void RtmpSession::onCmd_connect(AMFDecoder &dec) {
...
@@ -91,7 +91,7 @@ void RtmpSession::onCmd_connect(AMFDecoder &dec) {
amfVer
=
objectEncoding
.
as_number
();
amfVer
=
objectEncoding
.
as_number
();
}
}
///////////set chunk size////////////////
///////////set chunk size////////////////
sendChunkSize
(
4096
);
sendChunkSize
(
60000
);
////////////window Acknowledgement size/////
////////////window Acknowledgement size/////
sendAcknowledgementSize
(
5000000
);
sendAcknowledgementSize
(
5000000
);
///////////set peerBandwidth////////////////
///////////set peerBandwidth////////////////
...
@@ -214,7 +214,8 @@ void RtmpSession::doPlay(){
...
@@ -214,7 +214,8 @@ void RtmpSession::doPlay(){
m_pRingReader
=
src
->
getRing
()
->
attach
();
m_pRingReader
=
src
->
getRing
()
->
attach
();
weak_ptr
<
RtmpSession
>
weakSelf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
weak_ptr
<
RtmpSession
>
weakSelf
=
dynamic_pointer_cast
<
RtmpSession
>
(
shared_from_this
());
m_pRingReader
->
setReadCB
([
weakSelf
](
const
RtmpPacket
::
Ptr
&
pkt
){
SockUtil
::
setNoDelay
(
sock
->
rawFD
(),
false
);
m_pRingReader
->
setReadCB
([
weakSelf
](
const
RtmpPacket
::
Ptr
&
pkt
){
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
if
(
!
strongSelf
)
{
return
;
return
;
...
@@ -377,7 +378,7 @@ void RtmpSession::onSendMedia(const RtmpPacket::Ptr &pkt) {
...
@@ -377,7 +378,7 @@ void RtmpSession::onSendMedia(const RtmpPacket::Ptr &pkt) {
CLEAR_ARR
(
m_aui32FirstStamp
);
CLEAR_ARR
(
m_aui32FirstStamp
);
modifiedStamp
=
0
;
modifiedStamp
=
0
;
}
}
sendRtmp
(
pkt
->
typeId
,
pkt
->
streamId
,
pkt
->
strBuf
,
modifiedStamp
,
pkt
->
chunkId
);
sendRtmp
(
pkt
->
typeId
,
pkt
->
streamId
,
pkt
->
strBuf
,
modifiedStamp
,
pkt
->
chunkId
,
true
);
}
}
}
/* namespace Rtmp */
}
/* namespace Rtmp */
...
...
src/Rtmp/RtmpSession.h
查看文件 @
8c50aa6c
...
@@ -84,8 +84,8 @@ private:
...
@@ -84,8 +84,8 @@ private:
void
onSendRawData
(
const
char
*
pcRawData
,
int
iSize
)
override
{
void
onSendRawData
(
const
char
*
pcRawData
,
int
iSize
)
override
{
send
(
pcRawData
,
iSize
);
send
(
pcRawData
,
iSize
);
}
}
void
onSendRawData
(
string
&&
strData
)
override
{
void
onSendRawData
(
const
Socket
::
Buffer
::
Ptr
&
buffer
,
int
flags
)
override
{
s
end
(
std
::
move
(
strData
)
);
s
ock
->
send
(
buffer
,
flags
);
}
}
void
onRtmpChunk
(
RtmpPacket
&
chunkData
)
override
;
void
onRtmpChunk
(
RtmpPacket
&
chunkData
)
override
;
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
8c50aa6c
...
@@ -654,6 +654,7 @@ bool RtspSession::handleReq_Play() {
...
@@ -654,6 +654,7 @@ bool RtspSession::handleReq_Play() {
if
(
m_pRtpReader
){
if
(
m_pRtpReader
){
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
SockUtil
::
setNoDelay
(
m_pSender
->
rawFD
(),
false
);
m_pRtpReader
->
setReadCB
([
weakSelf
](
const
RtpPacket
::
Ptr
&
pack
)
{
m_pRtpReader
->
setReadCB
([
weakSelf
](
const
RtpPacket
::
Ptr
&
pack
)
{
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
if
(
!
strongSelf
)
{
...
...
src/Rtsp/RtspSession.h
查看文件 @
8c50aa6c
...
@@ -92,7 +92,7 @@ private:
...
@@ -92,7 +92,7 @@ private:
return
m_pSender
->
send
(
pcBuf
,
iSize
);
return
m_pSender
->
send
(
pcBuf
,
iSize
);
}
}
int
send
(
const
Socket
::
Buffer
::
Ptr
&
pkt
){
int
send
(
const
Socket
::
Buffer
::
Ptr
&
pkt
){
return
m_pSender
->
send
(
pkt
);
return
m_pSender
->
send
(
pkt
,
SOCKET_DEFAULE_FLAGS
|
FLAG_MORE
);
}
}
void
shutdown
()
override
;
void
shutdown
()
override
;
bool
handleReq_Options
();
//处理options方法
bool
handleReq_Options
();
//处理options方法
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论