diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2019-02-03 01:07:26 +0000 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2019-06-11 20:27:21 +0000 |
commit | 57bb2b2a099fd1df57a37b3a93a07212167c59aa (patch) | |
tree | 1066544c6480123d022f77e76b508ef4e2c248e2 /plugins/codecs | |
parent | de4463066667e5b3582eb7943c6bbd42d23059bf (diff) |
Move codec plugins to /plugins
Change-Id: I56d61e2ef737e4326080d75a2302c73a4075e8a1
Reviewed-on: https://code.wireshark.org/review/33067
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'plugins/codecs')
-rw-r--r-- | plugins/codecs/G711/CMakeLists.txt | 68 | ||||
-rw-r--r-- | plugins/codecs/G711/G711decode.c | 198 | ||||
-rw-r--r-- | plugins/codecs/G722/CMakeLists.txt | 70 | ||||
-rw-r--r-- | plugins/codecs/G722/G722decode.c | 96 | ||||
-rw-r--r-- | plugins/codecs/G726/CMakeLists.txt | 70 | ||||
-rw-r--r-- | plugins/codecs/G726/G726decode.c | 133 | ||||
-rw-r--r-- | plugins/codecs/G729/CMakeLists.txt | 70 | ||||
-rw-r--r-- | plugins/codecs/G729/G729decode.c | 97 | ||||
-rw-r--r-- | plugins/codecs/sbc/CMakeLists.txt | 70 | ||||
-rw-r--r-- | plugins/codecs/sbc/sbc.c | 139 |
10 files changed, 1011 insertions, 0 deletions
diff --git a/plugins/codecs/G711/CMakeLists.txt b/plugins/codecs/G711/CMakeLists.txt new file mode 100644 index 0000000000..642d32a3ae --- /dev/null +++ b/plugins/codecs/G711/CMakeLists.txt @@ -0,0 +1,68 @@ +# 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(g711 0 1 0 0) + +set(CODEC_SRC + G711decode.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(g711 codecs) + +target_link_libraries(g711 wscodecs) + +install_plugin(g711 codecs) + +file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h") +CHECKAPI( + NAME + g711 + SWITCHES + -g abort -g termoutput -build + SOURCES + ${CODEC_SRC} + ${CODEC_HEADERS} +) + +# +# Editor modelines - http://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/G711/G711decode.c b/plugins/codecs/G711/G711decode.c new file mode 100644 index 0000000000..19a7f32893 --- /dev/null +++ b/plugins/codecs/G711/G711decode.c @@ -0,0 +1,198 @@ +/* G711adecode.c + * A-law G.711 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 <glib.h> + +#include "codecs/codecs.h" +#include "ws_attributes.h" + +static gint16 ulaw_exp_table[256] = { + -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956, + -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764, + -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412, + -11900,-11388,-10876,-10364, -9852, -9340, -8828, -8316, + -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140, + -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092, + -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004, + -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980, + -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436, + -1372, -1308, -1244, -1180, -1116, -1052, -988, -924, + -876, -844, -812, -780, -748, -716, -684, -652, + -620, -588, -556, -524, -492, -460, -428, -396, + -372, -356, -340, -324, -308, -292, -276, -260, + -244, -228, -212, -196, -180, -164, -148, -132, + -120, -112, -104, -96, -88, -80, -72, -64, + -56, -48, -40, -32, -24, -16, -8, 0, + 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956, + 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764, + 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412, + 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316, + 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140, + 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092, + 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004, + 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980, + 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436, + 1372, 1308, 1244, 1180, 1116, 1052, 988, 924, + 876, 844, 812, 780, 748, 716, 684, 652, + 620, 588, 556, 524, 492, 460, 428, 396, + 372, 356, 340, 324, 308, 292, 276, 260, + 244, 228, 212, 196, 180, 164, 148, 132, + 120, 112, 104, 96, 88, 80, 72, 64, + 56, 48, 40, 32, 24, 16, 8, 0 +}; + +static gint16 alaw_exp_table[256] = { + -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736, + -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784, + -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368, + -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392, + -22016,-20992,-24064,-23040,-17920,-16896,-19968,-18944, + -30208,-29184,-32256,-31232,-26112,-25088,-28160,-27136, + -11008,-10496,-12032,-11520, -8960, -8448, -9984, -9472, + -15104,-14592,-16128,-15616,-13056,-12544,-14080,-13568, + -344, -328, -376, -360, -280, -264, -312, -296, + -472, -456, -504, -488, -408, -392, -440, -424, + -88, -72, -120, -104, -24, -8, -56, -40, + -216, -200, -248, -232, -152, -136, -184, -168, + -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184, + -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696, + -688, -656, -752, -720, -560, -528, -624, -592, + -944, -912, -1008, -976, -816, -784, -880, -848, + 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736, + 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784, + 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368, + 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392, + 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944, + 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136, + 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472, + 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568, + 344, 328, 376, 360, 280, 264, 312, 296, + 472, 456, 504, 488, 408, 392, 440, 424, + 88, 72, 120, 104, 24, 8, 56, 40, + 216, 200, 248, 232, 152, 136, 184, 168, + 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184, + 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696, + 688, 656, 752, 720, 560, 528, 624, 592, + 944, 912, 1008, 976, 816, 784, 880, 848 +}; + +static void * +codec_g711u_init(void) +{ + return NULL; +} + +static void +codec_g711u_release(void *ctx _U_) +{ + +} + +static unsigned +codec_g711u_get_channels(void *ctx _U_) +{ + return 1; +} + +static unsigned +codec_g711u_get_frequency(void *ctx _U_) +{ + return 8000; +} + +static size_t +codec_g711u_decode(void *ctx _U_, const void *input, size_t inputSizeBytes, void *output, + size_t *outputSizeBytes) +{ + const guint8 *dataIn = (const guint8 *) input; + gint16 *dataOut = (gint16 *) output; + size_t i; + + if (!output || !outputSizeBytes) { + return inputSizeBytes * 2; + } + + for (i = 0; i < inputSizeBytes; i++) + { + dataOut[i] = ulaw_exp_table[dataIn[i]]; + } + + *outputSizeBytes = inputSizeBytes * 2; + return inputSizeBytes * 2; +} + +static void * +codec_g711a_init(void) +{ + return NULL; +} + +static void +codec_g711a_release(void *ctx _U_) +{ + +} + +static unsigned +codec_g711a_get_channels(void *ctx _U_) +{ + return 1; +} + +static unsigned +codec_g711a_get_frequency(void *ctx _U_) +{ + return 8000; +} + +static size_t +codec_g711a_decode(void *ctx _U_, const void *input, size_t inputSizeBytes, void *output, + size_t *outputSizeBytes) +{ + const guint8 *dataIn = (const guint8 *) input; + gint16 *dataOut = (gint16 *) output; + size_t i; + + if (!output || !outputSizeBytes) { + return inputSizeBytes * 2; + } + + for (i = 0; i < inputSizeBytes; i++) + { + dataOut[i] = alaw_exp_table[dataIn[i]]; + } + + *outputSizeBytes = inputSizeBytes * 2; + return inputSizeBytes * 2; +} + +void +codec_register_g711(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); +} + +/* + * 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: + */ diff --git a/plugins/codecs/G722/CMakeLists.txt b/plugins/codecs/G722/CMakeLists.txt new file mode 100644 index 0000000000..2350cb0909 --- /dev/null +++ b/plugins/codecs/G722/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(g722 0 1 0 0) + +set(CODEC_SRC + G722decode.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(g722 codecs) + +target_link_libraries(g722 wscodecs ${SPANDSP_LIBRARIES}) + +target_include_directories(g722 SYSTEM PRIVATE ${SPANDSP_INCLUDE_DIRS}) + +install_plugin(g722 codecs) + +file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h") +CHECKAPI( + NAME + g722 + SWITCHES + -g abort -g termoutput -build + SOURCES + ${CODEC_SRC} + ${CODEC_HEADERS} +) + +# +# Editor modelines - http://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/G722/G722decode.c b/plugins/codecs/G722/G722decode.c new file mode 100644 index 0000000000..789e31b478 --- /dev/null +++ b/plugins/codecs/G722/G722decode.c @@ -0,0 +1,96 @@ +/* G722decode.c + * G.722 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 <glib.h> + +#include "spandsp.h" +#include "codecs/codecs.h" +#include "ws_attributes.h" + +static void * +codec_g722_init(void) +{ + g722_decode_state_t *state; + + /* Valid values for bit_rate for G.722 are 48000, 56000, 64000, but RTP/AVP + * profile requires 64kbps, aligned at octets. */ + state = g722_decode_init(NULL, 64000, 0); + + return state; +} + +static void +codec_g722_release(void *ctx) +{ + g722_decode_state_t *state = (g722_decode_state_t *)ctx; + + if (!state) { + return; /* out-of-memory; */ + } + + /* Note: replaces g722_decode_release since SpanDSP 20090211 */ + g722_decode_free(state); +} + +static unsigned +codec_g722_get_channels(void *ctx _U_) +{ + /* G.722 has only one channel. */ + return 1; +} + +static unsigned +codec_g722_get_frequency(void *ctx _U_) +{ + /* Note: RTP Clock rate is 8kHz due to a historic error, but actual sampling + * rate is 16kHz (RFC 3551, section 4.5.2). */ + return 16000; +} + +static size_t +codec_g722_decode(void *ctx, const void *input, size_t inputSizeBytes, void *output, + size_t *outputSizeBytes) +{ + g722_decode_state_t *state = (g722_decode_state_t *)ctx; + + if (!state) { + return 0; /* out-of-memory; */ + } + + if (!output || !outputSizeBytes) { + return 4 * inputSizeBytes; + } + + /* g722_decode returns the number of 16-bit samples. */ + *outputSizeBytes = 2 * g722_decode(state, (int16_t *)output, (const uint8_t *)input, (int)inputSizeBytes); + return *outputSizeBytes; +} + +void +codec_register_g722(void) +{ + register_codec("g722", codec_g722_init, codec_g722_release, + codec_g722_get_channels, codec_g722_get_frequency, codec_g722_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: + */ diff --git a/plugins/codecs/G726/CMakeLists.txt b/plugins/codecs/G726/CMakeLists.txt new file mode 100644 index 0000000000..e598cb82c0 --- /dev/null +++ b/plugins/codecs/G726/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(g726 0 1 0 0) + +set(CODEC_SRC + G726decode.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(g726 codecs) + +target_link_libraries(g726 wscodecs ${SPANDSP_LIBRARIES}) + +target_include_directories(g726 SYSTEM PRIVATE ${SPANDSP_INCLUDE_DIRS}) + +install_plugin(g726 codecs) + +file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h") +CHECKAPI( + NAME + g726 + SWITCHES + -g abort -g termoutput -build + SOURCES + ${CODEC_SRC} + ${CODEC_HEADERS} +) + +# +# Editor modelines - http://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/G726/G726decode.c b/plugins/codecs/G726/G726decode.c new file mode 100644 index 0000000000..86b61c0cbd --- /dev/null +++ b/plugins/codecs/G726/G726decode.c @@ -0,0 +1,133 @@ +/* G726decode.c + * G.726 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 <glib.h> + +#include "spandsp.h" +#include "codecs/codecs.h" +#include "ws_attributes.h" + +typedef struct _g726_codec_ctx { + g726_state_t *state; + int bit_rate; +} g726_codec_ctx; + +static void * +codec_g726_init(int bit_rate, int packing) +{ + g726_state_t *decoder = g726_init(NULL, bit_rate, G726_ENCODING_LINEAR, packing); + + if (!decoder) { + return NULL; /* out-of-memory; */ + } + + g726_codec_ctx *state = g_new(g726_codec_ctx, 1); + state->state = decoder; + state->bit_rate = bit_rate; + + return state; +} + +static void *codec_g726_16_init(void) { return codec_g726_init(16000, G726_PACKING_RIGHT); } +static void *codec_g726_24_init(void) { return codec_g726_init(24000, G726_PACKING_RIGHT); } +static void *codec_g726_32_init(void) { return codec_g726_init(32000, G726_PACKING_RIGHT); } +static void *codec_g726_40_init(void) { return codec_g726_init(40000, G726_PACKING_RIGHT); } +static void *codec_aal2_g726_16_init(void) { return codec_g726_init(16000, G726_PACKING_LEFT); } +static void *codec_aal2_g726_24_init(void) { return codec_g726_init(24000, G726_PACKING_LEFT); } +static void *codec_aal2_g726_32_init(void) { return codec_g726_init(32000, G726_PACKING_LEFT); } +static void *codec_aal2_g726_40_init(void) { return codec_g726_init(40000, G726_PACKING_LEFT); } + +static void +codec_g726_release(void *ctx) +{ + g726_codec_ctx *state = (g726_codec_ctx *)ctx; + + if (!state) { + return; /* out-of-memory; */ + } + + /* Note: replaces g726_release since SpanDSP 20090211 */ + g726_free(state->state); + g_free(state); +} + +static unsigned +codec_g726_get_channels(void *ctx _U_) +{ + return 1; +} + +static unsigned +codec_g726_get_frequency(void *ctx _U_) +{ + return 8000; +} + +static size_t +codec_g726_decode(void *ctx, const void *input, size_t inputSizeBytes, void *output, + size_t *outputSizeBytes) +{ + g726_codec_ctx *state = (g726_codec_ctx *)ctx; + + if (!state) { + return 0; /* out-of-memory; */ + } + + if (!output || !outputSizeBytes) { + /* + * sample rate 8kHz, for bitrate 16kHz we have 16/8 = 2 bits/sample, so + * 1 input byte (8 bits) will expand to four 16-bit samples. Likewise, + * for bitrate 40kHz we have 40/8 = 5 bits/sample. Alternatively: + * bitsPerSample = bitRate / sampleRate (8kHz). + * outputBytes = (inputBits / bitsPerSample) * sizeof(sample) + */ + return inputSizeBytes * 8 / (state->bit_rate / 8000) * 2; + } + + /* g726_decode returns the number of 16-bit samples. */ + *outputSizeBytes = 2 * g726_decode(state->state, (int16_t *)output, (const uint8_t *) input, (int)inputSizeBytes); + return *outputSizeBytes; +} + +void +codec_register_g726(void) +{ + 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); +} + +/* + * 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: + */ diff --git a/plugins/codecs/G729/CMakeLists.txt b/plugins/codecs/G729/CMakeLists.txt new file mode 100644 index 0000000000..f4c1765f27 --- /dev/null +++ b/plugins/codecs/G729/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(g729 0 1 0 0) + +set(CODEC_SRC + G729decode.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(g729 codecs) + +target_link_libraries(g729 wscodecs ${BCG729_LIBRARIES}) + +target_include_directories(g729 SYSTEM PRIVATE ${BCG729_INCLUDE_DIRS}) + +install_plugin(g729 codecs) + +file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h") +CHECKAPI( + NAME + g729 + SWITCHES + -g abort -g termoutput -build + SOURCES + ${CODEC_SRC} + ${CODEC_HEADERS} +) + +# +# Editor modelines - http://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/G729/G729decode.c b/plugins/codecs/G729/G729decode.c new file mode 100644 index 0000000000..e2308f36f8 --- /dev/null +++ b/plugins/codecs/G729/G729decode.c @@ -0,0 +1,97 @@ +/* G729decode.c + * G.729 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 <glib.h> + +#include "bcg729/decoder.h" +#include "codecs/codecs.h" +#include "ws_attributes.h" + +static void * +codec_g729_init(void) +{ + return initBcg729DecoderChannel(); +} + +static void +codec_g729_release(void *ctx) +{ + closeBcg729DecoderChannel((bcg729DecoderChannelContextStruct *)ctx); +} + +static unsigned +codec_g729_get_channels(void *ctx _U_) +{ + return 1; +} + +static unsigned +codec_g729_get_frequency(void *ctx _U_) +{ + return 8000; +} + +static size_t +codec_g729_decode(void *ctx, const void *input, size_t inputSizeBytes, void *output, + size_t *outputSizeBytes) +{ + bcg729DecoderChannelContextStruct *state = (bcg729DecoderChannelContextStruct *)ctx; + const guint8 *dataIn = (const guint8 *) input; + gint16 *dataOut = (gint16 *) output; + size_t i; + + if (!ctx) { + return 0; + } + + if (!output || !outputSizeBytes) { + return 80*2*(inputSizeBytes/10); + } + + /* The G729 algorithm encodes 10ms of voice into 80bit (10 bytes). + Based on the RTP packetization period (usually 20ms), we need to + pass to the bcg729 decoder chunks of 10ms (10 bytes) + */ + for (i = 0; i < (inputSizeBytes/10); i++) { + /* The bcg729 decoder library fails to declare the second + argument to bcg729Decoder() to be a const pointer. If you + fix it, and some other functions, to use const, the library + compiles, so presumably it doesn't modify its input and + therefore can safely be passed a const pointer. Cast away + the problem for now; a patch will be sent to the maintainers + of the library. + */ + bcg729Decoder(state, (guint8 *)dataIn + i*10, 10, 0, 0, 0, dataOut + i*80); + } + *outputSizeBytes = 80*2*(inputSizeBytes/10); + return *outputSizeBytes; +} + +void +codec_register_g729(void) +{ + register_codec("g729", codec_g729_init, codec_g729_release, + codec_g729_get_channels, codec_g729_get_frequency, codec_g729_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: + */ diff --git a/plugins/codecs/sbc/CMakeLists.txt b/plugins/codecs/sbc/CMakeLists.txt new file mode 100644 index 0000000000..bf068ed5e3 --- /dev/null +++ b/plugins/codecs/sbc/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(sbc 0 1 0 0) + +set(CODEC_SRC + sbc.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(sbc codecs) + +target_link_libraries(sbc wscodecs ${SBC_LIBRARIES}) + +target_include_directories(sbc SYSTEM PRIVATE ${SBC_INCLUDE_DIRS}) + +install_plugin(sbc codecs) + +file(GLOB CODEC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h") +CHECKAPI( + NAME + sbc + SWITCHES + -g abort -g termoutput -build + SOURCES + ${CODEC_SRC} + ${CODEC_HEADERS} +) + +# +# Editor modelines - http://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/sbc/sbc.c b/plugins/codecs/sbc/sbc.c new file mode 100644 index 0000000000..3992cd3840 --- /dev/null +++ b/plugins/codecs/sbc/sbc.c @@ -0,0 +1,139 @@ +/* sbc.c + * Support for external Bluetooth SBC codec + * + * Copyright 2012, Michal Labedzki for Tieto Corporation + * + * 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 <glib.h> +#include <sbc/sbc.h> + +#include "codecs/codecs.h" + +#define SBC_BUFFER 8192 + +static void * +codec_sbc_init(void) +{ + sbc_t *sbc; + + sbc = (sbc_t *) g_malloc(sizeof(sbc_t)); + sbc_init(sbc, 0L); + + return sbc; +} + +static void +codec_sbc_release(void *ctx) +{ + sbc_t *sbc = (sbc_t *) ctx; + + sbc_finish(sbc); + g_free(sbc); +} + +static unsigned +codec_sbc_get_channels(void *ctx) +{ + sbc_t *sbc = (sbc_t *) ctx; + if (sbc->mode == SBC_MODE_MONO) + return 1; + + return 2; +} + +static unsigned +codec_sbc_get_frequency(void *ctx) +{ + sbc_t *sbc = (sbc_t *) ctx; + int frequency; + + switch (sbc->frequency) { + case SBC_FREQ_16000: + frequency = 16000; + break; + + case SBC_FREQ_32000: + frequency = 32000; + break; + + case SBC_FREQ_44100: + frequency = 44100; + break; + + case SBC_FREQ_48000: + frequency = 48000; + break; + default: + frequency = 0; + } + + return frequency; +} + +static size_t +codec_sbc_decode(void *ctx, const void *input, size_t inputSizeBytes, void *output, + size_t *outputSizeBytes) +{ + size_t size_in = (size_t) inputSizeBytes; + size_t size_out = SBC_BUFFER; + size_t len; + size_t framelen; + size_t xframe_pos = 0; + const guint8 *data_in = (const guint8 *) input; + guint8 *data_out = (guint8 *) output; + sbc_t *sbc = (sbc_t *) ctx; + guint8 *i_data; + guint8 tmp; + + if (!output || !outputSizeBytes) { + return size_out; + } + + sbc->endian = SBC_BE; + + *outputSizeBytes = 0; + while (xframe_pos < inputSizeBytes) { + framelen = sbc_decode(sbc, data_in, size_in, data_out, size_out, &len); + xframe_pos += framelen; + data_in += framelen; + *outputSizeBytes += len; + + for (i_data = data_out; i_data < data_out + len; i_data += 2) { + tmp = i_data[0]; + i_data[0] = i_data[1]; + i_data[1] = tmp; + } + + data_out += len; + } + + return *outputSizeBytes; +} + +void +codec_register_sbc(void) +{ + register_codec("SBC", codec_sbc_init, codec_sbc_release, + codec_sbc_get_channels, codec_sbc_get_frequency, codec_sbc_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: + */ |