7 #if defined(USE_TV) && (defined(HAVE_TV_V4L) || defined(HAVE_TV_V4L2))
15 // sanitizes ai structure before calling other functions
16 int audio_in_init(audio_in_t
*ai
, int type
)
24 ai
->bytes_per_sample
= -1;
28 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
30 ai
->alsa
.handle
= NULL
;
32 ai
->alsa
.device
= strdup("default");
37 ai
->oss
.audio_fd
= -1;
38 ai
->oss
.device
= strdup("/dev/dsp");
46 int audio_in_setup(audio_in_t
*ai
)
50 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
52 if (ai_alsa_init(ai
) < 0) return -1;
58 if (ai_oss_init(ai
) < 0) return -1;
67 int audio_in_set_samplerate(audio_in_t
*ai
, int rate
)
70 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
72 ai
->req_samplerate
= rate
;
73 if (!ai
->setup
) return 0;
74 if (ai_alsa_setup(ai
) < 0) return -1;
75 return ai
->samplerate
;
79 ai
->req_samplerate
= rate
;
80 if (!ai
->setup
) return 0;
81 if (ai_oss_set_samplerate(ai
) < 0) return -1;
82 return ai
->samplerate
;
89 int audio_in_set_channels(audio_in_t
*ai
, int channels
)
92 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
94 ai
->req_channels
= channels
;
95 if (!ai
->setup
) return 0;
96 if (ai_alsa_setup(ai
) < 0) return -1;
101 ai
->req_channels
= channels
;
102 if (!ai
->setup
) return 0;
103 if (ai_oss_set_channels(ai
) < 0) return -1;
111 int audio_in_set_device(audio_in_t
*ai
, char *device
)
113 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
116 if (ai
->setup
) return -1;
118 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
120 if (ai
->alsa
.device
) free(ai
->alsa
.device
);
121 ai
->alsa
.device
= strdup(device
);
122 /* mplayer cannot handle colons in arguments */
123 for (i
= 0; i
< (int)strlen(ai
->alsa
.device
); i
++) {
124 if (ai
->alsa
.device
[i
] == '.') ai
->alsa
.device
[i
] = ':';
130 if (ai
->oss
.device
) free(ai
->oss
.device
);
131 ai
->oss
.device
= strdup(device
);
139 int audio_in_uninit(audio_in_t
*ai
)
143 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
146 snd_output_close(ai
->alsa
.log
);
147 if (ai
->alsa
.handle
) {
148 snd_pcm_close(ai
->alsa
.handle
);
155 close(ai
->oss
.audio_fd
);
164 int audio_in_start_capture(audio_in_t
*ai
)
167 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
169 return snd_pcm_start(ai
->alsa
.handle
);
180 int audio_in_read_chunk(audio_in_t
*ai
, unsigned char *buffer
)
185 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
187 ret
= snd_pcm_readi(ai
->alsa
.handle
, buffer
, ai
->alsa
.chunk_size
);
188 if (ret
!= ai
->alsa
.chunk_size
) {
190 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AUDIOIN_ErrReadingAudio
, snd_strerror(ret
));
192 if (ai_alsa_xrun(ai
) == 0) {
193 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AUDIOIN_XRUNSomeFramesMayBeLeftOut
);
195 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AUDIOIN_ErrFatalCannotRecover
);
199 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AUDIOIN_NotEnoughSamples
);
207 ret
= read(ai
->oss
.audio_fd
, buffer
, ai
->blocksize
);
208 if (ret
!= ai
->blocksize
) {
210 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AUDIOIN_ErrReadingAudio
, strerror(errno
));
212 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AUDIOIN_NotEnoughSamples
);