--- Makefile.in.orig 2009-08-31 21:16:47.000000000 +0800 +++ Makefile.in 2009-09-14 21:59:01.000000000 +0800 @@ -67,7 +67,7 @@ uninstall-recursive ETAGS = etags CTAGS = ctags -DIST_SUBDIRS = oss mix usb_stream arcam-av doc jack pulse rate a52 \ +DIST_SUBDIRS = oss mix doc jack pulse rate a52 \ rate-lavc maemo pph speex DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) @@ -214,7 +214,7 @@ speexdsp_LIBS = @speexdsp_LIBS@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ -SUBDIRS = oss mix usb_stream arcam-av doc $(am__append_1) \ +SUBDIRS = oss mix doc $(am__append_1) \ $(am__append_2) $(am__append_3) $(am__append_4) \ $(am__append_5) $(am__append_6) $(am__append_7) EXTRA_DIST = gitcompile version COPYING.GPL m4/attributes.m4 --- configure.orig 2009-08-31 21:16:47.000000000 +0800 +++ configure 2009-09-14 21:59:12.000000000 +0800 @@ -9645,7 +9645,7 @@ echo $ECHO_N "(cached) $ECHO_C" >&6 else ac_check_lib_save_LIBS=$LIBS -LIBS="-ldl $LIBS" +LIBS="$LIBS" cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF @@ -9717,7 +9717,7 @@ { echo "$as_me:$LINENO: result: $ac_cv_lib_dl_dlopen" >&5 echo "${ECHO_T}$ac_cv_lib_dl_dlopen" >&6; } if test $ac_cv_lib_dl_dlopen = yes; then - lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl" + lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="" else lt_cv_dlopen="dyld" @@ -10015,7 +10015,7 @@ echo $ECHO_N "(cached) $ECHO_C" >&6 else ac_check_lib_save_LIBS=$LIBS -LIBS="-ldl $LIBS" +LIBS="$LIBS" cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF @@ -10087,7 +10087,7 @@ { echo "$as_me:$LINENO: result: $ac_cv_lib_dl_dlopen" >&5 echo "${ECHO_T}$ac_cv_lib_dl_dlopen" >&6; } if test $ac_cv_lib_dl_dlopen = yes; then - lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl" + lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="" else { echo "$as_me:$LINENO: checking for dlopen in -lsvld" >&5 echo $ECHO_N "checking for dlopen in -lsvld... $ECHO_C" >&6; } @@ -20270,7 +20270,7 @@ echo $ECHO_N "(cached) $ECHO_C" >&6 else ac_check_lib_save_LIBS=$LIBS -LIBS="-lasound -ldl $LIBS" +LIBS="-lasound $LIBS" cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF @@ -21493,7 +21493,7 @@ echo "${ECHO_T}$SND_PLUGINS_VERSION" >&6; } -ac_config_files="$ac_config_files Makefile oss/Makefile pph/Makefile jack/Makefile pulse/Makefile mix/Makefile rate/Makefile a52/Makefile rate-lavc/Makefile maemo/Makefile doc/Makefile usb_stream/Makefile speex/Makefile arcam-av/Makefile" +ac_config_files="$ac_config_files Makefile oss/Makefile pph/Makefile jack/Makefile pulse/Makefile mix/Makefile rate/Makefile a52/Makefile rate-lavc/Makefile maemo/Makefile doc/Makefile speex/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -22134,9 +22134,7 @@ "rate-lavc/Makefile") CONFIG_FILES="$CONFIG_FILES rate-lavc/Makefile" ;; "maemo/Makefile") CONFIG_FILES="$CONFIG_FILES maemo/Makefile" ;; "doc/Makefile") CONFIG_FILES="$CONFIG_FILES doc/Makefile" ;; - "usb_stream/Makefile") CONFIG_FILES="$CONFIG_FILES usb_stream/Makefile" ;; "speex/Makefile") CONFIG_FILES="$CONFIG_FILES speex/Makefile" ;; - "arcam-av/Makefile") CONFIG_FILES="$CONFIG_FILES arcam-av/Makefile" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 echo "$as_me: error: invalid argument: $ac_config_target" >&2;} --- jack/pcm_jack.c.orig 2009-09-16 04:33:36.000000000 +0800 +++ jack/pcm_jack.c 2009-09-16 04:33:55.000000000 +0800 @@ -20,7 +20,9 @@ * */ +#ifndef __FreeBSD__ #include +#endif #include #include #include --- oss/ctl_oss.c.orig 2009-08-31 21:09:41.000000000 +0800 +++ oss/ctl_oss.c 2009-09-15 01:07:51.000000000 +0800 @@ -26,7 +26,11 @@ #include #include #include +#ifdef __FreeBSD__ +#include +#else #include +#endif typedef struct snd_ctl_oss { snd_ctl_ext_t ext; @@ -362,7 +366,9 @@ { snd_config_iterator_t it, next; const char *device = "/dev/mixer"; +#ifndef __FreeBSD__ struct mixer_info mixinfo; +#endif int i, err, val; snd_ctl_oss_t *oss; @@ -399,19 +405,29 @@ goto error; } +#ifndef __FreeBSD__ if (ioctl(oss->fd, SOUND_MIXER_INFO, &mixinfo) < 0) { err = -errno; SNDERR("Cannot get mixer info for device %s", device); goto error; } +#endif oss->ext.version = SND_CTL_EXT_VERSION; oss->ext.card_idx = 0; /* FIXME */ +#ifdef __FreeBSD__ + strncpy(oss->ext.id, "fbsd", sizeof(oss->ext.id) - 1); + strcpy(oss->ext.driver, "FreeBSD/OSS plugin"); + strncpy(oss->ext.name, "FreeBSD/OSS", sizeof(oss->ext.name) - 1); + strncpy(oss->ext.longname, "FreeBSD/OSS", sizeof(oss->ext.longname) - 1); + strncpy(oss->ext.mixername, "FreeBSD/OSS", sizeof(oss->ext.mixername) - 1); +#else strncpy(oss->ext.id, mixinfo.id, sizeof(oss->ext.id) - 1); strcpy(oss->ext.driver, "OSS-Emulation"); strncpy(oss->ext.name, mixinfo.name, sizeof(oss->ext.name) - 1); strncpy(oss->ext.longname, mixinfo.name, sizeof(oss->ext.longname) - 1); strncpy(oss->ext.mixername, mixinfo.name, sizeof(oss->ext.mixername) - 1); +#endif oss->ext.poll_fd = -1; oss->ext.callback = &oss_ext_callback; oss->ext.private_data = oss; --- oss/pcm_oss.c.orig 2009-09-17 22:39:40.000000000 +0800 +++ oss/pcm_oss.c 2009-09-17 22:48:57.000000000 +0800 @@ -22,15 +22,25 @@ #include #include #include +#ifdef __FreeBSD__ +#include +#else #include +#endif + +#define ARRAY_SIZE(ary) (sizeof(ary)/sizeof(ary[0])) typedef struct snd_pcm_oss { snd_pcm_ioplug_t io; char *device; int fd; +#ifndef __FreeBSD__ int fragment_set; int caps; +#endif int format; + int xrun; + int last_ptr; unsigned int period_shift; unsigned int periods; unsigned int frame_bytes; @@ -49,8 +59,14 @@ buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8; size *= oss->frame_bytes; result = write(oss->fd, buf, size); +#ifdef __FreeBSD__ + if (result == -1) + return -errno; +#else if (result <= 0) return result; +#endif + oss->xrun = 0; return result / oss->frame_bytes; } @@ -67,8 +83,13 @@ buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8; size *= oss->frame_bytes; result = read(oss->fd, buf, size); +#ifdef __FreeBSD__ + if (result == -1) + return -errno; +#else if (result <= 0) return result; +#endif return result / oss->frame_bytes; } @@ -78,26 +99,101 @@ struct count_info info; int ptr; + if (io->state != SND_PCM_STATE_RUNNING) + return 0; + + if (io->state == SND_PCM_STATE_XRUN) + return -EPIPE; + if (ioctl(oss->fd, io->stream == SND_PCM_STREAM_PLAYBACK ? SNDCTL_DSP_GETOPTR : SNDCTL_DSP_GETIPTR, &info) < 0) { fprintf(stderr, "*** OSS: oss_pointer error\n"); return 0; } + +#if defined(SNDCTL_DSP_GETERRORS) || defined(SNDCTL_DSP_GETODELAY) + /* + * XXX Clumsy way to detect stream underruns, but enough to make + * the rest of the world happy. + */ + if (oss->last_ptr == info.ptr && io->stream == SND_PCM_STREAM_PLAYBACK) { + oss->xrun++; + if (oss->xrun > oss->periods) { +#ifdef SNDCTL_DSP_GETERRORS + audio_errinfo ei; + + if (ioctl(oss->fd, SNDCTL_DSP_GETERROR, &ei) < 0) + return -EINVAL; + if (ei.play_underruns != 0) +#else + int tmp; + + if (ioctl(oss->fd, SNDCTL_DSP_GETODELAY, &tmp) < 0) + return -EINVAL; + if (tmp < 1) +#endif + snd_pcm_ioplug_set_state(io, SND_PCM_STATE_XRUN); + else + oss->xrun = 0; + } + } else + oss->xrun = 0; +#endif + + oss->last_ptr = info.ptr; + ptr = snd_pcm_bytes_to_frames(io->pcm, info.ptr); return ptr; } +#ifdef XXX_SNDCTL_DSP_GETODELAY +static int oss_delay(snd_pcm_ioplug_t *io, snd_pcm_sframes_t *delayp) +{ + snd_pcm_oss_t *oss = io->private_data; + int tmp; + + if (io->state != SND_PCM_STATE_RUNNING) + return 0; + + if (io->state == SND_PCM_STATE_XRUN) + return -EPIPE; + + if (ioctl(oss->fd, SNDCTL_DSP_GETODELAY, &tmp) < 0) + return -EINVAL; + + /* + * XXX Clumsy way to detect stream underruns, but enough to make + * the rest of the world happy. + */ + if (tmp > 0) + oss->xrun = 0; + else { + oss->xrun++; + if (oss->xrun > oss->periods) + snd_pcm_ioplug_set_state(io, SND_PCM_STATE_XRUN); + } + + *delayp = snd_pcm_bytes_to_frames(io->pcm, tmp); + + return 0; +} +#endif + static int oss_start(snd_pcm_ioplug_t *io) { snd_pcm_oss_t *oss = io->private_data; int tmp = io->stream == SND_PCM_STREAM_PLAYBACK ? PCM_ENABLE_OUTPUT : PCM_ENABLE_INPUT; + oss->xrun = 0; + if (ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &tmp) < 0) { fprintf(stderr, "*** OSS: trigger failed\n"); +#ifndef __FreeBSD__ if (io->stream == SND_PCM_STREAM_CAPTURE) /* fake read to trigger */ read(oss->fd, &tmp, 0); +#endif } return 0; } @@ -125,6 +221,9 @@ snd_pcm_oss_t *oss = io->private_data; int tmp; + if (io->state == SND_PCM_STATE_PREPARED) + return 0; + ioctl(oss->fd, SNDCTL_DSP_RESET); tmp = io->channels; @@ -146,6 +245,43 @@ return 0; } +#ifdef __FreeBSD__ +static const struct { + int oss_format; + snd_pcm_format_t alsa_format; +} oss_formats_tab[] = { + { AFMT_U8, SND_PCM_FORMAT_U8 }, + { AFMT_S8, SND_PCM_FORMAT_S8 }, + { AFMT_MU_LAW, SND_PCM_FORMAT_MU_LAW }, + { AFMT_A_LAW, SND_PCM_FORMAT_A_LAW }, + { AFMT_S16_LE, SND_PCM_FORMAT_S16_LE }, + { AFMT_S16_BE, SND_PCM_FORMAT_S16_BE }, + { AFMT_U16_LE, SND_PCM_FORMAT_U16_LE }, + { AFMT_U16_BE, SND_PCM_FORMAT_U16_BE }, + { AFMT_S24_LE, SND_PCM_FORMAT_S24_3LE }, + { AFMT_S24_BE, SND_PCM_FORMAT_S24_3BE }, + { AFMT_U24_LE, SND_PCM_FORMAT_U24_3LE }, + { AFMT_U24_BE, SND_PCM_FORMAT_U24_3BE }, + { AFMT_S32_LE, SND_PCM_FORMAT_S32_LE }, + { AFMT_S32_BE, SND_PCM_FORMAT_S32_BE }, + { AFMT_U32_LE, SND_PCM_FORMAT_U32_LE }, + { AFMT_U32_BE, SND_PCM_FORMAT_U32_BE }, + /* Special */ + { AFMT_S24_LE, SND_PCM_FORMAT_S20_3LE }, + { AFMT_S24_BE, SND_PCM_FORMAT_S20_3BE }, + { AFMT_U24_LE, SND_PCM_FORMAT_U20_3LE }, + { AFMT_U24_BE, SND_PCM_FORMAT_U20_3BE }, + { AFMT_S24_LE, SND_PCM_FORMAT_S18_3LE }, + { AFMT_S24_BE, SND_PCM_FORMAT_S18_3BE }, + { AFMT_U24_LE, SND_PCM_FORMAT_U18_3LE }, + { AFMT_U24_BE, SND_PCM_FORMAT_U18_3BE }, + { AFMT_S32_LE, SND_PCM_FORMAT_S24_LE }, + { AFMT_S32_BE, SND_PCM_FORMAT_S24_BE }, + { AFMT_U32_LE, SND_PCM_FORMAT_U24_LE }, + { AFMT_U32_BE, SND_PCM_FORMAT_U24_BE }, +}; +#endif + static int oss_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED) { @@ -155,6 +291,16 @@ long oflags, flags; oss->frame_bytes = (snd_pcm_format_physical_width(io->format) * io->channels) / 8; +#ifdef __FreeBSD__ + oss->format = -1; + for (i = 0; i < ARRAY_SIZE(oss_formats_tab); i++) { + if (oss_formats_tab[i].alsa_format == io->format) { + oss->format = oss_formats_tab[i].oss_format; + break; + } + } + if (oss->format == -1) { +#else switch (io->format) { case SND_PCM_FORMAT_U8: oss->format = AFMT_U8; @@ -166,6 +312,7 @@ oss->format = AFMT_S16_BE; break; default: +#endif fprintf(stderr, "*** OSS: unsupported format %s\n", snd_pcm_format_name(io->format)); return -EINVAL; } @@ -183,6 +330,28 @@ } oss->periods = io->buffer_size / io->period_size; +#ifdef __FreeBSD__ + tmp = oss->period_shift | (oss->periods << 16); + if (ioctl(oss->fd, SNDCTL_DSP_SETFRAGMENT, &tmp) < 0) + return -EINVAL; + + err = oss_prepare(io); + if (err < 0) + return err; + +#if 0 + { + audio_buf_info bi; + + if (ioctl(oss->fd, io->stream == SND_PCM_STREAM_PLAYBACK ? + SNDCTL_DSP_GETOSPACE : SNDCTL_DSP_GETISPACE, &bi) < 0) + return -EINVAL; + + oss->periods = bi.fragstotal; + fprintf(stderr, "\n\n%d %d\n\n", bi.fragsize, bi.fragstotal); + } +#endif +#else _retry: tmp = oss->period_shift | (oss->periods << 16); if (ioctl(oss->fd, SNDCTL_DSP_SETFRAGMENT, &tmp) < 0) { @@ -209,6 +378,7 @@ goto _retry; } oss->fragment_set = 1; +#endif if ((flags = fcntl(oss->fd, F_GETFL)) < 0) { err = -errno; @@ -229,10 +399,95 @@ return 0; } -#define ARRAY_SIZE(ary) (sizeof(ary)/sizeof(ary[0])) - static int oss_hw_constraint(snd_pcm_oss_t *oss) { +#ifdef __FreeBSD__ + snd_pcm_ioplug_t *io = &oss->io; + static const snd_pcm_access_t access_list[] = { + SND_PCM_ACCESS_RW_INTERLEAVED, + SND_PCM_ACCESS_MMAP_INTERLEAVED + }; + static const unsigned int periods_list[] = { + 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, + 2048, 4096, 8192, 16384, 32768, 65536 + }; + unsigned int nformats; + unsigned int format[ARRAY_SIZE(oss_formats_tab)]; + unsigned int nchannels; + unsigned int channel[8]; + int i, err, tmp; + + /* check trigger */ + tmp = 0; + if (ioctl(oss->fd, SNDCTL_DSP_GETCAPS, &tmp) >= 0) { + if (!(tmp & DSP_CAP_TRIGGER)) + fprintf(stderr, "*** OSS: trigger is not supported!\n"); + } + + /* access type - interleaved only */ + if ((err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_ACCESS, + ARRAY_SIZE(access_list), access_list)) < 0) + return err; + + /* supported formats. */ + tmp = 0; + ioctl(oss->fd, SNDCTL_DSP_GETFMTS, &tmp); + nformats = 0; + for (i = 0; i < ARRAY_SIZE(oss_formats_tab); i++) { + if (tmp & oss_formats_tab[i].oss_format) + format[nformats++] = oss_formats_tab[i].alsa_format; + } + if (! nformats) + format[nformats++] = SND_PCM_FORMAT_S16; + if ((err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_FORMAT, + nformats, format)) < 0) + return err; + + /* supported channels */ + nchannels = 0; + for (i = 0; i < 8; i++) { + tmp = i + 1; + if (ioctl(oss->fd, SNDCTL_DSP_CHANNELS, &tmp) >= 0 && 1 + i == tmp) + channel[nchannels++] = tmp; + } + if (! nchannels) /* assume 2ch stereo */ + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_CHANNELS, + 2, 2); + else + err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_CHANNELS, + nchannels, channel); + if (err < 0) + return err; + + /* supported rates */ + /* FIXME: should query? */ + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_RATE, 1, 384000); + if (err < 0) + return err; + + /* + * Maximum buffer size on FreeBSD can go up to 131072 bytes without + * strict ^2 alignment so that s24le in 3bytes packing can be fed + * directly. However ALSA seems expecting <= 65536, and number of + * periods must be ^2 aligned. The size of periods are a bit relaxed. + */ + + /* period size , not strictly ^2 */ + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_PERIOD_BYTES, 1, 32768); + if (err < 0) + return err; + /* periods , strictly ^2 */ + err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_PERIODS, + ARRAY_SIZE(periods_list), periods_list); + if (err < 0) + return err; + /* buffer size , not strictly ^2 , 2 <=> 65536 */ + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_BUFFER_BYTES, 2, 65536); + if (err < 0) + return err; + + return 0; +#else snd_pcm_ioplug_t *io = &oss->io; static const snd_pcm_access_t access_list[] = { SND_PCM_ACCESS_RW_INTERLEAVED, @@ -317,6 +572,7 @@ return err; return 0; +#endif } @@ -335,6 +591,9 @@ .stop = oss_stop, .transfer = oss_write, .pointer = oss_pointer, +#ifdef XXX_SNDCTL_DSP_GETODELAY + .delay = oss_delay, +#endif .close = oss_close, .hw_params = oss_hw_params, .prepare = oss_prepare,