2002-08-31 22:41:29 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2002-08-21 22:50:40 +00:00
|
|
|
#include "config.h"
|
2002-08-26 17:20:17 +00:00
|
|
|
|
2003-08-07 12:24:35 +00:00
|
|
|
#if defined(USE_TV) && (defined(HAVE_TV_V4L) || defined(HAVE_TV_V4L2)) && defined(USE_OSS_AUDIO)
|
2002-08-31 22:41:29 +00:00
|
|
|
|
|
|
|
#include <string.h> /* strerror */
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2002-08-22 08:05:27 +00:00
|
|
|
#ifdef HAVE_SYS_SOUNDCARD_H
|
|
|
|
#include <sys/soundcard.h>
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_SOUNDCARD_H
|
|
|
|
#include <soundcard.h>
|
|
|
|
#else
|
2002-08-21 22:50:40 +00:00
|
|
|
#include <linux/soundcard.h>
|
2002-08-22 08:05:27 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2002-08-21 22:50:40 +00:00
|
|
|
|
|
|
|
#include "audio_in.h"
|
|
|
|
#include "mp_msg.h"
|
2005-10-31 23:37:41 +00:00
|
|
|
#include "help_mp.h"
|
2002-08-21 22:50:40 +00:00
|
|
|
|
|
|
|
int ai_oss_set_samplerate(audio_in_t *ai)
|
|
|
|
{
|
|
|
|
int tmp = ai->req_samplerate;
|
|
|
|
if (ioctl(ai->oss.audio_fd, SNDCTL_DSP_SPEED, &tmp) == -1) return -1;
|
2004-01-11 10:01:18 +00:00
|
|
|
ai->samplerate = tmp;
|
2002-08-21 22:50:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ai_oss_set_channels(audio_in_t *ai)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int ioctl_param;
|
|
|
|
|
|
|
|
if (ai->req_channels > 2)
|
|
|
|
{
|
|
|
|
ioctl_param = ai->req_channels;
|
|
|
|
mp_msg(MSGT_TV, MSGL_V, "ioctl dsp channels: %d\n",
|
|
|
|
err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_CHANNELS, &ioctl_param));
|
|
|
|
if (err < 0) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2SetChanCount,
|
2002-08-21 22:50:40 +00:00
|
|
|
ai->req_channels);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-01-29 12:43:54 +00:00
|
|
|
ai->channels = ioctl_param;
|
2002-08-21 22:50:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ioctl_param = (ai->req_channels == 2);
|
|
|
|
mp_msg(MSGT_TV, MSGL_V, "ioctl dsp stereo: %d (req: %d)\n",
|
|
|
|
err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_STEREO, &ioctl_param),
|
|
|
|
ioctl_param);
|
|
|
|
if (err < 0) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2SetStereo,
|
2002-08-21 22:50:40 +00:00
|
|
|
ai->req_channels == 2);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-01-29 12:43:54 +00:00
|
|
|
ai->channels = ioctl_param ? 2 : 1;
|
2002-08-21 22:50:40 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ai_oss_init(audio_in_t *ai)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int ioctl_param;
|
|
|
|
|
|
|
|
ai->oss.audio_fd = open(ai->oss.device, O_RDONLY);
|
|
|
|
if (ai->oss.audio_fd < 0)
|
|
|
|
{
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2Open,
|
2002-08-21 22:50:40 +00:00
|
|
|
ai->oss.device, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ioctl_param = 0 ;
|
|
|
|
mp_msg(MSGT_TV, MSGL_V, "ioctl dsp getfmt: %d\n",
|
|
|
|
ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETFMTS, &ioctl_param));
|
|
|
|
|
|
|
|
mp_msg(MSGT_TV, MSGL_V, "Supported formats: %x\n", ioctl_param);
|
|
|
|
if (!(ioctl_param & AFMT_S16_LE))
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_UnsupportedFmt);
|
2002-08-21 22:50:40 +00:00
|
|
|
|
|
|
|
ioctl_param = AFMT_S16_LE;
|
|
|
|
mp_msg(MSGT_TV, MSGL_V, "ioctl dsp setfmt: %d\n",
|
|
|
|
err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SETFMT, &ioctl_param));
|
|
|
|
if (err < 0) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2SetAudioFmt);
|
2002-08-21 22:50:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ai_oss_set_channels(ai) < 0) return -1;
|
|
|
|
|
|
|
|
ioctl_param = ai->req_samplerate;
|
|
|
|
mp_msg(MSGT_TV, MSGL_V, "ioctl dsp speed: %d\n",
|
|
|
|
err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SPEED, &ioctl_param));
|
|
|
|
if (err < 0) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2SetSamplerate,
|
2002-08-21 22:50:40 +00:00
|
|
|
ai->req_samplerate);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-01-29 12:43:54 +00:00
|
|
|
ai->samplerate = ioctl_param;
|
2002-08-21 22:50:40 +00:00
|
|
|
|
|
|
|
mp_msg(MSGT_TV, MSGL_V, "ioctl dsp trigger: %d\n",
|
|
|
|
ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETTRIGGER, &ioctl_param));
|
|
|
|
mp_msg(MSGT_TV, MSGL_V, "trigger: %x\n", ioctl_param);
|
|
|
|
ioctl_param = PCM_ENABLE_INPUT;
|
|
|
|
mp_msg(MSGT_TV, MSGL_V, "ioctl dsp trigger: %d\n",
|
|
|
|
err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param));
|
|
|
|
if (err < 0) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2SetTrigger,
|
2002-08-21 22:50:40 +00:00
|
|
|
PCM_ENABLE_INPUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
ai->blocksize = 0;
|
|
|
|
mp_msg(MSGT_TV, MSGL_V, "ioctl dsp getblocksize: %d\n",
|
|
|
|
err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETBLKSIZE, &ai->blocksize));
|
|
|
|
if (err < 0) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2GetBlockSize);
|
2002-08-21 22:50:40 +00:00
|
|
|
}
|
|
|
|
mp_msg(MSGT_TV, MSGL_V, "blocksize: %d\n", ai->blocksize);
|
|
|
|
|
|
|
|
// correct the blocksize to a reasonable value
|
|
|
|
if (ai->blocksize <= 0) {
|
|
|
|
ai->blocksize = 4096*ai->channels*2;
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_AudioBlockSizeZero, ai->blocksize);
|
2002-08-21 22:50:40 +00:00
|
|
|
} else if (ai->blocksize < 4096*ai->channels*2) {
|
|
|
|
ai->blocksize *= 4096*ai->channels*2/ai->blocksize;
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_AudioBlockSize2Low, ai->blocksize);
|
2002-08-21 22:50:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ai->samplesize = 16;
|
|
|
|
ai->bytes_per_sample = 2;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2002-08-26 17:20:17 +00:00
|
|
|
|
|
|
|
#endif /* USE_OSS_AUDIO */
|