2 * Easy codecs stub for EasyG7231
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include "codec-g7231.h"
35 #include "EasyG7231/EasyG7231.h"
37 struct g7231_context {
39 short speach_buffer[L_G7231_FRAME];
40 int l_g7231_frame_compressed;
43 void *codec_g7231_init(void) {
44 struct g7231_context *ctx = 0;
46 ctx = (struct g7231_context*)g_malloc0(sizeof(struct g7231_context));
51 void codec_g7231_release(void *context) {
52 struct g7231_context *ctx = (struct g7231_context*)context;
55 EasyG7231_release_decoder(ctx->handle);
59 int codec_g7231_decode(void *context, const void *input, int inputSizeBytes, void *output, int *outputSizeBytes) {
60 struct g7231_context *ctx = (struct g7231_context*)context;
61 const unsigned char *bitstream = (const unsigned char*)input;
62 short *speech = (short*)output;
67 if ( ctx->handle == -1) {
68 if ( bitstream[0] & 0x03 ) {
69 ctx->handle=EasyG7231_init_decoder(FALSE);
70 ctx->l_g7231_frame_compressed = L_G7231_FRAME_COMPRESSED_53;
72 ctx->handle=EasyG7231_init_decoder(TRUE);
73 ctx->l_g7231_frame_compressed = L_G7231_FRAME_COMPRESSED_63;
77 if ((inputSizeBytes % ctx->l_g7231_frame_compressed) != 0)
81 return (inputSizeBytes / ctx->l_g7231_frame_compressed) * L_G7231_FRAME * sizeof(short);
84 while ((inputSizeBytes >= ctx->l_g7231_frame_compressed) &&
85 ((*outputSizeBytes - decodedBytes) >= L_G7231_FRAME * sizeof(short))) {
86 if (EasyG7231_decoder(ctx->handle, (unsigned char*)bitstream, ctx->speach_buffer)) {
88 memcpy(speech, ctx->speach_buffer, L_G7231_FRAME * sizeof(short));
89 speech += L_G7231_FRAME;
90 decodedBytes += L_G7231_FRAME * sizeof(short);
93 bitstream += ctx->l_g7231_frame_compressed;
94 inputSizeBytes -= ctx->l_g7231_frame_compressed;