Skip to content

Conversation

@acooks
Copy link
Owner

@acooks acooks commented Dec 15, 2025

Summary

This PR adds comprehensive video/audio stream detection, quality metrics tracking, and in-browser WebRTC video playback to JitterTrap.
It enables real-time visibility into RTP and MPEG-TS streams with deep packet inspection—no configuration required.

Features

🎬 Video Stream Detection

  • Automatic codec detection via deep packet inspection (not port heuristics)
  • Supported codecs: H.264, H.265/HEVC, VP8, VP9, AV1
  • Resolution extraction from H.264/H.265 SPS NAL units
  • RTP and MPEG-TS transport stream support
  • Audio stream detection for G.711 μ-law/A-law and G.729

📊 Video Quality Metrics

  • RFC 3550 jitter calculation with log-scale histogram
  • Frame rate and bitrate tracking (1-second windowed)
  • Keyframe detection and GOP size measurement
  • Sequence loss and discontinuity tracking

📺 WebRTC Video Playback

  • Watch live video streams directly in the browser
  • Sub-second latency via WebRTC (no transcoding)
  • H.264 depacketization with SPS/PPS injection for mid-stream joins
  • SDP negotiation with automatic profile selection (Constrained Baseline preferred)
  • Build-time opt-in: ENABLE_WEBRTC_PLAYBACK=1 make

🩺 TCP Health Indicators

  • RTT histograms (14 log-scale buckets from <100μs to >1s)
  • Congestion event tracking: zero windows, duplicate ACKs, retransmissions, ECE flags
  • Health status classification: Good / Warning / Problem
  • Issue flags: tail latency, elevated loss, window starvation, RTO stalls

⚡ Client Performance

  • Reduced GC pressure via object pooling and reusable data structures
  • Custom D3 stack implementation replacing allocation-heavy d3.stack()
  • Throttled legend updates (10Hz) for smoother chart rendering

Build Options

Standard build (video detection enabled, WebRTC disabled)
make

With WebRTC playback support (requires libdatachannel)
ENABLE_WEBRTC_PLAYBACK=1 make

CI Improvements

Added AddressSanitizer workflow to catch memory leaks and buffer overflows. This already identified and fixed two pre-existing memory
leaks:

  • JSON reference leak in toptalk message packer
  • Missing cleanup in slist test

Screenshots

Add screenshots of the video stream detection UI and WebRTC player overlay here

Testing

  • Unit tests pass (make test)
  • AddressSanitizer tests pass (make test-asan)
  • Tested with H.264 RTP streams (IP cameras, FFmpeg)
  • Tested with MPEG-TS over UDP
  • WebRTC playback verified in Chrome and Firefox

Documentation

  • Updated README with WebRTC build instructions
  • Added inline documentation for video detection algorithms
  • Documented histogram bucket ranges in flow.h

…lysis

Add comprehensive video and audio stream analysis capabilities:

Video Detection (video_detect.c/h):
- RTP payload type identification for H.264, H.265, MPEG-4, MJPEG
- NAL unit parsing with emulation prevention byte removal
- SPS/PPS extraction for codec parameter detection
- Resolution and framerate extraction from video headers
- Support for both single NAL and aggregation packets (STAP-A, FU-A)

Video Metrics (video_metrics.c/h):
- RTP sequence tracking with loss detection
- Inter-packet gap (IPG) measurement and histograms
- Video jitter calculation per RFC 3550
- Frame size histograms (20 buckets covering VoIP to MTU sizes)
- Packets-per-second (PPS) distribution histograms
- Bitrate calculation from RTP timestamps

RTSP Signaling Tap (rtsp_tap.c/h):
- Passive observation of RTSP DESCRIBE/SETUP/PLAY
- SDP parsing for media stream parameters
- Track-to-port mapping for RTP stream correlation
- Session lifecycle tracking

TCP Analysis Enhancements:
- RTT histogram with 14 log-scale buckets (10µs to 10s+)
- Health status classification (good/warning/problem)
- Health flags for specific issues (tail latency, loss, stalls)
- IPG histogram for all flows (12 log-scale buckets)

Extended Flow Record (flow.h):
- New fields for video codec, resolution, framerate
- Audio type and codec detection
- Histogram arrays for RTT, IPG, jitter, frame size, PPS
- Health status and flags
WebRTC Video Bridge (webrtc_bridge.c/h):
- GStreamer-based RTP to WebRTC transcoding pipeline
- Dynamic H.264 profile selection from browser SDP capabilities
- Supports Baseline, Main, and High profiles with level negotiation
- Session management with automatic cleanup on disconnect
- Thread-safe design with mutex-protected state

Protocol Extensions (messages/):
- New message types for WebRTC signaling (180-184):
  - JT_MSG_WEBRTC_OFFER/ANSWER for SDP exchange
  - JT_MSG_WEBRTC_ICE for ICE candidate exchange
  - JT_MSG_WEBRTC_START/STOP for session control
- Extended toptalk message format with:
  - Video telemetry: codec, resolution, framerate, bitrate, jitter
  - Audio telemetry: type, codec, jitter
  - TCP health: status, flags, RTT histogram
  - Flow histograms: IPG, frame size, PPS

Server Integration:
- WebRTC message handlers in jt_server_message_handler.c
- Toptalk thread integration for video/audio stream detection
- Updated compression dictionary for new telemetry fields
- Increased MAX_JSON_MSG_LEN to 64KB for histogram data

Build System:
- Optional ENABLE_WEBRTC_PLAYBACK flag for GStreamer dependency
- Debug/release build modes with sanitizer support
- New test targets for video functionality
…ements

WebRTC Video Playback (jittertrap-webrtc.js):
- In-browser video playback via WebRTC
- SDP offer/answer exchange with server
- ICE candidate handling for NAT traversal
- Play button in Top Talkers legend for video flows
- Draggable, resizable video overlay with close button

Top Talkers Enhancements (jittertrap-chart-toptalk.js):
- Expandable video/audio telemetry rows showing codec, resolution, bitrate
- TCP health indicators (✓/⚠/✗) based on RTT distribution
- Expandable health details with RTT histogram visualization
- IPG, frame size, and PPS histogram displays
- Click-to-select on byte distribution bar segments
- Bitrate column in flow legend
- Removed redundant hover tooltips (~200 lines)

Chart Improvements:
- Flow selection highlighting synced across all charts
- Logarithmic Y-axis scale for RTT chart (better for wide value ranges)
- SVG clip paths to prevent overdraw during scrolling
- Improved axis label readability

Performance Optimizations (jittertrap-core.js):
- Object pooling for data points to reduce GC pressure
- Custom stack implementation reusing arrays
- Cached tick formatters to avoid closure allocation
- Throttled legend updates (10Hz vs 60Hz)
- Smooth chart scrolling with interval refinement
- Shared X-axis domain calculation across charts

Documentation (modal-help.part.html):
- New TCP Analysis section with troubleshooting guidance
- Enhanced Video & Audio Stream Analysis section
- NAL unit explanation with diagrams and encoding table

Styling (jittertrap.css):
- Video overlay and controls styling
- Health indicator and histogram bar styles
- Expandable row animations
GitHub Actions:
- New test_asan job running AddressSanitizer tests
- Installs build dependencies and runs make test-asan

Build System:
- Debug/release build modes (BUILD_TYPE variable)
- AddressSanitizer targets: test-asan, test-video-asan
- Fuzzing targets: fuzz-build, fuzz, fuzz-quick
- Fix scan-build to use $(MAKE) for proper recursion

Test Infrastructure:
- Comprehensive video detection test suite (test_video_detect.c)
- Tests for H.264/H.265 NAL parsing, SPS extraction
- RTP packet decoding and aggregation packet handling
- Emulation prevention byte removal verification
Fix two memory leaks found when running the test suite with ASan:

1. messages/src/jt_msg_toptalk.c (jt_toptalk_packer):
   - Use json_object_set_new() instead of json_object_set() for
     timestamp fields to properly transfer ownership
   - Remove redundant json_decref(timestamp) since ownership is
     now transferred to params via json_object_set_new()

2. server/test_slist.c:
   - Add cleanup code at end of test to free allocated nodes
   - Free the slist meta structure and head node
   - Add return statement

These leaks were pre-existing but only caught now that ASan
testing was added to the CI workflow.
Add documentation for the optional WebRTC video playback feature:

Makefile:
- Add ENABLE_WEBRTC_PLAYBACK to `make config` output under Feature Flags

README.md:
- Add "Video & Audio Stream Analysis" to Key Features section
- Add "Optional Features" section explaining how to enable WebRTC
  playback and the libdatachannel dependency

The in-app Help modal already documents this feature comprehensively,
and a runtime alert guides users if the server lacks WebRTC support.
@acooks acooks merged commit bd6f8e1 into master Dec 15, 2025
3 checks passed
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