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
2014-12-06 00:59:10 +0800
1
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d073adde58735b49c91390c0d27a60003d539393
d073adde
1 parent
de993b64
for bug #251, somhc(session-oriented message-header cache). 2.0.61
显示空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
55 行增加
和
7 行删除
trunk/src/core/srs_core.hpp
trunk/src/rtmp/srs_protocol_stack.cpp
trunk/src/rtmp/srs_protocol_stack.hpp
trunk/src/core/srs_core.hpp
查看文件 @
d073add
...
...
@@ -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 6
0
#define VERSION_REVISION 6
1
// server info.
#define RTMP_SIG_SRS_KEY "SRS"
#define RTMP_SIG_SRS_ROLE "origin/edge server"
...
...
trunk/src/rtmp/srs_protocol_stack.cpp
查看文件 @
d073add
...
...
@@ -729,6 +729,13 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
int
c0c3_cache_index
=
0
;
char
*
c0c3_cache
=
out_c0c3_caches
+
c0c3_cache_index
;
// the somc(session-oriented message-header cache),
// many message header are same, use cache.
// @see https://github.com/winlinvip/simple-rtmp-server/issues/251
SrsMessageHeader
*
somhc
=
NULL
;
char
*
somhc_bytes
=
NULL
;
int
nb_somhc_bytes
=
0
;
// try to send use the c0c3 header cache,
// if cache is consumed, try another loop.
for
(
int
i
=
0
;
i
<
nb_msgs
;
i
++
)
{
...
...
@@ -755,8 +762,20 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
// always write the header event payload is empty.
while
(
p
<
pend
)
{
// the first chunk is c0, others is c3.
bool
is_c0
=
p
==
msg
->
payload
;
// header use iov[0].
generate_chunk_header
(
c0c3_cache
,
&
msg
->
header
,
p
==
msg
->
payload
,
iov
);
generate_chunk_header
(
somhc
,
somhc_bytes
,
nb_somhc_bytes
,
c0c3_cache
,
SRS_CONSTS_C0C3_HEADERS_MAX
-
c0c3_cache_index
,
&
msg
->
header
,
is_c0
,
iov
);
// set somhc to the first header.
if
(
!
somhc
)
{
somhc
=
&
msg
->
header
;
somhc_bytes
=
(
char
*
)
iov
[
0
].
iov_base
;
nb_somhc_bytes
=
iov
[
0
].
iov_len
;
}
// payload use iov[1].
int
payload_size
=
pend
-
p
;
...
...
@@ -898,8 +917,10 @@ int SrsProtocol::do_send_and_free_packet(SrsPacket* packet, int stream_id)
return
ret
;
}
void
SrsProtocol
::
generate_chunk_header
(
char
*
cache
,
SrsMessageHeader
*
mh
,
bool
c0
,
iovec
*
iov
)
{
void
SrsProtocol
::
generate_chunk_header
(
SrsMessageHeader
*
somhc
,
char
*
somhc_bytes
,
int
nb_somhc_bytes
,
char
*
cache
,
int
nb_cache
,
SrsMessageHeader
*
mh
,
bool
c0
,
iovec
*
iov
)
{
// to directly set the field.
char
*
pp
=
NULL
;
...
...
@@ -910,11 +931,20 @@ void SrsProtocol::generate_chunk_header(char* cache, SrsMessageHeader* mh, bool
u_int32_t
timestamp
=
(
u_int32_t
)
mh
->
timestamp
;
if
(
c0
)
{
// if cached header, copy it.
if
(
somhc
)
{
srs_assert
(
nb_cache
>=
nb_somhc_bytes
);
memcpy
(
cache
,
somhc_bytes
,
nb_somhc_bytes
);
}
// write new chunk stream header, fmt is 0
*
p
++
=
0x00
|
(
mh
->
perfer_cid
&
0x3F
);
// chunk message header, 11 bytes
// timestamp, 3bytes, big-endian
if
(
somhc
&&
somhc
->
timestamp
==
mh
->
timestamp
)
{
p
+=
3
;
}
else
{
if
(
timestamp
<
RTMP_EXTENDED_TIMESTAMP
)
{
pp
=
(
char
*
)
&
timestamp
;
*
p
++
=
pp
[
2
];
...
...
@@ -925,22 +955,31 @@ void SrsProtocol::generate_chunk_header(char* cache, SrsMessageHeader* mh, bool
*
p
++
=
0xFF
;
*
p
++
=
0xFF
;
}
}
// message_length, 3bytes, big-endian
if
(
somhc
&&
somhc
->
payload_length
==
mh
->
payload_length
)
{
p
+=
3
;
}
else
{
pp
=
(
char
*
)
&
mh
->
payload_length
;
*
p
++
=
pp
[
2
];
*
p
++
=
pp
[
1
];
*
p
++
=
pp
[
0
];
}
// message_type, 1bytes
*
p
++
=
mh
->
message_type
;
// message_length, 3bytes, little-endian
// stream_id, 4bytes, little-endian.
if
(
somhc
&&
somhc
->
stream_id
==
mh
->
stream_id
)
{
p
+=
4
;
}
else
{
pp
=
(
char
*
)
&
mh
->
stream_id
;
*
p
++
=
pp
[
0
];
*
p
++
=
pp
[
1
];
*
p
++
=
pp
[
2
];
*
p
++
=
pp
[
3
];
}
}
else
{
// write no message header chunk stream, fmt is 3
// @remark, if perfer_cid > 0x3F, that is, use 2B/3B chunk header,
...
...
@@ -967,12 +1006,16 @@ void SrsProtocol::generate_chunk_header(char* cache, SrsMessageHeader* mh, bool
// @see: http://blog.csdn.net/win_lin/article/details/13363699
// TODO: FIXME: extract to outer.
if
(
timestamp
>=
RTMP_EXTENDED_TIMESTAMP
)
{
if
(
somhc
&&
somhc
->
payload_length
==
mh
->
payload_length
)
{
p
+=
4
;
}
else
{
pp
=
(
char
*
)
&
timestamp
;
*
p
++
=
pp
[
3
];
*
p
++
=
pp
[
2
];
*
p
++
=
pp
[
1
];
*
p
++
=
pp
[
0
];
}
}
// always has header
iov
->
iov_base
=
cache
;
...
...
trunk/src/rtmp/srs_protocol_stack.hpp
查看文件 @
d073add
...
...
@@ -84,7 +84,7 @@ public:
/**
* 4bytes.
* Four-byte field that identifies the stream of the message. These
* bytes are set in
big
-endian format.
* bytes are set in
little
-endian format.
*/
int32_t
stream_id
;
...
...
@@ -494,11 +494,16 @@ private:
virtual
int
do_send_and_free_packet
(
SrsPacket
*
packet
,
int
stream_id
);
/**
* generate the chunk header for msg.
* @param somhc, session-oriented message-header cache.
* @param somhc_bytes, the serialized bytes.
* @param nb_somhc_bytes, the size of somhc_bytes.
* @param mh, the header of msg to send.
* @param c0, whether the first chunk, the c0 chunk.
* @param iov, output the header and size to iovec.
*/
virtual
void
generate_chunk_header
(
char
*
cache
,
SrsMessageHeader
*
mh
,
bool
c0
,
iovec
*
iov
);
virtual
void
generate_chunk_header
(
SrsMessageHeader
*
somhc
,
char
*
somhc_bytes
,
int
nb_somhc_bytes
,
char
*
cache
,
int
nb_cache
,
SrsMessageHeader
*
mh
,
bool
c0
,
iovec
*
iov
);
/**
* imp for decode_message
*/
...
...
胡斌
@hubin
2017-02-06 05:12:37 UTC
mentioned in commit
9892b922
请
注册
或
登录
后发表评论