From: Ryan McCartney <ryan@mccartney.info> To: ffmpeg-devel@ffmpeg.org Cc: Ryan McCartney <ryan@mccartney.info> Subject: [FFmpeg-devel] [PATCH v2] libavformat/libsrt.c: Add statistics option to output SRT statistics with av_log() Date: Tue, 19 Mar 2024 11:51:11 +0000 Message-ID: <20240319115108.65823-1-ryan@mccartney.info> (raw) --- libavformat/libsrt.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c index a7aafea536..80d52b1737 100644 --- a/libavformat/libsrt.c +++ b/libavformat/libsrt.c @@ -56,6 +56,8 @@ typedef struct SRTContext { int eid; int64_t rw_timeout; int64_t listen_timeout; + int64_t lastStatsTime; + int64_t stats; int recv_buffer_size; int send_buffer_size; @@ -100,6 +102,7 @@ typedef struct SRTContext { static const AVOption libsrt_options[] = { { "timeout", "Timeout of socket I/O operations (in microseconds)", OFFSET(rw_timeout), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E }, { "listen_timeout", "Connection awaiting timeout (in microseconds)" , OFFSET(listen_timeout), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E }, + { "stats", "Show SRT statistics in the log output", OFFSET(stats), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E }, { "send_buffer_size", "Socket send buffer size (in bytes)", OFFSET(send_buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, { "recv_buffer_size", "Socket receive buffer size (in bytes)", OFFSET(recv_buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, { "pkt_size", "Maximum SRT packet size", OFFSET(payload_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, SRT_LIVE_MAX_PAYLOAD_SIZE, .flags = D|E, .unit = "payload_size" }, @@ -158,6 +161,29 @@ static int libsrt_neterrno(URLContext *h) return os_errno ? AVERROR(os_errno) : AVERROR_UNKNOWN; } +static int libsrt_stats(URLContext *h,int read) +{ + SRTContext *s = h->priv_data; + SRT_TRACEBSTATS trace; + + int ret = srt_bistats(s->fd, &trace, 0,1); + int64_t timeNow = trace.msTimeStamp; + int64_t timeNext = s->lastStatsTime + s->stats; + + if((ret >= 0) && (timeNow > timeNext )){ + s->lastStatsTime = timeNow; + + if(read > 0){ + av_log(h, AV_LOG_INFO, "[srt-stats] rate=%.2fMbps bw=%.2fMbps rtt=%.2fms total=%jdpkts retrans=%jdpkts loss=%jdpkts \n", trace.mbpsRecvRate,trace.mbpsBandwidth,trace.msRTT,trace.pktRecvTotal,trace.pktRcvRetrans,trace.pktRcvLossTotal); + } + else{ + av_log(h, AV_LOG_INFO, "[srt-stats] rate=%.2fMbps bw=%.2fMbps rtt=%.2fms total=%jdpkts retrans=%jdpkts loss=%jdpkts \n", trace.mbpsSendRate,trace.mbpsBandwidth,trace.msRTT,trace.pktSentTotal,trace.pktRetrans,trace.pktSndLossTotal); + } + } + + return 0; +} + static int libsrt_getsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const char * optnamestr, void * optval, int * optlen) { if (srt_getsockopt(fd, 0, optname, optval, optlen) < 0) { @@ -557,6 +583,9 @@ static int libsrt_open(URLContext *h, const char *uri, int flags) goto err; } } + if (av_find_info_tag(buf, sizeof(buf), "stats", p)) { + s->stats = strtol(buf, NULL, 10); + } #if SRT_VERSION_VALUE >= 0x010302 if (av_find_info_tag(buf, sizeof(buf), "enforced_encryption", p)) { s->enforced_encryption = strtol(buf, NULL, 10); @@ -686,6 +715,10 @@ static int libsrt_read(URLContext *h, uint8_t *buf, int size) SRTContext *s = h->priv_data; int ret; + if(s->stats > 0){ + libsrt_stats(h,1); + } + if (!(h->flags & AVIO_FLAG_NONBLOCK)) { ret = libsrt_network_wait_fd_timeout(h, s->eid, 0, h->rw_timeout, &h->interrupt_callback); if (ret) @@ -705,6 +738,10 @@ static int libsrt_write(URLContext *h, const uint8_t *buf, int size) SRTContext *s = h->priv_data; int ret; + if(s->stats > 0){ + libsrt_stats(h,0); + } + if (!(h->flags & AVIO_FLAG_NONBLOCK)) { ret = libsrt_network_wait_fd_timeout(h, s->eid, 1, h->rw_timeout, &h->interrupt_callback); if (ret) -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2024-03-19 11:51 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-03-19 11:51 Ryan McCartney [this message] 2024-04-02 14:45 ` Zhao Zhili
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=20240319115108.65823-1-ryan@mccartney.info \ --to=ryan@mccartney.info \ --cc=ffmpeg-devel@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