From 34c5e90c0159ab63b2636c596cceeea9f5613537 Mon Sep 17 00:00:00 2001 From: samr7 Date: Sat, 29 Nov 2008 00:40:01 +0000 Subject: Minor SoundIo backend cleanups. - Make SetNonBlock() common. - Fix handling of Create/GetDeviceList calls when backend is deconfigured. git-svn-id: http://nohands.svn.sourceforge.net/svnroot/nohands/trunk@48 126591fb-c623-4b62-a76d-97a8e4f34109 --- libhfp/bt.cpp | 16 ---------- libhfp/events.cpp | 18 +++++++++++ libhfp/soundio-alsa.cpp | 27 ++++++++++++++--- libhfp/soundio-oss.cpp | 81 ++++++++++++++++++++++++++++++------------------- 4 files changed, 90 insertions(+), 52 deletions(-) (limited to 'libhfp') diff --git a/libhfp/bt.cpp b/libhfp/bt.cpp index 40658f6..b5a6dc9 100644 --- a/libhfp/bt.cpp +++ b/libhfp/bt.cpp @@ -50,22 +50,6 @@ namespace libhfp { -bool -SetNonBlock(int fh, bool nonblock) -{ - int flags = fcntl(fh, F_GETFL); - if (nonblock) { - if (flags & O_NONBLOCK) { return true; } - flags |= O_NONBLOCK; - } else { - if (!(flags & O_NONBLOCK)) { return true; } - flags &= ~O_NONBLOCK; - } - - return (fcntl(fh, F_SETFL, flags) >= 0); -} - - /* * Communicating with SDP servers requires a lot more parsing logic * than using the HCI command/event interfaces. The libbluetooth SDP diff --git a/libhfp/events.cpp b/libhfp/events.cpp index c3850b9..e885f0c 100644 --- a/libhfp/events.cpp +++ b/libhfp/events.cpp @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include +#include #include #include #include @@ -28,6 +30,22 @@ namespace libhfp { +bool +SetNonBlock(int fh, bool nonblock) +{ + int flags = fcntl(fh, F_GETFL); + if (nonblock) { + if (flags & O_NONBLOCK) { return true; } + flags |= O_NONBLOCK; + } else { + if (!(flags & O_NONBLOCK)) { return true; } + flags &= ~O_NONBLOCK; + } + + return (fcntl(fh, F_SETFL, flags) >= 0); +} + + bool StringBuffer:: Enlarge(void) { diff --git a/libhfp/soundio-alsa.cpp b/libhfp/soundio-alsa.cpp index 3211079..128370a 100644 --- a/libhfp/soundio-alsa.cpp +++ b/libhfp/soundio-alsa.cpp @@ -908,8 +908,13 @@ public: if (m_rec_nonblock != nonblock) { err = snd_pcm_nonblock(m_alsa.m_rec_handle, nonblock); if (err < 0) { - m_alsa.m_ei->LogWarn("ALSA set nonblock: " + m_alsa.m_ei->LogWarn(&error, + LIBHFP_ERROR_SUBSYS_SOUNDIO, + LIBHFP_ERROR_SOUNDIO_SYSCALL, + "ALSA set rec nonblock: " "%ld", err); + BufAbort(m_alsa.m_ei, error); + return; } m_rec_nonblock = nonblock; } @@ -974,8 +979,13 @@ public: if (m_play_nonblock != nonblock) { err = snd_pcm_nonblock(m_alsa.m_play_handle, nonblock); if (err < 0) { - m_alsa.m_ei->LogWarn("ALSA set nonblock: " + m_alsa.m_ei->LogWarn(&error, + LIBHFP_ERROR_SUBSYS_SOUNDIO, + LIBHFP_ERROR_SOUNDIO_SYSCALL, + "ALSA set play nonblock: " "%zd", err); + BufAbort(m_alsa.m_ei, error); + return; } m_play_nonblock = nonblock; } @@ -1640,13 +1650,22 @@ SoundIoGetDeviceListAlsa(ErrorInfo *error) #else /* defined(USE_ALSA_SOUNDIO) */ SoundIo * -SoundIoCreateAlsa(DispatchInterface *dip, const char *devspec) +SoundIoCreateAlsa(DispatchInterface *dip, const char *devspec, + ErrorInfo *error) { + if (error) + error->Set(LIBHFP_ERROR_SUBSYS_SOUNDIO, + LIBHFP_ERROR_SOUNDIO_NOT_SUPPORTED, + "Support for ALSA omitted"); return 0; } SoundIoDeviceList * -SoundIoGetDeviceListAlsa(void) +SoundIoGetDeviceListAlsa(ErrorInfo *error) { + if (error) + error->Set(LIBHFP_ERROR_SUBSYS_SOUNDIO, + LIBHFP_ERROR_SOUNDIO_NOT_SUPPORTED, + "Support for ALSA omitted"); return 0; } #endif /* defined(USE_ALSA_SOUNDIO) */ diff --git a/libhfp/soundio-oss.cpp b/libhfp/soundio-oss.cpp index b811dc2..add3686 100644 --- a/libhfp/soundio-oss.cpp +++ b/libhfp/soundio-oss.cpp @@ -44,21 +44,6 @@ namespace libhfp { #if defined(USE_OSS_SOUNDIO) -static bool -SetNonBlock(int fh, bool nonblock) -{ - int flags = fcntl(fh, F_GETFL); - if (nonblock) { - if (flags & O_NONBLOCK) { return true; } - flags |= O_NONBLOCK; - } else { - if (!(flags & O_NONBLOCK)) { return true; } - flags &= ~O_NONBLOCK; - } - - return (fcntl(fh, F_SETFL, flags) >= 0); -} - /* * Sound I/O routines for deprecated OSS. Don't use this unless you have to. */ @@ -81,16 +66,10 @@ class OssSoundIo : public SoundIoBufferBase { SocketNotifier *m_not; public: - OssSoundIo(DispatchInterface *eip, - const char *play_dev, const char *rec_dev) + OssSoundIo(DispatchInterface *eip, char *play_dev, char *rec_dev) : m_play_fh(-1), m_rec_fh(-1), - m_play_path(NULL), m_rec_path(NULL), m_obuf_size(0), + m_play_path(play_dev), m_rec_path(rec_dev), m_obuf_size(0), m_ei(eip), m_not(NULL) { - if (play_dev) - m_play_path = strdup(play_dev); - if (rec_dev) - m_rec_path = strdup(rec_dev); - /* Set a default format */ memset(&m_format, 0, sizeof(m_format)); m_format.sampletype = SIO_PCM_S16_LE; @@ -219,7 +198,7 @@ public: m_ei->LogWarn(error, LIBHFP_ERROR_SUBSYS_SOUNDIO, LIBHFP_ERROR_SOUNDIO_SYSCALL, - "OSS get output space: %s", + "OSS GETOSPACE: %s", strerror(errno)); return false; } @@ -376,8 +355,13 @@ public: if (m_rec_nonblock != nonblock) { if (!SetNonBlock(m_rec_fh, nonblock)) { - m_ei->LogWarn("OSS set rec nonblock: %s", + m_ei->LogWarn(&error, + LIBHFP_ERROR_SUBSYS_SOUNDIO, + LIBHFP_ERROR_SOUNDIO_SYSCALL, + "OSS set rec nonblock: %s", strerror(errno)); + BufAbort(m_ei, error); + return; } m_rec_nonblock = nonblock; if (m_play_fh == m_rec_fh) @@ -417,8 +401,13 @@ public: if (m_play_nonblock != nonblock) { if (!SetNonBlock(m_play_fh, nonblock)) { - m_ei->LogWarn("OSS set play nonblock " - "failed"); + m_ei->LogWarn(&error, + LIBHFP_ERROR_SUBSYS_SOUNDIO, + LIBHFP_ERROR_SOUNDIO_SYSCALL, + "OSS set play nonblock: %s", + strerror(errno)); + BufAbort(m_ei, error); + return; } m_play_nonblock = nonblock; if (m_play_fh == m_rec_fh) @@ -461,7 +450,7 @@ public: if (m_play_fh >= 0) { if (ioctl(m_play_fh, SNDCTL_DSP_GETODELAY, &delay) < 0) { - m_ei->LogWarn("OSS GETOSPACE: %s", + m_ei->LogWarn("OSS GETODELAY: %s", strerror(errno)); delay = m_hw_outq; } else { @@ -610,14 +599,33 @@ SoundIoCreateOss(DispatchInterface *dip, const char *driveropts, tok = strtok_r(NULL, "&", &save); } - ossp = new OssSoundIo(dip, outd, ind); + tmp = strdup(outd); + if (!outd) { + free(tmp); + if (error) + error->SetNoMem(); + ossp = 0; + goto failed; + } + + tok = strdup(ind); + if (!tok) { + if (error) + error->SetNoMem(); + ossp = 0; + goto failed; + } + ossp = new OssSoundIo(dip, tmp, tok); if (!ossp) { + free(tmp); + free(tok); if (error) error->SetNoMem(); - return 0; + goto failed; } +failed: if (opts) free(opts); return ossp; @@ -667,13 +675,22 @@ SoundIoGetDeviceListOss(ErrorInfo *error) #else /* defined(USE_OSS_SOUNDIO) */ SoundIo * -SoundIoCreateOss(DispatchInterface *dip, const char *driveropts) +SoundIoCreateOss(DispatchInterface *dip, const char *driveropts, + ErrorInfo *error) { + if (error) + error->Set(LIBHFP_ERROR_SUBSYS_SOUNDIO, + LIBHFP_ERROR_SOUNDIO_NOT_SUPPORTED, + "Support for OSS omitted"); return 0; } SoundIoDeviceList * -SoundIoGetDeviceInfoOss(void) +SoundIoGetDeviceInfoOss(ErrorInfo *error) { + if (error) + error->Set(LIBHFP_ERROR_SUBSYS_SOUNDIO, + LIBHFP_ERROR_SOUNDIO_NOT_SUPPORTED, + "Support for OSS omitted"); return 0; } #endif /* defined(USE_OSS_SOUNDIO) */ -- cgit v1.2.1