Skip to content

Expose active Java socket for RTMP diagnostics - #2215

Merged
pedroSG94 merged 2 commits into
pedroSG94:masterfrom
AubreyHaskett:aeh/expose-java-socket
Oct 17, 2026
Merged

pedroSG94 merged 2 commits into
pedroSG94:masterfrom
AubreyHaskett:aeh/expose-java-socket

Conversation

@AubreyHaskett

@AubreyHaskett AubreyHaskett commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

👋 RootEncoder exposes RTMP ping/pong RTT, but not the RTT tracked by the kernel for the underlying TCP connection, which I'd love to have. This PR will:

  • expose the active java.net.Socket for direct RTMP connections that use the Java socket implementation
  • surface the socket through RtmpClient, RtmpStreamClient, and GenericStreamClient
  • return null when the connection is inactive, tunneled, uses another protocol, or uses a non-Java socket
  • document that callers may inspect the socket but must not close or reconfigure it

Context

This is a follow-up to #2211. That proposal added native TCP_INFO support inside RootEncoder, which we do not want to do, as it required heavy non-Java/Kotlin additions to the repo.

This revision follows your recommendation -- RootEncoder only exposes its Java socket, while consumers can do what they like with that on their end (in my case, that will be obtaining a descriptor and implementing JNA/JNI diagnostics). This keeps code native, and keeps CMake/NDK config + ABI maintenance out of RootEncoder.

Users of RootEncoder will be able to use this socket access point for things other than kernel RTT as well (IP addresses/ports, correlating the connection w/app telemetry, additional info during SSLSocket use, additional TCP info, etc.).

Validation

  • ./gradlew :common:testDebugUnitTest
  • ./gradlew :rtmp:testDebugUnitTest
  • ./gradlew :library:compileReleaseKotlin
  • validated from the sample app with a test-only consumer using ParcelFileDescriptor.fromSocket() and getsockopt(TCP_INFO) during a live RTMPS stream: 111 consecutive RTT samples, 0 unavailable readings, 37.7–60.3 ms range, 48.0 ms average

Pedro - thanks for your time reviewing, chatting, and for the great library!


abstract class TcpStreamSocketJavaBase: TcpStreamSocket() {

@Volatile

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Needed here and for the RtmpSocket so that every thread is told to read the latest value of the socket instead of potentially using a cached value. This is important for how I will be using the info from the socket, but should overall strengthen thread visibility without changing how the code behaves.

This will not do anything undesirable like change how the socket connects, sends data, reconnects, or closes.

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2024 pedroSG94.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added because most (but not all) of the tests have this. hope that's okay.

@AubreyHaskett
AubreyHaskett marked this pull request as ready for review October 14, 2026 19:53
@pedroSG94
pedroSG94 merged commit b40770b into pedroSG94:master Oct 17, 2026
1 check passed
@pedroSG94

Copy link
Copy Markdown
Owner

Thank you for the PR. Merged

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