From 186f985793cceb7d7222955987df72ab5a82beeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Sat, 2 Feb 2019 14:52:07 +0000 Subject: [PATCH] CMake: Check for and use system SpeexDSP library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8443379d23a2946dd21c12e5e0bd5464ab73ca25 Reviewed-on: https://code.wireshark.org/review/31857 Reviewed-by: Peter Wu Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: João Valverde --- CMakeLists.txt | 23 ++++++++++ cmake/modules/FindSpeexDSP.cmake | 38 +++++++++++++++++ cmakeconfig.h.in | 3 ++ codecs/CMakeLists.txt | 4 -- debian/libwscodecs0.symbols | 22 ---------- docbook/release-notes.adoc | 2 + sharkd_session.c | 2 +- speexdsp/CMakeLists.txt | 15 +++++++ {codecs/speex => speexdsp}/README.txt | 0 {codecs/speex => speexdsp}/arch.h | 0 {codecs/speex => speexdsp}/resample.c | 0 {codecs/speex => speexdsp}/speex_resampler.h | 44 ++++++++++---------- {codecs/speex => speexdsp}/stack_alloc.h | 0 ui/qt/CMakeLists.txt | 1 + ui/qt/main.cpp | 6 +++ ui/qt/rtp_audio_stream.cpp | 2 +- 16 files changed, 112 insertions(+), 50 deletions(-) create mode 100644 cmake/modules/FindSpeexDSP.cmake create mode 100644 speexdsp/CMakeLists.txt rename {codecs/speex => speexdsp}/README.txt (100%) rename {codecs/speex => speexdsp}/arch.h (100%) rename {codecs/speex => speexdsp}/resample.c (100%) rename {codecs/speex => speexdsp}/speex_resampler.h (89%) rename {codecs/speex => speexdsp}/stack_alloc.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 84c2b0d133..4e44f96849 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1162,6 +1162,18 @@ find_package(POD REQUIRED) find_package(DOXYGEN) +# The SpeexDSP resampler is required iff building wireshark or sharkd. +if(BUILD_wireshark OR BUILD_sharkd) + find_package(SpeexDSP) + if(SpeexDSP_FOUND) + set(HAVE_SPEEXDSP 1) + else() + add_subdirectory(speexdsp) + set(SPEEXDSP_INCLUDE_DIRS "") + set(SPEEXDSP_LIBRARIES "speexresampler") + endif() +endif() + # dist target that prepares source dir # XXX Duplicated in the RPM section below. add_custom_target(dist @@ -1558,6 +1570,11 @@ set_package_properties(MaxMindDB PROPERTIES DESCRIPTION "C library for the MaxMind DB file format" PURPOSE "Support for GeoIP lookup" ) +set_package_properties(SpeexDSP PROPERTIES + URL "https://www.speex.org/" + DESCRIPTION "SpeexDSP is a patent-free, Open Source/Free Software DSP library" + PURPOSE "RTP audio resampling" +) string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type) message(STATUS "C-Flags: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_build_type}}") @@ -2180,6 +2197,7 @@ if(BUILD_wireshark AND QT_FOUND) ${WIN_VERSION_LIBRARY} ${WINSPARKLE_LIBRARIES} $<$:UxTheme.lib> + ${SPEEXDSP_LIBRARIES} ) add_executable(wireshark WIN32 MACOSX_BUNDLE ${wireshark_FILES} ${EXTRA_BUNDLE_FILES}) @@ -2368,6 +2386,7 @@ if(BUILD_sharkd) ${APPLE_CORE_FOUNDATION_LIBRARY} ${APPLE_SYSTEM_CONFIGURATION_LIBRARY} ${WIN_WS2_32_LIBRARY} + ${SPEEXDSP_LIBRARIES} ) set(sharkd_FILES # @@ -2384,6 +2403,10 @@ if(BUILD_sharkd) add_executable(sharkd ${sharkd_FILES}) set_extra_executable_properties(sharkd "Executables") target_link_libraries(sharkd ${sharkd_LIBS}) + target_include_directories(sharkd SYSTEM + PUBLIC + ${SPEEXDSP_INCLUDE_DIRS} + ) install(TARGETS sharkd RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/cmake/modules/FindSpeexDSP.cmake b/cmake/modules/FindSpeexDSP.cmake new file mode 100644 index 0000000000..6c111111e5 --- /dev/null +++ b/cmake/modules/FindSpeexDSP.cmake @@ -0,0 +1,38 @@ +# +# - Find speexdsp libraries +# +# SPEEXDSP_INCLUDE_DIRS - where to find speexdsp headers. +# SPEEXDSP_LIBRARIES - List of libraries when using speexdsp. +# SPEEXDSP_FOUND - True if speexdsp is found. + +find_package(PkgConfig QUIET) +pkg_search_module(PC_SPEEXDSP QUIET speexdsp) + +find_path(SPEEXDSP_INCLUDE_DIR + NAMES + speex/speex_resampler.h + HINTS + ${PC_SPEEXDSP_INCLUDE_DIRS} +) + +find_library(SPEEXDSP_LIBRARY + NAMES + speexdsp + HINTS + ${PC_SPEEXDSP_LIBRARY_DIRS} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SpeexDSP + REQUIRED_VARS SPEEXDSP_LIBRARY SPEEXDSP_INCLUDE_DIR + VERSION_VAR PC_SPEEXDSP_VERSION) + +if(SPEEXDSP_FOUND) + set(SPEEXDSP_LIBRARIES ${SPEEXDSP_LIBRARY}) + set(SPEEXDSP_INCLUDE_DIRS ${SPEEXDSP_INCLUDE_DIR}) +else() + set(SPEEXDSP_LIBRARIES) + set(SPEEXDSP_INCLUDE_DIRS) +endif() + +mark_as_advanced(SPEEXDSP_LIBRARIES SPEEXDSP_INCLUDE_DIRS) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 924d9347eb..32c812981a 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -275,6 +275,9 @@ /* Define to 1 if you have the bcg729 library. */ #cmakedefine HAVE_BCG729 1 +/* Define to 1 if you have the speexdsp library. */ +#cmakedefine HAVE_SPEEXDSP 1 + /* Define to 1 if you have the lixbml2 library. */ #cmakedefine HAVE_LIBXML2 1 diff --git a/codecs/CMakeLists.txt b/codecs/CMakeLists.txt index f46cabc96e..e714975c94 100644 --- a/codecs/CMakeLists.txt +++ b/codecs/CMakeLists.txt @@ -15,7 +15,6 @@ set(WSCODECS_FILES codecs.c G711a/G711adecode.c G711u/G711udecode.c - speex/resample.c ) # Enables visibility in IDEs @@ -23,9 +22,6 @@ 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) diff --git a/debian/libwscodecs0.symbols b/debian/libwscodecs0.symbols index b83aa5f1b5..e2f4951ebf 100644 --- a/debian/libwscodecs0.symbols +++ b/debian/libwscodecs0.symbols @@ -11,25 +11,3 @@ libwscodecs.so.0 libwscodecs0 #MINVER# codecs_register_plugin@Base 2.5.0 codec_get_compiled_version_info@Base 2.3.0 register_codec@Base 2.1.0 - ws_codec_resampler_destroy@Base 2.1.0 - ws_codec_resampler_get_input_latency@Base 2.1.0 - ws_codec_resampler_get_input_stride@Base 2.1.0 - ws_codec_resampler_get_output_latency@Base 2.1.0 - ws_codec_resampler_get_output_stride@Base 2.1.0 - ws_codec_resampler_get_quality@Base 2.1.0 - ws_codec_resampler_get_rate@Base 2.1.0 - ws_codec_resampler_get_ratio@Base 2.1.0 - ws_codec_resampler_init@Base 2.1.0 - ws_codec_resampler_init_frac@Base 2.1.0 - ws_codec_resampler_process_float@Base 2.1.0 - ws_codec_resampler_process_int@Base 2.1.0 - ws_codec_resampler_process_interleaved_float@Base 2.1.0 - ws_codec_resampler_process_interleaved_int@Base 2.1.0 - ws_codec_resampler_reset_mem@Base 2.1.0 - ws_codec_resampler_set_input_stride@Base 2.1.0 - ws_codec_resampler_set_output_stride@Base 2.1.0 - ws_codec_resampler_set_quality@Base 2.1.0 - ws_codec_resampler_set_rate@Base 2.1.0 - ws_codec_resampler_set_rate_frac@Base 2.1.0 - ws_codec_resampler_skip_zeros@Base 2.1.0 - ws_codec_resampler_strerror@Base 2.1.0 diff --git a/docbook/release-notes.adoc b/docbook/release-notes.adoc index 3ad46bd5fa..ec923df273 100644 --- a/docbook/release-notes.adoc +++ b/docbook/release-notes.adoc @@ -35,6 +35,8 @@ The following features are new (or have been significantly updated) since version 3.0.0: * Brotli decompression support in HTTP/HTTP2 (requires the brotli library). +* The build system now checks for a SpeexDSP system library installation. The + bundled Speex resampler code is still provided as a fallback. // === Removed Features and Support diff --git a/sharkd_session.c b/sharkd_session.c index b611df297a..bf3531669a 100644 --- a/sharkd_session.c +++ b/sharkd_session.c @@ -61,7 +61,7 @@ #ifdef HAVE_SPEEXDSP # include #else -# include +# include "speexdsp/speex_resampler.h" #endif /* HAVE_SPEEXDSP */ #include diff --git a/speexdsp/CMakeLists.txt b/speexdsp/CMakeLists.txt new file mode 100644 index 0000000000..1667dfec28 --- /dev/null +++ b/speexdsp/CMakeLists.txt @@ -0,0 +1,15 @@ +# CMakeLists.txt +# +# Wireshark - Network traffic analyzer +# By Gerald Combs +# Copyright 1998 Gerald Combs +# +# SPDX-License-Identifier: GPL-2.0-or-later +# + +add_library(speexresampler STATIC resample.c) + +set_target_properties(speexresampler PROPERTIES + LINK_FLAGS "${WS_LINK_FLAGS}" + FOLDER "Libs" +) diff --git a/codecs/speex/README.txt b/speexdsp/README.txt similarity index 100% rename from codecs/speex/README.txt rename to speexdsp/README.txt diff --git a/codecs/speex/arch.h b/speexdsp/arch.h similarity index 100% rename from codecs/speex/arch.h rename to speexdsp/arch.h diff --git a/codecs/speex/resample.c b/speexdsp/resample.c similarity index 100% rename from codecs/speex/resample.c rename to speexdsp/resample.c diff --git a/codecs/speex/speex_resampler.h b/speexdsp/speex_resampler.h similarity index 89% rename from codecs/speex/speex_resampler.h rename to speexdsp/speex_resampler.h index 59eb307f6e..57dbd526b0 100644 --- a/codecs/speex/speex_resampler.h +++ b/speexdsp/speex_resampler.h @@ -124,7 +124,7 @@ typedef struct SpeexResamplerState_ SpeexResamplerState; * @return Newly created resampler state * @retval NULL Error: not enough memory */ -WS_DLL_PUBLIC SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels, +SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels, spx_uint32_t in_rate, spx_uint32_t out_rate, int quality, @@ -143,7 +143,7 @@ WS_DLL_PUBLIC SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels * @return Newly created resampler state * @retval NULL Error: not enough memory */ -WS_DLL_PUBLIC SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels, +SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels, spx_uint32_t ratio_num, spx_uint32_t ratio_den, spx_uint32_t in_rate, @@ -154,7 +154,7 @@ WS_DLL_PUBLIC SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_cha /** Destroy a resampler state. * @param st Resampler state */ -WS_DLL_PUBLIC void speex_resampler_destroy(SpeexResamplerState *st); +void speex_resampler_destroy(SpeexResamplerState *st); /** Resample a float array. The input and output buffers must *not* overlap. * @param st Resampler state @@ -166,7 +166,7 @@ WS_DLL_PUBLIC void speex_resampler_destroy(SpeexResamplerState *st); * @param out Output buffer * @param out_len Size of the output buffer. Returns the number of samples written */ -WS_DLL_PUBLIC int speex_resampler_process_float(SpeexResamplerState *st, +int speex_resampler_process_float(SpeexResamplerState *st, spx_uint32_t channel_index, const float *in, spx_uint32_t *in_len, @@ -183,7 +183,7 @@ WS_DLL_PUBLIC int speex_resampler_process_float(SpeexResamplerState *st, * @param out Output buffer * @param out_len Size of the output buffer. Returns the number of samples written */ -WS_DLL_PUBLIC int speex_resampler_process_int(SpeexResamplerState *st, +int speex_resampler_process_int(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_int16_t *in, spx_uint32_t *in_len, @@ -199,7 +199,7 @@ WS_DLL_PUBLIC int speex_resampler_process_int(SpeexResamplerState *st, * @param out_len Size of the output buffer. Returns the number of samples written. * This is all per-channel. */ -WS_DLL_PUBLIC int speex_resampler_process_interleaved_float(SpeexResamplerState *st, +int speex_resampler_process_interleaved_float(SpeexResamplerState *st, const float *in, spx_uint32_t *in_len, float *out, @@ -214,7 +214,7 @@ WS_DLL_PUBLIC int speex_resampler_process_interleaved_float(SpeexResamplerState * @param out_len Size of the output buffer. Returns the number of samples written. * This is all per-channel. */ -WS_DLL_PUBLIC int speex_resampler_process_interleaved_int(SpeexResamplerState *st, +int speex_resampler_process_interleaved_int(SpeexResamplerState *st, const spx_int16_t *in, spx_uint32_t *in_len, spx_int16_t *out, @@ -225,7 +225,7 @@ WS_DLL_PUBLIC int speex_resampler_process_interleaved_int(SpeexResamplerState *s * @param in_rate Input sampling rate (integer number of Hz). * @param out_rate Output sampling rate (integer number of Hz). */ -WS_DLL_PUBLIC int speex_resampler_set_rate(SpeexResamplerState *st, +int speex_resampler_set_rate(SpeexResamplerState *st, spx_uint32_t in_rate, spx_uint32_t out_rate); @@ -234,7 +234,7 @@ WS_DLL_PUBLIC int speex_resampler_set_rate(SpeexResamplerState *st, * @param in_rate Input sampling rate (integer number of Hz) copied. * @param out_rate Output sampling rate (integer number of Hz) copied. */ -WS_DLL_PUBLIC void speex_resampler_get_rate(SpeexResamplerState *st, +void speex_resampler_get_rate(SpeexResamplerState *st, spx_uint32_t *in_rate, spx_uint32_t *out_rate); @@ -246,7 +246,7 @@ WS_DLL_PUBLIC void speex_resampler_get_rate(SpeexResamplerState *st, * @param in_rate Input sampling rate rounded to the nearest integer (in Hz). * @param out_rate Output sampling rate rounded to the nearest integer (in Hz). */ -WS_DLL_PUBLIC int speex_resampler_set_rate_frac(SpeexResamplerState *st, +int speex_resampler_set_rate_frac(SpeexResamplerState *st, spx_uint32_t ratio_num, spx_uint32_t ratio_den, spx_uint32_t in_rate, @@ -258,7 +258,7 @@ WS_DLL_PUBLIC int speex_resampler_set_rate_frac(SpeexResamplerState *st, * @param ratio_num Numerator of the sampling rate ratio copied * @param ratio_den Denominator of the sampling rate ratio copied */ -WS_DLL_PUBLIC void speex_resampler_get_ratio(SpeexResamplerState *st, +void speex_resampler_get_ratio(SpeexResamplerState *st, spx_uint32_t *ratio_num, spx_uint32_t *ratio_den); @@ -267,7 +267,7 @@ WS_DLL_PUBLIC void speex_resampler_get_ratio(SpeexResamplerState *st, * @param quality Resampling quality between 0 and 10, where 0 has poor * quality and 10 has very high quality. */ -WS_DLL_PUBLIC int speex_resampler_set_quality(SpeexResamplerState *st, +int speex_resampler_set_quality(SpeexResamplerState *st, int quality); /** Get the conversion quality. @@ -275,46 +275,46 @@ WS_DLL_PUBLIC int speex_resampler_set_quality(SpeexResamplerState *st, * @param quality Resampling quality between 0 and 10, where 0 has poor * quality and 10 has very high quality. */ -WS_DLL_PUBLIC void speex_resampler_get_quality(SpeexResamplerState *st, +void speex_resampler_get_quality(SpeexResamplerState *st, int *quality); /** Set (change) the input stride. * @param st Resampler state * @param stride Input stride */ -WS_DLL_PUBLIC void speex_resampler_set_input_stride(SpeexResamplerState *st, +void speex_resampler_set_input_stride(SpeexResamplerState *st, spx_uint32_t stride); /** Get the input stride. * @param st Resampler state * @param stride Input stride copied */ -WS_DLL_PUBLIC void speex_resampler_get_input_stride(SpeexResamplerState *st, +void speex_resampler_get_input_stride(SpeexResamplerState *st, spx_uint32_t *stride); /** Set (change) the output stride. * @param st Resampler state * @param stride Output stride */ -WS_DLL_PUBLIC void speex_resampler_set_output_stride(SpeexResamplerState *st, +void speex_resampler_set_output_stride(SpeexResamplerState *st, spx_uint32_t stride); /** Get the output stride. * @param st Resampler state copied * @param stride Output stride */ -WS_DLL_PUBLIC void speex_resampler_get_output_stride(SpeexResamplerState *st, +void speex_resampler_get_output_stride(SpeexResamplerState *st, spx_uint32_t *stride); /** Get the latency introduced by the resampler measured in input samples. * @param st Resampler state */ -WS_DLL_PUBLIC int speex_resampler_get_input_latency(SpeexResamplerState *st); +int speex_resampler_get_input_latency(SpeexResamplerState *st); /** Get the latency introduced by the resampler measured in output samples. * @param st Resampler state */ -WS_DLL_PUBLIC int speex_resampler_get_output_latency(SpeexResamplerState *st); +int speex_resampler_get_output_latency(SpeexResamplerState *st); /** Make sure that the first samples to go out of the resamplers don't have * leading zeros. This is only useful before starting to use a newly created @@ -324,18 +324,18 @@ WS_DLL_PUBLIC int speex_resampler_get_output_latency(SpeexResamplerState *st); * is the same for the first frame). * @param st Resampler state */ -WS_DLL_PUBLIC int speex_resampler_skip_zeros(SpeexResamplerState *st); +int speex_resampler_skip_zeros(SpeexResamplerState *st); /** Reset a resampler so a new (unrelated) stream can be processed. * @param st Resampler state */ -WS_DLL_PUBLIC int speex_resampler_reset_mem(SpeexResamplerState *st); +int speex_resampler_reset_mem(SpeexResamplerState *st); /** Returns the English meaning for an error code * @param err Error code * @return English string */ -WS_DLL_PUBLIC const char *speex_resampler_strerror(int err); +const char *speex_resampler_strerror(int err); #ifdef __cplusplus } diff --git a/codecs/speex/stack_alloc.h b/speexdsp/stack_alloc.h similarity index 100% rename from codecs/speex/stack_alloc.h rename to speexdsp/stack_alloc.h diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt index 2af1eb4cb5..226e51f830 100644 --- a/ui/qt/CMakeLists.txt +++ b/ui/qt/CMakeLists.txt @@ -663,6 +663,7 @@ target_include_directories(qtui SYSTEM PUBLIC ${QT_INCLUDE_DIRS} ${WINSPARKLE_INCLUDE_DIRS} + ${SPEEXDSP_INCLUDE_DIRS} PRIVATE ${PCAP_INCLUDE_DIRS} ) diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index db0a123ffe..8026b9f4fb 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -235,6 +235,12 @@ get_gui_compiled_info(GString *str) #endif #endif /* _WIN32 */ +#ifdef HAVE_SPEEXDSP + g_string_append(str, ", with SpeexDSP (using system library)"); +#else + g_string_append(str, ", with SpeexDSP (using bundled resampler)"); +#endif + codec_get_compiled_version_info(str); } diff --git a/ui/qt/rtp_audio_stream.cpp b/ui/qt/rtp_audio_stream.cpp index 3f05cfd9cc..f5ed020b38 100644 --- a/ui/qt/rtp_audio_stream.cpp +++ b/ui/qt/rtp_audio_stream.cpp @@ -14,7 +14,7 @@ #ifdef HAVE_SPEEXDSP #include #else -#include +#include "../../speexdsp/speex_resampler.h" #endif /* HAVE_SPEEXDSP */ #include