Skip to content

Codec

class Codec

Audio file reader and writer.

The Codec class is used to implement an audio file reader and writer. This is the base class for all audio codecs, each implementation should allow to build decoders and encoders.

Types

Name Description
Decoder Audio file reader.
Encoder Audio file writer.

Variables

Name Description
m_name The name of this codec.

Functions

Name Description
Codec Create a new Codec instance.
~Codec Default destructor.
CreateDecoder Creates a new instance of the decoder associated to this codec.
DestroyDecoder Destroys the decoder associated to this codec.
CreateEncoder Creates a new instance of the encoder associated to this codec.
DestroyEncoder Destroys the encoder associated to this codec.
CanHandleFile Checks whether this Codec can handle the file at the given path.
GetName Gets the name of this codec.
Register Registers a new audio codec.
Unregister Unregisters a audio codec.
Find Look up a codec by name.
FindCodecForFile Finds the codec which can handle the given file.
LockRegistry Locks the codecs registry.
UnlockRegistry Unlocks the codecs registry.

Variable Details

m_name

AmString m_name

The name of this codec.

Function Details

CanHandleFile

[[nodiscard]] virtual bool CanHandleFile(std::shared_ptr<File> file) const = 0

Checks whether this Codec can handle the file at the given path.

Parameter file
The file to check.
Return
true if the Codec can handle the file, false otherwise.

Codec

explicit Codec(AmString name)

Create a new Codec instance.

Parameter name
The codec name. Recommended names are "FILE_EXTENSION". eg. "WAV" or "OGG".

CreateDecoder

* CreateDecoder()

Creates a new instance of the decoder associated to this codec.

Return
A Decoder instance.

CreateEncoder

* CreateEncoder()

Creates a new instance of the encoder associated to this codec.

Return
An Encoder instance.

DestroyDecoder

virtual void DestroyDecoder(Decoder* decoder) = 0

Destroys the decoder associated to this codec.

Parameter decoder
The decoder instance to destroy.

DestroyEncoder

virtual void DestroyEncoder(Encoder* encoder) = 0

Destroys the encoder associated to this codec.

Parameter encoder
The encoder instance to destroy.

Find

static Codec* Find(const AmString& name)

Look up a codec by name.

Parameter name
The name of the codec to find.
Return
The codec with the given name, or nullptr if none.

FindCodecForFile

static Codec* FindCodecForFile(std::shared_ptr<File> file)

Finds the codec which can handle the given file.

Parameter file
The file to find the codec for.
Return
The codec which can handle the given file, or nullptr if none.

GetName

[[nodiscard]] const AmString& GetName() const

Gets the name of this codec.

Return
The name of this codec.

LockRegistry

static void LockRegistry()

Locks the codecs registry.

Warning

This function is mainly used for internal purposes. It's called before the Engine initialization, to discard the registration of new codecs after the engine is fully loaded.

Register

static void Register(Codec* codec)

Registers a new audio codec.

Parameter codec
The audio codec to add in the registry.

UnlockRegistry

static void UnlockRegistry()

Unlocks the codecs registry.

Warning

This function is mainly used for internal purposes. It's called after the Engine deinitialization, to allow the registration of new codecs after the engine is fully unloaded.

Unregister

static void Unregister(const Codec* codec)

Unregisters a audio codec.

Parameter codec
The audio codec to remove from the registry.

~Codec

virtual ~Codec()

Default destructor.