diff options
author | Peter Wu <peter@lekensteyn.nl> | 2016-11-24 00:27:14 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2016-12-06 17:51:47 +0000 |
commit | f5e22a14877922aa7b907d2e434958c86efd6875 (patch) | |
tree | 33439d1a8cd3322faa9ce8b0f6b12a08427d47fb /codecs/G722 | |
parent | d8cdb550445a1bc86626bd9d45da1ce958d1592b (diff) |
codecs: Add support for G.722 and G.726
Integrate the Spandsp library for G.722 and G.726 support. Adds support
for G.722 and all eight variants of G.726.
Note: this also fixes a crash in Qt (buffer overrun, reading too much
data) caused by confusion of the larger output buffer (resample_buff)
with the smaller input buffer (decode_buff). It was not triggered before
because the sample rate was always 8k, but with the addition of the new
codecs, a different sample rate became possible (16k).
Fix also a crash which occurs when the RTP_STREAM_DEBUG macro is enabled
and the VOIP Calls dialog is opened (the begin frame, start_fd, is not
yet known and therfore a NULL dereference could occur).
Passes testing (plays normally without bad RTP timing errors) with
SampleCaptures files: sip-rtp-g722.pcap and sip-rtp-g726.pcap. Tested
with cmake (Qt), autotools (Qt and GTK+) with ASAN enabled.
Bug: 5619
Change-Id: I5661908d193927bba50901079119eeff0c04991f
Reviewed-on: https://code.wireshark.org/review/18939
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'codecs/G722')
-rw-r--r-- | codecs/G722/G722decode.c | 55 | ||||
-rw-r--r-- | codecs/G722/G722decode.h | 10 |
2 files changed, 43 insertions, 22 deletions
diff --git a/codecs/G722/G722decode.c b/codecs/G722/G722decode.c index af45520d08..fae16c0626 100644 --- a/codecs/G722/G722decode.c +++ b/codecs/G722/G722decode.c @@ -1,5 +1,5 @@ /* G722decode.c - * A-law G.711 codec + * G.722 codec * * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> @@ -25,45 +25,66 @@ #include <glib.h> #ifdef HAVE_SPANDSP -#include "telephony.h" -#include "g722.h" +#include "spandsp.h" #include "G722decode.h" -static g722_decode_state_t state; - void * codec_g722_init(void) { - memset (&state, 0, sizeof (state)); - g722_decode_init(&state, 64000, 0); + g722_decode_state_t *state; + + /* Valid values for bit_rate for G.722 are 48000, 56000, 64000, but RTP/AVP + * profile requires 64kbps, aligned at octets. */ + state = g722_decode_init(NULL, 64000, 0); - return NULL; + return state; } void -codec_g722_release(void *ctx _U_) +codec_g722_release(void *ctx) { + g722_decode_state_t *state = (g722_decode_state_t *)ctx; + + if (!state) { + return; /* out-of-memory; */ + } + /* Note: replaces g722_decode_release since spandsp 20090211 */ + g722_decode_free(state); } -int +unsigned codec_g722_get_channels(void *ctx _U_) { + /* G.722 has only one channel. */ return 1; } -int +unsigned codec_g722_get_frequency(void *ctx _U_) { - return 64000; + /* Note: RTP Clock rate is 8kHz due to a historic error, but actual sampling + * rate is 16kHz (RFC 3551, section 4.5.2). */ + return 16000; } -int -codec_g722_decode(void *ctx _U_, const void *input, int inputSizeBytes, void *output, - int *outputSizeBytes) +size_t +codec_g722_decode(void *ctx, const void *input, size_t inputSizeBytes, void *output, + size_t *outputSizeBytes) { - *outputSizeBytes = g722_decode(&state, output, input, inputSizeBytes); - return 0; + g722_decode_state_t *state = (g722_decode_state_t *)ctx; + + if (!state) { + return 0; /* out-of-memory; */ + } + + if (!output || !outputSizeBytes) { + return 4 * inputSizeBytes; + } + + /* g722_decode returns the number of 16-bit samples. */ + *outputSizeBytes = 2 * g722_decode(state, (int16_t *)output, (const uint8_t *)input, (int)inputSizeBytes); + return *outputSizeBytes; } #endif diff --git a/codecs/G722/G722decode.h b/codecs/G722/G722decode.h index fa30a092c0..46502632a7 100644 --- a/codecs/G722/G722decode.h +++ b/codecs/G722/G722decode.h @@ -1,5 +1,5 @@ /* G722decode.h - * Definitions for A-law G.722 codec + * Definitions for G.722 codec * * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> @@ -25,10 +25,10 @@ void *codec_g722_init(void); void codec_g722_release(void *ctx); -int codec_g722_get_channels(void *ctx); -int codec_g722_get_frequency(void *ctx); -int codec_g722_decode(void *ctx, const void *input, int inputSizeBytes, void *output, - int *outputSizeBytes); +unsigned codec_g722_get_channels(void *ctx); +unsigned codec_g722_get_frequency(void *ctx); +size_t codec_g722_decode(void *ctx, const void *input, size_t inputSizeBytes, void *output, + size_t *outputSizeBytes); #endif /* G722decode.h */ |