Browse Source

Enable WASM builds

Remove ulaw/alaw coding in favor of eth_ar lib version
master
Jeroen Vreeken 1 year ago
parent
commit
92cf5bcf6d
23 changed files with 304 additions and 316 deletions
  1. +14
    -6
      Makefile.am
  2. +16
    -117
      alaw.c
  3. +1
    -3
      alaw.h
  4. +25
    -1
      configure.ac
  5. +2
    -8
      dml/dml_crypto.h
  6. +10
    -0
      dml_crypto.c
  7. +1
    -0
      dml_host.c
  8. +1
    -0
      dml_poll.c
  9. +0
    -1
      dml_stream_client.c
  10. +1
    -1
      dml_stream_client_codec2.c
  11. +0
    -1
      dml_stream_client_simple.c
  12. +0
    -1
      dml_streamer.c
  13. +1
    -1
      trx_dv.c
  14. +0
    -149
      ulaw.c
  15. +0
    -27
      ulaw.h
  16. +33
    -0
      wasm_stubs/openssl/ecdsa.h
  17. +9
    -0
      wasm_stubs/openssl/err.h
  18. +24
    -0
      wasm_stubs/openssl/evp.h
  19. +34
    -0
      wasm_stubs/openssl/ossl_typ.h
  20. +16
    -0
      wasm_stubs/openssl/pem.h
  21. +25
    -0
      wasm_stubs/openssl/sha.h
  22. +91
    -0
      wasm_stubs/openssl/x509.h
  23. +0
    -0
      wasm_stubs/openssl/x509v3.h

+ 14
- 6
Makefile.am View File

@ -21,9 +21,9 @@ libdml_la_SOURCES = \
dml_stream.c
libdml_la_CFLAGS=-fPIC
libdml_la_LDFLAGS= -shared -fPIC -version-info 0:0:0 -lcrypto
libdml_la_LDFLAGS= -shared -fPIC -version-info 0:0:0 @LIB_LDFLAGS@
bin_PROGRAMS = dmld dml_list dml_reflector dml_streamer dml_stream_client dml_stream_client_codec2 dml_trx dml_fprs_db
bin_PROGRAMS = dmld dml_list dml_streamer dml_stream_client dml_stream_client_codec2 dml_fprs_db
DML_SRCS = \
dml_config.c \
@ -31,11 +31,8 @@ DML_SRCS = \
ALAW_SRCS = alaw.c
ULAW_SRCS = ulaw.c
TRX_SRCS = \
trx_dv.c \
$(ULAW_SRCS) \
$(ALAW_SRCS)
@ -52,15 +49,26 @@ dmld_LDADD = libdml.la
dml_list_SOURCES = $(DML_SRCS) dml_list.c
dml_list_LDADD = libdml.la
if ENABLE_DML_REFLECTOR
bin_PROGRAMS += dml_reflector
dml_reflector_SOURCES = $(DML_SRCS) $(TRX_SRCS) dml_reflector.c soundlib.c
dml_reflector_LDADD = libdml.la
dml_reflector_LDFLAGS = -lcodec2 -leth_ar -lm
endif
if ENABLE_DML_TRX
bin_PROGRAMS += dml_trx
dml_trx_SOURCES = $(DML_SRCS) $(TRX_SRCS) $(FPRS_DB_SRCS) dml_trx.c soundlib.c
dml_trx_LDADD = libdml.la
dml_trx_LDFLAGS = -lasound -lcodec2 -leth_ar -lm
endif
dml_streamer_SOURCES = $(DML_SRCS) dml_streamer.c matroska.c ogg.c isom.c
dml_streamer_LDADD = libdml.la
@ -69,7 +77,7 @@ dml_streamer_LDADD = libdml.la
dml_stream_client_SOURCES = $(DML_SRCS) dml_stream_client.c
dml_stream_client_LDADD = libdml.la
dml_stream_client_codec2_SOURCES = $(DML_SRCS) $(ULAW_SRCS) $(ALAW_SRCS) dml_stream_client_codec2.c
dml_stream_client_codec2_SOURCES = $(DML_SRCS) $(ALAW_SRCS) dml_stream_client_codec2.c
dml_stream_client_codec2_LDADD = libdml.la
dml_stream_client_codec2_LDFLAGS = -lm


+ 16
- 117
alaw.c View File

@ -1,127 +1,26 @@
/* A-law code from GStreamer
* Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
* PCM - A-Law conversion
* Copyright (C) 2000 by Abramo Bagnara <abramo@alsa-project.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "alaw.h"
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
static int16_t alaw_to_s16 (uint8_t a_val)
{
int t;
int seg;
a_val ^= 0x55;
t = a_val & 0x7f;
if (t < 16)
t = (t << 4) + 8;
else {
seg = (t >> 4) & 0x07;
t = ((t & 0x0f) << 4) + 0x108;
t <<= seg - 1;
}
return ((a_val & 0x80) ? t : -t);
}
void alaw_decode(int16_t *samples, uint8_t *alaw, int nr)
{
int i;
for (i = 0; i < nr; i++) {
samples[i] = alaw_to_s16(alaw[i]);
}
}
/*
* s16_to_alaw() - Convert a 16-bit linear PCM value to 8-bit A-law
*
* s16_to_alaw() accepts an 16-bit integer and encodes it as A-law data.
*
* Linear Input Code Compressed Code
* ------------------------ ---------------
* 0000000wxyza 000wxyz
* 0000001wxyza 001wxyz
* 000001wxyzab 010wxyz
* 00001wxyzabc 011wxyz
* 0001wxyzabcd 100wxyz
* 001wxyzabcde 101wxyz
* 01wxyzabcdef 110wxyz
* 1wxyzabcdefg 111wxyz
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley & Sons, pps 98-111 and 472-476.
*/
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2019
static int val_seg (int val)
{
int r = 1;
val >>= 8;
if (val & 0xf0) {
val >>= 4;
r += 4;
}
if (val & 0x0c) {
val >>= 2;
r += 2;
}
if (val & 0x02)
r += 1;
return r;
}
This program 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.
This program 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.
static uint8_t s16_to_alaw (int16_t pcm_val)
{
int seg;
uint8_t mask;
uint8_t aval;
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
if (pcm_val >= 0) {
mask = 0xD5;
} else {
mask = 0x55;
pcm_val = -pcm_val;
if (pcm_val > 0x7fff)
pcm_val = 0x7fff;
}
*/
if (pcm_val < 256)
aval = pcm_val >> 4;
else {
/* Convert the scaled magnitude to segment number. */
seg = val_seg (pcm_val);
aval = (seg << 4) | ((pcm_val >> (seg + 3)) & 0x0f);
}
return aval ^ mask;
}
#include "alaw.h"
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
void alaw_encode(uint8_t *alaw, int16_t *samples, int nr)
{
int i;
for (i = 0; i < nr; i++) {
alaw[i] = s16_to_alaw(samples[i]);
}
}
uint8_t *alaw_beep(double freq, double rate, double length)
{


+ 1
- 3
alaw.h View File

@ -20,9 +20,7 @@
#define _INCLUDE_ALAW_H_
#include <stdint.h>
void alaw_decode(int16_t *samples, uint8_t *alaw, int nr);
void alaw_encode(uint8_t *alaw, int16_t *samples, int nr);
#include <eth_ar/alaw.h>
uint8_t *alaw_beep(double freq, double rate, double length);
uint8_t *alaw_silence(double rate, double length);


+ 25
- 1
configure.ac View File

@ -8,6 +8,19 @@ AC_PROG_CC
AC_CONFIG_MACRO_DIR([m4])
# Are we using emscripten?
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#ifndef __EMSCRIPTEN__
# error this is not emscripten
#endif
]])],
[EMSCRIPTEN_FOUND="yes"; CFLAGS+=' -I$(srcdir)/wasm_stubs' ],
[EMSCRIPTEN_FOUND="no" ; LIB_LDFLAGS+=' -lcrypto' ]
)
# Check for codec2 library
dnl Search for libcodec2
@ -85,11 +98,22 @@ AS_IF([test "x$libmagic_found_headers" = "xyes" && test "x$libmagic_found_lib" =
[enable_dml_httpd="yes"], [enable_dml_httpd="no"]
)
AS_IF([test "x$EMSCRIPTEN_FOUND" = "xno" ],
[enable_dml_trx="yes"; enable_dml_reflector="yes" ],
[enable_dml_trx="no"; enable_dml_reflector="no" ]
)
AM_CONDITIONAL(ENABLE_DML_HTTPD, test "x$enable_dml_httpd" = "xyes")
AM_CONDITIONAL(ENABLE_DML_REFLECTOR, test "x$enable_dml_reflector" = "xyes")
AM_CONDITIONAL(ENABLE_DML_TRX, test "x$enable_dml_trx" = "xyes")
AC_SUBST([LIB_LDFLAGS])
AC_OUTPUT([Makefile])
echo "Optional parts:"
echo " dml_httpd:" $enable_dml_httpd
echo " dml_httpd: " $enable_dml_httpd
echo " dml_reflector: " $enable_dml_reflector
echo " dml_trx: " $enable_dml_trx
echo " wasm: " $EMSCRIPTEN_FOUND

+ 2
- 8
dml/dml_crypto.h View File

@ -20,14 +20,8 @@
#include "dml.h"
#include <openssl/pem.h>
struct dml_crypto_key {
EC_KEY *ec_key;
X509 *cert;
STACK_OF(X509) *chain;
};
struct dml_crypto_key;
int dml_crypto_init(char *ca_file, char *ca_dir);


+ 10
- 0
dml_crypto.c View File

@ -24,7 +24,17 @@
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/ecdsa.h>
#include <openssl/sha.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
struct dml_crypto_key {
EC_KEY *ec_key;
X509 *cert;
STACK_OF(X509) *chain;
};
X509_STORE *x509_store;
STACK_OF(X509) *certchain;


+ 1
- 0
dml_host.c View File

@ -25,6 +25,7 @@
#include <dml/dml_poll.h>
#include <string.h>
#include <stdio.h>
struct dml_host {
struct dml_client *client;


+ 1
- 0
dml_poll.c View File

@ -21,6 +21,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
struct dml_poll {
struct dml_poll *next;


+ 0
- 1
dml_stream_client.c View File

@ -26,7 +26,6 @@
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <openssl/pem.h>
size_t skip = 0;


+ 1
- 1
dml_stream_client_codec2.c View File

@ -24,7 +24,7 @@
#include "dml_config.h"
#include "dml_stream_client_simple.h"
#include "alaw.h"
#include "ulaw.h"
#include <eth_ar/ulaw.h>
#include <stdlib.h>
#include <unistd.h>


+ 0
- 1
dml_stream_client_simple.c View File

@ -30,7 +30,6 @@
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <openssl/pem.h>
#define DML_STREAM_CLIENT_SIMPLE_KEEPALIVE 120


+ 0
- 1
dml_streamer.c View File

@ -34,7 +34,6 @@
#include <string.h>
#include <time.h>
#include <inttypes.h>
#include <openssl/pem.h>
uint8_t ref_id[DML_ID_SIZE];


+ 1
- 1
trx_dv.c View File

@ -19,7 +19,7 @@
#include <eth_ar/eth_ar.h>
#include <dml/dml_poll.h>
#include "alaw.h"
#include "ulaw.h"
#include <eth_ar/ulaw.h>
#include <arpa/inet.h>
#include <linux/if_packet.h>


+ 0
- 149
ulaw.c View File

@ -1,149 +0,0 @@
/* Mu-law code from Linux kernel
* Copyright (c) 1999 by Jaroslav Kysela <perex@perex.cz>
* Uros Bizjak <uros@kss-loka.si>
* Copyright Jeroen Vreeken (jeroen@vreeken.net), 2017
*
* Based on reference implementation by Sun Microsystems, Inc.
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program 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 Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "ulaw.h"
#define BIAS (0x84) /* Bias for linear code. */
#define SIGN_BIT (0x80) /* Sign bit for a u-law byte. */
#define QUANT_MASK (0xf) /* Quantization field mask. */
#define NSEGS (8) /* Number of u-law segments. */
#define SEG_SHIFT (4) /* Left shift for segment number. */
#define SEG_MASK (0x70) /* Segment field mask. */
static inline int val_seg(int val)
{
int r = 0;
val >>= 7;
if (val & 0xf0) {
val >>= 4;
r += 4;
}
if (val & 0x0c) {
val >>= 2;
r += 2;
}
if (val & 0x02)
r += 1;
return r;
}
/*
* linear2ulaw() - Convert a linear PCM value to u-law
*
* In order to simplify the encoding process, the original linear magnitude
* is biased by adding 33 which shifts the encoding range from (0 - 8158) to
* (33 - 8191). The result can be seen in the following encoding table:
*
* Biased Linear Input Code Compressed Code
* ------------------------ ---------------
* 00000001wxyza 000wxyz
* 0000001wxyzab 001wxyz
* 000001wxyzabc 010wxyz
* 00001wxyzabcd 011wxyz
* 0001wxyzabcde 100wxyz
* 001wxyzabcdef 101wxyz
* 01wxyzabcdefg 110wxyz
* 1wxyzabcdefgh 111wxyz
*
* Each biased linear code has a leading 1 which identifies the segment
* number. The value of the segment number is equal to 7 minus the number
* of leading 0's. The quantization interval is directly available as the
* four bits wxyz. * The trailing bits (a - h) are ignored.
*
* Ordinarily the complement of the resulting code word is used for
* transmission, and so the code word is complemented before it is returned.
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley & Sons, pps 98-111 and 472-476.
*/
static uint8_t linear2ulaw(int16_t pcm_val) /* 2's complement (16-bit range) */
{
int mask;
int seg;
unsigned char uval;
/* Get the sign and the magnitude of the value. */
if (pcm_val < 0) {
pcm_val = BIAS - pcm_val;
mask = 0x7F;
} else {
pcm_val += BIAS;
mask = 0xFF;
}
if (pcm_val > 0x7FFF)
pcm_val = 0x7FFF;
/* Convert the scaled magnitude to segment number. */
seg = val_seg(pcm_val);
/*
* Combine the sign, segment, quantization bits;
* and complement the code word.
*/
uval = (seg << 4) | ((pcm_val >> (seg + 3)) & 0xF);
return uval ^ mask;
}
/*
* ulaw2linear() - Convert a u-law value to 16-bit linear PCM
*
* First, a biased linear code is derived from the code word. An unbiased
* output can then be obtained by subtracting 33 from the biased code.
*
* Note that this function expects to be passed the complement of the
* original code word. This is in keeping with ISDN conventions.
*/
static int16_t ulaw2linear(uint8_t u_val)
{
int t;
/* Complement to obtain normal u-law value. */
u_val = ~u_val;
/*
* Extract and bias the quantization bits. Then
* shift up by the segment number and subtract out the bias.
*/
t = ((u_val & QUANT_MASK) << 3) + BIAS;
t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS));
}
void ulaw_decode(int16_t *samples, uint8_t *ulaw, int nr)
{
int i;
for (i = 0; i < nr; i++) {
samples[i] = ulaw2linear(ulaw[i]);
}
}
void ulaw_encode(uint8_t *ulaw, int16_t *samples, int nr)
{
int i;
for (i = 0; i < nr; i++) {
ulaw[i] = linear2ulaw(samples[i]);
}
}

+ 0
- 27
ulaw.h View File

@ -1,27 +0,0 @@
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2017
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _INCLUDE_ULAW_H_
#define _INCLUDE_ULAW_H_
#include <stdint.h>
void ulaw_decode(int16_t *samples, uint8_t *ulaw, int nr);
void ulaw_encode(uint8_t *ulaw, int16_t *samples, int nr);
#endif /* _INCLUDE_ULAW_H_ */

+ 33
- 0
wasm_stubs/openssl/ecdsa.h View File

@ -0,0 +1,33 @@
#ifndef _DML_WASM_STUB_ECDSA_H_
#define _DML_WASM_STUB_ECDSA_H_
#include <openssl/ossl_typ.h>
void EC_KEY_free(EC_KEY *key);
typedef struct ECDSA_SIG_st {
BIGNUM *r;
BIGNUM *s;
} ECDSA_SIG;
static inline int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig, EC_KEY *eckey)
{
return 0;
}
static inline ECDSA_SIG *ECDSA_SIG_new(void)
{
return NULL;
}
static inline ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len, EC_KEY *eckey)
{
return NULL;
}
static inline void ECDSA_SIG_free(ECDSA_SIG *sig)
{
}
#endif

+ 9
- 0
wasm_stubs/openssl/err.h View File

@ -0,0 +1,9 @@
#ifndef _DML_WASM_STUB_ERR_H_
#define _DML_WASM_STUB_ERR_H_
static inline unsigned long ERR_get_error(void)
{
return 0;
}
#endif

+ 24
- 0
wasm_stubs/openssl/evp.h View File

@ -0,0 +1,24 @@
#ifndef _DML_WASM_STUB_EVP_H_
#define _DML_WASM_STUB_EVP_H_
#include <openssl/ossl_typ.h>
static inline void OpenSSL_add_all_algorithms(void)
{
}
static inline void EVP_PKEY_free(EVP_PKEY *pkey)
{
}
static inline int EVP_PKEY_bits(const EVP_PKEY *pkey)
{
return 0;
}
static inline struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)
{
return NULL;
}
#endif

+ 34
- 0
wasm_stubs/openssl/ossl_typ.h View File

@ -0,0 +1,34 @@
#ifndef _DML_WASM_STUB_OSSL_TYP_H_
#define _DML_WASM_STUB_OSSL_TYP_H_
typedef struct x509_st X509;
typedef struct x509_store_st X509_STORE;
typedef struct x509_store_ctx_st X509_STORE_CTX;
typedef struct ec_key_st EC_KEY;
typedef struct evp_pkey_st EVP_PKEY;
typedef struct bignum_st {} BIGNUM;
#define STACK_OF(type) struct stack_st_##type
STACK_OF(X509);
#define BN_num_bytes(a) 0
static inline BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
{
return NULL;
}
static inline int BN_bn2bin(const BIGNUM *a, unsigned char *to)
{
return 0;
}
#endif /* _DML_WASM_STUB_OSSL_TYP_H_ */

+ 16
- 0
wasm_stubs/openssl/pem.h View File

@ -0,0 +1,16 @@
#ifndef _DML_WASM_STUB_PEM_H_
#define _DML_WASM_STUB_PEM_H_
#include <openssl/ossl_typ.h>
static inline EVP_PKEY *PEM_read_PrivateKey(void *fp, void *a, void *b, void *c)
{
return NULL;
}
static inline X509 *PEM_read_X509(void *fp, void *a, void *b, void *c)
{
return NULL;
}
#endif

+ 25
- 0
wasm_stubs/openssl/sha.h View File

@ -0,0 +1,25 @@
#ifndef _DML_WASM_STUB_SHA_H_
#define _DML_WASM_STUB_SHA_H_
#define SHA256_DIGEST_LENGTH 32
typedef struct {
} SHA256_CTX;
static inline int SHA256_Init(SHA256_CTX *c)
{
return 0;
}
static inline int SHA256_Update(SHA256_CTX *c, const void *data, size_t len)
{
return 0;
}
static inline int SHA256_Final(unsigned char *md, SHA256_CTX *c)
{
return 0;
}
#endif /* _DML_WASM_STUB_SHA_H_ */

+ 91
- 0
wasm_stubs/openssl/x509.h View File

@ -0,0 +1,91 @@
#ifndef _DML_WASM_STUB_X509_H_
#define _DML_WASM_STUB_X509_H_
#include <openssl/ossl_typ.h>
static inline void X509_free(void *a)
{
}
X509_STORE *X509_STORE_new(void)
{
return NULL;
}
static inline void X509_STORE_free(X509_STORE *a)
{
}
static inline int X509_STORE_load_locations(X509_STORE *ctx, const char *file, const char *dir)
{
return 0;
}
X509_STORE_CTX *X509_STORE_CTX_new(void)
{
return NULL;
}
static inline void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
{
}
static inline int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509, STACK_OF(X509) *chain)
{
return 0;
}
static inline EVP_PKEY *X509_get_pubkey(X509 *x)
{
return NULL;
}
static inline void *sk_X509_new_null(void)
{
return NULL;
}
static inline void sk_X509_free(void *x)
{
}
static inline void sk_X509_push(void *x, void *y)
{
}
static inline void *sk_X509_pop(void *x)
{
return NULL;
}
static inline X509 *d2i_X509(X509 **a, const unsigned char **pp, long length)
{
return NULL;
}
static inline int i2d_X509(X509 *a, unsigned char **pp)
{
return 0;
}
static inline int sk_X509_num(void *a)
{
return 0;
}
static inline int X509_verify_cert(X509_STORE_CTX *ctx)
{
return 0;
}
static inline void * sk_X509_value(void *ctx, int i)
{
return NULL;
}
static inline int X509_check_host(X509 *cert, char *name, int a, int b, void *c)
{
return 0;
}
#endif

+ 0
- 0
wasm_stubs/openssl/x509v3.h View File


Loading…
Cancel
Save