From 0a1dc2492856a22a4551b02dc5a866322a7d514d Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sat, 24 Apr 2021 13:23:12 +0200 Subject: [PATCH] oss: remove deprecated module FreeBSD now supports ALSA and Portaudio which can be used instead. --- README.md | 2 - mk/modules.mk | 7 - modules/oss/module.mk | 18 -- modules/oss/oss.c | 372 ------------------------------------------ src/config.c | 4 +- 5 files changed, 2 insertions(+), 401 deletions(-) delete mode 100644 modules/oss/module.mk delete mode 100644 modules/oss/oss.c diff --git a/README.md b/README.md index d87a76564..f4afe0a8d 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,6 @@ Distributed under BSD license - Gstreamer playbin input audio-driver - JACK Audio Connection Kit audio-driver - MacOSX/iOS coreaudio/audiounit audio-driver - - Open Sound System (OSS) audio-driver - Portaudio audio-driver - Windows winwave audio-driver @@ -265,7 +264,6 @@ natpmp NAT Port Mapping Protocol (NAT-PMP) module omx OpenMAX IL video display module opensles OpenSLES audio driver opus OPUS Interactive audio codec -oss Open Sound System (OSS) audio driver pcp Port Control Protocol (PCP) module plc Packet Loss Concealment (PLC) using spandsp portaudio Portaudio driver diff --git a/mk/modules.mk b/mk/modules.mk index d4e53a337..6143edd90 100644 --- a/mk/modules.mk +++ b/mk/modules.mk @@ -38,7 +38,6 @@ # USE_OMX_BELLAGIO libomxil-bellagio xvideosink driver # USE_OPUS Opus audio codec # USE_OPUS_MS Opus multistream audio codec -# USE_OSS OSS audio driver # USE_PLC Packet Loss Concealment # USE_PORTAUDIO Portaudio audio driver # USE_PULSE Pulseaudio audio driver @@ -144,9 +143,6 @@ USE_OPUS := $(shell [ -f $(SYSROOT)/include/opus/opus.h ] || \ USE_OPUS_MS := $(shell [ -f $(SYSROOT)/include/opus/opus_multistream.h ] || \ [ -f $(SYSROOT_ALT)/include/opus/opus_multistream.h ] || \ [ -f $(SYSROOT)/local/include/opus/opus_multistream.h ] && echo "yes") -USE_OSS := $(shell [ -f $(SYSROOT)/include/soundcard.h ] || \ - [ -f $(SYSROOT)/include/linux/soundcard.h ] || \ - [ -f $(SYSROOT)/include/sys/soundcard.h ] && echo "yes") USE_PLC := $(shell [ -f $(SYSROOT)/include/spandsp/plc.h ] || \ [ -f $(SYSROOT_ALT)/include/spandsp/plc.h ] || \ [ -f $(SYSROOT_LOCAL)/include/spandsp/plc.h ] && echo "yes") @@ -408,9 +404,6 @@ endif ifneq ($(USE_OPUS),) MODULES += opus endif -ifneq ($(USE_OSS),) -MODULES += oss -endif ifneq ($(USE_PLC),) MODULES += plc endif diff --git a/modules/oss/module.mk b/modules/oss/module.mk deleted file mode 100644 index 109d34d63..000000000 --- a/modules/oss/module.mk +++ /dev/null @@ -1,18 +0,0 @@ -# -# module.mk -# -# Copyright (C) 2010 Alfred E. Heggestad -# - -MOD := oss -$(MOD)_SRCS += oss.c -$(MOD)_LFLAGS += - -ifeq ($(OS), openbsd) -$(MOD)_LFLAGS += -lossaudio -endif -ifeq ($(OS), netbsd) -$(MOD)_LFLAGS += -lossaudio -endif - -include mk/mod.mk diff --git a/modules/oss/oss.c b/modules/oss/oss.c deleted file mode 100644 index 507b8af98..000000000 --- a/modules/oss/oss.c +++ /dev/null @@ -1,372 +0,0 @@ -/** - * @file oss.c Open Sound System (OSS) driver - * - * Copyright (C) 2010 Alfred E. Heggestad - */ -#include -#include -#include -#include -#include -#include -#include -#include -#if defined(NETBSD) || defined(OPENBSD) -#include -#elif defined (LINUX) -#include -#else -#include -#endif -#ifdef SOLARIS -#include -#endif - - -/** - * @defgroup oss oss - * - * Open Sound System (OSS) audio driver module - * - * - * References: - * - * http://www.4front-tech.com/linux.html - */ - - -struct ausrc_st { - pthread_t thread; - bool run; - int fd; - struct ausrc_prm prm; - int16_t *sampv; - size_t sampc; - ausrc_read_h *rh; - ausrc_error_h *errh; - void *arg; -}; - -struct auplay_st { - pthread_t thread; - bool run; - int fd; - int16_t *sampv; - size_t sampc; - auplay_write_h *wh; - void *arg; -}; - - -static struct ausrc *ausrc; -static struct auplay *auplay; -static char oss_dev[64] = "/dev/dsp"; - - -/* - * Automatically calculate the fragment size depending on sampling rate - * and number of channels. More entries can be added to the table below. - * - * NOTE. Powermac 8200 and linux 2.4.18 gives: - * SNDCTL_DSP_SETFRAGMENT: Invalid argument - */ -static int set_fragment(int fd, uint32_t sampc) -{ - static const struct { - uint16_t max; - uint16_t size; - } fragv[] = { - {10, 7}, /* 10 x 2^7 = 1280 = 4 x 320 */ - {15, 7}, /* 15 x 2^7 = 1920 = 6 x 320 */ - {20, 7}, /* 20 x 2^7 = 2560 = 8 x 320 */ - {25, 7}, /* 25 x 2^7 = 3200 = 10 x 320 */ - {15, 8}, /* 15 x 2^8 = 3840 = 12 x 320 */ - {20, 8}, /* 20 x 2^8 = 5120 = 16 x 320 */ - {25, 8} /* 25 x 2^8 = 6400 = 20 x 320 */ - }; - size_t i; - const uint32_t buf_size = 2 * sampc; - - for (i=0; irun) { - st->run = false; - pthread_join(st->thread, NULL); - } - - if (-1 != st->fd) { - (void)close(st->fd); - } - - mem_deref(st->sampv); -} - - -static void ausrc_destructor(void *arg) -{ - struct ausrc_st *st = arg; - - if (st->run) { - st->run = false; - pthread_join(st->thread, NULL); - } - - if (-1 != st->fd) { - (void)close(st->fd); - } - - mem_deref(st->sampv); -} - - -static void *record_thread(void *arg) -{ - struct ausrc_st *st = arg; - struct auframe af; - uint64_t sampc = 0; - int n; - - while (st->run) { - - n = (int)read(st->fd, st->sampv, st->sampc*2); - if (n <= 0) - continue; - - af.fmt = AUFMT_S16LE; - af.sampv = st->sampv; - af.sampc = n/2; - af.timestamp = sampc * AUDIO_TIMEBASE / st->prm.srate; - - sampc += n/2; - - st->rh(&af, st->arg); - } - - return NULL; -} - - -static void *play_thread(void *arg) -{ - struct auplay_st *st = arg; - struct auframe af; - int n; - - auframe_init(&af, AUFMT_S16LE, st->sampv, st->sampc); - - while (st->run) { - - st->wh(&af, st->arg); - - n = (int)write(st->fd, st->sampv, st->sampc*2); - if (n < 0) { - warning("oss: write: %m\n", errno); - break; - } - } - - return NULL; -} - - -static int src_alloc(struct ausrc_st **stp, const struct ausrc *as, - struct media_ctx **ctx, - struct ausrc_prm *prm, const char *device, - ausrc_read_h *rh, ausrc_error_h *errh, void *arg) -{ - struct ausrc_st *st; - int err; - - (void)ctx; - (void)errh; - - if (!stp || !as || !prm || prm->fmt != AUFMT_S16LE || !rh) - return EINVAL; - - st = mem_zalloc(sizeof(*st), ausrc_destructor); - if (!st) - return ENOMEM; - - st->fd = -1; - st->rh = rh; - st->errh = errh; - st->arg = arg; - - if (!device) - device = oss_dev; - - st->prm = *prm; - st->sampc = prm->srate * prm->ch * prm->ptime / 1000; - - st->sampv = mem_alloc(2 * st->sampc, NULL); - if (!st->sampv) { - err = ENOMEM; - goto out; - } - - st->fd = open(device, O_RDONLY); - if (st->fd < 0) { - err = errno; - goto out; - } - - err = oss_reset(st->fd, prm->srate, prm->ch, (int)st->sampc, 0); - if (err) - goto out; - - st->run = true; - err = pthread_create(&st->thread, NULL, record_thread, st); - if (err) { - st->run = false; - goto out; - } - - out: - if (err) - mem_deref(st); - else - *stp = st; - - return err; -} - - -static int play_alloc(struct auplay_st **stp, const struct auplay *ap, - struct auplay_prm *prm, const char *device, - auplay_write_h *wh, void *arg) -{ - struct auplay_st *st; - int err; - - if (!stp || !ap || !prm || prm->fmt != AUFMT_S16LE || !wh) - return EINVAL; - - st = mem_zalloc(sizeof(*st), auplay_destructor); - if (!st) - return ENOMEM; - - st->fd = -1; - st->wh = wh; - st->arg = arg; - - if (!device) - device = oss_dev; - - st->sampc = prm->srate * prm->ch * prm->ptime / 1000; - - st->sampv = mem_alloc(st->sampc * 2, NULL); - if (!st->sampv) { - err = ENOMEM; - goto out; - } - - st->fd = open(device, O_WRONLY); - if (st->fd < 0) { - err = errno; - goto out; - } - - err = oss_reset(st->fd, prm->srate, prm->ch, (int)st->sampc, 0); - if (err) - goto out; - - st->run = true; - err = pthread_create(&st->thread, NULL, play_thread, st); - if (err) { - st->run = false; - goto out; - } - - out: - if (err) - mem_deref(st); - else - *stp = st; - - return err; -} - - -static int module_init(void) -{ - int err; - - err = ausrc_register(&ausrc, baresip_ausrcl(), "oss", src_alloc); - err |= auplay_register(&auplay, baresip_auplayl(), "oss", play_alloc); - - return err; -} - - -static int module_close(void) -{ - ausrc = mem_deref(ausrc); - auplay = mem_deref(auplay); - - return 0; -} - - -EXPORT_SYM const struct mod_export DECL_EXPORTS(oss) = { - "oss", - "audio", - module_init, - module_close, -}; diff --git a/src/config.c b/src/config.c index 6a2e53c06..bf1d99db6 100644 --- a/src/config.c +++ b/src/config.c @@ -542,7 +542,7 @@ static const char *default_audio_device(void) return "coreaudio,default"; #endif #elif defined (FREEBSD) - return "oss,/dev/dsp"; + return "alsa,default"; #elif defined (OPENBSD) return "sndio,default"; #elif defined (WIN32) @@ -865,7 +865,7 @@ int config_write_template(const char *file, const struct config *cfg) (void)re_fprintf(f, "#module\t\t\t" "audiounit" MOD_EXT "\n"); #endif #elif defined (FREEBSD) - (void)re_fprintf(f, "module\t\t\t" "oss" MOD_EXT "\n"); + (void)re_fprintf(f, "module\t\t\t" "alsa" MOD_EXT "\n"); #elif defined (OPENBSD) (void)re_fprintf(f, "module\t\t\t" "sndio" MOD_EXT "\n"); #elif defined (WIN32)