From 730c964029f7b649510490d8766aba801f576492 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 8 Mar 2021 22:29:40 -0800 Subject: Allow calling BackendBase::open multiple times on playback devices It will not be called while the device is running. If the first call succeeds, a subsequent call that happens to fail must leave the existing device state as it was so it can be resumed. This is a rough first pass. It will fail when trying to re-open the same device which can only be opened once (for instance, with direct hardware access, on hardware that doesn't do its own mixing). Some backends won't guarantee the new device is usable until the reset() or start() call. --- alc/backends/oss.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'alc/backends/oss.cpp') diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 4cff5959..196744b0 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -249,7 +249,7 @@ struct OSSPlayback final : public BackendBase { OSSPlayback::~OSSPlayback() { if(mFd != -1) - close(mFd); + ::close(mFd); mFd = -1; } @@ -328,11 +328,15 @@ void OSSPlayback::open(const char *name) devname = iter->device_name.c_str(); } - mFd = ::open(devname, O_WRONLY); - if(mFd == -1) + int fd{::open(devname, O_WRONLY)}; + if(fd == -1) throw al::backend_exception{al::backend_error::NoDevice, "Could not open %s: %s", devname, strerror(errno)}; + if(mFd != -1) + ::close(mFd); + mFd = fd; + mDevice->DeviceName = name; } -- cgit v1.2.3