# `Dala.Media.Adaptive`
[🔗](https://github.com/manhvu/dala/blob/main/lib/dala/media/adaptive.ex#L1)

Adaptive bitrate streaming and jitter buffer.

Monitors network conditions and dynamically adjusts:
- Video resolution and bitrate
- Buffer size
- Frame dropping strategy

Borrowed from WebRTC / RTP / QUIC approaches.

## States

    :stable     → network is good, use highest quality
    :degrading  → packet loss detected, reduce quality
    :recovering → network improving, slowly ramp up
    :buffered   → buffer full, can increase quality

## Example

    {:ok, adapter} = Dala.Media.Adaptive.start_link(%{
      min_bitrate: 200_000,
      max_bitrate: 4_000_000,
      target_buffer_ms: 2000
    })

    # Report network stats (called by stream decoder)
    Dala.Media.Adaptive.report_stats(adapter, %{
      bytes_received: 50000,
      packets_lost: 2,
      jitter_ms: 15,
      rtt_ms: 80
    })

# `adapter_ref`

```elixir
@type adapter_ref() :: pid()
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `diagnostic`

```elixir
@spec diagnostic(adapter_ref()) :: map()
```

Get full diagnostic info.

# `get_state`

```elixir
@spec get_state(adapter_ref()) :: atom()
```

Get current adapter state.

# `recommended_bitrate`

```elixir
@spec recommended_bitrate(adapter_ref()) :: non_neg_integer()
```

Get the current recommended bitrate.

# `recommended_resolution`

```elixir
@spec recommended_resolution(adapter_ref()) :: {non_neg_integer(), non_neg_integer()}
```

Get the current recommended resolution.

# `report_stats`

```elixir
@spec report_stats(adapter_ref(), map()) :: :ok
```

Report network statistics from the stream decoder.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Start the adaptive bitrate adapter.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
