aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/codecs
diff options
context:
space:
mode:
authorLin Sun <lin.sun@zoom.us>2020-09-29 12:33:06 +0800
committerWireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2020-10-03 21:15:09 +0000
commit6136c719da4ec9b96c01adb4b0fd7f01af171688 (patch)
tree797542009e2f4d9d8453db1c7a97bb427ef4dfda /plugins/codecs
parentc1eb36b84b6fcfea93bfc087b280da60273b597d (diff)
RTP: opus playback
It's possible to play opus payload with libopus (https://opus-codec.org/). Closes #16882. Helped-by: Pascal Quantin <pascal.quantin@gmail.com> Signed-off-by: Lin Sun <lin.sun@zoom.us> Signed-off-by: Yuanzhi Li <ryanlee@mail.ustc.edu.cn>
Diffstat (limited to 'plugins/codecs')
-rw-r--r--plugins/codecs/opus_dec/CMakeLists.txt70
-rw-r--r--plugins/codecs/opus_dec/opusdecode.c95
2 files changed, 165 insertions, 0 deletions
diff --git a/plugins/codecs/opus_dec/CMakeLists.txt b/plugins/codecs/opus_dec/CMakeLists.txt
new file mode 100644
index 0000000000..aee83a33c9
--- /dev/null
+++ b/plugins/codecs/opus_dec/CMakeLists.txt
@@ -0,0 +1,70 @@
+# 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}"
+)
+
+include_directories(
+ ${CMAKE_SOURCE_DIR}/codecs
+ ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+register_plugin_files(plugin.c
+ plugin_codec
+ ${CODEC_SRC}
+)
+
+add_plugin_library(opus_dec 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
+ -g abort -g termoutput
+ 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 0000000000..d4d9d34a79
--- /dev/null
+++ b/plugins/codecs/opus_dec/opusdecode.c
@@ -0,0 +1,95 @@
+/* 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"
+
+static void *
+codec_opus_init(void)
+{
+ OpusDecoder *state;
+ int err = OPUS_INTERNAL_ERROR;
+ /* always use maximum 48000 to cover all 8k/12k/16k/24k/48k */
+ state = opus_decoder_create(48000, 1, &err);
+ return state;
+}
+
+static void
+codec_opus_release(void *ctx)
+{
+ OpusDecoder* state = (OpusDecoder*)ctx;
+ if (!state) {
+ return; /* out-of-memory; */
+ }
+ opus_decoder_destroy(state);
+}
+
+static unsigned
+codec_opus_get_channels(void *ctx _U_)
+{
+ return 1;
+}
+
+static unsigned
+codec_opus_get_frequency(void *ctx _U_)
+{
+ /* although can set kinds of fs, but we set 48K now */
+ return 48000;
+}
+
+static size_t
+codec_opus_decode(void *ctx , const void *input, size_t inputSizeBytes,
+ void *output, size_t *outputSizeBytes )
+{
+ OpusDecoder *state = (OpusDecoder *)ctx;
+
+ if (!ctx) {
+ return 0; /* out-of-memory */
+ }
+ // reserve space for the first time
+ if (!output || !outputSizeBytes) {
+ return 1920;
+ }
+ const unsigned char *data = (const unsigned char *)input;
+ opus_int32 len= (opus_int32)inputSizeBytes;
+ opus_int16 *pcm = (opus_int16*)(output);
+ int frame_size = 960;
+ int ret = opus_decode(state, data, len, pcm, frame_size, 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:
+ */