From: Jack Lau via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: Jack Lau <code@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH] avformat/whip: make time measure more precise (PR #20391) Message-ID: <175677343683.25.12395839022854773097@463a07221176> (raw) PR #20391 opened by Jack Lau (JackLau) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20391 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20391.patch Use av_gettime_relative() replace av_gettime() to get better measure Changed the display precision from showing only integers to showing two decimal places (in milliseconds) Signed-off-by: Jack Lau <jacklau1222@qq.com> refer to https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20030#issuecomment-822 and https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20030#issuecomment-823 >From 7c9162f8ca1753f13e2a46ad58b34a6b05e884dd Mon Sep 17 00:00:00 2001 From: Jack Lau <jacklau1222@qq.com> Date: Tue, 2 Sep 2025 08:28:36 +0800 Subject: [PATCH] avformat/whip: make time measure more precise Use av_gettime_relative() replace av_gettime() to get better measure Changed the display precision from showing only integers to showing two decimal places (in milliseconds) Signed-off-by: Jack Lau <jacklau1222@qq.com> --- libavformat/whip.c | 50 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/libavformat/whip.c b/libavformat/whip.c index 1fcf19aaa3..e8b8a16d9f 100644 --- a/libavformat/whip.c +++ b/libavformat/whip.c @@ -151,7 +151,7 @@ #define WHIP_SDP_CREATOR_IP "127.0.0.1" /* Calculate the elapsed time from starttime to endtime in milliseconds. */ -#define ELAPSED(starttime, endtime) ((int)(endtime - starttime) / 1000) +#define ELAPSED(starttime, endtime) ((float)(endtime - starttime) / 1000) /* STUN Attribute, comprehension-required range (0x0000-0x7FFF) */ enum STUNAttr { @@ -370,7 +370,7 @@ static av_cold int initialize(AVFormatContext *s) WHIPContext *whip = s->priv_data; uint32_t seed; - whip->whip_starttime = av_gettime(); + whip->whip_starttime = av_gettime_relative(); ret = certificate_key_init(s); if (ret < 0) { @@ -391,9 +391,9 @@ static av_cold int initialize(AVFormatContext *s) if (whip->state < WHIP_STATE_INIT) whip->state = WHIP_STATE_INIT; - whip->whip_init_time = av_gettime(); - av_log(whip, AV_LOG_VERBOSE, "Init state=%d, handshake_timeout=%dms, pkt_size=%d, seed=%d, elapsed=%dms\n", - whip->state, whip->handshake_timeout, whip->pkt_size, seed, ELAPSED(whip->whip_starttime, av_gettime())); + whip->whip_init_time = av_gettime_relative(); + av_log(whip, AV_LOG_VERBOSE, "Init state=%d, handshake_timeout=%dms, pkt_size=%d, seed=%d, elapsed=%.2fms\n", + whip->state, whip->handshake_timeout, whip->pkt_size, seed, ELAPSED(whip->whip_starttime, av_gettime_relative())); return 0; } @@ -682,7 +682,7 @@ static int generate_sdp_offer(AVFormatContext *s) if (whip->state < WHIP_STATE_OFFER) whip->state = WHIP_STATE_OFFER; - whip->whip_offer_time = av_gettime(); + whip->whip_offer_time = av_gettime_relative(); av_log(whip, AV_LOG_VERBOSE, "Generated state=%d, offer: %s\n", whip->state, whip->sdp_offer); end: @@ -898,10 +898,10 @@ static int parse_answer(AVFormatContext *s) if (whip->state < WHIP_STATE_NEGOTIATED) whip->state = WHIP_STATE_NEGOTIATED; - whip->whip_answer_time = av_gettime(); - av_log(whip, AV_LOG_VERBOSE, "SDP state=%d, offer=%zuB, answer=%zuB, ufrag=%s, pwd=%zuB, transport=%s://%s:%d, elapsed=%dms\n", + whip->whip_answer_time = av_gettime_relative(); + av_log(whip, AV_LOG_VERBOSE, "SDP state=%d, offer=%zuB, answer=%zuB, ufrag=%s, pwd=%zuB, transport=%s://%s:%d, elapsed=%.2fms\n", whip->state, strlen(whip->sdp_offer), strlen(whip->sdp_answer), whip->ice_ufrag_remote, strlen(whip->ice_pwd_remote), - whip->ice_protocol, whip->ice_host, whip->ice_port, ELAPSED(whip->whip_starttime, av_gettime())); + whip->ice_protocol, whip->ice_host, whip->ice_port, ELAPSED(whip->whip_starttime, av_gettime_relative())); end: avio_context_free(&pb); @@ -1179,9 +1179,9 @@ static int udp_connect(AVFormatContext *s) if (whip->state < WHIP_STATE_UDP_CONNECTED) whip->state = WHIP_STATE_UDP_CONNECTED; - whip->whip_udp_time = av_gettime(); - av_log(whip, AV_LOG_VERBOSE, "UDP state=%d, elapsed=%dms, connected to udp://%s:%d\n", - whip->state, ELAPSED(whip->whip_starttime, av_gettime()), whip->ice_host, whip->ice_port); + whip->whip_udp_time = av_gettime_relative(); + av_log(whip, AV_LOG_VERBOSE, "UDP state=%d, elapsed=%.2fms, connected to udp://%s:%d\n", + whip->state, ELAPSED(whip->whip_starttime, av_gettime_relative()), whip->ice_host, whip->ice_port); end: av_dict_free(&opts); @@ -1191,7 +1191,7 @@ end: static int ice_dtls_handshake(AVFormatContext *s) { int ret = 0, size, i; - int64_t starttime = av_gettime(), now; + int64_t starttime = av_gettime_relative(), now; WHIPContext *whip = s->priv_data; AVDictionary *opts = NULL; char buf[256], *cert_buf = NULL, *key_buf = NULL; @@ -1225,9 +1225,9 @@ next_packet: /* DTLS handshake is done, exit the loop. */ break; - now = av_gettime(); + now = av_gettime_relative(); if (now - starttime >= whip->handshake_timeout * 1000) { - av_log(whip, AV_LOG_ERROR, "DTLS handshake timeout=%dms, cost=%dms, elapsed=%dms, state=%d\n", + av_log(whip, AV_LOG_ERROR, "DTLS handshake timeout=%dms, cost=%.2fms, elapsed=%.2fms, state=%d\n", whip->handshake_timeout, ELAPSED(starttime, now), ELAPSED(whip->whip_starttime, now), whip->state); ret = AVERROR(ETIMEDOUT); goto end; @@ -1254,10 +1254,10 @@ next_packet: if (ice_is_binding_response(whip->buf, ret)) { if (whip->state < WHIP_STATE_ICE_CONNECTED) { whip->state = WHIP_STATE_ICE_CONNECTED; - whip->whip_ice_time = av_gettime(); - av_log(whip, AV_LOG_VERBOSE, "ICE STUN ok, state=%d, url=udp://%s:%d, location=%s, username=%s:%s, res=%dB, elapsed=%dms\n", + whip->whip_ice_time = av_gettime_relative(); + av_log(whip, AV_LOG_VERBOSE, "ICE STUN ok, state=%d, url=udp://%s:%d, location=%s, username=%s:%s, res=%dB, elapsed=%.2fms\n", whip->state, whip->ice_host, whip->ice_port, whip->whip_resource_url ? whip->whip_resource_url : "", - whip->ice_ufrag_remote, whip->ice_ufrag_local, ret, ELAPSED(whip->whip_starttime, av_gettime())); + whip->ice_ufrag_remote, whip->ice_ufrag_local, ret, ELAPSED(whip->whip_starttime, av_gettime_relative())); ff_url_join(buf, sizeof(buf), "dtls", NULL, whip->ice_host, whip->ice_port, NULL); av_dict_set_int(&opts, "mtu", whip->pkt_size, 0); @@ -1302,8 +1302,8 @@ next_packet: } if (!ret) { whip->state = WHIP_STATE_DTLS_FINISHED; - whip->whip_dtls_time = av_gettime(); - av_log(whip, AV_LOG_VERBOSE, "DTLS handshake is done, elapsed=%dms\n", + whip->whip_dtls_time = av_gettime_relative(); + av_log(whip, AV_LOG_VERBOSE, "DTLS handshake is done, elapsed=%.2fms\n", ELAPSED(whip->whip_starttime, whip->whip_dtls_time)); } goto next_packet; @@ -1401,9 +1401,9 @@ static int setup_srtp(AVFormatContext *s) if (whip->state < WHIP_STATE_SRTP_FINISHED) whip->state = WHIP_STATE_SRTP_FINISHED; - whip->whip_srtp_time = av_gettime(); - av_log(whip, AV_LOG_VERBOSE, "SRTP setup done, state=%d, suite=%s, key=%zuB, elapsed=%dms\n", - whip->state, suite, sizeof(send_key), ELAPSED(whip->whip_starttime, av_gettime())); + whip->whip_srtp_time = av_gettime_relative(); + av_log(whip, AV_LOG_VERBOSE, "SRTP setup done, state=%d, suite=%s, key=%zuB, elapsed=%.2fms\n", + whip->state, suite, sizeof(send_key), ELAPSED(whip->whip_starttime, av_gettime_relative())); end: return ret; @@ -1559,8 +1559,8 @@ static int create_rtp_muxer(AVFormatContext *s) if (whip->state < WHIP_STATE_READY) whip->state = WHIP_STATE_READY; av_log(whip, AV_LOG_INFO, "Muxer state=%d, buffer_size=%d, max_packet_size=%d, " - "elapsed=%dms(init:%d,offer:%d,answer:%d,udp:%d,ice:%d,dtls:%d,srtp:%d)\n", - whip->state, buffer_size, max_packet_size, ELAPSED(whip->whip_starttime, av_gettime()), + "elapsed=%.2fms(init:%.2f,offer:%.2f,answer:%.2f,udp:%.2f,ice:%.2f,dtls:%.2f,srtp:%.2f)\n", + whip->state, buffer_size, max_packet_size, ELAPSED(whip->whip_starttime, av_gettime_relative()), ELAPSED(whip->whip_starttime, whip->whip_init_time), ELAPSED(whip->whip_init_time, whip->whip_offer_time), ELAPSED(whip->whip_offer_time, whip->whip_answer_time), -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-09-02 0:37 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=175677343683.25.12395839022854773097@463a07221176 \ --to=ffmpeg-devel@ffmpeg.org \ --cc=code@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git