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
16 #include "wsutil/codecs.h"
17 #include "ws_attributes.h"
19 typedef struct _g726_codec_ctx
{
24 void codec_register_g726(void);
27 codec_g726_init(int bit_rate
, int packing
)
29 g726_state_t
*decoder
= g726_init(NULL
, bit_rate
, G726_ENCODING_LINEAR
, packing
);
32 return NULL
; /* out-of-memory; */
35 g726_codec_ctx
*state
= g_new(g726_codec_ctx
, 1);
36 state
->state
= decoder
;
37 state
->bit_rate
= bit_rate
;
42 static void *codec_g726_16_init(codec_context_t
*ctx _U_
) { return codec_g726_init(16000, G726_PACKING_RIGHT
); }
43 static void *codec_g726_24_init(codec_context_t
*ctx _U_
) { return codec_g726_init(24000, G726_PACKING_RIGHT
); }
44 static void *codec_g726_32_init(codec_context_t
*ctx _U_
) { return codec_g726_init(32000, G726_PACKING_RIGHT
); }
45 static void *codec_g726_40_init(codec_context_t
*ctx _U_
) { return codec_g726_init(40000, G726_PACKING_RIGHT
); }
46 static void *codec_aal2_g726_16_init(codec_context_t
*ctx _U_
) { return codec_g726_init(16000, G726_PACKING_LEFT
); }
47 static void *codec_aal2_g726_24_init(codec_context_t
*ctx _U_
) { return codec_g726_init(24000, G726_PACKING_LEFT
); }
48 static void *codec_aal2_g726_32_init(codec_context_t
*ctx _U_
) { return codec_g726_init(32000, G726_PACKING_LEFT
); }
49 static void *codec_aal2_g726_40_init(codec_context_t
*ctx _U_
) { return codec_g726_init(40000, G726_PACKING_LEFT
); }
52 codec_g726_release(codec_context_t
*ctx
)
54 g726_codec_ctx
*state
= (g726_codec_ctx
*)(ctx
->priv
);
57 return; /* out-of-memory; */
60 /* Note: replaces g726_release since SpanDSP 20090211 */
61 g726_free(state
->state
);
66 codec_g726_get_channels(codec_context_t
*ctx _U_
)
72 codec_g726_get_frequency(codec_context_t
*ctx _U_
)
78 codec_g726_decode(codec_context_t
*ctx
, const void *inputBytes
,
79 size_t inputBytesSize
, void *outputSamples
, size_t *outputSamplesSize
)
81 g726_codec_ctx
*state
= (g726_codec_ctx
*)ctx
->priv
;
84 return 0; /* out-of-memory; */
87 if (!outputSamples
|| !outputSamplesSize
) {
89 * sample rate 8kHz, for bitrate 16kHz we have 16/8 = 2 bits/sample, so
90 * 1 input byte (8 bits) will expand to four 16-bit samples. Likewise,
91 * for bitrate 40kHz we have 40/8 = 5 bits/sample. Alternatively:
92 * bitsPerSample = bitRate / sampleRate (8kHz).
93 * outputBytes = (inputBits / bitsPerSample) * sizeof(sample)
95 return inputBytesSize
* 8 / (state
->bit_rate
/ 8000) * 2;
98 /* g726_decode returns the number of 16-bit samples. */
99 *outputSamplesSize
= 2 * g726_decode(state
->state
, (int16_t *)outputSamples
, (const uint8_t *) inputBytes
, (int)inputBytesSize
);
100 return *outputSamplesSize
;
104 codec_register_g726(void)
106 register_codec("G726-16", codec_g726_16_init
, codec_g726_release
,
107 codec_g726_get_channels
, codec_g726_get_frequency
, codec_g726_decode
);
108 register_codec("G726-24", codec_g726_24_init
, codec_g726_release
,
109 codec_g726_get_channels
, codec_g726_get_frequency
, codec_g726_decode
);
110 register_codec("G726-32", codec_g726_32_init
, codec_g726_release
,
111 codec_g726_get_channels
, codec_g726_get_frequency
, codec_g726_decode
);
112 register_codec("G726-40", codec_g726_40_init
, codec_g726_release
,
113 codec_g726_get_channels
, codec_g726_get_frequency
, codec_g726_decode
);
114 register_codec("AAL2-G726-16", codec_aal2_g726_16_init
, codec_g726_release
,
115 codec_g726_get_channels
, codec_g726_get_frequency
, codec_g726_decode
);
116 register_codec("AAL2-G726-24", codec_aal2_g726_24_init
, codec_g726_release
,
117 codec_g726_get_channels
, codec_g726_get_frequency
, codec_g726_decode
);
118 register_codec("AAL2-G726-32", codec_aal2_g726_32_init
, codec_g726_release
,
119 codec_g726_get_channels
, codec_g726_get_frequency
, codec_g726_decode
);
120 register_codec("AAL2-G726-40", codec_aal2_g726_40_init
, codec_g726_release
,
121 codec_g726_get_channels
, codec_g726_get_frequency
, codec_g726_decode
);
125 * Editor modelines - https://www.wireshark.org/tools/modelines.html
130 * indent-tabs-mode: nil
133 * vi: set shiftwidth=4 tabstop=8 expandtab:
134 * :indentSize=4:tabSize=8:noTabs=true: