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
18 #include "wsutil/codecs.h"
19 #include "ws_attributes.h"
23 #define ILBC_PAYLOAD_LEN_20MS 38
24 #define ILBC_PAYLOAD_LEN_30MS 50
28 #ifdef LIBILBC_VERSION_MAJOR
29 IlbcDecoderInstance
*ilbc_ctx
; /* Real iLBC context */
31 iLBC_decinst_t
*ilbc_ctx
; /* Real iLBC context */
33 uint8_t payload_len
; /* Remember last payload_len */
36 void codec_register_iLBC(void);
39 codec_iLBC_init(codec_context_t
*ctx _U_
)
43 priv
=(ilbc_ctx_t
*)g_malloc0(sizeof(*priv
));
44 WebRtcIlbcfix_DecoderCreate(&(priv
->ilbc_ctx
));
50 codec_iLBC_release(codec_context_t
*ctx
)
52 WebRtcIlbcfix_DecoderFree(((ilbc_ctx_t
*)ctx
->priv
)->ilbc_ctx
);
57 codec_iLBC_get_channels(codec_context_t
*ctx _U_
)
63 codec_iLBC_get_frequency(codec_context_t
*ctx _U_
)
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
;
77 int16_t *dataIn
= (int16_t *)inputBytes
;
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
;
92 /* unknown packet size */
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
);
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
;
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
136 * indent-tabs-mode: nil
139 * vi: set shiftwidth=4 tabstop=8 expandtab:
140 * :indentSize=4:tabSize=8:noTabs=true: