正在显示
3 个修改的文件
包含
19 行增加
和
13 行删除
| @@ -31,6 +31,7 @@ gcc srs_detect_rtmp.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_detect | @@ -31,6 +31,7 @@ gcc srs_detect_rtmp.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_detect | ||
| 31 | 31 | ||
| 32 | int main(int argc, char** argv) | 32 | int main(int argc, char** argv) |
| 33 | { | 33 | { |
| 34 | + int ret = 0; | ||
| 34 | srs_rtmp_t rtmp; | 35 | srs_rtmp_t rtmp; |
| 35 | 36 | ||
| 36 | // time | 37 | // time |
| @@ -62,7 +63,7 @@ int main(int argc, char** argv) | @@ -62,7 +63,7 @@ int main(int argc, char** argv) | ||
| 62 | "For example:\n" | 63 | "For example:\n" |
| 63 | " %s rtmp://127.0.0.1:1935/live/livestream 3 10\n", | 64 | " %s rtmp://127.0.0.1:1935/live/livestream 3 10\n", |
| 64 | argv[0]); | 65 | argv[0]); |
| 65 | - int ret = 1; | 66 | + ret = 1; |
| 66 | exit(ret); | 67 | exit(ret); |
| 67 | return ret; | 68 | return ret; |
| 68 | } | 69 | } |
| @@ -79,39 +80,40 @@ int main(int argc, char** argv) | @@ -79,39 +80,40 @@ int main(int argc, char** argv) | ||
| 79 | 80 | ||
| 80 | if (duration <= 0 || timeout <= 0) { | 81 | if (duration <= 0 || timeout <= 0) { |
| 81 | printf("duration and timeout must be positive.\n"); | 82 | printf("duration and timeout must be positive.\n"); |
| 82 | - exit(1); | ||
| 83 | - return 1; | 83 | + ret = 1; |
| 84 | + exit(ret); | ||
| 85 | + return ret; | ||
| 84 | } | 86 | } |
| 85 | 87 | ||
| 86 | rtmp = srs_rtmp_create(rtmp_url); | 88 | rtmp = srs_rtmp_create(rtmp_url); |
| 87 | 89 | ||
| 88 | - if (__srs_dns_resolve(rtmp) != 0) { | 90 | + if ((ret = __srs_dns_resolve(rtmp)) != 0) { |
| 89 | printf("dns resolve failed.\n"); | 91 | printf("dns resolve failed.\n"); |
| 90 | goto rtmp_destroy; | 92 | goto rtmp_destroy; |
| 91 | } | 93 | } |
| 92 | printf("dns resolve success\n"); | 94 | printf("dns resolve success\n"); |
| 93 | time_dns_resolve = srs_get_time_ms(); | 95 | time_dns_resolve = srs_get_time_ms(); |
| 94 | 96 | ||
| 95 | - if (__srs_connect_server(rtmp) != 0) { | 97 | + if ((ret = __srs_connect_server(rtmp)) != 0) { |
| 96 | printf("socket connect failed.\n"); | 98 | printf("socket connect failed.\n"); |
| 97 | goto rtmp_destroy; | 99 | goto rtmp_destroy; |
| 98 | } | 100 | } |
| 99 | printf("socket connect success\n"); | 101 | printf("socket connect success\n"); |
| 100 | time_socket_connect = srs_get_time_ms(); | 102 | time_socket_connect = srs_get_time_ms(); |
| 101 | 103 | ||
| 102 | - if (__srs_do_simple_handshake(rtmp) != 0) { | 104 | + if ((ret = __srs_do_simple_handshake(rtmp)) != 0) { |
| 103 | printf("do simple handshake failed.\n"); | 105 | printf("do simple handshake failed.\n"); |
| 104 | goto rtmp_destroy; | 106 | goto rtmp_destroy; |
| 105 | } | 107 | } |
| 106 | printf("do simple handshake success\n"); | 108 | printf("do simple handshake success\n"); |
| 107 | 109 | ||
| 108 | - if (srs_connect_app(rtmp) != 0) { | 110 | + if ((ret = srs_connect_app(rtmp)) != 0) { |
| 109 | printf("connect vhost/app failed.\n"); | 111 | printf("connect vhost/app failed.\n"); |
| 110 | goto rtmp_destroy; | 112 | goto rtmp_destroy; |
| 111 | } | 113 | } |
| 112 | printf("connect vhost/app success\n"); | 114 | printf("connect vhost/app success\n"); |
| 113 | 115 | ||
| 114 | - if (srs_play_stream(rtmp) != 0) { | 116 | + if ((ret = srs_play_stream(rtmp)) != 0) { |
| 115 | printf("play stream failed.\n"); | 117 | printf("play stream failed.\n"); |
| 116 | goto rtmp_destroy; | 118 | goto rtmp_destroy; |
| 117 | } | 119 | } |
| @@ -119,7 +121,7 @@ int main(int argc, char** argv) | @@ -119,7 +121,7 @@ int main(int argc, char** argv) | ||
| 119 | time_play_stream = srs_get_time_ms(); | 121 | time_play_stream = srs_get_time_ms(); |
| 120 | 122 | ||
| 121 | for (;;) { | 123 | for (;;) { |
| 122 | - if (srs_read_packet(rtmp, &type, ×tamp, &data, &size) != 0) { | 124 | + if ((ret = srs_read_packet(rtmp, &type, ×tamp, &data, &size)) != 0) { |
| 123 | goto rtmp_destroy; | 125 | goto rtmp_destroy; |
| 124 | } | 126 | } |
| 125 | printf("got packet: type=%s, time=%d, size=%d\n", srs_type2string(type), timestamp, size); | 127 | printf("got packet: type=%s, time=%d, size=%d\n", srs_type2string(type), timestamp, size); |
| @@ -147,6 +149,7 @@ rtmp_destroy: | @@ -147,6 +149,7 @@ rtmp_destroy: | ||
| 147 | 149 | ||
| 148 | // print result to stderr. | 150 | // print result to stderr. |
| 149 | fprintf(stderr, "{" | 151 | fprintf(stderr, "{" |
| 152 | + "\"%s\":%d, " //#0 | ||
| 150 | "\"%s\":%d, " //#1 | 153 | "\"%s\":%d, " //#1 |
| 151 | "\"%s\":%d, " // #2 | 154 | "\"%s\":%d, " // #2 |
| 152 | "\"%s\":%d, " // #3 | 155 | "\"%s\":%d, " // #3 |
| @@ -155,7 +158,8 @@ rtmp_destroy: | @@ -155,7 +158,8 @@ rtmp_destroy: | ||
| 155 | "\"%s\":%d, " // #6 | 158 | "\"%s\":%d, " // #6 |
| 156 | "\"%s\":%d, " // #7 | 159 | "\"%s\":%d, " // #7 |
| 157 | "\"%s\":%d, " // #8 | 160 | "\"%s\":%d, " // #8 |
| 158 | - "%s%s%s}", | 161 | + "%s%s%s%s}", |
| 162 | + "code", ret, //#0 | ||
| 159 | // total = dns + tcp_connect + start_play + first_packet + last_packet | 163 | // total = dns + tcp_connect + start_play + first_packet + last_packet |
| 160 | "total", (int)(time_cleanup - time_startup), //#1 | 164 | "total", (int)(time_cleanup - time_startup), //#1 |
| 161 | "dns", (int)(time_dns_resolve - time_startup), //#2 | 165 | "dns", (int)(time_dns_resolve - time_startup), //#2 |
| @@ -171,7 +175,8 @@ rtmp_destroy: | @@ -171,7 +175,8 @@ rtmp_destroy: | ||
| 171 | // unit in ms. | 175 | // unit in ms. |
| 172 | "\"unit\": \"ms\",", | 176 | "\"unit\": \"ms\",", |
| 173 | "\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\",", | 177 | "\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\",", |
| 174 | - "\"remark1\": \"delay = stream - (time_cleanup - time_first_packet)\"" | 178 | + "\"remark1\": \"delay = stream - (time_cleanup - time_first_packet)\"", |
| 179 | + "\"remark2\": \"if code is not 0, user must ignore all data\"" | ||
| 175 | ); | 180 | ); |
| 176 | printf("\n"); | 181 | printf("\n"); |
| 177 | 182 |
| @@ -51,6 +51,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -51,6 +51,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 51 | #define ERROR_SOCKET_WRITE 209 | 51 | #define ERROR_SOCKET_WRITE 209 |
| 52 | #define ERROR_SOCKET_WAIT 210 | 52 | #define ERROR_SOCKET_WAIT 210 |
| 53 | #define ERROR_SOCKET_TIMEOUT 211 | 53 | #define ERROR_SOCKET_TIMEOUT 211 |
| 54 | +#define ERROR_SOCKET_CONNECT 212 | ||
| 54 | //#define ERROR_SOCKET_GET_LOCAL_IP 212 | 55 | //#define ERROR_SOCKET_GET_LOCAL_IP 212 |
| 55 | 56 | ||
| 56 | #define ERROR_RTMP_PLAIN_REQUIRED 300 | 57 | #define ERROR_RTMP_PLAIN_REQUIRED 300 |
| @@ -57,7 +57,7 @@ SimpleSocketStream::~SimpleSocketStream() | @@ -57,7 +57,7 @@ SimpleSocketStream::~SimpleSocketStream() | ||
| 57 | int SimpleSocketStream::create_socket() | 57 | int SimpleSocketStream::create_socket() |
| 58 | { | 58 | { |
| 59 | if((fd = ::socket(AF_INET, SOCK_STREAM, 0)) < 0){ | 59 | if((fd = ::socket(AF_INET, SOCK_STREAM, 0)) < 0){ |
| 60 | - return -1; | 60 | + return ERROR_SOCKET_CREATE; |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | return ERROR_SUCCESS; | 63 | return ERROR_SUCCESS; |
| @@ -71,7 +71,7 @@ int SimpleSocketStream::connect(const char* server_ip, int port) | @@ -71,7 +71,7 @@ int SimpleSocketStream::connect(const char* server_ip, int port) | ||
| 71 | addr.sin_addr.s_addr = inet_addr(server_ip); | 71 | addr.sin_addr.s_addr = inet_addr(server_ip); |
| 72 | 72 | ||
| 73 | if(::connect(fd, (const struct sockaddr*)&addr, sizeof(sockaddr_in)) < 0){ | 73 | if(::connect(fd, (const struct sockaddr*)&addr, sizeof(sockaddr_in)) < 0){ |
| 74 | - return -1; | 74 | + return ERROR_SOCKET_CONNECT; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | return ERROR_SUCCESS; | 77 | return ERROR_SUCCESS; |
-
请 注册 或 登录 后发表评论