Commit 69c7aad4 authored by Timothy Gu's avatar Timothy Gu Committed by Michael Niedermayer

oss_audio: use a macro to simplify ioctl() error checking

Also add a note about SNDCTL_DSP_GETFMTS which may fail even if OSS is
available.
Signed-off-by: 's avatarTimothy Gu <timothygu99@gmail.com>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent e1e3ec9b
...@@ -87,7 +87,16 @@ static int audio_open(AVFormatContext *s1, int is_output, const char *audio_devi ...@@ -87,7 +87,16 @@ static int audio_open(AVFormatContext *s1, int is_output, const char *audio_devi
s->frame_size = AUDIO_BLOCK_SIZE; s->frame_size = AUDIO_BLOCK_SIZE;
/* select format : favour native format */ #define CHECK_IOCTL_ERROR(event) \
if (err < 0) { \
av_log(s1, AV_LOG_ERROR, #event ": %s\n", strerror(errno)); \
goto fail; \
}
/* select format : favour native format
* We don't CHECK_IOCTL_ERROR here because even if failed OSS still may be
* usable. If OSS is not usable the SNDCTL_DSP_SETFMTS later is going to
* fail anyway. `err =` kept to eliminate compiler warning. */
err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp); err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp);
#if HAVE_BIGENDIAN #if HAVE_BIGENDIAN
...@@ -121,24 +130,15 @@ static int audio_open(AVFormatContext *s1, int is_output, const char *audio_devi ...@@ -121,24 +130,15 @@ static int audio_open(AVFormatContext *s1, int is_output, const char *audio_devi
return AVERROR(EIO); return AVERROR(EIO);
} }
err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp); err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp);
if (err < 0) { CHECK_IOCTL_ERROR(SNDCTL_DSP_SETFMTS)
av_log(s1, AV_LOG_ERROR, "SNDCTL_DSP_SETFMT: %s\n", strerror(errno));
goto fail;
}
tmp = (s->channels == 2); tmp = (s->channels == 2);
err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp); err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
if (err < 0) { CHECK_IOCTL_ERROR(SNDCTL_DSP_STEREO)
av_log(s1, AV_LOG_ERROR, "SNDCTL_DSP_STEREO: %s\n", strerror(errno));
goto fail;
}
tmp = s->sample_rate; tmp = s->sample_rate;
err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &tmp); err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &tmp);
if (err < 0) { CHECK_IOCTL_ERROR(SNDCTL_DSP_SPEED)
av_log(s1, AV_LOG_ERROR, "SNDCTL_DSP_SPEED: %s\n", strerror(errno));
goto fail;
}
s->sample_rate = tmp; /* store real sample rate */ s->sample_rate = tmp; /* store real sample rate */
s->fd = audio_fd; s->fd = audio_fd;
...@@ -146,6 +146,7 @@ static int audio_open(AVFormatContext *s1, int is_output, const char *audio_devi ...@@ -146,6 +146,7 @@ static int audio_open(AVFormatContext *s1, int is_output, const char *audio_devi
fail: fail:
close(audio_fd); close(audio_fd);
return AVERROR(EIO); return AVERROR(EIO);
#undef CHECK_IOCTL_ERROR
} }
static int audio_close(AudioData *s) static int audio_close(AudioData *s)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment