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>
This commit is contained in:
Lin Sun 2020-09-29 12:33:06 +08:00 committed by Wireshark GitLab Utility
parent c1eb36b84b
commit 6136c719da
16 changed files with 328 additions and 6 deletions

View File

@ -1173,6 +1173,8 @@ ws_find_package(BCG729 ENABLE_BCG729 HAVE_BCG729)
ws_find_package(ILBC ENABLE_ILBC HAVE_ILBC)
ws_find_package(OPUS ENABLE_OPUS HAVE_OPUS)
# CMake 3.9 and below used 'LIBXML2_LIBRARIES' as the name of the cache entry
# storing the find_library result. Transfer it to the new cache variable such
# that reset_find_package can detect and clear outdated cache variables.
@ -1494,6 +1496,11 @@ if(ENABLE_PLUGINS)
plugins/codecs/iLBC
)
endif()
if(OPUS_FOUND)
list(APPEND PLUGIN_SRC_DIRS
plugins/codecs/opus_dec
)
endif()
if(SBC_FOUND)
list(APPEND PLUGIN_SRC_DIRS
plugins/codecs/sbc
@ -1613,6 +1620,11 @@ set_package_properties(ILBC PROPERTIES
URL "https://github.com/TimothyGu/libilbc"
PURPOSE "Support for iLBC codec in RTP player"
)
set_package_properties(OPUS PROPERTIES
DESCRIPTION "opus decoder"
URL "https://opus-codec.org/"
PURPOSE "Support for opus codec in RTP player"
)
set_package_properties(LIBXML2 PROPERTIES
DESCRIPTION "XML parsing library"
URL "http://xmlsoft.org/"
@ -1907,6 +1919,9 @@ if(WIN32)
if (ILBC_FOUND)
list (APPEND OPTIONAL_DLLS "${ILBC_DLL_DIR}/${ILBC_DLL}")
endif(ILBC_FOUND)
if (OPUS_FOUND)
list (APPEND OPTIONAL_DLLS "${OPUS_DLL_DIR}/${OPUS_DLL}")
endif(OPUS_FOUND)
if (LIBXML2_FOUND)
foreach( _dll ${LIBXML2_DLLS} )
list (APPEND OPTIONAL_DLLS "${LIBXML2_DLL_DIR}/${_dll}")
@ -3037,6 +3052,9 @@ if(RPMBUILD_EXECUTABLE)
if (ILBC_FOUND)
list(APPEND _rpmbuild_with_args --with ilbc)
endif()
if (OPUS_FOUND)
list(APPEND _rpmbuild_with_args --with opus)
endif()
if (LIBXML2_FOUND)
list(APPEND _rpmbuild_with_args --with libxml2)
endif()

View File

@ -99,6 +99,7 @@ option(ENABLE_SPANDSP "Build with G.722/G.726 codecs support in RTP Player" O
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_LIBXML2 "Build with libxml2 support" ON)
option(ENABLE_OPUS "Build with opus support" ON)
# How to install
set(DUMPCAP_INSTALL_OPTION "normal" CACHE STRING "Permissions to install")

View File

@ -0,0 +1,57 @@
# Find the system's opus includes and library
#
# OPUS_INCLUDE_DIRS - where to find opus.h
# OPUS_LIBRARIES - List of libraries when using opus
# OPUS_FOUND - True if opus found
# OPUS_DLL_DIR - (Windows) Path to the opus DLL
# OPUS_DLL - (Windows) Name of the opus DLL
include( FindWSWinLibs )
FindWSWinLibs( "opus-.*" "OPUS_HINTS" )
if (NOT WIN32)
find_package(PkgConfig)
pkg_search_module(OPUS opus)
endif()
find_path(OPUS_INCLUDE_DIR
NAMES opus/opus.h
HINTS
"${OPUS_INCLUDE_DIRS}"
"${OPUS_HINTS}/include"
PATHS /usr/local/include /usr/include
)
find_library(OPUS_LIBRARY
NAMES opus
HINTS
"${OPUS_LIBRARY_DIRS}"
"${OPUS_HINTS}/lib"
PATHS /usr/local/lib /usr/lib
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OPUS DEFAULT_MSG OPUS_LIBRARY OPUS_INCLUDE_DIR)
if( OPUS_FOUND )
set( OPUS_INCLUDE_DIRS ${OPUS_INCLUDE_DIR} )
set( OPUS_LIBRARIES ${OPUS_LIBRARY} )
if (WIN32)
set ( OPUS_DLL_DIR "${OPUS_HINTS}/bin"
CACHE PATH "Path to opus DLL"
)
file( GLOB _opus_dll RELATIVE "${OPUS_DLL_DIR}"
"${OPUS_DLL_DIR}/opus.dll"
)
set ( OPUS_DLL ${_opus_dll}
# We're storing filenames only. Should we use STRING instead?
CACHE FILEPATH "opus DLL file name"
)
mark_as_advanced( OPUS_DLL_DIR OPUS_DLL )
endif()
else()
set( OPUS_INCLUDE_DIRS )
set( OPUS_LIBRARIES )
endif()
mark_as_advanced( OPUS_LIBRARIES OPUS_INCLUDE_DIRS )

View File

@ -235,6 +235,9 @@
/* Define to 1 if you have the ilbc library. */
#cmakedefine HAVE_ILBC 1
/* Define to 1 if you have the opus library. */
#cmakedefine HAVE_OPUS 1
/* Define to 1 if you have the speexdsp library. */
#cmakedefine HAVE_SPEEXDSP 1

View File

@ -50,6 +50,7 @@ The following features are new (or have been significantly updated) since versio
* Dissectors based on Protobuf can register themselves to a new 'protobuf_field' dissector table,
which is keyed with the full names of fields, for further parsing fields of BYTES or STRING type.
* Wireshark is able to decode, play, and save iLBC payload on platforms where the https://github.com/TimothyGu/libilbc[iLBC library] is available.
* Wireshark is able to decode, play, and save opus payload on platforms where the https://opus-codec.org/[opus library] is available.
* “Decode As” entries can now be copied from other profiles using a button in the dialog.
* sshdump can now be copied to multiple instances. Each instance will show up a different interface and will have its own profile.
* The main window now supports a packet diagram view, which shows each packet as a textbook-style diagram.

View File

@ -150,7 +150,7 @@ foreach(_dll ${CARES_DLL} ${GCRYPT_DLLS}
${GNUTLS_DLLS} ${KERBEROS_DLLS} ${LIBSSH_DLL} ${LUA_DLL}
${LZ4_DLL} ${NGHTTP2_DLL} ${SBC_DLL} ${SMI_DLL} ${SNAPPY_DLL}
${SPANDSP_DLL} ${BCG729_DLL} ${LIBXML2_DLLS} ${WINSPARKLE_DLL}
${ZLIB_DLL} ${BROTLI_DLLS} ${ZSTD_DLL} ${ILBC_DLL}
${ZLIB_DLL} ${BROTLI_DLLS} ${ZSTD_DLL} ${ILBC_DLL} ${OPUS_DLL}
# Needed for mmdbresolve
${MAXMINDDB_DLL}
)

View File

@ -1058,6 +1058,7 @@ File "${STAGING_DIR}\plugins\${VERSION_MAJOR}.${VERSION_MINOR}\codecs\g729.dll"
File "${STAGING_DIR}\plugins\${VERSION_MAJOR}.${VERSION_MINOR}\codecs\l16mono.dll"
File "${STAGING_DIR}\plugins\${VERSION_MAJOR}.${VERSION_MINOR}\codecs\sbc.dll"
File "${STAGING_DIR}\plugins\${VERSION_MAJOR}.${VERSION_MINOR}\codecs\ilbc.dll"
File "${STAGING_DIR}\plugins\${VERSION_MAJOR}.${VERSION_MINOR}\codecs\opus_dec.dll"
SectionEnd
Section "Configuration Profiles" SecProfiles

View File

@ -21,6 +21,7 @@
%bcond_with brotli
%bcond_with zstd
%bcond_with ilbc
%bcond_with opus
# Set at most one of these two:
# Note that setcap requires rpmbuild 4.7.0 or later.
@ -350,6 +351,11 @@ cmake3 \
%else
-DENABLE_ILBC=OFF \
%endif
%if %{with opus}
-DENABLE_OPUS=ON \
%else
-DENABLE_OPUS=OFF \
%endif
%if %{with ninja}
# Older RPM-based distributions used ninja-build in order to prevent a collision with
@ -507,6 +513,9 @@ update-mime-database %{_datadir}/mime &> /dev/null || :
%{_libdir}/pkgconfig/wireshark.pc
%changelog
* Tue Sep 29 2020 Lin Sun
- Added opus codec as an option
* Sun Jan 19 2020 Jiri Novak
- Added ilbc codec as an option

View File

@ -135,7 +135,7 @@ foreach(_dll ${CARES_DLL} ${GCRYPT_DLLS}
${GNUTLS_DLLS} ${KERBEROS_DLLS} ${LIBSSH_DLL} ${LUA_DLL}
${LZ4_DLL} ${NGHTTP2_DLL} ${SBC_DLL} ${SMI_DLL} ${SNAPPY_DLL}
${SPANDSP_DLL} ${BCG729_DLL} ${LIBXML2_DLLS} ${WINSPARKLE_DLL}
${ZLIB_DLL} ${BROTLI_DLLS} ${ZSTD_DLL} ${ILBC_DLL}
${ZLIB_DLL} ${BROTLI_DLLS} ${ZSTD_DLL} ${ILBC_DLL} ${OPUS_DLL}
# Required for mmdbresolve
${MAXMINDDB_DLL}
)
@ -174,7 +174,7 @@ foreach(_dll ${CARES_DLL} ${GCRYPT_DLLS}
${GNUTLS_DLLS} ${KERBEROS_DLLS} ${LIBSSH_DLL} ${LUA_DLL}
${LZ4_DLL} ${NGHTTP2_DLL} ${SBC_DLL} ${SMI_DLL} ${SNAPPY_DLL}
${SPANDSP_DLL} ${BCG729_DLL} ${LIBXML2_DLLS} ${WINSPARKLE_DLL}
${ZLIB_DLL} ${BROTLI_DLLS} ${ZSTD_DLL} ${ILBC_DLL}
${ZLIB_DLL} ${BROTLI_DLLS} ${ZSTD_DLL} ${ILBC_DLL} ${OPUS_DLL}
# mmdbresolve
${MAXMINDDB_DLL}
)

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Include>
<!-- Plugins -->
@ -129,6 +129,9 @@
<Component Id="cmpILBC_dll" Guid="*">
<File Id="filILBC_dll" KeyPath="yes" Source="$(var.Plugins.Dir)\$(var.WiresharkMajorVersion).$(var.WiresharkMinorVersion)\codecs\ilbc.dll" />
</Component>
<Component Id="cmpOPUS_dll" Guid="*">
<File Id="filOPUS_dll" KeyPath="yes" Source="$(var.Plugins.Dir)\$(var.WiresharkMajorVersion).$(var.WiresharkMinorVersion)\codecs\opus_dec.dll" />
</Component>
</DirectoryRef>
</Fragment>
<Fragment>
@ -140,6 +143,7 @@
<ComponentRef Id="cmpL16mono_dll" />
<ComponentRef Id="cmpSBC_dll" />
<ComponentRef Id="cmpILBC_dll" />
<ComponentRef Id="cmpOPUS_dll" />
</ComponentGroup>
</Fragment>

View File

@ -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:
#

View File

@ -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:
*/

View File

@ -159,6 +159,10 @@ echo "libsystemd-dev is unavailable"
add_package ADDITIONAL_LIST libilbc-dev ||
echo "libilbc-dev is unavailable"
# opus library libopus-dev
add_package ADDITIONAL_LIST libopus-dev ||
echo "libopus-dev is unavailable"
# softhsm2 2.0.0: Ubuntu 16.04
# softhsm2 2.2.0: Debian >= jessie-backports, Ubuntu 18.04
# softhsm2 >= 2.4.0: Debian >= buster, Ubuntu >= 18.10

View File

@ -170,6 +170,7 @@ if [ "$SPANDSP_VERSION" ]; then
fi
BCG729_VERSION=1.0.2
ILBC_VERSION=2.0.2
OPUS_VERSION=1.3.1
PYTHON3_VERSION=3.7.1
BROTLI_VERSION=1.0.7
# minizip
@ -1776,6 +1777,42 @@ uninstall_ilbc() {
fi
}
install_opus() {
if [ "$OPUS_VERSION" -a ! -f opus-$OPUS_VERSION-done ] ; then
echo "Downloading, building, and installing opus:"
[ -f opus-$OPUS_VERSION.tar.gz ] || curl -L -O https://archive.mozilla.org/pub/opus/opus-$OPUS_VERSION.tar.gz || exit 1
$no_build && echo "Skipping installation" && return
gzcat opus-$OPUS_VERSION.tar.gz | tar xf - || exit 1
cd opus-$OPUS_VERSION
CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
make $MAKE_BUILD_OPTS || exit 1
$DO_MAKE_INSTALL || exit 1
cd ..
touch opus-$OPUS_VERSION-done
fi
}
uninstall_opus() {
if [ ! -z "$installed_opus_version" ] ; then
echo "Uninstalling opus:"
cd opus-$installed_opus_version
$DO_MAKE_UNINSTALL || exit 1
make distclean || exit 1
cd ..
rm opus-$installed_opus_version-done
if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
#
# Get rid of the previously downloaded and unpacked version.
#
rm -rf opus-$installed_opus_version
rm -rf opus-$installed_opus_version.tar.gz
fi
installed_opus_version=""
fi
}
install_python3() {
local macver=10.9
if [[ $DARWIN_MAJOR_VERSION -lt 13 ]]; then
@ -1987,6 +2024,17 @@ install_all() {
uninstall_ilbc -r
fi
if [ -n "$installed_opus_version" ] \
&& [ "$installed_opus_version" != "$OPUS_VERSION" ] ; then
echo "Installed opus version is $installed_opus_version"
if [ -z "$OPUS_VERSION" ] ; then
echo "opus is not requested"
else
echo "Requested opus version is $OPUS_VERSION"
fi
uninstall_opus -r
fi
if [ ! -z "$installed_spandsp_version" -a \
"$installed_spandsp_version" != "$SPANDSP_VERSION" ] ; then
echo "Installed SpanDSP version is $installed_spandsp_version"
@ -2475,6 +2523,8 @@ install_all() {
install_ilbc
install_opus
install_python3
install_brotli
@ -2506,6 +2556,8 @@ uninstall_all() {
uninstall_python3
uninstall_opus
uninstall_ilbc
uninstall_bcg729
@ -2714,6 +2766,7 @@ then
installed_speexdsp_version=`ls speexdsp-*-done 2>/dev/null | sed 's/speexdsp-\(.*\)-done/\1/'`
installed_bcg729_version=`ls bcg729-*-done 2>/dev/null | sed 's/bcg729-\(.*\)-done/\1/'`
installed_ilbc_version=`ls ilbc-*-done 2>/dev/null | sed 's/ilbc-\(.*\)-done/\1/'`
installed_opus_version=`ls opus-*-done 2>/dev/null | sed 's/opus-\(.*\)-done/\1/'`
installed_python3_version=`ls python3-*-done 2>/dev/null | sed 's/python3-\(.*\)-done/\1/'`
installed_brotli_version=`ls brotli-*-done 2>/dev/null | sed 's/brotli-\(.*\)-done/\1/'`
installed_minizip_version=`ls minizip-*-done 2>/dev/null | sed 's/minizip-\(.*\)-done/\1/'`

View File

@ -217,6 +217,9 @@ echo "libnl3/libnl are unavailable" >&2
add_package ADDITIONAL_LIST ilbc-devel ||
echo "ilbc is unavailable" >&2
add_package ADDITIONAL_LIST opus-devel ||
echo "opus is unavailable" >&2
ACTUAL_LIST=$BASIC_LIST
# Now arrange for optional support libraries

View File

@ -69,8 +69,8 @@ Param(
# trouble instead of trying to catch exceptions everywhere.
$ErrorActionPreference = "Stop"
$Win64CurrentTag = "2020-09-27"
$Win32CurrentTag = "2020-09-27"
$Win64CurrentTag = "2020-09-30"
$Win32CurrentTag = "2020-09-30"
# Archive file / SHA256
$Win64Archives = @{
@ -90,6 +90,7 @@ $Win64Archives = @{
"MaxMindDB-1.3.2-win64ws.zip" = "9025c43e9b21ff0bfbaf206b8ed96e2920ef1434107f789e4c7c0c1d8b508952";
"minizip-1.2.11-4-win64ws.zip" = "dd6bf24e2d946465ad19aa4f8c38e0db91da6585887935de68011982cd6fb2cb";
"nghttp2-1.39.2-win64ws.zip" = "a53f4074bffd919539d90c8d0cde2ea6a10a383f14e38b706e7e70e55476e6bf";
"opus-1.3.1-3-win64ws.zip" = "1f7a55a6d2d7215dffa4a43bca8ca05024bd4ba1ac3d0d0c405fd38b09cc2205";
"sbc-1.3-1-win64ws.zip" = "08cef6898c421277a6582ef3225d8820f74a037cbd5b6e673a4d8f4593ce80a1";
"snappy-1.1.3-1-win64ws.zip" = "692a15e70f2cdeca621988a46e936d3651e7feb5176981f2656a5e913c394bcc";
"spandsp-0.0.6-1-win64ws.zip" = "0e46c61a5a8dca562c36e88a8962a50c1ec1a9fcf89dd05996dac5a79e454527";
@ -115,6 +116,7 @@ $Win32Archives = @{
"MaxMindDB-1.3.2-win32ws.zip" = "5c8b4bf3092da8fad6edb005a5283c6a74b7e115a50da010953eed77d33c11b7";
"minizip-1.2.11-4-win32ws.zip" = "41e113930902c2519c4644e8307a0cc51c5855e001e1e69768c48deb376142d0";
"nghttp2-1.39.2-win32ws.zip" = "b511260befc210c1d6d0e920e5f5c47b9e6a21baee6e9874ef12a92093abd245";
"opus-1.3.1-3-win32ws.zip" = "9700b14c8945fcfed2188b806a2ee7e8628922c22569a4c5183075f3dc133177";
"sbc-1.3-1-win32ws.zip" = "ad37825e9ace4b849a5442c08f1ed7e30634e6b774bba4307fb86f35f82e71ba";
"snappy-1.1.3-1-win32ws.zip" = "2508ef7c5d27655c356d7b86a00ac887fc178eab5df63595b8793953dae5c379";
"spandsp-0.0.6-1-win32ws.zip" = "3c25f2f4d641d4257ec9922f6db77346a8eed2e360e7d0e27b828ade19c4705b";
@ -176,6 +178,7 @@ $CleanupItems = @(
"MaxMindDB-1.3.2-win??ws"
"minizip-*-win??ws"
"nghttp2-*-win??ws"
"opus-1.3.1-?-win??ws"
"portaudio_v19"
"portaudio_v19_2"
"sbc-1.3-win??ws"