Base class for a single A2DP codec's encode support: pairs an A2DP codec type and its SEP capability advertisement with an audio_tools::AudioEncoder that performs the actual encoding. Provide one concrete subclass per codec (see A2DPEncoderSBC, A2DPEncoderAAC) and register instances via BluetoothA2DPSource::add_encoder() - stream endpoint registration is driven entirely by what gets registered here.
More...
#include <A2DPEncoder.h>
|
|
| A2DPEncoder (audio_tools::AudioEncoder &encoder) |
| |
| virtual bool | begin (const esp_a2d_mcc_t &mcc) |
| |
| virtual void | build_capability (esp_a2d_mcc_t &mcc)=0 |
| | Fills in the SEP capability advertised for this codec at registration.
|
| |
| virtual esp_a2d_mct_t | codec_type ()=0 |
| | A2DP codec type this encoder handles (e.g. ESP_A2D_MCT_SBC)
|
| |
|
virtual void | end () |
| | Closes the wrapped audio_tools encoder.
|
| |
|
audio_tools::AudioInfo | get_audio_info () |
| | Negotiated sample rate/channels (the PCM is always provided as stereo)
|
| |
| virtual int | max_frames_per_packet () |
| | Max number of encoded frames that can be combined in one media packet.
|
| |
| virtual const char * | mime ()=0 |
| | MIME type of the codec this encoder produces (e.g. "audio/sbc")
|
| |
| virtual uint16_t | payload_header_size () |
| |
|
int | sample_rate () |
| | Sample rate of the PCM provided by the data callbacks.
|
| |
| virtual uint32_t | samples_per_frame ()=0 |
| |
|
void | set_frame_sink (A2DPFrameSink *sink) |
| | Defines the target of the encoded frames.
|
| |
| void | set_sample_rate (int rate) |
| |
| virtual size_t | write (const uint8_t *pcm, size_t len) |
| |
|
| virtual void | configure (const esp_a2d_mcc_t &mcc) |
| | optional codec specific configuration of the wrapped encoder
|
| |
| virtual void | parse_audio_info (const esp_a2d_mcc_t &mcc)=0 |
| |
| virtual void | write_encoded (const uint8_t *data, size_t len) |
| |
|
|
int | channels_cfg = 2 |
| |
|
FrameOutput | frame_output |
| |
|
int | input_sample_rate = 44100 |
| |
|
audio_tools::AudioEncoder * | p_encoder |
| |
|
A2DPFrameSink * | p_sink = nullptr |
| |
|
int | sample_rate_cfg = 44100 |
| |
Base class for a single A2DP codec's encode support: pairs an A2DP codec type and its SEP capability advertisement with an audio_tools::AudioEncoder that performs the actual encoding. Provide one concrete subclass per codec (see A2DPEncoderSBC, A2DPEncoderAAC) and register instances via BluetoothA2DPSource::add_encoder() - stream endpoint registration is driven entirely by what gets registered here.
The PCM which is provided by the data callbacks of the source is always 16 bit stereo (as in the legacy source API) at the sample rate defined with set_sample_rate() (default 44100). The sample rate is the only one advertised to the sink. If the sink negotiates mono, the PCM is downmixed before it is encoded.
- Author
- Phil Schatzmann
- Copyright
- Apache License Version 2
◆ begin()
| virtual bool A2DPEncoder::begin |
( |
const esp_a2d_mcc_t & |
mcc | ) |
|
|
inlinevirtual |
Opens the wrapped audio_tools encoder for the negotiated SEP configuration: calls parse_audio_info(mcc) and configure(mcc) (implemented per codec), then wires up the frame output and starts the encoder.
Reimplemented in A2DPEncoderAAC.
◆ build_capability()
| virtual void A2DPEncoder::build_capability |
( |
esp_a2d_mcc_t & |
mcc | ) |
|
|
pure virtual |
◆ codec_type()
| virtual esp_a2d_mct_t A2DPEncoder::codec_type |
( |
| ) |
|
|
pure virtual |
◆ configure()
| virtual void A2DPEncoder::configure |
( |
const esp_a2d_mcc_t & |
mcc | ) |
|
|
inlineprotectedvirtual |
◆ max_frames_per_packet()
| virtual int A2DPEncoder::max_frames_per_packet |
( |
| ) |
|
|
inlinevirtual |
Max number of encoded frames that can be combined in one media packet.
Reimplemented in A2DPEncoderSBC.
◆ mime()
| virtual const char * A2DPEncoder::mime |
( |
| ) |
|
|
pure virtual |
◆ parse_audio_info()
| virtual void A2DPEncoder::parse_audio_info |
( |
const esp_a2d_mcc_t & |
mcc | ) |
|
|
protectedpure virtual |
◆ payload_header_size()
| virtual uint16_t A2DPEncoder::payload_header_size |
( |
| ) |
|
|
inlinevirtual |
Bytes of the audio MTU that are needed by the media payload header which is added by the stack (e.g. SBC: 1 byte, AAC: LATM header)
Reimplemented in A2DPEncoderSBC.
◆ samples_per_frame()
| virtual uint32_t A2DPEncoder::samples_per_frame |
( |
| ) |
|
|
pure virtual |
Number of samples (per channel) covered by one encoded frame: used for the media packet timestamps
Implemented in A2DPEncoderAAC, and A2DPEncoderSBC.
◆ set_sample_rate()
| void A2DPEncoder::set_sample_rate |
( |
int |
rate | ) |
|
|
inline |
◆ write()
| virtual size_t A2DPEncoder::write |
( |
const uint8_t * |
pcm, |
|
|
size_t |
len |
|
) |
| |
|
inlinevirtual |
Feeds 16 bit stereo PCM to the wrapped encoder (downmixed to mono if this was negotiated); the encoded frames are forwarded to the frame sink
◆ write_encoded()
| virtual void A2DPEncoder::write_encoded |
( |
const uint8_t * |
data, |
|
|
size_t |
len |
|
) |
| |
|
inlineprotectedvirtual |
Receives the output of the wrapped encoder: by default each write is expected to be exactly one encoded frame
Reimplemented in A2DPEncoderAAC.
The documentation for this class was generated from the following file: