mixer/oss: use class FileDescriptor

This commit is contained in:
Max Kellermann 2017-08-10 19:41:22 +02:00
parent c00b6ff999
commit 56cb92fdaf

View File

@ -20,7 +20,7 @@
#include "config.h"
#include "mixer/MixerInternal.hxx"
#include "config/Block.hxx"
#include "system/fd_util.h"
#include "system/FileDescriptor.hxx"
#include "system/Error.hxx"
#include "util/ASCII.hxx"
#include "util/Domain.hxx"
@ -46,7 +46,7 @@ class OssMixer final : public Mixer {
const char *device;
const char *control;
int device_fd;
FileDescriptor device_fd;
int volume_control;
public:
@ -108,23 +108,23 @@ oss_mixer_init(gcc_unused EventLoop &event_loop,
void
OssMixer::Close() noexcept
{
assert(device_fd >= 0);
assert(device_fd.IsDefined());
close(device_fd);
device_fd.Close();
}
void
OssMixer::Open()
{
device_fd = open_cloexec(device, O_RDONLY, 0);
if (device_fd < 0)
device_fd.OpenReadOnly(device);
if (!device_fd.IsDefined())
throw FormatErrno("failed to open %s", device);
try {
if (control) {
int devmask = 0;
if (ioctl(device_fd, SOUND_MIXER_READ_DEVMASK, &devmask) < 0)
if (ioctl(device_fd.Get(), SOUND_MIXER_READ_DEVMASK, &devmask) < 0)
throw MakeErrno("READ_DEVMASK failed");
if (((1 << volume_control) & devmask) == 0)
@ -143,9 +143,9 @@ OssMixer::GetVolume()
int left, right, level;
int ret;
assert(device_fd >= 0);
assert(device_fd.IsDefined());
ret = ioctl(device_fd, MIXER_READ(volume_control), &level);
ret = ioctl(device_fd.Get(), MIXER_READ(volume_control), &level);
if (ret < 0)
throw MakeErrno("failed to read OSS volume");
@ -166,12 +166,12 @@ OssMixer::SetVolume(unsigned volume)
{
int level;
assert(device_fd >= 0);
assert(device_fd.IsDefined());
assert(volume <= 100);
level = (volume << 8) + volume;
if (ioctl(device_fd, MIXER_WRITE(volume_control), &level) < 0)
if (ioctl(device_fd.Get(), MIXER_WRITE(volume_control), &level) < 0)
throw MakeErrno("failed to set OSS volume");
}