From d1e4422a4abc3667351286b13a4224fda65ba26b Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Sat, 30 Nov 2013 15:42:14 +0000 Subject: Add G.722, G.726 and SBC codecs. G.722 and G.726 are from bug 5619 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=5619) and SBC is from bug 7893 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7893). Codecs are added, but (intentionally) not hooked to the RTP player as a "more generic architecture" is desired. There are some discussions in bug 7893 on how to do this. One thing to add would be how to handle codecs that may not be supported on all platforms. Should the codec not be "registered" at all (with a #define over the whole module) or should it's register functions be stubbed (with a #define in each function that requires a non-supported library) svn path=/trunk/; revision=53676 --- codecs/CMakeLists.txt | 3 ++ codecs/G722/G722decode.c | 53 ++++++++++++++++++ codecs/G722/G722decode.h | 34 ++++++++++++ codecs/G726/G726decode.c | 59 ++++++++++++++++++++ codecs/G726/G726decode.h | 34 ++++++++++++ codecs/Makefile.am | 10 +++- codecs/Makefile.nmake | 19 ++++++- codecs/SBC/sbc.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++ codecs/SBC/sbc.h | 37 +++++++++++++ 9 files changed, 381 insertions(+), 4 deletions(-) create mode 100644 codecs/G722/G722decode.c create mode 100644 codecs/G722/G722decode.h create mode 100644 codecs/G726/G726decode.c create mode 100644 codecs/G726/G726decode.h create mode 100644 codecs/SBC/sbc.c create mode 100644 codecs/SBC/sbc.h (limited to 'codecs') diff --git a/codecs/CMakeLists.txt b/codecs/CMakeLists.txt index 8c7c39e877..723d891510 100644 --- a/codecs/CMakeLists.txt +++ b/codecs/CMakeLists.txt @@ -24,6 +24,9 @@ set(CODECS_FILES G711a/G711adecode.c G711u/G711udecode.c + G722/G722decode.c + G726/G726decode.c + SBC/SBC.c ) add_library(codecs STATIC diff --git a/codecs/G722/G722decode.c b/codecs/G722/G722decode.c new file mode 100644 index 0000000000..2286bd0a61 --- /dev/null +++ b/codecs/G722/G722decode.c @@ -0,0 +1,53 @@ +/* G722decode.c + * A-law G.711 codec + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +#ifdef HAVE_SPANDSP +#include "telephony.h" +#include "g722.h" +#endif +#include "G722decode.h" + +#ifdef HAVE_SPANDSP +static g722_decode_state_t state; +#endif + +void +initG722(void) +{ +#ifdef HAVE_SPANDSP + memset (&state, 0, sizeof (state)); + g722_decode_init(&state, 64000, 0); +#endif +} + +int +decodeG722(void *input, int inputSizeBytes, void *output, int *outputSizeBytes) +{ +#ifdef HAVE_SPANDSP + *outputSizeBytes = g722_decode(&state, output, input, inputSizeBytes); +#endif + return 0; +} diff --git a/codecs/G722/G722decode.h b/codecs/G722/G722decode.h new file mode 100644 index 0000000000..a1ec060dc0 --- /dev/null +++ b/codecs/G722/G722decode.h @@ -0,0 +1,34 @@ +/* G722decode.h + * Definitions for A-law G.722 codec + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __CODECS_G722DECODE_H__ +#define __CODECS_G722DECODE_H__ + +void +initG722(void); + +int +decodeG722(void *input, int inputSizeBytes, void *output, int *outputSizeBytes); + +#endif /* G722decode.h */ diff --git a/codecs/G726/G726decode.c b/codecs/G726/G726decode.c new file mode 100644 index 0000000000..d97e386272 --- /dev/null +++ b/codecs/G726/G726decode.c @@ -0,0 +1,59 @@ +/* G726decode.c + * G.726 codec + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#ifdef HAVE_SPANDSP +#include "telephony.h" +#include "bitstream.h" +#include "g726.h" +#endif +#include "G726decode.h" + +#ifdef HAVE_SPANDSP +/* this isn't reentrant. Making it might involve quite a few changes to be able to pass a g726 state + * variable to the various functions involved in G.726 decoding. + */ +static g726_state_t state; +#endif + +/* Currently, only G.726-32, linear encoding, left packed is supported */ +void initG726_32(void) +{ +#ifdef HAVE_SPANDSP + memset (&state, 0, sizeof (state)); + g726_init(&state, 32000, 0, 1); +#endif +} + +/* Packing should be user defined (via the decode dialog) since due to historical reasons two diverging + * de facto standards are in use today (see RFC3551). + */ +int +decodeG726_32(void *input, int inputSizeBytes, void *output, int *outputSizeBytes) +{ +#ifdef HAVE_SPANDSP + *outputSizeBytes = 2 * g726_decode(&state, output, (void*) input, inputSizeBytes); +#endif + return 0; +} diff --git a/codecs/G726/G726decode.h b/codecs/G726/G726decode.h new file mode 100644 index 0000000000..4c139d008b --- /dev/null +++ b/codecs/G726/G726decode.h @@ -0,0 +1,34 @@ +/* G726decode.h + * Definitions for A-law G.722 codec + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __CODECS_G726DECODE_H__ +#define __CODECS_G726DECODE_H__ + +void +initG726_32(void); + +int +decodeG726_32(void *input, int inputSizeBytes, void *output, int *outputSizeBytes); + +#endif /* G726decode.h */ diff --git a/codecs/Makefile.am b/codecs/Makefile.am index cdf1df4fa7..9d036e982e 100644 --- a/codecs/Makefile.am +++ b/codecs/Makefile.am @@ -36,7 +36,10 @@ MAINTAINERCLEANFILES = \ libcodec_a_SOURCES = \ G711a/G711adecode.c G711a/G711adecode.h G711a/G711atable.h \ - G711u/G711udecode.c G711u/G711udecode.h G711u/G711utable.h + G711u/G711udecode.c G711u/G711udecode.h G711u/G711utable.h \ + G722/G722decode.c G722/G722decode.h \ + G726/G726decode.c G726/G726decode.h \ + SBC/SBC.c SBC/SBC.h libcodec_a_DEPENDENCIES = @@ -47,4 +50,7 @@ EXTRA_DIST = \ checkapi: $(PERL) ../tools/checkAPIs.pl -g abort -g termoutput -build \ G711a/G711adecode.c \ - G711u/G711udecode.c + G711u/G711udecode.c \ + G722/G722decode.c \ + G726/G726decode.c \ + SBC/SBC.c diff --git a/codecs/Makefile.nmake b/codecs/Makefile.nmake index 65158720cc..f335a48e5c 100644 --- a/codecs/Makefile.nmake +++ b/codecs/Makefile.nmake @@ -15,7 +15,10 @@ CFLAGS=$(WARNINGS_ARE_ERRORS) $(STANDARD_CFLAGS) \ CODEC_OBJECTS= \ G711udecode.obj \ - G711adecode.obj + G711adecode.obj \ + G722decode.obj \ + G726decode.obj \ + SBC.obj codecs.lib : $(CODEC_OBJECTS) @@ -28,6 +31,15 @@ G711adecode.obj: G711a\G711adecode.c G711a\G711adecode.h G711a\G711atable.h G711udecode.obj: G711u\G711udecode.c G711u\G711udecode.h G711u\G711utable.h $(CC) $(CFLAGS) -Fd.\ -c G711u\G711udecode.c /Fo%|fF.obj +G722decode.obj: G722\G722decode.c G722\G722decode.h + $(CC) $(CFLAGS) -Fd.\ -c G722\G722decode.c /Fo%|fF.obj + +G726decode.obj: G726\G726decode.c G726\G726decode.h + $(CC) $(CFLAGS) -Fd.\ -c G726\G726decode.c /Fo%|fF.obj + +SBC.obj: SBC\SBC.c SBC\SBC.h + $(CC) $(CFLAGS) -Fd.\ -c SBC\SBC.c /Fo%|fF.obj + clean: rm -f $(CODEC_OBJECTS) codecs.lib *.pdb *.sbr @@ -38,4 +50,7 @@ maintainer-clean: distclean checkapi: $(PERL) ../tools/checkAPIs.pl -g abort -g termoutput -build \ G711a/G711adecode.c \ - G711u/G711udecode.c + G711u/G711udecode.c \ + G722/G722decode.c \ + G726/G726decode.c \ + SBC/SBC.c diff --git a/codecs/SBC/sbc.c b/codecs/SBC/sbc.c new file mode 100644 index 0000000000..43954ff751 --- /dev/null +++ b/codecs/SBC/sbc.c @@ -0,0 +1,136 @@ +/* sbc.c + * Support for external Bluetooth SBC codec + * + * Copyright 2012, Michal Labedzki for Tieto Corporation + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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. + */ + +#ifdef HAVE_SBC + +#include +#include + +#include "sbc.h" + +#define SBC_BUFFER 8192 + +void * +codec_sbc_init(void) +{ + sbc_t *sbc; + + sbc = g_malloc(sizeof(sbc_t)); + sbc_init(sbc, 0L); + + return sbc; +} + +void +codec_sbc_release(void *ctx) +{ + sbc_t *sbc = (sbc_t *) ctx; + + sbc_finish(sbc); + g_free(sbc); +} + +int +codec_sbc_get_channels(void *ctx) +{ + sbc_t *sbc = (sbc_t *) ctx; + if (sbc->mode == SBC_MODE_MONO) + return 1; + + return 2; +} + +int +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; +} + +int +codec_sbc_decode(void *ctx, const void *input, int inputSizeBytes, void *output, + int *outputSizeBytes) +{ + size_t size_in = (size_t) inputSizeBytes; + size_t size_out = SBC_BUFFER; + size_t len; + int framelen; + int xframe_pos = 0; + guint8 *data_in = (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; + + framelen = 0; + *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; +} + +#endif diff --git a/codecs/SBC/sbc.h b/codecs/SBC/sbc.h new file mode 100644 index 0000000000..5cc8ad0927 --- /dev/null +++ b/codecs/SBC/sbc.h @@ -0,0 +1,37 @@ +/* sbc.h + * Definitions for Bluetooth SBC codec + * + * Copyright 2012, Michal Labedzki for Tieto Corporation + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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_SBC_H__ +#define __CODECS_SBC_H__ + +void *codec_sbc_init(void); +void codec_sbc_release(void *ctx); +int codec_sbc_get_channels(void *ctx); +int codec_sbc_get_frequency(void *ctx); +int codec_sbc_decode(void *ctx, const void *input, int inputSizeBytes, void *output, + int *outputSizeBytes); + +#endif /* sbc.h */ -- cgit v1.2.3