aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <dwillmann@sysmocom.de>2016-07-12 20:25:33 +0200
committerHarald Welte <laforge@osmocom.org>2023-03-11 20:44:13 +0100
commite2bf2138d083fe472fbb25c5325a612c8eb4d693 (patch)
tree638cd4f33cd624817b675c22ad0103ad7878efcc
parenta329db7dd289d125417d32a2c10379e6a04b99dc (diff)
Add AMR codec supportlaforge/amr-2023
CMake work and rebase on current wireshark master by Harald Welte Change-Id: I5ec963b910f8f271aa2e5d680ea33e2170a6f367
-rw-r--r--CMakeLists.txt18
-rw-r--r--CMakeOptions.txt1
-rw-r--r--cmake/modules/FindAMRNB.cmake57
-rw-r--r--cmakeconfig.h.in3
-rw-r--r--plugins/codecs/amrnb/CMakeLists.txt66
-rw-r--r--plugins/codecs/amrnb/amrdecode.c107
6 files changed, 252 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8a54184f1c..ceeaa42f01 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1288,6 +1288,8 @@ ws_find_package(SPANDSP ENABLE_SPANDSP HAVE_SPANDSP)
ws_find_package(BCG729 ENABLE_BCG729 HAVE_BCG729)
+ws_find_package(AMRNB ENABLE_AMRNB HAVE_AMRNB)
+
ws_find_package(ILBC ENABLE_ILBC HAVE_ILBC)
ws_find_package(OPUS ENABLE_OPUS HAVE_OPUS)
@@ -1628,6 +1630,11 @@ if(ENABLE_PLUGINS)
plugins/codecs/G729
)
endif()
+ if(AMRNB_FOUND)
+ list(APPEND PLUGIN_SRC_DIRS
+ plugins/codecs/amrnb
+ )
+ endif()
if(ILBC_FOUND)
list(APPEND PLUGIN_SRC_DIRS
plugins/codecs/iLBC
@@ -1767,6 +1774,11 @@ set_package_properties(BCG729 PROPERTIES
URL "https://www.linphone.org/technical-corner/bcg729"
PURPOSE "Support for G.729 codec in RTP player"
)
+set_package_properties(AMRNB PROPERTIES
+ DESCRIPTION "AMRNB decoder"
+ URL "https://sourceforge.net/p/opencore-amr"
+ PURPOSE "Support for AMRNB codec in RTP player"
+)
set_package_properties(ILBC PROPERTIES
DESCRIPTION "iLBC decoder"
URL "https://github.com/TimothyGu/libilbc"
@@ -2088,6 +2100,9 @@ if(USE_REPOSITORY)
if (BCG729_FOUND)
list (APPEND THIRD_PARTY_DLLS "${BCG729_DLL_DIR}/${BCG729_DLL}")
endif(BCG729_FOUND)
+ if (AMRNB_FOUND)
+ list (APPEND OPTIONAL_DLLS "${AMRNB_DLL_DIR}/${AMRNB_DLL}")
+ endif(AMRNB_FOUND)
if (ILBC_FOUND)
list (APPEND THIRD_PARTY_DLLS "${ILBC_DLL_DIR}/${ILBC_DLL}")
endif(ILBC_FOUND)
@@ -3622,6 +3637,9 @@ if(RPMBUILD_EXECUTABLE)
if (BCG729_FOUND)
list(APPEND _rpmbuild_with_args --with bcg729)
endif()
+ if (AMRNB_FOUND)
+ list(APPEND _rpmbuild_with_args --with amrnb)
+ endif()
if (ILBC_FOUND)
list(APPEND _rpmbuild_with_args --with ilbc)
endif()
diff --git a/CMakeOptions.txt b/CMakeOptions.txt
index f6d07a855b..5dc26a8a8c 100644
--- a/CMakeOptions.txt
+++ b/CMakeOptions.txt
@@ -121,6 +121,7 @@ option(ENABLE_KERBEROS "Build with Kerberos support" ON)
option(ENABLE_SBC "Build with SBC Codec support in RTP Player" ON)
option(ENABLE_SPANDSP "Build with G.722/G.726 codecs support in RTP Player" ON)
option(ENABLE_BCG729 "Build with G.729 codec support in RTP Player" ON)
+option(ENABLE_AMRNB "Build with AMRNB codec support in RTP Player" ON)
option(ENABLE_ILBC "Build with iLBC codec support in RTP Player" ON)
option(ENABLE_LIBXML2 "Build with libxml2 support" ON)
option(ENABLE_OPUS "Build with opus support" ON)
diff --git a/cmake/modules/FindAMRNB.cmake b/cmake/modules/FindAMRNB.cmake
new file mode 100644
index 0000000000..21f152ba11
--- /dev/null
+++ b/cmake/modules/FindAMRNB.cmake
@@ -0,0 +1,57 @@
+# Find the system's opencore-amrnb includes and library
+#
+# AMRNB_INCLUDE_DIRS - where to find amrnb/decoder.h
+# AMRNB_LIBRARIES - List of libraries when using amrnb
+# AMRNB_FOUND - True if amrnb found
+# AMRNB_DLL_DIR - (Windows) Path to the amrnb DLL
+# AMRNB_DLL - (Windows) Name of the amrnb DLL
+
+include( FindWSWinLibs )
+FindWSWinLibs( "opencore-amrnb-.*" "AMRNB_HINTS" )
+
+if (NOT WIN32)
+ find_package(PkgConfig)
+ pkg_search_module(AMRNB opencore-amrnb)
+endif()
+
+find_path( AMRNB_INCLUDE_DIR
+ NAMES opencore-amrnb/interf_dec.h
+ HINTS
+ "${AMRNB_INCLUDE_DIR}"
+ "${AMRNB_HINTS}/include"
+ PATHS /usr/local/include /usr/include
+)
+
+find_library( AMRNB_LIBRARY
+ NAMES opencore-amrnb
+ HINTS
+ "${AMRNB_LIBDIR}"
+ "${AMRNB_HINTS}/lib"
+ PATHS /usr/local/lib /usr/lib
+)
+
+include( FindPackageHandleStandardArgs )
+find_package_handle_standard_args( amrnb DEFAULT_MSG AMRNB_INCLUDE_DIR AMRNB_LIBRARY )
+
+if( AMRNB_FOUND )
+ set( AMRNB_INCLUDE_DIRS ${AMRNB_INCLUDE_DIR} )
+ set( AMRNB_LIBRARIES ${AMRNB_LIBRARY} )
+ if (WIN32)
+ set ( AMRNB_DLL_DIR "${AMRNB_HINTS}/bin"
+ CACHE PATH "Path to amrnb DLL"
+ )
+ file( GLOB _amrnb_dll RELATIVE "${AMRNB_DLL_DIR}"
+ "${AMRNB_DLL_DIR}/libamrnb.dll"
+ )
+ set ( AMRNB_DLL ${_amrnb_dll}
+ # We're storing filenames only. Should we use STRING instead?
+ CACHE FILEPATH "amrnb DLL file name"
+ )
+ mark_as_advanced( AMRNB_DLL_DIR AMRNB_DLL )
+ endif()
+else()
+ set( AMRNB_INCLUDE_DIRS )
+ set( AMRNB_LIBRARIES )
+endif()
+
+mark_as_advanced( AMRNB_LIBRARIES AMRNB_INCLUDE_DIRS )
diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in
index 817da33692..20d3f1eb3e 100644
--- a/cmakeconfig.h.in
+++ b/cmakeconfig.h.in
@@ -232,6 +232,9 @@
/* Define to 1 if you have the bcg729 library. */
#cmakedefine HAVE_BCG729 1
+/* Define to 1 if you have the opencore-amrnb library. */
+#cmakedefine HAVE_AMRNB 1
+
/* Define to 1 if you have the ilbc library. */
#cmakedefine HAVE_ILBC 1
diff --git a/plugins/codecs/amrnb/CMakeLists.txt b/plugins/codecs/amrnb/CMakeLists.txt
new file mode 100644
index 0000000000..b49314689e
--- /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 0000000000..9d4e32f058
--- /dev/null
+++ b/plugins/codecs/amrnb/amrdecode.c
@@ -0,0 +1,107 @@
+/* amrdecode.c
+ * AMR codec
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <string.h>
+
+#include "wsutil/codecs.h"
+#include "ws_attributes.h"
+
+#include <opencore-amrnb/interf_dec.h>
+
+void codec_register_amr(void);
+
+void *
+codec_amr_init(void)
+{
+ void *state;
+ state = Decoder_Interface_init();
+
+ return state;
+}
+
+void
+codec_amr_release(void *state)
+{
+ Decoder_Interface_exit(state);
+}
+
+unsigned
+codec_amr_get_channels(void *ctx _U_)
+{
+ return 1;
+}
+
+unsigned
+codec_amr_get_frequency(void *ctx _U_)
+{
+ return 8000;
+}
+
+size_t
+codec_amr_decode(void *state, const void *input, size_t inputSizeBytes, void *output,
+ size_t *outputSizeBytes)
+{
+ int mode;
+ unsigned packet_size;
+ static const guint8 block_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
+
+ /* First byte is CMR, second is the Payload TOC */
+ mode = (((guint8 *)input)[1] >> 3) & 0x0F;
+ packet_size = block_size[mode] + 2;
+
+ if (!output || !outputSizeBytes)
+ return 160*2;
+
+ *outputSizeBytes = 160 * 2; /* 160 frames, two byte per frame, 20ms */
+
+ /* If the size is screwed up, insert silence */
+ if (packet_size > inputSizeBytes) {
+ memset(output, 0, *outputSizeBytes);
+ return *outputSizeBytes;
+ }
+
+ Decoder_Interface_Decode(state, (const unsigned char *)input+1, (short *)output, 0);
+ 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:
+ */