Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / plugins / codecs / iLBC / iLBCdecode.c
blobf551e2e5618633741829df7eec00e62288d155d8
1 /* iLBCdecode.c
2 * iLBC codec
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #include "config.h"
13 #include <stdio.h>
15 #include <glib.h>
17 #include "ilbc.h"
18 #include "wsutil/codecs.h"
19 #include "ws_attributes.h"
21 #define ILBC_20MS 20
22 #define ILBC_30MS 30
23 #define ILBC_PAYLOAD_LEN_20MS 38
24 #define ILBC_PAYLOAD_LEN_30MS 50
25 #define SAMPLE_SIZE 2
27 typedef struct {
28 #ifdef LIBILBC_VERSION_MAJOR
29 IlbcDecoderInstance *ilbc_ctx; /* Real iLBC context */
30 #else
31 iLBC_decinst_t *ilbc_ctx; /* Real iLBC context */
32 #endif
33 uint8_t payload_len; /* Remember last payload_len */
34 } ilbc_ctx_t;
36 void codec_register_iLBC(void);
38 static void *
39 codec_iLBC_init(codec_context_t *ctx _U_)
41 ilbc_ctx_t *priv;
43 priv=(ilbc_ctx_t *)g_malloc0(sizeof(*priv));
44 WebRtcIlbcfix_DecoderCreate(&(priv->ilbc_ctx));
46 return priv;
49 static void
50 codec_iLBC_release(codec_context_t *ctx)
52 WebRtcIlbcfix_DecoderFree(((ilbc_ctx_t *)ctx->priv)->ilbc_ctx);
53 g_free(ctx);
56 static unsigned
57 codec_iLBC_get_channels(codec_context_t *ctx _U_)
59 return 1;
62 static unsigned
63 codec_iLBC_get_frequency(codec_context_t *ctx _U_)
65 return 8000;
68 static size_t
69 codec_iLBC_decode(codec_context_t *ctx,
70 const void *inputBytes, size_t inputBytesSize,
71 void *outputSamples, size_t *outputSamplesSize)
73 int16_t speechType; // Not used in Wireshark code
74 #ifdef LIBILBC_VERSION_MAJOR
75 int8_t *dataIn = (int8_t *)inputBytes;
76 #else
77 int16_t *dataIn = (int16_t *)inputBytes;
78 #endif
79 int16_t *dataOut = (int16_t *)outputSamples;
80 ilbc_ctx_t *dataCtx = (ilbc_ctx_t *)ctx->priv;
81 size_t outputSamplesCount;
83 if (!outputSamples || !outputSamplesSize)
85 if (0 == inputBytesSize%ILBC_PAYLOAD_LEN_20MS) {
86 /* 20ms packet size = 160 samples = 320 bytes */
87 return BLOCKL_20MS*SAMPLE_SIZE;
88 } else if (0 == inputBytesSize%ILBC_PAYLOAD_LEN_30MS) {
89 /* 30ms packet size = 240 samples = 480 bytes */
90 return BLOCKL_30MS*SAMPLE_SIZE;
91 } else {
92 /* unknown packet size */
93 return 0;
97 if (0 == inputBytesSize%ILBC_PAYLOAD_LEN_20MS) {
98 /* 20ms packet size */
99 if (dataCtx->payload_len != ILBC_20MS) {
100 WebRtcIlbcfix_DecoderInit(dataCtx->ilbc_ctx, ILBC_20MS);
101 dataCtx->payload_len = ILBC_20MS;
103 outputSamplesCount = WebRtcIlbcfix_Decode(dataCtx->ilbc_ctx, dataIn,
104 (int16_t)inputBytesSize, dataOut, &speechType);
105 } else if (0 == inputBytesSize%ILBC_PAYLOAD_LEN_30MS) {
106 /* 30ms packet size */
107 if (dataCtx->payload_len != ILBC_30MS) {
108 WebRtcIlbcfix_DecoderInit(dataCtx->ilbc_ctx, ILBC_30MS);
109 dataCtx->payload_len = ILBC_30MS;
111 outputSamplesCount = WebRtcIlbcfix_Decode(dataCtx->ilbc_ctx, dataIn,
112 (int16_t)inputBytesSize, dataOut, &speechType);
113 } else {
114 /* unknown packet size */
115 outputSamplesCount = 0;
118 /* WebRtcIlbcfix_Decode returns count of samples, but we return count of bytes */
119 *outputSamplesSize = outputSamplesCount*SAMPLE_SIZE;
120 return *outputSamplesSize;
123 void
124 codec_register_iLBC(void)
126 register_codec("iLBC", codec_iLBC_init, codec_iLBC_release,
127 codec_iLBC_get_channels, codec_iLBC_get_frequency, codec_iLBC_decode);
131 * Editor modelines - https://www.wireshark.org/tools/modelines.html
133 * Local variables:
134 * c-basic-offset: 4
135 * tab-width: 8
136 * indent-tabs-mode: nil
137 * End:
139 * vi: set shiftwidth=4 tabstop=8 expandtab:
140 * :indentSize=4:tabSize=8:noTabs=true: