Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / plugins / codecs / G722 / G722decode.c
blob30c461070e6547ace69b054bc7e0cdc7108da5dc
1 /* G722decode.c
2 * G.722 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 <glib.h>
15 #include "spandsp.h"
16 #include "wsutil/codecs.h"
17 #include "ws_attributes.h"
19 void codec_register_g722(void);
21 static void *
22 codec_g722_init(codec_context_t *ctx _U_)
24 g722_decode_state_t *state;
26 /* Valid values for bit_rate for G.722 are 48000, 56000, 64000, but RTP/AVP
27 * profile requires 64kbps, aligned at octets. */
28 state = g722_decode_init(NULL, 64000, 0);
30 return state;
33 static void
34 codec_g722_release(codec_context_t *ctx)
36 g722_decode_state_t *state = (g722_decode_state_t *)ctx->priv;
38 if (!state) {
39 return; /* out-of-memory; */
42 /* Note: replaces g722_decode_release since SpanDSP 20090211 */
43 g722_decode_free(state);
46 static unsigned
47 codec_g722_get_channels(codec_context_t *ctx _U_)
49 /* G.722 has only one channel. */
50 return 1;
53 static unsigned
54 codec_g722_get_frequency(codec_context_t *ctx _U_)
56 /* Note: RTP Clock rate is 8kHz due to a historic error, but actual sampling
57 * rate is 16kHz (RFC 3551, section 4.5.2). */
58 return 16000;
61 static size_t
62 codec_g722_decode(codec_context_t *ctx, const void *inputBytes,
63 size_t inputBytesSize, void *outputSamples, size_t *outputSamplesSize)
65 g722_decode_state_t *state = (g722_decode_state_t *)ctx->priv;
67 if (!state) {
68 return 0; /* out-of-memory; */
71 if (!outputSamples || !outputSamplesSize) {
72 return 4 * inputBytesSize;
75 /* g722_decode returns the number of 16-bit samples. */
76 *outputSamplesSize = 2 * g722_decode(state, (int16_t *)outputSamples,
77 (const uint8_t *)inputBytes, (int)inputBytesSize);
78 return *outputSamplesSize;
81 void
82 codec_register_g722(void)
84 register_codec("g722", codec_g722_init, codec_g722_release,
85 codec_g722_get_channels, codec_g722_get_frequency, codec_g722_decode);
89 * Editor modelines - https://www.wireshark.org/tools/modelines.html
91 * Local variables:
92 * c-basic-offset: 4
93 * tab-width: 8
94 * indent-tabs-mode: nil
95 * End:
97 * vi: set shiftwidth=4 tabstop=8 expandtab:
98 * :indentSize=4:tabSize=8:noTabs=true: