Skip to content

Comments

Add video/audio bitrate stats and RTT measurement for RTMP streaming#1

Open
Copilot wants to merge 6 commits intomasterfrom
copilot/add-video-audio-bitrate-stats
Open

Add video/audio bitrate stats and RTT measurement for RTMP streaming#1
Copilot wants to merge 6 commits intomasterfrom
copilot/add-video-audio-bitrate-stats

Conversation

Copy link

Copilot AI commented Dec 18, 2025

Adds separate video/audio bitrate tracking and RTT measurement using RTMP User Control ping-pong messages.

Changes

BaseSender.kt

  • Track videoBytesSendPerSecond and audioBytesSendPerSecond separately
  • Expose getVideoBitrate() and getAudioBitrate() returning bits/sec
  • Reset new counters in resetBytesSend()

RtmpSender.kt

  • Update video/audio byte counters in onRun() based on packet type

CommandsManager.kt

  • Add sendPing(sequence, socket) for RTMP PING_REQUEST

RtmpClient.kt

  • RTT tracking with sequence-verified ping-pong matching
  • getRtt() / getAverageRtt() for current and average RTT (ms)
  • measureRtt() triggers ping, resetRtt() clears history
  • Forward getVideoBitrate() / getAudioBitrate() from sender

RtmpStreamClient.kt

  • Expose all new stats to library consumers

Usage

val rtmpClient = RtmpStreamClient(...)

// Trigger RTT measurement
rtmpClient.measureRtt()

// Read stats
val videoKbps = rtmpClient.getVideoBitrate() / 1000
val audioKbps = rtmpClient.getAudioBitrate() / 1000
val rttMs = rtmpClient.getRtt()
val avgRttMs = rtmpClient.getAverageRtt()

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.14.3-bin/cv11ve7ro1n3o1j4so8xd9n66/gradle-8.14.3/lib/gradle-daemon-main-8.14.3.jar (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

为 RTMP 推流添加独立的视频/音频比特率统计和 RTT 测量功能

需求

1. 分离视频/音频比特率统计

当前 BaseSender.kt 只统计合并的 bytesSendPerSecond。请添加:

  • videoBytesSendPerSecond: Long - 追踪每秒视频字节数
  • audioBytesSendPerSecond: Long - 追踪每秒音频字节数
  • getVideoBitrate(): Long - 返回当前视频比特率(bits/sec)
  • getAudioBitrate(): Long - 返回当前音频比特率(bits/sec)

修改 RtmpSender.kt,在 onRun() 方法中发送视频和音频包时分别更新这些统计。

2. RTMP RTT(往返时延)测量

RtmpClient.kt 中添加 RTT 统计:

  • 使用 RTMP User Control Messages 或基于时间戳的方式实现 ping-pong 机制
  • 添加 getRtt(): Long 方法返回当前 RTT(毫秒)
  • 追踪 RTT 历史并提供 getAverageRtt(): Long

3. 暴露新统计信息

  • RtmpClient.kt 中添加 getVideoBitrate()getAudioBitrate()getRtt() 的 getter 方法
  • 更新 library 模块中的 RtmpStreamClient 以暴露这些新统计信息

需要修改的关键文件

  • common/src/main/java/com/pedro/common/base/BaseSender.kt
  • rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpSender.kt
  • rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient. kt
  • library/src/main/java/com/pedro/library/util/streamclient/RtmpStreamClient.kt

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits December 18, 2025 08:47
Co-authored-by: xiuminga <35331382+xiuminga@users.noreply.github.com>
Co-authored-by: xiuminga <35331382+xiuminga@users.noreply.github.com>
Co-authored-by: xiuminga <35331382+xiuminga@users.noreply.github.com>
Co-authored-by: xiuminga <35331382+xiuminga@users.noreply.github.com>
Co-authored-by: xiuminga <35331382+xiuminga@users.noreply.github.com>
Copilot AI changed the title [WIP] Add independent video/audio bitrate stats and RTT measurement Add video/audio bitrate stats and RTT measurement for RTMP streaming Dec 18, 2025
Copilot AI requested a review from xiuminga December 18, 2025 08:59
@xiuminga xiuminga marked this pull request as ready for review December 18, 2025 11:31
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants