diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
commit | e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch) | |
tree | 68cb5ef9081156392f1dd62a00c6ccc1451b93df /plugins/codecs/iLBC | |
parent | Initial commit. (diff) | |
download | wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.tar.xz wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.zip |
Adding upstream version 4.2.2.upstream/4.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'plugins/codecs/iLBC')
-rw-r--r-- | plugins/codecs/iLBC/CMakeLists.txt | 66 | ||||
-rw-r--r-- | plugins/codecs/iLBC/iLBCdecode.c | 141 |
2 files changed, 207 insertions, 0 deletions
diff --git a/plugins/codecs/iLBC/CMakeLists.txt b/plugins/codecs/iLBC/CMakeLists.txt new file mode 100644 index 00000000..89292043 --- /dev/null +++ b/plugins/codecs/iLBC/CMakeLists.txt @@ -0,0 +1,66 @@ +# CMakeLists.txt +# +# Wireshark - Network traffic analyzer +# By Gerald Combs <gerald@wireshark.org> +# Copyright 1998 Gerald Combs +# +# SPDX-License-Identifier: GPL-2.0-or-later +# + +include(WiresharkPlugin) + +# Plugin name and version info (major minor micro extra) +set_module_info(ilbc 0 1 0 0) + +set(CODEC_SRC + iLBCdecode.c +) + +set(PLUGIN_FILES + plugin.c + ${CODEC_SRC} +) + +set_source_files_properties( + ${PLUGIN_FILES} + PROPERTIES + COMPILE_FLAGS "${WERROR_COMMON_FLAGS}" +) + +register_plugin_files(plugin.c + plugin_codec + ${CODEC_SRC} +) + +add_wireshark_plugin_library(ilbc codecs) + +target_include_directories(ilbc PRIVATE ${CMAKE_SOURCE_DIR}/codecs) + +target_link_libraries(ilbc wsutil ${ILBC_LIBRARIES}) + +target_include_directories(ilbc SYSTEM PRIVATE ${ILBC_INCLUDE_DIRS}) + +install_plugin(ilbc codecs) + +file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h") +CHECKAPI( + NAME + ilbc + SWITCHES + SOURCES + ${CODEC_SRC} + ${CODEC_HEADERS} +) + +# +# Editor modelines - https://www.wireshark.org/tools/modelines.html +# +# Local variables: +# c-basic-offset: 8 +# tab-width: 8 +# indent-tabs-mode: t +# End: +# +# vi: set shiftwidth=8 tabstop=8 noexpandtab: +# :indentSize=8:tabSize=8:noTabs=false: +# diff --git a/plugins/codecs/iLBC/iLBCdecode.c b/plugins/codecs/iLBC/iLBCdecode.c new file mode 100644 index 00000000..d127f160 --- /dev/null +++ b/plugins/codecs/iLBC/iLBCdecode.c @@ -0,0 +1,141 @@ +/* iLBCdecode.c + * iLBC codec + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "config.h" + +#include <stdio.h> + +#include <glib.h> + +#include "ilbc.h" +#include "wsutil/codecs.h" +#include "ws_attributes.h" + +#define ILBC_20MS 20 +#define ILBC_30MS 30 +#define ILBC_PAYLOAD_LEN_20MS 38 +#define ILBC_PAYLOAD_LEN_30MS 50 +#define SAMPLE_SIZE 2 + +typedef struct { +#ifdef LIBILBC_VERSION_MAJOR + IlbcDecoderInstance *ilbc_ctx; /* Real iLBC context */ +#else + iLBC_decinst_t *ilbc_ctx; /* Real iLBC context */ +#endif + guint8 payload_len; /* Remember last payload_len */ +} ilbc_ctx_t; + +void codec_register_iLBC(void); + +static void * +codec_iLBC_init(codec_context_t *ctx _U_) +{ + ilbc_ctx_t *priv; + + priv=(ilbc_ctx_t *)g_malloc0(sizeof(*priv)); + WebRtcIlbcfix_DecoderCreate(&(priv->ilbc_ctx)); + + return priv; +} + +static void +codec_iLBC_release(codec_context_t *ctx) +{ + WebRtcIlbcfix_DecoderFree(((ilbc_ctx_t *)ctx->priv)->ilbc_ctx); + g_free(ctx); +} + +static unsigned +codec_iLBC_get_channels(codec_context_t *ctx _U_) +{ + return 1; +} + +static unsigned +codec_iLBC_get_frequency(codec_context_t *ctx _U_) +{ + return 8000; +} + +static size_t +codec_iLBC_decode(codec_context_t *ctx, + const void *inputBytes, size_t inputBytesSize, + void *outputSamples, size_t *outputSamplesSize) +{ + int16_t speechType; // Not used in Wireshark code +#ifdef LIBILBC_VERSION_MAJOR + int8_t *dataIn = (int8_t *)inputBytes; +#else + int16_t *dataIn = (int16_t *)inputBytes; +#endif + int16_t *dataOut = (int16_t *)outputSamples; + ilbc_ctx_t *dataCtx = (ilbc_ctx_t *)ctx->priv; + size_t outputSamplesCount; + + if (!outputSamples || !outputSamplesSize) + { + if (0 == inputBytesSize%ILBC_PAYLOAD_LEN_20MS) { + /* 20ms packet size = 160 samples = 320 bytes */ + return BLOCKL_20MS*SAMPLE_SIZE; + } else if (0 == inputBytesSize%ILBC_PAYLOAD_LEN_30MS) { + /* 30ms packet size = 240 samples = 480 bytes */ + return BLOCKL_30MS*SAMPLE_SIZE; + } else { + /* unknown packet size */ + return 0; + } + } + + if (0 == inputBytesSize%ILBC_PAYLOAD_LEN_20MS) { + /* 20ms packet size */ + if (dataCtx->payload_len != ILBC_20MS) { + WebRtcIlbcfix_DecoderInit(dataCtx->ilbc_ctx, ILBC_20MS); + dataCtx->payload_len = ILBC_20MS; + } + outputSamplesCount = WebRtcIlbcfix_Decode(dataCtx->ilbc_ctx, dataIn, + (int16_t)inputBytesSize, dataOut, &speechType); + } else if (0 == inputBytesSize%ILBC_PAYLOAD_LEN_30MS) { + /* 30ms packet size */ + if (dataCtx->payload_len != ILBC_30MS) { + WebRtcIlbcfix_DecoderInit(dataCtx->ilbc_ctx, ILBC_30MS); + dataCtx->payload_len = ILBC_30MS; + } + outputSamplesCount = WebRtcIlbcfix_Decode(dataCtx->ilbc_ctx, dataIn, + (int16_t)inputBytesSize, dataOut, &speechType); + } else { + /* unknown packet size */ + outputSamplesCount = 0; + } + + /* WebRtcIlbcfix_Decode returns count of samples, but we return count of bytes */ + *outputSamplesSize = outputSamplesCount*SAMPLE_SIZE; + return *outputSamplesSize; +} + +void +codec_register_iLBC(void) +{ + register_codec("iLBC", codec_iLBC_init, codec_iLBC_release, + codec_iLBC_get_channels, codec_iLBC_get_frequency, codec_iLBC_decode); +} + +/* + * Editor modelines - https://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ |