Babel
Epitech's C++ VoIP project
Public Member Functions | Private Attributes | List of all members
Babel::Opus Class Reference

Class containing Opus encoder and decoder. More...

#include <Opus.hpp>

Inheritance diagram for Babel::Opus:
Collaboration diagram for Babel::Opus:

Public Member Functions

 Opus ()
 
 ~Opus () override
 ctor More...
 
int encode (const std::int16_t *pcm, unsigned char *data) override
 dtor More...
 
int encode (const float *pcm, unsigned char *data) override
 same as Encode() with floats More...
 
int decode (const unsigned char *data, std::int16_t *pcm, std::int32_t dataSize) override
 Decodes exactly one frame of audio data. More...
 
int decode (const unsigned char *data, float *pcm) override
 Same as Decode() with floats. More...
 
std::int32_t getBitrate () const override
 get the bitrate More...
 
void setBitrate (std::int32_t bitrate) override
 Sets the bitrate. More...
 
int getChannel () const override
 get the channels More...
 
void setChannel (int channel) override
 sets the channel More...
 
int getApplication () const override
 get the application type More...
 
void setApplication (int application) override
 sets the Opus application mode Possible values are OPUS_APPLICATION_AUDIO (default) OPUS_APPLICATION_VOIP OPUS_APPLICATION_RESTRICTED_LOWDELAY More...
 
int getFrameSize () const override
 get the frame size More...
 
void setFrameSize (int frameSize) override
 sets the number of samples per channel Possible values are 120/480/960 (default)/1920/2880 More...
 
bool isEncoderInitialized () const
 false if encoder failed to initialize More...
 
bool isDecoderInitialized () const
 false if decoder failed to initialize More...
 
- Public Member Functions inherited from Babel::ICodec
virtual ~ICodec ()=default
 

Private Attributes

OpusEncoder * _encoder
 Contains the encoder state. More...
 
bool _encoderIsInitialized
 True if encoder state is allocated and initialized, false otherwise. More...
 
bool _decoderIsInitialized
 True if decoder state is allocated and initialized, false otherwise. More...
 
OpusDecoder * _decoder
 Contains the decoder state. More...
 
opus_int32 _bitrate
 Decoder and encoder bitrate (default 48000) More...
 
int _channel
 Decoder and encoder audio channels (default 2) More...
 
int _application
 Encoder application mode (default OPUS_APPLICATION_VOIP) More...
 
int _frameSize
 Number of samples per channel in the input signal (default 960) More...
 
std::int32_t _dataSize
 Max duration of the frame in samples (per channel) that can fit into the decoded_frame array. More...
 
std::mutex _mutex
 Class mutex. More...
 

Detailed Description

Class containing Opus encoder and decoder.

Constructor & Destructor Documentation

◆ Opus()

Babel::Opus::Opus ( )

◆ ~Opus()

Babel::Opus::~Opus ( )
override

ctor

Member Function Documentation

◆ decode() [1/2]

int Babel::Opus::decode ( const unsigned char *  data,
float *  pcm 
)
overridevirtual

Same as Decode() with floats.

Implements Babel::ICodec.

◆ decode() [2/2]

int Babel::Opus::decode ( const unsigned char *  data,
std::int16_t *  pcm,
std::int32_t  dataSize 
)
overridevirtual

Decodes exactly one frame of audio data.

Parameters
datathe frame to decode, can be nullptr in case of packet loss
pcmdecoded data
Returns
number of samples decoded

Implements Babel::ICodec.

◆ encode() [1/2]

int Babel::Opus::encode ( const float *  pcm,
unsigned char *  data 
)
overridevirtual

same as Encode() with floats

Implements Babel::ICodec.

◆ encode() [2/2]

int Babel::Opus::encode ( const std::int16_t *  pcm,
unsigned char *  data 
)
overridevirtual

dtor

Encodes exactly one frame of audio data

Parameters
pcmthe frame to encode
dataencoded output

Implements Babel::ICodec.

◆ getApplication()

int Babel::Opus::getApplication ( ) const
overridevirtual

get the application type

Implements Babel::ICodec.

◆ getBitrate()

opus_int32 Babel::Opus::getBitrate ( ) const
overridevirtual

get the bitrate

Implements Babel::ICodec.

◆ getChannel()

int Babel::Opus::getChannel ( ) const
overridevirtual

get the channels

Implements Babel::ICodec.

◆ getFrameSize()

int Babel::Opus::getFrameSize ( ) const
overridevirtual

get the frame size

Implements Babel::ICodec.

◆ isDecoderInitialized()

bool Babel::Opus::isDecoderInitialized ( ) const

false if decoder failed to initialize

◆ isEncoderInitialized()

bool Babel::Opus::isEncoderInitialized ( ) const

false if encoder failed to initialize

◆ setApplication()

void Babel::Opus::setApplication ( int  application)
overridevirtual

sets the Opus application mode Possible values are OPUS_APPLICATION_AUDIO (default) OPUS_APPLICATION_VOIP OPUS_APPLICATION_RESTRICTED_LOWDELAY

Implements Babel::ICodec.

◆ setBitrate()

void Babel::Opus::setBitrate ( std::int32_t  bitrate)
overridevirtual

Sets the bitrate.

Implements Babel::ICodec.

◆ setChannel()

void Babel::Opus::setChannel ( int  channel)
overridevirtual

sets the channel

Implements Babel::ICodec.

◆ setFrameSize()

void Babel::Opus::setFrameSize ( int  frameSize)
overridevirtual

sets the number of samples per channel Possible values are 120/480/960 (default)/1920/2880

Implements Babel::ICodec.

Member Data Documentation

◆ _application

int Babel::Opus::_application
private

Encoder application mode (default OPUS_APPLICATION_VOIP)

◆ _bitrate

opus_int32 Babel::Opus::_bitrate
private

Decoder and encoder bitrate (default 48000)

◆ _channel

int Babel::Opus::_channel
private

Decoder and encoder audio channels (default 2)

◆ _dataSize

std::int32_t Babel::Opus::_dataSize
private

Max duration of the frame in samples (per channel) that can fit into the decoded_frame array.

◆ _decoder

OpusDecoder* Babel::Opus::_decoder
private

Contains the decoder state.

◆ _decoderIsInitialized

bool Babel::Opus::_decoderIsInitialized
private

True if decoder state is allocated and initialized, false otherwise.

◆ _encoder

OpusEncoder* Babel::Opus::_encoder
private

Contains the encoder state.

◆ _encoderIsInitialized

bool Babel::Opus::_encoderIsInitialized
private

True if encoder state is allocated and initialized, false otherwise.

◆ _frameSize

int Babel::Opus::_frameSize
private

Number of samples per channel in the input signal (default 960)

◆ _mutex

std::mutex Babel::Opus::_mutex
private

Class mutex.


The documentation for this class was generated from the following files: