mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
fix bug of buffer assert, erase can accept any value
This commit is contained in:
parent
d48d739fa7
commit
a639eb0596
4 changed files with 29 additions and 12 deletions
|
@ -79,8 +79,8 @@ int main(int argc, char** argv)
|
||||||
printf("duration: %ds, timeout:%ds\n", duration, timeout);
|
printf("duration: %ds, timeout:%ds\n", duration, timeout);
|
||||||
|
|
||||||
if (duration <= 0 || timeout <= 0) {
|
if (duration <= 0 || timeout <= 0) {
|
||||||
printf("duration and timeout must be positive.\n");
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
fprintf(stderr, "duration and timeout must be positive. ret=%d\n", ret);
|
||||||
exit(ret);
|
exit(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -88,33 +88,33 @@ int main(int argc, char** argv)
|
||||||
rtmp = srs_rtmp_create(rtmp_url);
|
rtmp = srs_rtmp_create(rtmp_url);
|
||||||
|
|
||||||
if ((ret = __srs_dns_resolve(rtmp)) != 0) {
|
if ((ret = __srs_dns_resolve(rtmp)) != 0) {
|
||||||
printf("dns resolve failed.\n");
|
fprintf(stderr, "dns resolve failed. ret=%d\n", ret);
|
||||||
goto rtmp_destroy;
|
goto rtmp_destroy;
|
||||||
}
|
}
|
||||||
printf("dns resolve success\n");
|
printf("dns resolve success\n");
|
||||||
time_dns_resolve = srs_get_time_ms();
|
time_dns_resolve = srs_get_time_ms();
|
||||||
|
|
||||||
if ((ret = __srs_connect_server(rtmp)) != 0) {
|
if ((ret = __srs_connect_server(rtmp)) != 0) {
|
||||||
printf("socket connect failed.\n");
|
fprintf(stderr, "socket connect failed. ret=%d\n", ret);
|
||||||
goto rtmp_destroy;
|
goto rtmp_destroy;
|
||||||
}
|
}
|
||||||
printf("socket connect success\n");
|
printf("socket connect success\n");
|
||||||
time_socket_connect = srs_get_time_ms();
|
time_socket_connect = srs_get_time_ms();
|
||||||
|
|
||||||
if ((ret = __srs_do_simple_handshake(rtmp)) != 0) {
|
if ((ret = __srs_do_simple_handshake(rtmp)) != 0) {
|
||||||
printf("do simple handshake failed.\n");
|
fprintf(stderr, "do simple handshake failed. ret=%d\n", ret);
|
||||||
goto rtmp_destroy;
|
goto rtmp_destroy;
|
||||||
}
|
}
|
||||||
printf("do simple handshake success\n");
|
printf("do simple handshake success\n");
|
||||||
|
|
||||||
if ((ret = srs_connect_app(rtmp)) != 0) {
|
if ((ret = srs_connect_app(rtmp)) != 0) {
|
||||||
printf("connect vhost/app failed.\n");
|
fprintf(stderr, "connect vhost/app failed. ret=%d\n", ret);
|
||||||
goto rtmp_destroy;
|
goto rtmp_destroy;
|
||||||
}
|
}
|
||||||
printf("connect vhost/app success\n");
|
printf("connect vhost/app success\n");
|
||||||
|
|
||||||
if ((ret = srs_play_stream(rtmp)) != 0) {
|
if ((ret = srs_play_stream(rtmp)) != 0) {
|
||||||
printf("play stream failed.\n");
|
fprintf(stderr, "play stream failed. ret=%d\n", ret);
|
||||||
goto rtmp_destroy;
|
goto rtmp_destroy;
|
||||||
}
|
}
|
||||||
printf("play stream success\n");
|
printf("play stream success\n");
|
||||||
|
@ -122,6 +122,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if ((ret = srs_read_packet(rtmp, &type, ×tamp, &data, &size)) != 0) {
|
if ((ret = srs_read_packet(rtmp, &type, ×tamp, &data, &size)) != 0) {
|
||||||
|
fprintf(stderr, "read packet failed. ret=%d\n", ret);
|
||||||
goto rtmp_destroy;
|
goto rtmp_destroy;
|
||||||
}
|
}
|
||||||
printf("got packet: type=%s, time=%d, size=%d\n", srs_type2string(type), timestamp, size);
|
printf("got packet: type=%s, time=%d, size=%d\n", srs_type2string(type), timestamp, size);
|
||||||
|
@ -158,7 +159,7 @@ rtmp_destroy:
|
||||||
"\"%s\":%d, " // #6
|
"\"%s\":%d, " // #6
|
||||||
"\"%s\":%d, " // #7
|
"\"%s\":%d, " // #7
|
||||||
"\"%s\":%d, " // #8
|
"\"%s\":%d, " // #8
|
||||||
"%s%s%s%s}",
|
"%s,%s,%s,%s}",
|
||||||
"code", ret, //#0
|
"code", ret, //#0
|
||||||
// total = dns + tcp_connect + start_play + first_packet + last_packet
|
// total = dns + tcp_connect + start_play + first_packet + last_packet
|
||||||
"total", (int)(time_cleanup - time_startup), //#1
|
"total", (int)(time_cleanup - time_startup), //#1
|
||||||
|
@ -173,12 +174,12 @@ rtmp_destroy:
|
||||||
// delay = actual - expect
|
// delay = actual - expect
|
||||||
"delay", (int)(timestamp - (time_cleanup - time_first_packet)), //#8
|
"delay", (int)(timestamp - (time_cleanup - time_first_packet)), //#8
|
||||||
// unit in ms.
|
// unit in ms.
|
||||||
"\"unit\": \"ms\",",
|
"\"unit\": \"ms\"",
|
||||||
"\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\",",
|
"\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\"",
|
||||||
"\"remark1\": \"delay = stream - (time_cleanup - time_first_packet)\"",
|
"\"remark1\": \"delay = stream - (time_cleanup - time_first_packet)\"",
|
||||||
"\"remark2\": \"if code is not 0, user must ignore all data\""
|
"\"remark2\": \"if code is not 0, user must ignore all data\""
|
||||||
);
|
);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,9 @@ char* SrsBuffer::bytes()
|
||||||
|
|
||||||
void SrsBuffer::erase(int size)
|
void SrsBuffer::erase(int size)
|
||||||
{
|
{
|
||||||
srs_assert(size > 0);
|
if (size <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (size >= length()) {
|
if (size >= length()) {
|
||||||
data.clear();
|
data.clear();
|
||||||
|
|
|
@ -71,7 +71,7 @@ public:
|
||||||
* erase size of bytes from begin.
|
* erase size of bytes from begin.
|
||||||
* @param size to erase size of bytes.
|
* @param size to erase size of bytes.
|
||||||
* clear if size greater than or equals to length()
|
* clear if size greater than or equals to length()
|
||||||
* @remark assert size is positive.
|
* @remark ignore size is not positive.
|
||||||
*/
|
*/
|
||||||
virtual void erase(int size);
|
virtual void erase(int size);
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -79,20 +79,34 @@ VOID TEST(BufferTest, EraseBytes)
|
||||||
{
|
{
|
||||||
SrsBuffer b;
|
SrsBuffer b;
|
||||||
|
|
||||||
|
b.erase(0);
|
||||||
|
b.erase(-1);
|
||||||
|
EXPECT_EQ(0, b.length());
|
||||||
|
|
||||||
char winlin[] = "winlin";
|
char winlin[] = "winlin";
|
||||||
b.append(winlin, strlen(winlin));
|
b.append(winlin, strlen(winlin));
|
||||||
b.erase(b.length());
|
b.erase(b.length());
|
||||||
EXPECT_EQ(0, b.length());
|
EXPECT_EQ(0, b.length());
|
||||||
|
|
||||||
|
b.erase(0);
|
||||||
|
b.erase(-1);
|
||||||
|
EXPECT_EQ(0, b.length());
|
||||||
|
|
||||||
b.append(winlin, strlen(winlin));
|
b.append(winlin, strlen(winlin));
|
||||||
b.erase(1);
|
b.erase(1);
|
||||||
EXPECT_EQ(5, b.length());
|
EXPECT_EQ(5, b.length());
|
||||||
EXPECT_EQ('i', b.bytes()[0]);
|
EXPECT_EQ('i', b.bytes()[0]);
|
||||||
EXPECT_EQ('n', b.bytes()[4]);
|
EXPECT_EQ('n', b.bytes()[4]);
|
||||||
|
|
||||||
b.erase(2);
|
b.erase(2);
|
||||||
EXPECT_EQ(3, b.length());
|
EXPECT_EQ(3, b.length());
|
||||||
EXPECT_EQ('l', b.bytes()[0]);
|
EXPECT_EQ('l', b.bytes()[0]);
|
||||||
EXPECT_EQ('n', b.bytes()[2]);
|
EXPECT_EQ('n', b.bytes()[2]);
|
||||||
|
|
||||||
|
b.erase(0);
|
||||||
|
b.erase(-1);
|
||||||
|
EXPECT_EQ(3, b.length());
|
||||||
|
|
||||||
b.erase(3);
|
b.erase(3);
|
||||||
EXPECT_EQ(0, b.length());
|
EXPECT_EQ(0, b.length());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue