正在显示
4 个修改的文件
包含
29 行增加
和
12 行删除
| @@ -79,8 +79,8 @@ int main(int argc, char** argv) | @@ -79,8 +79,8 @@ int main(int argc, char** argv) | ||
| 79 | printf("duration: %ds, timeout:%ds\n", duration, timeout); | 79 | printf("duration: %ds, timeout:%ds\n", duration, timeout); |
| 80 | 80 | ||
| 81 | if (duration <= 0 || timeout <= 0) { | 81 | if (duration <= 0 || timeout <= 0) { |
| 82 | - printf("duration and timeout must be positive.\n"); | ||
| 83 | ret = 1; | 82 | ret = 1; |
| 83 | + fprintf(stderr, "duration and timeout must be positive. ret=%d\n", ret); | ||
| 84 | exit(ret); | 84 | exit(ret); |
| 85 | return ret; | 85 | return ret; |
| 86 | } | 86 | } |
| @@ -88,33 +88,33 @@ int main(int argc, char** argv) | @@ -88,33 +88,33 @@ int main(int argc, char** argv) | ||
| 88 | rtmp = srs_rtmp_create(rtmp_url); | 88 | rtmp = srs_rtmp_create(rtmp_url); |
| 89 | 89 | ||
| 90 | if ((ret = __srs_dns_resolve(rtmp)) != 0) { | 90 | if ((ret = __srs_dns_resolve(rtmp)) != 0) { |
| 91 | - printf("dns resolve failed.\n"); | 91 | + fprintf(stderr, "dns resolve failed. ret=%d\n", ret); |
| 92 | goto rtmp_destroy; | 92 | goto rtmp_destroy; |
| 93 | } | 93 | } |
| 94 | printf("dns resolve success\n"); | 94 | printf("dns resolve success\n"); |
| 95 | time_dns_resolve = srs_get_time_ms(); | 95 | time_dns_resolve = srs_get_time_ms(); |
| 96 | 96 | ||
| 97 | if ((ret = __srs_connect_server(rtmp)) != 0) { | 97 | if ((ret = __srs_connect_server(rtmp)) != 0) { |
| 98 | - printf("socket connect failed.\n"); | 98 | + fprintf(stderr, "socket connect failed. ret=%d\n", ret); |
| 99 | goto rtmp_destroy; | 99 | goto rtmp_destroy; |
| 100 | } | 100 | } |
| 101 | printf("socket connect success\n"); | 101 | printf("socket connect success\n"); |
| 102 | time_socket_connect = srs_get_time_ms(); | 102 | time_socket_connect = srs_get_time_ms(); |
| 103 | 103 | ||
| 104 | if ((ret = __srs_do_simple_handshake(rtmp)) != 0) { | 104 | if ((ret = __srs_do_simple_handshake(rtmp)) != 0) { |
| 105 | - printf("do simple handshake failed.\n"); | 105 | + fprintf(stderr, "do simple handshake failed. ret=%d\n", ret); |
| 106 | goto rtmp_destroy; | 106 | goto rtmp_destroy; |
| 107 | } | 107 | } |
| 108 | printf("do simple handshake success\n"); | 108 | printf("do simple handshake success\n"); |
| 109 | 109 | ||
| 110 | if ((ret = srs_connect_app(rtmp)) != 0) { | 110 | if ((ret = srs_connect_app(rtmp)) != 0) { |
| 111 | - printf("connect vhost/app failed.\n"); | 111 | + fprintf(stderr, "connect vhost/app failed. ret=%d\n", ret); |
| 112 | goto rtmp_destroy; | 112 | goto rtmp_destroy; |
| 113 | } | 113 | } |
| 114 | printf("connect vhost/app success\n"); | 114 | printf("connect vhost/app success\n"); |
| 115 | 115 | ||
| 116 | if ((ret = srs_play_stream(rtmp)) != 0) { | 116 | if ((ret = srs_play_stream(rtmp)) != 0) { |
| 117 | - printf("play stream failed.\n"); | 117 | + fprintf(stderr, "play stream failed. ret=%d\n", ret); |
| 118 | goto rtmp_destroy; | 118 | goto rtmp_destroy; |
| 119 | } | 119 | } |
| 120 | printf("play stream success\n"); | 120 | printf("play stream success\n"); |
| @@ -122,6 +122,7 @@ int main(int argc, char** argv) | @@ -122,6 +122,7 @@ int main(int argc, char** argv) | ||
| 122 | 122 | ||
| 123 | for (;;) { | 123 | for (;;) { |
| 124 | if ((ret = srs_read_packet(rtmp, &type, ×tamp, &data, &size)) != 0) { | 124 | if ((ret = srs_read_packet(rtmp, &type, ×tamp, &data, &size)) != 0) { |
| 125 | + fprintf(stderr, "read packet failed. ret=%d\n", ret); | ||
| 125 | goto rtmp_destroy; | 126 | goto rtmp_destroy; |
| 126 | } | 127 | } |
| 127 | printf("got packet: type=%s, time=%d, size=%d\n", srs_type2string(type), timestamp, size); | 128 | printf("got packet: type=%s, time=%d, size=%d\n", srs_type2string(type), timestamp, size); |
| @@ -158,7 +159,7 @@ rtmp_destroy: | @@ -158,7 +159,7 @@ rtmp_destroy: | ||
| 158 | "\"%s\":%d, " // #6 | 159 | "\"%s\":%d, " // #6 |
| 159 | "\"%s\":%d, " // #7 | 160 | "\"%s\":%d, " // #7 |
| 160 | "\"%s\":%d, " // #8 | 161 | "\"%s\":%d, " // #8 |
| 161 | - "%s%s%s%s}", | 162 | + "%s,%s,%s,%s}", |
| 162 | "code", ret, //#0 | 163 | "code", ret, //#0 |
| 163 | // total = dns + tcp_connect + start_play + first_packet + last_packet | 164 | // total = dns + tcp_connect + start_play + first_packet + last_packet |
| 164 | "total", (int)(time_cleanup - time_startup), //#1 | 165 | "total", (int)(time_cleanup - time_startup), //#1 |
| @@ -173,12 +174,12 @@ rtmp_destroy: | @@ -173,12 +174,12 @@ rtmp_destroy: | ||
| 173 | // delay = actual - expect | 174 | // delay = actual - expect |
| 174 | "delay", (int)(timestamp - (time_cleanup - time_first_packet)), //#8 | 175 | "delay", (int)(timestamp - (time_cleanup - time_first_packet)), //#8 |
| 175 | // unit in ms. | 176 | // unit in ms. |
| 176 | - "\"unit\": \"ms\",", | ||
| 177 | - "\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\",", | 177 | + "\"unit\": \"ms\"", |
| 178 | + "\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\"", | ||
| 178 | "\"remark1\": \"delay = stream - (time_cleanup - time_first_packet)\"", | 179 | "\"remark1\": \"delay = stream - (time_cleanup - time_first_packet)\"", |
| 179 | "\"remark2\": \"if code is not 0, user must ignore all data\"" | 180 | "\"remark2\": \"if code is not 0, user must ignore all data\"" |
| 180 | ); | 181 | ); |
| 181 | printf("\n"); | 182 | printf("\n"); |
| 182 | 183 | ||
| 183 | - return 0; | 184 | + return ret; |
| 184 | } | 185 | } |
| @@ -58,7 +58,9 @@ char* SrsBuffer::bytes() | @@ -58,7 +58,9 @@ char* SrsBuffer::bytes() | ||
| 58 | 58 | ||
| 59 | void SrsBuffer::erase(int size) | 59 | void SrsBuffer::erase(int size) |
| 60 | { | 60 | { |
| 61 | - srs_assert(size > 0); | 61 | + if (size <= 0) { |
| 62 | + return; | ||
| 63 | + } | ||
| 62 | 64 | ||
| 63 | if (size >= length()) { | 65 | if (size >= length()) { |
| 64 | data.clear(); | 66 | data.clear(); |
| @@ -71,7 +71,7 @@ public: | @@ -71,7 +71,7 @@ public: | ||
| 71 | * erase size of bytes from begin. | 71 | * erase size of bytes from begin. |
| 72 | * @param size to erase size of bytes. | 72 | * @param size to erase size of bytes. |
| 73 | * clear if size greater than or equals to length() | 73 | * clear if size greater than or equals to length() |
| 74 | - * @remark assert size is positive. | 74 | + * @remark ignore size is not positive. |
| 75 | */ | 75 | */ |
| 76 | virtual void erase(int size); | 76 | virtual void erase(int size); |
| 77 | /** | 77 | /** |
| @@ -79,20 +79,34 @@ VOID TEST(BufferTest, EraseBytes) | @@ -79,20 +79,34 @@ VOID TEST(BufferTest, EraseBytes) | ||
| 79 | { | 79 | { |
| 80 | SrsBuffer b; | 80 | SrsBuffer b; |
| 81 | 81 | ||
| 82 | + b.erase(0); | ||
| 83 | + b.erase(-1); | ||
| 84 | + EXPECT_EQ(0, b.length()); | ||
| 85 | + | ||
| 82 | char winlin[] = "winlin"; | 86 | char winlin[] = "winlin"; |
| 83 | b.append(winlin, strlen(winlin)); | 87 | b.append(winlin, strlen(winlin)); |
| 84 | b.erase(b.length()); | 88 | b.erase(b.length()); |
| 85 | EXPECT_EQ(0, b.length()); | 89 | EXPECT_EQ(0, b.length()); |
| 86 | 90 | ||
| 91 | + b.erase(0); | ||
| 92 | + b.erase(-1); | ||
| 93 | + EXPECT_EQ(0, b.length()); | ||
| 94 | + | ||
| 87 | b.append(winlin, strlen(winlin)); | 95 | b.append(winlin, strlen(winlin)); |
| 88 | b.erase(1); | 96 | b.erase(1); |
| 89 | EXPECT_EQ(5, b.length()); | 97 | EXPECT_EQ(5, b.length()); |
| 90 | EXPECT_EQ('i', b.bytes()[0]); | 98 | EXPECT_EQ('i', b.bytes()[0]); |
| 91 | EXPECT_EQ('n', b.bytes()[4]); | 99 | EXPECT_EQ('n', b.bytes()[4]); |
| 100 | + | ||
| 92 | b.erase(2); | 101 | b.erase(2); |
| 93 | EXPECT_EQ(3, b.length()); | 102 | EXPECT_EQ(3, b.length()); |
| 94 | EXPECT_EQ('l', b.bytes()[0]); | 103 | EXPECT_EQ('l', b.bytes()[0]); |
| 95 | EXPECT_EQ('n', b.bytes()[2]); | 104 | EXPECT_EQ('n', b.bytes()[2]); |
| 105 | + | ||
| 106 | + b.erase(0); | ||
| 107 | + b.erase(-1); | ||
| 108 | + EXPECT_EQ(3, b.length()); | ||
| 109 | + | ||
| 96 | b.erase(3); | 110 | b.erase(3); |
| 97 | EXPECT_EQ(0, b.length()); | 111 | EXPECT_EQ(0, b.length()); |
| 98 | } | 112 | } |
-
请 注册 或 登录 后发表评论