mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
For #1042, cover RTMP client protocol.
This commit is contained in:
parent
69817a9f34
commit
41a9f15626
4 changed files with 190 additions and 0 deletions
|
@ -52,6 +52,11 @@ extern srs_utime_t _srs_tmp_timeout;
|
||||||
#define HELPER_EXPECT_SUCCESS(x) EXPECT_TRUE(srs_success == (err = x)); srs_freep(err)
|
#define HELPER_EXPECT_SUCCESS(x) EXPECT_TRUE(srs_success == (err = x)); srs_freep(err)
|
||||||
#define HELPER_EXPECT_FAILED(x) EXPECT_TRUE(srs_success != (err = x)); srs_freep(err)
|
#define HELPER_EXPECT_FAILED(x) EXPECT_TRUE(srs_success != (err = x)); srs_freep(err)
|
||||||
|
|
||||||
|
// For errors, assert.
|
||||||
|
// @remark The err is leak when error, but it's ok in utest.
|
||||||
|
#define HELPER_ASSERT_SUCCESS(x) ASSERT_TRUE(srs_success == (err = x)); srs_freep(err)
|
||||||
|
#define HELPER_ASSERT_FAILED(x) ASSERT_TRUE(srs_success != (err = x)); srs_freep(err)
|
||||||
|
|
||||||
// For init array data.
|
// For init array data.
|
||||||
#define HELPER_ARRAY_INIT(buf, sz, val) \
|
#define HELPER_ARRAY_INIT(buf, sz, val) \
|
||||||
for (int i = 0; i < (int)sz; i++) (buf)[i]=val
|
for (int i = 0; i < (int)sz; i++) (buf)[i]=val
|
||||||
|
|
|
@ -113,6 +113,12 @@ MockBufferIO* MockBufferIO::append(string data)
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MockBufferIO* MockBufferIO::append(MockBufferIO* data)
|
||||||
|
{
|
||||||
|
in_buffer.append(&data->in_buffer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
MockBufferIO* MockBufferIO::append(uint8_t* data, int size)
|
MockBufferIO* MockBufferIO::append(uint8_t* data, int size)
|
||||||
{
|
{
|
||||||
in_buffer.append((char*)data, size);
|
in_buffer.append((char*)data, size);
|
||||||
|
@ -130,6 +136,12 @@ MockBufferIO* MockBufferIO::out_append(string data)
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MockBufferIO* MockBufferIO::out_append(MockBufferIO* data)
|
||||||
|
{
|
||||||
|
out_buffer.append(&data->out_buffer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
MockBufferIO* MockBufferIO::out_append(uint8_t* data, int size)
|
MockBufferIO* MockBufferIO::out_append(uint8_t* data, int size)
|
||||||
{
|
{
|
||||||
out_buffer.append((char*)data, size);
|
out_buffer.append((char*)data, size);
|
||||||
|
@ -488,6 +500,15 @@ VOID TEST(ProtocolHandshakeTest, ComplexHandshake)
|
||||||
SrsRtmpClient r(&io);
|
SrsRtmpClient r(&io);
|
||||||
HELPER_EXPECT_SUCCESS(r.complex_handshake());
|
HELPER_EXPECT_SUCCESS(r.complex_handshake());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
MockBufferIO io;
|
||||||
|
io.append(c0c1, 1537);
|
||||||
|
io.append(c2, 1536);
|
||||||
|
|
||||||
|
SrsRtmpServer r(&io);
|
||||||
|
HELPER_EXPECT_SUCCESS(r.handshake());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID TEST(ProtocolHandshakeTest, SimpleHandshake)
|
VOID TEST(ProtocolHandshakeTest, SimpleHandshake)
|
||||||
|
@ -539,6 +560,15 @@ VOID TEST(ProtocolHandshakeTest, SimpleHandshake)
|
||||||
SrsRtmpClient r(&io);
|
SrsRtmpClient r(&io);
|
||||||
HELPER_EXPECT_SUCCESS(r.simple_handshake());
|
HELPER_EXPECT_SUCCESS(r.simple_handshake());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
MockBufferIO io;
|
||||||
|
io.append(c0c1, 1537);
|
||||||
|
io.append(c2, 1536);
|
||||||
|
|
||||||
|
SrsRtmpServer r(&io);
|
||||||
|
HELPER_EXPECT_SUCCESS(r.handshake());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -89,10 +89,12 @@ public:
|
||||||
public:
|
public:
|
||||||
virtual int length();
|
virtual int length();
|
||||||
virtual MockBufferIO* append(std::string data);
|
virtual MockBufferIO* append(std::string data);
|
||||||
|
virtual MockBufferIO* append(MockBufferIO* data);
|
||||||
virtual MockBufferIO* append(uint8_t* data, int size);
|
virtual MockBufferIO* append(uint8_t* data, int size);
|
||||||
public:
|
public:
|
||||||
virtual int out_length();
|
virtual int out_length();
|
||||||
virtual MockBufferIO* out_append(std::string data);
|
virtual MockBufferIO* out_append(std::string data);
|
||||||
|
virtual MockBufferIO* out_append(MockBufferIO* data);
|
||||||
virtual MockBufferIO* out_append(uint8_t* data, int size);
|
virtual MockBufferIO* out_append(uint8_t* data, int size);
|
||||||
// for handshake.
|
// for handshake.
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -1450,3 +1450,156 @@ VOID TEST(ProtoStackTest, ServerInfo)
|
||||||
EXPECT_EQ(0, si.build);
|
EXPECT_EQ(0, si.build);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOID TEST(ProtoStackTest, ClientCommandMessage)
|
||||||
|
{
|
||||||
|
srs_error_t err;
|
||||||
|
|
||||||
|
// ConnectApp.
|
||||||
|
if (true) {
|
||||||
|
MockBufferIO io;
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
SrsConnectAppResPacket* res = new SrsConnectAppResPacket();
|
||||||
|
|
||||||
|
SrsAmf0EcmaArray* data = SrsAmf0Any::ecma_array();
|
||||||
|
res->info->set("data", data);
|
||||||
|
|
||||||
|
data->set("srs_server_ip", SrsAmf0Any::str("1.2.3.4"));
|
||||||
|
data->set("srs_server", SrsAmf0Any::str("srs"));
|
||||||
|
data->set("srs_id", SrsAmf0Any::number(100));
|
||||||
|
data->set("srs_pid", SrsAmf0Any::number(200));
|
||||||
|
data->set("srs_version", SrsAmf0Any::str("3.4.5.678"));
|
||||||
|
|
||||||
|
MockBufferIO tio;
|
||||||
|
SrsProtocol p(&tio);
|
||||||
|
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(res, 0));
|
||||||
|
|
||||||
|
io.in_buffer.append(&tio.out_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
SrsRequest req;
|
||||||
|
SrsRtmpClient r(&io);
|
||||||
|
|
||||||
|
SrsServerInfo si;
|
||||||
|
HELPER_EXPECT_SUCCESS(r.connect_app("live", "rtmp://127.0.0.1/live", &req, true, &si));
|
||||||
|
EXPECT_STREQ("1.2.3.4", si.ip.c_str());
|
||||||
|
EXPECT_STREQ("srs", si.sig.c_str());
|
||||||
|
EXPECT_EQ(100, si.cid);
|
||||||
|
EXPECT_EQ(200, si.pid);
|
||||||
|
EXPECT_EQ(3, si.major);
|
||||||
|
EXPECT_EQ(4, si.minor);
|
||||||
|
EXPECT_EQ(5, si.revision);
|
||||||
|
EXPECT_EQ(678, si.build);
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateStream.
|
||||||
|
if (true) {
|
||||||
|
MockBufferIO io;
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
SrsCreateStreamResPacket* res = new SrsCreateStreamResPacket(2.0, 3.0);
|
||||||
|
|
||||||
|
MockBufferIO tio;
|
||||||
|
SrsProtocol p(&tio);
|
||||||
|
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(res, 0));
|
||||||
|
|
||||||
|
io.in_buffer.append(&tio.out_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
SrsRtmpClient r(&io);
|
||||||
|
|
||||||
|
int stream_id = 0;
|
||||||
|
HELPER_EXPECT_SUCCESS(r.create_stream(stream_id));
|
||||||
|
EXPECT_EQ(3, stream_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Play.
|
||||||
|
if (true) {
|
||||||
|
MockBufferIO io;
|
||||||
|
SrsRtmpClient r(&io);
|
||||||
|
HELPER_EXPECT_SUCCESS(r.play("livestream", 1, 128));
|
||||||
|
EXPECT_TRUE(io.out_length() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Publish.
|
||||||
|
if (true) {
|
||||||
|
MockBufferIO io;
|
||||||
|
SrsRtmpClient r(&io);
|
||||||
|
HELPER_EXPECT_SUCCESS(r.publish("livestream", 1, 128));
|
||||||
|
EXPECT_TRUE(io.out_length() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FMLE publish.
|
||||||
|
if (true) {
|
||||||
|
MockBufferIO io;
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
SrsCreateStreamResPacket* res = new SrsCreateStreamResPacket(4.0, 3.0);
|
||||||
|
|
||||||
|
MockBufferIO tio;
|
||||||
|
SrsProtocol p(&tio);
|
||||||
|
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(res, 0));
|
||||||
|
|
||||||
|
io.in_buffer.append(&tio.out_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
SrsRtmpClient r(&io);
|
||||||
|
|
||||||
|
int stream_id = 0;
|
||||||
|
HELPER_EXPECT_SUCCESS(r.fmle_publish("livestream", stream_id));
|
||||||
|
EXPECT_EQ(3, stream_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID TEST(ProtoStackTest, ServerCommandMessage)
|
||||||
|
{
|
||||||
|
srs_error_t err;
|
||||||
|
|
||||||
|
// ConnectApp.
|
||||||
|
if (true) {
|
||||||
|
MockBufferIO io;
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
SrsConnectAppPacket* res = new SrsConnectAppPacket();
|
||||||
|
res->command_object->set("tcUrl", SrsAmf0Any::str("rtmp://127.0.0.1/live"));
|
||||||
|
|
||||||
|
MockBufferIO tio;
|
||||||
|
SrsProtocol p(&tio);
|
||||||
|
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(res, 0));
|
||||||
|
|
||||||
|
io.in_buffer.append(&tio.out_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
SrsRtmpServer r(&io);
|
||||||
|
|
||||||
|
SrsRequest req;
|
||||||
|
HELPER_EXPECT_SUCCESS(r.connect_app(&req));
|
||||||
|
EXPECT_STREQ("rtmp", req.schema.c_str());
|
||||||
|
EXPECT_STREQ("127.0.0.1", req.host.c_str());
|
||||||
|
EXPECT_STREQ("127.0.0.1", req.vhost.c_str());
|
||||||
|
EXPECT_STREQ("live", req.app.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Window ACK size.
|
||||||
|
if (true) {
|
||||||
|
MockBufferIO io;
|
||||||
|
SrsRtmpServer r(&io);
|
||||||
|
HELPER_EXPECT_SUCCESS(r.set_window_ack_size(1024));
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
MockBufferIO tio;
|
||||||
|
tio.in_buffer.append(&io.out_buffer);
|
||||||
|
|
||||||
|
SrsProtocol p(&tio);
|
||||||
|
|
||||||
|
SrsCommonMessage* msg = NULL;
|
||||||
|
SrsSetWindowAckSizePacket* pkt = NULL;
|
||||||
|
HELPER_EXPECT_SUCCESS(p.expect_message(&msg, &pkt));
|
||||||
|
EXPECT_EQ(1024, pkt->ackowledgement_window_size);
|
||||||
|
|
||||||
|
srs_freep(msg);
|
||||||
|
srs_freep(pkt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue