Add ABR characterization Python module for HLS player behavior analysis#48
Add ABR characterization Python module for HLS player behavior analysis#48
Conversation
Co-authored-by: jonathaneoliver <11263508+jonathaneoliver@users.noreply.github.com>
Co-authored-by: jonathaneoliver <11263508+jonathaneoliver@users.noreply.github.com>
Co-authored-by: jonathaneoliver <11263508+jonathaneoliver@users.noreply.github.com>
Co-authored-by: jonathaneoliver <11263508+jonathaneoliver@users.noreply.github.com>
|
@copilot interesting but why use go and not pyunit ? |
I chose Go because:
However, I see the repository has strong Python testing infrastructure (pytest) and existing HLS analysis tools ( Would you prefer I reimplement this in Python? I can create a
The Python version would fit better with the existing test suite and be easier to extend with the existing helpers. Let me know your preference and I can make the change. |
|
@copilot 2 |
Got it - reimplementing in Python. I'll:
Working on it now. |
|
@copilot you know if we use go can we add a web interface button calleed "ABR analysis" and have it run all the testing and generate a report ? |
- Remove Go implementation from cmd/abrchar/ - Create Python module in tests/abrchar/ with: - playlist.py - HLS multivariant playlist parsing - telemetry.py - Telemetry data structures and loading - throttle.py - Network throttling (HTTP and shell) - analysis.py - Switch detection and metrics calculation - output.py - JSON and Markdown report generation - cli.py - Command-line interface - Add pytest tests for playlist parsing - Include sample test data and working example - Update README with usage instructions - Integrate with existing Python test infrastructure Co-authored-by: jonathaneoliver <11263508+jonathaneoliver@users.noreply.github.com>
Yes, definitely! Whether using Go or Python, we can add an "ABR Analysis" button to the testing dashboard. Here are the options: Option 1: Keep Python, add Go API wrapper
Option 2: Revert to Go implementation
Option 3: Hybrid
I recommend Option 1 (keep Python, add Go API wrapper) because:
Want me to add the Go API endpoint and dashboard button? I can do that while keeping the Python analysis engine. |
|
@copilot ok make me a new local branch call abr-characterization. sync it with main. |
I can't create or switch branches directly using git commands - that's restricted in my environment. However, I can help you do it: To create and sync the branch yourself: git checkout main
git pull origin main
git checkout -b abr-characterization
git push -u origin abr-characterizationOr, if you want to copy current work to a new branch: git checkout -b abr-characterization copilot/automate-abr-characterization
git push -u origin abr-characterizationOnce you've created the branch and I'm running on it, I can continue adding the Go API wrapper and dashboard button for ABR analysis. Which approach would you prefer? |
|
Closing as superseded — ABR characterization is now done via |
Implements automated ABR characterization to measure player switching behavior under controlled throttling. Parses HLS multivariant playlists, analyzes telemetry, and computes safety factors (α where
variant_bw ≤ α × throughput), switch thresholds, and hysteresis.Implementation
Python Module (
tests/abrchar/)hls_speed_probe.py,hls_failure_probe.py)HLS Parsing (
playlist.py)Analysis Engine (
analysis.py)Throttling (
throttle.py)Output (
output.py)CLI
Telemetry schema (JSON lines):
{"timestamp":"2024-01-01T12:00:00Z","variant_bitrate_mbps":5.0,"buffer_depth_s":10.5} {"url":"seg.m4s","bytes":500000,"duration_ms":200,"throughput_mbps":20.0}Testing
See
tests/abrchar/README.mdfor detailed usage.Original prompt
This section details on the original issue you should resolve
<issue_title>characterize player ABR behaviour by gradually throttling network and observing when it rate shifts etc.</issue_title>
<issue_description>Goal: implement an automated ABR characterization harness for HLS players using our existing hooks:
• network throttling control (bandwidth limit up/down over time)
• player telemetry logging (selected variant/bitrate, buffer depth, stall count, etc.)
We want to run repeatable experiments like:
1. Load HLS content with ~2s segments and a known bitrate ladder (parse the multivariant playlist).
2. Start playback at high network capacity.
3. Apply a throttle schedule (prefer stair-steps with holds, not a continuous ramp) to push the player down through variants, then back up.
4. Collect telemetry + per-request download stats if available.
5. Analyze results to estimate per-boundary:
• downswitch throughput threshold distribution
• upswitch throughput threshold distribution (hysteresis)
• switch latency (seconds and segments)
• “safety factor” α where player tends to choose a variant when variant_bitrate <= α * estimated_throughput
6. Output a machine-readable JSON summary and a human-friendly report (Markdown). If feasible, generate plots (PNG) too.
Important HLS details:
• Parse #EXT-X-STREAM-INF and capture BANDWIDTH (required) and AVERAGE-BANDWIDTH (optional but recommended by Apple). Use both in analysis when present. 
• Segment duration is ~2s; use holds long enough for estimator stabilization (e.g., hold >= max(20s, 6 segments)).
Implementation requirements:
• Add a new CLI tool: cmd/abrchar (or tools/abrchar) with subcommands:
• run (executes an experiment)
• analyze (analyzes an existing telemetry log directory)
• Configuration via a single YAML/JSON config:
• HLS URL (master playlist)
• experiment duration
• throttle schedule parameters:
• warmup bandwidth (e.g., 2x top variant bandwidth)
• step pattern: percent step (e.g., 10%), hold seconds, optional jitter ±%
• min/max bandwidth
• direction: down, up, or down+up
• output directory
• player identifier (for labeling)
• Integrate with existing throttling hook:
• If it’s an HTTP endpoint: call it
• If it’s a local command: invoke it
• Abstract this behind an interface Throttler with implementations for HTTP and shell command.
• Integrate with existing telemetry:
• Assume telemetry arrives as JSON lines (or define a schema) including at least:
• timestamp (ms or RFC3339)
• selected variant bitrate or variant URI/index
• buffer_seconds
• stall_count (cumulative)
• If available, also log per-segment request metrics:
• url, bytes, download_ms, start_ts, end_ts
• Ensure timestamps are normalized and aligned.
Analysis requirements:
• Parse ladder from master playlist; build ordered variants by bitrate.
• Detect “switch events” when selected variant changes; record:
• time of decision (best-effort: telemetry timestamp when new variant first observed)
• from_variant, to_variant
• buffer at that time
• measured throughput proxy:
• compute EWMA or median over last N segment downloads (N configurable, default 5)
• For each adjacent boundary i↔i-1 produce:
• downswitch threshold: distribution of T_meas at i→i-1 events
• upswitch threshold: distribution of T_meas at (i-1)→i events
• safety factor α:
• α_down = bitrate_adv(i) / T_meas_at_switch_down
• α_up = bitrate_adv(i) / T_meas_at_switch_up
• compute using AVERAGE-BANDWIDTH when present, else BANDWIDTH; also report both when both exist.
• Report switch latency:
• time between throttle step crossing a boundary target and observed switch
• and/or segments between step and switch (use segment request times)
• Produce:
• summary.json with all metrics
• report.md with tables per boundary and key conclusions
• optional plots:
• time series of throttle target vs measured throughput vs selected variant vs buffer
• hysteresis chart per boundary (down vs up thresholds)
Coding constraints:
• Keep code readable and testable.
• Add unit tests for:
• playlist parsing (BANDWIDTH/AVERAGE-BANDWIDTH extraction)
• switch detection logic
• throughput EWMA/median windowing
• Don’t break existing project behavior. New tool should be additive.
• Provide a short README section: how to run abrchar run ... and interpret outputs.
Assume we're using pyunit. Assume we're not yet trying to see an emergency downshift ( or stall ) so initially we're just going to move throttle gradually to give it lots of time to switch bitrate ( by which I mean ) if we're using 2s segments that require Xbps - then we know that if we reduced throughput to X/10 - the segment would take 10x2s to download - which would likely underlfow the video buffer. We don't want to do that yet.
Make reasonable assumptions where details are missing; isolate assumptions in config and document them.</issue_description>
Comments on the Issue (you are @copilot in this section...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.