Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
codecs.h File Reference
#include "ws_symbol_export.h"
#include "ws_attributes.h"
#include <stdbool.h>
#include "wsutil/wmem/wmem_map.h"

Go to the source code of this file.

Classes

struct  codecs_plugin
 
struct  _codec_context_t
 

Typedefs

typedef struct codec_handlecodec_handle_t
 
typedef struct _codec_context_t codec_context_t
 
typedef void *(* codec_init_fn) (codec_context_t *context)
 Initialize context of codec. Context can contain any information required by codec to pass between calls Note: There is just one codec context in runtime therefore no RTP stream related information should be stored in the context!
 
typedef void(* codec_release_fn) (codec_context_t *context)
 Destroy context of codec.
 
typedef unsigned(* codec_get_channels_fn) (codec_context_t *context)
 Get count of channels provided by the codec.
 
typedef unsigned(* codec_get_frequency_fn) (codec_context_t *context)
 Get frequency/rate provided by the codec.
 
typedef size_t(* codec_decode_fn) (codec_context_t *context, const void *inputBytes, size_t inputBytesSize, void *outputSamples, size_t *outputSamplesSize)
 Decode one frame of payload.
 

Functions

WS_DLL_PUBLIC void codecs_register_plugin (const codecs_plugin *plug)
 Register a codec plugin with the system.
 
WS_DLL_PUBLIC void codecs_init (const char *app_env_var_prefix)
 Initialize all built-in and plugin-based codecs.
 
WS_DLL_PUBLIC void codecs_cleanup (void)
 Clean up all registered codecs.
 
WS_DLL_PUBLIC void codec_get_compiled_version_info (GString *str)
 Retrieve compile-time version information for codec-related libraries.
 
WS_DLL_PUBLIC bool register_codec (const char *name, codec_init_fn init_fn, codec_release_fn release_fn, codec_get_channels_fn channels_fn, codec_get_frequency_fn frequency_fn, codec_decode_fn decode_fn)
 Register a new codec implementation.
 
WS_DLL_PUBLIC bool deregister_codec (const char *name)
 Deregister a previously registered codec.
 
WS_DLL_PUBLIC codec_handle_t find_codec (const char *name)
 Find a registered codec by name.
 
WS_DLL_PUBLIC void * codec_init (codec_handle_t codec, codec_context_t *context)
 Initialize codec-specific state.
 
WS_DLL_PUBLIC void codec_release (codec_handle_t codec, codec_context_t *context)
 Release codec-specific resources.
 
WS_DLL_PUBLIC unsigned codec_get_channels (codec_handle_t codec, codec_context_t *context)
 Query the number of audio channels for a codec.
 
WS_DLL_PUBLIC unsigned codec_get_frequency (codec_handle_t codec, codec_context_t *context)
 Query the sample rate for a codec.
 
WS_DLL_PUBLIC size_t codec_decode (codec_handle_t codec, codec_context_t *context, const void *inputBytes, size_t inputBytesSize, void *outputSamples, size_t *outputSamplesSize)
 Decode input bytes into audio samples.
 

Detailed Description

codecs interface 2007 Tomas Kukosa

Wireshark - Network traffic analyzer By Gerald Combs geral.nosp@m.d@wi.nosp@m.resha.nosp@m.rk.o.nosp@m.rg Copyright 1998 Gerald Combs

SPDX-License-Identifier: GPL-2.0-or-later

Typedef Documentation

◆ codec_decode_fn

typedef size_t(* codec_decode_fn) (codec_context_t *context, const void *inputBytes, size_t inputBytesSize, void *outputSamples, size_t *outputSamplesSize)

Decode one frame of payload.

Function is called twice, with different values of parameters: (1) To query size of required buffer in bytes for decoded samples pointed by inputBytes: outputSamples or outputSamplesSize must be set NULL (2) To decode samples: outputSamples points to allocated memory, outputSamplesSize is set to value returned in step (1)

Parameters
contextPointer to codec context
inputBytesPointer to input frame
inputBytesSizeLength of input frame in bytes (count of bytes to decode)
outputSamplesPointer to output buffer with samples
outputSamplesSizeLength of output buffer in bytes (not samples!) Function can override this value. All codecs set it to same value as it returns in (2) when (2) is called.
Returns
Count of required bytes (!not samples) to allocate in (1) or Count of decoded bytes (!not samples) in (2)

◆ codec_get_channels_fn

typedef unsigned(* codec_get_channels_fn) (codec_context_t *context)

Get count of channels provided by the codec.

Parameters
contextPointer to codec context
Returns
Count of channels (e.g. 1)

◆ codec_get_frequency_fn

typedef unsigned(* codec_get_frequency_fn) (codec_context_t *context)

Get frequency/rate provided by the codec.

Parameters
contextPointer to codec context
Returns
Frequency (e.g. 8000)

◆ codec_init_fn

typedef void *(* codec_init_fn) (codec_context_t *context)

Initialize context of codec. Context can contain any information required by codec to pass between calls Note: There is just one codec context in runtime therefore no RTP stream related information should be stored in the context!

Returns
Pointer to codec context

◆ codec_release_fn

typedef void(* codec_release_fn) (codec_context_t *context)

Destroy context of codec.

Parameters
contextPointer to codec context

Function Documentation

◆ codec_decode()

WS_DLL_PUBLIC size_t codec_decode ( codec_handle_t  codec,
codec_context_t context,
const void *  inputBytes,
size_t  inputBytesSize,
void *  outputSamples,
size_t *  outputSamplesSize 
)

Decode input bytes into audio samples.

Converts encoded input data into raw audio samples. The output buffer must be large enough to hold the decoded samples. The actual number of samples written is returned via outputSamplesSize.

Parameters
codecHandle to the codec.
contextPointer to the associated context.
inputBytesPointer to encoded input data.
inputBytesSizeSize of the input data in bytes.
outputSamplesPointer to output buffer for decoded samples.
outputSamplesSizePointer to variable receiving the number of bytes written.
Returns
Number of bytes consumed from input.

◆ codec_get_channels()

WS_DLL_PUBLIC unsigned codec_get_channels ( codec_handle_t  codec,
codec_context_t context 
)

Query the number of audio channels for a codec.

Returns the channel count (e.g., 1 for mono, 2 for stereo).

Parameters
codecHandle to the codec.
contextPointer to the associated context.
Returns
Number of channels.

◆ codec_get_compiled_version_info()

WS_DLL_PUBLIC void codec_get_compiled_version_info ( GString *  str)

Retrieve compile-time version information for codec-related libraries.

Appends version details for all libraries linked with libwscodecs at build time to the provided GString.

Parameters
strPointer to a GString that will receive the formatted version info.

◆ codec_get_frequency()

WS_DLL_PUBLIC unsigned codec_get_frequency ( codec_handle_t  codec,
codec_context_t context 
)

Query the sample rate for a codec.

Returns the sample rate in Hz (e.g., 8000, 44100).

Parameters
codecHandle to the codec.
contextPointer to the associated context.
Returns
Sample rate in Hz.

◆ codec_init()

WS_DLL_PUBLIC void * codec_init ( codec_handle_t  codec,
codec_context_t context 
)

Initialize codec-specific state.

Prepares the codec for decoding using the provided context.

Parameters
codecHandle to the codec.
contextPointer to a codec_context_t structure.
Returns
Pointer to codec-specific state, or NULL on failure.

◆ codec_release()

WS_DLL_PUBLIC void codec_release ( codec_handle_t  codec,
codec_context_t context 
)

Release codec-specific resources.

Cleans up any state associated with the codec and context.

Parameters
codecHandle to the codec.
contextPointer to the associated context.

◆ codecs_cleanup()

WS_DLL_PUBLIC void codecs_cleanup ( void  )

Clean up all registered codecs.

Releases resources associated with built-in and plugin-based codecs. This function is typically called during shutdown or when reinitializing codec support (e.g., after preference changes).

◆ codecs_init()

WS_DLL_PUBLIC void codecs_init ( const char *  app_env_var_prefix)

Initialize all built-in and plugin-based codecs.

Invokes the registration routines for all supported codecs, including statically linked and dynamically loaded plugins. This function should be called during application startup or dissector initialization to ensure codec availability for decoding and playback.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get plugin directory.

◆ codecs_register_plugin()

WS_DLL_PUBLIC void codecs_register_plugin ( const codecs_plugin plug)

Register a codec plugin with the system.

Adds the specified codec plugin to the internal registry, enabling support for additional encoding or decoding formats. This function is typically called during plugin initialization to make custom codecs available for dissection or playback.

Parameters
plugPointer to a codecs_plugin structure describing the plugin.

◆ deregister_codec()

WS_DLL_PUBLIC bool deregister_codec ( const char *  name)

Deregister a previously registered codec.

Removes the codec identified by name from the internal registry.

Parameters
nameName of the codec to remove.
Returns
true if the codec was found and removed, false otherwise.

◆ find_codec()

WS_DLL_PUBLIC codec_handle_t find_codec ( const char *  name)

Find a registered codec by name.

Retrieves a handle to the codec identified by name, if available.

Parameters
nameName of the codec to locate.
Returns
Handle to the codec, or NULL if not found.

◆ register_codec()

WS_DLL_PUBLIC bool register_codec ( const char *  name,
codec_init_fn  init_fn,
codec_release_fn  release_fn,
codec_get_channels_fn  channels_fn,
codec_get_frequency_fn  frequency_fn,
codec_decode_fn  decode_fn 
)

Register a new codec implementation.

Adds a codec to the internal registry using the provided function pointers. This enables support for custom decoding logic and metadata access.

Parameters
nameUnique name identifying the codec.
init_fnFunction to initialize codec state.
release_fnFunction to release codec resources.
channels_fnFunction to query channel count.
frequency_fnFunction to query sample rate.
decode_fnFunction to decode input bytes into audio samples.
Returns
true if registration succeeded, false otherwise.