summaryrefslogtreecommitdiffstats
path: root/plugins/codecs/l16_mono
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/l16_mono
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/l16_mono')
-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
4 files changed, 191 insertions, 0 deletions
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:
+ */