blob: 927ca0dae950361f3e7d64db072747d6dd47ca41 [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 Maier4e591b12019-09-16 13:22:58 +02008/* ECU state for GSM-FR */
Philipp Maier40def492017-12-16 03:42:15 +07009struct 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
Philipp Maier8bd05b52019-09-16 13:22:00 +020043/* Codec independent ECU state */
Harald Welte750d8312019-08-01 20:05:05 +020044struct osmo_ecu_state {
45 enum osmo_ecu_codec codec;
46 uint8_t data[0];
47};
48
49/* initialize an ECU instance */
50struct osmo_ecu_state *osmo_ecu_init(void *ctx, enum osmo_ecu_codec codec);
51
52/* destroy an ECU instance */
53void osmo_ecu_destroy(struct osmo_ecu_state *st);
54
55/* process a received frame a substitute/erroneous frame */
56int osmo_ecu_frame_in(struct osmo_ecu_state *st, bool bfi,
57 const uint8_t *frame, unsigned int frame_bytes);
58
59/* generate output data for a substitute/erroneous frame */
60int osmo_ecu_frame_out(struct osmo_ecu_state *st, uint8_t *frame_out);
61
62struct osmo_ecu_ops {
63 struct osmo_ecu_state * (*init)(void *ctx, enum osmo_ecu_codec codec);
64 void (*destroy)(struct osmo_ecu_state *);
65 int (*frame_in)(struct osmo_ecu_state *st, bool bfi,
66 const uint8_t *frame, unsigned int frame_bytes);
67 int (*frame_out)(struct osmo_ecu_state *st, uint8_t *frame_out);
68};
69
70int osmo_ecu_register(const struct osmo_ecu_ops *ops, enum osmo_ecu_codec codec);