or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/aiortc@1.13.x
tile.json

tessl/pypi-aiortc

tessl install tessl/pypi-aiortc@1.13.0

Python implementation of WebRTC and ORTC for real-time peer-to-peer communication

Agent Success

Agent success rate when using this tile

87%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.02x

Baseline

Agent success rate without this tile

85%

task.mdevals/scenario-7/

Adaptive Video Streaming Server

Build a video streaming server that monitors network conditions and dynamically adjusts video quality to maintain smooth playback.

Overview

Create a system that streams video content to clients while actively monitoring connection quality. The system should automatically adjust frame rate and bitrate based on real-time network statistics to prevent buffering and maintain optimal viewing experience.

Capabilities

Video Stream Setup

  • It creates a video source that can have its frame rate dynamically controlled @test
  • It establishes a peer connection and adds the video track for streaming @test

Quality Monitoring

  • It retrieves connection statistics including packet loss and round-trip time @test
  • It calculates quality metrics from the statistics to determine connection health @test

Adaptive Quality Control

  • It reduces frame rate when packet loss exceeds 5% @test
  • It adjusts video bitrate based on estimated bandwidth from connection statistics @test

Complete Streaming Pipeline

  • It integrates quality monitoring with adaptive adjustments in a continuous monitoring loop @test

Requirements

The implementation should:

  1. Support creating video tracks with configurable frame rates
  2. Monitor connection statistics at regular intervals (e.g., every 2 seconds)
  3. Implement quality thresholds:
    • Packet loss > 5%: Reduce frame rate
    • Packet loss < 2%: Increase frame rate (if previously reduced)
    • Low RTT and minimal loss: Increase bitrate
    • High RTT or packet loss: Decrease bitrate
  4. Apply frame rate changes by controlling the video track's frame generation timing
  5. Apply bitrate changes through codec reconfiguration

Implementation

@generates

API

import asyncio
from typing import Optional


class AdaptiveVideoTrack:
    """
    A video track that supports dynamic frame rate control.
    Inherits from an appropriate base class to provide video frames.
    """

    def __init__(self, initial_fps: int = 30):
        """
        Initialize video track with specified frame rate.

        Args:
            initial_fps: Initial frames per second (default: 30)
        """
        pass

    async def recv(self):
        """
        Generate and return the next video frame.
        Timing should respect the current frame rate setting.

        Returns:
            A video frame object
        """
        pass

    def set_fps(self, fps: int):
        """
        Dynamically change the frame rate.

        Args:
            fps: New frames per second value
        """
        pass


class QualityMonitor:
    """
    Monitors connection quality and determines when adjustments are needed.
    """

    def __init__(self, peer_connection):
        """
        Initialize monitor with a peer connection to observe.

        Args:
            peer_connection: The peer connection to monitor
        """
        pass

    async def get_connection_stats(self) -> dict:
        """
        Retrieve current connection statistics.

        Returns:
            Dictionary containing metrics like packet_loss, rtt, bytes_sent, etc.
        """
        pass

    def should_reduce_quality(self, stats: dict) -> bool:
        """
        Determine if quality should be reduced based on statistics.

        Args:
            stats: Connection statistics dictionary

        Returns:
            True if quality should be reduced, False otherwise
        """
        pass

    def should_increase_quality(self, stats: dict) -> bool:
        """
        Determine if quality can be increased based on statistics.

        Args:
            stats: Connection statistics dictionary

        Returns:
            True if quality can be increased, False otherwise
        """
        pass


class AdaptiveStreamingServer:
    """
    Coordinates the adaptive streaming system.
    """

    def __init__(self):
        """
        Initialize the streaming server.
        """
        pass

    async def setup_connection(self, peer_connection, video_track: AdaptiveVideoTrack):
        """
        Set up a peer connection with the video track.

        Args:
            peer_connection: The peer connection object
            video_track: The adaptive video track to stream
        """
        pass

    async def monitor_and_adapt(self, peer_connection, video_track: AdaptiveVideoTrack,
                               monitor_interval: float = 2.0):
        """
        Continuously monitor connection and adapt quality.
        Runs until the connection closes.

        Args:
            peer_connection: The peer connection to monitor
            video_track: The video track to adjust
            monitor_interval: How often to check stats (seconds)
        """
        pass

    def adjust_frame_rate(self, video_track: AdaptiveVideoTrack, increase: bool):
        """
        Adjust the video track's frame rate up or down.

        Args:
            video_track: The video track to adjust
            increase: True to increase FPS, False to decrease
        """
        pass

    async def adjust_bitrate(self, peer_connection, increase: bool):
        """
        Adjust the video bitrate through codec reconfiguration.

        Args:
            peer_connection: The peer connection with video sender
            increase: True to increase bitrate, False to decrease
        """
        pass

Dependencies { .dependencies }

aiortc { .dependency }

Provides WebRTC implementation with video streaming, connection statistics, and codec control capabilities.