6 #include <string.h> /* strerror */
11 #ifdef HAVE_SYS_SOUNDCARD_H
12 #include <sys/soundcard.h>
14 #ifdef HAVE_SOUNDCARD_H
15 #include <soundcard.h>
17 #include <linux/soundcard.h>
25 int ai_oss_set_samplerate(audio_in_t
*ai
)
27 int tmp
= ai
->req_samplerate
;
28 if (ioctl(ai
->oss
.audio_fd
, SNDCTL_DSP_SPEED
, &tmp
) == -1) return -1;
33 int ai_oss_set_channels(audio_in_t
*ai
)
38 if (ai
->req_channels
> 2)
40 ioctl_param
= ai
->req_channels
;
41 mp_msg(MSGT_TV
, MSGL_V
, "ioctl dsp channels: %d\n",
42 err
= ioctl(ai
->oss
.audio_fd
, SNDCTL_DSP_CHANNELS
, &ioctl_param
));
44 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AIOSS_Unable2SetChanCount
,
48 ai
->channels
= ioctl_param
;
52 ioctl_param
= (ai
->req_channels
== 2);
53 mp_msg(MSGT_TV
, MSGL_V
, "ioctl dsp stereo: %d (req: %d)\n",
54 err
= ioctl(ai
->oss
.audio_fd
, SNDCTL_DSP_STEREO
, &ioctl_param
),
57 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AIOSS_Unable2SetStereo
,
58 ai
->req_channels
== 2);
61 ai
->channels
= ioctl_param
? 2 : 1;
66 int ai_oss_init(audio_in_t
*ai
)
71 ai
->oss
.audio_fd
= open(ai
->oss
.device
, O_RDONLY
);
72 if (ai
->oss
.audio_fd
< 0)
74 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AIOSS_Unable2Open
,
75 ai
->oss
.device
, strerror(errno
));
80 mp_msg(MSGT_TV
, MSGL_V
, "ioctl dsp getfmt: %d\n",
81 ioctl(ai
->oss
.audio_fd
, SNDCTL_DSP_GETFMTS
, &ioctl_param
));
83 mp_msg(MSGT_TV
, MSGL_V
, "Supported formats: %x\n", ioctl_param
);
84 if (!(ioctl_param
& AFMT_S16_LE
))
85 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AIOSS_UnsupportedFmt
);
87 ioctl_param
= AFMT_S16_LE
;
88 mp_msg(MSGT_TV
, MSGL_V
, "ioctl dsp setfmt: %d\n",
89 err
= ioctl(ai
->oss
.audio_fd
, SNDCTL_DSP_SETFMT
, &ioctl_param
));
91 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AIOSS_Unable2SetAudioFmt
);
95 if (ai_oss_set_channels(ai
) < 0) return -1;
97 ioctl_param
= ai
->req_samplerate
;
98 mp_msg(MSGT_TV
, MSGL_V
, "ioctl dsp speed: %d\n",
99 err
= ioctl(ai
->oss
.audio_fd
, SNDCTL_DSP_SPEED
, &ioctl_param
));
101 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AIOSS_Unable2SetSamplerate
,
105 ai
->samplerate
= ioctl_param
;
107 mp_msg(MSGT_TV
, MSGL_V
, "ioctl dsp trigger: %d\n",
108 ioctl(ai
->oss
.audio_fd
, SNDCTL_DSP_GETTRIGGER
, &ioctl_param
));
109 mp_msg(MSGT_TV
, MSGL_V
, "trigger: %x\n", ioctl_param
);
110 ioctl_param
= PCM_ENABLE_INPUT
;
111 mp_msg(MSGT_TV
, MSGL_V
, "ioctl dsp trigger: %d\n",
112 err
= ioctl(ai
->oss
.audio_fd
, SNDCTL_DSP_SETTRIGGER
, &ioctl_param
));
114 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AIOSS_Unable2SetTrigger
,
119 mp_msg(MSGT_TV
, MSGL_V
, "ioctl dsp getblocksize: %d\n",
120 err
= ioctl(ai
->oss
.audio_fd
, SNDCTL_DSP_GETBLKSIZE
, &ai
->blocksize
));
122 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AIOSS_Unable2GetBlockSize
);
124 mp_msg(MSGT_TV
, MSGL_V
, "blocksize: %d\n", ai
->blocksize
);
126 // correct the blocksize to a reasonable value
127 if (ai
->blocksize
<= 0) {
128 ai
->blocksize
= 4096*ai
->channels
*2;
129 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AIOSS_AudioBlockSizeZero
, ai
->blocksize
);
130 } else if (ai
->blocksize
< 4096*ai
->channels
*2) {
131 ai
->blocksize
*= 4096*ai
->channels
*2/ai
->blocksize
;
132 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AIOSS_AudioBlockSize2Low
, ai
->blocksize
);
136 ai
->bytes_per_sample
= 2;