blob: ec94670204d2921dd378e2645cb34c0b232ae8a3 [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
8/* Codec independent ECU state */
9struct osmo_ecu_fr_state {
10 bool subsequent_lost_frame;
11 uint8_t frame_backup[GSM_FR_BYTES];
12};
13
Harald Weltec144f3a2019-08-01 20:02:40 +020014void osmo_ecu_fr_reset(struct osmo_ecu_fr_state *state, const uint8_t *frame);
Philipp Maier40def492017-12-16 03:42:15 +070015int osmo_ecu_fr_conceal(struct osmo_ecu_fr_state *state, uint8_t *frame);
Harald Welte750d8312019-08-01 20:05:05 +020016
17enum osmo_ecu_codec {
18 OSMO_ECU_CODEC_HR,
19 OSMO_ECU_CODEC_FR,
20 OSMO_ECU_CODEC_EFR,
21 OSMO_ECU_CODEC_AMR,
22 _NUM_OSMO_ECU_CODECS
23};
24
25/***********************************************************************
26 * Generic ECU abstraction layer below
27 ***********************************************************************/
28
29/* As the developer and copyright holder of the related code, I hereby
30 * state that any ECU implementation using 'struct osmo_ecu_ops' and
31 * registering with the 'osmo_ecu_register()' function shall not be
32 * considered as a derivative work under any applicable copyright law;
33 * the copyleft terms of GPLv2 shall hence not apply to any such ECU
34 * implementation.
35 *
36 * The intent of the above exception is to allow anyone to combine third
37 * party Error Concealment Unit implementations with libosmocodec.
38 * including but not limited to such published by ETSI.
39 *
40 * -- Harald Welte <laforge@gnumonks.org> on August 1, 2019.
41 */
42
43struct 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);