# Codec

<a id="codec"></a>

# Codec

```cpp
#include <icy/av/codec.h>

struct Codec
```

[Defined in src/av/include/icy/av/codec.h:29](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L29)

> **Subclassed by:** [`AudioCodec`](https://auscaster.com/icey/docs/api-reference/icy-av-AudioCodec.md#audiocodec), [`VideoCodec`](https://auscaster.com/icey/docs/api-reference/icy-av-VideoCodec.md#videocodec)

[Codec](#codec) for encoding/decoding media.

## Public Attributes

| Return | Name | Description |
|--------|------|-------------|
| `std::string` | [`name`](#name-4)  | The display name for this codec. |
| `std::string` | [`encoder`](#encoder)  | The encoder name for FFmpeg. |
| `int` | [`sampleRate`](#samplerate)  | The sampling rate or RTP clock rate. |
| `int` | [`bitRate`](#bitrate)  | The bit rate to encode at. |
| `int` | [`quality`](#quality)  | Optional quality value, variable range depending on codec. |
| `int` | [`compliance`](#compliance)  | FFmpeg strict_std_compliance level (default: FF_COMPLIANCE_EXPERIMENTAL). |
| `bool` | [`enabled`](#enabled)  | Weather or not the codec is available for use. |
| `std::map< std::string, std::string >` | [`options`](#options-1)  | Arbitrary encoder options passed to FFmpeg via av_opt_set(). Keys are FFmpeg option names (e.g. "preset", "tune", "profile"). Applied after codec-specific defaults, so they override everything. |

---

<a id="name-4"></a>

### name

```cpp
std::string name
```

[Defined in src/av/include/icy/av/codec.h:34](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L34)

The display name for this codec.

---

<a id="encoder"></a>

### encoder

```cpp
std::string encoder
```

[Defined in src/av/include/icy/av/codec.h:35](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L35)

The encoder name for FFmpeg.

---

<a id="samplerate"></a>

### sampleRate

```cpp
int sampleRate
```

[Defined in src/av/include/icy/av/codec.h:36](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L36)

The sampling rate or RTP clock rate.

---

<a id="bitrate"></a>

### bitRate

```cpp
int bitRate
```

[Defined in src/av/include/icy/av/codec.h:37](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L37)

The bit rate to encode at.

---

<a id="quality"></a>

### quality

```cpp
int quality
```

[Defined in src/av/include/icy/av/codec.h:38](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L38)

Optional quality value, variable range depending on codec.

---

<a id="compliance"></a>

### compliance

```cpp
int compliance
```

[Defined in src/av/include/icy/av/codec.h:39](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L39)

FFmpeg strict_std_compliance level (default: FF_COMPLIANCE_EXPERIMENTAL).

---

<a id="enabled"></a>

### enabled

```cpp
bool enabled
```

[Defined in src/av/include/icy/av/codec.h:40](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L40)

Weather or not the codec is available for use.

---

<a id="options-1"></a>

### options

```cpp
std::map< std::string, std::string > options
```

[Defined in src/av/include/icy/av/codec.h:45](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L45)

Arbitrary encoder options passed to FFmpeg via av_opt_set(). Keys are FFmpeg option names (e.g. "preset", "tune", "profile"). Applied after codec-specific defaults, so they override everything.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Codec`](#codec-1)  | Construct a disabled codec with zeroed parameters. |
|  | [`Codec`](#codec-2)  | Construct a codec with a display name, sample rate, bit rate, and enabled flag. |
|  | [`Codec`](#codec-3)  | Construct a codec with an explicit FFmpeg encoder name. |
|  | [`~Codec`](#codec-4) `virtual` `noexcept` | Codec(const Codec& r);. |
| `std::string` | [`toString`](#tostring-3) `virtual` `const` | Return a compact string representation of this codec. |
| `bool` | [`specified`](#specified) `const` | Returns true when this codec explicitly names either an RTP/media codec or an FFmpeg encoder and is enabled for use. |
| `void` | [`print`](#print-2) `virtual` | Print a multi-line human-readable description to the given stream. |

---

<a id="codec-1"></a>

### Codec

```cpp
Codec()
```

[Defined in src/av/include/icy/av/codec.h:51](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L51)

Construct a disabled codec with zeroed parameters.

---

<a id="codec-2"></a>

### Codec

```cpp
Codec(const std::string & name, int sampleRate = 0, int bitRate = 0, bool enabled = true)
```

[Defined in src/av/include/icy/av/codec.h:58](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L58)

Construct a codec with a display name, sample rate, bit rate, and enabled flag.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `const std::string &` | The codec display name. |
| `sampleRate` | `int` | The sampling rate or RTP clock rate in Hz. |
| `bitRate` | `int` | The target bit rate in bits per second. |
| `enabled` | `bool` | Whether the codec is available for use. |

---

<a id="codec-3"></a>

### Codec

```cpp
Codec(const std::string & name, const std::string & encoder, int sampleRate = 0, int bitRate = 0, bool enabled = true)
```

[Defined in src/av/include/icy/av/codec.h:67](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L67)

Construct a codec with an explicit FFmpeg encoder name.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `const std::string &` | The codec display name. |
| `encoder` | `const std::string &` | The FFmpeg encoder name (e.g. "libx264"). |
| `sampleRate` | `int` | The sampling rate or RTP clock rate in Hz. |
| `bitRate` | `int` | The target bit rate in bits per second. |
| `enabled` | `bool` | Whether the codec is available for use. |

---

<a id="codec-4"></a>

### ~Codec

`virtual` `noexcept`

```cpp
virtual ~Codec() noexcept
```

[Defined in src/av/include/icy/av/codec.h:70](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L70)

Codec(const Codec& r);.

---

<a id="tostring-3"></a>

### toString

`virtual` `const`

```cpp
virtual std::string toString() const
```

[Defined in src/av/include/icy/av/codec.h:77](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L77)

Return a compact string representation of this codec. 
#### Returns
A string in the form "Codec[name:encoder:sampleRate:enabled]".

#### Reimplemented by

- [`AudioCodec::toString`](https://auscaster.com/icey/docs/api-reference/icy-av-AudioCodec.md#tostring-4)
- [`VideoCodec::toString`](https://auscaster.com/icey/docs/api-reference/icy-av-VideoCodec.md#tostring-5)

---

<a id="specified"></a>

### specified

`const`

```cpp
bool specified() const
```

[Defined in src/av/include/icy/av/codec.h:81](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L81)

Returns true when this codec explicitly names either an RTP/media codec or an FFmpeg encoder and is enabled for use.

---

<a id="print-2"></a>

### print

`virtual`

```cpp
virtual void print(std::ostream & ost)
```

[Defined in src/av/include/icy/av/codec.h:85](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/codec.h#L85)

Print a multi-line human-readable description to the given stream.

#### Reimplemented by

- [`AudioCodec::print`](https://auscaster.com/icey/docs/api-reference/icy-av-AudioCodec.md#print-3)
- [`VideoCodec::print`](https://auscaster.com/icey/docs/api-reference/icy-av-VideoCodec.md#print-4)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `ost` | `std::ostream &` | The output stream to write to. |
