13 // sanitizes ai structure before calling other functions
14 int audio_in_init(audio_in_t
*ai
, int type
)
22 ai
->bytes_per_sample
= -1;
28 ai
->alsa
.handle
= NULL
;
30 ai
->alsa
.device
= strdup("default");
33 #ifdef CONFIG_OSS_AUDIO
35 ai
->oss
.audio_fd
= -1;
36 ai
->oss
.device
= strdup("/dev/dsp");
44 int audio_in_setup(audio_in_t
*ai
)
50 if (ai_alsa_init(ai
) < 0) return -1;
54 #ifdef CONFIG_OSS_AUDIO
56 if (ai_oss_init(ai
) < 0) return -1;
65 int audio_in_set_samplerate(audio_in_t
*ai
, int rate
)
70 ai
->req_samplerate
= rate
;
71 if (!ai
->setup
) return 0;
72 if (ai_alsa_setup(ai
) < 0) return -1;
73 return ai
->samplerate
;
75 #ifdef CONFIG_OSS_AUDIO
77 ai
->req_samplerate
= rate
;
78 if (!ai
->setup
) return 0;
79 if (ai_oss_set_samplerate(ai
) < 0) return -1;
80 return ai
->samplerate
;
87 int audio_in_set_channels(audio_in_t
*ai
, int channels
)
92 ai
->req_channels
= channels
;
93 if (!ai
->setup
) return 0;
94 if (ai_alsa_setup(ai
) < 0) return -1;
97 #ifdef CONFIG_OSS_AUDIO
99 ai
->req_channels
= channels
;
100 if (!ai
->setup
) return 0;
101 if (ai_oss_set_channels(ai
) < 0) return -1;
109 int audio_in_set_device(audio_in_t
*ai
, char *device
)
114 if (ai
->setup
) return -1;
118 if (ai
->alsa
.device
) free(ai
->alsa
.device
);
119 ai
->alsa
.device
= strdup(device
);
120 /* mplayer cannot handle colons in arguments */
121 for (i
= 0; i
< (int)strlen(ai
->alsa
.device
); i
++) {
122 if (ai
->alsa
.device
[i
] == '.') ai
->alsa
.device
[i
] = ':';
126 #ifdef CONFIG_OSS_AUDIO
128 if (ai
->oss
.device
) free(ai
->oss
.device
);
129 ai
->oss
.device
= strdup(device
);
137 int audio_in_uninit(audio_in_t
*ai
)
144 snd_output_close(ai
->alsa
.log
);
145 if (ai
->alsa
.handle
) {
146 snd_pcm_close(ai
->alsa
.handle
);
151 #ifdef CONFIG_OSS_AUDIO
153 close(ai
->oss
.audio_fd
);
162 int audio_in_start_capture(audio_in_t
*ai
)
167 return snd_pcm_start(ai
->alsa
.handle
);
169 #ifdef CONFIG_OSS_AUDIO
178 int audio_in_read_chunk(audio_in_t
*ai
, unsigned char *buffer
)
185 ret
= snd_pcm_readi(ai
->alsa
.handle
, buffer
, ai
->alsa
.chunk_size
);
186 if (ret
!= ai
->alsa
.chunk_size
) {
188 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AUDIOIN_ErrReadingAudio
, snd_strerror(ret
));
190 if (ai_alsa_xrun(ai
) == 0) {
191 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AUDIOIN_XRUNSomeFramesMayBeLeftOut
);
193 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AUDIOIN_ErrFatalCannotRecover
);
197 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AUDIOIN_NotEnoughSamples
);
203 #ifdef CONFIG_OSS_AUDIO
205 ret
= read(ai
->oss
.audio_fd
, buffer
, ai
->blocksize
);
206 if (ret
!= ai
->blocksize
) {
208 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AUDIOIN_ErrReadingAudio
, strerror(errno
));
210 mp_msg(MSGT_TV
, MSGL_ERR
, MSGTR_MPDEMUX_AUDIOIN_NotEnoughSamples
);