winlin

fix bug of buffer assert, erase can accept any value

... ... @@ -79,8 +79,8 @@ int main(int argc, char** argv)
printf("duration: %ds, timeout:%ds\n", duration, timeout);
if (duration <= 0 || timeout <= 0) {
printf("duration and timeout must be positive.\n");
ret = 1;
fprintf(stderr, "duration and timeout must be positive. ret=%d\n", ret);
exit(ret);
return ret;
}
... ... @@ -88,33 +88,33 @@ int main(int argc, char** argv)
rtmp = srs_rtmp_create(rtmp_url);
if ((ret = __srs_dns_resolve(rtmp)) != 0) {
printf("dns resolve failed.\n");
fprintf(stderr, "dns resolve failed. ret=%d\n", ret);
goto rtmp_destroy;
}
printf("dns resolve success\n");
time_dns_resolve = srs_get_time_ms();
if ((ret = __srs_connect_server(rtmp)) != 0) {
printf("socket connect failed.\n");
fprintf(stderr, "socket connect failed. ret=%d\n", ret);
goto rtmp_destroy;
}
printf("socket connect success\n");
time_socket_connect = srs_get_time_ms();
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;
}
printf("do simple handshake success\n");
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;
}
printf("connect vhost/app success\n");
if ((ret = srs_play_stream(rtmp)) != 0) {
printf("play stream failed.\n");
fprintf(stderr, "play stream failed. ret=%d\n", ret);
goto rtmp_destroy;
}
printf("play stream success\n");
... ... @@ -122,6 +122,7 @@ int main(int argc, char** argv)
for (;;) {
if ((ret = srs_read_packet(rtmp, &type, &timestamp, &data, &size)) != 0) {
fprintf(stderr, "read packet failed. ret=%d\n", ret);
goto rtmp_destroy;
}
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, " // #7
"\"%s\":%d, " // #8
"%s%s%s%s}",
"%s,%s,%s,%s}",
"code", ret, //#0
// total = dns + tcp_connect + start_play + first_packet + last_packet
"total", (int)(time_cleanup - time_startup), //#1
... ... @@ -173,12 +174,12 @@ rtmp_destroy:
// delay = actual - expect
"delay", (int)(timestamp - (time_cleanup - time_first_packet)), //#8
// unit in ms.
"\"unit\": \"ms\",",
"\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\",",
"\"unit\": \"ms\"",
"\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\"",
"\"remark1\": \"delay = stream - (time_cleanup - time_first_packet)\"",
"\"remark2\": \"if code is not 0, user must ignore all data\""
);
printf("\n");
return 0;
return ret;
}
... ...
... ... @@ -58,7 +58,9 @@ char* SrsBuffer::bytes()
void SrsBuffer::erase(int size)
{
srs_assert(size > 0);
if (size <= 0) {
return;
}
if (size >= length()) {
data.clear();
... ...
... ... @@ -71,7 +71,7 @@ public:
* erase size of bytes from begin.
* @param size to erase size of bytes.
* 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);
/**
... ...
... ... @@ -79,20 +79,34 @@ VOID TEST(BufferTest, EraseBytes)
{
SrsBuffer b;
b.erase(0);
b.erase(-1);
EXPECT_EQ(0, b.length());
char winlin[] = "winlin";
b.append(winlin, strlen(winlin));
b.erase(b.length());
EXPECT_EQ(0, b.length());
b.erase(0);
b.erase(-1);
EXPECT_EQ(0, b.length());
b.append(winlin, strlen(winlin));
b.erase(1);
EXPECT_EQ(5, b.length());
EXPECT_EQ('i', b.bytes()[0]);
EXPECT_EQ('n', b.bytes()[4]);
b.erase(2);
EXPECT_EQ(3, b.length());
EXPECT_EQ('l', b.bytes()[0]);
EXPECT_EQ('n', b.bytes()[2]);
b.erase(0);
b.erase(-1);
EXPECT_EQ(3, b.length());
b.erase(3);
EXPECT_EQ(0, b.length());
}
... ...