aboutsummaryrefslogtreecommitdiffstats
path: root/src/codec_fr.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-05-28 10:20:54 +0200
committerHarald Welte <laforge@gnumonks.org>2017-05-28 10:44:06 +0200
commit5912848d2edbf61158ac7edc72c2302649a0d9ed (patch)
treede76a2a48b98730f5cb92af44410e47761d0e61d /src/codec_fr.c
parent62688b60c29225d557da8844d7259ce3eee962c5 (diff)
prepare gapk for dealing with variable-length frames
The existing architecture was modelled around fixed-length codec frame sizes, which of course fails with multi-rate codecs such as AMR.
Diffstat (limited to 'src/codec_fr.c')
-rw-r--r--src/codec_fr.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/codec_fr.c b/src/codec_fr.c
index 182eb73..2ce44b4 100644
--- a/src/codec_fr.c
+++ b/src/codec_fr.c
@@ -17,6 +17,8 @@
* along with gapk. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <assert.h>
+
#include <gapk/codecs.h>
#include <gapk/benchmark.h>
@@ -50,28 +52,32 @@ codec_fr_exit(void *state)
}
static int
-codec_fr_encode(void *state, uint8_t *cod, const uint8_t *pcm)
+codec_fr_encode(void *state, uint8_t *cod, const uint8_t *pcm, unsigned int pcm_len)
{
gsm gh = (gsm)state;
- uint8_t pcm_b[2*160]; /* local copy as libgsm src isn't const ! */
- memcpy(pcm_b, pcm, 2*160);
+ uint8_t pcm_b[PCM_CANON_LEN]; /* local copy as libgsm src isn't const ! */
+ assert(pcm_len == PCM_CANON_LEN);
+ memcpy(pcm_b, pcm, PCM_CANON_LEN);
BENCHMARK_START;
gsm_encode(gh, (gsm_signal*)pcm, (gsm_byte*)cod);
BENCHMARK_STOP(CODEC_FR, 1);
- return 0;
+ return FR_CANON_LEN;
}
static int
-codec_fr_decode(void *state, uint8_t *pcm, const uint8_t *cod)
+codec_fr_decode(void *state, uint8_t *pcm, const uint8_t *cod, unsigned int cod_len)
{
gsm gh = (gsm)state;
- uint8_t cod_b[33]; /* local copy as libgsm src isn't const ! */
+ uint8_t cod_b[FR_CANON_LEN]; /* local copy as libgsm src isn't const ! */
int rc;
- memcpy(cod_b, cod, 33);
+ assert(cod_len == FR_CANON_LEN);
+ memcpy(cod_b, cod, FR_CANON_LEN);
BENCHMARK_START;
rc = gsm_decode(gh, (gsm_byte*)cod_b, (gsm_signal*)pcm);
BENCHMARK_STOP(CODEC_FR, 1);
- return rc;
+ if (rc < 0)
+ return rc;
+ return PCM_CANON_LEN;
}
#endif /* HAVE_LIBGSM */