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

refine ingester log.

This commit is contained in:
winlin 2016-01-13 16:20:05 +08:00
parent dfe5306327
commit f8358da316
3 changed files with 103 additions and 28 deletions

View file

@ -34,6 +34,11 @@ int connect_ic(srs_rtmp_t irtmp);
int connect_oc(srs_rtmp_t ortmp);
int proxy(srs_rtmp_t irtmp, srs_rtmp_t ortmp);
// whether use verbose log.
int verbose = 0;
// 2000 is about 30s.
#define PITHY_PRINT_EVERY_MSGS 2000
int main(int argc, char** argv)
{
int ret = 0;
@ -46,18 +51,19 @@ int main(int argc, char** argv)
// rtmp handler
srs_rtmp_t irtmp, ortmp;
printf("ingest RTMP and publish to RTMP server like edge.\n");
printf("srs(ossrs) client librtmp library.\n");
printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision());
printf("Ingest RTMP to server like FFMPEG over srs-librtmp %d.%d.%d\n",
srs_version_major(), srs_version_minor(), srs_version_revision());
if (argc <= 2) {
printf("ingest RTMP and publish to RTMP server\n"
"Usage: %s <-i in_rtmp_url> <-y out_rtmp_url>\n"
"Usage: %s <-i in_rtmp_url> <-y out_rtmp_url> [-v verbose]\n"
" in_rtmp_url input rtmp url, ingest from this url.\n"
" out_rtmp_url output rtmp url, publish to this url.\n"
" verbose output verbose log.\n"
"For example:\n"
" %s -i rtmp://127.0.0.1/live/livestream -y rtmp://127.0.0.1/live/demo\n",
argv[0], argv[0]);
" %s -i rtmp://127.0.0.1/live/livestream -y rtmp://127.0.0.1/live/demo\n"
" %s -i rtmp://127.0.0.1/live/livestream -y rtmp://127.0.0.1/live/demo -v verbose\n",
argv[0], argv[0], argv[0]);
exit(-1);
}
@ -73,8 +79,9 @@ int main(int argc, char** argv)
// parse according the option name.
switch (p[1]) {
case 'i': in_rtmp_url = argv[opt + 1]; break;
case 'y': out_rtmp_url = argv[opt + 1]; break;
case 'i': in_rtmp_url = argv[++opt]; break;
case 'y': out_rtmp_url = argv[++opt]; break;
case 'v': verbose=1; opt++; break;
default: break;
}
}
@ -88,8 +95,7 @@ int main(int argc, char** argv)
return -1;
}
srs_human_trace("input: %s", in_rtmp_url);
srs_human_trace("output: %s", out_rtmp_url);
srs_human_trace("ingest %s to %s, verbose=%d", in_rtmp_url, out_rtmp_url, verbose);
irtmp = srs_rtmp_create(in_rtmp_url);
ortmp = srs_rtmp_create(out_rtmp_url);
@ -112,6 +118,7 @@ int proxy(srs_rtmp_t irtmp, srs_rtmp_t ortmp)
char type;
char* data;
u_int32_t timestamp;
u_int64_t nb_msgs = 0;
if ((ret = connect_ic(irtmp)) != 0) {
return ret;
@ -120,7 +127,11 @@ int proxy(srs_rtmp_t irtmp, srs_rtmp_t ortmp)
return ret;
}
if (verbose) {
srs_human_trace("start proxy RTMP stream");
} else {
srs_human_verbose("start proxy RTMP stream");
}
for (;;) {
if ((ret = srs_rtmp_read_packet(irtmp, &type, &timestamp, &data, &size)) != 0) {
srs_human_trace("irtmp get packet failed. ret=%d", ret);
@ -128,23 +139,35 @@ int proxy(srs_rtmp_t irtmp, srs_rtmp_t ortmp)
}
if (!srs_utils_flv_tag_is_ok(type)) {
if (verbose) {
srs_human_trace("ignore invalid flv tag=%d, dts=%d, %d bytes", type, timestamp, size);
} else {
srs_human_verbose("ignore invalid flv tag=%d, dts=%d, %d bytes", type, timestamp, size);
}
free(data);
continue;
}
if (verbose || ((nb_msgs++ % PITHY_PRINT_EVERY_MSGS) == 0 && nb_msgs > 10)) {
if ((ret = srs_human_print_rtmp_packet(type, timestamp, data, size)) != 0) {
srs_human_trace("print packet failed. ret=%d", ret);
return ret;
}
}
if ((ret = srs_rtmp_write_packet(ortmp, type, timestamp, data, size)) != 0) {
srs_human_trace("irtmp get packet failed. ret=%d", ret);
return ret;
}
if (verbose) {
srs_human_trace("ortmp sent packet: type=%s, time=%d, size=%d",
srs_human_flv_tag_type2string(type), timestamp, size);
} else {
srs_human_verbose("ortmp sent packet: type=%s, time=%d, size=%d",
srs_human_flv_tag_type2string(type), timestamp, size);
}
}
return ret;
}
@ -153,23 +176,49 @@ int connect_ic(srs_rtmp_t irtmp)
{
int ret = 0;
// srs debug info.
char srs_server_ip[128];
char srs_server[128];
char srs_primary[128];
char srs_authors[128];
char srs_version[32];
int srs_id = 0;
int srs_pid = 0;
// set to zero.
srs_server_ip[0] = 0;
srs_server[0] = 0;
srs_primary[0] = 0;
srs_authors[0] = 0;
srs_version[0] = 0;
if ((ret = srs_rtmp_handshake(irtmp)) != 0) {
srs_human_trace("irtmp simple handshake failed. ret=%d", ret);
return ret;
}
if (verbose) {
srs_human_trace("irtmp simple handshake success");
} else {
srs_human_verbose("irtmp simple handshake success");
}
if ((ret = srs_rtmp_connect_app(irtmp)) != 0) {
if (srs_rtmp_connect_app2(irtmp,
srs_server_ip, srs_server, srs_primary, srs_authors, srs_version,
&srs_id, &srs_pid) != 0) {
srs_human_trace("irtmp connect vhost/app failed. ret=%d", ret);
return ret;
}
srs_human_trace("irtmp connect vhost/app success");
srs_human_trace("irtmp connect ok, ip=%s, server=%s/%s, pid=%d, cid=%d", srs_server_ip, srs_server, srs_version, srs_pid, srs_id);
if ((ret = srs_rtmp_play_stream(irtmp)) != 0) {
srs_human_trace("irtmp play stream failed. ret=%d", ret);
return ret;
}
if (verbose) {
srs_human_trace("irtmp play stream success");
} else {
srs_human_verbose("irtmp play stream success");
}
return ret;
}
@ -178,23 +227,49 @@ int connect_oc(srs_rtmp_t ortmp)
{
int ret = 0;
// srs debug info.
char srs_server_ip[128];
char srs_server[128];
char srs_primary[128];
char srs_authors[128];
char srs_version[32];
int srs_id = 0;
int srs_pid = 0;
// set to zero.
srs_server_ip[0] = 0;
srs_server[0] = 0;
srs_primary[0] = 0;
srs_authors[0] = 0;
srs_version[0] = 0;
if ((ret = srs_rtmp_handshake(ortmp)) != 0) {
srs_human_trace("ortmp simple handshake failed. ret=%d", ret);
return ret;
}
if (verbose) {
srs_human_trace("ortmp simple handshake success");
} else {
srs_human_verbose("ortmp simple handshake success");
}
if ((ret = srs_rtmp_connect_app(ortmp)) != 0) {
if (srs_rtmp_connect_app2(ortmp,
srs_server_ip, srs_server, srs_primary, srs_authors, srs_version,
&srs_id, &srs_pid) != 0) {
srs_human_trace("ortmp connect vhost/app failed. ret=%d", ret);
return ret;
}
srs_human_trace("ortmp connect vhost/app success");
srs_human_trace("ortmp connect ok, ip=%s, server=%s/%s, pid=%d, cid=%d", srs_server_ip, srs_server, srs_version, srs_pid, srs_id);
if ((ret = srs_rtmp_publish_stream(ortmp)) != 0) {
srs_human_trace("ortmp publish stream failed. ret=%d", ret);
return ret;
}
if (verbose) {
srs_human_trace("ortmp publish stream success");
} else {
srs_human_verbose("ortmp publish stream success");
}
return ret;
}

View file

@ -2410,7 +2410,7 @@ int srs_human_print_rtmp_packet4(char type, u_int32_t timestamp, char* data, int
srs_human_flv_audio_aac_packet_type2string(srs_utils_flv_audio_aac_packet_type(data, size))
);
} else if (type == SRS_RTMP_TYPE_SCRIPT) {
srs_human_verbose("Data packet id=%"PRId64"/%.1f/%.1f, type=%s, time=%d, ndiff=%d, diff=%d, size=%d",
srs_human_trace("Data packet id=%"PRId64"/%.1f/%.1f, type=%s, time=%d, ndiff=%d, diff=%d, size=%d",
nb_packets, pi, gfps, srs_human_flv_tag_type2string(type), timestamp, ndiff, diff, size);
int nparsed = 0;
while (nparsed < size) {

View file

@ -956,7 +956,7 @@ extern const char* srs_human_format_time();
#define srs_human_raw(msg, ...) (void)0
#else
#define srs_human_trace(msg, ...) printf("[%s][%d] ", srs_human_format_time(), getpid());printf(msg, ##__VA_ARGS__);printf("\n")
#define srs_human_verbose(msg, ...) printf("[%s][%d] ", srs_human_format_time(), getpid());printf(msg, ##__VA_ARGS__);printf("\n")
#define srs_human_verbose(msg, ...) (void)0
#define srs_human_raw(msg, ...) printf(msg, ##__VA_ARGS__)
#endif