diff options
author | Tomas Kukosa <tomas.kukosa@siemens.com> | 2007-12-03 09:59:18 +0000 |
---|---|---|
committer | Tomas Kukosa <tomas.kukosa@siemens.com> | 2007-12-03 09:59:18 +0000 |
commit | 4df43619aa5e750daad603bd374384f03cdac0c5 (patch) | |
tree | 9344e5aaec05e57d54c06d75283eafe84d719f7a /plugins/easy_codec/codec-g7231.c | |
parent | 395a5add850117138e666794772403bcb3ca4dbc (diff) | |
download | wireshark-4df43619aa5e750daad603bd374384f03cdac0c5.tar.gz |
Codec plugin example. The stub for ImTelephone libraries.
(It is not compiled by default.)
svn path=/trunk/; revision=23699
Diffstat (limited to 'plugins/easy_codec/codec-g7231.c')
-rw-r--r-- | plugins/easy_codec/codec-g7231.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/plugins/easy_codec/codec-g7231.c b/plugins/easy_codec/codec-g7231.c new file mode 100644 index 0000000000..b1b2b7e1ac --- /dev/null +++ b/plugins/easy_codec/codec-g7231.c @@ -0,0 +1,99 @@ +/* codec-g7231.c +* Easy codecs stub for EasyG7231 +* 2007 Ales Kocourek +* +* $Id$ +* +* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <glib.h> +#include <memory.h> + +#include "codec-g7231.h" + +#include "EasyG7231/EasyG7231.h" + +struct g7231_context { + CODER_HANDLE handle; + short speach_buffer[L_G7231_FRAME]; +}; + +void *codec_g7231_init(void) { + g7231_context *ctx = 0; + + ctx = (g7231_context*)g_malloc0(sizeof(g7231_context)); + ctx->handle = -1; + return ctx; +} + +void codec_g7231_release(void *context) { + g7231_context *ctx = (g7231_context*)context; + + if (!ctx) return; + EasyG7231_release_decoder(ctx->handle); + g_free(ctx); +} + +int codec_g7231_decode(void *context, const void *input, int inputSizeBytes, void *output, int *outputSizeBytes) { + g7231_context *ctx = (g7231_context*)context; + const unsigned char *bitstream = (const unsigned char*)input; + short *speech = (short*)output; + int decodedBytes = 0; + static int L_G7231_FRAME_COMPRESSED = 0; + + if (!ctx) return 0; + + if ( ctx->handle == -1) { + if ( bitstream[0] & 0x03 ) { + ctx->handle=EasyG7231_init_decoder(FALSE); + L_G7231_FRAME_COMPRESSED = L_G7231_FRAME_COMPRESSED_53; + } else { + ctx->handle=EasyG7231_init_decoder(TRUE); + L_G7231_FRAME_COMPRESSED = L_G7231_FRAME_COMPRESSED_63; + } + } + + if ((inputSizeBytes % L_G7231_FRAME_COMPRESSED) != 0) + return 0; + + if (!output) + return (inputSizeBytes / L_G7231_FRAME_COMPRESSED) * L_G7231_FRAME * sizeof(short); + + + while ((inputSizeBytes >= L_G7231_FRAME_COMPRESSED) && + ((*outputSizeBytes - decodedBytes) >= L_G7231_FRAME * sizeof(short))) { + if (EasyG7231_decoder(ctx->handle, (unsigned char*)bitstream, ctx->speach_buffer)) { + + memcpy(speech, ctx->speach_buffer, L_G7231_FRAME * sizeof(short)); + speech += L_G7231_FRAME; + decodedBytes += L_G7231_FRAME * sizeof(short); + + } + bitstream += L_G7231_FRAME_COMPRESSED; + inputSizeBytes -= L_G7231_FRAME_COMPRESSED; + } + + return decodedBytes; +} + |