Repository navigation
Interceptor Framework for RTP/RTCP Processing or Direct RTP/RTCP Access for Custom Packetization #220
Description
Is your feature request related to a problem? Please describe.
There's currently no way to intercept, modify, or inject custom encoders, transform packets, or interoperate into the RTP/RTCP packet processing pipeline. This prevents implementing:
Enhanced monitoring (inspect packet-level metrics (jitter, packet loss patterns, RTT)) , Custom FEC (forward error correction) schemes , Research and experimentation (Cannot prototype new RTP extensions or RTCP feedback mechanisms)
Describe the solution you'd like
Expose RTP/RTCP send and receive hooks via a MediaStreamTrack or RtpTransceiver API. This should allow access to RtpReceiver and RtpSender transport streams .
Implement a pluggable interceptor framework similar to Pion's interceptor package, allowing developers to insert custom processing logic into the media pipeline:
-
Interceptor Interface:
interface Interceptor { // Called for each outgoing RTP packet RTCRtpPacket interceptRTP(RTCRtpPacket packet, RTCRtpSender sender); // Called for each incoming RTP packet RTCRtpPacket interceptIncomingRTP(RTCRtpPacket packet, RTCRtpReceiver receiver); // Called for outgoing RTCP packets RTCRtcpPacket interceptRTCP(RTCRtcpPacket packet); // Called for incoming RTCP packets RTCRtcpPacket interceptIncomingRTCP(RTCRtcpPacket packet); }
-
Interceptor Chain Management:
interface InterceptorRegistry { void add(Interceptor interceptor); void remove(Interceptor interceptor); List<Interceptor> getInterceptors(); } // Usage peerConnection.getInterceptorRegistry().add(new CustomInterceptor());
-
Built-in Interceptors: Provide commonly-needed interceptors:
- NACKInterceptor: Handle NACKs as per RFC 4585
- TWCCInterceptor: Transport-Wide Congestion Control per draft-holmer-rmcat-transport-wide-cc-extensions
- StatsInterceptor: Collect per-SSRC statistics
- RecordingInterceptor: Dump packets to file for debugging
-
Packet Access Objects: Expose packet structures:
class RTCRtpPacket { RTCRtpHeader header; byte[] payload; List<RTCRtpHeaderExtension> extensions; } class RTCRtpHeader { int payloadType; int sequenceNumber; long timestamp; long ssrc; List<Long> csrcs; }
Describe alternatives you've considered
Tried to implement own interface but due to local dev complications with webrtc code base and JNI complexity but ran into a wall trying to do this , hence this request .
Additional context
-
Interceptors are essential for building production-grade WebRTC applications that need observability and control
-
Pion WebRTC's interceptor framework: github.com/pion/interceptor
-
Key specifications:
-
Direct packet access enables advanced analytics, media transformation, and interoperability.
Activity
devopvoid commentedon Sep 13, 2026
Thanks for the detailed writeup — I want to set the right expectation on feasibility here, since this is a fundamentally different situation than Pion.
Pion can offer a clean interceptor chain because it's a from-scratch Go implementation of the whole RTP/RTCP stack, with full control over that pipeline. This project is a JNI wrapper around Google's
libwebrtc(C++). NACK handling, TWCC, jitter buffering, and RTP/RTCP send/receive all live deep inside libwebrtc's own internals (modules/rtp_rtcp,call/, the congestion controller) and libwebrtc doesn't expose a public, stable extension point for arbitrary per-packet interception/injection the way you're describing — there's noInterceptor-shaped hook inPeerConnectionInterface,RtpSenderInterface, orRtpReceiverInterfaceto bridge to Java. Building this for real would mean patching libwebrtc's internal pipeline directly and maintaining those patches across every upstream version bump (this project already tracks WebRTC branch updates regularly, e.g. #249) — that's a maintenance burden I don't think is sustainable for this project.What is already available today for the monitoring piece specifically:
RTCPeerConnection/RTCRtpSender/RTCRtpReceiverexposegetStats()→RTCStatsReport, which gives per-SSRC jitter, packet-loss, and RTT-type metrics without needing raw packet access (seedocs/guide/monitoring/rtc-stats.md). That covers "enhanced monitoring" reasonably well already.For custom FEC / custom packetization / prototyping new RTP extensions, I don't have a path to offer through this library — that really does need either patching libwebrtc directly or a from-scratch stack like Pion.