Add AMR codec support

CMake work and rebase on current wireshark master by Pau Espin Pedrol.
Rebase on 3.4.7 by Oliver Smith.

Change-Id: I5ec963b910f8f271aa2e5d680ea33e2170a6f367
This commit is contained in:
Daniel Willmann 2016-07-12 20:25:33 +02:00 committed by Oliver Smith
parent 8ca21cbe7a
commit adc002a045
8 changed files with 443 additions and 0 deletions

View File

@ -1230,6 +1230,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_package(SETCAP)
endif()
if(ENABLE_AMRNB)
set(PACKAGELIST ${PACKAGELIST} AMRNB)
endif()
if(ENABLE_LIBXML2)
set(PACKAGELIST ${PACKAGELIST} LibXml2)
endif()
# Include minizip include directories
if(MINIZIP_FOUND)
include_directories(
@ -1283,6 +1291,65 @@ if(GNUTLS_FOUND AND NOT GNUTLS_VERSION VERSION_LESS "3.4.0")
cmake_pop_check_state()
endif()
if(HAVE_LIBAIRPCAP)
set(HAVE_AIRPCAP 1)
endif()
if(HAVE_LIBLUA)
set(HAVE_LUA_H 1)
set(HAVE_LUA 1)
endif()
if(HAVE_LIBKERBEROS)
set(HAVE_KERBEROS 1)
endif()
if(MAXMINDDB_FOUND)
set(HAVE_MAXMINDDB 1)
endif()
if(LIBSSH_FOUND)
set(HAVE_LIBSSH 1)
endif()
if(JSONGLIB_FOUND)
set(HAVE_JSONGLIB 1)
endif()
if(NGHTTP2_FOUND)
set(HAVE_NGHTTP2 1)
endif()
if(HAVE_LIBCARES)
set(HAVE_C_ARES 1)
endif()
if(NOT HAVE_LIBCARES)
message(WARNING "Not using c-ares.")
message(WARNING "DNS name resolution for captures will be disabled.")
endif()
if(HAVE_LIBNL AND HAVE_AIRPCAP)
message(ERROR "Airpcap and Libnl support are mutually exclusive")
endif()
if(HAVE_LIBSBC)
set(HAVE_SBC 1)
endif()
if(SPANDSP_FOUND)
set(HAVE_SPANDSP 1)
endif()
if(BCG729_FOUND)
set(HAVE_BCG729 1)
endif()
if(AMRNB_FOUND)
set(HAVE_AMRNB 1)
endif()
if(LIBXML2_FOUND)
set(HAVE_LIBXML2 1)
else()
# The (official) FindLibXml2.cmake file sets this cache variable to a
# non-empty value, be sure to clear it when not found.
set(LIBXML2_LIBRARIES "")
endif()
if(EXTCAP_ANDROIDDUMP_LIBPCAP)
set(ANDROIDDUMP_USE_LIBPCAP 1)
endif()
if (HAVE_LIBWINSPARKLE)
set(HAVE_SOFTWARE_UPDATE 1)
endif()
if (QT_FOUND)
if (Qt5Widgets_VERSION VERSION_LESS 5.3)
message(FATAL_ERROR "Qt 5.3 or later is required.")
@ -1657,6 +1724,11 @@ set_package_properties(OPUS PROPERTIES
URL "https://opus-codec.org/"
PURPOSE "Support for opus 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(LIBXML2 PROPERTIES
DESCRIPTION "XML parsing library"
URL "http://xmlsoft.org/"
@ -1954,6 +2026,9 @@ if(WIN32)
if (OPUS_FOUND)
list (APPEND OPTIONAL_DLLS "${OPUS_DLL_DIR}/${OPUS_DLL}")
endif(OPUS_FOUND)
if (AMRNB_FOUND)
list (APPEND OPTIONAL_DLLS "${AMRNB_DLL_DIR}/${AMRNB_DLL}")
endif(AMRNB_FOUND)
if (LIBXML2_FOUND)
foreach( _dll ${LIBXML2_DLLS} )
list (APPEND OPTIONAL_DLLS "${LIBXML2_DLL_DIR}/${_dll}")
@ -3092,6 +3167,9 @@ if(RPMBUILD_EXECUTABLE)
if (OPUS_FOUND)
list(APPEND _rpmbuild_with_args --with opus)
endif()
if (AMRNB_FOUND)
list(APPEND _rpmbuild_with_args --with amrnb)
endif()
if (LIBXML2_FOUND)
list(APPEND _rpmbuild_with_args --with libxml2)
endif()

View File

@ -98,6 +98,7 @@ 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_ILBC "Build with iLBC codec support in RTP Player" ON)
option(ENABLE_AMRNB "Build with AMRNB codec support in RTP Player" ON)
option(ENABLE_LIBXML2 "Build with libxml2 support" ON)
option(ENABLE_OPUS "Build with opus support" ON)

View File

@ -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 )

View File

@ -244,6 +244,9 @@
/* Define to 1 if you have the speexdsp library. */
#cmakedefine HAVE_SPEEXDSP 1
/* Define to 1 if you have the opencore-amrnb library. */
#cmakedefine HAVE_AMRNB 1
/* Define to 1 if you have the lixbml2 library. */
#cmakedefine HAVE_LIBXML2 1

99
codecs/CMakeLists.txt Normal file
View File

@ -0,0 +1,99 @@
# CMakeLists.txt
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.org>
# Copyright 1998 Gerald Combs
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
set(WSCODECS_PUBLIC_HEADERS
codecs.h
)
set(WSCODECS_FILES
codecs.c
G711a/G711adecode.c
G711u/G711udecode.c
speex/resample.c
)
# Enables visibility in IDEs
file(GLOB EXTRA_CODEC_HEADERS
codecs.h
G711a/G711adecode.h G711a/G711atable.h
G711u/G711udecode.h G711u/G711utable.h
speex/arch.h
speex/speex_resampler.h
speex/stack_alloc.h
)
if(SBC_FOUND)
set(WSCODECS_FILES ${WSCODECS_FILES} sbc/sbc.c)
endif()
set(wscodecs_LIBS
${M_LIBRARIES}
${GMODULE2_LIBRARIES}
${SBC_LIBRARIES}
wsutil
)
if(HAVE_SPANDSP)
list(APPEND WSCODECS_FILES G722/G722decode.c G726/G726decode.c)
list(APPEND wscodecs_LIBS ${SPANDSP_LIBRARIES})
endif()
if(HAVE_BCG729)
list(APPEND WSCODECS_FILES G729/G729decode.c)
list(APPEND wscodecs_LIBS ${BCG729_LIBRARIES})
endif()
if(AMRNB_FOUND)
list(APPEND WSCODECS_FILES amr/amrdecode.c)
list(APPEND wscodecs_LIBS ${AMRNB_LIBRARIES})
endif()
add_library(wscodecs
${WSCODECS_FILES}
${CMAKE_BINARY_DIR}/image/libwscodecs.rc
)
set(FULL_SO_VERSION "0.0.0")
set_target_properties(wscodecs PROPERTIES
PREFIX "lib"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
LINK_FLAGS "${WS_LINK_FLAGS}"
VERSION ${FULL_SO_VERSION} SOVERSION 0
FOLDER "DLLs"
)
if(ENABLE_APPLICATION_BUNDLE)
set_target_properties(wscodecs PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Frameworks
)
endif()
target_link_libraries(wscodecs ${wscodecs_LIBS})
install(TARGETS wscodecs
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
if(NOT WIN32)
install(FILES ${WSCODECS_PUBLIC_HEADERS}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${CPACK_PACKAGE_NAME}/codecs"
)
endif()
CHECKAPI(
NAME
codecs
SWITCHES
-g abort -g termoutput -build
SOURCES
${WSCODECS_FILES}
)

View File

@ -0,0 +1,98 @@
/* 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 "amrdecode.h"
#include "ws_attributes.h"
#include <opencore-amrnb/interf_dec.h>
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 uint8_t 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 = (((uint8_t *)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;
}
/*
* 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:
*/

View File

@ -0,0 +1,48 @@
/* G726decode.h
* Definitions for A-law G.722 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.
*/
#ifndef __CODECS_AMRDECODE_H__
#define __CODECS_AMRDECODE_H__
#include <stdint.h>
void *codec_amr_init(void);
void codec_amr_release(void *ctx);
unsigned codec_amr_get_channels(void *ctx);
unsigned codec_amr_get_frequency(void *ctx);
size_t codec_amr_decode(void *ctx, const void *input, size_t inputSizeBytes, void *output,
size_t *outputSizeBytes);
#endif /* AMRdecode.h */
/*
* 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:
*/

View File

@ -13,8 +13,29 @@
#include <glib.h>
#include "codecs.h"
#include "G711a/G711adecode.h"
#include "G711u/G711udecode.h"
#ifdef HAVE_SBC
#include "sbc/sbc_private.h"
#endif
#ifdef HAVE_SPANDSP
#include "G722/G722decode.h"
#include "G726/G726decode.h"
#endif
#ifdef HAVE_BCG729
#include "G729/G729decode.h"
#endif
#ifdef HAVE_AMRNB
#include "amr/amrdecode.h"
#endif
#ifdef HAVE_PLUGINS
static plugins_t *libwscodecs_plugins;
static GSList *codecs_plugins = NULL;
@ -42,6 +63,44 @@ call_plugin_register_codec_module(gpointer data, gpointer user_data _U_)
void
codecs_init(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);
#ifdef HAVE_SPANDSP
register_codec("g722", codec_g722_init, codec_g722_release,
codec_g722_get_channels, codec_g722_get_frequency, codec_g722_decode);
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);
#endif
#ifdef HAVE_BCG729
register_codec("g729", codec_g729_init, codec_g729_release,
codec_g729_get_channels, codec_g729_get_frequency, codec_g729_decode);
#endif
#ifdef HAVE_SBC
register_codec("SBC", codec_sbc_init, codec_sbc_release,
codec_sbc_get_channels, codec_sbc_get_frequency, codec_sbc_decode);
#endif
#ifdef HAVE_AMRNB
register_codec("AMR", codec_amr_init, codec_amr_release,
codec_amr_get_channels, codec_amr_get_frequency, codec_amr_decode);
#endif
#ifdef HAVE_PLUGINS
libwscodecs_plugins = plugins_init(WS_PLUGIN_CODEC);
g_slist_foreach(codecs_plugins, call_plugin_register_codec_module, NULL);