1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

add complex handshake utest

This commit is contained in:
winlin 2014-03-19 17:14:42 +08:00
parent 491ea4b630
commit da93b6fe99
6 changed files with 1083 additions and 1078 deletions

View file

@ -67,7 +67,7 @@ cd simple-rtmp-server/trunk
[Usage: How to deploy low lantency application?](https://github.com/winlinvip/simple-rtmp-server/wiki/SampleRealtime)<br/> [Usage: How to deploy low lantency application?](https://github.com/winlinvip/simple-rtmp-server/wiki/SampleRealtime)<br/>
[Usage: How to deploy srs on ARM?](https://github.com/winlinvip/simple-rtmp-server/wiki/SampleARM)<br/> [Usage: How to deploy srs on ARM?](https://github.com/winlinvip/simple-rtmp-server/wiki/SampleARM)<br/>
[Usage: How to show the demo of SRS?](https://github.com/winlinvip/simple-rtmp-server/wiki/SampleDemo)<br/> [Usage: How to show the demo of SRS?](https://github.com/winlinvip/simple-rtmp-server/wiki/SampleDemo)<br/>
[Usage: Who is using SRS?](https://github.com/winlinvip/simple-rtmp-server/wiki/Sample)<br/> [Usage: Solution using SRS?](https://github.com/winlinvip/simple-rtmp-server/wiki/Sample)<br/>
### System Requirements ### System Requirements
Supported operating systems and hardware: Supported operating systems and hardware:

File diff suppressed because it is too large Load diff

View file

@ -31,46 +31,46 @@ gcc srs_play.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_play
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
srs_rtmp_t rtmp; srs_rtmp_t rtmp;
// packet data // packet data
int type, size; int type, size;
u_int32_t timestamp = 0; u_int32_t timestamp = 0;
char* data; char* data;
printf("suck rtmp stream like rtmpdump\n"); printf("suck rtmp stream like rtmpdump\n");
printf("srs(simple-rtmp-server) client librtmp library.\n"); printf("srs(simple-rtmp-server) client librtmp library.\n");
printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision()); printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision());
rtmp = srs_rtmp_create("rtmp://127.0.0.1:1935/live/livestream"); rtmp = srs_rtmp_create("rtmp://127.0.0.1:1935/live/livestream");
if (srs_simple_handshake(rtmp) != 0) { if (srs_simple_handshake(rtmp) != 0) {
printf("simple handshake failed.\n"); printf("simple handshake failed.\n");
goto rtmp_destroy; goto rtmp_destroy;
} }
printf("simple handshake success\n"); printf("simple handshake success\n");
if (srs_connect_app(rtmp) != 0) { if (srs_connect_app(rtmp) != 0) {
printf("connect vhost/app failed.\n"); printf("connect vhost/app failed.\n");
goto rtmp_destroy; goto rtmp_destroy;
} }
printf("connect vhost/app success\n"); printf("connect vhost/app success\n");
if (srs_play_stream(rtmp) != 0) {
printf("play stream failed.\n");
goto rtmp_destroy;
}
printf("play stream success\n");
for (;;) {
if (srs_read_packet(rtmp, &type, &timestamp, &data, &size) != 0) {
goto rtmp_destroy;
}
printf("got packet: type=%s, time=%d, size=%d\n", srs_type2string(type), timestamp, size);
free(data);
}
if (srs_play_stream(rtmp) != 0) {
printf("play stream failed.\n");
goto rtmp_destroy;
}
printf("play stream success\n");
for (;;) {
if (srs_read_packet(rtmp, &type, &timestamp, &data, &size) != 0) {
goto rtmp_destroy;
}
printf("got packet: type=%s, time=%d, size=%d\n", srs_type2string(type), timestamp, size);
free(data);
}
rtmp_destroy: rtmp_destroy:
srs_rtmp_destroy(rtmp); srs_rtmp_destroy(rtmp);

View file

@ -32,51 +32,52 @@ gcc srs_publish.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_publish
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
srs_rtmp_t rtmp; srs_rtmp_t rtmp;
// packet data // packet data
int type, size; int type, size;
u_int32_t timestamp = 0; u_int32_t timestamp = 0;
char* data; char* data;
printf("publish rtmp stream to server like FMLE/FFMPEG/Encoder\n"); printf("publish rtmp stream to server like FMLE/FFMPEG/Encoder\n");
printf("srs(simple-rtmp-server) client librtmp library.\n"); printf("srs(simple-rtmp-server) client librtmp library.\n");
printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision()); printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision());
rtmp = srs_rtmp_create("rtmp://127.0.0.1:1935/live/livestream"); rtmp = srs_rtmp_create("rtmp://127.0.0.1:1935/live/livestream");
if (srs_simple_handshake(rtmp) != 0) { //if (srs_simple_handshake(rtmp) != 0) {
printf("simple handshake failed.\n"); if (srs_complex_handshake(rtmp) != 0) {
goto rtmp_destroy; printf("simple handshake failed.\n");
} goto rtmp_destroy;
printf("simple handshake success\n"); }
printf("simple handshake success\n");
if (srs_connect_app(rtmp) != 0) { if (srs_connect_app(rtmp) != 0) {
printf("connect vhost/app failed.\n"); printf("connect vhost/app failed.\n");
goto rtmp_destroy; goto rtmp_destroy;
} }
printf("connect vhost/app success\n"); printf("connect vhost/app success\n");
if (srs_publish_stream(rtmp) != 0) {
printf("publish stream failed.\n");
goto rtmp_destroy;
}
printf("publish stream success\n");
for (;;) {
type = SRS_RTMP_TYPE_VIDEO;
timestamp += 40;
size = 4096;
data = (char*)malloc(4096);
if (srs_write_packet(rtmp, type, timestamp, data, size) != 0) {
goto rtmp_destroy;
}
printf("sent packet: type=%s, time=%d, size=%d\n", srs_type2string(type), timestamp, size);
usleep(40 * 1000);
}
if (srs_publish_stream(rtmp) != 0) {
printf("publish stream failed.\n");
goto rtmp_destroy;
}
printf("publish stream success\n");
for (;;) {
type = SRS_RTMP_TYPE_VIDEO;
timestamp += 40;
size = 4096;
data = (char*)malloc(4096);
if (srs_write_packet(rtmp, type, timestamp, data, size) != 0) {
goto rtmp_destroy;
}
printf("sent packet: type=%s, time=%d, size=%d\n", srs_type2string(type), timestamp, size);
usleep(40 * 1000);
}
rtmp_destroy: rtmp_destroy:
srs_rtmp_destroy(rtmp); srs_rtmp_destroy(rtmp);

View file

@ -34,43 +34,7 @@ class ISrsProtocolReaderWriter;
class SrsComplexHandshake; class SrsComplexHandshake;
class SrsHandshakeBytes; class SrsHandshakeBytes;
/** #ifdef SRS_SSL
* try complex handshake, if failed, fallback to simple handshake.
*/
class SrsSimpleHandshake
{
public:
SrsSimpleHandshake();
virtual ~SrsSimpleHandshake();
public:
/**
* simple handshake.
*/
virtual int handshake_with_client(SrsHandshakeBytes* hs_bytes, ISrsProtocolReaderWriter* io);
virtual int handshake_with_server(SrsHandshakeBytes* hs_bytes, ISrsProtocolReaderWriter* io);
};
/**
* rtmp complex handshake,
* @see also crtmp(crtmpserver) or librtmp,
* @see also: http://blog.csdn.net/win_lin/article/details/13006803
*/
class SrsComplexHandshake
{
public:
SrsComplexHandshake();
virtual ~SrsComplexHandshake();
public:
/**
* complex hanshake.
* @return user must:
* continue connect app if success,
* try simple handshake if error is ERROR_RTMP_TRY_SIMPLE_HS,
* otherwise, disconnect
*/
virtual int handshake_with_client(SrsHandshakeBytes* hs_bytes, ISrsProtocolReaderWriter* io);
virtual int handshake_with_server(SrsHandshakeBytes* hs_bytes, ISrsProtocolReaderWriter* io);
};
namespace srs namespace srs
{ {
@ -303,4 +267,44 @@ namespace srs
int openssl_HMACsha256(const void* data, int data_size, const void* key, int key_size, void* digest); int openssl_HMACsha256(const void* data, int data_size, const void* key, int key_size, void* digest);
} }
#endif
/**
* try complex handshake, if failed, fallback to simple handshake.
*/
class SrsSimpleHandshake
{
public:
SrsSimpleHandshake();
virtual ~SrsSimpleHandshake();
public:
/**
* simple handshake.
*/
virtual int handshake_with_client(SrsHandshakeBytes* hs_bytes, ISrsProtocolReaderWriter* io);
virtual int handshake_with_server(SrsHandshakeBytes* hs_bytes, ISrsProtocolReaderWriter* io);
};
/**
* rtmp complex handshake,
* @see also crtmp(crtmpserver) or librtmp,
* @see also: http://blog.csdn.net/win_lin/article/details/13006803
*/
class SrsComplexHandshake
{
public:
SrsComplexHandshake();
virtual ~SrsComplexHandshake();
public:
/**
* complex hanshake.
* @return user must:
* continue connect app if success,
* try simple handshake if error is ERROR_RTMP_TRY_SIMPLE_HS,
* otherwise, disconnect
*/
virtual int handshake_with_client(SrsHandshakeBytes* hs_bytes, ISrsProtocolReaderWriter* io);
virtual int handshake_with_server(SrsHandshakeBytes* hs_bytes, ISrsProtocolReaderWriter* io);
};
#endif #endif

View file

@ -229,7 +229,7 @@ int SrsHandshakeBytes::read_s0s1s2(ISrsProtocolReaderWriter* io)
ssize_t nsize; ssize_t nsize;
c0c1 = new char[3073]; s0s1s2 = new char[3073];
if ((ret = io->read_fully(s0s1s2, 3073, &nsize)) != ERROR_SUCCESS) { if ((ret = io->read_fully(s0s1s2, 3073, &nsize)) != ERROR_SUCCESS) {
srs_warn("read s0s1s2 failed. ret=%d", ret); srs_warn("read s0s1s2 failed. ret=%d", ret);
return ret; return ret;