add packets interval in ms to set the right send_min_interval
正在显示
9 个修改的文件
包含
48 行增加
和
22 行删除
| @@ -875,8 +875,9 @@ vhost stream.control.com { | @@ -875,8 +875,9 @@ vhost stream.control.com { | ||
| 875 | # delivery packets in constant interval(not cbr). | 875 | # delivery packets in constant interval(not cbr). |
| 876 | # @remark 0 to disable the minimal interval. | 876 | # @remark 0 to disable the minimal interval. |
| 877 | # @remark >0 to make the srs to send message one by one. | 877 | # @remark >0 to make the srs to send message one by one. |
| 878 | + # @remark user can get the right packets interval in ms by srs_rtmp_dump. | ||
| 878 | # default: 0 | 879 | # default: 0 |
| 879 | - send_min_interval 10; | 880 | + send_min_interval 10.0; |
| 880 | # whether reduce the sequence header, | 881 | # whether reduce the sequence header, |
| 881 | # for some client which cannot got duplicated sequence header, | 882 | # for some client which cannot got duplicated sequence header, |
| 882 | # while the sequence header is not changed yet. | 883 | # while the sequence header is not changed yet. |
| @@ -256,8 +256,10 @@ int main(int argc, char** argv) | @@ -256,8 +256,10 @@ int main(int argc, char** argv) | ||
| 256 | } | 256 | } |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | + int64_t nb_packets = 0; | ||
| 259 | u_int32_t pre_timestamp = 0; | 260 | u_int32_t pre_timestamp = 0; |
| 260 | int64_t pre_now = srs_utils_time_ms(); | 261 | int64_t pre_now = srs_utils_time_ms(); |
| 262 | + int64_t start_time = pre_now; | ||
| 261 | for (;;) { | 263 | for (;;) { |
| 262 | int size; | 264 | int size; |
| 263 | char type; | 265 | char type; |
| @@ -269,7 +271,7 @@ int main(int argc, char** argv) | @@ -269,7 +271,7 @@ int main(int argc, char** argv) | ||
| 269 | goto rtmp_destroy; | 271 | goto rtmp_destroy; |
| 270 | } | 272 | } |
| 271 | 273 | ||
| 272 | - if (srs_human_print_rtmp_packet3(type, timestamp, data, size, pre_timestamp, pre_now) != 0) { | 274 | + if (srs_human_print_rtmp_packet4(type, timestamp, data, size, pre_timestamp, pre_now, start_time, nb_packets++) != 0) { |
| 273 | srs_human_trace("print rtmp packet failed."); | 275 | srs_human_trace("print rtmp packet failed."); |
| 274 | goto rtmp_destroy; | 276 | goto rtmp_destroy; |
| 275 | } | 277 | } |
| @@ -2518,9 +2518,9 @@ bool SrsConfig::get_tcp_nodelay(string vhost) | @@ -2518,9 +2518,9 @@ bool SrsConfig::get_tcp_nodelay(string vhost) | ||
| 2518 | return SRS_CONF_PERFER_FALSE(conf->arg0()); | 2518 | return SRS_CONF_PERFER_FALSE(conf->arg0()); |
| 2519 | } | 2519 | } |
| 2520 | 2520 | ||
| 2521 | -int SrsConfig::get_send_min_interval(string vhost) | 2521 | +double SrsConfig::get_send_min_interval(string vhost) |
| 2522 | { | 2522 | { |
| 2523 | - static int DEFAULT = 0; | 2523 | + static double DEFAULT = 0.0; |
| 2524 | 2524 | ||
| 2525 | SrsConfDirective* conf = get_vhost(vhost); | 2525 | SrsConfDirective* conf = get_vhost(vhost); |
| 2526 | if (!conf) { | 2526 | if (!conf) { |
| @@ -2532,7 +2532,7 @@ int SrsConfig::get_send_min_interval(string vhost) | @@ -2532,7 +2532,7 @@ int SrsConfig::get_send_min_interval(string vhost) | ||
| 2532 | return DEFAULT; | 2532 | return DEFAULT; |
| 2533 | } | 2533 | } |
| 2534 | 2534 | ||
| 2535 | - return ::atoi(conf->arg0().c_str()); | 2535 | + return ::atof(conf->arg0().c_str()); |
| 2536 | } | 2536 | } |
| 2537 | 2537 | ||
| 2538 | bool SrsConfig::get_reduce_sequence_header(string vhost) | 2538 | bool SrsConfig::get_reduce_sequence_header(string vhost) |
| @@ -529,7 +529,7 @@ public: | @@ -529,7 +529,7 @@ public: | ||
| 529 | /** | 529 | /** |
| 530 | * the minimal send interval in ms. | 530 | * the minimal send interval in ms. |
| 531 | */ | 531 | */ |
| 532 | - virtual int get_send_min_interval(std::string vhost); | 532 | + virtual double get_send_min_interval(std::string vhost); |
| 533 | /** | 533 | /** |
| 534 | * whether reduce the sequence header. | 534 | * whether reduce the sequence header. |
| 535 | */ | 535 | */ |
| @@ -256,9 +256,9 @@ int SrsRtmpConn::on_reload_vhost_smi(string vhost) | @@ -256,9 +256,9 @@ int SrsRtmpConn::on_reload_vhost_smi(string vhost) | ||
| 256 | return ret; | 256 | return ret; |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | - int smi = _srs_config->get_send_min_interval(vhost); | 259 | + double smi = _srs_config->get_send_min_interval(vhost); |
| 260 | if (smi != send_min_interval) { | 260 | if (smi != send_min_interval) { |
| 261 | - srs_trace("apply smi %d=>%d", send_min_interval, smi); | 261 | + srs_trace("apply smi %.2f=>%.2f", send_min_interval, smi); |
| 262 | send_min_interval = smi; | 262 | send_min_interval = smi; |
| 263 | } | 263 | } |
| 264 | 264 | ||
| @@ -615,7 +615,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe | @@ -615,7 +615,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe | ||
| 615 | // set the sock options. | 615 | // set the sock options. |
| 616 | set_sock_options(); | 616 | set_sock_options(); |
| 617 | 617 | ||
| 618 | - srs_trace("start play smi=%d, mw_sleep=%d, mw_enabled=%d, realtime=%d", | 618 | + srs_trace("start play smi=%.2f, mw_sleep=%d, mw_enabled=%d, realtime=%d", |
| 619 | send_min_interval, mw_sleep, mw_enabled, realtime); | 619 | send_min_interval, mw_sleep, mw_enabled, realtime); |
| 620 | 620 | ||
| 621 | while (!disposed) { | 621 | while (!disposed) { |
| @@ -667,7 +667,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe | @@ -667,7 +667,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe | ||
| 667 | // get messages from consumer. | 667 | // get messages from consumer. |
| 668 | // each msg in msgs.msgs must be free, for the SrsMessageArray never free them. | 668 | // each msg in msgs.msgs must be free, for the SrsMessageArray never free them. |
| 669 | // @remark when enable send_min_interval, only fetch one message a time. | 669 | // @remark when enable send_min_interval, only fetch one message a time. |
| 670 | - int count = send_min_interval? 1 : 0; | 670 | + int count = (send_min_interval > 0)? 1 : 0; |
| 671 | if ((ret = consumer->dump_packets(&msgs, count)) != ERROR_SUCCESS) { | 671 | if ((ret = consumer->dump_packets(&msgs, count)) != ERROR_SUCCESS) { |
| 672 | srs_error("get messages from consumer failed. ret=%d", ret); | 672 | srs_error("get messages from consumer failed. ret=%d", ret); |
| 673 | return ret; | 673 | return ret; |
| @@ -745,7 +745,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe | @@ -745,7 +745,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe | ||
| 745 | 745 | ||
| 746 | // apply the minimal interval for delivery stream in ms. | 746 | // apply the minimal interval for delivery stream in ms. |
| 747 | if (send_min_interval > 0) { | 747 | if (send_min_interval > 0) { |
| 748 | - st_usleep(send_min_interval * 1000); | 748 | + st_usleep((int64_t)(send_min_interval * 1000)); |
| 749 | } | 749 | } |
| 750 | } | 750 | } |
| 751 | 751 |
| @@ -86,7 +86,7 @@ private: | @@ -86,7 +86,7 @@ private: | ||
| 86 | // @see https://github.com/simple-rtmp-server/srs/issues/257 | 86 | // @see https://github.com/simple-rtmp-server/srs/issues/257 |
| 87 | bool realtime; | 87 | bool realtime; |
| 88 | // the minimal interval in ms for delivery stream. | 88 | // the minimal interval in ms for delivery stream. |
| 89 | - int send_min_interval; | 89 | + double send_min_interval; |
| 90 | public: | 90 | public: |
| 91 | SrsRtmpConn(SrsServer* svr, st_netfd_t c); | 91 | SrsRtmpConn(SrsServer* svr, st_netfd_t c); |
| 92 | virtual ~SrsRtmpConn(); | 92 | virtual ~SrsRtmpConn(); |
| @@ -1454,6 +1454,7 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata | @@ -1454,6 +1454,7 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata | ||
| 1454 | bool drop_for_reduce = false; | 1454 | bool drop_for_reduce = false; |
| 1455 | if (cache_metadata && _srs_config->get_reduce_sequence_header(_req->vhost)) { | 1455 | if (cache_metadata && _srs_config->get_reduce_sequence_header(_req->vhost)) { |
| 1456 | drop_for_reduce = true; | 1456 | drop_for_reduce = true; |
| 1457 | + srs_warn("drop for reduce sh metadata, size=%d", msg->size); | ||
| 1457 | } | 1458 | } |
| 1458 | 1459 | ||
| 1459 | // create a shared ptr message. | 1460 | // create a shared ptr message. |
| @@ -2325,8 +2325,19 @@ int srs_human_print_rtmp_packet2(char type, u_int32_t timestamp, char* data, int | @@ -2325,8 +2325,19 @@ int srs_human_print_rtmp_packet2(char type, u_int32_t timestamp, char* data, int | ||
| 2325 | 2325 | ||
| 2326 | int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp, int64_t pre_now) | 2326 | int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp, int64_t pre_now) |
| 2327 | { | 2327 | { |
| 2328 | + return srs_human_print_rtmp_packet4(type, timestamp, data, size, pre_timestamp, pre_now, 0, 0); | ||
| 2329 | +} | ||
| 2330 | + | ||
| 2331 | +int srs_human_print_rtmp_packet4(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp, int64_t pre_now, int64_t starttime, int64_t nb_packets) | ||
| 2332 | +{ | ||
| 2328 | int ret = ERROR_SUCCESS; | 2333 | int ret = ERROR_SUCCESS; |
| 2329 | 2334 | ||
| 2335 | + // packets interval in milliseconds. | ||
| 2336 | + double pi = 0; | ||
| 2337 | + if (pre_now > starttime) { | ||
| 2338 | + pi = (pre_now - starttime) / (double)nb_packets; | ||
| 2339 | + } | ||
| 2340 | + | ||
| 2330 | int diff = 0; | 2341 | int diff = 0; |
| 2331 | if (pre_timestamp > 0) { | 2342 | if (pre_timestamp > 0) { |
| 2332 | diff = (int)timestamp - (int)pre_timestamp; | 2343 | diff = (int)timestamp - (int)pre_timestamp; |
| @@ -2339,22 +2350,22 @@ int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int | @@ -2339,22 +2350,22 @@ int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int | ||
| 2339 | 2350 | ||
| 2340 | u_int32_t pts; | 2351 | u_int32_t pts; |
| 2341 | if (srs_utils_parse_timestamp(timestamp, type, data, size, &pts) != 0) { | 2352 | if (srs_utils_parse_timestamp(timestamp, type, data, size, &pts) != 0) { |
| 2342 | - srs_human_trace("Rtmp packet type=%s, dts=%d, diff=%d, ndiff=%d, size=%d, DecodeError", | ||
| 2343 | - srs_human_flv_tag_type2string(type), timestamp, diff, ndiff, size | 2353 | + srs_human_trace("Rtmp packet id=%"PRId64"/%.1f, type=%s, dts=%d, diff=%d, ndiff=%d, size=%d, DecodeError", |
| 2354 | + nb_packets, pi, srs_human_flv_tag_type2string(type), timestamp, diff, ndiff, size | ||
| 2344 | ); | 2355 | ); |
| 2345 | return ret; | 2356 | return ret; |
| 2346 | } | 2357 | } |
| 2347 | 2358 | ||
| 2348 | if (type == SRS_RTMP_TYPE_VIDEO) { | 2359 | if (type == SRS_RTMP_TYPE_VIDEO) { |
| 2349 | - srs_human_trace("Video packet type=%s, dts=%d, pts=%d, diff=%d, ndiff=%d, size=%d, %s(%s,%s)", | ||
| 2350 | - srs_human_flv_tag_type2string(type), timestamp, pts, diff, ndiff, size, | 2360 | + srs_human_trace("Video packet id=%"PRId64"/%.1f, type=%s, dts=%d, pts=%d, diff=%d, ndiff=%d, size=%d, %s(%s,%s)", |
| 2361 | + nb_packets, pi, srs_human_flv_tag_type2string(type), timestamp, pts, diff, ndiff, size, | ||
| 2351 | srs_human_flv_video_codec_id2string(srs_utils_flv_video_codec_id(data, size)), | 2362 | srs_human_flv_video_codec_id2string(srs_utils_flv_video_codec_id(data, size)), |
| 2352 | srs_human_flv_video_avc_packet_type2string(srs_utils_flv_video_avc_packet_type(data, size)), | 2363 | srs_human_flv_video_avc_packet_type2string(srs_utils_flv_video_avc_packet_type(data, size)), |
| 2353 | srs_human_flv_video_frame_type2string(srs_utils_flv_video_frame_type(data, size)) | 2364 | srs_human_flv_video_frame_type2string(srs_utils_flv_video_frame_type(data, size)) |
| 2354 | ); | 2365 | ); |
| 2355 | } else if (type == SRS_RTMP_TYPE_AUDIO) { | 2366 | } else if (type == SRS_RTMP_TYPE_AUDIO) { |
| 2356 | - srs_human_trace("Audio packet type=%s, dts=%d, pts=%d, diff=%d, ndiff=%d, size=%d, %s(%s,%s,%s,%s)", | ||
| 2357 | - srs_human_flv_tag_type2string(type), timestamp, pts, diff, ndiff, size, | 2367 | + srs_human_trace("Audio packet id=%"PRId64"/%.1f, type=%s, dts=%d, pts=%d, diff=%d, ndiff=%d, size=%d, %s(%s,%s,%s,%s)", |
| 2368 | + nb_packets, pi, srs_human_flv_tag_type2string(type), timestamp, pts, diff, ndiff, size, | ||
| 2358 | srs_human_flv_audio_sound_format2string(srs_utils_flv_audio_sound_format(data, size)), | 2369 | srs_human_flv_audio_sound_format2string(srs_utils_flv_audio_sound_format(data, size)), |
| 2359 | srs_human_flv_audio_sound_rate2string(srs_utils_flv_audio_sound_rate(data, size)), | 2370 | srs_human_flv_audio_sound_rate2string(srs_utils_flv_audio_sound_rate(data, size)), |
| 2360 | srs_human_flv_audio_sound_size2string(srs_utils_flv_audio_sound_size(data, size)), | 2371 | srs_human_flv_audio_sound_size2string(srs_utils_flv_audio_sound_size(data, size)), |
| @@ -2362,8 +2373,8 @@ int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int | @@ -2362,8 +2373,8 @@ int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int | ||
| 2362 | srs_human_flv_audio_aac_packet_type2string(srs_utils_flv_audio_aac_packet_type(data, size)) | 2373 | srs_human_flv_audio_aac_packet_type2string(srs_utils_flv_audio_aac_packet_type(data, size)) |
| 2363 | ); | 2374 | ); |
| 2364 | } else if (type == SRS_RTMP_TYPE_SCRIPT) { | 2375 | } else if (type == SRS_RTMP_TYPE_SCRIPT) { |
| 2365 | - srs_human_verbose("Data packet type=%s, time=%d, diff=%d, ndiff=%d, size=%d", | ||
| 2366 | - srs_human_flv_tag_type2string(type), timestamp, diff, ndiff, size); | 2376 | + srs_human_verbose("Data packet id=%"PRId64"/%.1f, type=%s, time=%d, diff=%d, ndiff=%d, size=%d", |
| 2377 | + nb_packets, pi, srs_human_flv_tag_type2string(type), timestamp, diff, ndiff, size); | ||
| 2367 | int nparsed = 0; | 2378 | int nparsed = 0; |
| 2368 | while (nparsed < size) { | 2379 | while (nparsed < size) { |
| 2369 | int nb_parsed_this = 0; | 2380 | int nb_parsed_this = 0; |
| @@ -2379,8 +2390,8 @@ int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int | @@ -2379,8 +2390,8 @@ int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int | ||
| 2379 | srs_freep(amf0_str); | 2390 | srs_freep(amf0_str); |
| 2380 | } | 2391 | } |
| 2381 | } else { | 2392 | } else { |
| 2382 | - srs_human_trace("Rtmp packet type=%#x, dts=%d, pts=%d, diff=%d, ndiff=%d, size=%d", | ||
| 2383 | - type, timestamp, pts, diff, ndiff, size); | 2393 | + srs_human_trace("Rtmp packet id=%"PRId64"/%.1f, type=%#x, dts=%d, pts=%d, diff=%d, ndiff=%d, size=%d", |
| 2394 | + nb_packets, pi, type, timestamp, pts, diff, ndiff, size); | ||
| 2384 | } | 2395 | } |
| 2385 | 2396 | ||
| 2386 | return ret; | 2397 | return ret; |
| @@ -904,8 +904,19 @@ extern const char* srs_human_flv_audio_aac_packet_type2string(char aac_packet_ty | @@ -904,8 +904,19 @@ extern const char* srs_human_flv_audio_aac_packet_type2string(char aac_packet_ty | ||
| 904 | * @return an error code for parse the timetstamp to dts and pts. | 904 | * @return an error code for parse the timetstamp to dts and pts. |
| 905 | */ | 905 | */ |
| 906 | extern int srs_human_print_rtmp_packet(char type, u_int32_t timestamp, char* data, int size); | 906 | extern int srs_human_print_rtmp_packet(char type, u_int32_t timestamp, char* data, int size); |
| 907 | +/** | ||
| 908 | + * @param pre_timestamp the previous timestamp in ms to calc the diff. | ||
| 909 | + */ | ||
| 907 | extern int srs_human_print_rtmp_packet2(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp); | 910 | extern int srs_human_print_rtmp_packet2(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp); |
| 911 | +/** | ||
| 912 | + * @param pre_now the previous system time in ms to calc the ndiff. | ||
| 913 | + */ | ||
| 908 | extern int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp, int64_t pre_now); | 914 | extern int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp, int64_t pre_now); |
| 915 | +/** | ||
| 916 | + * @param starttime the rtmpdump starttime in ms. | ||
| 917 | + * @param nb_packets the number of packets received, to calc the packets interval in ms. | ||
| 918 | + */ | ||
| 919 | +extern int srs_human_print_rtmp_packet4(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp, int64_t pre_now, int64_t starttime, int64_t nb_packets); | ||
| 909 | 920 | ||
| 910 | // log to console, for use srs-librtmp application. | 921 | // log to console, for use srs-librtmp application. |
| 911 | extern const char* srs_human_format_time(); | 922 | extern const char* srs_human_format_time(); |
-
请 注册 或 登录 后发表评论