mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
srs-librtmp: implements handshake.
This commit is contained in:
parent
f24f27deb9
commit
86267f854c
9 changed files with 83 additions and 39 deletions
|
@ -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 (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);
|
||||
}
|
||||
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);
|
||||
|
||||
// simple handshake
|
||||
ssize_t nsize;
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue