summaryrefslogtreecommitdiffstats
path: root/plugins/codecs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:34:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:34:10 +0000
commite4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch)
tree68cb5ef9081156392f1dd62a00c6ccc1451b93df /plugins/codecs
parentInitial commit. (diff)
downloadwireshark-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')
-rw-r--r--plugins/codecs/G711/CMakeLists.txt64
-rw-r--r--plugins/codecs/G711/G711decode.c202
-rw-r--r--plugins/codecs/G722/CMakeLists.txt66
-rw-r--r--plugins/codecs/G722/G722decode.c99
-rw-r--r--plugins/codecs/G726/CMakeLists.txt66
-rw-r--r--plugins/codecs/G726/G726decode.c135
-rw-r--r--plugins/codecs/G729/CMakeLists.txt66
-rw-r--r--plugins/codecs/G729/G729decode.c109
-rw-r--r--plugins/codecs/amrnb/CMakeLists.txt66
-rw-r--r--plugins/codecs/amrnb/amrdecode.c274
-rw-r--r--plugins/codecs/iLBC/CMakeLists.txt66
-rw-r--r--plugins/codecs/iLBC/iLBCdecode.c141
-rw-r--r--plugins/codecs/l16_mono/AUTHORS2
-rw-r--r--plugins/codecs/l16_mono/CMakeLists.txt64
-rw-r--r--plugins/codecs/l16_mono/README3
-rw-r--r--plugins/codecs/l16_mono/l16decode.c122
-rw-r--r--plugins/codecs/opus_dec/CMakeLists.txt66
-rw-r--r--plugins/codecs/opus_dec/opusdecode.c107
-rw-r--r--plugins/codecs/sbc/CMakeLists.txt66
-rw-r--r--plugins/codecs/sbc/sbc.c142
20 files changed, 1926 insertions, 0 deletions
diff --git a/plugins/codecs/G711/CMakeLists.txt b/plugins/codecs/G711/CMakeLists.txt
new file mode 100644
index 00000000..cc9ff0f1
--- /dev/null
+++ b/plugins/codecs/G711/CMakeLists.txt
@@ -0,0 +1,64 @@
+# 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(g711 0 1 0 0)
+
+set(CODEC_SRC
+ G711decode.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(g711 codecs)
+
+target_include_directories(g711 PRIVATE ${CMAKE_SOURCE_DIR}/codecs)
+
+target_link_libraries(g711 wsutil)
+
+install_plugin(g711 codecs)
+
+file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h")
+CHECKAPI(
+ NAME
+ g711
+ 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/G711/G711decode.c b/plugins/codecs/G711/G711decode.c
new file mode 100644
index 00000000..e15c4076
--- /dev/null
+++ b/plugins/codecs/G711/G711decode.c
@@ -0,0 +1,202 @@
+/* G711adecode.c
+ * A-law G.711 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 <glib.h>
+
+#include "wsutil/codecs.h"
+#include "ws_attributes.h"
+
+static gint16 ulaw_exp_table[256] = {
+ -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
+ -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
+ -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
+ -11900,-11388,-10876,-10364, -9852, -9340, -8828, -8316,
+ -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
+ -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
+ -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
+ -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
+ -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
+ -1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
+ -876, -844, -812, -780, -748, -716, -684, -652,
+ -620, -588, -556, -524, -492, -460, -428, -396,
+ -372, -356, -340, -324, -308, -292, -276, -260,
+ -244, -228, -212, -196, -180, -164, -148, -132,
+ -120, -112, -104, -96, -88, -80, -72, -64,
+ -56, -48, -40, -32, -24, -16, -8, 0,
+ 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
+ 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
+ 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
+ 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
+ 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
+ 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
+ 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
+ 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
+ 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
+ 1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
+ 876, 844, 812, 780, 748, 716, 684, 652,
+ 620, 588, 556, 524, 492, 460, 428, 396,
+ 372, 356, 340, 324, 308, 292, 276, 260,
+ 244, 228, 212, 196, 180, 164, 148, 132,
+ 120, 112, 104, 96, 88, 80, 72, 64,
+ 56, 48, 40, 32, 24, 16, 8, 0
+};
+
+static gint16 alaw_exp_table[256] = {
+ -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
+ -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
+ -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
+ -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392,
+ -22016,-20992,-24064,-23040,-17920,-16896,-19968,-18944,
+ -30208,-29184,-32256,-31232,-26112,-25088,-28160,-27136,
+ -11008,-10496,-12032,-11520, -8960, -8448, -9984, -9472,
+ -15104,-14592,-16128,-15616,-13056,-12544,-14080,-13568,
+ -344, -328, -376, -360, -280, -264, -312, -296,
+ -472, -456, -504, -488, -408, -392, -440, -424,
+ -88, -72, -120, -104, -24, -8, -56, -40,
+ -216, -200, -248, -232, -152, -136, -184, -168,
+ -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184,
+ -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696,
+ -688, -656, -752, -720, -560, -528, -624, -592,
+ -944, -912, -1008, -976, -816, -784, -880, -848,
+ 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736,
+ 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784,
+ 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368,
+ 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
+ 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944,
+ 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136,
+ 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472,
+ 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568,
+ 344, 328, 376, 360, 280, 264, 312, 296,
+ 472, 456, 504, 488, 408, 392, 440, 424,
+ 88, 72, 120, 104, 24, 8, 56, 40,
+ 216, 200, 248, 232, 152, 136, 184, 168,
+ 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184,
+ 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
+ 688, 656, 752, 720, 560, 528, 624, 592,
+ 944, 912, 1008, 976, 816, 784, 880, 848
+};
+
+void codec_register_g711(void);
+
+static void *
+codec_g711u_init(codec_context_t *ctx _U_)
+{
+ return NULL;
+}
+
+static void
+codec_g711u_release(codec_context_t *ctx _U_)
+{
+
+}
+
+static unsigned
+codec_g711u_get_channels(codec_context_t *ctx _U_)
+{
+ return 1;
+}
+
+static unsigned
+codec_g711u_get_frequency(codec_context_t *ctx _U_)
+{
+ return 8000;
+}
+
+static size_t
+codec_g711u_decode(codec_context_t *ctx _U_,
+ const void *inputBytes, size_t inputBytesSize,
+ void *outputSamples, size_t *outputSamplesSize)
+{
+ const guint8 *dataIn = (const guint8 *) inputBytes;
+ gint16 *dataOut = (gint16 *) outputSamples;
+ size_t i;
+
+ if (!outputSamples || !outputSamplesSize) {
+ return inputBytesSize * 2;
+ }
+
+ for (i = 0; i < inputBytesSize; i++)
+ {
+ dataOut[i] = ulaw_exp_table[dataIn[i]];
+ }
+
+ *outputSamplesSize = inputBytesSize * 2;
+ return inputBytesSize * 2;
+}
+
+static void *
+codec_g711a_init(codec_context_t *ctx _U_)
+{
+ return NULL;
+}
+
+static void
+codec_g711a_release(codec_context_t *ctx _U_)
+{
+
+}
+
+static unsigned
+codec_g711a_get_channels(codec_context_t *ctx _U_)
+{
+ return 1;
+}
+
+static unsigned
+codec_g711a_get_frequency(codec_context_t *ctx _U_)
+{
+ return 8000;
+}
+
+static size_t
+codec_g711a_decode(codec_context_t *ctx _U_,
+ const void *inputBytes, size_t inputBytesSize,
+ void *outputSamples, size_t *outputSamplesSize)
+{
+ const guint8 *dataIn = (const guint8 *) inputBytes;
+ gint16 *dataOut = (gint16 *) outputSamples;
+ size_t i;
+
+ if (!outputSamples || !outputSamplesSize) {
+ return inputBytesSize * 2;
+ }
+
+ for (i = 0; i < inputBytesSize; i++)
+ {
+ dataOut[i] = alaw_exp_table[dataIn[i]];
+ }
+
+ *outputSamplesSize = inputBytesSize * 2;
+ return inputBytesSize * 2;
+}
+
+void
+codec_register_g711(void)
+{
+ register_codec("g711U", codec_g711u_init, codec_g711u_release,
+ codec_g711u_get_channels, codec_g711u_get_frequency, codec_g711u_decode);
+ register_codec("g711A", codec_g711a_init, codec_g711a_release,
+ codec_g711a_get_channels, codec_g711a_get_frequency, codec_g711a_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:
+ */
diff --git a/plugins/codecs/G722/CMakeLists.txt b/plugins/codecs/G722/CMakeLists.txt
new file mode 100644
index 00000000..37c08cd1
--- /dev/null
+++ b/plugins/codecs/G722/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(g722 0 1 0 0)
+
+set(CODEC_SRC
+ G722decode.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(g722 codecs)
+
+target_include_directories(g722 PRIVATE ${CMAKE_SOURCE_DIR}/codecs)
+
+target_link_libraries(g722 wsutil ${SPANDSP_LIBRARIES})
+
+target_include_directories(g722 SYSTEM PRIVATE ${SPANDSP_INCLUDE_DIRS})
+
+install_plugin(g722 codecs)
+
+file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h")
+CHECKAPI(
+ NAME
+ g722
+ 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/G722/G722decode.c b/plugins/codecs/G722/G722decode.c
new file mode 100644
index 00000000..30c46107
--- /dev/null
+++ b/plugins/codecs/G722/G722decode.c
@@ -0,0 +1,99 @@
+/* G722decode.c
+ * G.722 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 <glib.h>
+
+#include "spandsp.h"
+#include "wsutil/codecs.h"
+#include "ws_attributes.h"
+
+void codec_register_g722(void);
+
+static void *
+codec_g722_init(codec_context_t *ctx _U_)
+{
+ g722_decode_state_t *state;
+
+ /* Valid values for bit_rate for G.722 are 48000, 56000, 64000, but RTP/AVP
+ * profile requires 64kbps, aligned at octets. */
+ state = g722_decode_init(NULL, 64000, 0);
+
+ return state;
+}
+
+static void
+codec_g722_release(codec_context_t *ctx)
+{
+ g722_decode_state_t *state = (g722_decode_state_t *)ctx->priv;
+
+ if (!state) {
+ return; /* out-of-memory; */
+ }
+
+ /* Note: replaces g722_decode_release since SpanDSP 20090211 */
+ g722_decode_free(state);
+}
+
+static unsigned
+codec_g722_get_channels(codec_context_t *ctx _U_)
+{
+ /* G.722 has only one channel. */
+ return 1;
+}
+
+static unsigned
+codec_g722_get_frequency(codec_context_t *ctx _U_)
+{
+ /* Note: RTP Clock rate is 8kHz due to a historic error, but actual sampling
+ * rate is 16kHz (RFC 3551, section 4.5.2). */
+ return 16000;
+}
+
+static size_t
+codec_g722_decode(codec_context_t *ctx, const void *inputBytes,
+ size_t inputBytesSize, void *outputSamples, size_t *outputSamplesSize)
+{
+ g722_decode_state_t *state = (g722_decode_state_t *)ctx->priv;
+
+ if (!state) {
+ return 0; /* out-of-memory; */
+ }
+
+ if (!outputSamples || !outputSamplesSize) {
+ return 4 * inputBytesSize;
+ }
+
+ /* g722_decode returns the number of 16-bit samples. */
+ *outputSamplesSize = 2 * g722_decode(state, (int16_t *)outputSamples,
+ (const uint8_t *)inputBytes, (int)inputBytesSize);
+ return *outputSamplesSize;
+}
+
+void
+codec_register_g722(void)
+{
+ register_codec("g722", codec_g722_init, codec_g722_release,
+ codec_g722_get_channels, codec_g722_get_frequency, codec_g722_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:
+ */
diff --git a/plugins/codecs/G726/CMakeLists.txt b/plugins/codecs/G726/CMakeLists.txt
new file mode 100644
index 00000000..239b67f0
--- /dev/null
+++ b/plugins/codecs/G726/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(g726 0 1 0 0)
+
+set(CODEC_SRC
+ G726decode.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(g726 codecs)
+
+target_include_directories(g726 PRIVATE ${CMAKE_SOURCE_DIR}/codecs)
+
+target_link_libraries(g726 wsutil ${SPANDSP_LIBRARIES})
+
+target_include_directories(g726 SYSTEM PRIVATE ${SPANDSP_INCLUDE_DIRS})
+
+install_plugin(g726 codecs)
+
+file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h")
+CHECKAPI(
+ NAME
+ g726
+ 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/G726/G726decode.c b/plugins/codecs/G726/G726decode.c
new file mode 100644
index 00000000..92965251
--- /dev/null
+++ b/plugins/codecs/G726/G726decode.c
@@ -0,0 +1,135 @@
+/* G726decode.c
+ * G.726 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 <glib.h>
+
+#include "spandsp.h"
+#include "wsutil/codecs.h"
+#include "ws_attributes.h"
+
+typedef struct _g726_codec_ctx {
+ g726_state_t *state;
+ int bit_rate;
+} g726_codec_ctx;
+
+void codec_register_g726(void);
+
+static void *
+codec_g726_init(int bit_rate, int packing)
+{
+ g726_state_t *decoder = g726_init(NULL, bit_rate, G726_ENCODING_LINEAR, packing);
+
+ if (!decoder) {
+ return NULL; /* out-of-memory; */
+ }
+
+ g726_codec_ctx *state = g_new(g726_codec_ctx, 1);
+ state->state = decoder;
+ state->bit_rate = bit_rate;
+
+ return state;
+}
+
+static void *codec_g726_16_init(codec_context_t *ctx _U_) { return codec_g726_init(16000, G726_PACKING_RIGHT); }
+static void *codec_g726_24_init(codec_context_t *ctx _U_) { return codec_g726_init(24000, G726_PACKING_RIGHT); }
+static void *codec_g726_32_init(codec_context_t *ctx _U_) { return codec_g726_init(32000, G726_PACKING_RIGHT); }
+static void *codec_g726_40_init(codec_context_t *ctx _U_) { return codec_g726_init(40000, G726_PACKING_RIGHT); }
+static void *codec_aal2_g726_16_init(codec_context_t *ctx _U_) { return codec_g726_init(16000, G726_PACKING_LEFT); }
+static void *codec_aal2_g726_24_init(codec_context_t *ctx _U_) { return codec_g726_init(24000, G726_PACKING_LEFT); }
+static void *codec_aal2_g726_32_init(codec_context_t *ctx _U_) { return codec_g726_init(32000, G726_PACKING_LEFT); }
+static void *codec_aal2_g726_40_init(codec_context_t *ctx _U_) { return codec_g726_init(40000, G726_PACKING_LEFT); }
+
+static void
+codec_g726_release(codec_context_t *ctx)
+{
+ g726_codec_ctx *state = (g726_codec_ctx *)(ctx->priv);
+
+ if (!state) {
+ return; /* out-of-memory; */
+ }
+
+ /* Note: replaces g726_release since SpanDSP 20090211 */
+ g726_free(state->state);
+ g_free(state);
+}
+
+static unsigned
+codec_g726_get_channels(codec_context_t *ctx _U_)
+{
+ return 1;
+}
+
+static unsigned
+codec_g726_get_frequency(codec_context_t *ctx _U_)
+{
+ return 8000;
+}
+
+static size_t
+codec_g726_decode(codec_context_t *ctx, const void *inputBytes,
+ size_t inputBytesSize, void *outputSamples, size_t *outputSamplesSize)
+{
+ g726_codec_ctx *state = (g726_codec_ctx *)ctx->priv;
+
+ if (!state) {
+ return 0; /* out-of-memory; */
+ }
+
+ if (!outputSamples || !outputSamplesSize) {
+ /*
+ * sample rate 8kHz, for bitrate 16kHz we have 16/8 = 2 bits/sample, so
+ * 1 input byte (8 bits) will expand to four 16-bit samples. Likewise,
+ * for bitrate 40kHz we have 40/8 = 5 bits/sample. Alternatively:
+ * bitsPerSample = bitRate / sampleRate (8kHz).
+ * outputBytes = (inputBits / bitsPerSample) * sizeof(sample)
+ */
+ return inputBytesSize * 8 / (state->bit_rate / 8000) * 2;
+ }
+
+ /* g726_decode returns the number of 16-bit samples. */
+ *outputSamplesSize = 2 * g726_decode(state->state, (int16_t *)outputSamples, (const uint8_t *) inputBytes, (int)inputBytesSize);
+ return *outputSamplesSize;
+}
+
+void
+codec_register_g726(void)
+{
+ register_codec("G726-16", codec_g726_16_init, codec_g726_release,
+ codec_g726_get_channels, codec_g726_get_frequency, codec_g726_decode);
+ register_codec("G726-24", codec_g726_24_init, codec_g726_release,
+ codec_g726_get_channels, codec_g726_get_frequency, codec_g726_decode);
+ register_codec("G726-32", codec_g726_32_init, codec_g726_release,
+ codec_g726_get_channels, codec_g726_get_frequency, codec_g726_decode);
+ register_codec("G726-40", codec_g726_40_init, codec_g726_release,
+ codec_g726_get_channels, codec_g726_get_frequency, codec_g726_decode);
+ register_codec("AAL2-G726-16", codec_aal2_g726_16_init, codec_g726_release,
+ codec_g726_get_channels, codec_g726_get_frequency, codec_g726_decode);
+ register_codec("AAL2-G726-24", codec_aal2_g726_24_init, codec_g726_release,
+ codec_g726_get_channels, codec_g726_get_frequency, codec_g726_decode);
+ register_codec("AAL2-G726-32", codec_aal2_g726_32_init, codec_g726_release,
+ codec_g726_get_channels, codec_g726_get_frequency, codec_g726_decode);
+ register_codec("AAL2-G726-40", codec_aal2_g726_40_init, codec_g726_release,
+ codec_g726_get_channels, codec_g726_get_frequency, codec_g726_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:
+ */
diff --git a/plugins/codecs/G729/CMakeLists.txt b/plugins/codecs/G729/CMakeLists.txt
new file mode 100644
index 00000000..6c533002
--- /dev/null
+++ b/plugins/codecs/G729/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(g729 0 1 0 0)
+
+set(CODEC_SRC
+ G729decode.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(g729 codecs)
+
+target_include_directories(g729 PRIVATE ${CMAKE_SOURCE_DIR}/codecs)
+
+target_link_libraries(g729 wsutil ${BCG729_LIBRARIES})
+
+target_include_directories(g729 SYSTEM PRIVATE ${BCG729_INCLUDE_DIRS})
+
+install_plugin(g729 codecs)
+
+file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h")
+CHECKAPI(
+ NAME
+ g729
+ 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/G729/G729decode.c b/plugins/codecs/G729/G729decode.c
new file mode 100644
index 00000000..7bb564e6
--- /dev/null
+++ b/plugins/codecs/G729/G729decode.c
@@ -0,0 +1,109 @@
+/* G729decode.c
+ * G.729 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 <glib.h>
+
+#include "bcg729/decoder.h"
+#include "wsutil/codecs.h"
+#include "ws_attributes.h"
+
+void codec_register_g729(void);
+
+static void *
+codec_g729_init(codec_context_t *ctx _U_)
+{
+ return initBcg729DecoderChannel();
+}
+
+static void
+codec_g729_release(codec_context_t *ctx)
+{
+ closeBcg729DecoderChannel((bcg729DecoderChannelContextStruct *)ctx->priv);
+}
+
+static unsigned
+codec_g729_get_channels(codec_context_t *ctx _U_)
+{
+ return 1;
+}
+
+static unsigned
+codec_g729_get_frequency(codec_context_t *ctx _U_)
+{
+ return 8000;
+}
+
+static size_t
+codec_g729_decode(codec_context_t *ctx,
+ const void *inputBytes, size_t inputBytesSize,
+ void *outputSamples, size_t *outputSamplesSize)
+{
+ bcg729DecoderChannelContextStruct *state = (bcg729DecoderChannelContextStruct *)ctx->priv;
+ const guint8 *dataIn = (const guint8 *) inputBytes;
+ gint16 *dataOut = (gint16 *) outputSamples;
+ size_t i;
+
+ if (!ctx) {
+ return 0;
+ }
+
+ size_t full_frames = inputBytesSize / 10;
+ /* Almost surely only one SID frame. SID frames come at the end of
+ the payload, and 10 ms packets can be used when transitioning to
+ avoid ambiguity. (RFC 3551 4.5.6 "G729")
+ */
+ size_t sid_frames = (inputBytesSize % 10) / 2;
+
+ if (!outputSamples || !outputSamplesSize) {
+ return 80*2*(full_frames + sid_frames);
+ }
+
+ /* The G729 algorithm encodes 10ms of voice into 80bit (10 bytes).
+ Based on the RTP packetization period (usually 20ms), we need to
+ pass to the bcg729 decoder chunks of 10ms (10 bytes)
+ */
+ for (i = 0; i < full_frames; i++) {
+ /* As of version 1.1.0, the bcg729 decoder library declares the second
+ argument to bcg729Decoder() to be a const pointer, but prior to
+ that it did not (though it didn't modify the input and could be
+ fixed to accept a const pointer.) Cast away the problem for now;
+ in the future we could check the version of the library.
+ */
+ bcg729Decoder(state, (guint8 *)dataIn + i*10, 10, 0, 0, 0, dataOut + i*80);
+ }
+
+ for (; i < full_frames + sid_frames; i++) {
+ bcg729Decoder(state, (guint8 *)dataIn + full_frames*10 + (i - full_frames)*2, 2, 0, 1, 0, dataOut + i*80);
+ }
+ *outputSamplesSize = 80*2*(full_frames + sid_frames);
+ return *outputSamplesSize;
+}
+
+void
+codec_register_g729(void)
+{
+ register_codec("g729", codec_g729_init, codec_g729_release,
+ codec_g729_get_channels, codec_g729_get_frequency, codec_g729_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:
+ */
diff --git a/plugins/codecs/amrnb/CMakeLists.txt b/plugins/codecs/amrnb/CMakeLists.txt
new file mode 100644
index 00000000..b4931468
--- /dev/null
+++ b/plugins/codecs/amrnb/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(amrnb 0 1 0 0)
+
+set(CODEC_SRC
+ amrdecode.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(amrnb codecs)
+
+target_include_directories(amrnb PRIVATE ${CMAKE_SOURCE_DIR}/codecs)
+
+target_link_libraries(amrnb wsutil ${AMRNB_LIBRARIES})
+
+target_include_directories(amrnb SYSTEM PRIVATE ${AMRNB_INCLUDE_DIRS})
+
+install_plugin(amrnb codecs)
+
+file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h")
+CHECKAPI(
+ NAME
+ amrnb
+ 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/amrnb/amrdecode.c b/plugins/codecs/amrnb/amrdecode.c
new file mode 100644
index 00000000..1cceca3c
--- /dev/null
+++ b/plugins/codecs/amrnb/amrdecode.c
@@ -0,0 +1,274 @@
+/* amrdecode.c
+ * AMR 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 <wireshark.h>
+
+#include "wsutil/codecs.h"
+#include "ws_attributes.h"
+
+#include <opencore-amrnb/interf_dec.h>
+
+void codec_register_amr(void);
+
+static void *
+codec_amr_init(codec_context_t *ctx _U_)
+{
+ void *state;
+ state = Decoder_Interface_init();
+
+ return state;
+}
+
+static void
+codec_amr_release(codec_context_t *state)
+{
+ Decoder_Interface_exit(state->priv);
+}
+
+static unsigned
+codec_amr_get_channels(codec_context_t *ctx _U_)
+{
+ return 1;
+}
+
+static unsigned
+codec_amr_get_frequency(codec_context_t *ctx _U_)
+{
+ return 8000;
+}
+
+/* RTP doesn't allow the other SID types */
+static const uint8_t speech_bits[16] = {95,103,118,134,148,159,204,244,39, 0, 0, 0, 0, 0, 0, 0};
+/* The number of speech bits rounded up to bytes */
+static const uint8_t block_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
+
+static const uint8_t bit_mask8[] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF };
+
+/* Retrieve no_of_bits (<= 8) from in, starting at bit_offset.
+ * Does not do bounds checking.
+ */
+static uint8_t
+get_bits8(uint8_t *in, unsigned bit_offset, const unsigned no_of_bits)
+{
+ uint8_t ret;
+ unsigned octet_offset = bit_offset >> 3;
+ unsigned bits_in_first_octet = 8 - (bit_offset % 8);
+ if (bits_in_first_octet >= no_of_bits) {
+ ret = in[octet_offset] >> (bits_in_first_octet - no_of_bits) & bit_mask8[no_of_bits];
+ } else {
+ unsigned left_shift = no_of_bits - bits_in_first_octet;
+ ret = (in[octet_offset] << left_shift) & bit_mask8[no_of_bits];
+ ret |= (in[octet_offset + 1] >> (8 - left_shift));
+ }
+ return ret;
+}
+
+static size_t
+codec_amr_decode_one(void *state, const void *input, size_t inputSizeBytes,
+ void *output, size_t *outputSizeBytes)
+{
+ uint8_t *in;
+ int mode;
+ unsigned packet_size;
+ packet_size = 2; /* CMR + TOC */
+
+ /* 160 samples per frame, two byte per frame, 20ms */
+ *outputSizeBytes = 160 * 2;
+
+ /* If no room for CMR + TOC, insert silence */
+ if (packet_size > inputSizeBytes) {
+ memset(output, 0, 160 * 2);
+ return *outputSizeBytes;
+ }
+
+ in = (uint8_t*)input + 1;
+ mode = (in[0] >> 3) & 0x0F;
+ packet_size += block_size[mode];
+
+ /* If the size is screwed up, insert silence */
+ if (packet_size > inputSizeBytes) {
+ memset(output, 0, 160 * 2);
+ return *outputSizeBytes;
+ }
+
+ /* XXX: The last parameter is the BFI - we could invert the
+ * Q-bit and pass it in, which might be better?
+ */
+ Decoder_Interface_Decode(state, in, (short *)output, 0);
+ return *outputSizeBytes;
+}
+
+static size_t
+codec_amr_decode_many(void *state, const void *input, size_t inputSizeBytes,
+ void *output, size_t *outputSizeBytes, unsigned frames)
+{
+ int mode;
+ unsigned packet_size = 1; /* CMR */
+
+ *outputSizeBytes = 160 * 2 * frames;
+
+ uint8_t *toc = (uint8_t *)input + 1;
+ uint8_t *speech = toc + frames;
+ uint8_t in[32];
+
+ for (unsigned i = 0; i < frames; i++) {
+ mode = (toc[i] >> 3) & 0x0F;
+ packet_size += block_size[mode] + 1; /* include the TOC */
+
+ /* If the size is screwed up, insert silence */
+ if (packet_size > inputSizeBytes) {
+ memset(output, 0, 160 * 2 * (frames - i));
+ return *outputSizeBytes;
+ }
+
+ /* OpenCORE-AMR ignores the F-bit (which is why we're doing
+ * this memcpy) but might as well clear it.
+ */
+ in[0] = toc[i] & 0x7F;
+ memcpy(&in[1], speech, block_size[mode]);
+ /* XXX: The last parameter is the BFI - we could invert the
+ * Q-bit and pass it in, which might be better?
+ */
+ Decoder_Interface_Decode(state, in, (short *)output, 0);
+ speech += block_size[mode];
+ output = (uint8_t *)output + 160 * 2;
+ }
+
+ return *outputSizeBytes;
+}
+
+static size_t
+codec_amr_decode_oa(codec_context_t *ctx, const void *input,
+ size_t inputSizeBytes, void *output, size_t *outputSizeBytes)
+{
+ bool f_bit;
+ unsigned frames = 0;
+ void *state = ctx->priv;
+
+ /* First byte is CMR, second is the Payload TOC */
+ if (inputSizeBytes < 2) {
+ frames = 1;
+ } else {
+ uint8_t *in = (uint8_t *)input;
+ do {
+ f_bit = (in[++frames] >> 7) & 0x01;
+ } while (f_bit && inputSizeBytes > frames + 1);
+ }
+
+ /* 160 samples per frame, two byte per frame, 20ms */
+ if (!output || !outputSizeBytes)
+ return 160 * 2 * frames;
+
+ if (frames == 1) {
+ return codec_amr_decode_one(state, input, inputSizeBytes, output, outputSizeBytes);
+ } else {
+ return codec_amr_decode_many(state, input, inputSizeBytes, output, outputSizeBytes, frames);
+ }
+}
+
+static size_t
+codec_amr_decode(codec_context_t *ctx, const void *input,
+ size_t inputSizeBytes, void *output, size_t *outputSizeBytes)
+{
+ bool f_bit;
+ unsigned frames = 0;
+ void *state = ctx->priv;
+
+ if (ctx->fmtp_map) {
+ const char* octet_align = (const char *)wmem_map_lookup(ctx->fmtp_map, "octet-align");
+ /* There's a few other lesser used options like "crc", "interleaving",
+ * and "robust-sorting" that can change how it should be decoded.
+ * (All of them imply octet-aligned.) Ideally we'd handle them too.
+ */
+ if (g_strcmp0(octet_align, "1") == 0) {
+ return codec_amr_decode_oa(ctx, input, inputSizeBytes, output, outputSizeBytes);
+ }
+ }
+
+ unsigned bit_offset = 4;
+ uint8_t *in = (uint8_t *)input;
+ /* Per RFC 4867, if the format parameters don't indicate octet-align,
+ * bandwidth-efficient mode is used. (For Decode As, we'll pass in
+ * the value of the dissector's prefs.)
+ * OpenCORE-AMR's interface only supports octet-aligned mode, so we
+ * have to align the data. (From the source, the decode also supports
+ * IF2, except that there's no way to access that from the interface.)
+ */
+ /* First byte is CMR, second is the Payload TOC */
+ if (inputSizeBytes < 2) {
+ frames = 1;
+ } else {
+ do {
+ f_bit = get_bits8(in, bit_offset, 1);
+ bit_offset += 6;
+ frames++;
+ } while (f_bit && inputSizeBytes > (bit_offset / 8));
+ }
+
+ /* 160 samples per frame, two byte per frame, 20ms */
+ if (!output || !outputSizeBytes)
+ return 160 * 2 * frames;
+
+ *outputSizeBytes = 160 * 2 * frames;
+ /* bit_offset is now where the speech bits begin */
+ unsigned toc_offset = 5; /* Mode start */
+ uint8_t aligned[32];
+ int mode;
+ for (unsigned i = 0; i < frames; ++i) {
+ mode = get_bits8(in, toc_offset, 4);
+
+ /* If the size is screwed up, insert silence */
+ if ((bit_offset + speech_bits[mode] + 7) / 8 > inputSizeBytes) {
+ memset(output, 0, 160 * 2 * (frames - i));
+ return *outputSizeBytes;
+ }
+
+ memset(aligned, 0, 32);
+ aligned[0] = mode << 3;
+ for (unsigned j = 0; j < speech_bits[mode] / 8; ++j) {
+ aligned[1 + j] = get_bits8(in, bit_offset, 8);
+ bit_offset += 8;
+ }
+ if (speech_bits[mode] % 8) {
+ aligned[1 + block_size[mode]] = get_bits8(in, bit_offset, speech_bits[mode] % 8);
+ }
+ /* Padding might be different. */
+
+ /* XXX: The last parameter is the BFI - we could invert the
+ * Q-bit and pass it in, which might be better?
+ */
+ Decoder_Interface_Decode(state, aligned, (short *)output, 0);
+ output = (uint8_t *)output + 160 * 2;
+ }
+
+ return *outputSizeBytes;
+}
+
+void
+codec_register_amr(void)
+{
+ register_codec("AMR", codec_amr_init, codec_amr_release,
+ codec_amr_get_channels, codec_amr_get_frequency, codec_amr_decode);
+}
+
+/*
+ * Editor modelines - http://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:
+ */
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:
+ */
diff --git a/plugins/codecs/l16_mono/AUTHORS b/plugins/codecs/l16_mono/AUTHORS
new file mode 100644
index 00000000..f00e0146
--- /dev/null
+++ b/plugins/codecs/l16_mono/AUTHORS
@@ -0,0 +1,2 @@
+Author :
+Jaap Keuter <jaap.keuter@xs4all.nl>
diff --git a/plugins/codecs/l16_mono/CMakeLists.txt b/plugins/codecs/l16_mono/CMakeLists.txt
new file mode 100644
index 00000000..f90713b7
--- /dev/null
+++ b/plugins/codecs/l16_mono/CMakeLists.txt
@@ -0,0 +1,64 @@
+# 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(l16mono 0 1 0 0)
+
+set(CODEC_SRC
+ l16decode.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(l16mono codecs)
+
+target_include_directories(l16mono PRIVATE ${CMAKE_SOURCE_DIR}/codecs)
+
+target_link_libraries(l16mono wsutil)
+
+install_plugin(l16mono codecs)
+
+file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h")
+CHECKAPI(
+ NAME
+ l16mono
+ 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/l16_mono/README b/plugins/codecs/l16_mono/README
new file mode 100644
index 00000000..993730a4
--- /dev/null
+++ b/plugins/codecs/l16_mono/README
@@ -0,0 +1,3 @@
+This codec plugin serves a dual purpose.
+First it is to add L16 codec suppport to Wireshark.
+Second it is an illustration of a basic codec plugin module.
diff --git a/plugins/codecs/l16_mono/l16decode.c b/plugins/codecs/l16_mono/l16decode.c
new file mode 100644
index 00000000..12994cfc
--- /dev/null
+++ b/plugins/codecs/l16_mono/l16decode.c
@@ -0,0 +1,122 @@
+/* l16decode.c
+ * 16-bit audio, mono 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 <glib.h>
+#include <string.h>
+
+#include "wsutil/codecs.h"
+#include "ws_attributes.h"
+
+void codec_register_l16(void);
+
+static void *
+codec_l16_init(codec_context_t *ctx _U_)
+{
+ return NULL;
+}
+
+static void *
+codec_l16_mono_init(codec_context_t *ctx)
+{
+ /* L16 mono as registered as PT 11 */
+ ctx->sample_rate = 44100;
+ ctx->channels = 1;
+ return NULL;
+}
+
+static void *
+codec_l16_stereo_init(codec_context_t *ctx)
+{
+ /* L16 stereo as registered as PT 10 */
+ ctx->sample_rate = 44100;
+ /* In practice, we will downmix to mono. */
+ ctx->channels = 2;
+ return NULL;
+}
+
+static void
+codec_l16_release(codec_context_t *ctx _U_)
+{
+
+}
+
+static unsigned
+codec_l16_get_channels(codec_context_t *ctx _U_)
+{
+ /* XXX: Downmix to mono regardless of the actual number of channels
+ * because RTP Player expects mono, and doesn't actually do anything
+ * with this.
+ */
+ return 1;
+}
+
+static unsigned
+codec_l16_get_frequency(codec_context_t *ctx)
+{
+ return ctx->sample_rate ? ctx->sample_rate : 44100;
+}
+
+static size_t
+codec_l16_decode(codec_context_t *ctx _U_,
+ const void *inputBytes, size_t inputBytesSize,
+ void *outputSamples, size_t *outputSamplesSize)
+{
+ const guint16 *dataIn = (const guint16 *)inputBytes;
+ guint16 *dataOut = (gint16 *)outputSamples;
+ size_t i;
+ unsigned channels = ctx->channels ? ctx->channels : 1;
+ if (!outputSamples || !outputSamplesSize)
+ {
+ return inputBytesSize/channels;
+ }
+
+ /* Downmix to mono. No worries about overflow because tmp is 32 bit. */
+ for (i=0; i<inputBytesSize/(2 * channels); i++)
+ {
+ gint32 tmp = 0;
+ for (unsigned j=0; j < channels; j++) {
+ tmp += (gint16)g_ntohs(dataIn[channels*i + j]);
+ }
+ dataOut[i] = (gint16)(tmp / channels);
+ }
+
+ *outputSamplesSize = inputBytesSize/channels;
+ return *outputSamplesSize;
+}
+
+void
+codec_register_l16(void)
+{
+ register_codec("16-bit audio, monaural", codec_l16_mono_init,
+ codec_l16_release, codec_l16_get_channels, codec_l16_get_frequency,
+ codec_l16_decode);
+
+ register_codec("16-bit audio, stereo", codec_l16_stereo_init,
+ codec_l16_release, codec_l16_get_channels, codec_l16_get_frequency,
+ codec_l16_decode);
+
+ register_codec("L16", codec_l16_init, codec_l16_release,
+ codec_l16_get_channels, codec_l16_get_frequency, codec_l16_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:
+ */
diff --git a/plugins/codecs/opus_dec/CMakeLists.txt b/plugins/codecs/opus_dec/CMakeLists.txt
new file mode 100644
index 00000000..dc3bdc21
--- /dev/null
+++ b/plugins/codecs/opus_dec/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(opus_dec 0 1 0 0)
+
+set(CODEC_SRC
+ opusdecode.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(opus_dec codecs)
+
+target_include_directories(opus_dec PRIVATE ${CMAKE_SOURCE_DIR}/codecs)
+
+target_link_libraries(opus_dec wsutil ${OPUS_LIBRARIES})
+
+target_include_directories(opus_dec SYSTEM PRIVATE ${OPUS_INCLUDE_DIRS})
+
+install_plugin(opus_dec codecs)
+
+file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h")
+CHECKAPI(
+ NAME
+ opus
+ 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/opus_dec/opusdecode.c b/plugins/codecs/opus_dec/opusdecode.c
new file mode 100644
index 00000000..97398bb5
--- /dev/null
+++ b/plugins/codecs/opus_dec/opusdecode.c
@@ -0,0 +1,107 @@
+/* opusdecode.c
+ * opus 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 <stdlib.h>
+#include "opus/opus.h"
+
+#include "wsutil/codecs.h"
+#include "ws_attributes.h"
+
+void codec_register_opus(void);
+
+static void *
+codec_opus_init(codec_context_t *ctx _U_)
+{
+ OpusDecoder *state;
+ int err = OPUS_INTERNAL_ERROR;
+ /* Opus has in-band signaling and can convert what is sent to our
+ * desired output.
+ * always use maximum 48000 to cover all 8k/12k/16k/24k/48k
+ * always downmix to mono because RTP Player only supports mono now
+ */
+ state = opus_decoder_create(48000, 1, &err);
+ return state;
+}
+
+static void
+codec_opus_release(codec_context_t *ctx)
+{
+ OpusDecoder* state = (OpusDecoder*)ctx->priv;
+ if (!state) {
+ return; /* out-of-memory; */
+ }
+ opus_decoder_destroy(state);
+}
+
+static unsigned
+codec_opus_get_channels(codec_context_t *ctx _U_)
+{
+ return 1;
+}
+
+static unsigned
+codec_opus_get_frequency(codec_context_t *ctx _U_)
+{
+ /* although can set kinds of fs, but we set 48K now */
+ return 48000;
+}
+
+static size_t
+codec_opus_decode(codec_context_t *ctx,
+ const void *input, size_t inputSizeBytes,
+ void *output, size_t *outputSizeBytes)
+{
+ OpusDecoder *state = (OpusDecoder *)ctx->priv;
+
+ if (!state) {
+ return 0; /* out-of-memory */
+ }
+
+ const unsigned char *data = (const unsigned char *)input;
+ opus_int32 len = (opus_int32)inputSizeBytes;
+ int frame_samples = opus_decoder_get_nb_samples(state, data, len);
+ if (frame_samples < 0) { // OPUS_INVALID_PACKET
+ return 0;
+ }
+
+ // reserve space for the first time
+ if (!output || !outputSizeBytes) {
+ return frame_samples*2;
+ }
+ opus_int16 *pcm = (opus_int16*)(output);
+ int ret = opus_decode(state, data, len, pcm, frame_samples, 0);
+
+ if (ret < 0) {
+ return 0;
+ }
+ *outputSizeBytes = ret * 2;
+ return *outputSizeBytes;
+}
+
+void
+codec_register_opus(void)
+{
+ register_codec("opus", codec_opus_init, codec_opus_release,
+ codec_opus_get_channels, codec_opus_get_frequency, codec_opus_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:
+ */
diff --git a/plugins/codecs/sbc/CMakeLists.txt b/plugins/codecs/sbc/CMakeLists.txt
new file mode 100644
index 00000000..d12de70d
--- /dev/null
+++ b/plugins/codecs/sbc/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(sbc 0 1 0 0)
+
+set(CODEC_SRC
+ sbc.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(sbc codecs)
+
+target_include_directories(sbc PRIVATE ${CMAKE_SOURCE_DIR}/codecs)
+
+target_link_libraries(sbc wsutil ${SBC_LIBRARIES})
+
+target_include_directories(sbc SYSTEM PRIVATE ${SBC_INCLUDE_DIRS})
+
+install_plugin(sbc codecs)
+
+file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h")
+CHECKAPI(
+ NAME
+ sbc
+ 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/sbc/sbc.c b/plugins/codecs/sbc/sbc.c
new file mode 100644
index 00000000..5ac31b94
--- /dev/null
+++ b/plugins/codecs/sbc/sbc.c
@@ -0,0 +1,142 @@
+/* sbc.c
+ * Support for external Bluetooth SBC codec
+ *
+ * Copyright 2012, Michal Labedzki for Tieto Corporation
+ *
+ * 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 <wireshark.h>
+#include <sbc/sbc.h>
+
+#include "wsutil/codecs.h"
+
+#define SBC_BUFFER 8192
+
+void codec_register_sbc(void);
+
+static void *
+codec_sbc_init(codec_context_t *ctx _U_)
+{
+ sbc_t *sbc;
+
+ sbc = g_new(sbc_t, 1);
+ sbc_init(sbc, 0L);
+
+ return sbc;
+}
+
+static void
+codec_sbc_release(codec_context_t *ctx)
+{
+ sbc_t *sbc = (sbc_t *) ctx->priv;
+
+ sbc_finish(sbc);
+ g_free(sbc);
+}
+
+static unsigned
+codec_sbc_get_channels(codec_context_t *ctx)
+{
+ sbc_t *sbc = (sbc_t *) ctx->priv;
+ if (sbc->mode == SBC_MODE_MONO)
+ return 1;
+
+ return 2;
+}
+
+static unsigned
+codec_sbc_get_frequency(codec_context_t *ctx)
+{
+ sbc_t *sbc = (sbc_t *) ctx->priv;
+ int frequency;
+
+ switch (sbc->frequency) {
+ case SBC_FREQ_16000:
+ frequency = 16000;
+ break;
+
+ case SBC_FREQ_32000:
+ frequency = 32000;
+ break;
+
+ case SBC_FREQ_44100:
+ frequency = 44100;
+ break;
+
+ case SBC_FREQ_48000:
+ frequency = 48000;
+ break;
+ default:
+ frequency = 0;
+ }
+
+ return frequency;
+}
+
+static size_t
+codec_sbc_decode(codec_context_t *ctx,
+ const void *input, size_t inputSizeBytes,
+ void *output, size_t *outputSizeBytes)
+{
+ size_t size_in = (size_t) inputSizeBytes;
+ size_t size_out = SBC_BUFFER;
+ size_t len;
+ size_t framelen;
+ size_t xframe_pos = 0;
+ const guint8 *data_in = (const guint8 *) input;
+ guint8 *data_out = (guint8 *) output;
+ sbc_t *sbc = (sbc_t *) ctx->priv;
+ guint8 *i_data;
+ guint8 tmp;
+
+ if (!output || !outputSizeBytes) {
+ return size_out;
+ }
+
+ sbc->endian = SBC_BE;
+
+ *outputSizeBytes = 0;
+ while (xframe_pos < inputSizeBytes) {
+ framelen = sbc_decode(sbc, data_in, size_in, data_out, size_out, &len);
+ xframe_pos += framelen;
+ data_in += framelen;
+ *outputSizeBytes += len;
+
+ for (i_data = data_out; i_data < data_out + len; i_data += 2) {
+ tmp = i_data[0];
+ i_data[0] = i_data[1];
+ i_data[1] = tmp;
+ }
+
+ data_out += len;
+ }
+
+ return *outputSizeBytes;
+}
+
+void
+codec_register_sbc(void)
+{
+ register_codec("SBC", codec_sbc_init, codec_sbc_release,
+ codec_sbc_get_channels, codec_sbc_get_frequency, codec_sbc_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:
+ */