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-03-02 12:35:15 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
86267f854cbda4969bd4364cf1ac56a5895e4fd0
86267f85
1 parent
f24f27de
srs-librtmp: implements handshake.
隐藏空白字符变更
内嵌
并排对比
正在显示
9 个修改的文件
包含
83 行增加
和
39 行删除
trunk/configure
trunk/research/librtmp/srs_play.c
trunk/src/libs/srs_lib_simple_socket.cpp
trunk/src/libs/srs_librtmp.cpp
trunk/src/libs/srs_librtmp.hpp
trunk/src/rtmp/srs_protocol_handshake.cpp
trunk/src/rtmp/srs_protocol_handshake.hpp
trunk/src/rtmp/srs_protocol_rtmp.cpp
trunk/src/rtmp/srs_protocol_rtmp.hpp
trunk/configure
100644 → 100755
查看文件 @
86267f8
trunk/research/librtmp/srs_play.c
查看文件 @
86267f8
...
...
@@ -37,8 +37,7 @@ int main(int argc, char** argv)
rtmp
=
srs_rtmp_create
(
"rtmp://127.0.0.1:1935/live/show?vhost=__defaultVhost__/livestream"
);
//if (srs_simple_handshake(rtmp) != 0) {
if
(
srs_complex_handshake
(
rtmp
)
!=
0
)
{
if
(
srs_simple_handshake
(
rtmp
)
!=
0
)
{
printf
(
"simple handshake failed.
\n
"
);
goto
rtmp_destroy
;
}
...
...
trunk/src/libs/srs_lib_simple_socket.cpp
查看文件 @
86267f8
...
...
@@ -81,20 +81,17 @@ void SimpleSocketStream::set_recv_timeout(int64_t timeout_us)
int64_t
SimpleSocketStream
::
get_recv_timeout
()
{
int
ret
=
ERROR_SUCCESS
;
return
ret
;
return
-
1
;
}
int64_t
SimpleSocketStream
::
get_recv_bytes
()
{
int
ret
=
ERROR_SUCCESS
;
return
ret
;
return
0
;
}
int
SimpleSocketStream
::
get_recv_kbps
()
{
int
ret
=
ERROR_SUCCESS
;
return
ret
;
return
0
;
}
// ISrsProtocolWriter
...
...
@@ -104,20 +101,17 @@ void SimpleSocketStream::set_send_timeout(int64_t timeout_us)
int64_t
SimpleSocketStream
::
get_send_timeout
()
{
int
ret
=
ERROR_SUCCESS
;
return
ret
;
return
-
1
;
}
int64_t
SimpleSocketStream
::
get_send_bytes
()
{
int
ret
=
ERROR_SUCCESS
;
return
ret
;
return
0
;
}
int
SimpleSocketStream
::
get_send_kbps
()
{
int
ret
=
ERROR_SUCCESS
;
return
ret
;
return
0
;
}
int
SimpleSocketStream
::
writev
(
const
iovec
*
iov
,
int
iov_size
,
ssize_t
*
nwrite
)
...
...
trunk/src/libs/srs_librtmp.cpp
查看文件 @
86267f8
...
...
@@ -170,6 +170,10 @@ int srs_simple_handshake(srs_rtmp_t rtmp)
srs_freep
(
context
->
rtmp
);
context
->
rtmp
=
new
SrsRtmpClient
(
context
->
skt
);
if
((
ret
=
context
->
rtmp
->
simple_handshake
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
return
ret
;
}
...
...
@@ -197,6 +201,14 @@ int srs_publish_stream(srs_rtmp_t rtmp)
return
ERROR_SUCCESS
;
}
int
srs_ssl_enabled
()
{
#ifndef SRS_SSL
return
false
;
#endif
return
true
;
}
int
srs_version_major
()
{
return
::
atoi
(
VERSION_MAJOR
);
...
...
trunk/src/libs/srs_librtmp.hpp
查看文件 @
86267f8
...
...
@@ -66,7 +66,10 @@ void srs_rtmp_destroy(srs_rtmp_t rtmp);
int
srs_simple_handshake
(
srs_rtmp_t
rtmp
);
/**
* complex handshake is specified by adobe Flash player,
* depends on ssl, user must link libssl.a and libcrypt.a
* depends on ssl, user must compile srs with ssl, then
* link user program libssl.a and libcrypt.a
* @remark user can use srs_ssl_enabled() to detect
* whether ssl is ok.
*/
int
srs_complex_handshake
(
srs_rtmp_t
rtmp
);
...
...
@@ -98,6 +101,14 @@ int srs_play_stream(srs_rtmp_t rtmp);
int
srs_publish_stream
(
srs_rtmp_t
rtmp
);
/**
* whether srs is compiled with ssl,
* that is, compile srs with ssl: ./configure --with-ssl,.
* if no ssl, complex handshake always error.
* @return 0 for false, otherwise, true.
*/
int
srs_ssl_enabled
();
/**
* get protocol stack version
*/
int
srs_version_major
();
...
...
trunk/src/rtmp/srs_protocol_handshake.cpp
查看文件 @
86267f8
...
...
@@ -1067,7 +1067,7 @@ SrsSimpleHandshake::~SrsSimpleHandshake()
{
}
int
SrsSimpleHandshake
::
handshake_with_client
(
ISrsProtocolReaderWriter
*
skt
,
SrsComplexHandshake
&
complex_hs
)
int
SrsSimpleHandshake
::
handshake_with_client
(
ISrsProtocolReaderWriter
*
skt
,
SrsComplexHandshake
*
complex_hs
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -1090,16 +1090,18 @@ int SrsSimpleHandshake::handshake_with_client(ISrsProtocolReaderWriter* skt, Srs
srs_verbose
(
"check c0 success, required plain text."
);
// try complex handshake
ret
=
complex_hs
.
handshake_with_client
(
skt
,
c0c1
+
1
);
if
(
ret
==
ERROR_SUCCESS
)
{
srs_trace
(
"complex handshake success."
);
return
ret
;
if
(
complex_hs
)
{
ret
=
complex_hs
->
handshake_with_client
(
skt
,
c0c1
+
1
);
if
(
ret
==
ERROR_SUCCESS
)
{
srs_trace
(
"complex handshake success."
);
return
ret
;
}
if
(
ret
!=
ERROR_RTMP_TRY_SIMPLE_HS
)
{
srs_error
(
"complex handshake failed. ret=%d"
,
ret
);
return
ret
;
}
srs_info
(
"rollback complex to simple handshake. ret=%d"
,
ret
);
}
if
(
ret
!=
ERROR_RTMP_TRY_SIMPLE_HS
)
{
srs_error
(
"complex handshake failed. ret=%d"
,
ret
);
return
ret
;
}
srs_info
(
"rollback complex to simple handshake. ret=%d"
,
ret
);
char
*
s0s1s2
=
new
char
[
3073
];
srs_random_generate
(
s0s1s2
,
3073
);
...
...
@@ -1125,21 +1127,23 @@ int SrsSimpleHandshake::handshake_with_client(ISrsProtocolReaderWriter* skt, Srs
return
ret
;
}
int
SrsSimpleHandshake
::
handshake_with_server
(
ISrsProtocolReaderWriter
*
skt
,
SrsComplexHandshake
&
complex_hs
)
int
SrsSimpleHandshake
::
handshake_with_server
(
ISrsProtocolReaderWriter
*
skt
,
SrsComplexHandshake
*
complex_hs
)
{
int
ret
=
ERROR_SUCCESS
;
// try complex handshake
ret
=
complex_hs
.
handshake_with_server
(
skt
);
if
(
ret
==
ERROR_SUCCESS
)
{
srs_trace
(
"complex handshake success."
);
return
ret
;
}
if
(
ret
!=
ERROR_RTMP_TRY_SIMPLE_HS
)
{
srs_error
(
"complex handshake failed. ret=%d"
,
ret
);
return
ret
;
if
(
complex_hs
)
{
ret
=
complex_hs
->
handshake_with_server
(
skt
);
if
(
ret
==
ERROR_SUCCESS
)
{
srs_trace
(
"complex handshake success."
);
return
ret
;
}
if
(
ret
!=
ERROR_RTMP_TRY_SIMPLE_HS
)
{
srs_error
(
"complex handshake failed. ret=%d"
,
ret
);
return
ret
;
}
srs_info
(
"rollback complex to simple handshake. ret=%d"
,
ret
);
}
srs_info
(
"rollback complex to simple handshake. ret=%d"
,
ret
);
// simple handshake
ssize_t
nsize
;
...
...
trunk/src/rtmp/srs_protocol_handshake.hpp
查看文件 @
86267f8
...
...
@@ -45,10 +45,11 @@ public:
/**
* simple handshake.
* @param complex_hs, try complex handshake first,
* if NULL, use simple handshake.
* if failed, rollback to simple handshake.
*/
virtual
int
handshake_with_client
(
ISrsProtocolReaderWriter
*
io
,
SrsComplexHandshake
&
complex_hs
);
virtual
int
handshake_with_server
(
ISrsProtocolReaderWriter
*
io
,
SrsComplexHandshake
&
complex_hs
);
virtual
int
handshake_with_client
(
ISrsProtocolReaderWriter
*
io
,
SrsComplexHandshake
*
complex_hs
);
virtual
int
handshake_with_server
(
ISrsProtocolReaderWriter
*
io
,
SrsComplexHandshake
*
complex_hs
);
};
/**
...
...
trunk/src/rtmp/srs_protocol_rtmp.cpp
查看文件 @
86267f8
...
...
@@ -233,13 +233,31 @@ int SrsRtmpClient::handshake()
SrsComplexHandshake
complex_hs
;
SrsSimpleHandshake
simple_hs
;
if
((
ret
=
simple_hs
.
handshake_with_server
(
io
,
complex_hs
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
simple_hs
.
handshake_with_server
(
io
,
&
complex_hs
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
return
ret
;
}
int
SrsRtmpClient
::
simple_handshake
()
{
int
ret
=
ERROR_SUCCESS
;
SrsSimpleHandshake
simple_hs
;
if
((
ret
=
simple_hs
.
handshake_with_server
(
io
,
NULL
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
return
ret
;
}
int
SrsRtmpClient
::
complex_handshake
()
{
// TODO: FIXME: only use complex handshake.
return
handshake
();
}
int
SrsRtmpClient
::
connect_app
(
string
app
,
string
tc_url
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -495,7 +513,7 @@ int SrsRtmp::handshake()
SrsComplexHandshake
complex_hs
;
SrsSimpleHandshake
simple_hs
;
if
((
ret
=
simple_hs
.
handshake_with_client
(
io
,
complex_hs
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
simple_hs
.
handshake_with_client
(
io
,
&
complex_hs
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
trunk/src/rtmp/srs_protocol_rtmp.hpp
查看文件 @
86267f8
...
...
@@ -128,7 +128,12 @@ public:
virtual
int
recv_message
(
SrsCommonMessage
**
pmsg
);
virtual
int
send_message
(
ISrsMessage
*
msg
);
public
:
// try complex, then simple handshake.
virtual
int
handshake
();
// only use simple handshake
virtual
int
simple_handshake
();
// only use complex handshake
virtual
int
complex_handshake
();
virtual
int
connect_app
(
std
::
string
app
,
std
::
string
tc_url
);
virtual
int
create_stream
(
int
&
stream_id
);
virtual
int
play
(
std
::
string
stream
,
int
stream_id
);
...
...
请
注册
或
登录
后发表评论