Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2015-03-03 17:22:44 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
34d6a2ece51d05917a0d04eb6a33a0bfa01e5ba4
34d6a2ec
1 parent
f619f174
for #320, support macro to disable the complex send algorithm and enable tcp no delay. 2.0.129
隐藏空白字符变更
内嵌
并排对比
正在显示
7 个修改的文件
包含
120 行增加
和
20 行删除
trunk/ide/srs_upp/init
trunk/ide/srs_upp/srs_upp.upp
trunk/src/app/srs_app_rtmp_conn.cpp
trunk/src/app/srs_app_rtmp_conn.hpp
trunk/src/core/srs_core.hpp
trunk/src/core/srs_core_performance.hpp
trunk/src/protocol/srs_rtmp_stack.cpp
trunk/ide/srs_upp/init
100644 → 100755
查看文件 @
34d6a2e
#ifndef _srs_icpp_init_stub
#define _srs_icpp_init_stub
#ifndef _srs_upp_icpp_init_stub
#define _srs_upp_icpp_init_stub
#endif
...
...
trunk/ide/srs_upp/srs_upp.upp
查看文件 @
34d6a2e
...
...
@@ -36,8 +36,8 @@ file
../../src/kernel/srs_kernel_log.cpp,
../../src/kernel/srs_kernel_mp3.hpp,
../../src/kernel/srs_kernel_mp3.cpp,
../../src/kernel/srs_rtsp_stack.hpp,
../../src/kernel/srs_rtsp_stack.cpp,
../../src/kernel/srs_rtsp_stack.hpp,
../../src/kernel/srs_rtsp_stack.cpp,
../../src/kernel/srs_kernel_stream.hpp,
../../src/kernel/srs_kernel_stream.cpp,
../../src/kernel/srs_kernel_ts.cpp,
...
...
@@ -45,8 +45,8 @@ file
../../src/kernel/srs_kernel_utility.hpp,
../../src/kernel/srs_kernel_utility.cpp,
protocol readonly separator,
../../src/protocol/srs_raw_avc.hpp,
../../src/protocol/srs_raw_avc.cpp,
../../src/protocol/srs_raw_avc.hpp,
../../src/protocol/srs_raw_avc.cpp,
../../src/protocol/srs_rtmp_amf0.hpp,
../../src/protocol/srs_rtmp_amf0.cpp,
../../src/protocol/srs_rtmp_buffer.hpp,
...
...
@@ -102,8 +102,8 @@ file
../../src/app/srs_app_json.cpp,
../../src/app/srs_app_kbps.hpp,
../../src/app/srs_app_kbps.cpp,
../../src/app/srs_app_listener.hpp,
../../src/app/srs_app_listener.cpp,
../../src/app/srs_app_listener.hpp,
../../src/app/srs_app_listener.cpp,
../../src/app/srs_app_log.hpp,
../../src/app/srs_app_log.cpp,
../../src/app/srs_app_mpegts_udp.hpp,
...
...
@@ -116,8 +116,8 @@ file
../../src/app/srs_app_reload.cpp,
../../src/app/srs_app_rtmp_conn.hpp,
../../src/app/srs_app_rtmp_conn.cpp,
../../src/app/srs_app_rtsp.hpp,
../../src/app/srs_app_rtsp.cpp,
../../src/app/srs_app_rtsp.hpp,
../../src/app/srs_app_rtsp.cpp,
../../src/app/srs_app_pithy_print.hpp,
../../src/app/srs_app_pithy_print.cpp,
../../src/app/srs_app_security.hpp,
...
...
trunk/src/app/srs_app_rtmp_conn.cpp
查看文件 @
34d6a2e
...
...
@@ -27,6 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
using
namespace
std
;
...
...
@@ -624,6 +625,9 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe
mw_enabled
=
true
;
change_mw_sleep
(
_srs_config
->
get_mw_sleep_ms
(
req
->
vhost
));
// set the sock options.
play_set_sock_options
();
while
(
true
)
{
// collect elapse for pithy print.
pprint
->
elapse
();
...
...
@@ -1089,7 +1093,7 @@ void SrsRtmpConn::change_mw_sleep(int sleep_ms)
socklen_t
sock_buf_size
=
sizeof
(
int
);
getsockopt
(
fd
,
SOL_SOCKET
,
SO_SNDBUF
,
&
onb_sbuf
,
&
sock_buf_size
);
#ifdef SRS_PERF_MW_SO_SNDBUF
#ifdef SRS_PERF_MW_SO_SNDBUF
// the bytes:
// 4KB=4096, 8KB=8192, 16KB=16384, 32KB=32768, 64KB=65536,
// 128KB=131072, 256KB=262144, 512KB=524288
...
...
@@ -1123,6 +1127,29 @@ void SrsRtmpConn::change_mw_sleep(int sleep_ms)
mw_sleep
=
sleep_ms
;
}
void
SrsRtmpConn
::
play_set_sock_options
()
{
int
fd
=
st_netfd_fileno
(
stfd
);
#ifdef SRS_PERF_TCP_NODELAY
if
(
true
)
{
socklen_t
nb_v
=
sizeof
(
int
);
int
ov
=
0
;
getsockopt
(
fd
,
IPPROTO_TCP
,
TCP_NODELAY
,
&
ov
,
&
nb_v
);
int
v
=
1
;
// set the socket send buffer when required larger buffer
if
(
setsockopt
(
fd
,
IPPROTO_TCP
,
TCP_NODELAY
,
&
v
,
nb_v
)
<
0
)
{
srs_warn
(
"set sock TCP_NODELAY=%d failed."
,
v
);
}
getsockopt
(
fd
,
IPPROTO_TCP
,
TCP_NODELAY
,
&
v
,
&
nb_v
);
srs_trace
(
"set TCP_NODELAY %d=>%d"
,
ov
,
v
);
}
#endif
}
int
SrsRtmpConn
::
check_edge_token_traverse_auth
()
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/app/srs_app_rtmp_conn.hpp
查看文件 @
34d6a2e
...
...
@@ -111,6 +111,7 @@ private:
virtual
int
process_publish_message
(
SrsSource
*
source
,
SrsCommonMessage
*
msg
,
bool
vhost_is_edge
);
virtual
int
process_play_control_msg
(
SrsConsumer
*
consumer
,
SrsCommonMessage
*
msg
);
virtual
void
change_mw_sleep
(
int
sleep_ms
);
virtual
void
play_set_sock_options
();
private
:
virtual
int
check_edge_token_traverse_auth
();
virtual
int
connect_server
(
int
origin_index
,
st_netfd_t
*
pstsock
);
...
...
trunk/src/core/srs_core.hpp
查看文件 @
34d6a2e
...
...
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_REVISION 12
8
#define VERSION_REVISION 12
9
// server info.
#define RTMP_SIG_SRS_KEY "SRS"
...
...
trunk/src/core/srs_core_performance.hpp
查看文件 @
34d6a2e
...
...
@@ -108,7 +108,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* whether set the socket send buffer size.
* @see https://github.com/winlinvip/simple-rtmp-server/issues/251
*/
#undef SRS_PERF_MW_SO_SNDBUF
#define SRS_PERF_MW_SO_SNDBUF
/**
* whether set the socket recv buffer size.
* @see https://github.com/winlinvip/simple-rtmp-server/issues/251
...
...
@@ -154,5 +155,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// in seconds, the live queue length.
#define SRS_PERF_PLAY_QUEUE 30
/**
* whether always use complex send algorithm.
* for some network does not support the complex send,
* @see https://github.com/winlinvip/simple-rtmp-server/issues/320
*/
//#undef SRS_PERF_COMPLEX_SEND
#define SRS_PERF_COMPLEX_SEND
/**
* whether enable the TCP_NODELAY
* user maybe need send small tcp packet for some network.
* @see https://github.com/winlinvip/simple-rtmp-server/issues/320
*/
//#define SRS_PERF_TCP_NODELAY
#undef SRS_PERF_TCP_NODELAY
#endif
...
...
trunk/src/protocol/srs_rtmp_stack.cpp
查看文件 @
34d6a2e
...
...
@@ -762,8 +762,9 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
{
int
ret
=
ERROR_SUCCESS
;
#ifdef SRS_PERF_COMPLEX_SEND
int
iov_index
=
0
;
iovec
*
iov
=
out_iovs
+
iov_index
;
iovec
*
iov
s
=
out_iovs
+
iov_index
;
int
c0c3_cache_index
=
0
;
char
*
c0c3_cache
=
out_c0c3_caches
+
c0c3_cache_index
;
...
...
@@ -796,13 +797,13 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
srs_assert
(
nbh
>
0
);
// header iov
iov
[
0
].
iov_base
=
c0c3_cache
;
iov
[
0
].
iov_len
=
nbh
;
iovs
[
0
].
iov_base
=
c0c3_cache
;
iovs
[
0
].
iov_len
=
nbh
;
// payload iov
int
payload_size
=
srs_min
(
out_chunk_size
,
pend
-
p
);
iov
[
1
].
iov_base
=
p
;
iov
[
1
].
iov_len
=
payload_size
;
iovs
[
1
].
iov_base
=
p
;
iovs
[
1
].
iov_len
=
payload_size
;
// consume sendout bytes.
p
+=
payload_size
;
...
...
@@ -822,7 +823,7 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
// to next pair of iovs
iov_index
+=
2
;
iov
=
out_iovs
+
iov_index
;
iov
s
=
out_iovs
+
iov_index
;
// to next c0c3 header cache
c0c3_cache_index
+=
nbh
;
...
...
@@ -849,7 +850,7 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
// reset caches, while these cache ensure
// atleast we can sendout a chunk.
iov_index
=
0
;
iov
=
out_iovs
+
iov_index
;
iov
s
=
out_iovs
+
iov_index
;
c0c3_cache_index
=
0
;
c0c3_cache
=
out_c0c3_caches
+
c0c3_cache_index
;
...
...
@@ -866,6 +867,61 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
nb_msgs
,
iov_index
,
SRS_PERF_MW_MSGS
,
nb_out_iovs
);
return
do_iovs_send
(
out_iovs
,
iov_index
);
#else
// try to send use the c0c3 header cache,
// if cache is consumed, try another loop.
for
(
int
i
=
0
;
i
<
nb_msgs
;
i
++
)
{
SrsSharedPtrMessage
*
msg
=
msgs
[
i
];
if
(
!
msg
)
{
continue
;
}
// ignore empty message.
if
(
!
msg
->
payload
||
msg
->
size
<=
0
)
{
srs_info
(
"ignore empty message."
);
continue
;
}
// p set to current write position,
// it's ok when payload is NULL and size is 0.
char
*
p
=
msg
->
payload
;
char
*
pend
=
msg
->
payload
+
msg
->
size
;
// always write the header event payload is empty.
while
(
p
<
pend
)
{
// for simple send, send each chunk one by one
iovec
*
iovs
=
out_iovs
;
char
*
c0c3_cache
=
out_c0c3_caches
;
int
nb_cache
=
SRS_CONSTS_C0C3_HEADERS_MAX
;
// always has header
int
nbh
=
msg
->
chunk_header
(
c0c3_cache
,
nb_cache
,
p
==
msg
->
payload
);
srs_assert
(
nbh
>
0
);
// header iov
iovs
[
0
].
iov_base
=
c0c3_cache
;
iovs
[
0
].
iov_len
=
nbh
;
// payload iov
int
payload_size
=
srs_min
(
out_chunk_size
,
pend
-
p
);
iovs
[
1
].
iov_base
=
p
;
iovs
[
1
].
iov_len
=
payload_size
;
// consume sendout bytes.
p
+=
payload_size
;
if
((
ret
=
skt
->
writev
(
iovs
,
2
,
NULL
))
!=
ERROR_SUCCESS
)
{
if
(
!
srs_is_client_gracefully_close
(
ret
))
{
srs_error
(
"send packet with writev failed. ret=%d"
,
ret
);
}
return
ret
;
}
}
}
return
ret
;
#endif
}
int
SrsProtocol
::
do_iovs_send
(
iovec
*
iovs
,
int
size
)
...
...
请
注册
或
登录
后发表评论