blob: f3b34c978787dce4c68fb9fa81a948a89638206d [file] [log] [blame]
Philipp Maier40def492017-12-16 03:42:15 +07001#pragma once
2
3#include <stdint.h>
4#include <stdbool.h>
5
6#include <osmocom/codec/codec.h>
7
Philipp Maier40def492017-12-16 03:42:15 +07008struct osmo_ecu_fr_state {
9 bool subsequent_lost_frame;
10 uint8_t frame_backup[GSM_FR_BYTES];
11};
12
Harald Weltec144f3a2019-08-01 20:02:40 +020013void osmo_ecu_fr_reset(struct osmo_ecu_fr_state *state, const uint8_t *frame);
Philipp Maier40def492017-12-16 03:42:15 +070014int osmo_ecu_fr_conceal(struct osmo_ecu_fr_state *state, uint8_t *frame);
Harald Welte750d8312019-08-01 20:05:05 +020015
16enum osmo_ecu_codec {
17 OSMO_ECU_CODEC_HR,
18 OSMO_ECU_CODEC_FR,
19 OSMO_ECU_CODEC_EFR,
20 OSMO_ECU_CODEC_AMR,
21 _NUM_OSMO_ECU_CODECS
22};
23
24/***********************************************************************
25 * Generic ECU abstraction layer below
26 ***********************************************************************/
27
28/* As the developer and copyright holder of the related code, I hereby
29 * state that any ECU implementation using 'struct osmo_ecu_ops' and
30 * registering with the 'osmo_ecu_register()' function shall not be
31 * considered as a derivative work under any applicable copyright law;
32 * the copyleft terms of GPLv2 shall hence not apply to any such ECU
33 * implementation.
34 *
35 * The intent of the above exception is to allow anyone to combine third
36 * party Error Concealment Unit implementations with libosmocodec.
37 * including but not limited to such published by ETSI.
38 *
39 * -- Harald Welte <laforge@gnumonks.org> on August 1, 2019.
40 */
41
Philipp Maier8bd05b52019-09-16 13:22:00 +020042/* Codec independent ECU state */
Harald Welte750d8312019-08-01 20:05:05 +020043struct osmo_ecu_state {
44 enum osmo_ecu_codec codec;
45 uint8_t data[0];
46};
47
48/* initialize an ECU instance */
49struct osmo_ecu_state *osmo_ecu_init(void *ctx, enum osmo_ecu_codec codec);
50
51/* destroy an ECU instance */
52void osmo_ecu_destroy(struct osmo_ecu_state *st);
53
54/* process a received frame a substitute/erroneous frame */
55int osmo_ecu_frame_in(struct osmo_ecu_state *st, bool bfi,
56 const uint8_t *frame, unsigned int frame_bytes);
57
58/* generate output data for a substitute/erroneous frame */
59int osmo_ecu_frame_out(struct osmo_ecu_state *st, uint8_t *frame_out);
60
61struct osmo_ecu_ops {
62 struct osmo_ecu_state * (*init)(void *ctx, enum osmo_ecu_codec codec);
63 void (*destroy)(struct osmo_ecu_state *);
64 int (*frame_in)(struct osmo_ecu_state *st, bool bfi,
65 const uint8_t *frame, unsigned int frame_bytes);
66 int (*frame_out)(struct osmo_ecu_state *st, uint8_t *frame_out);
67};
68
69int osmo_ecu_register(const struct osmo_ecu_ops *ops, enum osmo_ecu_codec codec);