1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

fix bug of detect rtmp, add error code

This commit is contained in:
winlin 2014-06-10 11:57:46 +08:00
parent 4d9ed6f7fe
commit d48d739fa7
3 changed files with 19 additions and 13 deletions

View file

@ -31,6 +31,7 @@ gcc srs_detect_rtmp.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_detect
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int ret = 0;
srs_rtmp_t rtmp; srs_rtmp_t rtmp;
// time // time
@ -62,7 +63,7 @@ int main(int argc, char** argv)
"For example:\n" "For example:\n"
" %s rtmp://127.0.0.1:1935/live/livestream 3 10\n", " %s rtmp://127.0.0.1:1935/live/livestream 3 10\n",
argv[0]); argv[0]);
int ret = 1; ret = 1;
exit(ret); exit(ret);
return ret; return ret;
} }
@ -79,39 +80,40 @@ int main(int argc, char** argv)
if (duration <= 0 || timeout <= 0) { if (duration <= 0 || timeout <= 0) {
printf("duration and timeout must be positive.\n"); printf("duration and timeout must be positive.\n");
exit(1); ret = 1;
return 1; exit(ret);
return ret;
} }
rtmp = srs_rtmp_create(rtmp_url); rtmp = srs_rtmp_create(rtmp_url);
if (__srs_dns_resolve(rtmp) != 0) { if ((ret = __srs_dns_resolve(rtmp)) != 0) {
printf("dns resolve failed.\n"); printf("dns resolve failed.\n");
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 (__srs_connect_server(rtmp) != 0) { if ((ret = __srs_connect_server(rtmp)) != 0) {
printf("socket connect failed.\n"); printf("socket connect failed.\n");
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 (__srs_do_simple_handshake(rtmp) != 0) { if ((ret = __srs_do_simple_handshake(rtmp)) != 0) {
printf("do simple handshake failed.\n"); printf("do simple handshake failed.\n");
goto rtmp_destroy; goto rtmp_destroy;
} }
printf("do simple handshake success\n"); printf("do simple handshake success\n");
if (srs_connect_app(rtmp) != 0) { if ((ret = srs_connect_app(rtmp)) != 0) {
printf("connect vhost/app failed.\n"); printf("connect vhost/app failed.\n");
goto rtmp_destroy; goto rtmp_destroy;
} }
printf("connect vhost/app success\n"); printf("connect vhost/app success\n");
if (srs_play_stream(rtmp) != 0) { if ((ret = srs_play_stream(rtmp)) != 0) {
printf("play stream failed.\n"); printf("play stream failed.\n");
goto rtmp_destroy; goto rtmp_destroy;
} }
@ -119,7 +121,7 @@ int main(int argc, char** argv)
time_play_stream = srs_get_time_ms(); time_play_stream = srs_get_time_ms();
for (;;) { for (;;) {
if (srs_read_packet(rtmp, &type, &timestamp, &data, &size) != 0) { if ((ret = srs_read_packet(rtmp, &type, &timestamp, &data, &size)) != 0) {
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);
@ -147,6 +149,7 @@ rtmp_destroy:
// print result to stderr. // print result to stderr.
fprintf(stderr, "{" fprintf(stderr, "{"
"\"%s\":%d, " //#0
"\"%s\":%d, " //#1 "\"%s\":%d, " //#1
"\"%s\":%d, " // #2 "\"%s\":%d, " // #2
"\"%s\":%d, " // #3 "\"%s\":%d, " // #3
@ -155,7 +158,8 @@ 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}",
"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
"dns", (int)(time_dns_resolve - time_startup), //#2 "dns", (int)(time_dns_resolve - time_startup), //#2
@ -171,7 +175,8 @@ rtmp_destroy:
// 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\""
); );
printf("\n"); printf("\n");

View file

@ -51,6 +51,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define ERROR_SOCKET_WRITE 209 #define ERROR_SOCKET_WRITE 209
#define ERROR_SOCKET_WAIT 210 #define ERROR_SOCKET_WAIT 210
#define ERROR_SOCKET_TIMEOUT 211 #define ERROR_SOCKET_TIMEOUT 211
#define ERROR_SOCKET_CONNECT 212
//#define ERROR_SOCKET_GET_LOCAL_IP 212 //#define ERROR_SOCKET_GET_LOCAL_IP 212
#define ERROR_RTMP_PLAIN_REQUIRED 300 #define ERROR_RTMP_PLAIN_REQUIRED 300

View file

@ -57,7 +57,7 @@ SimpleSocketStream::~SimpleSocketStream()
int SimpleSocketStream::create_socket() int SimpleSocketStream::create_socket()
{ {
if((fd = ::socket(AF_INET, SOCK_STREAM, 0)) < 0){ if((fd = ::socket(AF_INET, SOCK_STREAM, 0)) < 0){
return -1; return ERROR_SOCKET_CREATE;
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;
@ -71,7 +71,7 @@ int SimpleSocketStream::connect(const char* server_ip, int port)
addr.sin_addr.s_addr = inet_addr(server_ip); addr.sin_addr.s_addr = inet_addr(server_ip);
if(::connect(fd, (const struct sockaddr*)&addr, sizeof(sockaddr_in)) < 0){ if(::connect(fd, (const struct sockaddr*)&addr, sizeof(sockaddr_in)) < 0){
return -1; return ERROR_SOCKET_CONNECT;
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;