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