diff options
Diffstat (limited to 'src/plugins/Output/oss4/outputoss4.cpp')
| -rw-r--r-- | src/plugins/Output/oss4/outputoss4.cpp | 107 |
1 files changed, 51 insertions, 56 deletions
diff --git a/src/plugins/Output/oss4/outputoss4.cpp b/src/plugins/Output/oss4/outputoss4.cpp index d9c46f2b6..ecd37c504 100644 --- a/src/plugins/Output/oss4/outputoss4.cpp +++ b/src/plugins/Output/oss4/outputoss4.cpp @@ -44,7 +44,6 @@ extern "C" #include <qmmp/visual.h> #include "outputoss4.h" - OutputOSS4 *OutputOSS4::m_instance = 0; OutputOSS4::OutputOSS4(QObject *parent) : Output(parent) @@ -67,8 +66,50 @@ OutputOSS4::~OutputOSS4() m_instance = 0; } -void OutputOSS4::configure(quint32 freq, int chan, Qmmp::AudioFormat format) +int OutputOSS4::fd() +{ + return m_audio_fd; +} + +OutputOSS4 *OutputOSS4::instance() +{ + return m_instance; +} + +void OutputOSS4::post() +{ + ioctl(m_audio_fd, SNDCTL_DSP_POST, 0); +} + +void OutputOSS4::sync() +{ + ioctl(m_audio_fd, SNDCTL_DSP_SYNC, 0); +} + +bool OutputOSS4::initialize(quint32 freq, int chan, Qmmp::AudioFormat format) { + m_audio_fd = open(m_audio_device.toAscii(), O_WRONLY, 0); + + if (m_audio_fd < 0) + { + qWarning("OSS4Output: unable to open output device '%s'; error: %s", + qPrintable(m_audio_device), strerror(errno)); + return false; + } + + int flags; + if ((flags = fcntl(m_audio_fd, F_GETFL, 0)) > 0) + { + flags &= O_NDELAY; + fcntl(m_audio_fd, F_SETFL, flags); + } + fd_set afd; + FD_ZERO(&afd); + FD_SET(m_audio_fd, &afd); + struct timeval tv; + tv.tv_sec = 0l; + tv.tv_usec = 50000l; + m_do_select = (select(m_audio_fd + 1, 0, &afd, 0, &tv) > 0); int p; switch (format) { @@ -86,89 +127,43 @@ void OutputOSS4::configure(quint32 freq, int chan, Qmmp::AudioFormat format) break; default: qWarning("OutputOSS4: unsupported audio format"); - return; + return false; } int param = p; if (ioctl(m_audio_fd, SNDCTL_DSP_SETFMT, &p) < 0) { qWarning("OutputOSS4: ioctl SNDCTL_DSP_SETFMT failed: %s",strerror(errno)); - return; + return false; } if(param != p) { qWarning("OutputOSS4: unsupported audio format"); - return; + return false; } param = chan; if(ioctl(m_audio_fd, SNDCTL_DSP_CHANNELS, &chan) < 0) { qWarning("OutputOSS4: ioctl SNDCTL_DSP_CHANNELS failed: %s", strerror(errno)); - return; + return false; } if(param != chan) { qWarning("OutputOSS4: unsupported %d-channel mode", param); - return; + return false; } uint param2 = freq; if (ioctl(m_audio_fd, SNDCTL_DSP_SPEED, &freq) < 0) { qWarning("OutputOSS4: ioctl SNDCTL_DSP_SPEED failed: %s", strerror(errno)); - return; + return false; } if(param2 != freq) { qWarning("OutputOSS4: unsupported sample rate"); - return; - } - ioctl(m_audio_fd, SNDCTL_DSP_RESET, 0); - Output::configure(freq, chan, format); -} - -int OutputOSS4::fd() -{ - return m_audio_fd; -} - -OutputOSS4 *OutputOSS4::instance() -{ - return m_instance; -} - -void OutputOSS4::post() -{ - ioctl(m_audio_fd, SNDCTL_DSP_POST, 0); -} - -void OutputOSS4::sync() -{ - ioctl(m_audio_fd, SNDCTL_DSP_SYNC, 0); -} - -bool OutputOSS4::initialize() -{ - m_audio_fd = open(m_audio_device.toAscii(), O_WRONLY, 0); - - if (m_audio_fd < 0) - { - qWarning("OSS4Output: unable to open output device '%s'; error: %s", - qPrintable(m_audio_device), strerror(errno)); return false; } - - int flags; - if ((flags = fcntl(m_audio_fd, F_GETFL, 0)) > 0) - { - flags &= O_NDELAY; - fcntl(m_audio_fd, F_SETFL, flags); - } - fd_set afd; - FD_ZERO(&afd); - FD_SET(m_audio_fd, &afd); - struct timeval tv; - tv.tv_sec = 0l; - tv.tv_usec = 50000l; - m_do_select = (select(m_audio_fd + 1, 0, &afd, 0, &tv) > 0); + ioctl(m_audio_fd, SNDCTL_DSP_RESET, 0); + configure(freq, chan, format); return true; } |
