# `MobWebrtc.H264`
[🔗](https://github.com/GenericJam/mob_webrtc/blob/main/lib/mob_webrtc/h264.ex#L1)

H264 over RTP (RFC 6184, packetization mode 1), both directions.

Sending: `payloads/2` turns an Annex-B access unit, as `mob_screencast`
delivers it (NAL units behind `00 00 01` or `00 00 00 01` start codes,
SPS/PPS ahead of a keyframe's slices), into RTP payloads: each NAL unit that
fits in `max_payload` bytes is one payload (single NAL unit packet), larger
ones are split into FU-A fragments.

Receiving: `depayload/3` turns RTP payloads back into NAL units. ex_webrtc
0.18's H264 depayloader drops the header byte of single-NAL-unit packets, so
an SPS (type 7) comes out as a type 2 slice fragment and no decoder can
start; this one keeps whole NAL units.

# `depayloader`

```elixir
@type depayloader() :: %{
  fragments: [binary()] | nil,
  next_seq: non_neg_integer() | nil
}
```

An FU-A unit being reassembled, and the sequence number expected next.

# `depayload`

```elixir
@spec depayload(depayloader(), binary(), non_neg_integer()) ::
  {[binary()], depayloader()}
```

The whole NAL units (without start codes) that the RTP payload with
`sequence_number` completes. A fragmented NAL unit that misses a packet, or
whose start was never seen, is dropped rather than passed on corrupt.

# `depayloader`

```elixir
@spec depayloader() :: depayloader()
```

# `nal_units`

```elixir
@spec nal_units(binary()) :: [binary()]
```

The NAL units of an Annex-B access unit, without start codes.

# `payloads`

```elixir
@spec payloads(binary(), pos_integer()) :: [binary()]
```

The RTP payloads for `access_unit`, in order; the last one ends the frame (marker bit).

---

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