Change in gapk[master]: procqueue/ecu: use generic ECU abstraction API

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

fixeria gerrit-no-reply at lists.osmocom.org
Thu Nov 21 18:56:35 UTC 2019


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/gapk/+/16154 )


Change subject: procqueue/ecu: use generic ECU abstraction API
......................................................................

procqueue/ecu: use generic ECU abstraction API

Change-Id: I434a5973add38f92fc2ebe7f16125cfcb8ff9e23
---
M include/osmocom/gapk/codecs.h
M src/Makefile.am
M src/codec_fr.c
D src/ecu_fr.c
M src/pq_ecu.c
5 files changed, 80 insertions(+), 105 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/gapk refs/changes/54/16154/1

diff --git a/include/osmocom/gapk/codecs.h b/include/osmocom/gapk/codecs.h
index 33f6593..253fb14 100644
--- a/include/osmocom/gapk/codecs.h
+++ b/include/osmocom/gapk/codecs.h
@@ -73,9 +73,6 @@
 	/* Encoding / decoding function pointers */
 	osmo_gapk_codec_conv_cb_t codec_encode;
 	osmo_gapk_codec_conv_cb_t codec_decode;
-
-	/* ECU (Error Concealment Unit) function */
-	osmo_gapk_codec_conv_cb_t ecu_proc;
 };
 
 const struct osmo_gapk_codec_desc *
diff --git a/src/Makefile.am b/src/Makefile.am
index 8fdeff7..94d9356 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -46,11 +46,6 @@
 	pq_ecu.c \
 	$(NULL)
 
-# ECU (Error Concealment Unit) implementation
-libosmogapk_la_SOURCES += \
-	ecu_fr.c \
-	$(NULL)
-
 # Formats implementation
 libosmogapk_la_SOURCES += \
 	formats.c \
diff --git a/src/codec_fr.c b/src/codec_fr.c
index 75efeb7..f2ca6e6 100644
--- a/src/codec_fr.c
+++ b/src/codec_fr.c
@@ -83,9 +83,6 @@
 
 #endif /* HAVE_LIBGSM */
 
-/* Forward declaration of ECU (Error Concealment Unit) function */
-int ecu_proc_fr(void *state, uint8_t *out, const uint8_t *in, unsigned int in_len);
-
 const struct osmo_gapk_codec_desc codec_fr_desc = {
 	.type = CODEC_FR,
 	.name = "fr",
@@ -99,5 +96,4 @@
 	.codec_encode = codec_fr_encode,
 	.codec_decode = codec_fr_decode,
 #endif
-	.ecu_proc = ecu_proc_fr,
 };
diff --git a/src/ecu_fr.c b/src/ecu_fr.c
deleted file mode 100644
index db55fec..0000000
--- a/src/ecu_fr.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* ECU (Error Concealment Unit) for FR */
-
-/*
- * This file is part of GAPK (GSM Audio Pocket Knife).
- *
- * (C) 2018 by Vadim Yanitskiy <axilirator at gmail.com>
- *
- * All Rights Reserved
- *
- * GAPK is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GAPK is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GAPK.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdint.h>
-#include <string.h>
-#include <assert.h>
-#include <stdbool.h>
-
-#include <osmocom/gapk/codecs.h>
-#include <osmocom/codec/ecu.h>
-
-int
-ecu_proc_fr(void *_state, uint8_t *out, const uint8_t *in, unsigned int in_len)
-{
-	struct osmo_ecu_fr_state *state = (struct osmo_ecu_fr_state *) _state;
-	bool backup = false;
-	bool bfi = true;
-	int i, rc;
-
-	assert(in_len == FR_CANON_LEN);
-
-	/* Check if a frame is BFI */
-	for (i = 1; i < in_len; i++) {
-		if (in[i] != 0x00) {
-			bfi = false;
-			break;
-		}
-	}
-
-	/* We have got a good frame, nothing to do */
-	if (!bfi) {
-		osmo_ecu_fr_reset(state, (uint8_t *) in);
-		memcpy(out, in, in_len);
-		return in_len;
-	}
-
-	/* Check if ECU state contains a backup frame */
-	for (i = 0; i < in_len; i++) {
-		if (state->frame_backup[i] != 0x00) {
-			backup = true;
-			break;
-		}
-	}
-
-	/* There is no back-up frame */
-	if (!backup) {
-		/* Copy BFI 'as-is' */
-		memcpy(out, in, in_len);
-		return in_len;
-	}
-
-	/* Attempt to perform error concealment */
-	rc = osmo_ecu_fr_conceal(state, out);
-	if (rc)
-		return rc;
-
-	return in_len;
-}
diff --git a/src/pq_ecu.c b/src/pq_ecu.c
index fad853c..a9972b1 100644
--- a/src/pq_ecu.c
+++ b/src/pq_ecu.c
@@ -3,7 +3,7 @@
 /*
  * This file is part of GAPK (GSM Audio Pocket Knife).
  *
- * (C) 2018 by Vadim Yanitskiy <axilirator at gmail.com>
+ * (C) 2018-2019 by Vadim Yanitskiy <axilirator at gmail.com>
  *
  * All Rights Reserved
  *
@@ -22,20 +22,69 @@
  */
 
 #include <stdint.h>
+#include <string.h>
 #include <talloc.h>
 #include <errno.h>
 
+#include <osmocom/codec/codec.h>
+#include <osmocom/codec/ecu.h>
+
 #include <osmocom/gapk/procqueue.h>
 #include <osmocom/gapk/logging.h>
 #include <osmocom/gapk/formats.h>
 #include <osmocom/gapk/codecs.h>
 
-#include <osmocom/codec/ecu.h>
+/* Empty buffer for quick memcmp() based BFI detection */
+static const uint8_t zero_buf[40] = { 0x00 };
+
+static int
+pq_cb_ecu_proc(void *state, uint8_t *out, const uint8_t *in, unsigned int in_len)
+{
+	struct osmo_ecu_state *ecu_state = state;
+	int bfi, rc;
+
+	/* Check if the input frame is BFI */
+	switch (ecu_state->codec) {
+	case OSMO_ECU_CODEC_HR:
+		bfi = !memcmp(zero_buf, in + 1, GSM_HR_BYTES);
+		break;
+	case OSMO_ECU_CODEC_FR:
+		bfi = !memcmp(zero_buf, in + 1, GSM_FR_BYTES - 1);
+		break;
+	case OSMO_ECU_CODEC_EFR:
+		bfi = !memcmp(zero_buf, in + 1, GSM_EFR_BYTES - 1);
+		break;
+	/* TODO: implement BFI detection (in[0] == AMR_NO_DATA?) */
+	case OSMO_ECU_CODEC_AMR:
+	default:
+		LOGPGAPK(LOGL_FATAL, "Unknown ECU codec\n");
+		OSMO_ASSERT(0);
+	}
+
+	rc = osmo_ecu_frame_in(state, bfi, in, in_len);
+	if (rc) {
+		LOGPGAPK(LOGL_ERROR, "osmo_ecu_frame_in() failed: rc=%d\n", rc);
+		return -EIO;
+	}
+
+	if (bfi) {
+		rc = osmo_ecu_frame_out(state, out);
+		if (rc >= 0)
+			return rc;
+		LOGPGAPK(LOGL_NOTICE, "osmo_ecu_frame_out() failed: rc=%d\n", rc);
+		/* Forward BFI 'as-is' */
+	}
+
+	/* Forward frame 'as-is' */
+	memcpy(out, in, in_len);
+	return in_len;
+}
 
 static void
-clean_up(void *state)
+pq_cb_ecu_exit(void *state)
 {
-	talloc_free(state);
+	struct osmo_ecu_state *ecu_state = state;
+	osmo_ecu_destroy(ecu_state);
 }
 
 /*! Add a ECU block to the processing queue
@@ -47,23 +96,37 @@
 	const struct osmo_gapk_codec_desc *codec)
 {
 	const struct osmo_gapk_format_desc *fmt;
+	struct osmo_ecu_state *ecu_state;
 	struct osmo_gapk_pq_item *item;
 
+	/* Allocate the ECU state */
+	switch (codec->type) {
+	case CODEC_HR:
+		ecu_state = osmo_ecu_init(pq, OSMO_ECU_CODEC_HR);
+		break;
+	case CODEC_FR:
+		ecu_state = osmo_ecu_init(pq, OSMO_ECU_CODEC_FR);
+		break;
+	case CODEC_EFR:
+		ecu_state = osmo_ecu_init(pq, OSMO_ECU_CODEC_EFR);
+		break;
+	/* FIXME: we need to know how to detect AMR BFI */
+	case CODEC_AMR:
+	default:
+		ecu_state = NULL;
+		break;
+	}
+
 	/* Make sure that a codec has corresponding ECU implementation */
-	if (codec->ecu_proc == NULL) {
+	if (ecu_state == NULL) {
 		LOGPGAPK(LOGL_ERROR, "Codec '%s' has no ECU implementation\n", codec->name);
 		return -ENOTSUP;
 	}
 
 	/* Allocate a new item to the processing queue */
 	item = osmo_gapk_pq_add_item(pq);
-	if (!item)
-		return -ENOMEM;
-
-	/* Allocate the ECU state */
-	item->state = talloc_zero(item, struct osmo_ecu_fr_state);
-	if (!item->state) {
-		talloc_free(item);
+	if (!item) {
+		osmo_ecu_destroy(ecu_state);
 		return -ENOMEM;
 	}
 
@@ -72,9 +135,11 @@
 	item->len_in  = fmt->frame_len;
 	item->len_out = fmt->frame_len;
 
-	item->proc = codec->ecu_proc;
-	item->exit = &clean_up;
-	item->wait = NULL;
+	talloc_steal(item, ecu_state);
+	item->state = ecu_state;
+
+	item->proc = &pq_cb_ecu_proc;
+	item->exit = &pq_cb_ecu_exit;
 
 	/* Meta information */
 	item->type = OSMO_GAPK_ITEM_TYPE_PROC;

-- 
To view, visit https://gerrit.osmocom.org/c/gapk/+/16154
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: gapk
Gerrit-Branch: master
Gerrit-Change-Id: I434a5973add38f92fc2ebe7f16125cfcb8ff9e23
Gerrit-Change-Number: 16154
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <axilirator at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191121/44e1a82d/attachment.htm>


More information about the gerrit-log mailing list