# `BB.Camera.Format`
[🔗](https://github.com/beam-bots/bb_camera/blob/main/lib/bb/camera/format.ex#L5)

Which media formats `bb_camera` will carry, and why it refuses the rest.

`BB.Camera.Hub` keeps exactly one frame per camera and drops anything staler.
That policy is lossless for formats whose frames decode independently, and
destructive for formats whose frames reference earlier ones. So the set of
formats this package carries is exactly the set where dropping is safe.

Today that set is `:jpeg` - a stream of complete JPEG images, what the world
calls MJPEG. Raw pixel buffers would also qualify and are simply not
implemented yet; they are rejected as `:not_implemented` rather than
`:interframe`, because the distinction matters to anyone deciding whether to
add one.

Interframe codecs are refused outright. There is no mode in which this
package carries H.264 and drops frames, because the result would decode to
garbage without anything in the pipeline noticing.

# `t`

```elixir
@type t() :: :jpeg
```

# `assert`

```elixir
@spec assert(t(), term()) ::
  :ok | {:error, BB.Error.Invalid.Camera.UnsupportedFormat.t()}
```

Check a camera's format against what a caller asserted it would be.

`nil` asserts nothing.

# `independent_frames?`

```elixir
@spec independent_frames?(term()) :: boolean()
```

Whether every frame in this format decodes without reference to any other.

This is the predicate the hub's drop-the-stale-frame policy is safe under,
and therefore the predicate format support is gated on.

# `supported`

```elixir
@spec supported() :: [t()]
```

The formats this package carries.

# `validate`

```elixir
@spec validate(term()) ::
  {:ok, t()} | {:error, BB.Error.Invalid.Camera.UnsupportedFormat.t()}
```

Check a format is one this package will carry.

Returns `{:error, %UnsupportedFormat{reason: :interframe}}` for codecs whose
frames depend on each other, and `:not_implemented` for anything else.

---

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