blob: 99b1430f8d896c7d06db7516307538201723c024 [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
Philipp Maierae140bc2019-09-19 10:34:11 +020014void osmo_ecu_fr_reset(struct osmo_ecu_fr_state *state, const uint8_t *frame)
15 OSMO_DEPRECATED("Use generic ECU abstraction layer instead");
16int osmo_ecu_fr_conceal(struct osmo_ecu_fr_state *state, uint8_t *frame)
17 OSMO_DEPRECATED("Use generic ECU abstraction layer instead");
Harald Welte750d8312019-08-01 20:05:05 +020018
19enum osmo_ecu_codec {
20 OSMO_ECU_CODEC_HR,
21 OSMO_ECU_CODEC_FR,
22 OSMO_ECU_CODEC_EFR,
23 OSMO_ECU_CODEC_AMR,
24 _NUM_OSMO_ECU_CODECS
25};
26
27/***********************************************************************
28 * Generic ECU abstraction layer below
29 ***********************************************************************/
30
31/* As the developer and copyright holder of the related code, I hereby
32 * state that any ECU implementation using 'struct osmo_ecu_ops' and
33 * registering with the 'osmo_ecu_register()' function shall not be
34 * considered as a derivative work under any applicable copyright law;
35 * the copyleft terms of GPLv2 shall hence not apply to any such ECU
36 * implementation.
37 *
38 * The intent of the above exception is to allow anyone to combine third
39 * party Error Concealment Unit implementations with libosmocodec.
40 * including but not limited to such published by ETSI.
41 *
42 * -- Harald Welte <laforge@gnumonks.org> on August 1, 2019.
43 */
44
Philipp Maier8bd05b52019-09-16 13:22:00 +020045/* Codec independent ECU state */
Harald Welte750d8312019-08-01 20:05:05 +020046struct osmo_ecu_state {
47 enum osmo_ecu_codec codec;
48 uint8_t data[0];
49};
50
51/* initialize an ECU instance */
52struct osmo_ecu_state *osmo_ecu_init(void *ctx, enum osmo_ecu_codec codec);
53
54/* destroy an ECU instance */
55void osmo_ecu_destroy(struct osmo_ecu_state *st);
56
57/* process a received frame a substitute/erroneous frame */
58int osmo_ecu_frame_in(struct osmo_ecu_state *st, bool bfi,
59 const uint8_t *frame, unsigned int frame_bytes);
60
61/* generate output data for a substitute/erroneous frame */
62int osmo_ecu_frame_out(struct osmo_ecu_state *st, uint8_t *frame_out);
63
64struct osmo_ecu_ops {
65 struct osmo_ecu_state * (*init)(void *ctx, enum osmo_ecu_codec codec);
66 void (*destroy)(struct osmo_ecu_state *);
67 int (*frame_in)(struct osmo_ecu_state *st, bool bfi,
68 const uint8_t *frame, unsigned int frame_bytes);
69 int (*frame_out)(struct osmo_ecu_state *st, uint8_t *frame_out);
70};
71
72int osmo_ecu_register(const struct osmo_ecu_ops *ops, enum osmo_ecu_codec codec);