You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
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. CC: libav-stable@libav.org Bug-Id: CID 1238992 Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
This commit is contained in:
committed by
Vittorio Giovara
parent
963f761448
commit
b7c77912b6
@@ -48,6 +48,7 @@ int ff_oss_audio_open(AVFormatContext *s1, int is_output,
|
|||||||
int audio_fd;
|
int audio_fd;
|
||||||
int tmp, err;
|
int tmp, err;
|
||||||
char *flip = getenv("AUDIO_FLIP_LEFT");
|
char *flip = getenv("AUDIO_FLIP_LEFT");
|
||||||
|
char errbuff[128];
|
||||||
|
|
||||||
if (is_output)
|
if (is_output)
|
||||||
audio_fd = avpriv_open(audio_device, O_WRONLY);
|
audio_fd = avpriv_open(audio_device, O_WRONLY);
|
||||||
@@ -68,8 +69,18 @@ int ff_oss_audio_open(AVFormatContext *s1, int is_output,
|
|||||||
|
|
||||||
s->frame_size = OSS_AUDIO_BLOCK_SIZE;
|
s->frame_size = OSS_AUDIO_BLOCK_SIZE;
|
||||||
|
|
||||||
/* select format : favour native format */
|
#define CHECK_IOCTL_ERROR(event) \
|
||||||
err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp);
|
if (err < 0) { \
|
||||||
|
av_strerror(AVERROR(errno), errbuff, sizeof(errbuff)); \
|
||||||
|
av_log(s1, AV_LOG_ERROR, #event ": %s\n", errbuff); \
|
||||||
|
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. */
|
||||||
|
(void) ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp);
|
||||||
|
|
||||||
#if HAVE_BIGENDIAN
|
#if HAVE_BIGENDIAN
|
||||||
if (tmp & AFMT_S16_BE) {
|
if (tmp & AFMT_S16_BE) {
|
||||||
@@ -102,24 +113,15 @@ int ff_oss_audio_open(AVFormatContext *s1, int is_output,
|
|||||||
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;
|
||||||
|
|
||||||
@@ -127,6 +129,7 @@ int ff_oss_audio_open(AVFormatContext *s1, int is_output,
|
|||||||
fail:
|
fail:
|
||||||
close(audio_fd);
|
close(audio_fd);
|
||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
|
#undef CHECK_IOCTL_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_oss_audio_close(OSSAudioData *s)
|
int ff_oss_audio_close(OSSAudioData *s)
|
||||||
|
Reference in New Issue
Block a user