output/oss: oss_try_ioctl() throws on EINVAL
Eliminate some duplicate code.
This commit is contained in:
parent
c8c553c75c
commit
8da3f8c6a7
@ -255,14 +255,16 @@ oss_try_ioctl_r(FileDescriptor fd, unsigned long request, int *value_r,
|
|||||||
* Invoke an ioctl on the OSS file descriptor.
|
* Invoke an ioctl on the OSS file descriptor.
|
||||||
*
|
*
|
||||||
* Throws on error.
|
* Throws on error.
|
||||||
*
|
|
||||||
* @return true success, false if the parameter is not supported
|
|
||||||
*/
|
*/
|
||||||
static bool
|
static void
|
||||||
oss_try_ioctl(FileDescriptor fd, unsigned long request, int value,
|
oss_try_ioctl(FileDescriptor fd, unsigned long request, int value,
|
||||||
const char *msg)
|
const char *msg)
|
||||||
{
|
{
|
||||||
return oss_try_ioctl_r(fd, request, &value, msg);
|
assert(fd.IsDefined());
|
||||||
|
assert(msg != nullptr);
|
||||||
|
|
||||||
|
if (ioctl(fd.Get(), request, &value) < 0)
|
||||||
|
throw MakeErrno(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -527,20 +529,12 @@ try {
|
|||||||
if (!fd.Open(device, O_WRONLY))
|
if (!fd.Open(device, O_WRONLY))
|
||||||
throw FormatErrno("Error opening OSS device \"%s\"", device);
|
throw FormatErrno("Error opening OSS device \"%s\"", device);
|
||||||
|
|
||||||
const char *const msg1 = "Failed to set channel count";
|
oss_try_ioctl(fd, SNDCTL_DSP_CHANNELS, audio_format.channels,
|
||||||
if (!oss_try_ioctl(fd, SNDCTL_DSP_CHANNELS,
|
"Failed to set channel count");
|
||||||
audio_format.channels, msg1))
|
oss_try_ioctl(fd, SNDCTL_DSP_SPEED, audio_format.sample_rate,
|
||||||
throw std::runtime_error(msg1);
|
"Failed to set sample rate");
|
||||||
|
oss_try_ioctl(fd, SNDCTL_DSP_SAMPLESIZE, oss_format,
|
||||||
const char *const msg2 = "Failed to set sample rate";
|
"Failed to set sample format");
|
||||||
if (!oss_try_ioctl(fd, SNDCTL_DSP_SPEED,
|
|
||||||
audio_format.sample_rate, msg2))
|
|
||||||
throw std::runtime_error(msg2);
|
|
||||||
|
|
||||||
const char *const msg3 = "Failed to set sample format";
|
|
||||||
if (!oss_try_ioctl(fd, SNDCTL_DSP_SAMPLESIZE,
|
|
||||||
oss_format, msg3))
|
|
||||||
throw std::runtime_error(msg3);
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
DoClose();
|
DoClose();
|
||||||
throw;
|
throw;
|
||||||
|
Loading…
Reference in New Issue
Block a user