X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/515cd2bb4f4ec548f464edeb5be7564fa5b0139f..74cfbeaa0972bc7d1b1026bb1dfa7f6984084174:/clients/playrtp-oss.c?ds=sidebyside diff --git a/clients/playrtp-oss.c b/clients/playrtp-oss.c index 8a8f4c6..4b0ab83 100644 --- a/clients/playrtp-oss.c +++ b/clients/playrtp-oss.c @@ -1,43 +1,39 @@ /* * This file is part of DisOrder. * Copyright (C) 2007 Richard Kettlewell + * Portions copyright (C) 2007 Ross Younger * - * This program is free software; you can redistribute it and/or modify + * 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 2 of the License, or + * 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. - * + * + * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA + * along with this program. If not, see . */ /** @file clients/playrtp-oss.c - * @brief RTP player - OSS support + * @brief RTP player - OSS and empeg support */ -#include +#include "common.h" -#if HAVE_SYS_SOUNDCARD_H -#include "types.h" +#if HAVE_SYS_SOUNDCARD_H || EMPEG_HOST #include #include +#if !EMPEG_HOST #include -#include +#endif #include -#include #include #include #include -#if HAVE_LINUX_EMPEG_H -# include -#endif +#include #include "mem.h" #include "log.h" @@ -61,6 +57,16 @@ static int playrtp_oss_bufused; /** @brief Open and configure the OSS audio device */ static void playrtp_oss_enable(void) { if(playrtp_oss_fd == -1) { +#if EMPEG_HOST + /* empeg audio driver only knows /dev/audio, only supports the equivalent + * of AFMT_S16_NE, has a fixed buffer size, and does not support the + * SNDCTL_ ioctls. */ + if(!device) + device = "/dev/audio"; + if((playrtp_oss_fd = open(device, O_WRONLY)) < 0) + fatal(errno, "error opening %s", device); + playrtp_oss_bufsize = 4608; +#else int rate = 44100, stereo = 1, format = AFMT_S16_BE; if(!device) { if(access("/dev/dsp", W_OK) == 0) @@ -82,9 +88,10 @@ static void playrtp_oss_enable(void) { error(0, "asking for 44100Hz, got %dHz", rate); if(ioctl(playrtp_oss_fd, SNDCTL_DSP_GETBLKSIZE, &playrtp_oss_bufsize) < 0) fatal(errno, "ioctl SNDCTL_DSP_GETBLKSIZE"); + info("OSS buffer size %d", playrtp_oss_bufsize); +#endif playrtp_oss_buffer = xmalloc(playrtp_oss_bufsize); playrtp_oss_bufused = 0; - info("OSS buffer size %d", playrtp_oss_bufsize); nonblock(playrtp_oss_fd); } } @@ -100,6 +107,16 @@ static int playrtp_oss_flush(void) { /* 0 out the unused portion of the buffer */ memset(playrtp_oss_buffer + playrtp_oss_bufused, 0, playrtp_oss_bufsize - playrtp_oss_bufused); +#if EMPEG_HOST + /* empeg audio driver insists on native-endian samples */ + { + uint16_t *ptr, + *const limit = (uint16_t *)(playrtp_oss_buffer + playrtp_oss_bufused); + + for(ptr = (uint16_t *)playrtp_oss_buffer; ptr < limit; ++ptr) + *ptr = ntohs(*ptr); + } +#endif for(;;) { nbyteswritten = write(playrtp_oss_fd, playrtp_oss_buffer, playrtp_oss_bufsize); @@ -117,6 +134,15 @@ static int playrtp_oss_flush(void) { if(nbyteswritten < playrtp_oss_bufsize) error(0, "%s: short write (%d/%d)", device, nbyteswritten, playrtp_oss_bufsize); + if(dump_buffer) { + int count; + const int16_t *sp = (const int16_t *)playrtp_oss_buffer; + + for(count = 0; count < playrtp_oss_bufsize; count += sizeof(int16_t)) { + dump_buffer[dump_index++] = (int16_t)ntohs(*sp++); + dump_index %= dump_size; + } + } playrtp_oss_bufused = 0; return 0; } @@ -143,8 +169,11 @@ static void playrtp_oss_wait(void) { */ static void playrtp_oss_disable(int hard) { if(hard) { +#if !EMPEG_HOST + /* No SNDCTL_DSP_ ioctls on empeg */ if(ioctl(playrtp_oss_fd, SNDCTL_DSP_RESET, 0) < 0) error(errno, "ioctl SNDCTL_DSP_RESET"); +#endif } else playrtp_oss_flush(); xclose(playrtp_oss_fd); @@ -155,7 +184,7 @@ static void playrtp_oss_disable(int hard) { /** @brief Write samples to OSS output device * @param data Pointer to sample data - * @param nsamples Number of samples + * @param samples Number of samples * @return 0 on success, non-0 on error */ static int playrtp_oss_write(const char *data, size_t samples) {