diff options
| author | Calvin Morrison <calvin@pobox.com> | 2026-05-18 00:00:17 -0400 |
|---|---|---|
| committer | Calvin Morrison <calvin@pobox.com> | 2026-05-18 00:00:17 -0400 |
| commit | 65c7ea9fbf4886fa3d6127c5fa699520f30f386c (patch) | |
| tree | bca364e1c1f0244d477349345ec7dd531b8032f8 /src/model/ossmodel.cpp | |
| parent | 3909a06fe6786027c83e3adaef89c343cde4fbe3 (diff) | |
OSS backend for FreeBSD support
Adds a complete OSS audio backend alongside PulseAudio and ALSA:
- OssDevice/OssModel: enumerate /dev/mixer*, poll for changes at 500ms
- Full UI layer: mixer window, system tray, mini popup, per-channel widgets
- Fake mute (saves/restores volume since OSS has no mute bit)
- BackendController and PreferencesDlg updated; backend combo now uses
m_backendIds list so any combination of compiled-in backends works
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/model/ossmodel.cpp')
| -rw-r--r-- | src/model/ossmodel.cpp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/src/model/ossmodel.cpp b/src/model/ossmodel.cpp new file mode 100644 index 0000000..35aa842 --- /dev/null +++ b/src/model/ossmodel.cpp @@ -0,0 +1,140 @@ +#include "ossmodel.h" +#include <sys/soundcard.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdio.h> +#include <tdeconfig.h> +#include <tdeglobal.h> +#include <tqtimer.h> + +static const char *ossChannelNames[] = SOUND_DEVICE_NAMES; + +OssModel::OssModel( TQObject *parent ) + : TQObject(parent), m_timer(0) +{ + m_devices.setAutoDelete(true); + m_timer = new TQTimer(this); + connect(m_timer, TQ_SIGNAL(timeout()), this, TQ_SLOT(onPollTimer())); +} + +OssModel::~OssModel() +{ + close(); +} + +bool OssModel::open() +{ + openCard(0, "/dev/mixer"); + for ( int i = 1; i < 16; ++i ) { + char path[32]; + snprintf(path, sizeof(path), "/dev/mixer%d", i); + int probe = ::open(path, O_RDONLY); + if ( probe < 0 ) break; + ::close(probe); + openCard(i, TQString::fromLocal8Bit(path)); + } + if ( m_devices.isEmpty() ) return false; + m_timer->start(500); + emit ready(); + return true; +} + +void OssModel::openCard( int cardIdx, const TQString &path ) +{ + int fd = ::open(path.local8Bit().data(), O_RDWR); + if ( fd < 0 ) return; + + mixer_info info; + TQString cardName; + if ( ::ioctl(fd, SOUND_MIXER_INFO, &info) == 0 ) + cardName = TQString::fromLocal8Bit(info.name); + else + cardName = path; + + int devmask = 0, stmask = 0, recmask = 0; + ::ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devmask); + ::ioctl(fd, SOUND_MIXER_READ_STEREODEVS, &stmask); + ::ioctl(fd, SOUND_MIXER_READ_RECMASK, &recmask); + + OssCard card; + card.index = cardIdx; + card.path = path; + card.name = cardName; + m_cards.append(card); + m_fds.append(fd); + + for ( int i = 0; i < SOUND_MIXER_NRDEVICES; ++i ) { + if ( !(devmask & (1 << i)) ) continue; + OssDevice::Category cat = (recmask & (1 << i)) + ? OssDevice::Input : OssDevice::Output; + bool stereo = (stmask & (1 << i)) != 0; + TQString name = TQString::fromLocal8Bit(ossChannelNames[i]); + OssDevice *dev = new OssDevice(cat, cardIdx, path, fd, i, name, stereo, this); + m_devices.append(dev); + emit deviceAdded(dev); + } +} + +void OssModel::onPollTimer() +{ + for ( TQPtrListIterator<OssDevice> it(m_devices); *it; ++it ) + (*it)->syncFromOss(); +} + +void OssModel::close() +{ + if ( m_timer ) m_timer->stop(); + m_devices.clear(); + m_cards.clear(); + for ( TQValueListIterator<int> it = m_fds.begin(); it != m_fds.end(); ++it ) + ::close(*it); + m_fds.clear(); +} + +TQPtrList<OssDevice> OssModel::devicesForCard( int cardIdx ) const +{ + TQPtrList<OssDevice> result; + for ( TQPtrListIterator<OssDevice> it(m_devices); *it; ++it ) + if ( (*it)->cardIndex() == cardIdx ) + result.append(*it); + return result; +} + +OssDevice *OssModel::defaultOutput() const +{ + for ( TQPtrListIterator<OssDevice> it(m_devices); *it; ++it ) + if ( (*it)->category() == OssDevice::Output && (*it)->name() == "vol" ) + return *it; + for ( TQPtrListIterator<OssDevice> it(m_devices); *it; ++it ) + if ( (*it)->category() == OssDevice::Output ) + return *it; + return 0; +} + +OssDevice *OssModel::preferredOutput() const +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("OssTray"); + int card = cfg->readNumEntry("TrayCard", -1); + TQString name = cfg->readEntry("TrayDevice", ""); + if ( card >= 0 && !name.isEmpty() ) { + for ( TQPtrListIterator<OssDevice> it(m_devices); *it; ++it ) + if ( (*it)->cardIndex() == card && (*it)->name() == name && + (*it)->category() == OssDevice::Output ) + return *it; + } + return defaultOutput(); +} + +void OssModel::setPreferredOutput( int cardIdx, const TQString &name ) +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("OssTray"); + cfg->writeEntry("TrayCard", cardIdx); + cfg->writeEntry("TrayDevice", name); + cfg->sync(); + emit preferredOutputChanged( preferredOutput() ); +} + +#include "ossmodel.moc" |
